/** * Cancel a booking * @param type $a_usr_id * @param type $a_app_id * @return bool */ public static function cancelBooking($a_usr_id, $a_app_id, $a_send_notification = true) { // Delete personal copy of appointment include_once './Services/Calendar/classes/class.ilCalendarEntry.php'; $app = new ilCalendarEntry($a_app_id); include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php'; $user_apps = ilConsultationHourAppointments::getAppointmentIds($a_usr_id, $app->getContextId(), $app->getStart(), ilCalendarCategory::TYPE_CH, false); foreach ($user_apps as $uapp_id) { $uapp = new ilCalendarEntry($uapp_id); $uapp->delete(); include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; ilCalendarCategoryAssignments::_deleteByAppointmentId($uapp_id); break; } // Delete booking entries // Send notification $booking = new ilBookingEntry($app->getContextId()); if ($a_send_notification) { $booking->cancelBooking($a_app_id, $a_usr_id); } else { $booking->deleteBooking($a_app_id, $a_usr_id); } return true; }
/** * get HTML * * @access public * @param * @return */ public function getHTML($a_app) { global $tree, $lng, $ilUser; self::$counter++; $this->tpl = new ilTemplate('tpl.appointment_panel.html', true, true, 'Services/Calendar'); // Panel variables $this->tpl->setVariable('PANEL_NUM', self::$counter); $this->tpl->setVariable('PANEL_TITLE', str_replace(' ()', '', $a_app['event']->getPresentationTitle(false))); if ($a_app["event"]->isMilestone()) { $this->tpl->setVariable('PANEL_DETAILS', $this->lng->txt('cal_ms_details')); } else { $this->tpl->setVariable('PANEL_DETAILS', $this->lng->txt('cal_details')); } $this->tpl->setVariable('PANEL_TXT_DATE', $this->lng->txt('date')); if ($a_app['fullday']) { $this->tpl->setVariable('PANEL_DATE', ilDatePresentation::formatPeriod(new ilDate($a_app['dstart'], IL_CAL_UNIX), new ilDate($a_app['dend'], IL_CAL_UNIX))); } else { $this->tpl->setVariable('PANEL_DATE', ilDatePresentation::formatPeriod(new ilDateTime($a_app['dstart'], IL_CAL_UNIX), new ilDateTime($a_app['dend'], IL_CAL_UNIX))); } if ($a_app['event']->getLocation()) { $this->tpl->setVariable('PANEL_TXT_WHERE', $this->lng->txt('cal_where')); $this->tpl->setVariable('PANEL_WHERE', ilUtil::makeClickable($a_app['event']->getLocation()), true); } if ($a_app['event']->getDescription()) { $this->tpl->setVariable('PANEL_TXT_DESC', $this->lng->txt('description')); $this->tpl->setVariable('PANEL_DESC', ilUtil::makeClickable(nl2br($a_app['event']->getDescription()))); } if ($a_app['event']->isMilestone() && $a_app['event']->getCompletion() > 0) { $this->tpl->setVariable('PANEL_TXT_COMPL', $this->lng->txt('cal_task_completion')); $this->tpl->setVariable('PANEL_COMPL', $a_app['event']->getCompletion() . " %"); } if ($a_app['event']->isMilestone()) { // users responsible $users = $a_app['event']->readResponsibleUsers(); $delim = ""; foreach ($users as $r) { $value .= $delim . $r["lastname"] . ", " . $r["firstname"] . " [" . $r["login"] . "]"; $delim = "<br />"; } if (count($users) > 0) { $this->tpl->setVariable('PANEL_TXT_RESP', $this->lng->txt('cal_responsible')); $this->tpl->setVariable('PANEL_RESP', $value); } } include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; $cat_id = ilCalendarCategoryAssignments::_lookupCategory($a_app['event']->getEntryId()); $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id); $entry_obj_id = isset($cat_info['subitem_obj_ids'][$cat_id]) ? $cat_info['subitem_obj_ids'][$cat_id] : $cat_info['obj_id']; $this->tpl->setVariable('PANEL_TXT_CAL_TYPE', $this->lng->txt('cal_cal_type')); switch ($cat_info['type']) { case ilCalendarCategory::TYPE_GLOBAL: $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_system')); break; case ilCalendarCategory::TYPE_USR: $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_personal')); break; case ilCalendarCategory::TYPE_OBJ: $type = ilObject::_lookupType($cat_info['obj_id']); $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_' . $type)); // Course group appointment registration if ($this->settings->isCGRegistrationEnabled() and $type == 'crs' or type == 'grp') { if (!$a_app['event']->isAutoGenerated()) { include_once './Services/Calendar/classes/class.ilCalendarRegistration.php'; $reg = new ilCalendarRegistration($a_app['event']->getEntryId()); if ($reg->isRegistered($ilUser->getId(), new ilDateTime($a_app['dstart'], IL_CAL_UNIX), new ilDateTime($a_app['dend'], IL_CAL_UNIX))) { $this->tpl->setCurrentBlock('panel_cancel_book_link'); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE)); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId()); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dstart', $a_app['dstart']); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dend', $a_app['dend']); $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_reg_unregister')); $this->tpl->setVariable('PANEL_CANCELBOOK_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'confirmUnregister')); $this->tpl->parseCurrentBlock(); } else { $this->tpl->setCurrentBlock('panel_book_link'); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE)); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId()); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dstart', $a_app['dstart']); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dend', $a_app['dend']); $this->tpl->setVariable('TXT_PANEL_BOOK', $this->lng->txt('cal_reg_register')); $this->tpl->setVariable('PANEL_BOOK_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'confirmRegister')); $this->tpl->parseCurrentBlock(); } include_once './Services/Link/classes/class.ilLink.php'; $registrations = array(); foreach ($reg->getRegisteredUsers(new ilDateTime($a_app['dstart'], IL_CAL_UNIX), new ilDateTime($a_app['dend'], IL_CAL_UNIX)) as $usr_data) { $usr_id = $usr_data['usr_id']; $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', $usr_id); $registrations[] = '<a href="' . $this->ctrl->getLinkTargetByClass('ilconsultationhoursgui', 'showprofile') . '">' . ilObjUser::_lookupFullname($usr_id); $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', ''); } if (count($registrations)) { $this->tpl->setCurrentBlock('panel_current_booking'); $this->tpl->setVariable('PANEL_TXT_CURRENT_BOOKING', $this->lng->txt('cal_reg_registered_users')); $this->tpl->setVariable('PANEL_CURRENT_BOOKING', implode('<br />', $registrations)); $this->tpl->parseCurrentBlock(); } } } break; case ilCalendarCategory::TYPE_CH: $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_ch_ch')); include_once 'Services/Booking/classes/class.ilBookingEntry.php'; $entry = new ilBookingEntry($a_app['event']->getContextId()); $is_owner = $entry->isOwner(); $user_entry = $cat_info['obj_id'] == $ilUser->getId(); if ($user_entry && !$is_owner) { // find source calendar entry in owner calendar include_once 'Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php'; $apps = ilConsultationHourAppointments::getAppointmentIds($entry->getObjId(), $a_app['event']->getContextId(), $a_app['event']->getStart()); $ref_event = $apps[0]; } else { $ref_event = $a_app['event']->getEntryId(); } $this->tpl->setCurrentBlock('panel_booking_owner'); $this->tpl->setVariable('PANEL_TXT_BOOKING_OWNER', $this->lng->txt('cal_ch_booking_owner')); $this->tpl->setVariable('PANEL_BOOKING_OWNER', ilObjUser::_lookupFullname($entry->getObjId())); $this->tpl->parseCurrentBlock(); $this->tpl->setCurrentBlock('panel_max_booking'); $this->tpl->setVariable('PANEL_TXT_MAX_BOOKING', $this->lng->txt('cal_ch_num_bookings')); $this->tpl->setVariable('PANEL_MAX_BOOKING', $entry->getNumberOfBookings()); $this->tpl->parseCurrentBlock(); if (!$is_owner) { if ($entry->hasBooked($ref_event)) { if (ilDateTime::_after($a_app['event']->getStart(), new ilDateTime(time(), IL_CAL_UNIX))) { $this->tpl->setCurrentBlock('panel_cancel_book_link'); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $ref_event); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE)); $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_ch_cancel_booking')); $this->tpl->setVariable('PANEL_CANCELBOOK_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'cancelBooking')); $this->tpl->parseCurrentBlock(); } } elseif ($entry->isAppointmentBookableForUser($ref_event, $GLOBALS['ilUser']->getId())) { $this->tpl->setCurrentBlock('panel_book_link'); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $ref_event); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE)); $this->tpl->setVariable('TXT_PANEL_BOOK', $this->lng->txt('cal_ch_book')); $this->tpl->setVariable('PANEL_BOOK_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'book')); $this->tpl->parseCurrentBlock(); } $this->tpl->setCurrentBlock('panel_current_booking'); $this->tpl->setVariable('PANEL_TXT_CURRENT_BOOKING', $this->lng->txt('cal_ch_current_bookings')); $this->tpl->setVariable('PANEL_CURRENT_BOOKING', $entry->getCurrentNumberOfBookings($ref_event)); $this->tpl->parseCurrentBlock(); } else { $obj_ids = $entry->getTargetObjIds(); foreach ($obj_ids as $obj_id) { $title = ilObject::_lookupTitle($obj_id); $refs = ilObject::_getAllReferences($obj_id); include_once './Services/Link/classes/class.ilLink.php'; $this->tpl->setCurrentBlock('panel_booking_target_row'); $this->tpl->setVariable('PANEL_BOOKING_TARGET_TITLE', $title); $this->tpl->setVariable('PANEL_BOOKING_TARGET', ilLink::_getLink(end($refs))); $this->tpl->parseCurrentBlock(); } if ($obj_ids) { $this->tpl->setCurrentBlock('panel_booking_target'); $this->tpl->setVariable('PANEL_TXT_BOOKING_TARGET', $this->lng->txt('cal_ch_target_object')); $this->tpl->parseCurrentBlock(); } $link_users = true; if (ilCalendarCategories::_getInstance()->getMode() == ilCalendarCategories::MODE_PORTFOLIO_CONSULTATION) { $link_users = false; } include_once './Services/Link/classes/class.ilLink.php'; $bookings = array(); $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'panel', 1); foreach ($entry->getCurrentBookings($a_app['event']->getEntryId()) as $user_id) { if ($link_users) { $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', $user_id); $bookings[] = '<a href="' . $this->ctrl->getLinkTargetByClass('ilconsultationhoursgui', 'showprofile') . '">' . ilObjUser::_lookupFullname($user_id) . '</a>'; $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', ''); } else { $bookings[] = ilObjUser::_lookupFullname($user_id); } } $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'panel', ''); $this->tpl->setCurrentBlock('panel_current_booking'); $this->tpl->setVariable('PANEL_TXT_CURRENT_BOOKING', $this->lng->txt('cal_ch_current_bookings')); $this->tpl->setVariable('PANEL_CURRENT_BOOKING', implode('<br />', $bookings)); $this->tpl->parseCurrentBlock(); } break; case ilCalendarCategory::TYPE_BOOK: $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_ch_booking')); $this->tpl->setCurrentBlock('panel_cancel_book_link'); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId()); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE)); $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_ch_cancel_booking')); $this->tpl->setVariable('PANEL_CANCELBOOK_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'cancelBooking')); $this->tpl->parseCurrentBlock(); break; } $this->tpl->setVariable('PANEL_TXT_CAL_NAME', $this->lng->txt('cal_calendar_name')); $this->tpl->setVariable('PANEL_CAL_NAME', $cat_info['title']); if ($cat_info['editable'] and !$a_app['event']->isAutoGenerated()) { $this->tpl->setCurrentBlock('panel_edit_link'); $this->tpl->setVariable('TXT_PANEL_EDIT', $this->lng->txt('edit')); $this->ctrl->clearParametersByClass('ilcalendarappointmentgui'); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE)); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId()); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $a_app['dstart']); $this->tpl->setVariable('PANEL_EDIT_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'askEdit')); $this->tpl->setCurrentBlock('panel_delete_link'); $this->tpl->setVariable('TXT_PANEL_DELETE', $this->lng->txt('delete')); $this->ctrl->clearParametersByClass('ilcalendarappointmentgui'); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE)); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId()); $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $a_app['dstart']); $this->tpl->setVariable('PANEL_DELETE_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'askdelete')); $this->tpl->parseCurrentBlock(); } include_once './Services/Calendar/classes/class.ilCalendarCategory.php'; if ($cat_info['type'] == ilCalendarCategory::TYPE_OBJ) { $refs = ilObject::_getAllReferences($entry_obj_id); $type = ilObject::_lookupType($entry_obj_id); $title = ilObject::_lookupTitle($entry_obj_id) ? ilObject::_lookupTitle($entry_obj_id) : $lng->txt('obj_' . $type); include_once './Services/Link/classes/class.ilLink.php'; $href = ilLink::_getStaticLink(current($refs), ilObject::_lookupType($entry_obj_id)); $parent = $tree->getParentId(current($refs)); $parent_title = ilObject::_lookupTitle(ilObject::_lookupObjId($parent)); $this->tpl->setVariable('PANEL_TXT_LINK', $this->lng->txt('ext_link')); $this->tpl->setVariable('PANEL_LINK_HREF', $href); $this->tpl->setVariable('PANEL_LINK_NAME', $title); $this->tpl->setVariable('PANEL_PARENT', $parent_title); } return $this->tpl->get(); }
/** * Import ical in calendar * @param ilCalendarCategory $cat */ protected function importIcal(ilCalendarCategory $cat) { // Delete old appointments include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; foreach (ilCalendarCategoryAssignments::_getAssignedAppointments(array($cat->getCategoryID())) as $app_id) { include_once './Services/Calendar/classes/class.ilCalendarEntry.php'; ilCalendarEntry::_delete($app_id); } ilCalendarCategoryAssignments::_deleteByCategoryId($cat->getCategoryID()); // Import new appointments include_once './Services/Calendar/classes/iCal/class.ilICalParser.php'; $parser = new ilICalParser($this->ical, ilICalParser::INPUT_STRING); $parser->setCategoryId($cat->getCategoryID()); $parser->parse(); }
/** * Book object for date * * @param int $a_object_id * @param int $a_from timestamp * @param int $a_to timestamp */ function processBooking($a_object_id, $a_from = null, $a_to = null) { global $ilUser; include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php'; $reservation = new ilBookingReservation(); $reservation->setObjectId($a_object_id); $reservation->setUserId($ilUser->getID()); $reservation->setFrom($a_from); $reservation->setTo($a_to); $reservation->save(); if ($a_from) { $this->lng->loadLanguageModule('dateplaner'); include_once 'Services/Calendar/classes/class.ilCalendarUtil.php'; include_once 'Services/Calendar/classes/class.ilCalendarCategory.php'; $def_cat = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_BOOK, $ilUser->getId(), $this->lng->txt('cal_ch_personal_book'), true); include_once 'Modules/BookingManager/classes/class.ilBookingObject.php'; $object = new ilBookingObject($a_object_id); include_once 'Services/Calendar/classes/class.ilCalendarEntry.php'; $entry = new ilCalendarEntry(); $entry->setStart(new ilDateTime($a_from, IL_CAL_UNIX)); $entry->setEnd(new ilDateTime($a_to, IL_CAL_UNIX)); $entry->setTitle($this->lng->txt('book_cal_entry') . ' ' . $object->getTitle()); $entry->setContextId($reservation->getId()); $entry->save(); include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; $assignment = new ilCalendarCategoryAssignments($entry->getEntryId()); $assignment->addAssignment($def_cat->getCategoryId()); } }
/** * check whether an appoinment is visible or not * * @access public * @param * @return */ public function isAppointmentVisible($a_cal_id) { include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; foreach (ilCalendarCategoryAssignments::_lookupCategories($a_cal_id) as $cat_id) { if (in_array($cat_id, $this->hidden)) { return true; } } return false; }
/** * Book consultation appointment, was confirmed */ public function bookconfirmed() { global $ilUser; $entry = (int) $_POST['app_id']; $user = (int) $_GET['bkid']; include_once 'Services/Calendar/classes/class.ilCalendarEntry.php'; include_once 'Services/Booking/classes/class.ilBookingEntry.php'; $entry = new ilCalendarEntry($entry); $booking = new ilBookingEntry($entry->getContextId()); $booking->book($entry->getEntryId()); // create user calendar/appointment include_once './Services/Calendar/classes/class.ilCalendarCategory.php'; include_once './Services/Calendar/classes/class.ilCalendarUtil.php'; include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; $user_entry = clone $entry; $user_entry->save(); $def_cat = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_CH, $ilUser->getId(), $this->lng->txt('cal_ch_personal_ch'), true); $assign = new ilCalendarCategoryAssignments($user_entry->getEntryId()); $assign->addAssignment($def_cat->getCategoryID()); ilUtil::sendSuccess($this->lng->txt('cal_booking_confirmed'), true); $this->ctrl->returnToParent($this); }
/** * Import ics * @param type $file * @param type $category_id */ protected function doImportFile($file, $category_id) { include_once './Services/Calendar/classes/../classes/iCal/class.ilICalParser.php'; include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; $GLOBALS['ilLog']->write(__METHOD__ . ': Starting ical import...'); $assigned_before = ilCalendarCategoryAssignments::lookupNumberOfAssignedAppointments(array($category_id)); $parser = new ilICalParser($file, ilICalParser::INPUT_FILE); $parser->setCategoryId($category_id); $parser->parse(); $assigned_after = ilCalendarCategoryAssignments::lookupNumberOfAssignedAppointments(array($category_id)); return $assigned_after - $assigned_before; }
/** * Build url from calendar entry * @param ilCalendarEntry $entry * @return string */ protected function buildAppointmentUrl(ilCalendarEntry $entry) { $cat = ilCalendarCategory::getInstanceByCategoryId(current((array) ilCalendarCategoryAssignments::_lookupCategories($entry->getEntryId()))); if ($cat->getType() != ilCalendarCategory::TYPE_OBJ) { $this->writer->addLine('URL;VALUE=URI:' . ILIAS_HTTP_PATH); } else { $refs = ilObject::_getAllReferences($cat->getObjId()); include_once './Services/Link/classes/class.ilLink.php'; $this->writer->addLine('URL;VALUE=URI:' . ilLink::_getLink(current((array) $refs))); } }
/** * Delete automatic generated appointments * * @access public * @param int obj_id * @static */ public static function deleteAppointments($a_obj_id) { include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; include_once './Services/Calendar/classes/class.ilCalendarEntry.php'; foreach (ilCalendarCategoryAssignments::_getAutoGeneratedAppointmentsByObjId($a_obj_id) as $app_id) { ilCalendarCategoryAssignments::_deleteByAppointmentId($app_id); ilCalendarEntry::_delete($app_id); } }
/** * calculate * * @access protected */ public function calculate() { global $ilDB; $events = $this->getEvents(); // we need category type for booking handling $ids = array(); foreach ($events as $event) { $ids[] = $event->getEntryId(); } include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; $cat_map = ilCalendarCategoryAssignments::_getAppointmentCalendars($ids); include_once 'Services/Calendar/classes/class.ilCalendarCategory.php'; $cat_types = array(); foreach (array_unique($cat_map) as $cat_id) { $cat = new ilCalendarCategory($cat_id); $cat_types[$cat_id] = $cat->getType(); } $counter = 0; foreach ($events as $event) { // Calculdate recurring events include_once 'Services/Calendar/classes/class.ilCalendarRecurrences.php'; if ($recs = ilCalendarRecurrences::_getRecurrences($event->getEntryId())) { $duration = $event->getEnd()->get(IL_CAL_UNIX) - $event->getStart()->get(IL_CAL_UNIX); foreach ($recs as $rec) { $calc = new ilCalendarRecurrenceCalculator($event, $rec); foreach ($calc->calculateDateList($this->start, $this->end)->get() as $rec_date) { $this->schedule[$counter]['event'] = $event; $this->schedule[$counter]['dstart'] = $rec_date->get(IL_CAL_UNIX); $this->schedule[$counter]['dend'] = $this->schedule[$counter]['dstart'] + $duration; $this->schedule[$counter]['fullday'] = $event->isFullday(); $this->schedule[$counter]['category_id'] = $cat_map[$event->getEntryId()]; $this->schedule[$counter]['category_type'] = $cat_types[$cat_map[$event->getEntryId()]]; switch ($this->type) { case self::TYPE_DAY: case self::TYPE_WEEK: // store date info (used for calculation of overlapping events) $tmp_date = new ilDateTime($this->schedule[$counter]['dstart'], IL_CAL_UNIX, $this->timezone); $this->schedule[$counter]['start_info'] = $tmp_date->get(IL_CAL_FKT_GETDATE, '', $this->timezone); $tmp_date = new ilDateTime($this->schedule[$counter]['dend'], IL_CAL_UNIX, $this->timezone); $this->schedule[$counter]['end_info'] = $tmp_date->get(IL_CAL_FKT_GETDATE, '', $this->timezone); break; default: break; } $counter++; if ($this->areEventsLimited() && $counter >= $this->getEventsLimit()) { break; } } } } else { $this->schedule[$counter]['event'] = $event; $this->schedule[$counter]['dstart'] = $event->getStart()->get(IL_CAL_UNIX); $this->schedule[$counter]['dend'] = $event->getEnd()->get(IL_CAL_UNIX); $this->schedule[$counter]['fullday'] = $event->isFullday(); $this->schedule[$counter]['category_id'] = $cat_map[$event->getEntryId()]; $this->schedule[$counter]['category_type'] = $cat_types[$cat_map[$event->getEntryId()]]; if (!$event->isFullday()) { switch ($this->type) { case self::TYPE_DAY: case self::TYPE_WEEK: // store date info (used for calculation of overlapping events) $tmp_date = new ilDateTime($this->schedule[$counter]['dstart'], IL_CAL_UNIX, $this->timezone); $this->schedule[$counter]['start_info'] = $tmp_date->get(IL_CAL_FKT_GETDATE, '', $this->timezone); $tmp_date = new ilDateTime($this->schedule[$counter]['dend'], IL_CAL_UNIX, $this->timezone); $this->schedule[$counter]['end_info'] = $tmp_date->get(IL_CAL_FKT_GETDATE, '', $this->timezone); break; default: break; } } $counter++; if ($this->areEventsLimited() && $counter >= $this->getEventsLimit()) { break; } } } }
/** * Book object for date * * @param int $a_object_id * @param int $a_from timestamp * @param int $a_to timestamp * @param int $a_group_id * @return int */ function processBooking($a_object_id, $a_from = null, $a_to = null, $a_group_id = null) { global $ilUser, $ilAccess; // #11995 if (!$ilAccess->checkAccess('read', '', $this->object->getRefId())) { $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"), $this->ilias->error_obj->MESSAGE); } include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php'; $reservation = new ilBookingReservation(); $reservation->setObjectId($a_object_id); $reservation->setUserId($ilUser->getID()); $reservation->setFrom($a_from); $reservation->setTo($a_to); $reservation->setGroupId($a_group_id); $reservation->save(); if ($a_from) { $this->lng->loadLanguageModule('dateplaner'); include_once 'Services/Calendar/classes/class.ilCalendarUtil.php'; include_once 'Services/Calendar/classes/class.ilCalendarCategory.php'; $def_cat = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_BOOK, $ilUser->getId(), $this->lng->txt('cal_ch_personal_book'), true); include_once 'Modules/BookingManager/classes/class.ilBookingObject.php'; $object = new ilBookingObject($a_object_id); include_once 'Services/Calendar/classes/class.ilCalendarEntry.php'; $entry = new ilCalendarEntry(); $entry->setStart(new ilDateTime($a_from, IL_CAL_UNIX)); $entry->setEnd(new ilDateTime($a_to, IL_CAL_UNIX)); $entry->setTitle($this->lng->txt('book_cal_entry') . ' ' . $object->getTitle()); $entry->setContextId($reservation->getId()); $entry->save(); include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; $assignment = new ilCalendarCategoryAssignments($entry->getEntryId()); $assignment->addAssignment($def_cat->getCategoryId()); } return $reservation->getId(); }
/** * Delete automatic generated appointments * * @access public * @param int obj_id * @param array context ids * @static */ public static function deleteAppointments($a_obj_id, array $a_context_ids = null) { include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; include_once './Services/Calendar/classes/class.ilCalendarEntry.php'; foreach (ilCalendarCategoryAssignments::_getAutoGeneratedAppointmentsByObjId($a_obj_id) as $app_id) { // delete only selected entries if (is_array($a_context_ids)) { $entry = new ilCalendarEntry($app_id); if (!in_array($entry->getContextId(), $a_context_ids)) { continue; } } ilCalendarCategoryAssignments::_deleteByAppointmentId($app_id); ilCalendarEntry::_delete($app_id); } }
/** * Import record * * @param * @return */ function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version) { switch ($a_entity) { case "calendar": // please note: we currently only support private user calendars to // be imported if ($a_rec["Type"] == 1) { $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["ObjId"]); if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") { include_once './Services/Calendar/classes/class.ilCalendarCategory.php'; $category = new ilCalendarCategory(0); $category->setTitle($a_rec["Title"]); $category->setColor($a_rec["Color"]); $category->setType(ilCalendarCategory::TYPE_USR); $category->setObjId($usr_id); $category->add(); $a_mapping->addMapping("Services/Calendar", "calendar", $a_rec["CatId"], $category->getCategoryID()); } } break; case "cal_entry": // please note: we currently only support private user calendars to // be imported if ((int) $a_rec["ContextId"] == 0) { include_once './Services/Calendar/classes/class.ilCalendarEntry.php'; $entry = new ilCalendarEntry(0); $entry->setTitle($a_rec["Title"]); $entry->setSubtitle($a_rec["Subtitle"]); $entry->setDescription($a_rec["Description"]); $entry->setLocation($a_rec["Location"]); $entry->setFullday($a_rec["Fullday"]); if ($a_rec["Starta"] != "") { $entry->setStart(new ilDateTime($a_rec["Starta"], IL_CAL_DATETIME, 'UTC')); } if ($a_rec["Enda"] != "") { $entry->setEnd(new ilDateTime($a_rec["Enda"], IL_CAL_DATETIME, 'UTC')); } $entry->setFurtherInformations($a_rec["Informations"]); $entry->setAutoGenerated($a_rec["AutoGenerated"]); $entry->setContextId($a_rec["ContextId"]); $entry->setMilestone($a_rec["Milestone"]); $entry->setCompletion($a_rec["Completion"]); $entry->setTranslationType($a_rec["TranslationType"]); $entry->enableNotification($a_rec["Notification"]); $entry->save(); $a_mapping->addMapping("Services/Calendar", "cal_entry", $a_rec["Id"], $entry->getEntryId()); } break; case "cal_assignment": $cat_id = $a_mapping->getMapping("Services/Calendar", "calendar", $a_rec["CatId"]); $entry_id = $a_mapping->getMapping("Services/Calendar", "cal_entry", $a_rec["EntryId"]); if ($cat_id > 0 && $entry_id > 0) { include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; $ass = new ilCalendarCategoryAssignments($entry_id); $ass->addAssignment($cat_id); } break; case "recurrence_rule": $entry_id = $a_mapping->getMapping("Services/Calendar", "cal_entry", $a_rec["EntryId"]); if ($entry_id > 0) { include_once './Services/Calendar/classes/class.ilCalendarRecurrence.php'; $rec = new ilCalendarRecurrence(); $rec->setEntryId($entry_id); $rec->setRecurrence($a_rec["CalRecurrence"]); $rec->setFrequenceType($a_rec["FreqType"]); if ($a_rec["FreqUntilDate"] != "") { $rec->setFrequenceUntilDate(new ilDateTime($a_rec["FreqUntilDate"], IL_CAL_DATETIME)); } $rec->setFrequenceUntilCount($a_rec["FreqUntilCount"]); $rec->setInterval($a_rec["Interval"]); $rec->setBYDAY($a_rec["Byday"]); $rec->setBYWEEKNO($a_rec["Byweekno"]); $rec->setBYMONTH($a_rec["Bymonth"]); $rec->setBYMONTHDAY($a_rec["Bymonthday"]); $rec->setBYYEARDAY($a_rec["Byyearday"]); $rec->setBYSETPOS($a_rec["Bysetpos"]); $rec->setWeekstart($a_rec["Weekstart"]); $rec->save(); $a_mapping->addMapping("Services/Calendar", "recurrence_rule", $a_rec["RuleId"], $rec->getRecurrenceId()); } break; } }
/** * Generate Calendar Entries * * @param * @return */ function generateCalendarEntries($a_num_per_course = 10) { include_once "./Services/Calendar/classes/class.ilDateTime.php"; include_once "./Services/Calendar/classes/class.ilCalendarEntry.php"; include_once "./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php"; include_once "./Services/Calendar/classes/class.ilCalendarCategories.php"; $this->log("Creating Calendar Entries"); $crs_ref_ids = ilUtil::_getObjectsByOperations("crs", "read", 0, $limit = 1000000); $cnt = 1; foreach ($crs_ref_ids as $rid) { $obj_id = ilObject::_lookupObjId($rid); $cat_id = ilCalendarCategories::_lookupCategoryIdByObjId($obj_id); $start = new ilDate(time(), IL_CAL_UNIX); $end = new ilDate(time(), IL_CAL_UNIX); $end->increment(IL_CAL_HOUR, 2); for ($i = 1; $i <= $a_num_per_course; $i++) { $this->log("Event " . $cnt); $entry = new ilCalendarEntry(); $entry->setStart($start); //ilDateTiem $entry->setEnd($end); //ilDateTiem $entry->setFullday(false); //ilDateTiem $entry->setTitle("Event " . $cnt); //ilDateTiem $entry->save(); $id = $entry->getEntryId(); $ass = new ilCalendarCategoryAssignments($id); $ass->addAssignment($cat_id); $start->increment(IL_CAL_DAY, 1); $end->increment(IL_CAL_DAY, 1); //echo "-$cat_id-"; //echo "+".ilDatePresentation::formatDate($start)."+"; $cnt++; } } }
/** * delete * * @access public * @return */ public function delete() { global $ilDB; $query = "DELETE FROM cal_categories " . "WHERE cat_id = " . $this->db->quote($this->cat_id, 'integer') . " "; $res = $ilDB->manipulate($query); include_once './Services/Calendar/classes/class.ilCalendarHidden.php'; ilCalendarHidden::_deleteCategories($this->cat_id); include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; foreach (ilCalendarCategoryAssignments::_getAssignedAppointments(array($this->cat_id)) as $app_id) { include_once './Services/Calendar/classes/class.ilCalendarEntry.php'; ilCalendarEntry::_delete($app_id); } ilCalendarCategoryAssignments::_deleteByCategoryId($this->cat_id); }
/** * delete * * @access protected * @param * @return */ protected function delete() { foreach ($_POST['appointments'] as $app_id) { $app = new ilCalendarEntry($app_id); $app->delete(); include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; ilCalendarCategoryAssignments::_deleteByAppointmentId($app_id); include_once './Services/Calendar/classes/class.ilCalendarUserNotification.php'; ilCalendarUserNotification::deleteCalendarEntry($app_id); } ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'), true); $this->ctrl->returnToParent($this); }
/** * parse calendar data * * @access public * @param * @return */ public function parse() { global $ilUser; $counter = 0; $calendars = array(); $status = new ilCalendarSharedStatus($ilUser->getId()); foreach ($this->cal_data as $data) { if ($status->isDeclined($data['cal_id']) || $status->isAccepted($data['cal_id'])) { continue; } $tmp_calendar = new ilCalendarCategory($data['cal_id']); $calendars[$counter]['cal_id'] = $data['cal_id']; $calendars[$counter]['create_date'] = $data['create_date']; $calendars[$counter]['obj_type'] = $data['obj_type']; $calendars[$counter]['name'] = $tmp_calendar->getTitle(); $calendars[$counter]['owner'] = $tmp_calendar->getObjId(); $calendars[$counter]['apps'] = count(ilCalendarCategoryAssignments::_getAssignedAppointments(array($data['cal_id']))); $calendars[$counter]['accepted'] = $status->isAccepted($data['cal_id']); $calendars[$counter]['declined'] = $status->isDeclined($data['cal_id']); $counter++; } $this->setData($calendars ? $calendars : array()); return count($calendars) ? true : false; }
/** * delete * * @access public * @return */ public function delete() { global $ilDB; include_once './Services/Calendar/classes/class.ilCalendarRecurrence.php'; ilCalendarRecurrence::_delete($this->getEntryId()); $query = "DELETE FROM cal_entries " . "WHERE cal_id = " . $this->db->quote($this->getEntryId(), 'integer') . " "; $res = $ilDB->manipulate($query); include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; ilCalendarCategoryAssignments::_deleteByAppointmentId($this->getEntryId()); return true; }
public function insertBookingAppointment($a_insertedId, $a_booking_values, $a_from = NULL, $a_to = NULL) { //create appointment first if ($a_from == NULL || $a_to == NULL) { $a_from = $a_booking_values['from']['date'] . " " . $a_booking_values['from']['time']; $a_to = $a_booking_values['to']['date'] . " " . $a_booking_values['to']['time']; } $time_start = new ilDateTime($a_from, 1); $time_end = new ilDateTime($a_to, 1); $title = $a_booking_values['subject']; $room_name = $this->ilRoomSharingDatabase->getRoomName($a_booking_values['room']); $cal_cat_id = $a_booking_values['cal_id']; //use original ilCalendarEntry and let ILIAS do the work $app = new ilCalendarEntry(); $app->setStart($time_start); $app->setEnd($time_end); $app->setFullday(false); $app->setTitle($title); $app->setDescription($a_booking_values['comment']); $app->setAutoGenerated(true); $app->enableNotification(false); $app->setLocation($room_name); $app->validate(); $app->save(); $ass = new ilCalendarCategoryAssignments($app->getEntryId()); $ass->addAssignment($cal_cat_id); //update bookings-table afterwards $this->ilDB->manipulate('UPDATE ' . dbc::BOOKINGS_TABLE . ' SET calendar_entry_id = ' . $this->ilDB->quote($app->getEntryId(), 'integer') . ' WHERE id = ' . $this->ilDB->quote($a_insertedId, 'integer') . ' AND pool_id =' . $this->ilDB->quote($this->pool_id, 'integer')); }
/** * delete multiple entries */ public function delete() { if (!isset($_POST['apps'])) { ilUtil::sendFailure($this->lng->txt('select_one')); return $this->appointmentList(); } include_once 'Services/Calendar/classes/class.ilCalendarEntry.php'; include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; foreach ($_POST['apps'] as $entry_id) { // cancel booking for users $booking = ilBookingEntry::getInstanceByCalendarEntryId($entry_id); if ($booking) { foreach ($booking->getCurrentBookings($entry_id) as $user_id) { include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php'; ilConsultationHourUtils::cancelBooking($user_id, $entry_id, false); } } // remove calendar entries include_once './Services/Calendar/classes/class.ilCalendarEntry.php'; $entry = new ilCalendarEntry($entry_id); $entry->delete(); ilCalendarCategoryAssignments::_deleteByAppointmentId($entry_id); } ilBookingEntry::removeObsoleteEntries(); ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'), true); $this->ctrl->redirect($this, 'appointmentList'); }
/** * write a new event * * @access protected */ protected function writeEvent() { $entry = new ilCalendarEntry(); // Search for summary foreach ($this->getContainer()->getItemsByName('SUMMARY', false) as $item) { if (is_a($item, 'ilICalProperty')) { $entry->setTitle($this->purgeString($item->getValue())); break; } } // Search description foreach ($this->getContainer()->getItemsByName('DESCRIPTION', false) as $item) { if (is_a($item, 'ilICalProperty')) { $entry->setDescription($this->purgeString($item->getValue())); break; } } // Search location foreach ($this->getContainer()->getItemsByName('LOCATION', false) as $item) { if (is_a($item, 'ilICalProperty')) { $entry->setLocation($this->purgeString($item->getValue())); break; } } foreach ($this->getContainer()->getItemsByName('DTSTART') as $start) { $fullday = false; foreach ($start->getItemsByName('VALUE') as $type) { if ($type->getValue() == 'DATE') { $fullday = true; } } $start_tz = $this->default_timezone; foreach ($start->getItemsByName('TZID') as $param) { $start_tz = $this->getTZ($param->getValue()); } if ($fullday) { $start = new ilDate($start->getValue(), IL_CAL_DATE); } else { $start = new ilDateTime($start->getValue(), IL_CAL_DATETIME, $start_tz->getIdentifier()); } $entry->setStart($start); $entry->setFullday($fullday); } foreach ($this->getContainer()->getItemsByName('DTEND') as $end) { $fullday = false; foreach ($end->getItemsByName('VALUE') as $type) { if ($type->getValue() == 'DATE') { $fullday = true; } } $end_tz = $this->default_timezone; foreach ($end->getItemsByName('TZID') as $param) { $end_tz = $this->getTZ($param->getValue()); } if ($fullday) { $end = new ilDate($end->getValue(), IL_CAL_DATE); $end->increment(IL_CAL_DAY, -1); } else { $end = new ilDateTime($end->getValue(), IL_CAL_DATETIME, $end_tz->getIdentifier()); } $entry->setEnd($end); $entry->setFullday($fullday); } // save calendar event if ($this->category->getLocationType() == ilCalendarCategory::LTYPE_REMOTE) { $entry->setAutoGenerated(true); } $entry->save(); include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; $ass = new ilCalendarCategoryAssignments($entry->getEntryId()); $ass->addAssignment($this->category->getCategoryID()); // Recurrences foreach ($this->getContainer()->getItemsByName('RRULE') as $recurrence) { #var_dump("<pre>",$recurrence,"</pre>"); include_once './Services/Calendar/classes/class.ilCalendarRecurrence.php'; $rec = new ilCalendarRecurrence(); $rec->setEntryId($entry->getEntryId()); foreach ($recurrence->getItemsByName('FREQ') as $freq) { switch ($freq->getValue()) { case 'DAILY': case 'WEEKLY': case 'MONTHLY': case 'YEARLY': $rec->setFrequenceType((string) $freq->getValue()); break; default: $this->log->write(__METHOD__ . ': Cannot handle recurring event of type: ' . $freq->getValue()); break 3; } } foreach ($recurrence->getItemsByName('COUNT') as $value) { $rec->setFrequenceUntilCount((string) $value->getValue()); break; } foreach ($recurrence->getItemsByName('UNTIL') as $until) { $rec->setFrequenceUntilDate(new ilDate($until->getValue(), IL_CAL_DATE)); break; } foreach ($recurrence->getItemsByName('INTERVAL') as $value) { $rec->setInterval((string) $value->getValue()); break; } foreach ($recurrence->getItemsByName('BYDAY') as $value) { $rec->setBYDAY((string) $value->getValue()); break; } foreach ($recurrence->getItemsByName('BYWEEKNO') as $value) { $rec->setBYWEEKNO((string) $value->getValue()); break; } foreach ($recurrence->getItemsByName('BYMONTH') as $value) { $rec->setBYMONTH((string) $value->getValue()); break; } foreach ($recurrence->getItemsByName('BYMONTHDAY') as $value) { $rec->setBYMONTHDAY((string) $value->getValue()); break; } foreach ($recurrence->getItemsByName('BYYEARDAY') as $value) { $rec->setBYYEARDAY((string) $value->getValue()); break; } foreach ($recurrence->getItemsByName('BYSETPOS') as $value) { $rec->setBYSETPOS((string) $value->getValue()); break; } foreach ($recurrence->getItemsByName('WKST') as $value) { $rec->setWeekstart((string) $value->getValue()); break; } $rec->save(); } }