/** * Book object - either of type or specific - for given dates */ function confirmedBookingObject() { include_once 'Modules/BookingManager/classes/class.ilBookingObject.php'; include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php'; $success = false; if ($this->object->getScheduleType() == ilObjBookingPool::TYPE_NO_SCHEDULE) { if ($_POST['object_id']) { $object_id = $_POST['object_id']; if ($object_id) { if (ilBookingReservation::isObjectAvailableNoSchedule($object_id)) { $this->processBooking($object_id); $success = $object_id; } else { // #11852 ilUtil::sendFailure($this->lng->txt('book_reservation_failed_overbooked'), true); $this->ctrl->redirect($this, 'render'); } } } } else { if (!isset($_POST['date'])) { ilUtil::sendFailure($this->lng->txt('select_one')); return $this->bookObject(); } // single object reservation(s) if (isset($_GET['object_id'])) { $confirm = array(); $object_id = (int) $_GET['object_id']; if ($object_id) { $group_id = null; $nr = ilBookingObject::getNrOfItemsForObjects(array($object_id)); if ($nr[$object_id] > 1 || sizeof($_POST['date']) > 1) { $group_id = ilBookingReservation::getNewGroupId(); } foreach ($_POST['date'] as $date) { $fromto = explode('_', $date); $fromto[1]--; $counter = ilBookingReservation::getAvailableObject(array($object_id), $fromto[0], $fromto[1], false, true); $counter = $counter[$object_id]; if ($counter) { if ($counter > 1) { $confirm[$object_id . "_" . $fromto[0] . "_" . ($fromto[1] + 1)] = $counter; } else { $this->processBooking($object_id, $fromto[0], $fromto[1], $group_id); $success = $object_id; } } } } if (sizeof($confirm)) { return $this->confirmBookingNumbers($confirm, $group_id); } } /* // group object reservation(s) else { $all_object_ids = array(); foreach(ilBookingObject::getList((int)$_GET['type_id']) as $item) { $all_object_ids[] = $item['booking_object_id']; } $possible_objects = $counter = array(); sort($_POST['date']); foreach($_POST['date'] as $date) { $fromto = explode('_', $date); $fromto[1]--; $possible_objects[$date] = ilBookingReservation::getAvailableObject($all_object_ids, $fromto[0], $fromto[1], false); foreach($possible_objects[$date] as $obj_id) { $counter[$obj_id]++; } } if(max($counter)) { // we prefer the objects which are available for most slots arsort($counter); $counter = array_keys($counter); // book each slot foreach($possible_objects as $date => $available_ids) { $fromto = explode('_', $date); $fromto[1]--; // find "best" object for slot foreach($counter as $best_object_id) { if(in_array($best_object_id, $available_ids)) { $object_id = $best_object_id; break; } } $this->processBooking($object_id, $fromto[0], $fromto[1]); $success = true; } } } */ } if ($success) { $this->handleBookingSuccess($success); } else { ilUtil::sendFailure($this->lng->txt('book_reservation_failed'), true); $this->ctrl->redirect($this, 'book'); } }