MDL-26142 fix immediately spelling in strings, comments and code
[moodle.git] / tag / coursetags_more.php
blobb1075a14ee2238c228f18ebc67caab9288312b24
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 $PAGE->navbar->add(format_string($course->shortname), new moodle_url('/course/view.php', array('id'=>$courseid)));
72 $PAGE->navbar->add($title);
73 $PAGE->set_title($title);
74 $PAGE->set_heading($COURSE->fullname);
75 echo $OUTPUT->header();
76 echo $OUTPUT->heading($title, 2, 'centre');
78 // Prepare data for tags
79 $courselink = '';
80 if ($courseid) { $courselink = '&amp;courseid='.$courseid; }
81 $myurl = $CFG->wwwroot.'/tag/coursetags_more.php';
82 $myurl2 = $CFG->wwwroot.'/tag/coursetags_more.php?show='.$show;
84 // Course tags
85 if ($show == 'course' and $courseid) {
87 if ($sort == 'popularity') {
88 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'popularity'), true, 200, 90);
89 } else if ($sort == 'date') {
90 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'timemodified'), true, 200, 90);
91 } else {
92 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'name'), true, 200, 90);
95 // My tags
96 } else if ($show == 'my' and $loggedin) {
98 if ($sort == 'popularity') {
99 $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'popularity'), true, 200, 90);
100 } else if ($sort == 'date') {
101 $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'timemodified'), true, 200, 90);
102 } else {
103 $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'name'), true, 200, 90);
106 // Official course tags
107 } else if ($show == 'official') {
109 if ($sort == 'popularity') {
110 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'popularity'), true, 200, 90);
111 } else if ($sort == 'date') {
112 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'timemodified'), true, 200, 90);
113 } else {
114 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'name'), true, 200, 90);
117 // Community (official and personal together) also called user tags
118 } else if ($show == 'community') {
120 if ($sort == 'popularity') {
121 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'popularity'), true, 200, 90);
122 } else if ($sort == 'date') {
123 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'timemodified'), true, 200, 90);
124 } else {
125 $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'name'), true, 200, 90);
128 // All tags for courses and blogs and any thing else tagged - the fallback default ($show == all)
129 } else {
131 $subtitle = $showalltags;
132 if ($sort == 'popularity') {
133 $tags = coursetag_print_cloud(coursetag_get_all_tags('popularity'), true, 200, 90);
134 } else if ($sort == 'date') {
135 $tags = coursetag_print_cloud(coursetag_get_all_tags('timemodified'), true, 200, 90);
136 } else {
137 $tags = coursetag_print_cloud(coursetag_get_all_tags('name'), true, 200, 90);
142 // Prepare the links for the show and order lines
143 if ($show == 'all') {
144 $link1 .= '<b>'.$showalltags.'</b>';
145 } else {
146 $link1 .= '<a href="'.$myurl.'?show=all'.$courselink.'">'.$showalltags.'</a>';
148 //if ($show == 'official') { //add back in if you start to use official course tags
149 // $link1 .= ' | <b>'.$showofficialtags.'</b>';
150 //} else {
151 // $link1 .= ' | <a href="'.$myurl.'?show=official'.$courselink.'">'.$showofficialtags.'</a>';
153 if ($show == 'community') {
154 $link1 .= ' | <b>'.$showcommtags.'</b>';
155 } else {
156 $link1 .= ' | <a href="'.$myurl.'?show=community'.$courselink.'">'.$showcommtags.'</a>';
158 if ($loggedin) {
159 if ($show == 'my') {
160 $link1 .= ' | <b>'.$showmytags.'</b>';
161 } else {
162 $link1 .= ' | <a href="'.$myurl.'?show=my'.$courselink.'">'.$showmytags.'</a>';
165 if ($courseid) {
166 if ($show == 'course') {
167 $link1 .= ' | <b>'.get_string('moreshowcoursetags', $tagslang, $course->fullname).'</b>';
168 } else {
169 $link1 .= ' | <a href="'.$myurl.'?show=course'.$courselink.'">'.get_string('moreshowcoursetags', $tagslang, $course->fullname).'</a>';
172 if ($sort == 'alpha') {
173 $link2 .= '<b>'.$orderalpha.'</b> | ';
174 } else {
175 $link2 .= '<a href="'.$myurl2.'&amp;sort=alpha'.$courselink.'">'.$orderalpha.'</a> | ';
177 if ($sort == 'popularity') {
178 $link2 .= '<b>'.$orderpop.'</b> | ';
179 } else {
180 $link2 .= '<a href="'.$myurl2.'&amp;sort=popularity'.$courselink.'">'.$orderpop.'</a> | ';
182 if ($sort == 'date') {
183 $link2 .= '<b>'.$orderdate.'</b>';
184 } else {
185 $link2 .= '<a href="'.$myurl2.'&amp;sort=date'.$courselink.'">'.$orderdate.'</a>';
188 // Prepare output
189 $fclass = '';
190 // make the tags larger when there are not so many
191 if (strlen($tags) < 10000) { $fclass = 'coursetag_more_large'; }
192 $outstr = '
193 <div class="coursetag_more_title">
194 <div style="padding-bottom:5px">'.$welcome.'</div>
195 <div class="coursetag_more_link">'.$link1.'</div>
196 <div class="coursetag_more_link">'.$link2.'</div>
197 </div>
198 <div class="coursetag_more_tags '.$fclass.'">'.
199 $tags.'
200 </div>';
201 echo $outstr;
203 echo $OUTPUT->footer();