Merge branch 'MDL-23813_21' of git://github.com/timhunt/moodle into MOODLE_21_STABLE
[moodle.git] / tag / coursetags_more.php
blobee7c75c454b46d1b2648d386ed573f4bfa54cfb0
1 <?php
2 /**
3 * coursetags_more.php
4 * a full display of tags allowing some filtering and reordering
5 * @author j.beedell@open.ac.uk June07
6 */
8 require_once('../config.php');
9 require_once($CFG->dirroot.'/tag/coursetagslib.php');
10 require_once($CFG->dirroot.'/tag/lib.php');
12 $sort = optional_param('sort', 'alpha', PARAM_ALPHA); //alpha, date or popularity
13 $show = optional_param('show', 'all', PARAM_ALPHA); //all, my, official, community or course
14 $courseid = optional_param('courseid', 0, PARAM_INT);
16 $url = new moodle_url('/tag/coursetags_more.php');
17 if ($sort !== 'alpha') {
18 $url->param('sort', $sort);
20 if ($show !== 'all') {
21 $url->param('show', $show);
23 if ($courseid !== 0) {
24 $url->param('courseid', $courseid);
26 $PAGE->set_url($url);
28 if (empty($CFG->usetags)) {
29 print_error('tagsaredisabled', 'tag');
32 // Some things require logging in
33 if ($CFG->forcelogin or $show == 'my') {
34 require_login();
37 // Permissions
38 $loggedin = isloggedin() && !isguestuser();
40 // Course check
41 if ($courseid) {
42 if (!($course = $DB->get_record('course', array('id'=>$courseid)))) {
43 $courseid = 0;
45 if ($courseid == SITEID) $courseid = 0;
48 if ($courseid) {
49 $PAGE->set_context(get_context_instance(CONTEXT_COURSE, $courseid));
50 } else {
51 $PAGE->set_context(get_system_context());
54 // Language strings
55 $tagslang = 'block_tags';
56 $title = get_string('moretitle', $tagslang);
57 $link1 = get_string('moreshow', $tagslang);
58 $link2 = get_string('moreorder', $tagslang);
59 $showalltags = get_string('moreshowalltags', $tagslang);
60 $showofficialtags = get_string('moreshowofficialtags', $tagslang);
61 $showmytags = get_string('moreshowmytags', $tagslang);
62 $showcommtags = get_string('moreshowcommtags', $tagslang);
63 $orderalpha = get_string('moreorderalpha', $tagslang);
64 $orderdate = get_string('moreorderdate', $tagslang);
65 $orderpop = get_string('moreorderpop', $tagslang);
66 $welcome = get_string('morewelcome', $tagslang);
68 // The title and breadcrumb
69 if ($courseid) {
70 $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid)));
71 $PAGE->navbar->add($courseshortname, new moodle_url('/course/view.php', array('id'=>$courseid)));
73 $PAGE->navbar->add($title);
74 $PAGE->set_title($title);
75 $PAGE->set_heading($COURSE->fullname);
76 echo $OUTPUT->header();
77 echo $OUTPUT->heading($title, 2, 'centre');
79 // Prepare data for tags
80 $courselink = '';
81 if ($courseid) { $courselink = '&amp;courseid='.$courseid; }
82 $myurl = $CFG->wwwroot.'/tag/coursetags_more.php';
83 $myurl2 = $CFG->wwwroot.'/tag/coursetags_more.php?show='.$show;
85 // Course tags
86 if ($show == 'course' and $courseid) {
88 if ($sort == 'popularity') {
89 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'popularity'), true, 200, 90);
90 } else if ($sort == 'date') {
91 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'timemodified'), true, 200, 90);
92 } else {
93 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'name'), true, 200, 90);
96 // My tags
97 } else if ($show == 'my' and $loggedin) {
99 if ($sort == 'popularity') {
100 $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'popularity'), true, 200, 90);
101 } else if ($sort == 'date') {
102 $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'timemodified'), true, 200, 90);
103 } else {
104 $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'name'), true, 200, 90);
107 // Official course tags
108 } else if ($show == 'official') {
110 if ($sort == 'popularity') {
111 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'popularity'), true, 200, 90);
112 } else if ($sort == 'date') {
113 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'timemodified'), true, 200, 90);
114 } else {
115 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'name'), true, 200, 90);
118 // Community (official and personal together) also called user tags
119 } else if ($show == 'community') {
121 if ($sort == 'popularity') {
122 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'popularity'), true, 200, 90);
123 } else if ($sort == 'date') {
124 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'timemodified'), true, 200, 90);
125 } else {
126 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'name'), true, 200, 90);
129 // All tags for courses and blogs and any thing else tagged - the fallback default ($show == all)
130 } else {
132 $subtitle = $showalltags;
133 if ($sort == 'popularity') {
134 $tags = coursetag_print_cloud(coursetag_get_all_tags('popularity'), true, 200, 90);
135 } else if ($sort == 'date') {
136 $tags = coursetag_print_cloud(coursetag_get_all_tags('timemodified'), true, 200, 90);
137 } else {
138 $tags = coursetag_print_cloud(coursetag_get_all_tags('name'), true, 200, 90);
143 // Prepare the links for the show and order lines
144 if ($show == 'all') {
145 $link1 .= '<b>'.$showalltags.'</b>';
146 } else {
147 $link1 .= '<a href="'.$myurl.'?show=all'.$courselink.'">'.$showalltags.'</a>';
149 //if ($show == 'official') { //add back in if you start to use official course tags
150 // $link1 .= ' | <b>'.$showofficialtags.'</b>';
151 //} else {
152 // $link1 .= ' | <a href="'.$myurl.'?show=official'.$courselink.'">'.$showofficialtags.'</a>';
154 if ($show == 'community') {
155 $link1 .= ' | <b>'.$showcommtags.'</b>';
156 } else {
157 $link1 .= ' | <a href="'.$myurl.'?show=community'.$courselink.'">'.$showcommtags.'</a>';
159 if ($loggedin) {
160 if ($show == 'my') {
161 $link1 .= ' | <b>'.$showmytags.'</b>';
162 } else {
163 $link1 .= ' | <a href="'.$myurl.'?show=my'.$courselink.'">'.$showmytags.'</a>';
166 if ($courseid) {
167 $fullname = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
168 if ($show == 'course') {
169 $link1 .= ' | <b>'.get_string('moreshowcoursetags', $tagslang, $fullname).'</b>';
170 } else {
171 $link1 .= ' | <a href="'.$myurl.'?show=course'.$courselink.'">'.get_string('moreshowcoursetags', $tagslang, $fullname).'</a>';
174 if ($sort == 'alpha') {
175 $link2 .= '<b>'.$orderalpha.'</b> | ';
176 } else {
177 $link2 .= '<a href="'.$myurl2.'&amp;sort=alpha'.$courselink.'">'.$orderalpha.'</a> | ';
179 if ($sort == 'popularity') {
180 $link2 .= '<b>'.$orderpop.'</b> | ';
181 } else {
182 $link2 .= '<a href="'.$myurl2.'&amp;sort=popularity'.$courselink.'">'.$orderpop.'</a> | ';
184 if ($sort == 'date') {
185 $link2 .= '<b>'.$orderdate.'</b>';
186 } else {
187 $link2 .= '<a href="'.$myurl2.'&amp;sort=date'.$courselink.'">'.$orderdate.'</a>';
190 // Prepare output
191 $fclass = '';
192 // make the tags larger when there are not so many
193 if (strlen($tags) < 10000) { $fclass = 'coursetag_more_large'; }
194 $outstr = '
195 <div class="coursetag_more_title">
196 <div style="padding-bottom:5px">'.$welcome.'</div>
197 <div class="coursetag_more_link">'.$link1.'</div>
198 <div class="coursetag_more_link">'.$link2.'</div>
199 </div>
200 <div class="coursetag_more_tags '.$fclass.'">'.
201 $tags.'
202 </div>';
203 echo $outstr;
205 echo $OUTPUT->footer();