Skip to content

Commit

Permalink
MDL-2712 tags: removing the anchor links when there are no results
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitagarwal committed Mar 9, 2012
1 parent 5bbf3cb commit 5c333af
Showing 1 changed file with 72 additions and 45 deletions.
117 changes: 72 additions & 45 deletions tag/index.php
Expand Up @@ -92,14 +92,51 @@
echo $OUTPUT->heading($tagname, 2, 'headingblock header tag-heading'); echo $OUTPUT->heading($tagname, 2, 'headingblock header tag-heading');
tag_print_management_box($tag); tag_print_management_box($tag);
tag_print_description_box($tag); tag_print_description_box($tag);
// Check what type of results are avaialable
require_once($CFG->dirroot.'/tag/coursetagslib.php');
$courses = coursetag_get_tagged_courses($tag->id);

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;
$blogs = $bloglisting->get_entries($start, $limit);
}
$usercount = tag_record_count('user', $tag->id);


echo '<div class="relatedpages"><p><a href="#course">'.get_string('courses'). // Only include <a href />'s to those anchors that actually will be shown
'</a> | <a href="#blog">'.get_string('relatedblogs', 'tag'). $relatedpageslink = "";
'</a> | <a href="#user">'.get_string('users').'</a></p></div>'; $countanchors = 0;
if (!empty($courses)) {
$relatedpageslink = '<a href="#course">'.get_string('courses').'</a>';
$countanchors++;
}
if (!empty($blogs)) {
if ($countanchors > 0) {
$relatedpageslink .= ' | ';
}
$relatedpageslink .= '<a href="#blog">'.get_string('relatedblogs', 'tag').'</a>';
$countanchors++;
}
if ($usercount > 0) {
if ($countanchors > 0) {
$relatedpageslink .= ' | ';
}
$relatedpageslink .= '<a href="#user">'.get_string('users').'</a>';
$countanchors++;
}
// If only one anchor is present, no <a href /> is needed
if ($countanchors == 0) {
echo '<div class="relatedpages"><p>'.get_string('noresultsfor', 'tag', $tagname).'</p></div>';
} elseif ($countanchors > 1) {
echo '<div class="relatedpages"><p>'.$relatedpageslink.'</p></div>';
}


// Display courses tagged with the tag // Display courses tagged with the tag
require_once($CFG->dirroot.'/tag/coursetagslib.php'); if (!empty($courses)) {
if ($courses = coursetag_get_tagged_courses($tag->id)) {


$totalcount = count( $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 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
Expand All @@ -116,49 +153,39 @@
} }


// Print up to 10 previous blogs entries // 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)); if (!empty($blogs)) {
$limit = 10; echo $OUTPUT->box_start('generalbox', 'tag-blogs');
$start = 0; $heading = get_string('relatedblogs', 'tag', $tagname). ' ' . get_string('taggedwith', 'tag', $tagname);

echo "<a name='blog'></a>";
if ($blogs = $bloglisting->get_entries($start, $limit)) { echo $OUTPUT->heading($heading, 3);


echo $OUTPUT->box_start('generalbox', 'tag-blogs'); echo '<ul id="tagblogentries">';
$heading = get_string('relatedblogs', 'tag', $tagname). ' ' . get_string('taggedwith', 'tag', $tagname); foreach ($blogs as $blog) {
echo "<a name='blog'></a>"; if ($blog->publishstate == 'draft') {
echo $OUTPUT->heading($heading, 3); $class = 'class="dimmed"';

} else {
echo '<ul id="tagblogentries">'; $class = '';
foreach ($blogs as $blog) { }
if ($blog->publishstate == 'draft') { echo '<li '.$class.'>';
$class = 'class="dimmed"'; echo '<a '.$class.' href="'.$CFG->wwwroot.'/blog/index.php?entryid='.$blog->id.'">';
} else { echo format_string($blog->subject);
$class = ''; echo '</a>';
} echo ' - ';
echo '<li '.$class.'>'; echo '<a '.$class.' href="'.$CFG->wwwroot.'/user/view.php?id='.$blog->userid.'">';
echo '<a '.$class.' href="'.$CFG->wwwroot.'/blog/index.php?entryid='.$blog->id.'">'; echo fullname($blog);
echo format_string($blog->subject); echo '</a>';
echo '</a>'; echo ', '. userdate($blog->lastmodified);
echo ' - '; echo '</li>';
echo '<a '.$class.' href="'.$CFG->wwwroot.'/user/view.php?id='.$blog->userid.'">'; }
echo fullname($blog); echo '</ul>';
echo '</a>';
echo ', '. userdate($blog->lastmodified); $allblogsurl = new moodle_url('/blog/index.php', array('tagid' => $tag->id));
echo '</li>'; echo '<p class="moreblogs"><a href="'.$allblogsurl->out().'">'.get_string('seeallblogs', 'tag', $tagname).'</a></p>';
}
echo '</ul>'; echo $OUTPUT->box_end();

$allblogsurl = new moodle_url('/blog/index.php', array('tagid' => $tag->id));
echo '<p class="moreblogs"><a href="'.$allblogsurl->out().'">'.get_string('seeallblogs', 'tag', $tagname).'</a></p>';

echo $OUTPUT->box_end();
}
} }


$usercount = tag_record_count('user', $tag->id);
if ($usercount > 0) { if ($usercount > 0) {


//user table box //user table box
Expand Down

0 comments on commit 5c333af

Please sign in to comment.