MDL-50622 lang: Merge English strings from the en_fix language pack
[moodle.git] / tag / index.php
blob9636e1149fb6e38c29c0968e25fdc139e5c7cee9
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 $tagnode = $PAGE->navigation->find('tags', null);
60 $tagnode->make_active();
61 $PAGE->set_pagelayout('standard');
62 $PAGE->set_blocks_editing_capability('moodle/tag:editblocks');
64 if (($edit != -1) and $PAGE->user_allowed_editing()) {
65 $USER->editing = $edit;
68 $tagname = tag_display_name($tag);
69 $title = get_string('tag', 'tag') .' - '. $tagname;
71 $button = '';
72 if ($PAGE->user_allowed_editing() ) {
73 $button = $OUTPUT->edit_button(new moodle_url("$CFG->wwwroot/tag/index.php", array('id' => $tag->id)));
76 $PAGE->navbar->add($tagname);
77 $PAGE->set_title($title);
78 $PAGE->set_heading($COURSE->fullname);
79 $PAGE->set_button($button);
80 $courserenderer = $PAGE->get_renderer('core', 'course');
81 echo $OUTPUT->header();
83 // Manage all tags links
84 if (has_capability('moodle/tag:manage', $systemcontext)) {
85 echo '<div class="managelink"><a href="'. $CFG->wwwroot .'/tag/manage.php">'. get_string('managetags', 'tag') .'</a></div>' ;
88 $tagname = tag_display_name($tag);
90 if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
91 $tagname = '<span class="flagged-tag">' . $tagname . '</span>';
94 echo $OUTPUT->heading($tagname, 2);
95 tag_print_management_box($tag);
96 tag_print_description_box($tag);
97 // Check what type of results are avaialable
98 require_once($CFG->dirroot.'/tag/coursetagslib.php');
99 $courses = $courserenderer->tagged_courses($tag->id);
101 if (!empty($CFG->enableblogs) && has_capability('moodle/blog:view', $systemcontext)) {
102 require_once($CFG->dirroot.'/blog/lib.php');
103 require_once($CFG->dirroot.'/blog/locallib.php');
105 $bloglisting = new blog_listing(array('tag' => $tag->id));
106 $limit = 10;
107 $start = 0;
108 $blogs = $bloglisting->get_entries($start, $limit);
110 $usercount = tag_record_count('user', $tag->id);
112 // Only include <a href />'s to those anchors that actually will be shown
113 $relatedpageslink = "";
114 $countanchors = 0;
115 if (!empty($courses)) {
116 $relatedpageslink = '<a href="#course">'.get_string('courses').'</a>';
117 $countanchors++;
119 if (!empty($blogs)) {
120 if ($countanchors > 0) {
121 $relatedpageslink .= ' | ';
123 $relatedpageslink .= '<a href="#blog">'.get_string('relatedblogs', 'tag').'</a>';
124 $countanchors++;
126 if ($usercount > 0) {
127 if ($countanchors > 0) {
128 $relatedpageslink .= ' | ';
130 $relatedpageslink .= '<a href="#user">'.get_string('users').'</a>';
131 $countanchors++;
133 // If only one anchor is present, no <a href /> is needed
134 if ($countanchors == 0) {
135 echo '<div class="relatedpages"><p>'.get_string('noresultsfor', 'tag', $tagname).'</p></div>';
136 } elseif ($countanchors > 1) {
137 echo '<div class="relatedpages"><p>'.$relatedpageslink.'</p></div>';
140 // Display courses tagged with the tag
141 if (!empty($courses)) {
143 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
145 echo "<a name='course'></a>";
146 echo $courses;
148 echo $OUTPUT->box_end();
151 // Print up to 10 previous blogs entries
153 if (!empty($blogs)) {
154 echo $OUTPUT->box_start('generalbox', 'tag-blogs');
155 $heading = get_string('relatedblogs', 'tag', $tagname). ' ' . get_string('taggedwith', 'tag', $tagname);
156 echo "<a name='blog'></a>";
157 echo $OUTPUT->heading($heading, 3);
159 echo '<ul id="tagblogentries">';
160 foreach ($blogs as $blog) {
161 if ($blog->publishstate == 'draft') {
162 $class = 'class="dimmed"';
163 } else {
164 $class = '';
166 echo '<li '.$class.'>';
167 echo '<a '.$class.' href="'.$CFG->wwwroot.'/blog/index.php?entryid='.$blog->id.'">';
168 echo format_string($blog->subject);
169 echo '</a>';
170 echo ' - ';
171 echo '<a '.$class.' href="'.$CFG->wwwroot.'/user/view.php?id='.$blog->userid.'">';
172 echo fullname($blog);
173 echo '</a>';
174 echo ', '. userdate($blog->lastmodified);
175 echo '</li>';
177 echo '</ul>';
179 $allblogsurl = new moodle_url('/blog/index.php', array('tagid' => $tag->id));
180 echo '<p class="moreblogs"><a href="'.$allblogsurl->out().'">'.get_string('seeallblogs', 'tag', $tagname).'</a></p>';
182 echo $OUTPUT->box_end();
185 if ($usercount > 0) {
187 //user table box
188 echo $OUTPUT->box_start('generalbox', 'tag-user-table');
190 $heading = get_string('users'). ' ' . get_string('taggedwith', 'tag', $tagname) . ': ' . $usercount;
191 echo "<a name='user'></a>";
192 echo $OUTPUT->heading($heading, 3);
194 $baseurl = new moodle_url('/tag/index.php', array('id' => $tag->id));
195 $pagingbar = new paging_bar($usercount, $userpage, $perpage, $baseurl);
196 $pagingbar->pagevar = 'userpage';
197 echo $OUTPUT->render($pagingbar);
198 tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
199 echo $OUTPUT->box_end();
202 echo $OUTPUT->footer();