From 105ae71bf16f4869d2f74deca94da4cf1adeac91 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Fri, 27 Oct 2017 14:17:19 +1300 Subject: [PATCH] Improve error handling when adding a new status fails. --- lang/en/attendance.php | 1 + preferences.php | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lang/en/attendance.php b/lang/en/attendance.php index d40ace8..f60e08b 100644 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -82,6 +82,7 @@ $string['calshow'] = 'Choose date'; $string['caltoday'] = 'Today'; $string['calweekdays'] = 'Su,Mo,Tu,We,Th,Fr,Sa'; $string['cannottakeforgroup'] = 'You can\'t take attendance for group "{$a}"'; +$string['cantaddstatus'] = 'You must set an acronym and description when adding a new status.'; $string['categoryreport'] = 'Course category report'; $string['changeattendance'] = 'Change attendance'; $string['changeduration'] = 'Change duration'; diff --git a/preferences.php b/preferences.php index 776de7e..3e6305e 100644 --- a/preferences.php +++ b/preferences.php @@ -61,7 +61,7 @@ $errors = array(); if (!empty($att->pageparams->action)) { require_sesskey(); } - +$notification = ''; // TODO: combine this with the stuff in defaultstatus.php to avoid code duplication. switch ($att->pageparams->action) { case mod_attendance_preferences_page_params::ACTION_ADD: @@ -83,7 +83,7 @@ switch ($att->pageparams->action) { $status = attendance_add_status($newstatus); if (!$status) { - print_error('cantaddstatus', 'attendance', $this->url_preferences()); + $notification = $OUTPUT->notification(get_string('cantaddstatus', 'attendance'), 'error'); } if ($pageparams->statusset > $maxstatusset) { @@ -157,6 +157,9 @@ $setselector = new attendance_set_selector($att, $maxstatusset); // Output starts here. echo $output->header(); +if (!empty($notification)) { + echo $notification; +} echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: '. format_string($course->fullname)); echo $output->render($tabs); echo $OUTPUT->box(get_string('preferences_desc', 'attendance'), 'generalbox attendancedesc', 'notice');