MDL-19235 Basic phpdocs and copyright statements for core_tag subsystem
[moodle.git] / tag / index.php
CommitLineData
6bfe7aac 1<?php
c933a060 2
000ebd5c
DM
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * @package core
20 * @subpackage tag
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
0edd6535 44$systemcontext = get_context_instance(CONTEXT_SYSTEM);
8479c2e0 45
46if ($tagname) {
47 $tag = tag_get('name', $tagname, '*');
48} else if ($tagid) {
49 $tag = tag_get('id', $tagid, '*');
50}
51
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);
cfcfb9f3 59$PAGE->set_blocks_editing_capability('moodle/tag:editblocks');
5557c75a 60
61if (($edit != -1) and $PAGE->user_allowed_editing()) {
62 $USER->editing = $edit;
63}
64
f8b80dbd 65$tagname = tag_display_name($tag);
f8b80dbd 66$title = get_string('tag', 'tag') .' - '. $tagname;
67
68$button = '';
69if ($PAGE->user_allowed_editing() ) {
cf132980 70 $button = $OUTPUT->edit_button(new moodle_url("$CFG->wwwroot/tag/index.php", array('id' => $tagid)));
f8b80dbd 71}
968583af 72
a6855934 73$PAGE->navbar->add(get_string('tags', 'tag'), new moodle_url('/tag/search.php'));
968583af 74$PAGE->navbar->add($tagname);
75$PAGE->set_title($title);
440e1f1a 76$PAGE->set_heading($COURSE->fullname);
968583af 77$PAGE->set_button($button);
78echo $OUTPUT->header();
5557c75a 79
03ce38cd 80// Manage all tags links
81if (has_capability('moodle/tag:manage', $systemcontext)) {
82 echo '<div class="managelink"><a href="'. $CFG->wwwroot .'/tag/manage.php">'. get_string('managetags', 'tag') .'</a></div>' ;
83}
84
5557c75a 85$tagname = tag_display_name($tag);
c933a060 86
c933a060 87if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
28f64040 88 $tagname = '<span class="flagged-tag">' . $tagname . '</span>';
c933a060 89}
90
73aec3a7 91echo $OUTPUT->heading($tagname, 2, 'headingblock header tag-heading');
3d535996 92tag_print_management_box($tag);
93tag_print_description_box($tag);
c933a060 94
90723839 95echo '<div class="relatedpages"><p><a href="#course">'.get_string('courses').
3caea5dc 96 '</a> | <a href="#blog">'.get_string('relatedblogs', 'tag').
97 '</a> | <a href="#user">'.get_string('users').'</a></p></div>';
98
38fb8190 99// Display courses tagged with the tag
100require_once($CFG->dirroot.'/tag/coursetagslib.php');
101if ($courses = coursetag_get_tagged_courses($tag->id)) {
c933a060 102
38fb8190 103 $totalcount = count( $courses );
456d32fd 104 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 105
3caea5dc 106 $heading = get_string('courses') . ' ' . get_string('taggedwith', 'tag', $tagname) .': '. $totalcount;
107 echo "<a name='course'></a>";
73aec3a7 108 echo $OUTPUT->heading($heading, 3);
5557c75a 109
38fb8190 110 foreach ($courses as $course) {
111 print_course($course);
4454447d 112 }
c933a060 113
456d32fd 114 echo $OUTPUT->box_end();
c933a060 115}
c933a060 116
38fb8190 117// Print up to 10 previous blogs entries
1c7b8b93
NC
118if (has_capability('moodle/blog:view', $systemcontext)) {
119 require_once($CFG->dirroot.'/blog/lib.php');
120 require_once($CFG->dirroot.'/blog/locallib.php');
061f14b2 121
1c7b8b93
NC
122 $bloglisting = new blog_listing(array('tag' => $tag->id));
123 $limit = 10;
124 $start = 0;
b55d5f76 125
1c7b8b93 126 if ($blogs = $bloglisting->get_entries($start, $limit)) {
b55d5f76 127
456d32fd 128 echo $OUTPUT->box_start('generalbox', 'tag-blogs');
3caea5dc 129 $heading = get_string('relatedblogs', 'tag', $tagname). ' ' . get_string('taggedwith', 'tag', $tagname);
130 echo "<a name='blog'></a>";
73aec3a7 131 echo $OUTPUT->heading($heading, 3);
b55d5f76 132
133 echo '<ul id="tagblogentries">';
134 foreach ($blogs as $blog) {
135 if ($blog->publishstate == 'draft') {
136 $class = 'class="dimmed"';
137 } else {
138 $class = '';
139 }
140 echo '<li '.$class.'>';
1c7b8b93 141 echo '<a '.$class.' href="'.$CFG->wwwroot.'/blog/index.php?entryid='.$blog->id.'">';
b55d5f76 142 echo format_string($blog->subject);
143 echo '</a>';
38fb8190 144 echo ' - ';
b55d5f76 145 echo '<a '.$class.' href="'.$CFG->wwwroot.'/user/view.php?id='.$blog->userid.'">';
146 echo fullname($blog);
147 echo '</a>';
148 echo ', '. userdate($blog->lastmodified);
149 echo '</li>';
53bde3e1 150 }
b55d5f76 151 echo '</ul>';
5557c75a 152
a6855934 153 $allblogsurl = new moodle_url('/blog/index.php', array('tagid' => $tag->id));
1c7b8b93 154 echo '<p class="moreblogs"><a href="'.$allblogsurl->out().'">'.get_string('seeallblogs', 'tag', $tagname).'</a></p>';
44842cc6 155
456d32fd 156 echo $OUTPUT->box_end();
b55d5f76 157 }
061f14b2 158}
01d0a971 159
38fb8190 160$usercount = tag_record_count('user', $tag->id);
161if ($usercount > 0) {
061f14b2 162
38fb8190 163 //user table box
456d32fd 164 echo $OUTPUT->box_start('generalbox', 'tag-user-table');
5557c75a 165
3caea5dc 166 $heading = get_string('users'). ' ' . get_string('taggedwith', 'tag', $tagname) . ': ' . $usercount;
167 echo "<a name='user'></a>";
73aec3a7 168 echo $OUTPUT->heading($heading, 3);
38fb8190 169
a6855934 170 $baseurl = new moodle_url('/tag/index.php', array('id' => $tag->id));
929d7a83 171 $pagingbar = new paging_bar($usercount, $userpage, $perpage, $baseurl);
928a93da 172 $pagingbar->pagevar = 'userpage';
929d7a83 173 echo $OUTPUT->render($pagingbar);
38fb8190 174 tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
456d32fd 175 echo $OUTPUT->box_end();
38fb8190 176}
177
1dd2ba54 178echo $OUTPUT->footer();