2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
21 * @copyright 2007 Luiz Cruz <luiz.laydner@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once('../config.php');
26 require_once('lib.php');
27 require_once('locallib.php');
28 require_once($CFG->dirroot
.'/lib/weblib.php');
29 require_once($CFG->dirroot
.'/blog/lib.php');
33 if (empty($CFG->usetags
)) {
34 print_error('tagsaredisabled', 'tag');
37 $tagid = optional_param('id', 0, PARAM_INT
); // tag id
38 $tagname = optional_param('tag', '', PARAM_TAG
); // tag
40 $edit = optional_param('edit', -1, PARAM_BOOL
);
41 $userpage = optional_param('userpage', 0, PARAM_INT
); // which page to show
42 $perpage = optional_param('perpage', 24, PARAM_INT
);
44 $systemcontext = get_context_instance(CONTEXT_SYSTEM
);
47 $tag = tag_get('name', $tagname, '*');
49 $tag = tag_get('id', $tagid, '*');
53 redirect($CFG->wwwroot
.'/tag/search.php');
56 $PAGE->set_url('/tag/index.php', array('id' => $tag->id
));
57 $PAGE->set_subpage($tag->id
);
58 $PAGE->set_context($systemcontext);
59 $PAGE->set_pagelayout('standard');
60 $PAGE->set_blocks_editing_capability('moodle/tag:editblocks');
62 if (($edit != -1) and $PAGE->user_allowed_editing()) {
63 $USER->editing
= $edit;
66 $tagname = tag_display_name($tag);
67 $title = get_string('tag', 'tag') .' - '. $tagname;
70 if ($PAGE->user_allowed_editing() ) {
71 $button = $OUTPUT->edit_button(new moodle_url("$CFG->wwwroot/tag/index.php", array('id' => $tag->id
)));
74 $PAGE->navbar
->add(get_string('tags', 'tag'), new moodle_url('/tag/search.php'));
75 $PAGE->navbar
->add($tagname);
76 $PAGE->set_title($title);
77 $PAGE->set_heading($COURSE->fullname
);
78 $PAGE->set_button($button);
79 echo $OUTPUT->header();
81 // Manage all tags links
82 if (has_capability('moodle/tag:manage', $systemcontext)) {
83 echo '<div class="managelink"><a href="'. $CFG->wwwroot
.'/tag/manage.php">'. get_string('managetags', 'tag') .'</a></div>' ;
86 $tagname = tag_display_name($tag);
88 if ($tag->flag
> 0 && has_capability('moodle/tag:manage', $systemcontext)) {
89 $tagname = '<span class="flagged-tag">' . $tagname . '</span>';
92 echo $OUTPUT->heading($tagname, 2, 'headingblock header tag-heading');
93 tag_print_management_box($tag);
94 tag_print_description_box($tag);
95 // Check what type of results are avaialable
96 require_once($CFG->dirroot
.'/tag/coursetagslib.php');
97 $courses = coursetag_get_tagged_courses($tag->id
);
99 if (has_capability('moodle/blog:view', $systemcontext)) {
100 require_once($CFG->dirroot
.'/blog/lib.php');
101 require_once($CFG->dirroot
.'/blog/locallib.php');
103 $bloglisting = new blog_listing(array('tag' => $tag->id
));
106 $blogs = $bloglisting->get_entries($start, $limit);
108 $usercount = tag_record_count('user', $tag->id
);
110 // Only include <a href />'s to those anchors that actually will be shown
111 $relatedpageslink = "";
113 if (!empty($courses)) {
114 $relatedpageslink = '<a href="#course">'.get_string('courses').'</a>';
117 if (!empty($blogs)) {
118 if ($countanchors > 0) {
119 $relatedpageslink .= ' | ';
121 $relatedpageslink .= '<a href="#blog">'.get_string('relatedblogs', 'tag').'</a>';
124 if ($usercount > 0) {
125 if ($countanchors > 0) {
126 $relatedpageslink .= ' | ';
128 $relatedpageslink .= '<a href="#user">'.get_string('users').'</a>';
131 // If only one anchor is present, no <a href /> is needed
132 if ($countanchors == 0) {
133 echo '<div class="relatedpages"><p>'.get_string('noresultsfor', 'tag', $tagname).'</p></div>';
134 } elseif ($countanchors > 1) {
135 echo '<div class="relatedpages"><p>'.$relatedpageslink.'</p></div>';
138 // Display courses tagged with the tag
139 if (!empty($courses)) {
141 $totalcount = count( $courses );
142 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
144 $heading = get_string('courses') . ' ' . get_string('taggedwith', 'tag', $tagname) .': '. $totalcount;
145 echo "<a name='course'></a>";
146 echo $OUTPUT->heading($heading, 3);
148 foreach ($courses as $course) {
149 print_course($course);
152 echo $OUTPUT->box_end();
155 // Print up to 10 previous blogs entries
157 if (!empty($blogs)) {
158 echo $OUTPUT->box_start('generalbox', 'tag-blogs');
159 $heading = get_string('relatedblogs', 'tag', $tagname). ' ' . get_string('taggedwith', 'tag', $tagname);
160 echo "<a name='blog'></a>";
161 echo $OUTPUT->heading($heading, 3);
163 echo '<ul id="tagblogentries">';
164 foreach ($blogs as $blog) {
165 if ($blog->publishstate
== 'draft') {
166 $class = 'class="dimmed"';
170 echo '<li '.$class.'>';
171 echo '<a '.$class.' href="'.$CFG->wwwroot
.'/blog/index.php?entryid='.$blog->id
.'">';
172 echo format_string($blog->subject
);
175 echo '<a '.$class.' href="'.$CFG->wwwroot
.'/user/view.php?id='.$blog->userid
.'">';
176 echo fullname($blog);
178 echo ', '. userdate($blog->lastmodified
);
183 $allblogsurl = new moodle_url('/blog/index.php', array('tagid' => $tag->id
));
184 echo '<p class="moreblogs"><a href="'.$allblogsurl->out().'">'.get_string('seeallblogs', 'tag', $tagname).'</a></p>';
186 echo $OUTPUT->box_end();
189 if ($usercount > 0) {
192 echo $OUTPUT->box_start('generalbox', 'tag-user-table');
194 $heading = get_string('users'). ' ' . get_string('taggedwith', 'tag', $tagname) . ': ' . $usercount;
195 echo "<a name='user'></a>";
196 echo $OUTPUT->heading($heading, 3);
198 $baseurl = new moodle_url('/tag/index.php', array('id' => $tag->id
));
199 $pagingbar = new paging_bar($usercount, $userpage, $perpage, $baseurl);
200 $pagingbar->pagevar
= 'userpage';
201 echo $OUTPUT->render($pagingbar);
202 tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
203 echo $OUTPUT->box_end();
206 echo $OUTPUT->footer();