on-demand release 2.2beta+
[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');
9e32912b 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
63 /**
64 * Display add community course success message and a button to be redirected to te referer page
65 * @param moodle_url $url the page to be redirected to
66 * @return string html
67 */
68 public function save_link_success(moodle_url $url) {
69 $html = $this->output->notification(get_string('addedtoblock', 'block_community'),
70 'notifysuccess');
38e22fe9 71 $continuebutton = new single_button($url,
72 get_string('continue', 'block_community'));
73 $html .= html_writer::tag('div', $this->output->render($continuebutton),
74 array('class' => 'continuebutton'));
75 return $html;
76 }
77
c48ab36a 78 /**
79 * The 'Next'/'more course result' link for a courses search
80 * @param array $data - the form parameter to execute the search on more result
81 * @return string html code
82 */
83 public function next_button($data) {
84 $nextlink = html_writer::tag('a', get_string('next', 'block_community'),
85 array('href' => new moodle_url('', $data)));
86 return html_writer::tag('div', $nextlink, array( 'class' => 'nextlink'));
87 }
88
f5747998 89 /**
07ab0c80 90 * Display a list of courses
91 * @param array $courses
92 * @param boolean $withwriteaccess
b48c4478 93 * @param int $contextcourseid context course id
07ab0c80 94 * @return string
95 */
b48c4478 96 public function course_list($courses, $huburl, $contextcourseid) {
97 global $CFG;
07ab0c80 98
99 $renderedhtml = '';
100
07ab0c80 101 if (empty($courses)) {
9c7dcf0f 102 if (isset($courses)) {
103 $renderedhtml .= get_string('nocourse', 'block_community');
104 }
07ab0c80 105 } else {
1ce282c8 106 $courseiteration = 0;
07ab0c80 107 foreach ($courses as $course) {
1ce282c8 108 $course = (object) $course;
109 $courseiteration = $courseiteration + 1;
07ab0c80 110
1ce282c8 111 //create visit link html
07ab0c80 112 if (!empty($course->courseurl)) {
113 $courseurl = new moodle_url($course->courseurl);
1ce282c8 114 $linktext = get_string('visitsite', 'block_community');
07ab0c80 115 } else {
116 $courseurl = new moodle_url($course->demourl);
1ce282c8 117 $linktext = get_string('visitdemo', 'block_community');
07ab0c80 118 }
07ab0c80 119
1ce282c8 120 $visitlinkhtml = html_writer::tag('a', $linktext,
fb6b4542 121 array('href' => $courseurl, 'class' => 'hubcoursedownload',
122 'onclick' => 'this.target="_blank"'));
07ab0c80 123
1ce282c8 124 //create title html
125 $coursename = html_writer::tag('h3', $course->fullname,
126 array('class' => 'hubcoursetitle'));
20e033bd 127 $coursenamehtml = html_writer::tag('div', $coursename,
128 array('class' => 'hubcoursetitlepanel'));
07ab0c80 129
1ce282c8 130 // create screenshots html
9c7dcf0f 131 $screenshothtml = '';
132 if (!empty($course->screenshots)) {
b48c4478 133 $baseurl = new moodle_url($huburl . '/local/hub/webservice/download.php',
134 array('courseid' => $course->id,
135 'filetype' => HUB_SCREENSHOT_FILE_TYPE));
20e033bd 136 $screenshothtml = html_writer::empty_tag('img',
137 array('src' => $baseurl, 'alt' => $course->fullname));
9c7dcf0f 138 }
1ce282c8 139 $coursescreenshot = html_writer::tag('div', $screenshothtml,
20e033bd 140 array('class' => 'coursescreenshot',
141 'id' => 'image-' . $course->id));
1ce282c8 142
143 //create description html
144 $deschtml = html_writer::tag('div', $course->description,
145 array('class' => 'hubcoursedescription'));
146
147 //create users related information html
8a3b20ce 148 $courseuserinfo = get_string('userinfo', 'block_community', $course);
b48c4478 149 if ($course->contributornames) {
8a3b20ce 150 $courseuserinfo .= ' - ' . get_string('contributors', 'block_community',
1ce282c8 151 $course->contributornames);
76be2d4e 152 }
1ce282c8 153 $courseuserinfohtml = html_writer::tag('div', $courseuserinfo,
154 array('class' => 'hubcourseuserinfo'));
155
156 //create course content related information html
157 $course->subject = get_string($course->subject, 'edufields');
158 $course->audience = get_string('audience' . $course->audience, 'hub');
159 $course->educationallevel = get_string('edulevel' . $course->educationallevel, 'hub');
81da6918 160 $coursecontentinfo = '';
1ce282c8 161 if (empty($course->coverage)) {
162 $course->coverage = '';
163 } else {
164 $coursecontentinfo .= get_string('coverage', 'block_community', $course->coverage);
165 $coursecontentinfo .= ' - ';
76be2d4e 166 }
81da6918 167 $coursecontentinfo .= get_string('contentinfo', 'block_community', $course);
1ce282c8 168 $coursecontentinfohtml = html_writer::tag('div', $coursecontentinfo,
169 array('class' => 'hubcoursecontentinfo'));
170
171 ///create course file related information html
172 //language
9c7dcf0f 173 if (!empty($course->language)) {
174 $languages = get_string_manager()->get_list_of_languages();
1ce282c8 175 $course->lang = $languages[$course->language];
9c7dcf0f 176 } else {
177 $course->lang = '';
178 }
437c2b85 179 //licence
a8e174cc 180 require_once($CFG->libdir . "/licenselib.php");
437c2b85 181 $licensemanager = new license_manager();
182 $licenses = $licensemanager->get_licenses();
183 foreach ($licenses as $license) {
184 if ($license->shortname == $course->licenceshortname) {
185 $course->license = $license->fullname;
186 }
187 }
1ce282c8 188 $course->timeupdated = userdate($course->timemodified);
189 $coursefileinfo = get_string('fileinfo', 'block_community', $course);
190 $coursefileinfohtml = html_writer::tag('div', $coursefileinfo,
191 array('class' => 'hubcoursefileinfo'));
9c7dcf0f 192
437c2b85 193
194
1ce282c8 195 //Create course content html
bab04a6d 196 if (!empty($course->contents)) {
197 $activitieshtml = '';
198 $blockhtml = '';
199 foreach ($course->contents as $content) {
1ce282c8 200 $content = (object) $content;
201 if ($content->moduletype == 'block') {
76be2d4e 202 if (!empty($blockhtml)) {
203 $blockhtml .= ' - ';
204 }
1ce282c8 205 $blockhtml .= get_string('pluginname', 'block_' . $content->modulename)
206 . " (" . $content->contentcount . ")";
bab04a6d 207 } else {
76be2d4e 208 if (!empty($activitieshtml)) {
209 $activitieshtml .= ' - ';
210 }
1ce282c8 211 $activitieshtml .= get_string('modulename', $content->modulename)
212 . " (" . $content->contentcount . ")";
bab04a6d 213 }
214 }
07ab0c80 215
1ce282c8 216 $blocksandactivities = html_writer::tag('div',
217 get_string('activities', 'block_community') . " : " . $activitieshtml);
218
219 //Uncomment following lines to display blocks information
220// $blocksandactivities .= html_writer::tag('span',
221// get_string('blocks', 'block_community') . " : " . $blockhtml);
222 }
b48c4478 223
914ffb4a 224 //Create outcomes html
225 $outcomes= '';
226 if (!empty($course->outcomes)) {
227 foreach ($course->outcomes as $outcome) {
228 if (!empty($outcomes)) {
229 $outcomes .= ', ';
230 }
231 $outcomes .= $outcome['fullname'];
232 }
233 $outcomes = get_string('outcomes', 'block_community',
234 $outcomes);
235 }
236 $outcomeshtml = html_writer::tag('div', $outcomes, array('class' => 'hubcourseoutcomes'));
237
1ce282c8 238 //create additional information html
239 $additionaldesc = $courseuserinfohtml . $coursecontentinfohtml
914ffb4a 240 . $coursefileinfohtml . $blocksandactivities . $outcomeshtml;
1ce282c8 241 $additionaldeschtml = html_writer::tag('div', $additionaldesc,
242 array('class' => 'additionaldesc'));
07ab0c80 243
1ce282c8 244 //Create add button html
245 $addbuttonhtml = "";
f5747998 246 if ($course->enrollable) {
78f00eab 247 $params = array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1,
f5747998 248 'coursefullname' => $course->fullname, 'courseurl' => $courseurl,
b48c4478 249 'coursedescription' => $course->description,
250 'courseid' => $contextcourseid);
78f00eab 251 $addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
1ce282c8 252 $addbuttonhtml = html_writer::tag('a',
253 get_string('addtocommunityblock', 'block_community'),
254 array('href' => $addurl, 'class' => 'centeredbutton, hubcoursedownload'));
255 }
256
257 //create download button html
258 $downloadbuttonhtml = "";
259 if (!$course->enrollable) {
78f00eab 260 $params = array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
b48c4478 261 'remotemoodleurl' => $CFG->wwwroot, 'courseid' => $contextcourseid,
262 'downloadcourseid' => $course->id, 'huburl' => $huburl,
19eb73cd 263 'coursefullname' => $course->fullname, 'backupsize' => $course->backupsize);
1ce282c8 264 $downloadurl = new moodle_url("/blocks/community/communitycourse.php", $params);
265 $downloadbuttonhtml = html_writer::tag('a', get_string('download', 'block_community'),
266 array('href' => $downloadurl, 'class' => 'centeredbutton, hubcoursedownload'));
267 }
268
269 //Create rating html
270 $rating = html_writer::tag('div', get_string('noratings', 'block_community'),
271 array('class' => 'norating'));
272 if (!empty($course->rating)) {
273 $course->rating = (object) $course->rating;
274 if ($course->rating->count > 0) {
275
276 //calculate size of the rating star
277 $starimagesize = 20; //in px
278 $numberofstars = 5;
279 $size = ($course->rating->aggregate / $course->rating->scaleid)
280 * $numberofstars * $starimagesize;
281 $rating = html_writer::tag('li', '',
282 array('class' => 'current-rating',
283 'style' => 'width:' . $size . 'px;'));
284
fb6b4542 285 $rating = html_writer::tag('ul', $rating,
1ce282c8 286 array('class' => 'star-rating clearfix'));
fb6b4542 287 $rating .= html_writer::tag('div', ' (' . $course->rating->count . ')',
288 array('class' => 'ratingcount clearfix'));
1ce282c8 289 }
07ab0c80 290 }
291
b48c4478 292
1ce282c8 293 //Create comments html
294 $coursecomments = html_writer::tag('div', get_string('nocomments', 'block_community'),
295 array('class' => 'nocomments'));
296 $commentcount = 0;
297 if (!empty($course->comments)) {
298 //display only if there is some comment if there is some comment
299 $commentcount = count($course->comments);
300 $coursecomments = html_writer::tag('div',
fb6b4542 301 get_string('comments', 'block_community', $commentcount),
302 array('class' => 'commenttitle'));
1ce282c8 303
304 foreach ($course->comments as $comment) {
305 $commentator = html_writer::tag('div',
306 $comment['commentator'],
307 array('class' => 'hubcommentator'));
308 $commentdate = html_writer::tag('div',
309 ' - ' . userdate($comment['date'], '%e/%m/%y'),
310 array('class' => 'hubcommentdate clearfix'));
fb6b4542 311
1ce282c8 312 $commenttext = html_writer::tag('div',
313 $comment['comment'],
314 array('class' => 'hubcommenttext'));
fb6b4542 315
1ce282c8 316 $coursecomments .= html_writer::tag('div',
317 $commentator . $commentdate . $commenttext,
318 array('class' => 'hubcomment'));
319 }
320 $coursecommenticon = html_writer::tag('div',
321 get_string('comments', 'block_community', $commentcount),
322 array('class' => 'hubcoursecomments',
323 'id' => 'comments-' . $course->id));
324 $coursecomments = $coursecommenticon . html_writer::tag('div',
325 $coursecomments,
326 array('class' => 'yui3-overlay-loading',
fb6b4542 327 'id' => 'commentoverlay-' . $course->id));
1ce282c8 328 }
329
fb6b4542 330 //link rate and comment
331 $rateandcomment = html_writer::tag('div',
332 html_writer::tag('a', get_string('rateandcomment', 'block_community'),
333 array('href' => new moodle_url($huburl,
09d2da6e 334 array('courseid' => $course->id, 'mustbelogged' => true)),
fb6b4542 335 'onclick' => 'this.target="_blank"')),
336 array('class' => 'hubrateandcomment'));
337
1ce282c8 338 //the main DIV tags
339 $buttonsdiv = html_writer::tag('div',
340 $addbuttonhtml . $downloadbuttonhtml . $visitlinkhtml,
341 array('class' => 'courseoperations'));
342 $screenshotbuttonsdiv = html_writer::tag('div',
343 $coursescreenshot . $buttonsdiv,
344 array('class' => 'courselinks'));
345
346 $coursedescdiv = html_writer::tag('div',
347 $deschtml . $additionaldeschtml
fb6b4542 348 . $rating . $coursecomments . $rateandcomment,
1ce282c8 349 array('class' => 'coursedescription'));
350 $coursehtml =
351 $coursenamehtml . html_writer::tag('div',
352 $coursedescdiv . $screenshotbuttonsdiv,
353 array('class' => 'hubcourseinfo clearfix'));
354
355 $renderedhtml .=html_writer::tag('div', $coursehtml,
356 array('class' => 'fullhubcourse clearfix'));
07ab0c80 357 }
1ce282c8 358
359 $renderedhtml = html_writer::tag('div', $renderedhtml,
360 array('class' => 'hubcourseresult'));
07ab0c80 361 }
1ce282c8 362
07ab0c80 363 return $renderedhtml;
364 }
365
2a102b90 366}