コード例 #1
0
 /**
  * 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();
 }
コード例 #2
0
 /**
  * Create a new bookings calendar category.
  *
  * It is named after the parenting RoomSharing-oject
  *
  * @access protected
  * @return
  */
 protected function createBookingsCalendarCategory()
 {
     global $ilUser;
     $cat = new ilCalendarCategory();
     $cat->setColor($this->color);
     $cat->setType(ilCalendarCategory::TYPE_USR);
     $title = $this->getParentObject()->getTitle();
     $cat->setTitle($title);
     $cat->setObjId($ilUser->getId());
     return $cat->add();
 }
コード例 #3
0
 /**
  * read permissions
  *
  * @access private
  * @param
  * @return
  */
 private function readPermissions()
 {
     global $ilUser, $rbacsystem, $ilAccess;
     $this->editable = false;
     $this->visible = false;
     $this->importable = false;
     include_once './Services/Calendar/classes/class.ilCalendarShared.php';
     $shared = ilCalendarShared::getSharedCalendarsForUser($ilUser->getId());
     $cat = new ilCalendarCategory((int) $_GET['category_id']);
     switch ($cat->getType()) {
         case ilCalendarCategory::TYPE_USR:
             if ($cat->getObjId() == $ilUser->getId()) {
                 $this->visible = true;
                 $this->editable = true;
                 $this->importable = true;
             } elseif (isset($shared[$cat->getCategoryID()])) {
                 $this->visible = true;
             }
             break;
         case ilCalendarCategory::TYPE_GLOBAL:
             $this->importable = $this->editable = $rbacsystem->checkAccess('edit_event', ilCalendarSettings::_getInstance()->getCalendarSettingsId());
             $this->visible = true;
             break;
         case ilCalendarCategory::TYPE_OBJ:
             $this->editable = false;
             $refs = ilObject::_getAllReferences($cat->getObjId());
             foreach ($refs as $ref) {
                 if ($ilAccess->checkAccess('read', '', $ref)) {
                     $this->visible = true;
                 }
                 if ($ilAccess->checkAccess('edit_event', '', $ref)) {
                     $this->importable = true;
                 }
             }
             break;
         case ilCalendarCategory::TYPE_BOOK:
         case ilCalendarCategory::TYPE_CH:
             $this->editable = $ilUser->getId() == $cat->getCategoryID();
             $this->visible = true;
             $this->importable = false;
             break;
     }
 }
コード例 #4
0
 /**
  * Read info about selected calendar
  * @param type $a_cal_id
  */
 protected function readSelectedCalendar($a_cal_id)
 {
     include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
     $cat = new ilCalendarCategory($a_cal_id);
     if ($cat->getType() == ilCalendarCategory::TYPE_OBJ) {
         $this->readSelectedCategories(array($cat->getObjId()));
         $this->addSubitemCalendars();
     } else {
         $this->categories[] = $a_cal_id;
     }
 }
コード例 #5
0
 /**
  * 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)));
     }
 }
コード例 #6
0
 /**
  * Sync external calendars
  */
 protected function synchroniseExternalCalendars()
 {
     global $ilUser;
     if (!ilCalendarSettings::_getInstance()->isWebCalSyncEnabled()) {
         return false;
     }
     // @todo make this thread safe
     $limit = new ilDateTime(time(), IL_CAL_UNIX);
     $limit->increment(IL_CAL_HOUR, -1 * ilCalendarSettings::_getInstance()->getWebCalSyncHours());
     $cats = ilCalendarCategories::_getInstance($ilUser->getId());
     foreach ($cats->getCategoriesInfo() as $cat_id => $info) {
         if ($info['remote']) {
             // Check for execution
             $category = new ilCalendarCategory($cat_id);
             if (ilDateTime::_before($category->getRemoteSyncLastExecution(), $limit)) {
                 // update in any case to avoid multiple updates of invalid calendar sources.
                 $category->setRemoteSyncLastExecution(new ilDateTime(time(), IL_CAL_UNIX));
                 $category->update();
                 include_once './Services/Calendar/classes/class.ilCalendarRemoteReader.php';
                 $remote = new ilCalendarRemoteReader($category->getRemoteUrl());
                 $remote->setUser($category->getRemoteUser());
                 $remote->setPass($category->getRemotePass());
                 $remote->read();
                 $remote->import($category);
                 break;
             }
         }
     }
 }
コード例 #7
0
 /**
  * Create a default calendar
  *
  * @access protected
  * @return
  */
 protected function createDefaultCalendar()
 {
     global $ilUser, $lng;
     $cat = new ilCalendarCategory();
     $cat->setColor(ilCalendarCategory::DEFAULT_COLOR);
     $cat->setType(ilCalendarCategory::TYPE_USR);
     $cat->setTitle($this->lng->txt('cal_default_calendar'));
     $cat->setObjId($ilUser->getId());
     return $cat->add();
 }
コード例 #8
0
 /**
  * Get calendars
  */
 public function getCalendars()
 {
     global $ilUser, $tree;
     include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
     include_once './Services/Calendar/classes/class.ilCalendarHidden.php';
     $hidden_obj = ilCalendarHidden::_getInstanceByUserId($ilUser->getId());
     $hidden = $hidden_obj->getHidden();
     $cats = ilCalendarCategories::_getInstance($ilUser->getId());
     $all = $cats->getCategoriesInfo();
     $tmp_title_counter = array();
     $categories = array();
     foreach ($all as $category) {
         $tmp_arr['obj_id'] = $category['obj_id'];
         $tmp_arr['id'] = $category['cat_id'];
         $tmp_arr['hidden'] = (bool) in_array($category['cat_id'], $hidden);
         $tmp_arr['title'] = $category['title'];
         $tmp_arr['type'] = $category['type'];
         // Append object type to make type sortable
         $tmp_arr['type_sortable'] = ilCalendarCategory::lookupCategorySortIndex($category['type']);
         if ($category['type'] == ilCalendarCategory::TYPE_OBJ) {
             $tmp_arr['type_sortable'] .= '_' . ilObject::_lookupType($category['obj_id']);
         }
         $tmp_arr['color'] = $category['color'];
         $tmp_arr['editable'] = $category['editable'];
         $categories[] = $tmp_arr;
         // count title for appending the parent container if there is more than one entry.
         $tmp_title_counter[$category['type'] . '_' . $category['title']]++;
     }
     $path_categories = array();
     foreach ($categories as $cat) {
         if ($cat['type'] == ilCalendarCategory::TYPE_OBJ) {
             if ($tmp_title_counter[$cat['type'] . '_' . $cat['title']] > 1) {
                 foreach (ilObject::_getAllReferences($cat['obj_id']) as $ref_id) {
                     $cat['path'] = $this->buildPath($ref_id);
                     break;
                 }
             }
         }
         $path_categories[] = $cat;
     }
     $path_categories = ilUtil::sortArray($path_categories, 'title', "asc");
     $this->calendars = $path_categories;
 }
コード例 #9
0
 /**
  * parse
  *
  * @access public
  * @return
  */
 public function parse()
 {
     global $ilUser, $tree;
     include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
     $cats = ilCalendarCategories::_getInstance($ilUser->getId());
     $cats->initialize(ilCalendarCategories::MODE_MANAGE);
     $tmp_title_counter = array();
     $categories = array();
     foreach ($cats->getCategoriesInfo() as $category) {
         $tmp_arr['obj_id'] = $category['obj_id'];
         $tmp_arr['id'] = $category['cat_id'];
         $tmp_arr['title'] = $category['title'];
         $tmp_arr['type'] = $category['type'];
         // Append object type to make type sortable
         $tmp_arr['type_sortable'] = ilCalendarCategory::lookupCategorySortIndex($category['type']);
         if ($category['type'] == ilCalendarCategory::TYPE_OBJ) {
             $tmp_arr['type_sortable'] .= '_' . ilObject::_lookupType($category['obj_id']);
         }
         $tmp_arr['color'] = $category['color'];
         $tmp_arr['editable'] = $category['editable'];
         $tmp_arr['accepted'] = $category['accepted'];
         $tmp_arr['remote'] = $category['remote'];
         $categories[] = $tmp_arr;
         // count title for appending the parent container if there is more than one entry.
         $tmp_title_counter[$category['type'] . '_' . $category['title']]++;
     }
     $path_categories = array();
     foreach ($categories as $cat) {
         if ($cat['type'] == ilCalendarCategory::TYPE_OBJ) {
             if ($tmp_title_counter[$cat['type'] . '_' . $cat['title']] > 1) {
                 foreach (ilObject::_getAllReferences($cat['obj_id']) as $ref_id) {
                     include_once './Services/Tree/classes/class.ilPathGUI.php';
                     $path = new ilPathGUI();
                     $path->setUseImages(false);
                     $path->enableTextOnly(false);
                     $cat['path'] = $path->getPath(ROOT_FOLDER_ID, $ref_id);
                     break;
                 }
             }
         }
         $path_categories[] = $cat;
     }
     $this->setData($path_categories);
 }
コード例 #10
0
 /**
  * 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;
 }
コード例 #11
0
 /**
  * delete category
  *
  * @access public
  * @param
  * @return
  * @static
  */
 public static function deleteCategory($a_obj_id)
 {
     global $ilLog;
     include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
     if (!($cat_id = ilCalendarCategories::_lookupCategoryIdByObjId($a_obj_id))) {
         $ilLog->write(__METHOD__ . ': Cannot find calendar category for obj_id ' . $a_obj_id);
         return false;
     }
     $category = new ilCalendarCategory($cat_id);
     $category->delete();
 }
コード例 #12
0
 /**
  * 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;
             }
         }
     }
 }
コード例 #13
0
 /**
  * set appointments
  *
  * @access public
  * @return
  */
 public function setAppointments($a_apps)
 {
     include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
     include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
     include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
     $cat = new ilCalendarCategory($this->cat_id);
     foreach ($a_apps as $cal_entry_id) {
         $entry = new ilCalendarEntry($cal_entry_id);
         $rec = ilCalendarRecurrences::_getFirstRecurrence($entry->getEntryId());
         // booking
         if ($cat->getType() == ilCalendarCategory::TYPE_CH) {
             include_once 'Services/Booking/classes/class.ilBookingEntry.php';
             $book = new ilBookingEntry($entry->getContextId());
             if ($book) {
                 $title = $entry->getTitle();
                 if ($book->isOwner()) {
                     $max = (int) $book->getNumberOfBookings();
                     $current = (int) $book->getCurrentNumberOfBookings($entry->getEntryId());
                     if ($max > 1) {
                         $title .= ' (' . $current . '/' . $max . ')';
                     } else {
                         if ($current == $max) {
                             $title .= ' (' . $this->lng->txt('cal_booked_out') . ')';
                         } else {
                             $title .= ' (' . $this->lng->txt('cal_book_free') . ')';
                         }
                     }
                 } else {
                     if ($book->hasBooked($entry->getEntryId())) {
                         $title .= ' (' . $this->lng->txt('cal_date_booked') . ')';
                     }
                 }
             }
         } else {
             $title = $entry->getPresentationTitle();
         }
         $tmp_arr['id'] = $entry->getEntryId();
         $tmp_arr['title'] = $title;
         $tmp_arr['description'] = $entry->getDescription();
         $tmp_arr['fullday'] = $entry->isFullday();
         $tmp_arr['begin'] = $entry->getStart()->get(IL_CAL_UNIX);
         $tmp_arr['end'] = $entry->getEnd()->get(IL_CAL_UNIX);
         $tmp_arr['dt_sort'] = $entry->getStart()->get(IL_CAL_UNIX);
         $tmp_arr['dt'] = ilDatePresentation::formatPeriod($entry->getStart(), $entry->getEnd());
         #$tmp_arr['duration'] = ($dur = $tmp_arr['end'] - $tmp_arr['begin']) ? $dur : 60 * 60 * 24;
         $tmp_arr['duration'] = $tmp_arr['end'] - $tmp_arr['begin'];
         if ($tmp_arr['fullday']) {
             $tmp_arr['duration'] += 60 * 60 * 24;
         }
         if (!$tmp_arr['fullday'] and $tmp_arr['end'] == $tmp_arr['begin']) {
             $tmp_arr['duration'] = '';
         }
         $tmp_arr['frequence'] = $rec->getFrequenceType();
         $tmp_arr['deletable'] = (!$entry->isAutoGenerated() and $this->is_editable);
         $appointments[] = $tmp_arr;
     }
     $this->setData($appointments ? $appointments : array());
 }
コード例 #14
0
 /**
  * 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;
     }
 }