Improve error handling when adding a new status fails.
authorDan Marsden <dan@danmarsden.com>
Fri, 27 Oct 2017 01:17:19 +0000 (14:17 +1300)
committerDan Marsden <dan@danmarsden.com>
Fri, 27 Oct 2017 01:17:19 +0000 (14:17 +1300)
lang/en/attendance.php
preferences.php

index d40ace8..f60e08b 100644 (file)
@@ -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';
index 776de7e..3e6305e 100644 (file)
@@ -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');