public function __construct(ICalendarManager $calendarManager = NULL, ApiManager $apiManager = NULL) { if (!$calendarManager) { $calendarManager = CalendarManager::getInstance(); } $this->calendarManager = $calendarManager; if (!$apiManager) { $apiManager = new ApiManager(); } $this->apiManager = $apiManager; }
public function &getShareableObjectData(IShareable $object, array &$shareableObjectData) { if (!$object instanceof ICalendar) { throw new EyeInvalidClassException('$object must be an instance of ICalendar.'); } try { CalendarManager::getInstance()->getCalendarById($object->getId()); } catch (EyeCalendarNotFoundException $e) { throw new EyeSharingException('Unable to share non-existing calendar ' . $object->getId() . '.', 0, $e); } $shareableObjectData[self::OBJECTDATA_KEY_ID] = $object->getId(); return $shareableObjectData; }
public function userCreated(UMEvent $e) { $newUser = $e->getSource(); if ($newUser instanceof AbstractEyeosUser) { $calendar = CalendarManager::getInstance()->getNewCalendar(); $calendar->setOwnerId($newUser->getId()); $calendar->setName($newUser->getName()); $calendar->setDescription($newUser->getName() . '\'s personal calendar.'); $calendar->setTimezone(0); CalendarManager::getInstance()->saveCalendar($calendar); $prefs = CalendarManager::getInstance()->getCalendarPreferences($newUser->getId(), $calendar->getId()); $prefs->setVisible(true); CalendarManager::getInstance()->saveCalendarPreferences($prefs); } }
public static function getMaxEventLimit($params) { return CalendarManager::getInstance()->getMaxEventLimit(); }
/** * * @param <type> $account * @param <type> $settings * @return <type> */ public function performSync() { $user_id = $this->_account->IdUser; $fnUserId = $this->_account->Email; $this->log("-----sync calendars for user_id={$user_id} fnUserId={$fnUserId}"); $wmCalendarManager = new CalendarManager($user_id); $fnCalendarManager = new FunambolCalendarManager($user_id); if (!$wmCalendarManager->InitManager() || !$fnCalendarManager->InitManager()) { return false; } $wmCalendarManager->InitAccount($this->_account); // in minutes. with dayLightSavingTime adjustment // WARNING // this is different from contacts $accountOffset = $this->_settings->AllowUsersChangeTimeZone ? $this->_account->GetDefaultTimeOffset() : $this->_account->GetDefaultTimeOffset($this->_settings->DefaultTimeZone); // - (int)date('I')*60; // get full list of calendars from account $wmCalendars = $wmCalendarManager->GetCalendarsList(true, true); $funambolEventIds = array(); $minCalendarId = NULL; foreach ($wmCalendars as $wmCalendar) { $wmEvents = $wmCalendar->GetValue('calendarEvents'); //echo "<pre>"; //var_dump( $wmEvents ); //echo "</pre>"; //continue; if ($minCalendarId == NULL) { $minCalendarId = $wmCalendar->GetValue('calendarId', 'int'); } if ($wmCalendar->GetValue('calendarId', 'int') < $minCalendarId) { $minCalendarId = $wmCalendar->GetValue('calendarId', 'int'); } foreach ($wmEvents as $wmEvent) { /* if($wmEvent->IsEventRepeat() ) { $internalRepeatForm = $wmEvent->GetInternalRepeatForm(); if(!is_null($internalRepeatForm)) { echo "<br/> RepeatContainer"; echo "<br/> eventTimeFrom=".$internalRepeatForm->GetValue('eventTimeFrom'); echo "<br/> repeatPeriod=".$internalRepeatForm->GetValue('repeatPeriod'); echo "<br/> repeatOrder=".$internalRepeatForm->GetValue('repeatOrder'); echo "<br/> repeatNum=".$internalRepeatForm->GetValue('repeatNum'); echo "<br/> repeatUntil=".$internalRepeatForm->GetValue('repeatUntil'); echo "<br/> repeatWeekNumber=".$internalRepeatForm->GetValue('repeatWeekNumber'); echo "<br/> repeatEnd=".$internalRepeatForm->GetValue('repeatEnd'); echo "<br/> repeatSun=".$internalRepeatForm->GetValue('repeatSun'); echo "<br/> repeatMon=".$internalRepeatForm->GetValue('repeatMon'); echo "<br/> repeatTue=".$internalRepeatForm->GetValue('repeatTue'); echo "<br/> repeatWed=".$internalRepeatForm->GetValue('repeatWed'); echo "<br/> repeatThu=".$internalRepeatForm->GetValue('repeatThu'); echo "<br/> repeatFri=".$internalRepeatForm->GetValue('repeatFri'); echo "<br/> repeatSat=".$internalRepeatForm->GetValue('repeatSat'); echo "<br/> excluded=".$internalRepeatForm->GetValue('excluded'); } } */ if ($wmEvent->GetValue('FunambolEventId', 'int') == NULL) { // new event in WM, push event to FN // FIXME, calendar name $fnEventContainer = $this->ConvertWMToFunambolEventContainer($fnUserId, "", $wmEvent, TRUE, $accountOffset); $funambolEventId = $fnCalendarManager->ReplaceEvent($fnEventContainer); $wmCalendarManager->SetEventFunambolId($wmEvent, $funambolEventId); array_push($funambolEventIds, $funambolEventId); $this->log("new event in WM. wmEventId=" . $wmEvent->GetValue('eventId') . " fnEventId={$funambolEventId}"); } else { // this event was already synchronized with FN $fnEvent = $fnCalendarManager->GetEvent($wmEvent->GetValue('FunambolEventId', 'int')); // if wmEvent is updated lately - overwrite it in FN $this->log("known event in WM. wmEventId=" . $wmEvent->GetValue('eventId') . " fnEventId=" . $fnEvent->GetValue('id')); // GMT modification date as 2000-12-31 23:59:59 $wmDateModified = $wmEvent->GetValue('eventLastModified'); // seconds from Epoch for this date $wmTimestampModified = strtotime($wmDateModified); // local server's timestamp - offset to get GMT as seconds from Epoch $fnTimestampModified = $this->ConvertFNtoWMTimestamp($fnEvent->GetValue('last_update'), TRUE); if ($wmTimestampModified == $fnTimestampModified) { $this->log("known event -- unmodified"); array_push($funambolEventIds, $wmEvent->GetValue('FunambolEventId', 'int')); } else { if ($wmTimestampModified > $fnTimestampModified) { // push event to FN // FIXME, calendar name $this->log("known event -- push from WM to FN"); $fnEventContainer = $this->ConvertWMToFunambolEventContainer($fnUserId, "", $wmEvent, TRUE, $accountOffset); $fnCalendarManager->ReplaceEvent($fnEventContainer); array_push($funambolEventIds, $wmEvent->GetValue('FunambolEventId', 'int')); } else { // TODO $this->log("known event -- pull from FN to WM"); // the simplest way - delete event and create new one; $wmCalendarManager->DeleteEvent($wmEvent, TRUE, TRUE); } } } // if(new or old event) } // foreach ($wmEvents) } // foreach( $wmCalendars ) // $funambolEventIds contains all events that are in WM // pull data from FN which are not in WM already $fnCalendarManager->SetUserAccount($fnUserId); $this->log("Pulling events from FN to WM. funambolEventIds=" . join(',', $funambolEventIds)); $fnEvents = $fnCalendarManager->GetEventsListExcluded($funambolEventIds); foreach ($fnEvents as $fnEvent) { $this->log("adding new event from FN to WM subj=" . $fnEvent->GetValue('subject') . " id=" . $fnEvent->GetValue('id')); $this->log("status of FN event:" . $fnEvent->GetValue('status')); $this->log("adding to calendar:" . $minCalendarId); $wmEvent = $this->ConvertFunambolToWMEventContainer($fnEvent, TRUE, $accountOffset); // FIXME, calendar id $wmEvent->SetValue('calendarId', $minCalendarId); $wmEvent->ConvertToRRule(); // echo "<pre>"; // var_dump($wmEvent); // echo "</pre>"; if ($fnEvent->GetValue('status') != FUNAMBOL_STATUS_DELETED) { $wmCalendarManager->CreateEvent($wmEvent); } } // foreach($fnEvents) return true; }
public function deleteCalendar($params) { if (!isset($params['calendarId']) || !is_string($params['calendarId'])) { throw new EyeMissingArgumentException('Missing or invalid $params[\'calendarId\'].'); } $cal = CalendarManager::getInstance()->getCalendarById($params['calendarId']); CalendarManager::getInstance()->deleteCalendar($cal); }
public function updateEvent($params) { $filter = array(CalendarManager::CALENDAR_KEY_ID => $params['calendarId']); $calendarData = self::retrieveCalendarData($filter); $cal = self::getRemoteCalendar($calendarData); $urls = explode('_', $params['id']); $url = $urls[0]; foreach ($cal as $obj1) { if ($url == $obj1->getUrl()) { $thisEvent = $obj1; } } $props = $thisEvent->getBaseComponent()->getProperties(); foreach ($props as $prop) { if ($prop->name == "DTSTART") { $dtstartzone = isset($prop->parameters["TZID"]) ? $prop->parameters["TZID"] : ""; $params['dtstartzone'] = $dtstartzone; $dtStartForAll = $prop->content; } if ($prop->name == "DTEND") { $dtEndForAll = $prop->content; } } //if (!$params['isEditAll'] && $params['eventGroup'] > 0) if (!$params['isEditAll']) { // edit on only this. $thisEvent = $cal->newComponent('VEVENT'); $thisEvent->update($params, $cal); $repeated = false; /*$startDate= date("Ymd\THis\Z",$params['timeStart']); $endDate= date("Ymd\THis\Z",$params['timeEnd']); */ $startDate = date("Ymd\\THis\\Z", CalDavConverter::dateCalDavToEyeos($dtStartForAll) - $params['gmtTimeDiffrence'] * 3600); $endDate = date("Ymd\\THis\\Z", CalDavConverter::dateCalDavToEyeos($dtEndForAll) - $params['gmtTimeDiffrence'] * 3600); } else { // edit all events $newValues = array('DTSTART' => $params['dtstart'], 'DTEND' => $params['dtend'], 'SUMMARY' => $params['subject'], 'LOCATION' => $params['location'], 'DESCRIPTION' => $params['description']); $thisEvent->setAllProperties($newValues); $cal->update($thisEvent->getUrl(), $thisEvent->getEtag()); $repeated = true; $startDate = date("Ymd\\THis\\Z", CalDavConverter::dateCalDavToEyeos($dtStartForAll) - $params['gmtTimeDiffrence'] * 3600); $endDate = date("Ymd\\THis\\Z", CalDavConverter::dateCalDavToEyeos($dtEndForAll) - $params['gmtTimeDiffrence'] * 3600); } $creator = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser(); $start = new When(); $start->recur($startDate)->rrule($rrule); $end = new When(); $end->recur($endDate)->rrule($rrule); /*$repeated=false; if($params['repeatType']!='n'){ $repeated=true; }*/ $maxRepeatLimit = CalendarManager::MAX_REPEAT_LIMIT; $repeated = true; if ($repeated) { for ($i = 0; $i < $maxRepeatLimit; $i++) { $sDate = $start->next(); if (!is_object($sDate)) { break; } $timeStart = $sDate->getTimestamp(); $eDate = $end->next(); $timeEnd = $eDate->getTimestamp(); $newEvent = CalendarManager::getInstance()->getNewEvent(); $eventId = $url . '_' . $i; $newEvent->setId($eventId); $newEvent->setSubject($params['subject']); $newEvent->setTimeStart($timeStart); $newEvent->setTimeEnd($timeEnd); $newEvent->setCalendarId($params['calendarId']); $newEvent->setIsAllDay($params['isAllDay']); $newEvent->setRepetition($params['repetition']); $newEvent->setRepeatType($params['repeatType']); $newEvent->setLocation($params['location']); $newEvent->setDescription($params['description']); $newEvent->setFinalType($params['finalType']); $newEvent->setFinalValue($params['finalValue']); //$newEvent->seteventGroup(1); // its repeat event so we need to set it to greater then 0 $newEvent->setCreatorId($creator->getId()); $newEvent->setEventGroup(1); $newRepeatEventArr[] = $newEvent; } } else { $newEvent = CalendarManager::getInstance()->getNewEvent(); $eventId = $url; $newEvent->setId($eventId); $newEvent->setSubject($params['subject']); $newEvent->setTimeStart($params['timeStart']); $newEvent->setTimeEnd($params['timeEnd']); $newEvent->setCalendarId($params['calendarId']); $newEvent->setIsAllDay($params['isAllDay']); $newEvent->setRepetition($params['repetition']); $newEvent->setRepeatType($params['repeatType']); $newEvent->setLocation($params['location']); $newEvent->setDescription($params['description']); $newEvent->setFinalType($params['finalType']); $newEvent->setFinalValue($params['finalValue']); //$newEvent->seteventGroup(1); // its repeat event so we need to set it to greater then 0 $newEvent->setCreatorId($creator->getId()); $newEvent->setEventGroup(0); $newRepeatEventArr[] = $newEvent; } //print_r($newRepeatEventArr); return $newRepeatEventArr; }
public function setCalendarId($calendarId) { self::$CalendarID = $calendarId; }
public function getShareOwner() { $calendar = CalendarManager::getInstance()->getCalendarById($this->getCalendarId()); return UMManager::getInstance()->getUserById($calendar->getOwnerId()); }