/** * get first recurrence * * @access public * @param int cal id * @return * @static */ public static function _getFirstRecurrence($a_cal_id) { if ($recs = self::_getRecurrences($a_cal_id)) { return $recs[0]; } $new_rec = new ilCalendarRecurrence(); $new_rec->setEntryId($a_cal_id); return $new_rec; }
/** * 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; }
/** * Constructor * * @access public * @param * @return */ public function __construct() { parent::__construct(); }
/** * 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; } }
/** * 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(); } }