Merge branch 'MDL-49143-28' of git://github.com/cameron1729/moodle into MOODLE_28_STABLE
[moodle.git] / tag / index.php
blobda4064d36ebafa7ccda0756aaee4cf2f342a59ad
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
18 /**
19 * @package core_tag
20 * @category tag
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');
31 require_login();
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 = context_system::instance();
46 if ($tagname) {
47 $tag = tag_get('name', $tagname, '*');
48 } else if ($tagid) {
49 $tag = tag_get('id', $tagid, '*');
51 unset($tagid);
52 if (empty($tag)) {
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;
69 $button = '';
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 $courserenderer = $PAGE->get_renderer('core', 'course');
80 echo $OUTPUT->header();
82 // Manage all tags links
83 if (has_capability('moodle/tag:manage', $systemcontext)) {
84 echo '<div class="managelink"><a href="'. $CFG->wwwroot .'/tag/manage.php">'. get_string('managetags', 'tag') .'</a></div>' ;
87 $tagname = tag_display_name($tag);
89 if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
90 $tagname = '<span class="flagged-tag">' . $tagname . '</span>';
93 echo $OUTPUT->heading($tagname, 2);
94 tag_print_management_box($tag);
95 tag_print_description_box($tag);
96 // Check what type of results are avaialable
97 require_once($CFG->dirroot.'/tag/coursetagslib.php');
98 $courses = $courserenderer->tagged_courses($tag->id);
100 if (!empty($CFG->enableblogs) && has_capability('moodle/blog:view', $systemcontext)) {
101 require_once($CFG->dirroot.'/blog/lib.php');
102 require_once($CFG->dirroot.'/blog/locallib.php');
104 $bloglisting = new blog_listing(array('tag' => $tag->id));
105 $limit = 10;
106 $start = 0;
107 $blogs = $bloglisting->get_entries($start, $limit);
109 $usercount = tag_record_count('user', $tag->id);
111 // Only include <a href />'s to those anchors that actually will be shown
112 $relatedpageslink = "";
113 $countanchors = 0;
114 if (!empty($courses)) {
115 $relatedpageslink = '<a href="#course">'.get_string('courses').'</a>';
116 $countanchors++;
118 if (!empty($blogs)) {
119 if ($countanchors > 0) {
120 $relatedpageslink .= ' | ';
122 $relatedpageslink .= '<a href="#blog">'.get_string('relatedblogs', 'tag').'</a>';
123 $countanchors++;
125 if ($usercount > 0) {
126 if ($countanchors > 0) {
127 $relatedpageslink .= ' | ';
129 $relatedpageslink .= '<a href="#user">'.get_string('users').'</a>';
130 $countanchors++;
132 // If only one anchor is present, no <a href /> is needed
133 if ($countanchors == 0) {
134 echo '<div class="relatedpages"><p>'.get_string('noresultsfor', 'tag', $tagname).'</p></div>';
135 } elseif ($countanchors > 1) {
136 echo '<div class="relatedpages"><p>'.$relatedpageslink.'</p></div>';
139 // Display courses tagged with the tag
140 if (!empty($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 echo "<a name='course'></a>";
145 echo $courses;
147 echo $OUTPUT->box_end();
150 // Print up to 10 previous blogs entries
152 if (!empty($blogs)) {
153 echo $OUTPUT->box_start('generalbox', 'tag-blogs');
154 $heading = get_string('relatedblogs', 'tag', $tagname). ' ' . get_string('taggedwith', 'tag', $tagname);
155 echo "<a name='blog'></a>";
156 echo $OUTPUT->heading($heading, 3);
158 echo '<ul id="tagblogentries">';
159 foreach ($blogs as $blog) {
160 if ($blog->publishstate == 'draft') {
161 $class = 'class="dimmed"';
162 } else {
163 $class = '';
165 echo '<li '.$class.'>';
166 echo '<a '.$class.' href="'.$CFG->wwwroot.'/blog/index.php?entryid='.$blog->id.'">';
167 echo format_string($blog->subject);
168 echo '</a>';
169 echo ' - ';
170 echo '<a '.$class.' href="'.$CFG->wwwroot.'/user/view.php?id='.$blog->userid.'">';
171 echo fullname($blog);
172 echo '</a>';
173 echo ', '. userdate($blog->lastmodified);
174 echo '</li>';
176 echo '</ul>';
178 $allblogsurl = new moodle_url('/blog/index.php', array('tagid' => $tag->id));
179 echo '<p class="moreblogs"><a href="'.$allblogsurl->out().'">'.get_string('seeallblogs', 'tag', $tagname).'</a></p>';
181 echo $OUTPUT->box_end();
184 if ($usercount > 0) {
186 //user table box
187 echo $OUTPUT->box_start('generalbox', 'tag-user-table');
189 $heading = get_string('users'). ' ' . get_string('taggedwith', 'tag', $tagname) . ': ' . $usercount;
190 echo "<a name='user'></a>";
191 echo $OUTPUT->heading($heading, 3);
193 $baseurl = new moodle_url('/tag/index.php', array('id' => $tag->id));
194 $pagingbar = new paging_bar($usercount, $userpage, $perpage, $baseurl);
195 $pagingbar->pagevar = 'userpage';
196 echo $OUTPUT->render($pagingbar);
197 tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
198 echo $OUTPUT->box_end();
201 echo $OUTPUT->footer();