publication MDL-24608 display a waiting page when uploading a backup
[moodle.git] / course / publish / renderer.php
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
30  */
31 class core_publish_renderer extends plugin_renderer_base {
33     /**
34      * Display the selector to advertise or publish a course
35      */
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;
56     }
58     /**
59      * Display the listing of hub where a course is registered on
60      */
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;
96             }
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');
107                 }
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()));
121             }
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;
129         }
131         $contenthtml = html_writer::table($table);
133         return $contenthtml;
134     }
136     /**
137      * Display unpublishing confirmation page
138      * @param object $publication
139      *      $publication->courseshortname
140       $publication->courseid
141       $publication->hubname
142       $publication->huburl
143       $publication->id
144      */
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);
159     }
161     /**
162      * Display waiting information about backup size during uploading backup process
163      * @param object $backupfile the backup stored_file
164      * @return $html string
165      */
166     public function sendingbackupinfo($backupfile) {
167         $html = html_writer::tag('div', get_string('sending', 'hub'),
168                         array('class' => 'textinfo'));
169         $sizeinfo = new stdClass();
170         $sizeinfo->total = $backupfile->get_filesize() / 1000000;
171         $sizeinfo->modem = (int) ($backupfile->get_filesize() / 5000);
172         $sizeinfo->dsl = (int) $sizeinfo->total;
173         $html .= html_writer::tag('div', get_string('sendingsize', 'hub', $sizeinfo),
174                         array('class' => 'textinfo'));
175         return $html;
176     }
178     /**
179      * Display upload successfull message and a button to the publish index page
180      * @param int $id the course id
181      * @param string $huburl the hub url where the course is published
182      * @param string $hubname the hub name where the course is published
183      * @return $html string
184      */
185     public function sentbackupinfo($id, $huburl, $hubname) {
186         $html = html_writer::tag('div', get_string('sent', 'hub'),
187                         array('class' => 'textinfo'));
188         $publishindexurl = new moodle_url('/course/publish/index.php',
189                         array('sesskey' => sesskey(), 'id' => $id,
190                             'published' => true, 'huburl' => $huburl, 'hubname' => $hubname));
191         $continue = $this->output->render(
192                         new single_button($publishindexurl, get_string('continue', 'hub')));
193         $html .= html_writer::tag('div', $continue, array('class' => 'sharecoursecontinue'));
194         return $html;
195     }