Commit 975bafa8 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Display list of files attached to blog posts

parent cec5ab99
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage artefact-blog
* @author Richard Mansfield <richard.mansfield@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'blog');
$limit = param_integer('limit', null);
$offset = param_integer('offset', 0);
$id = param_integer('blogpost', 0);
if ($id) {
$blogpost = new ArtefactTypeBlogPost($id);
if (!$filelist = $blogpost->get_attached_files()) {
$filelist = array();
}
}
else {
$filelist = array();
}
$result = array(
'count' => count($filelist),
'limit' => $limit,
'offset' => $offset,
'data' => $filelist,
'error' => false,
'message' => get_string('attachedfilelistloaded'),
);
json_headers();
print json_encode($result);
......@@ -34,8 +34,8 @@ safe_require('artefact', 'blog');
// For a new post, the 'blog' parameter will be set to the blog's artefact id.
// For an existing post, the 'post' parameter will be set to the blogpost's artefact id.
$post = param_integer('post', 0);
if (!$post) {
$blogpost = param_integer('blogpost', 0);
if (!$blogpost) {
// This is a new post; get a create id so we can attach files to it.
$createid = $SESSION->get('createid');
if (empty($createid)) {
......@@ -43,24 +43,57 @@ if (!$post) {
}
$SESSION->set('createid', $createid + 1);
$blog = param_integer('blog');
$post = '';
$blogpost = 0;
$title = '';
$description = '';
$checked = '';
$pagetitle = 'newblogpost';
}
else {
$blogpost = new ArtefactTypeBlogPost($post);
if ($blogpost->get('owner') != $USER->get('id')) {
$blogpostobj = new ArtefactTypeBlogPost($blogpost);
if ($blogpostobj->get('owner') != $USER->get('id')) {
return;
}
$blog = $blogpost->get('parent');
$title = $blogpost->get('title');
$description = $blogpost->get('description');
$checked = !$blogpost->get('published');
$blog = $blogpostobj->get('parent');
$title = $blogpostobj->get('title');
$description = $blogpostobj->get('description');
$checked = !$blogpostobj->get('published');
$pagetitle = 'editblogpost';
}
$getstring = quotestrings(array(
'mahara' => array(
),
'artefact.blog' => array(
'nofilesattachedtothispost',
)));
$attachedhtml = '<h3>' . get_string('attachedfiles', 'artefact.blog') . "</h3>\n";
$attachedhtml .= "<table id='attachedfiles'><tbody><tr><td></td></tr></tbody></table>\n";
//$blogpostjs = $blogpost ? $blogpost : 'null';
$javascript = <<< EOF
var attached = new TableRenderer(
'attachedfiles',
'attachedfiles.json.php',
[
'title',
'description',
function () { return TD(null); }
]
);
attached.emptycontent = {$getstring['nofilesattachedtothispost']};
attached.paginate = false;
attached.blogpost = {$blogpost};
attached.statevars.push('blogpost');
attached.rowfunction = function (r) { return TR({'id':'attached_old_' + r.id}); };
attached.updateOnLoad();
EOF;
$form = pieform(array(
'name' => 'editpost',
'method' => 'post',
......@@ -72,7 +105,7 @@ $form = pieform(array(
),
'id' => array(
'type' => 'hidden',
'value' => $post,
'value' => $blogpost,
),
'title' => array(
'type' => 'text',
......@@ -100,6 +133,10 @@ $form = pieform(array(
'description' => get_string('thisisdraftdesc', 'artefact.blog'),
'checked' => $checked
),
'attachedfiles' => array(
'type' => 'html',
'value' => $attachedhtml,
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(
......@@ -110,15 +147,11 @@ $form = pieform(array(
)
));
$javascript = <<< EOF
EOF;
$smarty = smarty();
$smarty = smarty(array('tablerenderer'));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('pagetitle', $pagetitle);
$smarty->assign_by_ref('editpostform', $form);
$smarty->display('artefact:blog:editpost.tpl');
exit;
/**
* This function gets called to create a new blog post, and publish it
......
......@@ -32,6 +32,9 @@ $string['description'] = 'description';
$string['addblog'] = 'Add Blog';
$string['newblog'] = 'New Blog';
$string['attachedfiles'] = 'Attached files';
$string['nofilesattachedtothispost'] = 'No attached files';
$string['blogtitle'] = 'Title';
$string['blogtitledesc'] = 'e.g., ‘Jill’s Travel Blog’.';
$string['blogdesc'] = 'Description';
......
......@@ -75,10 +75,10 @@ class PluginArtefactBlog extends PluginArtefact {
*/
public static function clean_post_files() {
safe_require('artefact', 'file');
($files = get_records_sql_array("
SELECT file
FROM artefact_blog_blogpost_file_pending
FROM " . get_config('dbprefix') . "artefact_blog_blogpost_file_pending
WHERE when + ?::INTERVAL < CURRENT_TIMESTAMP", array(self::maxpending)))
|| ($files = array());
......@@ -572,6 +572,21 @@ class ArtefactTypeBlogPost extends ArtefactType {
}
return true;
}
/**
* This function returns a list of files attached to a post to use
* when displaying or editing a blog post
*
* @return array
*/
public function get_attached_files() {
$prefix = get_config('dbprefix');
return 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, '');
}
}
?>
......@@ -11,14 +11,16 @@
</div>
<div id="column-left">
<div class="content">
<div class="box-cnrs"><span class="cnr-tl"><span class="cnr-tr"><span class="cnr-bl"><span class="cnr-br">
<div class="maincontent">
<h2>{str section="artefact.blog" tag=$pagetitle}</h2>
{$editpostform}
</div>
</span></span></span></span></div>
<div class="content">
<div class="box-cnrs">
<span class="cnr-tl"><span class="cnr-tr"><span class="cnr-bl"><span class="cnr-br">
<div class="maincontent">
<h2>{str section="artefact.blog" tag=$pagetitle}</h2>
{$editpostform}
</div>
</span></span></span></span>
</div>
</div>
</div>
{include file="footer.tpl"}
......@@ -84,7 +84,7 @@ postlist.rowfunction = function(d, n, gd) {
INPUT(
{
'type' : 'hidden',
'name' : 'post',
'name' : 'blogpost',
'value' : d.id
}
),
......
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