diff -Naur moodle-git/tag/index.php my-moodle-git/tag/index.php --- moodle-git/tag/index.php 2011-04-15 11:46:55.039450400 +0200 +++ my-moodle-git/tag/index.php 2011-04-15 16:21:45.009814000 +0200 @@ -93,13 +93,62 @@ tag_print_management_box($tag); tag_print_description_box($tag); -echo '
'; +// Determine if Courses, Blogs and/or Users will be shown +// defines $courses, $blogs and $usercount which are used in the display code below +$hasCourses = false; +$hasBlogs = false; +$hasUsers = false; -// Display courses tagged with the tag +// Check and store $courses require_once($CFG->dirroot.'/tag/coursetagslib.php'); if ($courses = coursetag_get_tagged_courses($tag->id)) { + $hasCourses = true; +} + +// Check and store $blogs +if (has_capability('moodle/blog:view', $systemcontext)) { + require_once($CFG->dirroot.'/blog/lib.php'); + require_once($CFG->dirroot.'/blog/locallib.php'); + + $bloglisting = new blog_listing(array('tag' => $tag->id)); + $limit = 10; + $start = 0; + + $hasBlogs = ($blogs = $bloglisting->get_entries($start, $limit)); +} + +// Check and store $usercount +$usercount = tag_record_count('user', $tag->id); +$hasUsers = ($usercount > 0); + +// Only include 's to those anchors that actually will be shown +$relatedpagesLink = ""; +$countAnchors = 0; +if ($hasCourses) { + $relatedpagesLink = ''.get_string('courses'). ''; + $countAnchors++; +} +if ($hasBlogs) { + if ($countAnchors > 0) { + $relatedpagesLink = $relatedpagesLink.' | '; + } + $relatedpagesLink = $relatedpagesLink.''.get_string('relatedblogs', 'tag').''; + $countAnchors++; +} +if ($hasUsers) { + if ($countAnchors > 0) { + $relatedpagesLink = $relatedpagesLink.' | '; + } + $relatedpagesLink = $relatedpagesLink.''.get_string('users').''; +} + +// If only one anchor is present, no is needed +if ($countAnchors > 1) { + echo ''; +} + +// Display courses tagged with the tag +if ($courses) { $totalcount = count( $courses ); echo $OUTPUT->box_start('generalbox', 'tag-blogs'); //could use an id separate from tag-blogs, but would have to copy the css style to make it look the same @@ -117,14 +166,8 @@ // Print up to 10 previous blogs entries if (has_capability('moodle/blog:view', $systemcontext)) { - require_once($CFG->dirroot.'/blog/lib.php'); - require_once($CFG->dirroot.'/blog/locallib.php'); - - $bloglisting = new blog_listing(array('tag' => $tag->id)); - $limit = 10; - $start = 0; - - if ($blogs = $bloglisting->get_entries($start, $limit)) { + // just to be safe, recheck if $blogs is set above + if (isset($blogs) && $blogs) { echo $OUTPUT->box_start('generalbox', 'tag-blogs'); $heading = get_string('relatedblogs', 'tag', $tagname). ' ' . get_string('taggedwith', 'tag', $tagname); @@ -158,7 +201,6 @@ } } -$usercount = tag_record_count('user', $tag->id); if ($usercount > 0) { //user table box @@ -176,4 +218,4 @@ echo $OUTPUT->box_end(); } -echo $OUTPUT->footer(); +echo $OUTPUT->footer(); \ No newline at end of file