fix shift calendar headers

main
msquare 8 years ago
parent 54f3253c32
commit ac53559fea

@ -37,8 +37,18 @@ function user_shifts() {
* The shiftfilter to update. * The shiftfilter to update.
*/ */
function update_ShiftsFilter_timerange(ShiftsFilter $shiftsFilter, $days) { function update_ShiftsFilter_timerange(ShiftsFilter $shiftsFilter, $days) {
$shiftsFilter->setStartTime(check_request_datetime('start_day', 'start_time', $days, time())); $start_time = $shiftsFilter->getStartTime();
$shiftsFilter->setEndTime(check_request_datetime('end_day', 'end_time', $days, time() + 24 * 60 * 60)); if ($start_time == null) {
$start_time = time();
}
$end_time = $shiftsFilter->getEndTime();
if ($end_time == null) {
$end_time = $start_time + 24 * 60 * 60;
}
$shiftsFilter->setStartTime(check_request_datetime('start_day', 'start_time', $days, $start_time));
$shiftsFilter->setEndTime(check_request_datetime('end_day', 'end_time', $days, $end_time));
if ($shiftsFilter->getStartTime() > $shiftsFilter->getEndTime()) { if ($shiftsFilter->getStartTime() > $shiftsFilter->getEndTime()) {
$shiftsFilter->setEndTime($shiftsFilter->getStartTime() + 24 * 60 * 60); $shiftsFilter->setEndTime($shiftsFilter->getStartTime() + 24 * 60 * 60);
@ -57,18 +67,10 @@ function update_ShiftsFilter_timerange(ShiftsFilter $shiftsFilter, $days) {
*/ */
function update_ShiftsFilter(ShiftsFilter $shiftsFilter, $user_shifts_admin, $days) { function update_ShiftsFilter(ShiftsFilter $shiftsFilter, $user_shifts_admin, $days) {
$shiftsFilter->setUserShiftsAdmin($user_shifts_admin); $shiftsFilter->setUserShiftsAdmin($user_shifts_admin);
if (isset($_REQUEST['filled'])) { $shiftsFilter->setFilled(check_request_int_array('filled', $shiftsFilter->getFilled()));
$shiftsFilter->setFilled(check_request_int_array('filled')); $shiftsFilter->setRooms(check_request_int_array('rooms', $shiftsFilter->getRooms()));
} $shiftsFilter->setTypes(check_request_int_array('types', $shiftsFilter->getTypes()));
if (isset($_REQUEST['rooms'])) {
$shiftsFilter->setRooms(check_request_int_array('rooms'));
}
if (isset($_REQUEST['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) {
update_ShiftsFilter_timerange($shiftsFilter, $days); update_ShiftsFilter_timerange($shiftsFilter, $days);
}
} }
function load_rooms() { function load_rooms() {

@ -89,12 +89,14 @@ function select_array($data, $key_name, $value_name) {
* *
* @param String $name * @param String $name
* Name of the request param * Name of the request param
* @param array<int> $default
* Default return value, if param is not set
*/ */
function check_request_int_array($name) { function check_request_int_array($name, $default = []) {
if (isset($_REQUEST[$name]) && is_array($_REQUEST[$name])) { if (isset($_REQUEST[$name]) && is_array($_REQUEST[$name])) {
return array_filter($_REQUEST[$name], 'is_numeric'); return array_filter($_REQUEST[$name], 'is_numeric');
} }
return []; return $default;
} }
/** /**

@ -56,12 +56,12 @@ class ShiftCalendarRenderer {
foreach ($shifts as $shift) { foreach ($shifts as $shift) {
$room_id = $shift['RID']; $room_id = $shift['RID'];
if (! isset($lanes[$room_id])) {
// initialize room with one lane
$header = Room_name_render([ $header = Room_name_render([
'RID' => $room_id, 'RID' => $room_id,
'Name' => $shift['room_name'] 'Name' => $shift['room_name']
]); ]);
if (! isset($lanes[$room_id])) {
// initialize room with one lane
$lanes[$room_id] = [ $lanes[$room_id] = [
new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot()) new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot())
]; ];
@ -108,6 +108,9 @@ class ShiftCalendarRenderer {
* @return the generated html * @return the generated html
*/ */
public function render() { public function render() {
if (count($this->lanes) == 0) {
return '';
}
return div('shift-calendar', [ return div('shift-calendar', [
$this->renderTimeLane(), $this->renderTimeLane(),
$this->renderShiftLanes() $this->renderShiftLanes()

Loading…
Cancel
Save