weekly release 2.3dev
[moodle.git] / admin / tool / assignmentupgrade / renderer.php
CommitLineData
bbd0e548
DW
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Defines the renderer for the assignment upgrade helper plugin.
19 *
20 * @package tool_assignmentupgrade
21 * @copyright 2012 NetSpot
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27/**
28 * Renderer for the assignment upgrade helper plugin.
29 *
30 * @package tool_assignmentupgrade
31 * @copyright 2012 NetSpot
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 */
34class tool_assignmentupgrade_renderer extends plugin_renderer_base {
35
36 /**
37 * Render the index page.
38 * @param string $detected information about what sort of site was detected.
39 * @param array $actions list of actions to show on this page.
40 * @return string html to output.
41 */
42 public function index_page($detected, array $actions) {
43 $output = '';
44 $output .= $this->header();
45 $output .= $this->heading(get_string('pluginname', 'tool_assignmentupgrade'));
46 $output .= $this->box($detected);
47 $output .= html_writer::start_tag('ul');
48 foreach ($actions as $action) {
49 $output .= html_writer::tag('li',
50 html_writer::link($action->url, $action->name) . ' - ' .
51 $action->description);
52 }
53 $output .= html_writer::end_tag('ul');
54 $output .= $this->footer();
55 return $output;
56 }
57
58 /**
59 * Render a page that is just a simple message.
60 * @param string $message the message to display.
61 * @return string html to output.
62 */
63 public function simple_message_page($message) {
64 $output = '';
65 $output .= $this->header();
66 $output .= $this->heading($message);
67 $output .= $this->back_to_index();
68 $output .= $this->footer();
69 return $output;
70 }
71
72 /**
73 * Render the confirm batch operation page
74 * @param stdClass $data Submitted form data with list of assignments to upgrade
75 * @return string html to output.
76 */
77 public function confirm_batch_operation_page(stdClass $data) {
78 $output = '';
79 $output .= $this->header();
80
81 $output .= $this->heading(get_string('confirmbatchupgrade', 'tool_assignmentupgrade'));
82 $output .= $this->output->spacer(array(), true);
83
84 $output .= $this->container_start('tool_assignmentupgrade_confirmbatch');
85
86 $output .= $this->render(new tool_assignmentupgrade_batchoperationconfirm($data));
87 $output .= $this->container_end();
88
89 $output .= $this->back_to_index();
90 $output .= $this->footer();
91 return $output;
92 }
93
94 /**
95 * Render the confirm batch continue / cancel links
96 * @param tool_assignmentupgrade_batchoperationconfirm $confirm Wrapper class to determine the continue message and url
97 * @return string html to output.
98 */
99 public function render_tool_assignmentupgrade_batchoperationconfirm(tool_assignmentupgrade_batchoperationconfirm $confirm) {
100 $output = '';
101
102 if ($confirm->continueurl) {
103 $output .= $this->output->confirm($confirm->continuemessage, $confirm->continueurl, tool_assignmentupgrade_url('listnotupgraded'));
104 } else {
105 $output .= $this->output->box($confirm->continuemessage);
106 $output .= $this->output->continue_button(tool_assignmentupgrade_url('listnotupgraded'));
107 }
108 return $output;
109 }
110
111 /**
112 * Render the list of assignments that still need to be upgraded page.
113 * @param tool_assignmentupgrade_assignments_table $assignments of data about assignments.
114 * @param tool_assignmentupgrade_batchoperations_form $batchform Submitted form with list of assignments to upgrade
115 * @return string html to output.
116 */
117 public function assignment_list_page(tool_assignmentupgrade_assignments_table $assignments, tool_assignmentupgrade_batchoperations_form $batchform) {
118 $output = '';
119 $output .= $this->header();
120 $this->page->requires->js_init_call('M.tool_assignmentupgrade.init_upgrade_table', array());
121
122
123 $output .= $this->heading(get_string('notupgradedtitle', 'tool_assignmentupgrade'));
124 $output .= $this->box(get_string('notupgradedintro', 'tool_assignmentupgrade'));
125 $output .= $this->output->spacer(array(), true);
126
127 $output .= $this->container_start('tool_assignmentupgrade_upgradetable');
128
129 $output .= $this->flexible_table($assignments, $assignments->get_rows_per_page(), true);
130 $output .= $this->container_end();
131
132 if ($assignments->anyupgradableassignments) {
133 $output .= $this->container_start('tool_assignmentupgrade_batchform');
134 $output .= $this->moodleform($batchform);
135 $output .= $this->container_end();
136 }
137
138 $output .= $this->back_to_index();
139 $output .= $this->footer();
140 return $output;
141 }
142
143 /**
144 * Render the result of an assignment conversion
145 * @param array $assignments - An array of arrays with keys $entry['assignmentsummary', 'success', 'log']
146 * See convert_assignment_result for more description of these keys.
147 * @return string html to output.
148 */
149 public function convert_multiple_assignments_result($assignments) {
150 $output = '';
151 $output .= $this->header();
152 $output .= $this->heading(get_string('batchupgrade', 'tool_assignmentupgrade'));
153
154 foreach ($assignments as $assignment) {
155 $assignmentsummary = $assignment['assignmentsummary'];
156 $success = $assignment['success'];
157 $log = $assignment['log'];
158
159 $output .= $this->heading(get_string('upgradeassignmentsummary', 'tool_assignmentupgrade', $assignmentsummary), 5);
160 if ($success) {
161 $output .= $this->container(get_string('upgradeassignmentsuccess', 'tool_assignmentupgrade'));
162
163 } else {
164 $output .= $this->container(get_string('upgradeassignmentfailed', 'tool_assignmentupgrade', $assignment));
165 }
166 if (isset($assignmentsummary->courseid)) {
167 $output .= html_writer::link(new moodle_url('/course/view.php', array('id'=>$assignmentsummary->courseid)) ,get_string('viewcourse', 'tool_assignmentupgrade'));
168 }
169
170
171 }
172
173 $output .= $this->continue_button(tool_assignmentupgrade_url('listnotupgraded'));
174
175
176 $output .= $this->footer();
177 return $output;
178 }
179
180 /**
181 * Render the result of an assignment conversion
182 * @param stdClass $assignmentsummary data about the assignment to upgrade.
183 * @param bool $success Set to true if the outcome of the conversion was a success
184 * @param string $log The log from the conversion
185 * @return string html to output.
186 */
187 public function convert_assignment_result($assignmentsummary, $success, $log) {
188 $output = '';
189 $output .= $this->header();
190 $output .= $this->heading(get_string('conversioncomplete', 'tool_assignmentupgrade'));
191
192 if (!$success) {
193 $output .= get_string('conversionfailed', 'tool_assignmentupgrade', $log);
194 } else {
195 $output .= html_writer::link(new moodle_url('/course/view.php', array('id'=>$assignmentsummary->courseid)) ,get_string('viewcourse', 'tool_assignmentupgrade'));
196 }
197
198 $output .= $this->continue_button(tool_assignmentupgrade_url('listnotupgraded'));
199
200
201 $output .= $this->footer();
202 return $output;
203 }
204
205 /**
206 * Render the are-you-sure page to confirm a manual upgrade.
207 * @param stdClass $assignmentsummary data about the assignment to upgrade.
208 * @return string html to output.
209 */
210 public function convert_assignment_are_you_sure($assignmentsummary) {
211 $output = '';
212 $output .= $this->header();
213 $output .= $this->heading(get_string('areyousure', 'tool_assignmentupgrade'));
214
215 $params = array('id' => $assignmentsummary->id, 'confirmed' => 1, 'sesskey' => sesskey());
216 $output .= $this->confirm(get_string('areyousuremessage', 'tool_assignmentupgrade', $assignmentsummary),
217 new single_button(tool_assignmentupgrade_url('upgradesingle', $params), get_string('yes')),
218 tool_assignmentupgrade_url('listnotupgraded'));
219
220 $output .= $this->footer();
221 return $output;
222 }
223
224 /**
225 * Helper method dealing with the fact we can not just fetch the output of flexible_table
226 *
227 * @param flexible_table $table
228 * @param int $rowsperpage
229 * @param bool $displaylinks Show links in the table
230 * @return string HTML
231 */
232 protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
233
234 $o = '';
235 ob_start();
236 $table->out($rowsperpage, $displaylinks);
237 $o = ob_get_contents();
238 ob_end_clean();
239
240 return $o;
241 }
242
243 /**
244 * Helper method dealing with the fact we can not just fetch the output of moodleforms
245 *
246 * @param moodleform $mform
247 * @return string HTML
248 */
249 protected function moodleform(moodleform $mform) {
250
251 $o = '';
252 ob_start();
253 $mform->display();
254 $o = ob_get_contents();
255 ob_end_clean();
256
257 return $o;
258 }
259
260
261 /**
262 * Render a link in a div, such as the 'Back to plugin main page' link.
263 * @param string|moodle_url $url the link URL.
264 * @param string $text the link text.
265 * @return string html to output.
266 */
267 public function end_of_page_link($url, $text) {
268 return html_writer::tag('div', html_writer::link($url, $text), array('class' => 'mdl-align'));
269 }
270
271 /**
272 * Output a link back to the plugin index page.
273 * @return string html to output.
274 */
275 public function back_to_index() {
276 return $this->end_of_page_link(tool_assignmentupgrade_url('index'), get_string('backtoindex', 'tool_assignmentupgrade'));
277 }
278}