MDL-21695 adding help string
[moodle.git] / tag / coursetags_more.php
blob9dfccf8c1b65552a0123abf0e8e7edf275798688
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_TEXT); //alpha, date or popularity
13 $show = optional_param('show', 'all', PARAM_TEXT); //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 // Language strings
49 $tagslang = 'block_tags';
50 $title = get_string('moretitle', $tagslang);
51 $link1 = get_string('moreshow', $tagslang);
52 $link2 = get_string('moreorder', $tagslang);
53 $showalltags = get_string('moreshowalltags', $tagslang);
54 $showofficialtags = get_string('moreshowofficialtags', $tagslang);
55 $showmytags = get_string('moreshowmytags', $tagslang);
56 $showcommtags = get_string('moreshowcommtags', $tagslang);
57 $orderalpha = get_string('moreorderalpha', $tagslang);
58 $orderdate = get_string('moreorderdate', $tagslang);
59 $orderpop = get_string('moreorderpop', $tagslang);
60 $welcome = get_string('morewelcome', $tagslang);
62 // The title and breadcrumb
63 if ($courseid) {
64 $PAGE->navbar->add(format_string($course->shortname), new moodle_url('/course/view.php', array('id'=>$courseid)));
66 $PAGE->navbar->add($title);
67 $PAGE->set_title($title);
68 echo $OUTPUT->header();
69 echo $OUTPUT->heading($title, 2, 'centre');
71 // Prepare data for tags
72 $courselink = '';
73 if ($courseid) { $courselink = '&amp;courseid='.$courseid; }
74 $myurl = $CFG->wwwroot.'/tag/coursetags_more.php';
75 $myurl2 = $CFG->wwwroot.'/tag/coursetags_more.php?show='.$show;
77 // Course tags
78 if ($show == 'course' and $courseid) {
80 if ($sort == 'popularity') {
81 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'popularity'), true, 200, 90);
82 } else if ($sort == 'date') {
83 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'timemodified'), true, 200, 90);
84 } else {
85 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'name'), true, 200, 90);
88 // My tags
89 } else if ($show == 'my' and $loggedin) {
91 if ($sort == 'popularity') {
92 $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'popularity'), true, 200, 90);
93 } else if ($sort == 'date') {
94 $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'timemodified'), true, 200, 90);
95 } else {
96 $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'name'), true, 200, 90);
99 // Official course tags
100 } else if ($show == 'official') {
102 if ($sort == 'popularity') {
103 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'popularity'), true, 200, 90);
104 } else if ($sort == 'date') {
105 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'timemodified'), true, 200, 90);
106 } else {
107 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'name'), true, 200, 90);
110 // Community (official and personal together) also called user tags
111 } else if ($show == 'community') {
113 if ($sort == 'popularity') {
114 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'popularity'), true, 200, 90);
115 } else if ($sort == 'date') {
116 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'timemodified'), true, 200, 90);
117 } else {
118 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'name'), true, 200, 90);
121 // All tags for courses and blogs and any thing else tagged - the fallback default ($show == all)
122 } else {
124 $subtitle = $showalltags;
125 if ($sort == 'popularity') {
126 $tags = coursetag_print_cloud(coursetag_get_all_tags('popularity'), true, 200, 90);
127 } else if ($sort == 'date') {
128 $tags = coursetag_print_cloud(coursetag_get_all_tags('timemodified'), true, 200, 90);
129 } else {
130 $tags = coursetag_print_cloud(coursetag_get_all_tags('name'), true, 200, 90);
135 // Prepare the links for the show and order lines
136 if ($show == 'all') {
137 $link1 .= '<b>'.$showalltags.'</b>';
138 } else {
139 $link1 .= '<a href="'.$myurl.'?show=all'.$courselink.'">'.$showalltags.'</a>';
141 //if ($show == 'official') { //add back in if you start to use official course tags
142 // $link1 .= ' | <b>'.$showofficialtags.'</b>';
143 //} else {
144 // $link1 .= ' | <a href="'.$myurl.'?show=official'.$courselink.'">'.$showofficialtags.'</a>';
146 if ($show == 'community') {
147 $link1 .= ' | <b>'.$showcommtags.'</b>';
148 } else {
149 $link1 .= ' | <a href="'.$myurl.'?show=community'.$courselink.'">'.$showcommtags.'</a>';
151 if ($loggedin) {
152 if ($show == 'my') {
153 $link1 .= ' | <b>'.$showmytags.'</b>';
154 } else {
155 $link1 .= ' | <a href="'.$myurl.'?show=my'.$courselink.'">'.$showmytags.'</a>';
158 if ($courseid) {
159 if ($show == 'course') {
160 $link1 .= ' | <b>'.get_string('moreshowcoursetags', $tagslang, $course->fullname).'</b>';
161 } else {
162 $link1 .= ' | <a href="'.$myurl.'?show=course'.$courselink.'">'.get_string('moreshowcoursetags', $tagslang, $course->fullname).'</a>';
165 if ($sort == 'alpha') {
166 $link2 .= '<b>'.$orderalpha.'</b> | ';
167 } else {
168 $link2 .= '<a href="'.$myurl2.'&amp;sort=alpha'.$courselink.'">'.$orderalpha.'</a> | ';
170 if ($sort == 'popularity') {
171 $link2 .= '<b>'.$orderpop.'</b> | ';
172 } else {
173 $link2 .= '<a href="'.$myurl2.'&amp;sort=popularity'.$courselink.'">'.$orderpop.'</a> | ';
175 if ($sort == 'date') {
176 $link2 .= '<b>'.$orderdate.'</b>';
177 } else {
178 $link2 .= '<a href="'.$myurl2.'&amp;sort=date'.$courselink.'">'.$orderdate.'</a>';
181 // Prepare output
182 $fclass = '';
183 // make the tags larger when there are not so many
184 if (strlen($tags) < 10000) { $fclass = 'coursetag_more_large'; }
185 $outstr = '
186 <div class="coursetag_more_title">
187 <div style="padding-bottom:5px">'.$welcome.
188 $OUTPUT->old_help_icon('usingtags', 'using tags', $tagslang).'
189 </div>
190 <div class="coursetag_more_link">'.$link1.'</div>
191 <div class="coursetag_more_link">'.$link2.'</div>
192 </div>
193 <div class="coursetag_more_tags '.$fclass.'">'.
194 $tags.'
195 </div>';
196 echo $outstr;
198 echo $OUTPUT->footer();