/**
  * Gather data and build rows
  */
 function getItems()
 {
     global $ilUser;
     include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
     $data = ilBookingObject::getList($this->pool_id);
     include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
     foreach ($data as $item) {
         $item_id = $item["booking_object_id"];
         $item_rsv = ilBookingReservation::getList(array($item_id), 1000, 0, array());
         $this->reservations[$item_id] = $item_rsv["data"];
     }
     if (!$this->has_schedule && $this->overall_limit) {
         $this->current_bookings = 0;
         foreach ($this->reservations as $obj_rsv) {
             foreach ($obj_rsv as $item) {
                 if ($item["status"] != ilBookingReservation::STATUS_CANCELLED) {
                     if ($item["user_id"] == $ilUser->getId()) {
                         $this->current_bookings++;
                     }
                 }
             }
         }
         if ($this->current_bookings >= $this->overall_limit) {
             ilUtil::sendInfo($this->lng->txt("book_overall_limit_warning"));
         }
     }
     $this->setMaxCount(sizeof($data));
     $this->setData($data);
 }
 /**
  * Gather data and build rows
  */
 function getItems()
 {
     include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
     $data = ilBookingObject::getList($this->pool_id);
     $this->setMaxCount(sizeof($data));
     $this->setData($data);
 }
 /**
  * Render list of booking schedules
  *
  * uses ilBookingSchedulesTableGUI
  */
 function render()
 {
     global $tpl, $lng, $ilCtrl, $ilAccess;
     include_once 'Modules/BookingManager/classes/class.ilBookingSchedulesTableGUI.php';
     $table = new ilBookingSchedulesTableGUI($this, 'render', $this->ref_id);
     if ($ilAccess->checkAccess('write', '', $this->ref_id)) {
         // if we have schedules but no objects - show info
         if (sizeof($table->getData())) {
             include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
             if (!sizeof(ilBookingObject::getList(ilObject::_lookupObjId($this->ref_id)))) {
                 ilUtil::sendInfo($lng->txt("book_type_warning"));
             }
         }
         include_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
         $bar = new ilToolbarGUI();
         $bar->addButton($lng->txt('book_add_schedule'), $ilCtrl->getLinkTarget($this, 'create'));
         $bar = $bar->getHTML();
     }
     $tpl->setContent($bar . $table->getHTML());
 }
 /**
  * Init filter
  */
 function initFilter(array $a_filter_pre = null)
 {
     if (is_array($a_filter_pre) && isset($a_filter_pre["object"])) {
         $_SESSION["form_" . $this->getId()]["object"] = serialize($a_filter_pre["object"]);
         if ($this->has_schedule) {
             $_SESSION["form_" . $this->getId()]["fromto"] = serialize(array("from" => serialize(new ilDateTime(date("Y-m-d"), IL_CAL_DATE)), "to" => ""));
         }
     }
     $this->objects = array();
     include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
     foreach (ilBookingObject::getList($this->pool_id) as $item) {
         $this->objects[$item["booking_object_id"]] = $item["title"];
     }
     $item = $this->addFilterItemByMetaType("object", ilTable2GUI::FILTER_SELECT);
     $item->setOptions(array("" => $this->lng->txt('book_all')) + $this->objects);
     $this->filter["object"] = $item->getValue();
     if ($this->hasSchedule) {
         $valid_status = array(ilBookingReservation::STATUS_IN_USE, ilBookingReservation::STATUS_CANCELLED, -ilBookingReservation::STATUS_IN_USE, -ilBookingReservation::STATUS_CANCELLED);
     } else {
         $valid_status = array(ilBookingReservation::STATUS_CANCELLED, -ilBookingReservation::STATUS_CANCELLED);
     }
     $options = array("" => $this->lng->txt('book_all'));
     foreach ($valid_status as $loop) {
         if ($loop > 0) {
             $options[$loop] = $this->lng->txt('book_reservation_status_' . $loop);
         } else {
             $options[$loop] = $this->lng->txt('book_not') . ' ' . $this->lng->txt('book_reservation_status_' . -$loop);
         }
     }
     $item = $this->addFilterItemByMetaType("status", ilTable2GUI::FILTER_SELECT);
     $item->setOptions($options);
     $this->filter["status"] = $item->getValue();
     if ($this->has_schedule) {
         $item = $this->addFilterItemByMetaType("fromto", ilTable2GUI::FILTER_DATE_RANGE, false, $this->lng->txt('book_fromto'));
         $this->filter["fromto"] = $item->getDate();
     }
 }
 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
 {
     $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
     //copy online status if object is not the root copy object
     $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
     if (!$cp_options->isRootNode($this->getRefId())) {
         $new_obj->setOffline($this->isOffline());
     }
     $new_obj->setScheduleType($this->getScheduleType());
     $new_obj->setPublicLog($this->hasPublicLog());
     $new_obj->setOverallLimit($this->getOverallLimit());
     $smap = null;
     if ($this->getScheduleType() == self::TYPE_FIX_SCHEDULE) {
         // schedules
         include_once "Modules/BookingManager/classes/class.ilBookingSchedule.php";
         foreach (ilBookingSchedule::getList($this->getId()) as $item) {
             $schedule = new ilBookingSchedule($item["booking_schedule_id"]);
             $smap[$item["booking_schedule_id"]] = $schedule->doClone($new_obj->getId());
         }
     }
     // objects
     include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
     foreach (ilBookingObject::getList($this->getId()) as $item) {
         $bobj = new ilBookingObject($item["booking_object_id"]);
         $bobj->doClone($new_obj->getId(), $smap);
     }
     $new_obj->update();
     return $new_obj;
 }
 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
 {
     $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
     $new_obj->setOffline($this->isOffline());
     $new_obj->setScheduleType($this->getScheduleType());
     $new_obj->setPublicLog($this->hasPublicLog());
     $smap = null;
     if ($this->getScheduleType() == self::TYPE_FIX_SCHEDULE) {
         $new_obj->setNumberOfSlots($this->getNumberOfSlots());
         // schedules
         include_once "Modules/BookingManager/classes/class.ilBookingSchedule.php";
         foreach (ilBookingSchedule::getList($this->getId()) as $item) {
             $schedule = new ilBookingSchedule($item["booking_schedule_id"]);
             $smap[$item["booking_schedule_id"]] = $schedule->doClone($new_obj->getId());
         }
     }
     // objects
     include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
     foreach (ilBookingObject::getList($this->getId()) as $item) {
         $bobj = new ilBookingObject($item["booking_object_id"]);
         $bobj->doClone($new_obj->getId(), $smap);
     }
     $new_obj->update();
     return $new_obj;
 }
 function rsvConfirmCancelObject()
 {
     global $ilCtrl, $lng, $tpl, $ilAccess, $ilUser;
     $ids = $this->getLogReservationIds();
     if (!sizeof($ids)) {
         $this->ctrl->redirect($this, 'log');
     }
     include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
     include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
     $max = array();
     foreach ($ids as $idx => $id) {
         if (!is_numeric($id)) {
             list($obj_id, $user_id, $from, $to) = explode("_", $id);
             $valid_ids = array();
             foreach (ilBookingObject::getList($this->object->getId()) as $item) {
                 $valid_ids[$item["booking_object_id"]] = $item["title"];
             }
             if (($ilAccess->checkAccess("write", "", $this->ref_id) || $user_id == $ilUser->getId()) && $from > time() && in_array($obj_id, array_keys($valid_ids))) {
                 $rsv_ids = ilBookingReservation::getCancelDetails($obj_id, $user_id, $from, $to);
                 if (!sizeof($rsv_ids)) {
                     unset($ids[$idx]);
                 }
                 if (sizeof($rsv_ids) > 1) {
                     $max[$id] = sizeof($rsv_ids);
                     $ids[$idx] = $rsv_ids;
                 } else {
                     // only 1 in group?  treat as normal reservation
                     $ids[$idx] = array_shift($rsv_ids);
                 }
             } else {
                 unset($ids[$idx]);
             }
         }
     }
     if (!sizeof($ids)) {
         $this->ctrl->redirect($this, 'log');
     }
     // show form instead
     if (sizeof($max) && max($max) > 1) {
         return $this->rsvConfirmCancelAggregationObject($ids);
     }
     $this->tabs_gui->clearTargets();
     $this->tabs_gui->setBackTarget($lng->txt("back"), $ilCtrl->getLinkTarget($this, "log"));
     include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
     $conf = new ilConfirmationGUI();
     $conf->setFormAction($ilCtrl->getFormAction($this, 'rsvCancel'));
     $conf->setHeaderText($lng->txt('book_confirm_cancel'));
     $conf->setConfirm($lng->txt('book_set_cancel'), 'rsvCancel');
     $conf->setCancel($lng->txt('cancel'), 'log');
     foreach ($ids as $id) {
         $rsv = new ilBookingReservation($id);
         $obj = new ilBookingObject($rsv->getObjectId());
         $details = $obj->getTitle();
         if ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE) {
             $details .= ", " . ilDatePresentation::formatPeriod(new ilDateTime($rsv->getFrom(), IL_CAL_UNIX), new ilDateTime($rsv->getTo() + 1, IL_CAL_UNIX));
         }
         $conf->addItem('rsv_id[]', $id, $details);
     }
     $tpl->setContent($conf->getHTML());
 }
 /**
  * Gather data and build rows
  * @param	array	$filter
  */
 function getItems(array $filter)
 {
     $this->determineOffsetAndOrder();
     $ids = array();
     include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
     foreach (ilBookingObject::getList($this->pool_id) as $item) {
         $ids[] = $item["booking_object_id"];
     }
     include_once "Modules/BookingManager/classes/class.ilBookingReservation.php";
     $data = ilBookingReservation::getList($ids, $this->getLimit(), $this->getOffset(), $filter);
     $this->setMaxCount($data['counter']);
     $this->setData($data['data']);
 }
 /**
  * Init filter
  */
 function initFilter(array $a_filter_pre = null)
 {
     if (is_array($a_filter_pre) && isset($a_filter_pre["object"])) {
         $_SESSION["form_" . $this->getId()]["object"] = serialize($a_filter_pre["object"]);
         if ($this->has_schedule) {
             $_SESSION["form_" . $this->getId()]["fromto"] = serialize(array("from" => serialize(new ilDateTime(date("Y-m-d"), IL_CAL_DATE)), "to" => ""));
         }
     }
     $this->objects = array();
     include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
     foreach (ilBookingObject::getList($this->pool_id) as $item) {
         $this->objects[$item["booking_object_id"]] = $item["title"];
     }
     $item = $this->addFilterItemByMetaType("object", ilTable2GUI::FILTER_SELECT);
     $item->setOptions(array("" => $this->lng->txt('book_all')) + $this->objects);
     $this->filter["object"] = $item->getValue();
     if ($this->has_schedule) {
         if (!$_SESSION["form_" . $this->getId()]["fromto"]) {
             // default: from today
             $_SESSION["form_" . $this->getId()]["fromto"] = serialize(array("from" => serialize(new ilDateTime(date("Y-m-d"), IL_CAL_DATE)), "to" => null));
         }
         $item = $this->addFilterItemByMetaType("fromto", ilTable2GUI::FILTER_DATE_RANGE, false, $this->lng->txt('book_fromto'));
         $this->filter["fromto"] = $item->getDate();
         // only needed for full log
         if ($this->show_all) {
             // see ilObjBookingPoolGUI::buildDatesBySchedule()
             $map = array_flip(array('su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'));
             $options = array("" => $this->lng->txt('book_all'));
             // schedule to slot
             require_once "Modules/BookingManager/classes/class.ilBookingSchedule.php";
             foreach (ilBookingSchedule::getList($this->pool_id) as $def) {
                 $schedule = new ilBookingSchedule($def["booking_schedule_id"]);
                 foreach ($schedule->getDefinition() as $day => $slots) {
                     $day_caption = ilCalendarUtil::_numericDayToString($map[$day], false);
                     foreach ($slots as $slot) {
                         $idx = $map[$day] . "_" . $slot;
                         $options[$idx] = $day_caption . ", " . $slot;
                     }
                 }
             }
             ksort($options);
             $item = $this->addFilterItemByMetaType("book_schedule_slot", ilTable2GUI::FILTER_SELECT);
             $item->setOptions($options);
             $this->filter["slot"] = $item->getValue();
         }
     }
     // status
     $valid_status = array(-ilBookingReservation::STATUS_CANCELLED, ilBookingReservation::STATUS_CANCELLED);
     if (!$this->has_schedule) {
         $options = array("" => $this->lng->txt('book_all'));
     } else {
         $options = array();
     }
     foreach ($valid_status as $loop) {
         if ($loop > 0) {
             $options[$loop] = $this->lng->txt('book_reservation_status_' . $loop);
         } else {
             $options[$loop] = $this->lng->txt('book_not') . ' ' . $this->lng->txt('book_reservation_status_' . -$loop);
         }
     }
     $item = $this->addFilterItemByMetaType("status", ilTable2GUI::FILTER_SELECT);
     $item->setOptions($options);
     $this->filter["status"] = $item->getValue();
     // only needed for full log
     if ($this->show_all) {
         $options = array("" => $this->lng->txt('book_all')) + ilBookingReservation::getUserFilter(array_keys($this->objects));
         $item = $this->addFilterItemByMetaType("user", ilTable2GUI::FILTER_SELECT);
         $item->setOptions($options);
         $this->filter["user_id"] = $item->getValue();
     }
 }