hub MDL-19309 new site registration form + course publication + community block
[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)) {
56 $renderedhtml .= get_string('nocourse', 'block_community');
57 } else {
58
59 $table->width = '100%';
60 $table->data = array();
61 $table->attributes['class'] = 'sitedirectory';
62
63 // iterate through sites and add to the display table
64 foreach ($courses as $course) {
65
66 if (is_array($course)) {
67 $course = (object) $course;
68 }
69
70 //create site name with link
71 if (!empty($course->courseurl)) {
72 $courseurl = new moodle_url($course->courseurl);
73 } else {
74 $courseurl = new moodle_url($course->demourl);
75 }
76 $courseatag = html_writer::tag('a', $course->fullname, array('href' => $courseurl));
77
78 $coursenamehtml = html_writer::tag('span', $courseatag, array());
79
80
81 //create description to display
82 $deschtml = $course->description; //the description
83 /// courses and sites number display under the description, in smaller
84 $deschtml .= html_writer::empty_tag('br');
85 $additionaldesc = get_string('additionalcoursedesc', 'block_community', $course);
86 $deschtml .= html_writer::tag('span', $additionaldesc, array('class' => 'additionaldesc'));
87
88 //retrieve language string
89 //construct languages array
90 if (!empty($course->language)) {
91 $languages = get_string_manager()->get_list_of_languages();
92 $language = $languages[$course->language];
93 } else {
94 $language= '';
95 }
96
97 if ($course->enrollable) {
98 //Add link TODO make it a button and send by post
99 $addurl = new moodle_url("/blocks/community/communitycourse.php",
100 array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1,
101 'coursefullname' => $course->fullname, 'courseurl' => $courseurl,
102 'coursedescription' => $course->description));
103 $addlinkhtml = html_writer::tag('a', get_string('add'), array('href' => $addurl));
104 } else {
105 //Add link TODO make it a button and send by post
106// $addurl = new moodle_url("/blocks/community/communitycourse.php",
107// array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
108// 'courseid' => $course->id, 'huburl' => $huburl));
109// $addlinkhtml = html_writer::tag('a', get_string('download', 'block_community'), array('href' => $addurl));
110
111 $addlinkhtml = "Download not implemented yet";
112 }
113
114 // add a row to the table
115 $cells = array($coursenamehtml, $deschtml, $language, $addlinkhtml);
116
117
118 $row = new html_table_row($cells);
119
120 $table->data[] = $row;
121 }
122 $renderedhtml .= html_writer::table($table);
123 }
124 return $renderedhtml;
125 }
126
127}