2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * A full display of tags allowing some filtering and reordering
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);
47 if (empty($CFG->usetags
)) {
48 print_error('tagsaredisabled', 'tag');
51 // Some things require logging in
52 if ($CFG->forcelogin
or $show == 'my') {
57 $loggedin = isloggedin() && !isguestuser();
61 if (!($course = $DB->get_record('course', array('id'=>$courseid)))) {
64 if ($courseid == SITEID
) $courseid = 0;
68 $PAGE->set_context(get_context_instance(CONTEXT_COURSE
, $courseid));
70 $PAGE->set_context(get_system_context());
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
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
100 if ($courseid) { $courselink = '&courseid='.$courseid; }
101 $myurl = $CFG->wwwroot
.'/tag/coursetags_more.php';
102 $myurl2 = $CFG->wwwroot
.'/tag/coursetags_more.php?show='.$show;
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);
112 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'name'), true, 200, 90);
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);
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);
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);
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)
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);
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>';
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>';
171 // $link1 .= ' | <a href="'.$myurl.'?show=official'.$courselink.'">'.$showofficialtags.'</a>';
173 if ($show == 'community') {
174 $link1 .= ' | <b>'.$showcommtags.'</b>';
176 $link1 .= ' | <a href="'.$myurl.'?show=community'.$courselink.'">'.$showcommtags.'</a>';
180 $link1 .= ' | <b>'.$showmytags.'</b>';
182 $link1 .= ' | <a href="'.$myurl.'?show=my'.$courselink.'">'.$showmytags.'</a>';
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>';
190 $link1 .= ' | <a href="'.$myurl.'?show=course'.$courselink.'">'.get_string('moreshowcoursetags', $tagslang, $fullname).'</a>';
193 if ($sort == 'alpha') {
194 $link2 .= '<b>'.$orderalpha.'</b> | ';
196 $link2 .= '<a href="'.$myurl2.'&sort=alpha'.$courselink.'">'.$orderalpha.'</a> | ';
198 if ($sort == 'popularity') {
199 $link2 .= '<b>'.$orderpop.'</b> | ';
201 $link2 .= '<a href="'.$myurl2.'&sort=popularity'.$courselink.'">'.$orderpop.'</a> | ';
203 if ($sort == 'date') {
204 $link2 .= '<b>'.$orderdate.'</b>';
206 $link2 .= '<a href="'.$myurl2.'&sort=date'.$courselink.'">'.$orderdate.'</a>';
211 // make the tags larger when there are not so many
212 if (strlen($tags) < 10000) { $fclass = 'coursetag_more_large'; }
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>
219 <div class="coursetag_more_tags '.$fclass.'">'.
224 echo $OUTPUT->footer();