|
| 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 | + * Table listing all process errors |
| 19 | + * |
| 20 | + * @package tool_lifecycle |
| 21 | + * @copyright 2021 Justus Dieckmann WWU |
| 22 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 23 | + */ |
| 24 | +namespace tool_lifecycle\local\table; |
| 25 | + |
| 26 | +defined('MOODLE_INTERNAL') || die; |
| 27 | + |
| 28 | +require_once($CFG->libdir . '/tablelib.php'); |
| 29 | + |
| 30 | +/** |
| 31 | + * Table listing all process errors |
| 32 | + * |
| 33 | + * @package tool_lifecycle |
| 34 | + * @copyright 2021 Justus Dieckmann WWU |
| 35 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 36 | + */ |
| 37 | +class process_errors_table extends \table_sql { |
| 38 | + |
| 39 | + private $strings; |
| 40 | + |
| 41 | + /** |
| 42 | + * Constructor for delayed_courses_table. |
| 43 | + * |
| 44 | + * @throws \coding_exception |
| 45 | + */ |
| 46 | + public function __construct() { |
| 47 | + global $OUTPUT; |
| 48 | + |
| 49 | + parent::__construct('tool_lifecycle-process_errors'); |
| 50 | + |
| 51 | + $this->strings = [ |
| 52 | + 'proceed' => get_string('proceed', 'tool_lifecycle'), |
| 53 | + 'rollback' => get_string('rollback', 'tool_lifecycle') |
| 54 | + ]; |
| 55 | + |
| 56 | + $fields = 'c.fullname as course, w.title as workflow, s.instancename as step, pe.*'; |
| 57 | + |
| 58 | + $from = '{tool_lifecycle_proc_error} pe ' . |
| 59 | + 'JOIN {tool_lifecycle_workflow} w ON pe.workflowid = w.id ' . |
| 60 | + 'JOIN {tool_lifecycle_step} s ON pe.workflowid = s.workflowid AND pe.stepindex = s.sortindex ' . |
| 61 | + 'LEFT JOIN {course} c ON pe.courseid = c.id '; |
| 62 | + |
| 63 | + $this->set_sql($fields, $from, 'TRUE'); |
| 64 | + $this->column_nosort = ['select', 'tools']; |
| 65 | + $this->define_columns(['select', 'workflow', 'step', 'courseid', 'course', 'error', 'tools']); |
| 66 | + $this->define_headers([ |
| 67 | + $OUTPUT->render(new \core\output\checkbox_toggleall('procerrors-table', true, [ |
| 68 | + 'id' => 'select-all-procerrors', |
| 69 | + 'name' => 'select-all-procerrors', |
| 70 | + 'label' => get_string('selectall'), |
| 71 | + 'labelclasses' => 'sr-only', |
| 72 | + 'classes' => 'm-1', |
| 73 | + 'checked' => false, |
| 74 | + ])), |
| 75 | + get_string('workflow', 'tool_lifecycle'), |
| 76 | + get_string('step', 'tool_lifecycle'), |
| 77 | + get_string('courseid', 'tool_lifecycle'), |
| 78 | + get_string('course'), |
| 79 | + get_string('error'), |
| 80 | + get_string('tools', 'tool_lifecycle') |
| 81 | + ]); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Render error column. |
| 86 | + * |
| 87 | + * @param object $row Row data. |
| 88 | + * @return string error cell |
| 89 | + * @throws \coding_exception |
| 90 | + * @throws \moodle_exception |
| 91 | + */ |
| 92 | + public function col_error($row) { |
| 93 | + return "<details><summary>" . |
| 94 | + nl2br(htmlentities($row->errormessage)) . |
| 95 | + "</summary>" . |
| 96 | + nl2br(htmlentities($row->errortrace)) . |
| 97 | + "</details>"; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Render tools column. |
| 102 | + * |
| 103 | + * @param object $row Row data. |
| 104 | + * @return string pluginname of the subplugin |
| 105 | + * @throws \coding_exception |
| 106 | + * @throws \moodle_exception |
| 107 | + */ |
| 108 | + public function col_tools($row) { |
| 109 | + global $OUTPUT; |
| 110 | + |
| 111 | + $actionmenu = new \action_menu(); |
| 112 | + $actionmenu->add_primary_action( |
| 113 | + new \action_menu_link_primary( |
| 114 | + new \moodle_url('', ['action' => 'proceed', 'id[]' => $row->id, 'sesskey' => sesskey()]), |
| 115 | + new \pix_icon('e/tick', $this->strings['proceed']), |
| 116 | + $this->strings['proceed'] |
| 117 | + ) |
| 118 | + ); |
| 119 | + $actionmenu->add_primary_action( |
| 120 | + new \action_menu_link_primary( |
| 121 | + new \moodle_url('', ['action' => 'rollback', 'id[]' => $row->id, 'sesskey' => sesskey()]), |
| 122 | + new \pix_icon('e/undo', $this->strings['rollback']), |
| 123 | + $this->strings['rollback'] |
| 124 | + ) |
| 125 | + ); |
| 126 | + return $OUTPUT->render($actionmenu); |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * Generate the select column. |
| 131 | + * |
| 132 | + * @param \stdClass $data |
| 133 | + * @return string |
| 134 | + */ |
| 135 | + public function col_select($data) { |
| 136 | + global $OUTPUT; |
| 137 | + |
| 138 | + $checkbox = new \core\output\checkbox_toggleall('procerrors-table', false, [ |
| 139 | + 'classes' => 'usercheckbox m-1', |
| 140 | + 'id' => 'procerror' . $data->id, |
| 141 | + 'name' => 'procerror-select', |
| 142 | + 'value' => $data->id, |
| 143 | + 'checked' => false, |
| 144 | + 'label' => get_string('selectitem', 'moodle', $data->id), |
| 145 | + 'labelclasses' => 'accesshide', |
| 146 | + ]); |
| 147 | + |
| 148 | + return $OUTPUT->render($checkbox); |
| 149 | + } |
| 150 | + |
| 151 | + /** |
| 152 | + * Override the table show_hide_link to not show for select column. |
| 153 | + * |
| 154 | + * @param string $column the column name, index into various names. |
| 155 | + * @param int $index numerical index of the column. |
| 156 | + * @return string HTML fragment. |
| 157 | + */ |
| 158 | + protected function show_hide_link($column, $index) { |
| 159 | + if ($index > 0) { |
| 160 | + return parent::show_hide_link($column, $index); |
| 161 | + } |
| 162 | + return ''; |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * Hook that can be overridden in child classes to wrap a table in a form |
| 167 | + * for example. Called only when there is data to display and not |
| 168 | + * downloading. |
| 169 | + */ |
| 170 | + public function wrap_html_finish() { |
| 171 | + global $OUTPUT; |
| 172 | + parent::wrap_html_finish(); |
| 173 | + echo "<br>"; |
| 174 | + |
| 175 | + $actionmenu = new \action_menu(); |
| 176 | + $actionmenu->add_secondary_action( |
| 177 | + new \action_menu_link_secondary( |
| 178 | + new \moodle_url(''), |
| 179 | + new \pix_icon('e/tick', $this->strings['proceed']), |
| 180 | + $this->strings['proceed'], |
| 181 | + ['data-lifecycle-action' => 'proceed'] |
| 182 | + ) |
| 183 | + ); |
| 184 | + |
| 185 | + $actionmenu->add_secondary_action( |
| 186 | + new \action_menu_link_secondary( |
| 187 | + new \moodle_url(''), |
| 188 | + new \pix_icon('e/undo', $this->strings['rollback']), |
| 189 | + $this->strings['rollback'], |
| 190 | + ['data-lifecycle-action' => 'rollback'] |
| 191 | + ) |
| 192 | + ); |
| 193 | + |
| 194 | + $actionmenu->set_menu_trigger(get_string('forselected', 'tool_lifecycle')); |
| 195 | + echo $OUTPUT->render_action_menu($actionmenu); |
| 196 | + } |
| 197 | +} |
0 commit comments