MDL-30639 mod_lesson: Used a consistent format for users display of answer
[moodle.git] / tag / index.php
blob3a993df95ee37ad57123869c3e81fbf62d03d594
1 <?php
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.
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/>.
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
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 = get_context_instance(CONTEXT_SYSTEM);
46 if ($tagname) {
47 $tag = tag_get('name', $tagname, '*');
48 } else if ($tagid) {
49 $tag = tag_get('id', $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' => $tagid)));
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);
96 echo '<div class="relatedpages"><p><a href="#course">'.get_string('courses').
97 '</a> | <a href="#blog">'.get_string('relatedblogs', 'tag').
98 '</a> | <a href="#user">'.get_string('users').'</a></p></div>';
100 // Display courses tagged with the tag
101 require_once($CFG->dirroot.'/tag/coursetagslib.php');
102 if ($courses = coursetag_get_tagged_courses($tag->id)) {
104 $totalcount = count( $courses );
105 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
107 $heading = get_string('courses') . ' ' . get_string('taggedwith', 'tag', $tagname) .': '. $totalcount;
108 echo "<a name='course'></a>";
109 echo $OUTPUT->heading($heading, 3);
111 foreach ($courses as $course) {
112 print_course($course);
115 echo $OUTPUT->box_end();
118 // Print up to 10 previous blogs entries
119 if (has_capability('moodle/blog:view', $systemcontext)) {
120 require_once($CFG->dirroot.'/blog/lib.php');
121 require_once($CFG->dirroot.'/blog/locallib.php');
123 $bloglisting = new blog_listing(array('tag' => $tag->id));
124 $limit = 10;
125 $start = 0;
127 if ($blogs = $bloglisting->get_entries($start, $limit)) {
129 echo $OUTPUT->box_start('generalbox', 'tag-blogs');
130 $heading = get_string('relatedblogs', 'tag', $tagname). ' ' . get_string('taggedwith', 'tag', $tagname);
131 echo "<a name='blog'></a>";
132 echo $OUTPUT->heading($heading, 3);
134 echo '<ul id="tagblogentries">';
135 foreach ($blogs as $blog) {
136 if ($blog->publishstate == 'draft') {
137 $class = 'class="dimmed"';
138 } else {
139 $class = '';
141 echo '<li '.$class.'>';
142 echo '<a '.$class.' href="'.$CFG->wwwroot.'/blog/index.php?entryid='.$blog->id.'">';
143 echo format_string($blog->subject);
144 echo '</a>';
145 echo ' - ';
146 echo '<a '.$class.' href="'.$CFG->wwwroot.'/user/view.php?id='.$blog->userid.'">';
147 echo fullname($blog);
148 echo '</a>';
149 echo ', '. userdate($blog->lastmodified);
150 echo '</li>';
152 echo '</ul>';
154 $allblogsurl = new moodle_url('/blog/index.php', array('tagid' => $tag->id));
155 echo '<p class="moreblogs"><a href="'.$allblogsurl->out().'">'.get_string('seeallblogs', 'tag', $tagname).'</a></p>';
157 echo $OUTPUT->box_end();
161 $usercount = tag_record_count('user', $tag->id);
162 if ($usercount > 0) {
164 //user table box
165 echo $OUTPUT->box_start('generalbox', 'tag-user-table');
167 $heading = get_string('users'). ' ' . get_string('taggedwith', 'tag', $tagname) . ': ' . $usercount;
168 echo "<a name='user'></a>";
169 echo $OUTPUT->heading($heading, 3);
171 $baseurl = new moodle_url('/tag/index.php', array('id' => $tag->id));
172 $pagingbar = new paging_bar($usercount, $userpage, $perpage, $baseurl);
173 $pagingbar->pagevar = 'userpage';
174 echo $OUTPUT->render($pagingbar);
175 tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
176 echo $OUTPUT->box_end();
179 echo $OUTPUT->footer();