diff --git a/classes/table/delayed_courses_table.php b/classes/table/delayed_courses_table.php index bbb95b4d0b83f32c2527d76ac94c2174fe3c5378..bd3dc9c7633713e7b4e1dc5d460947ef3eb102eb 100644 --- a/classes/table/delayed_courses_table.php +++ b/classes/table/delayed_courses_table.php @@ -23,10 +23,6 @@ */ namespace tool_lifecycle\table; -use tool_lifecycle\manager\interaction_manager; -use tool_lifecycle\manager\lib_manager; -use tool_lifecycle\manager\step_manager; - defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/tablelib.php'); @@ -46,21 +42,21 @@ class delayed_courses_table extends \table_sql { */ public function __construct() { parent::__construct('tool_lifecycle-delayed-courses'); - $fields = "c.id as courseid, c.fullname as coursefullname, cat.name as category, dw.workflowid, w.title as workflow, dw.delayeduntil AS workflowdelay, d.delayeduntil AS globaldelay, maxtable.wfcount AS workflowcount"; + $fields = 'c.id as courseid, c.fullname as coursefullname, cat.name as category, dw.workflowid, w.title as workflow, dw.delayeduntil AS workflowdelay, d.delayeduntil AS globaldelay, maxtable.wfcount AS workflowcount'; - $from = "(" . - "SELECT courseid, MAX(dw.id) AS maxid, COUNT(*) AS wfcount " . - "FROM {tool_lifecycle_delayed_workf} dw " . - "JOIN {tool_lifecycle_workflow} w ON dw.workflowid = w.id " . // To make sure no outdated delays are counted. - "WHERE dw.delayeduntil >= :time " . + $from = '(' . + 'SELECT courseid, MAX(dw.id) AS maxid, COUNT(*) AS wfcount ' . + 'FROM {tool_lifecycle_delayed_workf} dw ' . + 'JOIN {tool_lifecycle_workflow} w ON dw.workflowid = w.id ' . // To make sure no outdated delays are counted. + 'WHERE dw.delayeduntil >= :time ' . // TODO AND dw.workflowid IN $workflows - "GROUP BY courseid " . - ") maxtable " . - "JOIN {tool_lifecycle_delayed_workf} dw ON maxtable.maxid = dw.id " . - "JOIN {tool_lifecycle_workflow} w ON dw.workflowid = w.id " . - "FULL JOIN {tool_lifecycle_delayed} d ON dw.courseid = d.courseid " . - "JOIN {course} c ON c.id = dw.courseid " . - "JOIN {course_categories} cat ON c.category = cat.id"; + 'GROUP BY courseid ' . + ') maxtable ' . + 'JOIN {tool_lifecycle_delayed_workf} dw ON maxtable.maxid = dw.id ' . + 'JOIN {tool_lifecycle_workflow} w ON dw.workflowid = w.id ' . + 'FULL JOIN {tool_lifecycle_delayed} d ON dw.courseid = d.courseid ' . + 'JOIN {course} c ON c.id = COALESCE(dw.courseid, d.courseid) ' . + 'JOIN {course_categories} cat ON c.category = cat.id'; $where = 'true'; $params = ['time' => time()]; @@ -70,27 +66,65 @@ class delayed_courses_table extends \table_sql { $this->define_headers([ get_string('coursename', 'tool_lifecycle'), get_string('category'), - get_string('workflow', 'tool_lifecycle'), + get_string('delays', 'tool_lifecycle'), get_string('tools', 'tool_lifecycle') ]); } public function col_workflow($row) { - global $DB; - if ($row->workflowcount == 1) { - return $row->workflow . ' UNTIL ' . $row->workflowdelay; + if($row->globaldelay >= time()) { + if ($row->workflowcount == 1) { + $text = get_string('delayed_globally_and_seperately_for_one', 'tool_lifecycle'); + } else if ($row->workflowcount > 1) { + $text = get_string('delayed_globally_and_seperately', 'tool_lifecycle', $row->workflowcount); + } else { + $dateformat = get_string('strftimedatetimeshort', 'core_langconfig'); + $date = userdate($row->globaldelay, $dateformat); + $text = get_string('delayed_globally', 'tool_lifecycle', $date); + } } else { - $sql = "SELECT dw.delayeduntil, w.title - FROM {tool_lifecycle_delayed_workf} dw - JOIN {tool_lifecycle_workflow} w ON dw.workflowid = w.id - WHERE dw.courseid = :courseid"; + if ($row->workflowcount <= 0) { + $text = ''; + } else if($row->workflowcount == 1) { + $dateformat = get_string('strftimedatetimeshort', 'core_langconfig'); + $date = userdate($row->workflowdelay, $dateformat); + $text = get_string('delayed_for_workflow_until', 'tool_lifecycle', + array('name' => $row->workflow, 'date' => $date)); + } else { + $text = get_string('delayed_for_workflows', 'tool_lifecycle', $row->workflowcount); + } + } + + return \html_writer::start_span('tool_lifecycle-hint', array('title' => $this->get_mouseover($row))) . + $text . + \html_writer::end_span(); + } + + private function get_mouseover($row) { + global $DB; + $text = ''; + $dateformat = get_string('strftimedatetimeshort', 'core_langconfig'); + if($row->globaldelay >= time()) { + $date = userdate($row->globaldelay, $dateformat); + $text .= get_string('globally_until_date', 'tool_lifecycle', $date) . ' '; + } + if($row->workflowcount == 1) { + $date = userdate($row->workflowdelay, $dateformat); + $text .= get_string('name_until_date', 'tool_lifecycle', + array('name' => $row->workflow, 'date' => $date)) . ' '; + } else if ($row->workflowcount > 1) { + $sql = 'SELECT dw.id, dw.delayeduntil, w.title + FROM {tool_lifecycle_delayed_workf} dw + JOIN {tool_lifecycle_workflow} w ON dw.workflowid = w.id + WHERE dw.courseid = :courseid'; $records = $DB->get_records_sql($sql, ['courseid' => $row->courseid]); - $output = ""; foreach ($records as $record) { - $output .= $record->title . ' UNTIL ' . $record->delayeduntil . '<br>'; + $date = userdate($record->delayeduntil, $dateformat); + $text .= get_string('name_until_date', 'tool_lifecycle', + array('name' => $record->title, 'date' => $date)) . ' '; } - return $output; } + return $text; } /** @@ -101,5 +135,10 @@ class delayed_courses_table extends \table_sql { * @throws \invalid_parameter_exception */ public function col_tools($row) { + global $PAGE, $OUTPUT; + $button = new \single_button( + new \moodle_url($PAGE->url, array('cid' => $row->courseid)), + get_string('delete_delay', 'tool_lifecycle')); + return $OUTPUT->render($button); } } \ No newline at end of file diff --git a/lang/en/tool_lifecycle.php b/lang/en/tool_lifecycle.php index 156a9bf475a5e0470be54bc85ae678e8fd25dcaf..b7e5e5c6342921e7691058236d0811869a9219f4 100644 --- a/lang/en/tool_lifecycle.php +++ b/lang/en/tool_lifecycle.php @@ -191,3 +191,13 @@ $string['privacy:metadata:tool_lifecycle_action_log:userid'] = 'ID of the user t $string['privacy:metadata:tool_lifecycle_action_log:action'] = 'Identifier of the action that was done.'; // Delays $string['delayed_courses_header'] = 'Delayed courses'; +$string['delete_delay'] = 'Delete delay'; +$string['globally_until_date'] = 'Globally until {$a}'; +$string['name_until_date'] = '"{$a->name}" until {$a->date}'; +$string['delayed_globally_and_seperately'] = 'Delayed globally and seperately for {$a} workflows'; +$string['delayed_globally_and_seperately_for_one'] = 'Delayed globally and seperately for 1 workflow'; +$string['delayed_globally'] = 'Delayed globally until {$a}'; +$string['delayed_for_workflow_until'] = 'Delayed for "{$a->name}" until {$a->date}'; +$string['delayed_for_workflows'] = 'Delayed for {$a} workflows'; +$string['delays'] = "Delays"; + diff --git a/styles.css b/styles.css index 9966aa1387bf1ed5c3fada251a9b295edcdec8c6..b4dfbe878201cb8864d92e6d1152bc2d1ac4dbe9 100644 --- a/styles.css +++ b/styles.css @@ -7,4 +7,8 @@ color: #888; font-size: .9em; padding: 0.5em; +} + +span.tool_lifecycle-hint { + text-decoration: underline dashed #444; } \ No newline at end of file