From 730d28c53b5183933fda0f36b67fbca69695d7d1 Mon Sep 17 00:00:00 2001 From: Nicolas Connault Date: Fri, 30 Oct 2009 07:27:02 +0000 Subject: [PATCH] MDL-19685 Upgraded blog_tags block so that it displays course-associated or module-associated tags on the appropriate pages --- blocks/blog_tags/block_blog_tags.php | 41 +++++++++++++++++++--------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/blocks/blog_tags/block_blog_tags.php b/blocks/blog_tags/block_blog_tags.php index 8dfbab78f7..635856ba70 100644 --- a/blocks/blog_tags/block_blog_tags.php +++ b/blocks/blog_tags/block_blog_tags.php @@ -43,6 +43,9 @@ class block_blog_tags extends block_base { if (empty($CFG->usetags) || empty($CFG->bloglevel)) { $this->content->text = ''; + if ($this->page->user_is_editing()) { + $this->content->text = get_string('tagsaredisabled', 'tag'); + } return $this->content; } @@ -64,9 +67,10 @@ class block_blog_tags extends block_base { $this->content->text = ''; $this->content->footer = ''; - /// Get a list of tags - + /// Get a list of tags $timewithin = time() - $this->config->timewithin * 24 * 60 * 60; /// convert to seconds + + $blogheaders = blog_get_headers(); // admins should be able to read all tags $type = ''; @@ -75,11 +79,21 @@ class block_blog_tags extends block_base { } $sql = "SELECT t.id, t.tagtype, t.rawname, t.name, COUNT(DISTINCT ti.id) AS ct - FROM {tag} t, {tag_instance} ti, {post} p + FROM {tag} t, {tag_instance} ti, {post} p, {blog_association} ba WHERE t.id = ti.tagid AND p.id = ti.itemid $type AND ti.itemtype = 'post' - AND ti.timemodified > $timewithin + AND ti.timemodified > $timewithin"; + + if (!empty($blogheaders['filters']['module'])) { + $modulecontext = get_context_instance(CONTEXT_MODULE, $blogheaders['filters']['module']); + $sql .= " AND ba.contextid = $modulecontext->id AND p.id = ba.blogid "; + } else if (!empty($blogheaders['filters']['course'])) { + $coursecontext = get_context_instance(CONTEXT_COURSE, $blogheaders['filters']['course']); + $sql .= " AND ba.contextid = $coursecontext->id AND p.id = ba.blogid "; + } + + $sql .= " GROUP BY t.id, t.tagtype, t.name, t.rawname ORDER BY ct DESC, t.name ASC"; @@ -122,24 +136,25 @@ class block_blog_tags extends block_base { /// Accessibility: markup as a list. $this->content->text .= "\n