Commit 3cc2fc99 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add comments on html artefacts (bug #736665)



Let the owner enable comments at the artefact level.  If a textbox
contains an artefact which allows comments, add a comments link at
the bottom of the block to the artefact page where users can view
and leave comments.

Change-Id: I4428db947cbee987d5ce55f8062ce4b7c30b0239
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 0b1f7264
......@@ -364,7 +364,7 @@ class ArtefactTypeComment extends ArtefactType {
return $result;
}
public static function count_comments(&$viewids=null, &$artefactids=null) {
public static function count_comments($viewids=null, $artefactids=null) {
if (!empty($viewids)) {
return get_records_sql_assoc('
SELECT c.onview, COUNT(c.artefact) AS comments
......
......@@ -43,10 +43,30 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
public static function render_instance(BlockInstance $instance, $editing=false) {
$configdata = $instance->get('configdata');
$text = !empty($configdata['artefactid']) ? $instance->get_artefact_instance($configdata['artefactid'])->get('description') : '';
safe_require('artefact', 'file');
$text = ArtefactTypeFolder::append_view_url($text, $instance->get('view'));
return clean_html($text);
if (!empty($configdata['artefactid'])) {
safe_require('artefact', 'file');
safe_require('artefact', 'comment');
$artefact = $instance->get_artefact_instance($configdata['artefactid']);
$viewid = $instance->get('view');
$text = ArtefactTypeFolder::append_view_url($artefact->get('description'), $viewid);
$smarty = smarty_core();
$smarty->assign('text', $text);
if ($artefact->get('allowcomments')) {
$commentcount = ArtefactTypeComment::count_comments(null, array($configdata['artefactid']));
$commentcount = isset($commentcount[$configdata['artefactid']]) ? $commentcount[$configdata['artefactid']]->comments : 0;
$artefacturl = get_config('wwwroot') . 'view/artefact.php?view=' . $viewid . '&artefact=' . $configdata['artefactid'];
$smarty->assign('artefacturl', $artefacturl);
$smarty->assign('commentcount', $commentcount);
}
return $smarty->fetch('blocktype:textbox:content.tpl');
}
return '';
}
/**
......
{$text|clean_html|safe}
{if $commentcount || $commentcount === 0}
<div class="postdetails">
<a href="{$artefacturl}">{str tag=Comments section=artefact.comment} ({$commentcount})</a>
</div>
{/if}
......@@ -55,10 +55,16 @@ $form = pieform(array(
'elements' => array(
'description' => array(
'type' => 'wysiwyg',
'title' => get_string('Note', 'artefact.internal'),
'rows' => 10,
'cols' => 70,
'defaultvalue' => $artefact->get('description'),
),
'allowcomments' => array(
'type' => 'checkbox',
'title' => get_string('allowcomments', 'artefact.comment'),
'defaultvalue' => $artefact->get('allowcomments'),
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('save'), get_string('cancel')),
......@@ -75,6 +81,7 @@ $smarty->display('form.tpl');
function editnote_submit(Pieform $form, array $values) {
global $SESSION, $artefact, $goto;
$artefact->set('description', $values['description']);
$artefact->set('allowcomments', (int) $values['allowcomments']);
$artefact->commit();
$SESSION->add_ok_msg(get_string('noteupdated', 'artefact.internal'));
redirect($goto);
......
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