PageRenderTime 26ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/tool/assignmentupgrade/renderer.php

https://bitbucket.org/ngmares/moodle
PHP | 244 lines | 117 code | 35 blank | 92 comment | 6 complexity | a5af7b9352e2b4764203c380ae4b43aa MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, MPL-2.0-no-copyleft-exception, GPL-3.0, Apache-2.0, BSD-3-Clause
  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. * Defines the renderer for the assignment upgrade helper plugin.
  18. *
  19. * @package tool_assignmentupgrade
  20. * @copyright 2012 NetSpot
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die();
  24. /**
  25. * Renderer for the assignment upgrade helper plugin.
  26. *
  27. * @package tool_assignmentupgrade
  28. * @copyright 2012 NetSpot
  29. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30. */
  31. class tool_assignmentupgrade_renderer extends plugin_renderer_base {
  32. /**
  33. * Render the index page.
  34. * @param string $detected information about what sort of site was detected.
  35. * @param array $actions list of actions to show on this page.
  36. * @return string html to output.
  37. */
  38. public function index_page($detected, array $actions) {
  39. $output = '';
  40. $output .= $this->header();
  41. $output .= $this->heading(get_string('pluginname', 'tool_assignmentupgrade'));
  42. $output .= $this->box($detected);
  43. $output .= html_writer::start_tag('ul');
  44. foreach ($actions as $action) {
  45. $output .= html_writer::tag('li',
  46. html_writer::link($action->url, $action->name) . ' - ' .
  47. $action->description);
  48. }
  49. $output .= html_writer::end_tag('ul');
  50. $output .= $this->footer();
  51. return $output;
  52. }
  53. /**
  54. * Render a page that is just a simple message.
  55. * @param string $message the message to display.
  56. * @return string html to output.
  57. */
  58. public function simple_message_page($message) {
  59. $output = '';
  60. $output .= $this->header();
  61. $output .= $this->heading($message);
  62. $output .= $this->back_to_index();
  63. $output .= $this->footer();
  64. return $output;
  65. }
  66. /**
  67. * Render the confirm batch operation page
  68. * @param stdClass $data Submitted form data with list of assignments to upgrade
  69. * @return string html to output.
  70. */
  71. public function confirm_batch_operation_page(stdClass $data) {
  72. $output = '';
  73. $output .= $this->header();
  74. $output .= $this->heading(get_string('confirmbatchupgrade', 'tool_assignmentupgrade'));
  75. $output .= $this->output->spacer(array(), true);
  76. $output .= $this->container_start('tool_assignmentupgrade_confirmbatch');
  77. $output .= $this->render(new tool_assignmentupgrade_batchoperationconfirm($data));
  78. $output .= $this->container_end();
  79. $output .= $this->back_to_index();
  80. $output .= $this->footer();
  81. return $output;
  82. }
  83. /**
  84. * Render the confirm batch continue / cancel links
  85. * @param tool_assignmentupgrade_batchoperationconfirm $confirm Wrapper class to determine the continue message and url
  86. * @return string html to output.
  87. */
  88. public function render_tool_assignmentupgrade_batchoperationconfirm(tool_assignmentupgrade_batchoperationconfirm $confirm) {
  89. $output = '';
  90. if ($confirm->continueurl) {
  91. $output .= $this->output->confirm($confirm->continuemessage, $confirm->continueurl, tool_assignmentupgrade_url('listnotupgraded'));
  92. } else {
  93. $output .= $this->output->box($confirm->continuemessage);
  94. $output .= $this->output->continue_button(tool_assignmentupgrade_url('listnotupgraded'));
  95. }
  96. return $output;
  97. }
  98. /**
  99. * Render the list of assignments that still need to be upgraded page.
  100. * @param tool_assignmentupgrade_assignments_table $assignments of data about assignments.
  101. * @param tool_assignmentupgrade_batchoperations_form $batchform Submitted form with list of assignments to upgrade
  102. * @param tool_assignmentupgrade_pagination_form $paginationform Form which contains the preferences for paginating the table
  103. * @return string html to output.
  104. */
  105. public function assignment_list_page(tool_assignmentupgrade_assignments_table $assignments, tool_assignmentupgrade_batchoperations_form $batchform, tool_assignmentupgrade_pagination_form $paginationform) {
  106. $output = '';
  107. $output .= $this->header();
  108. $this->page->requires->js_init_call('M.tool_assignmentupgrade.init_upgrade_table', array());
  109. $output .= $this->heading(get_string('notupgradedtitle', 'tool_assignmentupgrade'));
  110. $output .= $this->box(get_string('notupgradedintro', 'tool_assignmentupgrade'));
  111. $output .= $this->output->spacer(array(), true);
  112. $output .= $this->container_start('tool_assignmentupgrade_upgradetable');
  113. $output .= $this->container_start('tool_assignmentupgrade_paginationform');
  114. $output .= $this->moodleform($paginationform);
  115. $output .= $this->container_end();
  116. $output .= $this->flexible_table($assignments, $assignments->get_rows_per_page(), true);
  117. $output .= $this->container_end();
  118. if ($assignments->anyupgradableassignments) {
  119. $output .= $this->container_start('tool_assignmentupgrade_batchform');
  120. $output .= $this->moodleform($batchform);
  121. $output .= $this->container_end();
  122. }
  123. $output .= $this->back_to_index();
  124. $output .= $this->footer();
  125. return $output;
  126. }
  127. /**
  128. * Render the result of an assignment conversion
  129. * @param stdClass $assignmentsummary data about the assignment to upgrade.
  130. * @param bool $success Set to true if the outcome of the conversion was a success
  131. * @param string $log The log from the conversion
  132. * @return string html to output.
  133. */
  134. public function convert_assignment_result($assignmentsummary, $success, $log) {
  135. $output = '';
  136. $output .= $this->container_start('tool_assignmentupgrade_result');
  137. $output .= $this->container(get_string('upgradeassignmentsummary', 'tool_assignmentupgrade', $assignmentsummary));
  138. if (!$success) {
  139. $output .= $this->container(get_string('conversionfailed', 'tool_assignmentupgrade', $log));
  140. } else {
  141. $output .= $this->container(get_string('upgradeassignmentsuccess', 'tool_assignmentupgrade'));
  142. $output .= $this->container(html_writer::link(new moodle_url('/course/view.php', array('id'=>$assignmentsummary->courseid)) ,get_string('viewcourse', 'tool_assignmentupgrade')));
  143. }
  144. $output .= $this->container_end();
  145. return $output;
  146. }
  147. /**
  148. * Render the are-you-sure page to confirm a manual upgrade.
  149. * @param stdClass $assignmentsummary data about the assignment to upgrade.
  150. * @return string html to output.
  151. */
  152. public function convert_assignment_are_you_sure($assignmentsummary) {
  153. $output = '';
  154. $output .= $this->header();
  155. $output .= $this->heading(get_string('areyousure', 'tool_assignmentupgrade'));
  156. $params = array('id' => $assignmentsummary->id, 'confirmed' => 1, 'sesskey' => sesskey());
  157. $output .= $this->confirm(get_string('areyousuremessage', 'tool_assignmentupgrade', $assignmentsummary),
  158. new single_button(tool_assignmentupgrade_url('upgradesingle', $params), get_string('yes')),
  159. tool_assignmentupgrade_url('listnotupgraded'));
  160. $output .= $this->footer();
  161. return $output;
  162. }
  163. /**
  164. * Helper method dealing with the fact we can not just fetch the output of flexible_table
  165. *
  166. * @param flexible_table $table
  167. * @param int $rowsperpage
  168. * @param bool $displaylinks Show links in the table
  169. * @return string HTML
  170. */
  171. protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
  172. $o = '';
  173. ob_start();
  174. $table->out($rowsperpage, $displaylinks);
  175. $o = ob_get_contents();
  176. ob_end_clean();
  177. return $o;
  178. }
  179. /**
  180. * Helper method dealing with the fact we can not just fetch the output of moodleforms
  181. *
  182. * @param moodleform $mform
  183. * @return string HTML
  184. */
  185. protected function moodleform(moodleform $mform) {
  186. $o = '';
  187. ob_start();
  188. $mform->display();
  189. $o = ob_get_contents();
  190. ob_end_clean();
  191. return $o;
  192. }
  193. /**
  194. * Render a link in a div, such as the 'Back to plugin main page' link.
  195. * @param string|moodle_url $url the link URL.
  196. * @param string $text the link text.
  197. * @return string html to output.
  198. */
  199. public function end_of_page_link($url, $text) {
  200. return html_writer::tag('div', html_writer::link($url, $text), array('class' => 'mdl-align'));
  201. }
  202. /**
  203. * Output a link back to the plugin index page.
  204. * @return string html to output.
  205. */
  206. public function back_to_index() {
  207. return $this->end_of_page_link(tool_assignmentupgrade_url('index'), get_string('backtoindex', 'tool_assignmentupgrade'));
  208. }
  209. }