Commit 87991c07 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Show attached files on view blog page

parent dbdc7d6a
......@@ -465,10 +465,11 @@ class ArtefactTypeBlogPost extends ArtefactType {
* @param integer
*/
public static function get_posts(User $user, $id, $limit = self::pagination, $offset = 0) {
($result = get_records_sql_array("
$prefix = get_config('dbprefix');
($result = get_records_sql_assoc("
SELECT a.id, a.title, a.description, a.ctime, a.mtime, bp.published
FROM " . get_config('dbprefix') . "artefact a
LEFT OUTER JOIN " . get_config('dbprefix') . "artefact_blog_blogpost bp
FROM " . $prefix . "artefact a
LEFT OUTER JOIN " . $prefix . "artefact_blog_blogpost bp
ON a.id = bp.blogpost
WHERE a.parent = ?
AND a.artefacttype = 'blogpost'
......@@ -482,9 +483,26 @@ class ArtefactTypeBlogPost extends ArtefactType {
)))
|| ($result = array());
$count = (int)get_field('artefact', 'COUNT(*)', 'owner', $user->get('id'), 'artefacttype', 'blogpost', 'parent', $id);
$count = (int)get_field('artefact', 'COUNT(*)', 'owner', $user->get('id'),
'artefacttype', 'blogpost', 'parent', $id);
// Get the attached files.
if ($count > 0) {
$idlist = implode(', ', array_map(create_function('$a', 'return $a->id;'), $result));
$files = get_records_sql_array('
SELECT
bf.blogpost, bf.file, a.artefacttype, a.title, a.description
FROM ' . $prefix . 'artefact_blog_blogpost_file bf
INNER JOIN ' . $prefix . 'artefact a ON bf.file = a.id
WHERE bf.blogpost IN (' . $idlist . ')', '');
if ($files) {
foreach ($files as $file) {
$result[$file->blogpost]->files[] = $file;
}
}
}
return array($count, $result);
return array($count, array_values($result));
}
/**
......
......@@ -37,6 +37,7 @@ $enc_publish_confirm = json_encode(get_string('publishblogpost?', 'artefact.blog
$enc_nopublish = json_encode(get_string('nopublish', 'artefact.blog'));
$enc_error = json_encode(get_string('jsonerror', 'artefact.blog'));
$enc_edit = json_encode(get_string('edit', 'artefact.blog'));
$enc_files = json_encode(get_string('attachedfiles', 'artefact.blog'));
$enc_delete = json_encode(get_string('delete', 'artefact.blog'));
$enc_delete_confirm = json_encode(get_string('deleteblogpost?', 'artefact.blog'));
......@@ -118,10 +119,27 @@ postlist.rowfunction = function(d, n, gd) {
status,
TD(null, [pub, ' ', edit, ' ', del])
),
TR(null, desctd),
TR(null, TD(null, d.ctime))
TR(null, desctd)
];
if (d.files) {
var filerows = [TR(null, TD({'colSpan':3}, {$enc_files}))];
for (var i = 0; i < d.files.length; i++) {
filerows.push(TR(null,
TD(null, IMG({'src':config.themeurl + d.files[i].artefacttype + '.gif'})),
TD(null, d.files[i].title),
TD(null, d.files[i].description)));
}
rows.push(TR(null, TD({'colSpan':3},
TABLE(null,
createDOM('col', {'width':'5%'}),
createDOM('col', {'width':'40%'}),
createDOM('col', {'width':'55%'}),
TBODY(null, filerows)))));
}
rows.push(TR(null, TD(null, d.ctime)));
connect(del, 'onclick', function(e) {
if (!confirm({$enc_delete_confirm})) {
return;
......
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