From 90b1e2cbabbb4bbbc9b09674234fc46e13799fb8 Mon Sep 17 00:00:00 2001 From: Ilya Tregubov Date: Fri, 8 Jul 2022 15:15:23 +0400 Subject: [PATCH] MDL-75173 core_completion: Inconsistent status check. There is inconsistent status check for course completion block and completion details page. Completion block was taking to account pending statuses for completion criteria while completion details page was ignoring those. --- blocks/completionstatus/details.php | 51 +++++++++++++++++------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/blocks/completionstatus/details.php b/blocks/completionstatus/details.php index dedcde42d97..0007799714c 100644 --- a/blocks/completionstatus/details.php +++ b/blocks/completionstatus/details.php @@ -110,7 +110,36 @@ $params = array( ); $ccompletion = new completion_completion($params); -if ($coursecomplete) { +// Save row data. +$rows = array(); + +// Flag to set if current completion data is inconsistent with what is stored in the database. +$pendingupdate = false; + +// Load criteria to display. +$completions = $info->get_completions($user->id); + +// Loop through course criteria. +foreach ($completions as $completion) { + $criteria = $completion->get_criteria(); + + if (!$pendingupdate && $criteria->is_pending($completion)) { + $pendingupdate = true; + } + + $row = array(); + $row['type'] = $criteria->criteriatype; + $row['title'] = $criteria->get_title(); + $row['status'] = $completion->get_status(); + $row['complete'] = $completion->is_complete(); + $row['timecompleted'] = $completion->timecompleted; + $row['details'] = $criteria->get_details($completion); + $rows[] = $row; +} + +if ($pendingupdate) { + echo html_writer::tag('i', get_string('pending', 'completion')); +} else if ($coursecomplete) { echo get_string('complete'); } else if (!$criteriacomplete && !$ccompletion->timestarted) { echo html_writer::tag('i', get_string('notyetstarted', 'completion')); @@ -121,9 +150,6 @@ if ($coursecomplete) { echo html_writer::end_tag('td'); echo html_writer::end_tag('tr'); -// Load criteria to display. -$completions = $info->get_completions($user->id); - // Check if this course has any criteria. if (empty($completions)) { echo html_writer::start_tag('tr'); @@ -166,23 +192,6 @@ if (empty($completions)) { echo html_writer::tag('th', get_string('completiondate', 'report_completion'), array('class' => 'c5 header', 'scope' => 'col')); echo html_writer::end_tag('tr'); - // Save row data. - $rows = array(); - - // Loop through course criteria. - foreach ($completions as $completion) { - $criteria = $completion->get_criteria(); - - $row = array(); - $row['type'] = $criteria->criteriatype; - $row['title'] = $criteria->get_title(); - $row['status'] = $completion->get_status(); - $row['complete'] = $completion->is_complete(); - $row['timecompleted'] = $completion->timecompleted; - $row['details'] = $criteria->get_details($completion); - $rows[] = $row; - } - // Print table. $last_type = ''; $agg_type = false;