global search MDL-24874 fixes for updating indexes via cron.
[moodle.git] / blocks / community / renderer.php
CommitLineData
07ab0c80 1<?php
f5747998 2
07ab0c80 3///////////////////////////////////////////////////////////////////////////
4// //
5// This file is part of Moodle - http://moodle.org/ //
6// Moodle - Modular Object-Oriented Dynamic Learning Environment //
7// //
8// Moodle is free software: you can redistribute it and/or modify //
9// it under the terms of the GNU General Public License as published by //
10// the Free Software Foundation, either version 3 of the License, or //
11// (at your option) any later version. //
12// //
13// Moodle is distributed in the hope that it will be useful, //
14// but WITHOUT ANY WARRANTY; without even the implied warranty of //
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
16// GNU General Public License for more details. //
17// //
18// You should have received a copy of the GNU General Public License //
19// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
20// //
21///////////////////////////////////////////////////////////////////////////
22
23/**
24 * Block community renderer.
25 * @package blocks
26 * @subpackage community
27 * @copyright 2010 Moodle Pty Ltd (http://moodle.com)
28 * @author Jerome Mouneyrac
29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 */
31class block_community_renderer extends plugin_renderer_base {
32
b48c4478 33 public function restore_confirmation_box($filename, $context) {
34 $restoreurl = new moodle_url('/backup/restore.php',
379a5b85 35 array('filename' => $filename . ".mbz", 'contextid' => $context->id));
b48c4478 36 $searchurl = new moodle_url('/blocks/community/communitycourse.php',
37 array('add' => 1, 'courseid' => $context->instanceid,
38 'cancelrestore' => 1, 'sesskey' => sesskey(),
39 'filename' => $filename));
40 $formrestore = new single_button($restoreurl,
41 get_string('dorestore', 'block_community'));
42 $formsearch = new single_button($searchurl,
43 get_string('donotrestore', 'block_community'));
44 return $this->output->confirm(get_string('restorecourseinfo', 'block_community'),
45 $formrestore, $formsearch);
46 }
47
38e22fe9 48 /**
49 * Display remove community success message and a button to be redirected to te referer page
50 * @param moodle_url $url the page to be redirected to
51 * @return string html
52 */
53 public function remove_success(moodle_url $url) {
54 $html = $this->output->notification(get_string('communityremoved', 'hub'),
55 'notifysuccess');
56 $continuebutton = new single_button($url,
57 get_string('continue', 'block_community'));
58 $html .= html_writer::tag('div', $this->output->render($continuebutton),
59 array('class' => 'continuebutton'));
60 return $html;
61 }
62
c48ab36a 63 /**
64 * The 'Next'/'more course result' link for a courses search
65 * @param array $data - the form parameter to execute the search on more result
66 * @return string html code
67 */
68 public function next_button($data) {
69 $nextlink = html_writer::tag('a', get_string('next', 'block_community'),
70 array('href' => new moodle_url('', $data)));
71 return html_writer::tag('div', $nextlink, array( 'class' => 'nextlink'));
72 }
73
f5747998 74 /**
07ab0c80 75 * Display a list of courses
76 * @param array $courses
77 * @param boolean $withwriteaccess
b48c4478 78 * @param int $contextcourseid context course id
07ab0c80 79 * @return string
80 */
b48c4478 81 public function course_list($courses, $huburl, $contextcourseid) {
82 global $CFG;
07ab0c80 83
84 $renderedhtml = '';
85
07ab0c80 86 if (empty($courses)) {
9c7dcf0f 87 if (isset($courses)) {
88 $renderedhtml .= get_string('nocourse', 'block_community');
89 }
07ab0c80 90 } else {
1ce282c8 91 $courseiteration = 0;
07ab0c80 92 foreach ($courses as $course) {
1ce282c8 93 $course = (object) $course;
94 $courseiteration = $courseiteration + 1;
07ab0c80 95
1ce282c8 96 //create visit link html
07ab0c80 97 if (!empty($course->courseurl)) {
98 $courseurl = new moodle_url($course->courseurl);
1ce282c8 99 $linktext = get_string('visitsite', 'block_community');
07ab0c80 100 } else {
101 $courseurl = new moodle_url($course->demourl);
1ce282c8 102 $linktext = get_string('visitdemo', 'block_community');
07ab0c80 103 }
07ab0c80 104
1ce282c8 105 $visitlinkhtml = html_writer::tag('a', $linktext,
fb6b4542 106 array('href' => $courseurl, 'class' => 'hubcoursedownload',
107 'onclick' => 'this.target="_blank"'));
07ab0c80 108
1ce282c8 109 //create title html
110 $coursename = html_writer::tag('h3', $course->fullname,
111 array('class' => 'hubcoursetitle'));
20e033bd 112 $coursenamehtml = html_writer::tag('div', $coursename,
113 array('class' => 'hubcoursetitlepanel'));
07ab0c80 114
1ce282c8 115 // create screenshots html
9c7dcf0f 116 $screenshothtml = '';
117 if (!empty($course->screenshots)) {
b48c4478 118 $baseurl = new moodle_url($huburl . '/local/hub/webservice/download.php',
119 array('courseid' => $course->id,
120 'filetype' => HUB_SCREENSHOT_FILE_TYPE));
20e033bd 121 $screenshothtml = html_writer::empty_tag('img',
122 array('src' => $baseurl, 'alt' => $course->fullname));
9c7dcf0f 123 }
1ce282c8 124 $coursescreenshot = html_writer::tag('div', $screenshothtml,
20e033bd 125 array('class' => 'coursescreenshot',
126 'id' => 'image-' . $course->id));
1ce282c8 127
128 //create description html
129 $deschtml = html_writer::tag('div', $course->description,
130 array('class' => 'hubcoursedescription'));
131
132 //create users related information html
8a3b20ce 133 $courseuserinfo = get_string('userinfo', 'block_community', $course);
b48c4478 134 if ($course->contributornames) {
8a3b20ce 135 $courseuserinfo .= ' - ' . get_string('contributors', 'block_community',
1ce282c8 136 $course->contributornames);
76be2d4e 137 }
1ce282c8 138 $courseuserinfohtml = html_writer::tag('div', $courseuserinfo,
139 array('class' => 'hubcourseuserinfo'));
140
141 //create course content related information html
142 $course->subject = get_string($course->subject, 'edufields');
143 $course->audience = get_string('audience' . $course->audience, 'hub');
144 $course->educationallevel = get_string('edulevel' . $course->educationallevel, 'hub');
81da6918 145 $coursecontentinfo = '';
1ce282c8 146 if (empty($course->coverage)) {
147 $course->coverage = '';
148 } else {
149 $coursecontentinfo .= get_string('coverage', 'block_community', $course->coverage);
150 $coursecontentinfo .= ' - ';
76be2d4e 151 }
81da6918 152 $coursecontentinfo .= get_string('contentinfo', 'block_community', $course);
1ce282c8 153 $coursecontentinfohtml = html_writer::tag('div', $coursecontentinfo,
154 array('class' => 'hubcoursecontentinfo'));
155
156 ///create course file related information html
157 //language
9c7dcf0f 158 if (!empty($course->language)) {
159 $languages = get_string_manager()->get_list_of_languages();
1ce282c8 160 $course->lang = $languages[$course->language];
9c7dcf0f 161 } else {
162 $course->lang = '';
163 }
437c2b85 164 //licence
a8e174cc 165 require_once($CFG->libdir . "/licenselib.php");
437c2b85 166 $licensemanager = new license_manager();
167 $licenses = $licensemanager->get_licenses();
168 foreach ($licenses as $license) {
169 if ($license->shortname == $course->licenceshortname) {
170 $course->license = $license->fullname;
171 }
172 }
1ce282c8 173 $course->timeupdated = userdate($course->timemodified);
174 $coursefileinfo = get_string('fileinfo', 'block_community', $course);
175 $coursefileinfohtml = html_writer::tag('div', $coursefileinfo,
176 array('class' => 'hubcoursefileinfo'));
9c7dcf0f 177
437c2b85 178
179
1ce282c8 180 //Create course content html
bab04a6d 181 if (!empty($course->contents)) {
182 $activitieshtml = '';
183 $blockhtml = '';
184 foreach ($course->contents as $content) {
1ce282c8 185 $content = (object) $content;
186 if ($content->moduletype == 'block') {
76be2d4e 187 if (!empty($blockhtml)) {
188 $blockhtml .= ' - ';
189 }
1ce282c8 190 $blockhtml .= get_string('pluginname', 'block_' . $content->modulename)
191 . " (" . $content->contentcount . ")";
bab04a6d 192 } else {
76be2d4e 193 if (!empty($activitieshtml)) {
194 $activitieshtml .= ' - ';
195 }
1ce282c8 196 $activitieshtml .= get_string('modulename', $content->modulename)
197 . " (" . $content->contentcount . ")";
bab04a6d 198 }
199 }
07ab0c80 200
1ce282c8 201 $blocksandactivities = html_writer::tag('div',
202 get_string('activities', 'block_community') . " : " . $activitieshtml);
203
204 //Uncomment following lines to display blocks information
205// $blocksandactivities .= html_writer::tag('span',
206// get_string('blocks', 'block_community') . " : " . $blockhtml);
207 }
b48c4478 208
914ffb4a 209 //Create outcomes html
210 $outcomes= '';
211 if (!empty($course->outcomes)) {
212 foreach ($course->outcomes as $outcome) {
213 if (!empty($outcomes)) {
214 $outcomes .= ', ';
215 }
216 $outcomes .= $outcome['fullname'];
217 }
218 $outcomes = get_string('outcomes', 'block_community',
219 $outcomes);
220 }
221 $outcomeshtml = html_writer::tag('div', $outcomes, array('class' => 'hubcourseoutcomes'));
222
1ce282c8 223 //create additional information html
224 $additionaldesc = $courseuserinfohtml . $coursecontentinfohtml
914ffb4a 225 . $coursefileinfohtml . $blocksandactivities . $outcomeshtml;
1ce282c8 226 $additionaldeschtml = html_writer::tag('div', $additionaldesc,
227 array('class' => 'additionaldesc'));
07ab0c80 228
1ce282c8 229 //Create add button html
230 $addbuttonhtml = "";
f5747998 231 if ($course->enrollable) {
78f00eab 232 $params = array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1,
f5747998 233 'coursefullname' => $course->fullname, 'courseurl' => $courseurl,
b48c4478 234 'coursedescription' => $course->description,
235 'courseid' => $contextcourseid);
78f00eab 236 $addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
1ce282c8 237 $addbuttonhtml = html_writer::tag('a',
238 get_string('addtocommunityblock', 'block_community'),
239 array('href' => $addurl, 'class' => 'centeredbutton, hubcoursedownload'));
240 }
241
242 //create download button html
243 $downloadbuttonhtml = "";
244 if (!$course->enrollable) {
78f00eab 245 $params = array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
b48c4478 246 'remotemoodleurl' => $CFG->wwwroot, 'courseid' => $contextcourseid,
247 'downloadcourseid' => $course->id, 'huburl' => $huburl,
19eb73cd 248 'coursefullname' => $course->fullname, 'backupsize' => $course->backupsize);
1ce282c8 249 $downloadurl = new moodle_url("/blocks/community/communitycourse.php", $params);
250 $downloadbuttonhtml = html_writer::tag('a', get_string('download', 'block_community'),
251 array('href' => $downloadurl, 'class' => 'centeredbutton, hubcoursedownload'));
252 }
253
254 //Create rating html
255 $rating = html_writer::tag('div', get_string('noratings', 'block_community'),
256 array('class' => 'norating'));
257 if (!empty($course->rating)) {
258 $course->rating = (object) $course->rating;
259 if ($course->rating->count > 0) {
260
261 //calculate size of the rating star
262 $starimagesize = 20; //in px
263 $numberofstars = 5;
264 $size = ($course->rating->aggregate / $course->rating->scaleid)
265 * $numberofstars * $starimagesize;
266 $rating = html_writer::tag('li', '',
267 array('class' => 'current-rating',
268 'style' => 'width:' . $size . 'px;'));
269
fb6b4542 270 $rating = html_writer::tag('ul', $rating,
1ce282c8 271 array('class' => 'star-rating clearfix'));
fb6b4542 272 $rating .= html_writer::tag('div', ' (' . $course->rating->count . ')',
273 array('class' => 'ratingcount clearfix'));
1ce282c8 274 }
07ab0c80 275 }
276
b48c4478 277
1ce282c8 278 //Create comments html
279 $coursecomments = html_writer::tag('div', get_string('nocomments', 'block_community'),
280 array('class' => 'nocomments'));
281 $commentcount = 0;
282 if (!empty($course->comments)) {
283 //display only if there is some comment if there is some comment
284 $commentcount = count($course->comments);
285 $coursecomments = html_writer::tag('div',
fb6b4542 286 get_string('comments', 'block_community', $commentcount),
287 array('class' => 'commenttitle'));
1ce282c8 288
289 foreach ($course->comments as $comment) {
290 $commentator = html_writer::tag('div',
291 $comment['commentator'],
292 array('class' => 'hubcommentator'));
293 $commentdate = html_writer::tag('div',
294 ' - ' . userdate($comment['date'], '%e/%m/%y'),
295 array('class' => 'hubcommentdate clearfix'));
fb6b4542 296
1ce282c8 297 $commenttext = html_writer::tag('div',
298 $comment['comment'],
299 array('class' => 'hubcommenttext'));
fb6b4542 300
1ce282c8 301 $coursecomments .= html_writer::tag('div',
302 $commentator . $commentdate . $commenttext,
303 array('class' => 'hubcomment'));
304 }
305 $coursecommenticon = html_writer::tag('div',
306 get_string('comments', 'block_community', $commentcount),
307 array('class' => 'hubcoursecomments',
308 'id' => 'comments-' . $course->id));
309 $coursecomments = $coursecommenticon . html_writer::tag('div',
310 $coursecomments,
311 array('class' => 'yui3-overlay-loading',
fb6b4542 312 'id' => 'commentoverlay-' . $course->id));
1ce282c8 313 }
314
fb6b4542 315 //link rate and comment
316 $rateandcomment = html_writer::tag('div',
317 html_writer::tag('a', get_string('rateandcomment', 'block_community'),
318 array('href' => new moodle_url($huburl,
09d2da6e 319 array('courseid' => $course->id, 'mustbelogged' => true)),
fb6b4542 320 'onclick' => 'this.target="_blank"')),
321 array('class' => 'hubrateandcomment'));
322
1ce282c8 323 //the main DIV tags
324 $buttonsdiv = html_writer::tag('div',
325 $addbuttonhtml . $downloadbuttonhtml . $visitlinkhtml,
326 array('class' => 'courseoperations'));
327 $screenshotbuttonsdiv = html_writer::tag('div',
328 $coursescreenshot . $buttonsdiv,
329 array('class' => 'courselinks'));
330
331 $coursedescdiv = html_writer::tag('div',
332 $deschtml . $additionaldeschtml
fb6b4542 333 . $rating . $coursecomments . $rateandcomment,
1ce282c8 334 array('class' => 'coursedescription'));
335 $coursehtml =
336 $coursenamehtml . html_writer::tag('div',
337 $coursedescdiv . $screenshotbuttonsdiv,
338 array('class' => 'hubcourseinfo clearfix'));
339
340 $renderedhtml .=html_writer::tag('div', $coursehtml,
341 array('class' => 'fullhubcourse clearfix'));
07ab0c80 342 }
1ce282c8 343
344 $renderedhtml = html_writer::tag('div', $renderedhtml,
345 array('class' => 'hubcourseresult'));
07ab0c80 346 }
1ce282c8 347
07ab0c80 348 return $renderedhtml;
349 }
350
2a102b90 351}