Commit 711f0faa authored by Alastair Pharo's avatar Alastair Pharo Committed by Alastair Pharo
Browse files

More fixes for blog rendering

parent 678e8ba6
......@@ -60,7 +60,7 @@ $form = pieform(array(
),
'description' => array(
'type' => 'wysiwyg',
'rows' => 5,
'rows' => 10,
'cols' => 80,
'title' => get_string('postbody', 'artefact.blog'),
'description' => get_string('postbodydesc', 'artefact.blog'),
......
......@@ -76,4 +76,6 @@ $string['thisisdraft'] = 'This post is a draft';
$string['thisisdraftdesc'] = 'When your post is a draft, no one except you can see it.';
$string['save'] = 'Save';
$string['noresults'] = 'No results';
?>
......@@ -187,10 +187,20 @@ class ArtefactTypeBlog extends ArtefactType {
* @return string
*/
function render_full($options) {
// This is because if there are multiple blocks on a page, they need separate
// js variables.
$blockid = isset($options['blockid'])
? $options['blockid']
: mt_rand();
// This uses the above blockid, so needs to be inlcuded after.
$javascript = require(get_config('docroot') . 'artefact/blog/render/blog_renderfull.js.php');
$smarty = smarty();
$smarty->assign('artefact', $this);
$smarty->assign('children', $this->get_children_instances());
$smarty->assign('blockid', $blockid);
$smarty->assign_by_ref('options', $options);
$smarty->assign_by_ref('javascript', $javascript);
return $smarty->fetch('artefact:blog:render/blog_renderfull.tpl');
}
......@@ -439,7 +449,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
* @param integer
*/
public static function render_posts($format, $id, $limit = self::pagination, $offset = 0, $options = null) {
$postids = get_records_sql_array("
($postids = get_records_sql_array("
SELECT a.id
FROM " . get_config('dbprefix') . "artefact a
LEFT OUTER JOIN " . get_config('dbprefix') . "artefact_blog_blogpost bp
......@@ -447,7 +457,8 @@ class ArtefactTypeBlogPost extends ArtefactType {
WHERE a.parent = ?
AND bp.published = 1
ORDER BY a.ctime DESC
LIMIT ? OFFSET ?;", array($id, $limit, $offset));
LIMIT ? OFFSET ?;", array($id, $limit, $offset)))
|| ($postids = array());
$posts = array();
foreach($postids as $postid) {
......@@ -458,7 +469,13 @@ class ArtefactTypeBlogPost extends ArtefactType {
);
}
$count = (int)get_field('artefact', 'COUNT(*)', 'parent', $id);
$count = (int)get_field_sql("
SELECT COUNT(*)
FROM " . get_config('dbprefix') . "artefact a
LEFT OUTER JOIN " . get_config('dbprefix') . "artefact_blog_blogpost bp
ON a.id = bp.blogpost
WHERE a.parent = ?
AND bp.published = 1", array($id));
return array($count, $posts);
}
......
......@@ -55,7 +55,7 @@ $form = pieform(array(
),
'description' => array(
'type' => 'wysiwyg',
'rows' => 5,
'rows' => 10,
'cols' => 80,
'title' => get_string('postbody', 'artefact.blog'),
'description' => get_string('postbodydesc', 'artefact.blog'),
......
......@@ -37,6 +37,15 @@ $id = param_integer('id');
list($count, $data) = ArtefactTypeBlogPost::render_posts(FORMAT_ARTEFACT_LISTSELF, $id, $limit, $offset);
if (!$count) {
$count = 1;
$data = array(
array(
'content' => get_string('noresults', 'artefact.blog')
)
);
}
echo json_encode(array(
'count' => $count,
'limit' => $limit,
......
<?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 Alastair Pharo <alastair@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
$enc_wwwroot = json_encode(get_config('wwwroot'));
$enc_id = json_encode($this->id);
return <<<EOJAVASCRIPT
var blog_renderfull{$blockid} = new TableRenderer(
'blog_renderfull{$blockid}',
{$enc_wwwroot} + 'artefact/blog/render/blog_renderfull.json.php',
[
function(r) {
var td = TD();
td.innerHTML = r.content;
return td;
}
]
);
blog_renderfull{$blockid}.statevars.push('id');
blog_renderfull{$blockid}.id = {$enc_id};
blog_renderfull{$blockid}.updateOnLoad();
alert('hi');
EOJAVASCRIPT;
?>
<?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 Alastair Pharo <alastair@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(dirname(__FILE__)))) . '/init.php');
safe_require('artefact', 'blog');
json_headers();
$limit = param_integer('limit', ArtefactTypeBlog::pagination);
$offset = param_integer('offset', 0);
$id = param_integer('id');
list($count, $data) = ArtefactTypeBlogPost::render_posts(FORMAT_ARTEFACT_RENDERFULL, $id, $limit, $offset);
if (!$count) {
$count = 1;
$data = array(
array(
'content' => get_string('noresults', 'artefact.blog')
)
);
}
echo json_encode(array(
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'data' => $data
));
?>
......@@ -6,6 +6,8 @@
{$javascript}
</script>
<h2>{$artefact->get('title')|escape}</h2>
<table id="blog_listchildren{$blockid}">
<thead></thead>
<tbody></tbody>
......
{**
* This smarty template renders the blog in full. This is currently a complete
* list of complete blog posts.
* This smarty template renders a list of a blog's children.
*}
<ul>
{foreach from=$children item=child}
<li>{$child->render(FORMAT_ARTEFACT_RENDERFULL, $options)}</li>
{/foreach}
</ul>
<script type="text/javascript">
{$javascript}
</script>
<h2>{$artefact->get('title')|escape}</h2>
<table id="blog_renderfull{$blockid}">
<thead></thead>
<tbody></tbody>
</table>
......@@ -3,5 +3,5 @@
*}
<div>
<span>{$artefact->get('title')|escape}</span>
<span>{$artefact->get('description')}</span>
<div>{$artefact->get('description')}</div>
</div>
......@@ -2,6 +2,6 @@
* This template displays a blog post.
*}
<div>
<span>{$artefact->get('title')|escape}</span>
<span>{$artefact->get('description')|escape}</span>
<h3>{$artefact->get('title')|escape}</h3>
<div>{$artefact->get('description')}</div>
</div>
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