Merge branch 'MDL-40255_M23' of git://github.com/lazydaisy/moodle into MOODLE_23_STABLE
[moodle.git] / tag / coursetags_more.php
blob60b18207be11853958d38face501822552f29f05
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 * A full display of tags allowing some filtering and reordering
21 * @package core_tag
22 * @category tag
23 * @copyright 2007 j.beedell@open.ac.uk
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require_once('../config.php');
28 require_once($CFG->dirroot.'/tag/coursetagslib.php');
29 require_once($CFG->dirroot.'/tag/lib.php');
31 $sort = optional_param('sort', 'alpha', PARAM_ALPHA); //alpha, date or popularity
32 $show = optional_param('show', 'all', PARAM_ALPHA); //all, my, official, community or course
33 $courseid = optional_param('courseid', 0, PARAM_INT);
35 $url = new moodle_url('/tag/coursetags_more.php');
36 if ($sort !== 'alpha') {
37 $url->param('sort', $sort);
39 if ($show !== 'all') {
40 $url->param('show', $show);
42 if ($courseid !== 0) {
43 $url->param('courseid', $courseid);
45 $PAGE->set_url($url);
47 if (empty($CFG->usetags)) {
48 print_error('tagsaredisabled', 'tag');
51 // Some things require logging in
52 if ($CFG->forcelogin or $show == 'my') {
53 require_login();
56 // Permissions
57 $loggedin = isloggedin() && !isguestuser();
59 // Course check
60 if ($courseid) {
61 if (!($course = $DB->get_record('course', array('id'=>$courseid)))) {
62 $courseid = 0;
64 if ($courseid == SITEID) $courseid = 0;
67 if ($courseid) {
68 $PAGE->set_context(get_context_instance(CONTEXT_COURSE, $courseid));
69 } else {
70 $PAGE->set_context(get_system_context());
73 // Language strings
74 $tagslang = 'block_tags';
75 $title = get_string('moretitle', $tagslang);
76 $link1 = get_string('moreshow', $tagslang);
77 $link2 = get_string('moreorder', $tagslang);
78 $showalltags = get_string('moreshowalltags', $tagslang);
79 $showofficialtags = get_string('moreshowofficialtags', $tagslang);
80 $showmytags = get_string('moreshowmytags', $tagslang);
81 $showcommtags = get_string('moreshowcommtags', $tagslang);
82 $orderalpha = get_string('moreorderalpha', $tagslang);
83 $orderdate = get_string('moreorderdate', $tagslang);
84 $orderpop = get_string('moreorderpop', $tagslang);
85 $welcome = get_string('morewelcome', $tagslang);
87 // The title and breadcrumb
88 if ($courseid) {
89 $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid)));
90 $PAGE->navbar->add($courseshortname, new moodle_url('/course/view.php', array('id'=>$courseid)));
92 $PAGE->navbar->add($title);
93 $PAGE->set_title($title);
94 $PAGE->set_heading($COURSE->fullname);
95 echo $OUTPUT->header();
96 echo $OUTPUT->heading($title, 2, 'centre');
98 // Prepare data for tags
99 $courselink = '';
100 if ($courseid) { $courselink = '&amp;courseid='.$courseid; }
101 $myurl = $CFG->wwwroot.'/tag/coursetags_more.php';
102 $myurl2 = $CFG->wwwroot.'/tag/coursetags_more.php?show='.$show;
104 // Course tags
105 if ($show == 'course' and $courseid) {
107 if ($sort == 'popularity') {
108 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'popularity'), true, 200, 90);
109 } else if ($sort == 'date') {
110 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'timemodified'), true, 200, 90);
111 } else {
112 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'name'), true, 200, 90);
115 // My tags
116 } else if ($show == 'my' and $loggedin) {
118 if ($sort == 'popularity') {
119 $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'popularity'), true, 200, 90);
120 } else if ($sort == 'date') {
121 $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'timemodified'), true, 200, 90);
122 } else {
123 $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'name'), true, 200, 90);
126 // Official course tags
127 } else if ($show == 'official') {
129 if ($sort == 'popularity') {
130 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'popularity'), true, 200, 90);
131 } else if ($sort == 'date') {
132 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'timemodified'), true, 200, 90);
133 } else {
134 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'name'), true, 200, 90);
137 // Community (official and personal together) also called user tags
138 } else if ($show == 'community') {
140 if ($sort == 'popularity') {
141 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'popularity'), true, 200, 90);
142 } else if ($sort == 'date') {
143 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'timemodified'), true, 200, 90);
144 } else {
145 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'name'), true, 200, 90);
148 // All tags for courses and blogs and any thing else tagged - the fallback default ($show == all)
149 } else {
151 $subtitle = $showalltags;
152 if ($sort == 'popularity') {
153 $tags = coursetag_print_cloud(coursetag_get_all_tags('popularity'), true, 200, 90);
154 } else if ($sort == 'date') {
155 $tags = coursetag_print_cloud(coursetag_get_all_tags('timemodified'), true, 200, 90);
156 } else {
157 $tags = coursetag_print_cloud(coursetag_get_all_tags('name'), true, 200, 90);
162 // Prepare the links for the show and order lines
163 if ($show == 'all') {
164 $link1 .= '<b>'.$showalltags.'</b>';
165 } else {
166 $link1 .= '<a href="'.$myurl.'?show=all'.$courselink.'">'.$showalltags.'</a>';
168 //if ($show == 'official') { //add back in if you start to use official course tags
169 // $link1 .= ' | <b>'.$showofficialtags.'</b>';
170 //} else {
171 // $link1 .= ' | <a href="'.$myurl.'?show=official'.$courselink.'">'.$showofficialtags.'</a>';
173 if ($show == 'community') {
174 $link1 .= ' | <b>'.$showcommtags.'</b>';
175 } else {
176 $link1 .= ' | <a href="'.$myurl.'?show=community'.$courselink.'">'.$showcommtags.'</a>';
178 if ($loggedin) {
179 if ($show == 'my') {
180 $link1 .= ' | <b>'.$showmytags.'</b>';
181 } else {
182 $link1 .= ' | <a href="'.$myurl.'?show=my'.$courselink.'">'.$showmytags.'</a>';
185 if ($courseid) {
186 $fullname = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
187 if ($show == 'course') {
188 $link1 .= ' | <b>'.get_string('moreshowcoursetags', $tagslang, $fullname).'</b>';
189 } else {
190 $link1 .= ' | <a href="'.$myurl.'?show=course'.$courselink.'">'.get_string('moreshowcoursetags', $tagslang, $fullname).'</a>';
193 if ($sort == 'alpha') {
194 $link2 .= '<b>'.$orderalpha.'</b> | ';
195 } else {
196 $link2 .= '<a href="'.$myurl2.'&amp;sort=alpha'.$courselink.'">'.$orderalpha.'</a> | ';
198 if ($sort == 'popularity') {
199 $link2 .= '<b>'.$orderpop.'</b> | ';
200 } else {
201 $link2 .= '<a href="'.$myurl2.'&amp;sort=popularity'.$courselink.'">'.$orderpop.'</a> | ';
203 if ($sort == 'date') {
204 $link2 .= '<b>'.$orderdate.'</b>';
205 } else {
206 $link2 .= '<a href="'.$myurl2.'&amp;sort=date'.$courselink.'">'.$orderdate.'</a>';
209 // Prepare output
210 $fclass = '';
211 // make the tags larger when there are not so many
212 if (strlen($tags) < 10000) { $fclass = 'coursetag_more_large'; }
213 $outstr = '
214 <div class="coursetag_more_title">
215 <div style="padding-bottom:5px">'.$welcome.'</div>
216 <div class="coursetag_more_link">'.$link1.'</div>
217 <div class="coursetag_more_link">'.$link2.'</div>
218 </div>
219 <div class="coursetag_more_tags '.$fclass.'">'.
220 $tags.'
221 </div>';
222 echo $outstr;
224 echo $OUTPUT->footer();