MDL-50550 wiki: Added unit tests for mod_wiki_get_wikis_by_courses
[moodle.git] / tag / index.php
CommitLineData
6bfe7aac 1<?php
000ebd5c
DM
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.
13//
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/>.
16
bcdcee90 17
000ebd5c 18/**
bcdcee90
GGC
19 * @package core_tag
20 * @category tag
000ebd5c
DM
21 * @copyright 2007 Luiz Cruz <luiz.laydner@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
c933a060 25require_once('../config.php');
26require_once('lib.php');
48d56528 27require_once('locallib.php');
c933a060 28require_once($CFG->dirroot.'/lib/weblib.php');
8a275c72 29require_once($CFG->dirroot.'/blog/lib.php');
c933a060 30
31require_login();
32
33if (empty($CFG->usetags)) {
48d56528 34 print_error('tagsaredisabled', 'tag');
c933a060 35}
36
3d535996 37$tagid = optional_param('id', 0, PARAM_INT); // tag id
38fb8190 38$tagname = optional_param('tag', '', PARAM_TAG); // tag
8479c2e0 39
5557c75a 40$edit = optional_param('edit', -1, PARAM_BOOL);
3d535996 41$userpage = optional_param('userpage', 0, PARAM_INT); // which page to show
5557c75a 42$perpage = optional_param('perpage', 24, PARAM_INT);
c933a060 43
43731030 44$systemcontext = context_system::instance();
8479c2e0 45
46if ($tagname) {
47 $tag = tag_get('name', $tagname, '*');
48} else if ($tagid) {
49 $tag = tag_get('id', $tagid, '*');
50}
75258256 51unset($tagid);
8479c2e0 52if (empty($tag)) {
c933a060 53 redirect($CFG->wwwroot.'/tag/search.php');
54}
55
a6855934 56$PAGE->set_url('/tag/index.php', array('id' => $tag->id));
f8b80dbd 57$PAGE->set_subpage($tag->id);
0edd6535 58$PAGE->set_context($systemcontext);
4e1f6047
DW
59$tagnode = $PAGE->navigation->find('tags', null);
60$tagnode->make_active();
8d873bdc 61$PAGE->set_pagelayout('standard');
cfcfb9f3 62$PAGE->set_blocks_editing_capability('moodle/tag:editblocks');
5557c75a 63
64if (($edit != -1) and $PAGE->user_allowed_editing()) {
65 $USER->editing = $edit;
66}
67
f8b80dbd 68$tagname = tag_display_name($tag);
f8b80dbd 69$title = get_string('tag', 'tag') .' - '. $tagname;
70
71$button = '';
72if ($PAGE->user_allowed_editing() ) {
75258256 73 $button = $OUTPUT->edit_button(new moodle_url("$CFG->wwwroot/tag/index.php", array('id' => $tag->id)));
f8b80dbd 74}
968583af 75
968583af 76$PAGE->navbar->add($tagname);
77$PAGE->set_title($title);
440e1f1a 78$PAGE->set_heading($COURSE->fullname);
968583af 79$PAGE->set_button($button);
9e76429d 80$courserenderer = $PAGE->get_renderer('core', 'course');
968583af 81echo $OUTPUT->header();
5557c75a 82
03ce38cd 83// Manage all tags links
84if (has_capability('moodle/tag:manage', $systemcontext)) {
85 echo '<div class="managelink"><a href="'. $CFG->wwwroot .'/tag/manage.php">'. get_string('managetags', 'tag') .'</a></div>' ;
86}
87
5557c75a 88$tagname = tag_display_name($tag);
c933a060 89
c933a060 90if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
28f64040 91 $tagname = '<span class="flagged-tag">' . $tagname . '</span>';
c933a060 92}
93
faf6010b 94echo $OUTPUT->heading($tagname, 2);
3d535996 95tag_print_management_box($tag);
96tag_print_description_box($tag);
5c333af0 97// Check what type of results are avaialable
9e76429d 98$courses = $courserenderer->tagged_courses($tag->id);
5c333af0 99
0388a38e 100if (!empty($CFG->enableblogs) && has_capability('moodle/blog:view', $systemcontext)) {
5c333af0
AA
101 require_once($CFG->dirroot.'/blog/lib.php');
102 require_once($CFG->dirroot.'/blog/locallib.php');
103
104 $bloglisting = new blog_listing(array('tag' => $tag->id));
105 $limit = 10;
106 $start = 0;
107 $blogs = $bloglisting->get_entries($start, $limit);
108}
109$usercount = tag_record_count('user', $tag->id);
c933a060 110
5c333af0
AA
111// Only include <a href />'s to those anchors that actually will be shown
112$relatedpageslink = "";
113$countanchors = 0;
114if (!empty($courses)) {
115 $relatedpageslink = '<a href="#course">'.get_string('courses').'</a>';
116 $countanchors++;
117}
118if (!empty($blogs)) {
119 if ($countanchors > 0) {
120 $relatedpageslink .= ' | ';
121 }
122 $relatedpageslink .= '<a href="#blog">'.get_string('relatedblogs', 'tag').'</a>';
123 $countanchors++;
124}
125if ($usercount > 0) {
126 if ($countanchors > 0) {
127 $relatedpageslink .= ' | ';
128 }
129 $relatedpageslink .= '<a href="#user">'.get_string('users').'</a>';
130 $countanchors++;
131}
132// If only one anchor is present, no <a href /> is needed
133if ($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>';
137}
3caea5dc 138
38fb8190 139// Display courses tagged with the tag
5c333af0 140if (!empty($courses)) {
c933a060 141
456d32fd 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
6cbf4bd4 143
3caea5dc 144 echo "<a name='course'></a>";
9e76429d 145 echo $courses;
c933a060 146
456d32fd 147 echo $OUTPUT->box_end();
c933a060 148}
c933a060 149
38fb8190 150// Print up to 10 previous blogs entries
061f14b2 151
5c333af0 152if (!empty($blogs)) {
c257dfc5
SH
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);
157
158 echo '<ul id="tagblogentries">';
159 foreach ($blogs as $blog) {
160 if ($blog->publishstate == 'draft') {
161 $class = 'class="dimmed"';
162 } else {
163 $class = '';
164 }
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>';
175 }
176 echo '</ul>';
177
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>';
180
181 echo $OUTPUT->box_end();
061f14b2 182}
01d0a971 183
38fb8190 184if ($usercount > 0) {
061f14b2 185
38fb8190 186 //user table box
456d32fd 187 echo $OUTPUT->box_start('generalbox', 'tag-user-table');
5557c75a 188
3caea5dc 189 $heading = get_string('users'). ' ' . get_string('taggedwith', 'tag', $tagname) . ': ' . $usercount;
190 echo "<a name='user'></a>";
73aec3a7 191 echo $OUTPUT->heading($heading, 3);
38fb8190 192
a6855934 193 $baseurl = new moodle_url('/tag/index.php', array('id' => $tag->id));
929d7a83 194 $pagingbar = new paging_bar($usercount, $userpage, $perpage, $baseurl);
928a93da 195 $pagingbar->pagevar = 'userpage';
929d7a83 196 echo $OUTPUT->render($pagingbar);
38fb8190 197 tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
456d32fd 198 echo $OUTPUT->box_end();
38fb8190 199}
200
1dd2ba54 201echo $OUTPUT->footer();