MDL-45221 Allow unit tests to pass under any OS
[moodle.git] / admin / tool / task / renderer.php
CommitLineData
309ae892
DW
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Output rendering for the plugin.
20 *
21 * @package tool_task
22 * @copyright 2014 Damyon Wiese
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28/**
29 * Implements the plugin renderer
30 *
31 * @copyright 2014 Damyon Wiese
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 */
34class tool_task_renderer extends plugin_renderer_base {
35 /**
36 * This function will render one beautiful table with all the scheduled tasks.
37 *
5a1e6e35 38 * @param \core\task\scheduled_task[] $tasks - list of all scheduled tasks.
309ae892
DW
39 * @return string HTML to output.
40 */
41 public function scheduled_tasks_table($tasks) {
42 $table = new html_table();
43 $table->head = array(get_string('name'),
b2ad7813 44 get_string('component', 'tool_task'),
309ae892
DW
45 get_string('edit'),
46 get_string('lastruntime', 'tool_task'),
47 get_string('nextruntime', 'tool_task'),
48 get_string('taskscheduleminute', 'tool_task'),
49 get_string('taskschedulehour', 'tool_task'),
50 get_string('taskscheduleday', 'tool_task'),
51 get_string('taskscheduledayofweek', 'tool_task'),
52 get_string('taskschedulemonth', 'tool_task'),
53 get_string('faildelay', 'tool_task'),
54 get_string('default', 'tool_task'));
55 $table->attributes['class'] = 'admintable generaltable';
56 $data = array();
57 $yes = get_string('yes');
58 $no = get_string('no');
59 $never = get_string('never');
0a5aa65b
60 $asap = get_string('asap', 'tool_task');
61 $disabled = get_string('disabled', 'tool_task');
309ae892
DW
62 foreach ($tasks as $task) {
63 $customised = $task->is_customised() ? $no : $yes;
64 $lastrun = $task->get_last_run_time() ? userdate($task->get_last_run_time()) : $never;
0a5aa65b
65 $nextrun = $task->get_next_run_time();
66 if ($task->get_disabled()) {
67 $nextrun = $disabled;
68 } else if ($nextrun > time()) {
69 $nextrun = userdate($nextrun);
70 } else {
71 $nextrun = $asap;
72 }
309ae892
DW
73 $configureurl = new moodle_url('/admin/tool/task/scheduledtasks.php', array('action'=>'edit', 'task' => get_class($task)));
74 $editlink = $this->action_icon($configureurl, new pix_icon('t/edit', get_string('edittaskschedule', 'tool_task', $task->get_name())));
75
b2ad7813 76 $namecell = new html_table_cell($task->get_name() . "\n" . html_writer::tag('span', '\\'.get_class($task), array('class' => 'task-class')));
309ae892
DW
77 $namecell->header = true;
78
b2ad7813
79 $component = $task->get_component();
80 list($type, $plugin) = core_component::normalize_component($component);
81 if ($type === 'core') {
82 $componentcell = new html_table_cell(get_string('corecomponent', 'tool_task'));
83 } else {
84 if ($plugininfo = core_plugin_manager::instance()->get_plugin_info($component)) {
85 $plugininfo->init_display_name();
86 $componentcell = new html_table_cell($plugininfo->displayname);
87 } else {
88 $componentcell = new html_table_cell($component);
89 }
90 }
91
92 $row = new html_table_row(array(
93 $namecell,
94 $componentcell,
309ae892
DW
95 new html_table_cell($editlink),
96 new html_table_cell($lastrun),
97 new html_table_cell($nextrun),
98 new html_table_cell($task->get_minute()),
99 new html_table_cell($task->get_hour()),
100 new html_table_cell($task->get_day()),
101 new html_table_cell($task->get_day_of_week()),
102 new html_table_cell($task->get_month()),
103 new html_table_cell($task->get_fail_delay()),
104 new html_table_cell($customised)));
105
24623071
PS
106 if ($task->get_disabled()) {
107 $row->attributes['class'] = 'disabled';
108 }
309ae892
DW
109 $data[] = $row;
110 }
111 $table->data = $data;
112 return html_writer::table($table);
113 }
114}