Commit 5e066eca authored by Robert Lyon's avatar Robert Lyon

Getting correct comment count for blocks (Bug #1393223)

The blog and textbox (notes) blocks return incorrect comment count if
there are private comments and the user is not allowed to see the
private comment.

Change-Id: I20f7f51ec2e948d37a09c5447340aab3bef31a13
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 81bfc0bc
...@@ -641,10 +641,10 @@ class ArtefactTypeBlogPost extends ArtefactType { ...@@ -641,10 +641,10 @@ class ArtefactTypeBlogPost extends ArtefactType {
$postcontent = ArtefactTypeFolder::append_view_url($postcontent, $options['viewid']); $postcontent = ArtefactTypeFolder::append_view_url($postcontent, $options['viewid']);
if (isset($options['countcomments']) && $this->allowcomments) { if (isset($options['countcomments']) && $this->allowcomments) {
safe_require('artefact', 'comment'); safe_require('artefact', 'comment');
$empty = array(); require_once(get_config('docroot') . 'lib/view.php');
$ids = array($this->id); $view = new View($options['viewid']);
$commentcount = ArtefactTypeComment::count_comments($empty, $ids); $comments = ArtefactTypeComment::get_comments(0, 0, null, $view, $this);
$smarty->assign('commentcount', $commentcount ? $commentcount[$this->id]->comments : 0); $smarty->assign('commentcount', isset($comments->count) ? $comments->count : 0);
} }
} }
$smarty->assign('artefactdescription', $postcontent); $smarty->assign('artefactdescription', $postcontent);
...@@ -801,13 +801,6 @@ class ArtefactTypeBlogPost extends ArtefactType { ...@@ -801,13 +801,6 @@ class ArtefactTypeBlogPost extends ArtefactType {
} }
} }
// Get comment counts
if (!empty($viewoptions['countcomments'])) {
safe_require('artefact', 'comment');
$viewids = array();
$commentcounts = ArtefactTypeComment::count_comments($viewids, array_keys($data));
}
foreach ($data as &$post) { foreach ($data as &$post) {
// Format dates properly // Format dates properly
if (is_null($viewoptions)) { if (is_null($viewoptions)) {
...@@ -818,8 +811,14 @@ class ArtefactTypeBlogPost extends ArtefactType { ...@@ -818,8 +811,14 @@ class ArtefactTypeBlogPost extends ArtefactType {
else { else {
$by = $post->author ? display_default_name($post->author) : $post->authorname; $by = $post->author ? display_default_name($post->author) : $post->authorname;
$post->postedby = get_string('postedbyon', 'artefact.blog', $by, format_date($post->ctime)); $post->postedby = get_string('postedbyon', 'artefact.blog', $by, format_date($post->ctime));
if (isset($commentcounts)) { // Get comment counts
$post->commentcount = isset($commentcounts[$post->id]) ? $commentcounts[$post->id]->comments : 0; if (!empty($viewoptions['countcomments'])) {
safe_require('artefact', 'comment');
require_once(get_config('docroot') . 'lib/view.php');
$view = new View($viewoptions['viewid']);
$artefact = artefact_instance_from_id($post->id);
$comments = ArtefactTypeComment::get_comments(0, 0, null, $view, $artefact);
$post->commentcount = isset($comments->count) ? $comments->count : 0;
} }
} }
$post->ctime = format_date($post->ctime, 'strftimedaydatetime'); $post->ctime = format_date($post->ctime, 'strftimedaydatetime');
......
...@@ -61,8 +61,10 @@ class PluginBlocktypeTextbox extends PluginBlocktype { ...@@ -61,8 +61,10 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
} }
if ($artefact->get('allowcomments')) { if ($artefact->get('allowcomments')) {
$commentcount = ArtefactTypeComment::count_comments(null, array($configdata['artefactid'])); require_once(get_config('docroot') . 'lib/view.php');
$commentcount = isset($commentcount[$configdata['artefactid']]) ? $commentcount[$configdata['artefactid']]->comments : 0; $view = new View($viewid);
$comments = ArtefactTypeComment::get_comments(0, 0, null, $view, $artefact);
$commentcount = isset($comments->count) ? $comments->count : 0;
$artefacturl = get_config('wwwroot') . 'artefact/artefact.php?view=' . $viewid . '&artefact=' . $configdata['artefactid']; $artefacturl = get_config('wwwroot') . 'artefact/artefact.php?view=' . $viewid . '&artefact=' . $configdata['artefactid'];
$smarty->assign('artefacturl', $artefacturl); $smarty->assign('artefacturl', $artefacturl);
$smarty->assign('commentcount', $commentcount); $smarty->assign('commentcount', $commentcount);
......
Markdown is supported
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