Commit d57dd580 authored by Chris Wharton's avatar Chris Wharton
Browse files

Enhance tagged posts block - show full entry or summary



Bug #1027736

Add functionality to show journal items in summary or in full

Change-Id: I112f0a9be5dc5a841376f68c734bb778cbd6d4d2
Signed-off-by: default avatarChris Wharton <chrisw@catalyst.net.nz>
parent 1dfb7028
......@@ -36,5 +36,9 @@ $string['taglist'] = 'My tags';
$string['notags'] = 'There are no posts tagged "%s"';
$string['notagsavailable'] = 'You have not created any tags';
$string['postedin'] = 'in';
$string['postedon'] = 'on';
$string['itemstoshow'] = 'Items to show';
$string['configerror'] = 'Error during block configuration';
$string['showjournalitemsinfull'] = 'Show journal items in full';
$string['showjournalitemsinfulldesc'] = 'If checked, the journal entries will be displayed. Otherwise only the titles of the journal entries will be shown.';
$string['tag'] = 'Tag';
......@@ -57,7 +57,8 @@ class PluginBlocktypeTaggedposts extends SystemBlocktype {
$configdata = $instance->get('configdata');
$view = $instance->get('view');
$limit = isset($configdata['count']) ? (int) $configdata['count'] : 10;
$results = '';
$full = isset($configdata['full']) ? $configdata['full'] : false;
$results = array();
$smarty = smarty_core();
$smarty->assign('view', $view);
......@@ -67,7 +68,7 @@ class PluginBlocktypeTaggedposts extends SystemBlocktype {
$tagselect = $configdata['tagselect'];
$sql =
'SELECT a.title, p.title AS parenttitle, a.id, a.parent, a.owner, at.tag
'SELECT a.title, p.title AS parenttitle, a.id, a.parent, a.owner, a.description, a.allowcomments, at.tag, a.ctime
FROM {artefact} a
JOIN {artefact} p ON a.parent = p.id
JOIN {artefact_blog_blogpost} ab ON (ab.blogpost = a.id AND ab.published = 1)
......@@ -108,6 +109,17 @@ class PluginBlocktypeTaggedposts extends SystemBlocktype {
foreach ($results as $result) {
$dataobject["artefact"] = $result->parent;
ensure_record_exists('view_artefact', $dataobject, $dataobject);
$result->postedbyon = get_string('postedbyon', 'artefact.blog', display_default_name($result->owner), format_date(strtotime($result->ctime)));
$result->displaydate= format_date(strtotime($result->ctime));
// get comment count for this post
$result->commentcount = count_records_select('artefact_comment_comment', "onartefact = {$result->id} AND private = 0 AND deletedby IS NULL");
// get all tags for this post
$taglist = get_records_array('artefact_tag', 'artefact', $result->id, "tag DESC");
foreach ($taglist as $t) {
$result->taglist[] = $t->tag;
}
}
// check if the user viewing the page is the owner of the selected tag
......@@ -125,6 +137,7 @@ class PluginBlocktypeTaggedposts extends SystemBlocktype {
return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl');
}
$smarty->assign('full', $full);
$smarty->assign('results', $results);
return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl');
}
......@@ -135,6 +148,7 @@ class PluginBlocktypeTaggedposts extends SystemBlocktype {
public static function instance_config_form($instance) {
global $USER;
$configdata = $instance->get('configdata');
$tags = get_records_sql_array("
......@@ -148,28 +162,35 @@ class PluginBlocktypeTaggedposts extends SystemBlocktype {
ORDER BY at.tag ASC
", array($USER->id));
$elements = array();
$options = array();
if (!empty($tags)) {
foreach ($tags as $tag) {
$options[$tag->tag] = $tag->tag;
}
return array(
'tagselect' => array(
'type' => 'select',
'title' => get_string('taglist','blocktype.blog/taggedposts'),
'options' => $options,
'defaultvalue' => !empty($configdata['tagselect']) ? $configdata['tagselect'] : $tags[0]->tag,
'required' => true,
),
'count' => array(
'type' => 'text',
'title' => get_string('itemstoshow', 'blocktype.blog/taggedposts'),
'description' => get_string('betweenxandy', 'mahara', 1, 100),
'defaultvalue' => isset($configdata['count']) ? $configdata['count'] : 10,
'size' => 3,
'rules' => array('integer' => true, 'minvalue' => 1, 'maxvalue' => 100),
),
$elements['tagselect'] = array(
'type' => 'select',
'title' => get_string('taglist','blocktype.blog/taggedposts'),
'options' => $options,
'defaultvalue' => !empty($configdata['tagselect']) ? $configdata['tagselect'] : $tags[0]->tag,
'required' => true,
);
$elements['count'] = array(
'type' => 'text',
'title' => get_string('itemstoshow', 'blocktype.blog/taggedposts'),
'description' => get_string('betweenxandy', 'mahara', 1, 100),
'defaultvalue' => isset($configdata['count']) ? $configdata['count'] : 10,
'size' => 3,
'rules' => array('integer' => true, 'minvalue' => 1, 'maxvalue' => 999),
);
$elements['full'] = array(
'type' => 'checkbox',
'title' => get_string('showjournalitemsinfull', 'blocktype.blog/taggedposts'),
'description' => get_string('showjournalitemsinfulldesc', 'blocktype.blog/taggedposts'),
'defaultvalue' => isset($configdata['full']) ? $configdata['full'] : false,
);
return $elements;
}
else {
return array(
......
{if ($editing)}
<div class="shortcut right nojs-hidden-block">
<div{if (count($blogs) == 1)} class="hidden"{/if}>
<span class="text">{str tag='shortcutaddpost' section='artefact.blog'}</span>
<select id="blogselect_{$blockid}" class="select">
{foreach from=$blogs item=blog}
<option value="{$blog->id}"> {$blog->title} </option>
{/foreach}
</select>
<input class="select" type="hidden" value="{$tagselect}">
<a class="shortcut btn">{str tag='shortcutgo' section='artefact.blog'}</a>
</div>
<a class="shortcut btn{if (count($blogs) != 1)} hidden{/if}">{str tag='shortcutnewentry' section='artefact.blog'}</a>
<div class="shortcut right nojs-hidden-block">
<div{if (count($blogs) == 1)} class="hidden"{/if}>
<span class="text">{str tag='shortcutaddpost' section='artefact.blog'}</span>
<select id="blogselect_{$blockid}" class="select">{foreach from=$blogs item=blog}<option value="{$blog->id}"> {$blog->title} </option>{/foreach}</select>
<input class="select" type="hidden" value="{$tagselect}">
<a class="shortcut btn">{str tag='shortcutgo' section='artefact.blog'}</a>
</div>
<a class="shortcut btn{if (count($blogs) != 1)} hidden{/if}">{str tag='shortcutnewentry' section='artefact.blog'}</a>
</div>
{/if}
{if $configerror}
{str tag='configerror' section='blocktype.blog/taggedposts'}
{elseif $badtag}
{str tag='notags' section='blocktype.blog/taggedposts' arg1=$badtag}
{else}
{str tag='blockheading' section='blocktype.blog/taggedposts'}
{if $viewowner}
<strong>{$tag}</strong> by <strong><a href="{profile_url($viewowner)}">{$viewowner|display_default_name}</a></strong>
{else}
<strong><a href="{$WWWROOT}tags.php?tag={$tag}&sort=name&type=text">{$tag}</a></strong>
{/if}
<ul class="taggedposts">
{str tag='blockheading' section='blocktype.blog/taggedposts'}
{if $viewowner}<strong>{$tag}</strong> by <strong><a href="{profile_url($viewowner)}">{$viewowner|display_name}</a></strong>
{else}<strong><a href="{$WWWROOT}tags.php?tag={$tag}&sort=name&type=text">{$tag}</a></strong>{/if}
{if $configerror}{str tag='configerror' section='blocktype.blog/taggedposts'}
{elseif $badtag}{str tag='notags' section='blocktype.blog/taggedposts' arg1=$badtag}
{elseif $full}
<div id="blogdescription">
<table id="postlist_{$blockid}" class="postlist"><tbody>
{foreach from=$results item=post}
<li>
<strong><a href="{$WWWROOT}view/artefact.php?artefact={$post->id}&view={$view}">{$post->title}</a></strong>
{str tag='postedin' section='blocktype.blog/taggedposts'}
{if $viewowner}
{$post->parenttitle}
{else}
<a href="{$WWWROOT}view/artefact.php?artefact={$post->parent}&view={$view}">{$post->parenttitle}</a>
{/if}
</li>
<tr><td>
<h3><a href="{$WWWROOT}view/artefact.php?artefact={$post->id}&view={$view}">{$post->title}</a></h3>
<div>{$post->description|clean_html|safe}
<p class="tags s"><label>{str tag=tags}:</label> {list_tags owner=$post->owner tags=$post->taglist}</p>
</div>
<div class="postdetails">{$post->postedbyon}
{if $post->allowcomments} | <a href="{$WWWROOT}view/artefact.php?artefact={$post->id}&view={$view}">{str tag=Comments section=artefact.comment} ({$post->commentcount})</a>{/if}</div>
</td></tr>
{/foreach}
</ul>
</tbody></table>
</div>
{else}<ul class="taggedposts">{foreach from=$results item=post}
<li>
<strong><a href="{$WWWROOT}view/artefact.php?artefact={$post->id}&view={$view}">{$post->title}</a></strong>
{str tag='postedin' section='blocktype.blog/taggedposts'}
{if $viewowner}{$post->parenttitle}
{else}<a href="{$WWWROOT}view/artefact.php?artefact={$post->parent}&view={$view}">{$post->parenttitle}</a>{/if}
{str tag='postedon' section='blocktype.blog/taggedposts'} <span class="description">{$post->displaydate}</span>
</li>
{/foreach}</ul>
{/if}
......@@ -28,5 +28,5 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2011092600;
$config->release = '1.0.1';
$config->version = 2012080600;
$config->release = '1.0.2';
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