Commit 9ace7877 authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Fixed quota bug, added tagging to files, and improved some of the base class

methods for dealing with tagging
parent 859e334f
......@@ -36,6 +36,7 @@ json_headers();
$parentfolder = param_variable('parentfolder', null); // id of parent artefact
$title = param_variable('name');
$description = param_variable('description', null);
$tags = param_variable('tags', null);
$collideaction = param_variable('collideaction', 'fail');
$adminfiles = param_boolean('adminfiles', false);
......@@ -45,6 +46,7 @@ if ($parentfolder) {
}
$data->title = $title;
$data->description = $description;
$data->tags = $tags;
$data->owner = $USER->get('id');
$data->adminfiles = (int)$adminfiles;
......
......@@ -129,6 +129,7 @@ function FileBrowser(element, source, statevars, changedircallback, actionname,
data['name'] = $(formid).name.value;
data['collideaction'] = collideaction;
data['description'] = $(formid).description.value;
data['tags'] = $(formid).tags.value;
if (fileid) {
var script = self.updatemetadatascript;
......@@ -169,6 +170,8 @@ function FileBrowser(element, source, statevars, changedircallback, actionname,
TR(null,TH(null,LABEL(get_string('description'))),
TD(null,INPUT({'type':'text','class':'text','name':'description',
'value':fileinfo.description,'size':40}))),
TR(null, TH(null, LABEL(null, get_string('tags'))),
TD(null, create_tags_control('tags', fileinfo.tags))),
TR(null,TD({'colspan':2},SPAN({'id':formid+'message'}))),
TR(null,TD({'colspan':2}, savebutton, replacebutton, cancelbutton))));
hideElement(rowid);
......@@ -185,6 +188,7 @@ function FileBrowser(element, source, statevars, changedircallback, actionname,
hideElement($(formid).replace);
$(formid).name.value = '';
$(formid).description.value = '';
$(formid).tags.value = '';
$(formid+'message').innerHTML = '';
hideElement(formid);
};
......@@ -215,6 +219,8 @@ function FileBrowser(element, source, statevars, changedircallback, actionname,
TR(null,TH(null,LABEL(get_string('description'))),
TD(null,INPUT({'type':'text','class':'text','name':'description',
'value':'','size':40}))),
TR(null, TH(null, LABEL(null, get_string('tags'))),
TD(null, create_tags_control('tags'))),
TR(null,TD({'colspan':2},SPAN({'id':formid+'message'}))),
TR(null,TD({'colspan':2},createbutton,replacebutton,cancelbutton)))));
};
......@@ -359,6 +365,7 @@ function FileUploader(element, uploadscript, statevars, foldername, folderid, up
self.form.userfile.value = '';
self.form.title.value = '';
self.form.description.value = '';
self.form.tags.value = '';
hideElement(self.form.replace);
hideElement(self.form);
showElement(self.openbutton);
......@@ -382,6 +389,8 @@ function FileUploader(element, uploadscript, statevars, foldername, folderid, up
TD(null, INPUT({'type':'text', 'class':'text', 'name':'title', 'size':40}))),
TR(null, TH(null, LABEL(null, get_string('description'))),
TD(null, INPUT({'type':'text', 'class':'text', 'name':'description', 'size':40}))),
TR(null, TH(null, LABEL(null, get_string('tags'))),
TD(null, create_tags_control('tags'))),
TR(null,TD({'colspan':2, 'id':'uploadformmessage'})),
TR(null,TD({'colspan':2},
INPUT({'name':'upload','type':'button','class':'button',
......
......@@ -102,6 +102,7 @@ class PluginArtefactFile extends PluginArtefact {
'cancel',
'delete',
'edit',
'tags',
),
'artefact.file' => array(
'copyrightnotice',
......@@ -373,6 +374,10 @@ class ArtefactTypeFileBase extends ArtefactType {
else {
foreach ($filedata as $item) {
$item->mtime = format_date(strtotime($item->mtime), 'strfdaymonthyearshort');
$item->tags = get_column('artefact_tag', 'tag', 'artefact', $item->id);
if (!is_array($item->tags)) {
$item->tags = array();
}
}
}
......
......@@ -39,6 +39,7 @@ $parentfolder = param_variable('parentfolder', null); // id of parent artefact
$id = param_integer('id');
$name = param_variable('name');
$description = param_variable('description');
$tags = param_variable('tags');
$collideaction = param_variable('collideaction', 'fail');
$adminfiles = param_boolean('adminfiles', false);
$owner = $USER->get('id');
......@@ -59,6 +60,7 @@ if ($existingid = ArtefactTypeFileBase::file_exists($name, $owner, $parentfolder
$artefact = artefact_instance_from_id($id);
$artefact->set('title', $name);
$artefact->set('description', $description);
$artefact->set('tags', preg_split("/\s*,\s*/", trim($tags)));
$artefact->set('adminfiles', (int) $adminfiles);
$artefact->set('owner', $owner);
$artefact->commit();
......
......@@ -33,6 +33,7 @@ $parentfolder = param_variable('parentfolder', null); // id of parent art
$parentfoldername = param_variable('parentfoldername', ''); // path to parent folder
$title = param_variable('title');
$description = param_variable('description', null);
$tags = param_variable('tags', null);
$uploadnumber = param_integer('uploadnumber'); // id of target iframe
$collideaction = param_variable('collideaction', 'fail');
$adminfiles = param_boolean('adminfiles', false);
......@@ -43,6 +44,7 @@ if ($parentfolder) {
}
$data->title = $title;
$data->description = $description;
$data->tags = $tags;
$data->owner = $USER->get('id');
$data->adminfiles = (int) $adminfiles;
$data->container = 0;
......
......@@ -126,6 +126,9 @@ abstract class ArtefactType {
if (in_array($field, array('atime', 'ctime', 'mtime'))) {
$value = strtotime($value);
}
if ($field == 'tags' && !is_array($field)) {
$value = preg_split("/\s*,\s*/", trim($value));
}
$this->{$field} = $value;
}
}
......@@ -348,6 +351,9 @@ abstract class ArtefactType {
delete_records('artefact_tag', 'artefact', $this->id);
if (is_array($this->tags)) {
foreach ($this->tags as $tag) {
if (empty($tag)) {
continue;
}
insert_record(
'artefact_tag',
(object) array(
......@@ -403,6 +409,7 @@ abstract class ArtefactType {
delete_records('view_artefact', 'artefact', $this->id);
delete_records('artefact_feedback', 'artefact', $this->id);
delete_records('usr_watchlist_artefact', 'artefact', $this->id);
delete_records('artefact_tag', 'artefact', $this->id);
// Delete the record itself.
delete_records('artefact', 'id', $this->id);
......
......@@ -425,6 +425,27 @@ function keepElementInViewport(element) {
}
}
function create_tags_control(name, value, options) {
var elements = [];
options = update({
'size': 40
},
options
);
if (typeof(value) == 'object') {
value = value.join(', ');
}
if (!value) {
value = '';
}
elements.push(INPUT({'name': name, 'size': options.size, 'value': value}));
return elements;
}
function quotaUpdate(quotaused, quota) {
if (! $('quota_percentage') ) {
return;
......@@ -466,7 +487,7 @@ function quotaUpdate(quotaused, quota) {
$('quota_fill').style.width = (percentage * 2) + 'px';
}
if (quotaused && quota) {
if ((typeof(quotaused) == 'number' || typeof(quotaused) == 'string') && quota) {
var data = { 'quotaused': quotaused, 'quota': quota };
update(data);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment