source: moodle/trunk/fuentes/admin/tool/assignmentupgrade/renderer.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

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