Browse Source

When Multiple sessions is selected and no valid days of the week are selected show a tidy error.

Fixed no-daysofweek-selected issue
MOODLE_27_STABLE
Paolo Tramonti 11 years ago
committed by Barry Oosthuizen
parent
commit
f72f1cfe3e
  1. 30
      add_form.php

30
add_form.php

@ -177,7 +177,37 @@ class mod_attendance_add_form extends moodleform {
$data['sdays']= array(); $data['sdays']= array();
$errors['sdays'] = get_string('required', 'attendance'); $errors['sdays'] = get_string('required', 'attendance');
} }
if (isset($data['sdays'])) {
if (!$this->checkWeekDays($data['sessiondate'], $data['sessionenddate'], $data['sdays']) ) {
$errors['sdays'] = get_string('checkweekdays', 'attendance');
}
}
return $errors; return $errors;
} }
private function checkWeekDays($sessiondate, $sessionenddate, $sdays) {
$found = false;
$daysOfWeek = array(0 => "Sun", 1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat");
$start = new DateTime( date("Y-m-d",$sessiondate) );
$interval = new DateInterval('P1D');
$end = new DateTime( date("Y-m-d",$sessionenddate) );
$end->add( new DateInterval('P1D') );
$period = new DatePeriod($start, $interval, $end);
foreach ($period as $date) {
if (!$found) {
foreach ($sdays as $name => $value) {
$key = array_search($name, $daysOfWeek);
if ($date->format("w") == $key) {
$found = true;
break;
}
}
}
}
return $found;
}
} }

Loading…
Cancel
Save