MDL-32895 tool_assignmentupgrade: fix trailing whitespace
[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
5b121144 115 * @param tool_assignmentupgrade_pagination_form $paginationform Form which contains the preferences for paginating the table
bbd0e548
DW
116 * @return string html to output.
117 */
5b121144 118 public function assignment_list_page(tool_assignmentupgrade_assignments_table $assignments, tool_assignmentupgrade_batchoperations_form $batchform, tool_assignmentupgrade_pagination_form $paginationform) {
bbd0e548
DW
119 $output = '';
120 $output .= $this->header();
121 $this->page->requires->js_init_call('M.tool_assignmentupgrade.init_upgrade_table', array());
122
123
124 $output .= $this->heading(get_string('notupgradedtitle', 'tool_assignmentupgrade'));
125 $output .= $this->box(get_string('notupgradedintro', 'tool_assignmentupgrade'));
126 $output .= $this->output->spacer(array(), true);
127
128 $output .= $this->container_start('tool_assignmentupgrade_upgradetable');
129
5b121144
DW
130 $output .= $this->container_start('tool_assignmentupgrade_paginationform');
131 $output .= $this->moodleform($paginationform);
132 $output .= $this->container_end();
133
bbd0e548
DW
134 $output .= $this->flexible_table($assignments, $assignments->get_rows_per_page(), true);
135 $output .= $this->container_end();
136
137 if ($assignments->anyupgradableassignments) {
138 $output .= $this->container_start('tool_assignmentupgrade_batchform');
139 $output .= $this->moodleform($batchform);
140 $output .= $this->container_end();
141 }
142
143 $output .= $this->back_to_index();
144 $output .= $this->footer();
145 return $output;
146 }
147
bbd0e548
DW
148 /**
149 * Render the result of an assignment conversion
150 * @param stdClass $assignmentsummary data about the assignment to upgrade.
151 * @param bool $success Set to true if the outcome of the conversion was a success
152 * @param string $log The log from the conversion
153 * @return string html to output.
154 */
155 public function convert_assignment_result($assignmentsummary, $success, $log) {
156 $output = '';
bbd0e548 157
5b121144
DW
158 $output .= $this->container_start('tool_assignmentupgrade_result');
159 $output .= $this->container(get_string('upgradeassignmentsummary', 'tool_assignmentupgrade', $assignmentsummary));
bbd0e548 160 if (!$success) {
5b121144 161 $output .= $this->container(get_string('conversionfailed', 'tool_assignmentupgrade', $log));
bbd0e548 162 } else {
5b121144 163 $output .= $this->container(get_string('upgradeassignmentsuccess', 'tool_assignmentupgrade'));
5b121144 164 $output .= $this->container(html_writer::link(new moodle_url('/course/view.php', array('id'=>$assignmentsummary->courseid)) ,get_string('viewcourse', 'tool_assignmentupgrade')));
bbd0e548 165 }
5b121144 166 $output .= $this->container_end();
bbd0e548 167
bbd0e548
DW
168 return $output;
169 }
170
171 /**
172 * Render the are-you-sure page to confirm a manual upgrade.
173 * @param stdClass $assignmentsummary data about the assignment to upgrade.
174 * @return string html to output.
175 */
176 public function convert_assignment_are_you_sure($assignmentsummary) {
177 $output = '';
178 $output .= $this->header();
179 $output .= $this->heading(get_string('areyousure', 'tool_assignmentupgrade'));
180
181 $params = array('id' => $assignmentsummary->id, 'confirmed' => 1, 'sesskey' => sesskey());
182 $output .= $this->confirm(get_string('areyousuremessage', 'tool_assignmentupgrade', $assignmentsummary),
183 new single_button(tool_assignmentupgrade_url('upgradesingle', $params), get_string('yes')),
184 tool_assignmentupgrade_url('listnotupgraded'));
185
186 $output .= $this->footer();
187 return $output;
188 }
189
190 /**
191 * Helper method dealing with the fact we can not just fetch the output of flexible_table
192 *
193 * @param flexible_table $table
194 * @param int $rowsperpage
195 * @param bool $displaylinks Show links in the table
196 * @return string HTML
197 */
198 protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
199
200 $o = '';
201 ob_start();
202 $table->out($rowsperpage, $displaylinks);
203 $o = ob_get_contents();
204 ob_end_clean();
205
206 return $o;
207 }
208
209 /**
210 * Helper method dealing with the fact we can not just fetch the output of moodleforms
211 *
212 * @param moodleform $mform
213 * @return string HTML
214 */
215 protected function moodleform(moodleform $mform) {
216
217 $o = '';
218 ob_start();
219 $mform->display();
220 $o = ob_get_contents();
221 ob_end_clean();
222
223 return $o;
224 }
225
226
227 /**
228 * Render a link in a div, such as the 'Back to plugin main page' link.
229 * @param string|moodle_url $url the link URL.
230 * @param string $text the link text.
231 * @return string html to output.
232 */
233 public function end_of_page_link($url, $text) {
234 return html_writer::tag('div', html_writer::link($url, $text), array('class' => 'mdl-align'));
235 }
236
237 /**
238 * Output a link back to the plugin index page.
239 * @return string html to output.
240 */
241 public function back_to_index() {
242 return $this->end_of_page_link(tool_assignmentupgrade_url('index'), get_string('backtoindex', 'tool_assignmentupgrade'));
243 }
244}