MDL-19676 MDL-14408 MDL-8776 Blog improvements
[moodle.git] / tag / index.php
CommitLineData
c933a060 1<?php // $Id$
2
3require_once('../config.php');
4require_once('lib.php');
48d56528 5require_once('locallib.php');
c933a060 6require_once($CFG->dirroot.'/lib/weblib.php');
8a275c72 7require_once($CFG->dirroot.'/blog/lib.php');
c933a060 8
9require_login();
10
11if (empty($CFG->usetags)) {
48d56528 12 print_error('tagsaredisabled', 'tag');
c933a060 13}
14
3d535996 15$tagid = optional_param('id', 0, PARAM_INT); // tag id
38fb8190 16$tagname = optional_param('tag', '', PARAM_TAG); // tag
8479c2e0 17
5557c75a 18$edit = optional_param('edit', -1, PARAM_BOOL);
3d535996 19$userpage = optional_param('userpage', 0, PARAM_INT); // which page to show
5557c75a 20$perpage = optional_param('perpage', 24, PARAM_INT);
c933a060 21
0edd6535 22$systemcontext = get_context_instance(CONTEXT_SYSTEM);
8479c2e0 23
24if ($tagname) {
25 $tag = tag_get('name', $tagname, '*');
26} else if ($tagid) {
27 $tag = tag_get('id', $tagid, '*');
28}
29
30if (empty($tag)) {
c933a060 31 redirect($CFG->wwwroot.'/tag/search.php');
32}
33
ad52c04f 34$PAGE->set_url('tag/index.php', array('id' => $tag->id));
f8b80dbd 35$PAGE->set_subpage($tag->id);
0edd6535 36$PAGE->set_context($systemcontext);
cfcfb9f3 37$PAGE->set_blocks_editing_capability('moodle/tag:editblocks');
5557c75a 38
39if (($edit != -1) and $PAGE->user_allowed_editing()) {
40 $USER->editing = $edit;
41}
42
f8b80dbd 43$tagname = tag_display_name($tag);
f8b80dbd 44$title = get_string('tag', 'tag') .' - '. $tagname;
45
46$button = '';
47if ($PAGE->user_allowed_editing() ) {
cf132980 48 $button = $OUTPUT->edit_button(new moodle_url("$CFG->wwwroot/tag/index.php", array('id' => $tagid)));
f8b80dbd 49}
968583af 50
51$PAGE->navbar->add(get_string('tags', 'tag'), new moodle_url($CFG->wwwroot.'/tag/search.php'));
52$PAGE->navbar->add($tagname);
53$PAGE->set_title($title);
54$PAGE->set_button($button);
55echo $OUTPUT->header();
5557c75a 56
03ce38cd 57// Manage all tags links
58if (has_capability('moodle/tag:manage', $systemcontext)) {
59 echo '<div class="managelink"><a href="'. $CFG->wwwroot .'/tag/manage.php">'. get_string('managetags', 'tag') .'</a></div>' ;
60}
61
5557c75a 62$tagname = tag_display_name($tag);
c933a060 63
c933a060 64if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
28f64040 65 $tagname = '<span class="flagged-tag">' . $tagname . '</span>';
c933a060 66}
67
73aec3a7 68echo $OUTPUT->heading($tagname, 2, 'headingblock header tag-heading');
3d535996 69tag_print_management_box($tag);
70tag_print_description_box($tag);
c933a060 71
3caea5dc 72echo '<div style="text-align: center "><p><a href="#course">'.get_string('courses').
73 '</a> | <a href="#blog">'.get_string('relatedblogs', 'tag').
74 '</a> | <a href="#user">'.get_string('users').'</a></p></div>';
75
38fb8190 76// Display courses tagged with the tag
77require_once($CFG->dirroot.'/tag/coursetagslib.php');
78if ($courses = coursetag_get_tagged_courses($tag->id)) {
c933a060 79
38fb8190 80 $totalcount = count( $courses );
456d32fd 81 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
6cbf4bd4 82
3caea5dc 83 $heading = get_string('courses') . ' ' . get_string('taggedwith', 'tag', $tagname) .': '. $totalcount;
84 echo "<a name='course'></a>";
73aec3a7 85 echo $OUTPUT->heading($heading, 3);
5557c75a 86
38fb8190 87 foreach ($courses as $course) {
88 print_course($course);
89 }
c933a060 90
456d32fd 91 echo $OUTPUT->box_end();
c933a060 92}
c933a060 93
38fb8190 94// Print up to 10 previous blogs entries
1c7b8b93
NC
95if (has_capability('moodle/blog:view', $systemcontext)) {
96 require_once($CFG->dirroot.'/blog/lib.php');
97 require_once($CFG->dirroot.'/blog/locallib.php');
061f14b2 98
1c7b8b93
NC
99 $bloglisting = new blog_listing(array('tag' => $tag->id));
100 $limit = 10;
101 $start = 0;
b55d5f76 102
1c7b8b93 103 if ($blogs = $bloglisting->get_entries($start, $limit)) {
b55d5f76 104
456d32fd 105 echo $OUTPUT->box_start('generalbox', 'tag-blogs');
3caea5dc 106 $heading = get_string('relatedblogs', 'tag', $tagname). ' ' . get_string('taggedwith', 'tag', $tagname);
107 echo "<a name='blog'></a>";
73aec3a7 108 echo $OUTPUT->heading($heading, 3);
b55d5f76 109
110 echo '<ul id="tagblogentries">';
111 foreach ($blogs as $blog) {
112 if ($blog->publishstate == 'draft') {
113 $class = 'class="dimmed"';
114 } else {
115 $class = '';
116 }
117 echo '<li '.$class.'>';
1c7b8b93 118 echo '<a '.$class.' href="'.$CFG->wwwroot.'/blog/index.php?entryid='.$blog->id.'">';
b55d5f76 119 echo format_string($blog->subject);
120 echo '</a>';
38fb8190 121 echo ' - ';
b55d5f76 122 echo '<a '.$class.' href="'.$CFG->wwwroot.'/user/view.php?id='.$blog->userid.'">';
123 echo fullname($blog);
124 echo '</a>';
125 echo ', '. userdate($blog->lastmodified);
126 echo '</li>';
53bde3e1 127 }
b55d5f76 128 echo '</ul>';
5557c75a 129
1c7b8b93
NC
130 $allblogsurl = new moodle_url($CFG->wwwroot.'/blog/index.php', array('tagid' => $tag->id));
131 echo '<p class="moreblogs"><a href="'.$allblogsurl->out().'">'.get_string('seeallblogs', 'tag', $tagname).'</a></p>';
44842cc6 132
456d32fd 133 echo $OUTPUT->box_end();
b55d5f76 134 }
061f14b2 135}
01d0a971 136
38fb8190 137$usercount = tag_record_count('user', $tag->id);
138if ($usercount > 0) {
061f14b2 139
38fb8190 140 //user table box
456d32fd 141 echo $OUTPUT->box_start('generalbox', 'tag-user-table');
5557c75a 142
3caea5dc 143 $heading = get_string('users'). ' ' . get_string('taggedwith', 'tag', $tagname) . ': ' . $usercount;
144 echo "<a name='user'></a>";
73aec3a7 145 echo $OUTPUT->heading($heading, 3);
38fb8190 146
928a93da 147 $baseurl = new moodle_url($CFG->wwwroot.'/tag/index.php', array('id' => $tag->id));
148 $pagingbar = moodle_paging_bar::make($totalcount, $page, $perpage, $baseurl);
149 $pagingbar->pagevar = 'userpage';
150 echo $OUTPUT->paging_bar($pagingbar);
38fb8190 151 tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
456d32fd 152 echo $OUTPUT->box_end();
38fb8190 153}
154
1dd2ba54 155echo $OUTPUT->footer();
c933a060 156?>