navigation MDL-22709 Implemented use of section names in course editing links code...
[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',
35 array('filename' => $filename.".zip", '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);
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
60 $table = new html_table();
61
62
2a102b90
SH
63 $table->head = array(
64 get_string('coursename', 'block_community'),
f5747998 65 get_string('coursedesc', 'block_community'),
2a102b90
SH
66 get_string('operation', 'block_community')
67 );
f5747998 68 $table->align = array('center', 'left', 'center', 'left', 'center');
69 $table->size = array('20%', '45%', '5%', '5%', '5%');
07ab0c80 70
07ab0c80 71
72
73 if (empty($courses)) {
9c7dcf0f 74 if (isset($courses)) {
75 $renderedhtml .= get_string('nocourse', 'block_community');
76 }
07ab0c80 77 } else {
78
79 $table->width = '100%';
f5747998 80 $table->data = array();
07ab0c80 81 $table->attributes['class'] = 'sitedirectory';
82
83 // iterate through sites and add to the display table
84 foreach ($courses as $course) {
85
86 if (is_array($course)) {
87 $course = (object) $course;
88 }
89
90 //create site name with link
91 if (!empty($course->courseurl)) {
92 $courseurl = new moodle_url($course->courseurl);
93 } else {
94 $courseurl = new moodle_url($course->demourl);
95 }
b48c4478 96 $courseatag = html_writer::tag('a', $course->fullname,
97 array('href' => $courseurl));
07ab0c80 98
99 $coursenamehtml = html_writer::tag('span', $courseatag, array());
100
101
9c7dcf0f 102 // add a row to the table
103 $screenshothtml = '';
104 if (!empty($course->screenshots)) {
105 $images = array();
b48c4478 106 $baseurl = new moodle_url($huburl . '/local/hub/webservice/download.php',
107 array('courseid' => $course->id,
108 'filetype' => HUB_SCREENSHOT_FILE_TYPE));
9c7dcf0f 109 for ($i = 1; $i <= $course->screenshots; $i = $i + 1) {
110 $params['screenshotnumber'] = $i;
111 $images[] = array(
b48c4478 112 'thumburl' => new moodle_url($baseurl,
113 array('screenshotnumber' => $i)),
114 'imageurl' => new moodle_url($baseurl,
115 array('screenshotnumber' => $i, 'imagewidth' => 'original')),
9c7dcf0f 116 'title' => $course->fullname,
117 'alt' => $course->fullname
118 );
119 }
120 $imagegallery = new image_gallery($images, $course->shortname);
121 $imagegallery->displayfirstimageonly = true;
122 $screenshothtml = $this->output->render($imagegallery);
123 }
b48c4478 124 $deschtml = html_writer::tag('div', $screenshothtml,
125 array('class' => 'coursescreenshot'));
9c7dcf0f 126
07ab0c80 127 //create description to display
276f590e 128 $course->subject = get_string($course->subject, 'edufields');
f5747998 129 $course->audience = get_string('audience' . $course->audience, 'hub');
b48c4478 130 $course->educationallevel = get_string('edulevel' .
131 $course->educationallevel, 'hub');
9c7dcf0f 132 $deschtml .= $course->description; //the description
07ab0c80 133 /// courses and sites number display under the description, in smaller
134 $deschtml .= html_writer::empty_tag('br');
9c7dcf0f 135 $additionaldesc = '';
b48c4478 136 if ($course->contributornames) {
137 $additionaldesc .= get_string('contributors',
138 'block_community', $course->contributornames);
76be2d4e 139 $additionaldesc .= ' - ';
140 }
141 if ($course->coverage) {
b48c4478 142 $additionaldesc .= get_string('coverage',
143 'block_community', $course->coverage);
76be2d4e 144 $additionaldesc .= ' - ';
145 }
9c7dcf0f 146 //retrieve language string
9c7dcf0f 147 if (!empty($course->language)) {
148 $languages = get_string_manager()->get_list_of_languages();
b48c4478 149 $course->lang = get_string('langdesc',
150 'block_community', $languages[$course->language]);
9c7dcf0f 151 } else {
152 $course->lang = '';
153 }
437c2b85 154
155 //licence
156 require_once($CFG->dirroot . "/lib/licenselib.php");
157 $licensemanager = new license_manager();
158 $licenses = $licensemanager->get_licenses();
159 foreach ($licenses as $license) {
160 if ($license->shortname == $course->licenceshortname) {
161 $course->license = $license->fullname;
162 }
163 }
164
b48c4478 165 $additionaldesc .= get_string('additionalcoursedesc',
166 'block_community', $course);
9c7dcf0f 167
437c2b85 168
169
b48c4478 170 $deschtml .= html_writer::tag('span', $additionaldesc,
171 array('class' => 'additionaldesc'));
f5747998 172 //add content to the course description
bab04a6d 173 if (!empty($course->contents)) {
174 $activitieshtml = '';
175 $blockhtml = '';
176 foreach ($course->contents as $content) {
177 if ($content['moduletype'] == 'block') {
76be2d4e 178 if (!empty($blockhtml)) {
179 $blockhtml .= ' - ';
180 }
b48c4478 181 $blockhtml .= get_string('pluginname',
182 'block_' . $content['modulename'])
183 . " (" . $content['contentcount'] . ")";
bab04a6d 184 } else {
76be2d4e 185 if (!empty($activitieshtml)) {
186 $activitieshtml .= ' - ';
187 }
b48c4478 188 $activitieshtml .= get_string('modulename',
189 $content['modulename']) . " ("
190 . $content['contentcount'] . ")";
bab04a6d 191 }
192 }
76be2d4e 193 $blocksandactivities = html_writer::tag('span',
b48c4478 194 get_string('activities', 'block_community')
195 . " : " . $activitieshtml);
196 $blocksandactivities .= html_writer::empty_tag('br') . html_writer::tag('span',
197 get_string('blocks', 'block_community')
198 . " : " . $blockhtml);
76be2d4e 199
200 $deschtml .= print_collapsible_region($blocksandactivities, 'blockdescription',
b48c4478 201 'blocksandactivities-' . $course->id . '-'
202 . clean_param($courseurl, PARAM_ALPHANUMEXT),
203 get_string('moredetails', 'block_community'), '', false, true);
bab04a6d 204 }
07ab0c80 205
b48c4478 206
07ab0c80 207
f5747998 208 if ($course->enrollable) {
78f00eab 209 $params = array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1,
f5747998 210 'coursefullname' => $course->fullname, 'courseurl' => $courseurl,
b48c4478 211 'coursedescription' => $course->description,
212 'courseid' => $contextcourseid);
78f00eab 213 $addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
b48c4478 214 $addbutton = new single_button($addurl,
215 get_string('addtocommunityblock', 'block_community'));
78f00eab 216 $addbutton->class = 'centeredbutton';
b48c4478 217 $addbuttonhtml = $this->output->render($addbutton);
07ab0c80 218 } else {
78f00eab 219 $params = array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
b48c4478 220 'remotemoodleurl' => $CFG->wwwroot, 'courseid' => $contextcourseid,
221 'downloadcourseid' => $course->id, 'huburl' => $huburl,
222 'coursefullname' => $course->fullname);
78f00eab 223 $addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
b48c4478 224 $downloadbutton = new single_button($addurl,
225 get_string('download', 'block_community'));
78f00eab 226 $downloadbutton->class = 'centeredbutton';
b48c4478 227 $addbuttonhtml = $this->output->render($downloadbutton);
07ab0c80 228 }
229
b48c4478 230
9c7dcf0f 231 $table->data[] = array($coursenamehtml, $deschtml, $addbuttonhtml);
07ab0c80 232 }
233 $renderedhtml .= html_writer::table($table);
234 }
235 return $renderedhtml;
236 }
237
2a102b90 238}