MDL-18797 The selected language pack fetched during install
[moodle.git] / blocks / community / renderer.php
CommitLineData
07ab0c80 1<?php
2///////////////////////////////////////////////////////////////////////////
3// //
4// This file is part of Moodle - http://moodle.org/ //
5// Moodle - Modular Object-Oriented Dynamic Learning Environment //
6// //
7// Moodle is free software: you can redistribute it and/or modify //
8// it under the terms of the GNU General Public License as published by //
9// the Free Software Foundation, either version 3 of the License, or //
10// (at your option) any later version. //
11// //
12// Moodle is distributed in the hope that it will be useful, //
13// but WITHOUT ANY WARRANTY; without even the implied warranty of //
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
15// GNU General Public License for more details. //
16// //
17// You should have received a copy of the GNU General Public License //
18// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
19// //
20///////////////////////////////////////////////////////////////////////////
21
22/**
23 * Block community renderer.
24 * @package blocks
25 * @subpackage community
26 * @copyright 2010 Moodle Pty Ltd (http://moodle.com)
27 * @author Jerome Mouneyrac
28 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 */
30class block_community_renderer extends plugin_renderer_base {
31
32 /**
33 * Display a list of courses
34 * @param array $courses
35 * @param boolean $withwriteaccess
36 * @return string
37 */
38 public function course_list($courses, $huburl) {
39 global $OUTPUT, $CFG;
40
41 $renderedhtml = '';
42
43 $table = new html_table();
44
45
46 $table->head = array(get_string('coursename', 'block_community'),
47 get_string('coursedesc', 'block_community'),
48 get_string('courselang', 'block_community'),
49 get_string('operation', 'block_community'));
50
51 $table->align = array('left', 'left', 'center', 'center');
52 $table->size = array('25%', '40%', '5%', '%5');
53
54
55 if (empty($courses)) {
f1b4e19e 56 if (isset($courses)) {
57 $renderedhtml .= get_string('nocourse', 'block_community');
58 }
07ab0c80 59 } else {
60
61 $table->width = '100%';
62 $table->data = array();
63 $table->attributes['class'] = 'sitedirectory';
64
65 // iterate through sites and add to the display table
66 foreach ($courses as $course) {
67
68 if (is_array($course)) {
69 $course = (object) $course;
70 }
71
72 //create site name with link
73 if (!empty($course->courseurl)) {
74 $courseurl = new moodle_url($course->courseurl);
75 } else {
76 $courseurl = new moodle_url($course->demourl);
77 }
78 $courseatag = html_writer::tag('a', $course->fullname, array('href' => $courseurl));
79
80 $coursenamehtml = html_writer::tag('span', $courseatag, array());
81
82
83 //create description to display
276f590e 84 $course->subject = get_string($course->subject, 'edufields');
db38fcb7 85 $course->audience = get_string('audience'.$course->audience, 'hub');
86 $course->educationallevel = get_string('edulevel'.$course->educationallevel, 'hub');
87 if (!empty($course->contributornames)) {
88 $course->contributorname = get_string('contributors', 'block_community', $course->contributorname);
89 }
90 if (!empty($course->coverage)) {
91 $course->coverage = get_string('coverage', 'block_community', $course->coverage);
92 }
07ab0c80 93 $deschtml = $course->description; //the description
94 /// courses and sites number display under the description, in smaller
95 $deschtml .= html_writer::empty_tag('br');
96 $additionaldesc = get_string('additionalcoursedesc', 'block_community', $course);
97 $deschtml .= html_writer::tag('span', $additionaldesc, array('class' => 'additionaldesc'));
98
99 //retrieve language string
100 //construct languages array
101 if (!empty($course->language)) {
102 $languages = get_string_manager()->get_list_of_languages();
103 $language = $languages[$course->language];
104 } else {
105 $language= '';
106 }
107
78f00eab 108 if ($course->enrollable) {
109 $params = array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1,
07ab0c80 110 'coursefullname' => $course->fullname, 'courseurl' => $courseurl,
78f00eab 111 'coursedescription' => $course->description);
112 $addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
113 $addbutton = new single_button($addurl, get_string('addtocommunityblock', 'block_community'));
114 $addbutton->class = 'centeredbutton';
115 $addbuttonhtml = $OUTPUT->render($addbutton);
07ab0c80 116 } else {
78f00eab 117 $params = array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
118 'courseid' => $course->id, 'huburl' => $huburl, 'coursefullname' => $course->fullname);
119 $addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
120 $downloadbutton = new single_button($addurl, get_string('download', 'block_community'));
121 $downloadbutton->class = 'centeredbutton';
122 $addbuttonhtml = $OUTPUT->render($downloadbutton);
07ab0c80 123 }
124
125 // add a row to the table
78f00eab 126 $cells = array($coursenamehtml, $deschtml, $language, $addbuttonhtml);
07ab0c80 127
128
129 $row = new html_table_row($cells);
130
131 $table->data[] = $row;
132 }
133 $renderedhtml .= html_writer::table($table);
134 }
135 return $renderedhtml;
136 }
137
138}