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