Commit 1284c89f authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Added ability to tag file uploads to blog posts

parent e253e2b7
......@@ -735,7 +735,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
/**
* Save a temporary uploaded file to the myfiles area.
*/
public function save_attachment($directory, $filename, $title, $description) {
public function save_attachment($directory, $filename, $title, $description, $tags) {
// Create the blogfiles folder if it doesn't exist yet.
$blogfilesid = self::blogfiles_folder_id();
......@@ -750,6 +750,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
$data = new StdClass;
$data->title = $title;
$data->description = $description;
$data->tags = $tags;
$data->owner = $USER->get('id');
$data->adminfiles = 0; // No admin blogs yet...
$data->parent = $blogfilesid;
......@@ -803,10 +804,16 @@ class ArtefactTypeBlogPost extends ArtefactType {
*/
public function get_attached_files() {
$prefix = get_config('dbprefix');
return get_records_sql_array('SELECT a.id, a.artefacttype, a.title, a.description
$list = get_records_sql_array('SELECT a.id, a.artefacttype, a.title, a.description
FROM ' . $prefix . 'artefact_blog_blogpost_file f
INNER JOIN ' . $prefix . 'artefact a ON a.id = f.file
WHERE f.blogpost = ' . $this->id, '');
// load tags
foreach ( $list as &$attachment ) {
$attachment->tags = join(', ', get_column('artefact_tag', 'tag', 'artefact', $attachment->id));
}
return $list;
}
public function public_feedback_allowed() {
......
......@@ -222,6 +222,7 @@ var attached = new TableRenderer(
'alt':r.artefacttype})); },
'title',
'description',
'tags',
function (r) {
return TD(null, INPUT({'type':'button', 'class':'button',
'value':{$getstring['remove']},
......@@ -267,15 +268,25 @@ function attachtopost(data) {
if (fileattached_id(rowid) || data.error) {
return;
}
appendChildNodes(attached.tbody,
TR({'id':rowid},
map(partial(TD,null),
[IMG({'src':get_themeurl('images/'+data.artefacttype+'.gif'),
'alt':data.artefacttype}),
data.title, data.description,
INPUT({'type':'button', 'class':'button',
'value':{$getstring['remove']},
'onclick':"removefrompost('"+rowid+"')"})])));
appendChildNodes(
attached.tbody,
TR(
{'id':rowid},
map(
partial(TD,null),
[
IMG({'src':get_themeurl('images/'+data.artefacttype+'.gif'), 'alt':data.artefacttype}),
data.title,
data.description,
data.tags,
INPUT(
{'type':'button', 'class':'button', 'value':{$getstring['remove']},
'onclick':"removefrompost('"+rowid+"')"}
)
]
)
)
);
redrawAttachList();
}
......@@ -316,9 +327,12 @@ function saveblogpost() {
artefacts.push(idparts[1]);
}
else { // uploaded file
var record = {'id':idparts[1],
'title':scrapeText(attached.tbody.childNodes[i].childNodes[1]),
'description':scrapeText(attached.tbody.childNodes[i].childNodes[2])};
var record = {
'id':idparts[1],
'title':scrapeText(attached.tbody.childNodes[i].childNodes[1]),
'description':scrapeText(attached.tbody.childNodes[i].childNodes[2]),
'tags':scrapeText(attached.tbody.childNodes[i].childNodes[3])
};
uploads.push(record);
}
}
......
......@@ -112,7 +112,8 @@ $uploadartefact = array();
if (!empty($uploads)) {
foreach ($uploads as $upload) {
if (!$fileid = $postobj->save_attachment(session_id() . $createid, $upload->id,
$upload->title, $upload->description)) {
$upload->title, $upload->description,
$upload->tags)) {
json_reply('local', get_string('errorsavingattachments', 'artefact.blog'));
// Things could be in a bad state.
}
......
......@@ -35,6 +35,7 @@
<th></th>
<th>{str section=artefact.file tag=name}</th>
<th>{str section=artefact.file tag=description}</th>
<th>{str tag=tags}</th>
<th></th>
</tr></thead>
<tbody><tr><td></td></tr></tbody>
......
......@@ -33,6 +33,7 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$result = new StdClass;
$result->title = param_variable('title');
$result->description = param_variable('description', null);
$result->tags = param_variable('tags', null);
$result->uploadnumber = param_integer('uploadnumber'); // id of target iframe
$createid = param_variable('createid');
......
Supports Markdown
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