MDL-23371 reverting last commit in this file, this was most probably unintentional...
[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');
8afbe765 109 $course->educationallevel = get_string('edulevel' . $course->educationallevel, 'hub');
9c7dcf0f 110 $deschtml .= $course->description; //the description
07ab0c80 111 /// courses and sites number display under the description, in smaller
112 $deschtml .= html_writer::empty_tag('br');
9c7dcf0f 113 $additionaldesc = '';
114 if ($course->contributornames) {
76be2d4e 115 $additionaldesc .= get_string('contributors', 'block_community', $course->contributornames);
116 $additionaldesc .= ' - ';
117 }
118 if ($course->coverage) {
119 $additionaldesc .= get_string('coverage', 'block_community', $course->coverage);
120 $additionaldesc .= ' - ';
121 }
9c7dcf0f 122 //retrieve language string
9c7dcf0f 123 if (!empty($course->language)) {
124 $languages = get_string_manager()->get_list_of_languages();
125 $course->lang = get_string('langdesc', 'block_community', $languages[$course->language]);
126 } else {
127 $course->lang = '';
128 }
437c2b85 129
130 //licence
131 require_once($CFG->dirroot . "/lib/licenselib.php");
132 $licensemanager = new license_manager();
133 $licenses = $licensemanager->get_licenses();
134 foreach ($licenses as $license) {
135 if ($license->shortname == $course->licenceshortname) {
136 $course->license = $license->fullname;
137 }
138 }
139
9c7dcf0f 140 $additionaldesc .= get_string('additionalcoursedesc', 'block_community', $course);
141
437c2b85 142
143
07ab0c80 144 $deschtml .= html_writer::tag('span', $additionaldesc, array('class' => 'additionaldesc'));
f5747998 145 //add content to the course description
bab04a6d 146 if (!empty($course->contents)) {
147 $activitieshtml = '';
148 $blockhtml = '';
149 foreach ($course->contents as $content) {
150 if ($content['moduletype'] == 'block') {
76be2d4e 151 if (!empty($blockhtml)) {
152 $blockhtml .= ' - ';
153 }
154 $blockhtml .= get_string('pluginname', 'block_'.$content['modulename']). " (".$content['contentcount'].")";
bab04a6d 155 } else {
76be2d4e 156 if (!empty($activitieshtml)) {
157 $activitieshtml .= ' - ';
158 }
159 $activitieshtml .= get_string('modulename', $content['modulename']). " (".$content['contentcount'].")";
bab04a6d 160 }
161 }
76be2d4e 162 $blocksandactivities = html_writer::tag('span',
9c7dcf0f 163 get_string('activities', 'block_community')." : ". $activitieshtml);
76be2d4e 164 $blocksandactivities .= html_writer::empty_tag('br').html_writer::tag('span',
9c7dcf0f 165 get_string('blocks', 'block_community')." : ". $blockhtml);
76be2d4e 166
167 $deschtml .= print_collapsible_region($blocksandactivities, 'blockdescription',
770f7e24 168 'blocksandactivities-'.$course->id.'-'.clean_param($courseurl, PARAM_ALPHANUMEXT),
169 get_string('moredetails','block_community'), '', false,true);
bab04a6d 170 }
07ab0c80 171
9c7dcf0f 172
07ab0c80 173
f5747998 174 if ($course->enrollable) {
78f00eab 175 $params = array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1,
f5747998 176 'coursefullname' => $course->fullname, 'courseurl' => $courseurl,
177 'coursedescription' => $course->description);
78f00eab 178 $addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
179 $addbutton = new single_button($addurl, get_string('addtocommunityblock', 'block_community'));
180 $addbutton->class = 'centeredbutton';
181 $addbuttonhtml = $OUTPUT->render($addbutton);
07ab0c80 182 } else {
78f00eab 183 $params = array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
718afe59 184 'remotemoodleurl' => $CFG->wwwroot,
f5747998 185 'courseid' => $course->id, 'huburl' => $huburl, 'coursefullname' => $course->fullname);
78f00eab 186 $addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
187 $downloadbutton = new single_button($addurl, get_string('download', 'block_community'));
188 $downloadbutton->class = 'centeredbutton';
189 $addbuttonhtml = $OUTPUT->render($downloadbutton);
07ab0c80 190 }
191
9c7dcf0f 192
193 $table->data[] = array($coursenamehtml, $deschtml, $addbuttonhtml);
07ab0c80 194 }
195 $renderedhtml .= html_writer::table($table);
196 }
197 return $renderedhtml;
198 }
199
2a102b90 200}