function bookable_rooms_action() { if (!getGlobalPerms($GLOBALS['user']->id) == 'admin') { $resList = new ResourcesUserRoomsList($GLOBALS['user']->id, false, false, false); if (!$resList->roomsExist()) { throw new AccessDeniedException(); } } $select_options = Request::optionArray('rooms'); $rooms = array_filter($select_options, function ($v) { return strlen($v) === 32; }); $events = array(); $dates = array(); $timestamps = array(); if (count(Request::getArray('new_date'))) { $new_date = array(); foreach (Request::getArray('new_date') as $one) { if ($one['name'] == 'startDate') { $dmy = explode('.', $one['value']); $new_date['day'] = (int) $dmy[0]; $new_date['month'] = (int) $dmy[1]; $new_date['year'] = (int) $dmy[2]; } $new_date[$one['name']] = (int) $one['value']; } if (check_singledate($new_date['day'], $new_date['month'], $new_date['year'], $new_date['start_stunde'], $new_date['start_minute'], $new_date['end_stunde'], $new_date['end_minute'])) { $start = mktime($new_date['start_stunde'], $new_date['start_minute'], 0, $new_date['month'], $new_date['day'], $new_date['year']); $ende = mktime($new_date['end_stunde'], $new_date['end_minute'], 0, $new_date['month'], $new_date['day'], $new_date['year']); $timestamps[] = $start; $timestamps[] = $ende; $event = new AssignEvent('new_date', $start, $ende, null, null, ''); $events[$event->getId()] = $event; } } foreach (Request::optionArray('selected_dates') as $one) { $date = new SingleDate($one); if ($date->getStartTime()) { $timestamps[] = $date->getStartTime(); $timestamps[] = $date->getEndTime(); $event = new AssignEvent($date->getTerminID(), $date->getStartTime(), $date->getEndTime(), null, null, ''); $events[$event->getId()] = $event; $dates[$date->getTerminID()] = $date; } } if (count($events)) { $result = array(); $checker = new CheckMultipleOverlaps(); $checker->setTimeRange(min($timestamps), max($timestamps)); foreach ($rooms as $room) { $checker->addResource($room); } $checker->checkOverlap($events, $result, "assign_id"); foreach ((array) $result as $room_id => $details) { foreach ($details as $termin_id => $conflicts) { if ($termin_id == 'new_date' && Request::option('singleDateID')) { $assign_id = SingleDateDB::getAssignID(Request::option('singleDateID')); } else { $assign_id = SingleDateDB::getAssignID($termin_id); } $filter = function ($a) use($assign_id) { if ($a['assign_id'] && $a['assign_id'] == $assign_id) { return false; } return true; }; if (!count(array_filter($conflicts, $filter))) { unset($result[$room_id][$termin_id]); } } } $result = array_filter($result); $this->render_json(array_keys($result)); return; } $this->render_nothing(); }
/** * change the start and the end for this date. * ONLY SAVE WHEN SHRINKING DATES, otherwise unwanted assign-collisions * may happen... * * @param int $start the start-time to set for the assign * @param int $end the end-time to set for the assign */ private function shrinkAssign($start, $end) { if ($assign_id = SingleDateDB::getAssignID($this->termin_id)) { $changeAssign = AssignObject::Factory($assign_id); $changeAssign->setResourceId($this->resource_id); $changeAssign->chng_flag = true; $changeAssign->setBegin($start); $changeAssign->setEnd($end); $changeAssign->setRepeatEnd($end); $changeAssign->store(); } }