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