MDL-31831 whitespace clean - take2
[moodle.git] / course / publish / renderer.php
blob970fed51db49a1373704ddae6d43cf94f1e71745
1 <?php
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 ///////////////////////////////////////////////////////////////////////////
23 /**
24 * Course publish renderer.
25 * @package course
26 * @subpackage publish
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
31 class core_publish_renderer extends plugin_renderer_base {
33 /**
34 * Display the selector to advertise or publish a course
36 public function publicationselector($courseid) {
37 $text = '';
39 $advertiseurl = new moodle_url("/course/publish/hubselector.php",
40 array('sesskey' => sesskey(), 'id' => $courseid, 'advertise' => true));
41 $advertisebutton = new single_button($advertiseurl, get_string('advertise', 'hub'));
42 $text .= $this->output->render($advertisebutton);
43 $text .= html_writer::tag('div', get_string('advertisepublication_help', 'hub'),
44 array('class' => 'publishhelp'));
46 $text .= html_writer::empty_tag('br'); /// TODO Delete
48 $uploadurl = new moodle_url("/course/publish/hubselector.php",
49 array('sesskey' => sesskey(), 'id' => $courseid, 'share' => true));
50 $uploadbutton = new single_button($uploadurl, get_string('share', 'hub'));
51 $text .= $this->output->render($uploadbutton);
52 $text .= html_writer::tag('div', get_string('sharepublication_help', 'hub'),
53 array('class' => 'publishhelp'));
55 return $text;
58 /**
59 * Display the listing of hub where a course is registered on
61 public function registeredonhublisting($courseid, $publications) {
62 global $CFG;
63 $table = new html_table();
64 $table->head = array(get_string('type', 'hub'), get_string('hub', 'hub'),
65 get_string('date'), get_string('status', 'hub'), get_string('operation', 'hub'));
66 $table->size = array('10%', '40%', '20%', '%10', '%15');
68 $brtag = html_writer::empty_tag('br');
70 foreach ($publications as $publication) {
72 $updatebuttonhtml = '';
74 $params = array('sesskey' => sesskey(), 'id' => $publication->courseid,
75 'hubcourseid' => $publication->hubcourseid,
76 'huburl' => $publication->huburl, 'hubname' => $publication->hubname,
77 'cancel' => true, 'publicationid' => $publication->id,
78 'timepublished' => $publication->timepublished);
79 $cancelurl = new moodle_url("/course/publish/index.php", $params);
80 $cancelbutton = new single_button($cancelurl, get_string('removefromhub', 'hub'));
81 $cancelbutton->class = 'centeredbutton';
82 $cancelbuttonhtml = $this->output->render($cancelbutton);
84 if ($publication->enrollable) {
85 $params = array('sesskey' => sesskey(), 'id' => $publication->courseid,
86 'huburl' => $publication->huburl, 'hubname' => $publication->hubname,
87 'share' => !$publication->enrollable, 'advertise' => $publication->enrollable);
88 $updateurl = new moodle_url("/course/publish/metadata.php", $params);
89 $updatebutton = new single_button($updateurl, get_string('update', 'hub'));
90 $updatebutton->class = 'centeredbutton';
91 $updatebuttonhtml = $this->output->render($updatebutton);
93 $operations = $updatebuttonhtml . $brtag . $cancelbuttonhtml;
94 } else {
95 $operations = $cancelbuttonhtml;
98 $hubname = html_writer::tag('a',
99 $publication->hubname ? $publication->hubname : $publication->huburl,
100 array('href' => $publication->huburl));
101 //if the publication check time if bigger than May 2010, it has been checked
102 if ($publication->timechecked > 1273127954) {
103 if ($publication->status == 0) {
104 $status = get_string('statusunpublished', 'hub');
105 } else {
106 $status = get_string('statuspublished', 'hub');
109 $status .= $brtag . html_writer::tag('a', get_string('updatestatus', 'hub'),
110 array('href' => $CFG->wwwroot . '/course/publish/index.php?id='
111 . $courseid . "&updatestatusid=" . $publication->id
112 . "&sesskey=" . sesskey())) .
113 $brtag . get_string('lasttimechecked', 'hub') . ": "
114 . format_time(time() - $publication->timechecked);
115 } else {
116 $status = get_string('neverchecked', 'hub') . $brtag
117 . html_writer::tag('a', get_string('updatestatus', 'hub'),
118 array('href' => $CFG->wwwroot . '/course/publish/index.php?id='
119 . $courseid . "&updatestatusid=" . $publication->id
120 . "&sesskey=" . sesskey()));
122 //add button cells
123 $cells = array($publication->enrollable ?
124 get_string('advertised', 'hub') : get_string('shared', 'hub'),
125 $hubname, userdate($publication->timepublished,
126 get_string('strftimedatetimeshort')), $status, $operations);
127 $row = new html_table_row($cells);
128 $table->data[] = $row;
131 $contenthtml = html_writer::table($table);
133 return $contenthtml;
137 * Display unpublishing confirmation page
138 * @param object $publication
139 * $publication->courseshortname
140 $publication->courseid
141 $publication->hubname
142 $publication->huburl
143 $publication->id
145 public function confirmunpublishing($publication) {
146 $optionsyes = array('sesskey' => sesskey(), 'id' => $publication->courseid,
147 'hubcourseid' => $publication->hubcourseid,
148 'huburl' => $publication->huburl, 'hubname' => $publication->hubname,
149 'cancel' => true, 'publicationid' => $publication->id, 'confirm' => true);
150 $optionsno = array('sesskey' => sesskey(), 'id' => $publication->courseid);
151 $publication->hubname = html_writer::tag('a', $publication->hubname,
152 array('href' => $publication->huburl));
153 $formcontinue = new single_button(new moodle_url("/course/publish/index.php",
154 $optionsyes), get_string('unpublish', 'hub'), 'post');
155 $formcancel = new single_button(new moodle_url("/course/publish/index.php",
156 $optionsno), get_string('cancel'), 'get');
157 return $this->output->confirm(get_string('unpublishconfirmation', 'hub', $publication),
158 $formcontinue, $formcancel);
162 * Display waiting information about backup size during uploading backup process
163 * @param object $backupfile the backup stored_file
164 * @return $html string
166 public function sendingbackupinfo($backupfile) {
167 $sizeinfo = new stdClass();
168 $sizeinfo->total = number_format($backupfile->get_filesize() / 1000000, 2);
169 $html = html_writer::tag('div', get_string('sendingsize', 'hub', $sizeinfo),
170 array('class' => 'courseuploadtextinfo'));
171 return $html;
175 * Display upload successfull message and a button to the publish index page
176 * @param int $id the course id
177 * @param string $huburl the hub url where the course is published
178 * @param string $hubname the hub name where the course is published
179 * @return $html string
181 public function sentbackupinfo($id, $huburl, $hubname) {
182 $html = html_writer::tag('div', get_string('sent', 'hub'),
183 array('class' => 'courseuploadtextinfo'));
184 $publishindexurl = new moodle_url('/course/publish/index.php',
185 array('sesskey' => sesskey(), 'id' => $id,
186 'published' => true, 'huburl' => $huburl, 'hubname' => $hubname));
187 $continue = $this->output->render(
188 new single_button($publishindexurl, get_string('continue', 'hub')));
189 $html .= html_writer::tag('div', $continue, array('class' => 'sharecoursecontinue'));
190 return $html;
194 * Hub information (logo - name - description - link)
195 * @param object $hubinfo
196 * @return string html code
198 public function hubinfo($hubinfo) {
199 $params = array('filetype' => HUB_HUBSCREENSHOT_FILE_TYPE);
200 $imgurl = new moodle_url($hubinfo['url'] .
201 "/local/hub/webservice/download.php", $params);
202 $screenshothtml = html_writer::empty_tag('img',
203 array('src' => $imgurl, 'alt' => $hubinfo['name']));
204 $hubdescription = html_writer::tag('div', $screenshothtml,
205 array('class' => 'hubscreenshot'));
207 $hubdescription .= html_writer::tag('a', $hubinfo['name'],
208 array('class' => 'hublink', 'href' => $hubinfo['url'],
209 'onclick' => 'this.target="_blank"'));
211 $hubdescription .= html_writer::tag('div', format_text($hubinfo['description'], FORMAT_PLAIN),
212 array('class' => 'hubdescription'));
213 $hubdescription = html_writer::tag('div', $hubdescription, array('class' => 'hubinfo'));
215 return $hubdescription;