MDL-31831 whitespace clean - take2
[moodle.git] / blocks / community / renderer.php
blob4fb6c508bf03dcca7cf17fc12ca518788cc0fb32
1 <?php
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 ///////////////////////////////////////////////////////////////////////////
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
31 class block_community_renderer extends plugin_renderer_base {
33 public function restore_confirmation_box($filename, $context) {
34 $restoreurl = new moodle_url('/backup/restore.php',
35 array('filename' => $filename . ".mbz", 'contextid' => $context->id));
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);
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
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;
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
68 public function save_link_success(moodle_url $url) {
69 $html = $this->output->notification(get_string('addedtoblock', 'block_community'),
70 'notifysuccess');
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;
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
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'));
89 /**
90 * Display a list of courses
91 * @param array $courses
92 * @param boolean $withwriteaccess
93 * @param int $contextcourseid context course id
94 * @return string
96 public function course_list($courses, $huburl, $contextcourseid) {
97 global $CFG;
99 $renderedhtml = '';
101 if (empty($courses)) {
102 if (isset($courses)) {
103 $renderedhtml .= get_string('nocourse', 'block_community');
105 } else {
106 $courseiteration = 0;
107 foreach ($courses as $course) {
108 $course = (object) $course;
109 $courseiteration = $courseiteration + 1;
111 //create visit link html
112 if (!empty($course->courseurl)) {
113 $courseurl = new moodle_url($course->courseurl);
114 $linktext = get_string('visitsite', 'block_community');
115 } else {
116 $courseurl = new moodle_url($course->demourl);
117 $linktext = get_string('visitdemo', 'block_community');
120 $visitlinkhtml = html_writer::tag('a', $linktext,
121 array('href' => $courseurl, 'class' => 'hubcoursedownload',
122 'onclick' => 'this.target="_blank"'));
124 //create title html
125 $coursename = html_writer::tag('h3', $course->fullname,
126 array('class' => 'hubcoursetitle'));
127 $coursenamehtml = html_writer::tag('div', $coursename,
128 array('class' => 'hubcoursetitlepanel'));
130 // create screenshots html
131 $screenshothtml = '';
132 if (!empty($course->screenshots)) {
133 $baseurl = new moodle_url($huburl . '/local/hub/webservice/download.php',
134 array('courseid' => $course->id,
135 'filetype' => HUB_SCREENSHOT_FILE_TYPE));
136 $screenshothtml = html_writer::empty_tag('img',
137 array('src' => $baseurl, 'alt' => $course->fullname));
139 $coursescreenshot = html_writer::tag('div', $screenshothtml,
140 array('class' => 'coursescreenshot',
141 'id' => 'image-' . $course->id));
143 //create description html
144 $deschtml = html_writer::tag('div', $course->description,
145 array('class' => 'hubcoursedescription'));
147 //create users related information html
148 $courseuserinfo = get_string('userinfo', 'block_community', $course);
149 if ($course->contributornames) {
150 $courseuserinfo .= ' - ' . get_string('contributors', 'block_community',
151 $course->contributornames);
153 $courseuserinfohtml = html_writer::tag('div', $courseuserinfo,
154 array('class' => 'hubcourseuserinfo'));
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');
160 $coursecontentinfo = '';
161 if (empty($course->coverage)) {
162 $course->coverage = '';
163 } else {
164 $coursecontentinfo .= get_string('coverage', 'block_community', $course->coverage);
165 $coursecontentinfo .= ' - ';
167 $coursecontentinfo .= get_string('contentinfo', 'block_community', $course);
168 $coursecontentinfohtml = html_writer::tag('div', $coursecontentinfo,
169 array('class' => 'hubcoursecontentinfo'));
171 ///create course file related information html
172 //language
173 if (!empty($course->language)) {
174 $languages = get_string_manager()->get_list_of_languages();
175 $course->lang = $languages[$course->language];
176 } else {
177 $course->lang = '';
179 //licence
180 require_once($CFG->libdir . "/licenselib.php");
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;
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'));
195 //Create course content html
196 $blocks = get_plugin_list('block');
197 $activities = get_plugin_list('mod');
198 if (!empty($course->contents)) {
199 $activitieshtml = '';
200 $blockhtml = '';
201 foreach ($course->contents as $content) {
202 $content = (object) $content;
203 if ($content->moduletype == 'block') {
204 if (!empty($blockhtml)) {
205 $blockhtml .= ' - ';
207 if (array_key_exists($content->modulename, $blocks)) {
208 $blockname = get_string('pluginname', 'block_' . $content->modulename);
209 } else {
210 $blockname = $content->modulename;
212 $blockhtml .= $blockname . " (" . $content->contentcount . ")";
213 } else {
214 if (!empty($activitieshtml)) {
215 $activitieshtml .= ' - ';
217 if (array_key_exists($content->modulename, $activities)) {
218 $activityname = get_string('modulename', $content->modulename);
219 } else {
220 $activityname = $content->modulename;
222 $activitieshtml .= $activityname . " (" . $content->contentcount . ")";
226 $blocksandactivities = html_writer::tag('div',
227 get_string('activities', 'block_community') . " : " . $activitieshtml);
229 //Uncomment following lines to display blocks information
230 // $blocksandactivities .= html_writer::tag('span',
231 // get_string('blocks', 'block_community') . " : " . $blockhtml);
234 //Create outcomes html
235 $outcomes= '';
236 if (!empty($course->outcomes)) {
237 foreach ($course->outcomes as $outcome) {
238 if (!empty($outcomes)) {
239 $outcomes .= ', ';
241 $outcomes .= $outcome['fullname'];
243 $outcomes = get_string('outcomes', 'block_community',
244 $outcomes);
246 $outcomeshtml = html_writer::tag('div', $outcomes, array('class' => 'hubcourseoutcomes'));
248 //create additional information html
249 $additionaldesc = $courseuserinfohtml . $coursecontentinfohtml
250 . $coursefileinfohtml . $blocksandactivities . $outcomeshtml;
251 $additionaldeschtml = html_writer::tag('div', $additionaldesc,
252 array('class' => 'additionaldesc'));
254 //Create add button html
255 $addbuttonhtml = "";
256 if ($course->enrollable) {
257 $params = array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1,
258 'coursefullname' => $course->fullname, 'courseurl' => $courseurl,
259 'coursedescription' => $course->description,
260 'courseid' => $contextcourseid);
261 $addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
262 $addbuttonhtml = html_writer::tag('a',
263 get_string('addtocommunityblock', 'block_community'),
264 array('href' => $addurl, 'class' => 'centeredbutton, hubcoursedownload'));
267 //create download button html
268 $downloadbuttonhtml = "";
269 if (!$course->enrollable) {
270 $params = array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
271 'remotemoodleurl' => $CFG->wwwroot, 'courseid' => $contextcourseid,
272 'downloadcourseid' => $course->id, 'huburl' => $huburl,
273 'coursefullname' => $course->fullname, 'backupsize' => $course->backupsize);
274 $downloadurl = new moodle_url("/blocks/community/communitycourse.php", $params);
275 $downloadbuttonhtml = html_writer::tag('a', get_string('download', 'block_community'),
276 array('href' => $downloadurl, 'class' => 'centeredbutton, hubcoursedownload'));
279 //Create rating html
280 $rating = html_writer::tag('div', get_string('noratings', 'block_community'),
281 array('class' => 'norating'));
282 if (!empty($course->rating)) {
283 $course->rating = (object) $course->rating;
284 if ($course->rating->count > 0) {
286 //calculate size of the rating star
287 $starimagesize = 20; //in px
288 $numberofstars = 5;
289 $size = ($course->rating->aggregate / $course->rating->scaleid)
290 * $numberofstars * $starimagesize;
291 $rating = html_writer::tag('li', '',
292 array('class' => 'current-rating',
293 'style' => 'width:' . $size . 'px;'));
295 $rating = html_writer::tag('ul', $rating,
296 array('class' => 'star-rating clearfix'));
297 $rating .= html_writer::tag('div', ' (' . $course->rating->count . ')',
298 array('class' => 'ratingcount clearfix'));
303 //Create comments html
304 $coursecomments = html_writer::tag('div', get_string('nocomments', 'block_community'),
305 array('class' => 'nocomments'));
306 $commentcount = 0;
307 if (!empty($course->comments)) {
308 //display only if there is some comment if there is some comment
309 $commentcount = count($course->comments);
310 $coursecomments = html_writer::tag('div',
311 get_string('comments', 'block_community', $commentcount),
312 array('class' => 'commenttitle'));
314 foreach ($course->comments as $comment) {
315 $commentator = html_writer::tag('div',
316 $comment['commentator'],
317 array('class' => 'hubcommentator'));
318 $commentdate = html_writer::tag('div',
319 ' - ' . userdate($comment['date'], '%e/%m/%y'),
320 array('class' => 'hubcommentdate clearfix'));
322 $commenttext = html_writer::tag('div',
323 $comment['comment'],
324 array('class' => 'hubcommenttext'));
326 $coursecomments .= html_writer::tag('div',
327 $commentator . $commentdate . $commenttext,
328 array('class' => 'hubcomment'));
330 $coursecommenticon = html_writer::tag('div',
331 get_string('comments', 'block_community', $commentcount),
332 array('class' => 'hubcoursecomments',
333 'id' => 'comments-' . $course->id));
334 $coursecomments = $coursecommenticon . html_writer::tag('div',
335 $coursecomments,
336 array('class' => 'yui3-overlay-loading',
337 'id' => 'commentoverlay-' . $course->id));
340 //link rate and comment
341 $rateandcomment = html_writer::tag('div',
342 html_writer::tag('a', get_string('rateandcomment', 'block_community'),
343 array('href' => new moodle_url($huburl,
344 array('courseid' => $course->id, 'mustbelogged' => true)),
345 'onclick' => 'this.target="_blank"')),
346 array('class' => 'hubrateandcomment'));
348 //the main DIV tags
349 $buttonsdiv = html_writer::tag('div',
350 $addbuttonhtml . $downloadbuttonhtml . $visitlinkhtml,
351 array('class' => 'courseoperations'));
352 $screenshotbuttonsdiv = html_writer::tag('div',
353 $coursescreenshot . $buttonsdiv,
354 array('class' => 'courselinks'));
356 $coursedescdiv = html_writer::tag('div',
357 $deschtml . $additionaldeschtml
358 . $rating . $coursecomments . $rateandcomment,
359 array('class' => 'coursedescription'));
360 $coursehtml =
361 $coursenamehtml . html_writer::tag('div',
362 $coursedescdiv . $screenshotbuttonsdiv,
363 array('class' => 'hubcourseinfo clearfix'));
365 $renderedhtml .=html_writer::tag('div', $coursehtml,
366 array('class' => 'fullhubcourse clearfix'));
369 $renderedhtml = html_writer::tag('div', $renderedhtml,
370 array('class' => 'hubcourseresult'));
373 return $renderedhtml;