Assignment MDL-22893 oops, corrected the moodle_url instantiation to put param in...
[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
f5747998 33 /**
07ab0c80 34 * Display a list of courses
35 * @param array $courses
36 * @param boolean $withwriteaccess
37 * @return string
38 */
39 public function course_list($courses, $huburl) {
40 global $OUTPUT, $CFG;
41
42 $renderedhtml = '';
43
44 $table = new html_table();
45
46
2a102b90
SH
47 $table->head = array(
48 get_string('coursename', 'block_community'),
f5747998 49 get_string('coursedesc', 'block_community'),
2a102b90
SH
50 get_string('operation', 'block_community')
51 );
f5747998 52 $table->align = array('center', 'left', 'center', 'left', 'center');
53 $table->size = array('20%', '45%', '5%', '5%', '5%');
07ab0c80 54
07ab0c80 55
56
57 if (empty($courses)) {
9c7dcf0f 58 if (isset($courses)) {
59 $renderedhtml .= get_string('nocourse', 'block_community');
60 }
07ab0c80 61 } else {
62
63 $table->width = '100%';
f5747998 64 $table->data = array();
07ab0c80 65 $table->attributes['class'] = 'sitedirectory';
66
67 // iterate through sites and add to the display table
68 foreach ($courses as $course) {
69
70 if (is_array($course)) {
71 $course = (object) $course;
72 }
73
74 //create site name with link
75 if (!empty($course->courseurl)) {
76 $courseurl = new moodle_url($course->courseurl);
77 } else {
78 $courseurl = new moodle_url($course->demourl);
79 }
80 $courseatag = html_writer::tag('a', $course->fullname, array('href' => $courseurl));
81
82 $coursenamehtml = html_writer::tag('span', $courseatag, array());
83
84
9c7dcf0f 85 // add a row to the table
86 $screenshothtml = '';
87 if (!empty($course->screenshots)) {
88 $images = array();
89 $baseurl = new moodle_url($huburl.'/local/hub/webservice/download.php',
90 array('courseid' => $course->id, 'filetype' => HUB_SCREENSHOT_FILE_TYPE));
91 for ($i = 1; $i <= $course->screenshots; $i = $i + 1) {
92 $params['screenshotnumber'] = $i;
93 $images[] = array(
94 'thumburl' => new moodle_url($baseurl, array('screenshotnumber' => $i)),
95 'imageurl' => new moodle_url($baseurl, array('screenshotnumber' => $i, 'imagewidth' => 'original')),
96 'title' => $course->fullname,
97 'alt' => $course->fullname
98 );
99 }
100 $imagegallery = new image_gallery($images, $course->shortname);
101 $imagegallery->displayfirstimageonly = true;
102 $screenshothtml = $this->output->render($imagegallery);
103 }
104 $deschtml = html_writer::tag('div', $screenshothtml, array('class' => 'coursescreenshot'));
105
07ab0c80 106 //create description to display
276f590e 107 $course->subject = get_string($course->subject, 'edufields');
f5747998 108 $course->audience = get_string('audience' . $course->audience, 'hub');
109 $course->educationallevel = get_string('edulevel' . $course->educationallevel, 'hub');
db38fcb7 110 if (!empty($course->contributornames)) {
111 $course->contributorname = get_string('contributors', 'block_community', $course->contributorname);
112 }
113 if (!empty($course->coverage)) {
114 $course->coverage = get_string('coverage', 'block_community', $course->coverage);
115 }
9c7dcf0f 116 $deschtml .= $course->description; //the description
07ab0c80 117 /// courses and sites number display under the description, in smaller
118 $deschtml .= html_writer::empty_tag('br');
9c7dcf0f 119 $additionaldesc = '';
120 if ($course->contributornames) {
76be2d4e 121 $additionaldesc .= get_string('contributors', 'block_community', $course->contributornames);
122 $additionaldesc .= ' - ';
123 }
124 if ($course->coverage) {
125 $additionaldesc .= get_string('coverage', 'block_community', $course->coverage);
126 $additionaldesc .= ' - ';
127 }
9c7dcf0f 128 //retrieve language string
129 //construct languages array
130
131 if (!empty($course->language)) {
132 $languages = get_string_manager()->get_list_of_languages();
133 $course->lang = get_string('langdesc', 'block_community', $languages[$course->language]);
134 } else {
135 $course->lang = '';
136 }
137 $additionaldesc .= get_string('additionalcoursedesc', 'block_community', $course);
138
07ab0c80 139 $deschtml .= html_writer::tag('span', $additionaldesc, array('class' => 'additionaldesc'));
f5747998 140 //add content to the course description
bab04a6d 141 if (!empty($course->contents)) {
142 $activitieshtml = '';
143 $blockhtml = '';
144 foreach ($course->contents as $content) {
145 if ($content['moduletype'] == 'block') {
76be2d4e 146 if (!empty($blockhtml)) {
147 $blockhtml .= ' - ';
148 }
149 $blockhtml .= get_string('pluginname', 'block_'.$content['modulename']). " (".$content['contentcount'].")";
bab04a6d 150 } else {
76be2d4e 151 if (!empty($activitieshtml)) {
152 $activitieshtml .= ' - ';
153 }
154 $activitieshtml .= get_string('modulename', $content['modulename']). " (".$content['contentcount'].")";
bab04a6d 155 }
156 }
76be2d4e 157 $blocksandactivities = html_writer::tag('span',
9c7dcf0f 158 get_string('activities', 'block_community')." : ". $activitieshtml);
76be2d4e 159 $blocksandactivities .= html_writer::empty_tag('br').html_writer::tag('span',
9c7dcf0f 160 get_string('blocks', 'block_community')." : ". $blockhtml);
76be2d4e 161
162 $deschtml .= print_collapsible_region($blocksandactivities, 'blockdescription',
770f7e24 163 'blocksandactivities-'.$course->id.'-'.clean_param($courseurl, PARAM_ALPHANUMEXT),
164 get_string('moredetails','block_community'), '', false,true);
bab04a6d 165 }
07ab0c80 166
9c7dcf0f 167
07ab0c80 168
f5747998 169 if ($course->enrollable) {
78f00eab 170 $params = array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1,
f5747998 171 'coursefullname' => $course->fullname, 'courseurl' => $courseurl,
172 'coursedescription' => $course->description);
78f00eab 173 $addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
174 $addbutton = new single_button($addurl, get_string('addtocommunityblock', 'block_community'));
175 $addbutton->class = 'centeredbutton';
176 $addbuttonhtml = $OUTPUT->render($addbutton);
07ab0c80 177 } else {
78f00eab 178 $params = array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
718afe59 179 'remotemoodleurl' => $CFG->wwwroot,
f5747998 180 'courseid' => $course->id, 'huburl' => $huburl, 'coursefullname' => $course->fullname);
78f00eab 181 $addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
182 $downloadbutton = new single_button($addurl, get_string('download', 'block_community'));
183 $downloadbutton->class = 'centeredbutton';
184 $addbuttonhtml = $OUTPUT->render($downloadbutton);
07ab0c80 185 }
186
9c7dcf0f 187
188 $table->data[] = array($coursenamehtml, $deschtml, $addbuttonhtml);
07ab0c80 189 }
190 $renderedhtml .= html_writer::table($table);
191 }
192 return $renderedhtml;
193 }
194
2a102b90 195}