reduce complexity of shiftsfilter update
This commit is contained in:
parent
aa628208ec
commit
a50b26490c
|
@ -35,38 +35,13 @@ function user_shifts() {
|
||||||
* @param ShiftsFilter $shiftsFilter
|
* @param ShiftsFilter $shiftsFilter
|
||||||
* The shiftfilter to update.
|
* The shiftfilter to update.
|
||||||
*/
|
*/
|
||||||
function update_ShiftsFilter_timerange(ShiftsFilter $shiftsFilter) {
|
function update_ShiftsFilter_timerange(ShiftsFilter $shiftsFilter, $days) {
|
||||||
$day = date('Y-m-d', time());
|
$shiftsFilter->setStartTime(check_request_datetime('start_day', 'start_time', $days, time()));
|
||||||
$start_day = in_array($day, $days) ? $day : min($days);
|
$shiftsFilter->setEndTime(check_request_datetime('end_day', 'end_time', $days, time() + 24 * 60 * 60));
|
||||||
if (isset($_REQUEST['start_day']) && in_array($_REQUEST['start_day'], $days)) {
|
|
||||||
$start_day = $_REQUEST['start_day'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$start_time = date("H:i");
|
if ($shiftsFilter->getStartTime() > $shiftsFilter->getEndTime()) {
|
||||||
if (isset($_REQUEST['start_time']) && preg_match('#^\d{1,2}:\d\d$#', $_REQUEST['start_time'])) {
|
$shiftsFilter->setEndTime($shiftsFilter->getStartTime() + 24 * 60 * 60);
|
||||||
$start_time = $_REQUEST['start_time'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$day = date('Y-m-d', time() + 24 * 60 * 60);
|
|
||||||
$end_day = in_array($day, $days) ? $day : max($days);
|
|
||||||
if (isset($_REQUEST['end_day']) && in_array($_REQUEST['end_day'], $days)) {
|
|
||||||
$end_day = $_REQUEST['end_day'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$end_time = date("H:i");
|
|
||||||
if (isset($_REQUEST['end_time']) && preg_match('#^\d{1,2}:\d\d$#', $_REQUEST['end_time'])) {
|
|
||||||
$end_time = $_REQUEST['end_time'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($start_day > $end_day) {
|
|
||||||
$end_day = $start_day;
|
|
||||||
}
|
|
||||||
if ($start_day == $end_day && $start_time >= $end_time) {
|
|
||||||
$end_time = "23:59";
|
|
||||||
}
|
|
||||||
|
|
||||||
$shiftsFilter->setStartTime(parse_date("Y-m-d H:i", $start_day . " " . $start_time));
|
|
||||||
$shiftsFilter->setEndTime(parse_date("Y-m-d H:i", $end_day . " " . $end_time));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,7 +66,7 @@ function update_ShiftsFilter(ShiftsFilter $shiftsFilter, $user_shifts_admin, $da
|
||||||
$shiftsFilter->setTypes(check_request_int_array('types'));
|
$shiftsFilter->setTypes(check_request_int_array('types'));
|
||||||
}
|
}
|
||||||
if ((isset($_REQUEST['start_time']) && isset($_REQUEST['start_day']) && isset($_REQUEST['end_time']) && isset($_REQUEST['end_day'])) || $shiftsFilter->getStartTime() == null || $shiftsFilter->getEndTime() == null) {
|
if ((isset($_REQUEST['start_time']) && isset($_REQUEST['start_day']) && isset($_REQUEST['end_time']) && isset($_REQUEST['end_day'])) || $shiftsFilter->getStartTime() == null || $shiftsFilter->getEndTime() == null) {
|
||||||
update_ShiftsFilter_timerange($shiftsFilter);
|
update_ShiftsFilter_timerange($shiftsFilter, $days);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,32 @@
|
||||||
* Provide page/request helper functions
|
* Provide page/request helper functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a date from da day and a time textfield.
|
||||||
|
*
|
||||||
|
* @param string $date_name
|
||||||
|
* Name of the textfield containing the day (format Y-m-d)
|
||||||
|
* @param string $time_name
|
||||||
|
* Name of the textfield containing the time (format H:i)
|
||||||
|
* @param string[] $allowed_days
|
||||||
|
* List of allowed days in format Y-m-d
|
||||||
|
* @param int $default_value
|
||||||
|
* Default value unix timestamp
|
||||||
|
*/
|
||||||
|
function check_request_datetime($date_name, $time_name, $allowed_days, $default_value) {
|
||||||
|
$time = date("H:i", $default_value);
|
||||||
|
$day = date("Y-m-d", $default_value);
|
||||||
|
|
||||||
|
if (isset($_REQUEST[$time_name]) && preg_match('#^\d{1,2}:\d\d$#', trim($_REQUEST[$time_name]))) {
|
||||||
|
$time = trim($_REQUEST[$time_name]);
|
||||||
|
}
|
||||||
|
if (isset($_REQUEST[$date_name]) && in_array($_REQUEST[$date_name], $allowed_days)) {
|
||||||
|
$day = $_REQUEST[$date_name];
|
||||||
|
}
|
||||||
|
|
||||||
|
return parse_date("Y-m-d H:i", $day . " " . $time);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a date into unix timestamp
|
* Parse a date into unix timestamp
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue