4 * a full display of tags allowing some filtering and reordering
5 * @author j.beedell@open.ac.uk June07
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);
28 if (empty($CFG->usetags
)) {
29 print_error('tagsaredisabled', 'tag');
32 // Some things require logging in
33 if ($CFG->forcelogin
or $show == 'my') {
38 $loggedin = isloggedin() && !isguestuser();
42 if (!($course = $DB->get_record('course', array('id'=>$courseid)))) {
45 if ($courseid == SITEID
) $courseid = 0;
49 $PAGE->set_context(get_context_instance(CONTEXT_COURSE
, $courseid));
51 $PAGE->set_context(get_system_context());
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
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
81 if ($courseid) { $courselink = '&courseid='.$courseid; }
82 $myurl = $CFG->wwwroot
.'/tag/coursetags_more.php';
83 $myurl2 = $CFG->wwwroot
.'/tag/coursetags_more.php?show='.$show;
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);
93 $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'name'), true, 200, 90);
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);
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);
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);
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)
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);
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>';
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>';
152 // $link1 .= ' | <a href="'.$myurl.'?show=official'.$courselink.'">'.$showofficialtags.'</a>';
154 if ($show == 'community') {
155 $link1 .= ' | <b>'.$showcommtags.'</b>';
157 $link1 .= ' | <a href="'.$myurl.'?show=community'.$courselink.'">'.$showcommtags.'</a>';
161 $link1 .= ' | <b>'.$showmytags.'</b>';
163 $link1 .= ' | <a href="'.$myurl.'?show=my'.$courselink.'">'.$showmytags.'</a>';
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>';
171 $link1 .= ' | <a href="'.$myurl.'?show=course'.$courselink.'">'.get_string('moreshowcoursetags', $tagslang, $fullname).'</a>';
174 if ($sort == 'alpha') {
175 $link2 .= '<b>'.$orderalpha.'</b> | ';
177 $link2 .= '<a href="'.$myurl2.'&sort=alpha'.$courselink.'">'.$orderalpha.'</a> | ';
179 if ($sort == 'popularity') {
180 $link2 .= '<b>'.$orderpop.'</b> | ';
182 $link2 .= '<a href="'.$myurl2.'&sort=popularity'.$courselink.'">'.$orderpop.'</a> | ';
184 if ($sort == 'date') {
185 $link2 .= '<b>'.$orderdate.'</b>';
187 $link2 .= '<a href="'.$myurl2.'&sort=date'.$courselink.'">'.$orderdate.'</a>';
192 // make the tags larger when there are not so many
193 if (strlen($tags) < 10000) { $fclass = 'coursetag_more_large'; }
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>
200 <div class="coursetag_more_tags '.$fclass.'">'.
205 echo $OUTPUT->footer();