public function updateAllEvent(ICalendarEvent $event)
 {
     try {
         $dbHandler = $this->getConnection();
         $data = array(CalendarManager::EVENT_KEY_ID => $event->getId(), CalendarManager::EVENT_KEY_SUBJECT => $event->getSubject(), CalendarManager::EVENT_KEY_LOCATION => $event->getLocation(), CalendarManager::EVENT_KEY_DESCRIPTION => $event->getDescription(), CalendarManager::EVENT_KEY_ISALLDAY => $event->getIsAllDay(), CalendarManager::EVENT_KEY_TYPE => $event->getType(), CalendarManager::EVENT_KEY_PRIVACY => $event->getPrivacy(), CalendarManager::EVENT_KEY_CREATORID => $event->getCreatorId(), CalendarManager::EVENT_KEY_CALENDARID => $event->getCalendarId());
         $sqlQuery = 'UPDATE ' . self::EVENT_TABLE_NAME . ' SET ';
         foreach ($data as $key => $value) {
             if ($key != CalendarManager::EVENT_KEY_ID) {
                 $sqlQuery .= $key . ' = :' . $key . ', ';
             }
         }
         $sqlQuery = substr($sqlQuery, 0, -2);
         $sqlQuery .= ' WHERE ' . CalendarManager::EVENT_KEY_ID . ' = :' . CalendarManager::EVENT_KEY_ID;
         $stmt = $dbHandler->prepare($sqlQuery);
         $stmt->execute($data);
     } catch (Exception $e) {
         $this->destroyConnection();
         throw new EyeDBException('An error occured while attempting to update event with ID "' . $event->getId() . '".', 0, $e);
     }
     $this->destroyConnection();
 }
 public function createEvent(ICalendarEvent $event)
 {
     $filter = array(CalendarManager::CALENDAR_KEY_ID => $event->getCalendarid());
     $calendarData = self::retrieveCalendarData($filter);
     $cal = self::getRemoteCalendar($calendarData);
     $data = array('SUMMARY' => $event->getSubject(), 'LOCATION' => $event->getLocation(), 'DESCRIPTION' => $event->getDescription());
     $gmtTimeDiffrence = $event->getGmtTimeDiffrence();
     $ev = $cal->newComponent('VEVENT');
     $ev->setAllProperties($data);
     $isAllDay = $event->getIsAllDay();
     if ($isAllDay) {
         $ev->getBaseComponent()->addProperty('DTSTART', CalDavConverter::toCalDavDate($event->getTimeStart(), $isAllDay, $gmtTimeDiffrence), array('VALUE' => 'DATE'));
         $ev->getBaseComponent()->addProperty('DTEND', CalDavConverter::toCalDavDate($event->getTimeStart() + 86400, $isAllDay, $gmtTimeDiffrence), array('VALUE' => 'DATE'));
     } else {
         $ev->getBaseComponent()->addProperty('DTSTART', CalDavConverter::toCalDavDate($event->getTimeStart(), $isAllDay, $gmtTimeDiffrence));
         $ev->getBaseComponent()->addProperty('DTEND', CalDavConverter::toCalDavDate($event->getTimeEnd(), $isAllDay, $gmtTimeDiffrence));
     }
     if ($event->getRepeatType() == 'd') {
         if ($event->getFinalType() == 1) {
             $rrule = 'FREQ=DAILY';
         } else {
             if ($event->getFinalType() == 2) {
                 $rrule = 'FREQ=DAILY;UNTIL=' . CalDavConverter::toCalDavDate($event->getFinalValue(), 1, $gmtTimeDiffrence);
             } else {
                 if ($event->getFinalType() == 3) {
                     $rrule = 'FREQ=DAILY;COUNT=' . $event->getFinalValue();
                 }
             }
         }
         $ev->getBaseComponent()->addProperty('RRULE', $rrule);
     } else {
         if ($event->getRepeatType() == 'w') {
             $finalTS = $event->getFinalValue() + $gmtTimeDiffrence * 3600;
             $weekday = strtoupper(substr(date('l', $finalTS), 0, 2));
             if ($event->getFinalType() == 1) {
                 $rrule = 'FREQ=WEEKLY;BYDAY=' . $weekday;
             } else {
                 if ($event->getFinalType() == 2) {
                     $rrule = 'FREQ=WEEKLY;UNTIL=' . CalDavConverter::toCalDavDate($event->getFinalValue(), 0, $gmtTimeDiffrence) . ';BYDAY=' . $weekday;
                 } else {
                     if ($event->getFinalType() == 3) {
                         $rrule = 'FREQ=WEEKLY;COUNT=' . $event->getFinalValue() . ';BYDAY=' . $weekday;
                     }
                 }
             }
             $ev->getBaseComponent()->addProperty('RRULE', $rrule);
         } else {
             if ($event->getRepeatType() == 'm') {
                 $finalTS = $event->getTimeStart() + $gmtTimeDiffrence * 3600;
                 $monthday = date('d', $finalTS);
                 if ($event->getFinalType() == 1) {
                     $rrule = 'FREQ=YEARLY;BYMONTHDAY=' . $monthday;
                 } else {
                     if ($event->getFinalType() == 2) {
                         $rrule = 'FREQ=YEARLY;UNTIL=' . CalDavConverter::toCalDavDate($event->getFinalValue(), 0, $gmtTimeDiffrence) . ';BYMONTHDAY=' . $monthday;
                     } else {
                         if ($event->getFinalType() == 3) {
                             $rrule = 'FREQ=YEARLY;COUNT=' . $event->getFinalValue() . ';BYMONTHDAY=' . $monthday;
                         }
                     }
                 }
                 $ev->getBaseComponent()->addProperty('RRULE', $rrule);
             } else {
                 if ($event->getRepeatType() == 'y') {
                     $finalTS = $event->getTimeStart() + $gmtTimeDiffrence * 3600;
                     $monthday = date('d', $finalTS);
                     if ($event->getFinalType() == 1) {
                         $rrule = 'FREQ=YEARLY';
                     } else {
                         if ($event->getFinalType() == 2) {
                             $rrule = 'FREQ=YEARLY;UNTIL=' . CalDavConverter::toCalDavDate($event->getFinalValue(), 0, $gmtTimeDiffrence);
                         } else {
                             if ($event->getFinalType() == 3) {
                                 $rrule = 'FREQ=YEARLY;COUNT=' . $event->getFinalValue();
                             }
                         }
                     }
                     $ev->getBaseComponent()->addProperty('RRULE', $rrule);
                 }
             }
         }
     }
     $etag = $ev->getEtag();
     //$eventIdArr =  $cal->getAllRecurenceIdOfEvent($ev);
     $updatedEvent = $cal->update($ev->getUrl(), $ev->getEtag());
     $updatedUrl = $updatedEvent . '.ics';
     //print_r($updatedEvent);
     /*$calUpdated = self::getRemoteCalendar($calendarData);
     		
     		foreach ($calUpdated as $updatedCal){
     			//echo $updatedCal->getEtag().'=='.$etag;
     			if($updatedCal->getEtag()==$etag){
     				$updatedUrl=$updatedCal->getUrl();
     			
     			}
     		
     		}*/
     $startDate = date("Ymd\\THis\\Z", $event->getTimeStart());
     $endDate = date("Ymd\\THis\\Z", $event->getTimeEnd());
     $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 ($event->getRepeatType() != 'n') {
         $repeated = true;
     }
     $maxRepeatLimit = CalendarManager::MAX_REPEAT_LIMIT;
     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 = $updatedUrl . '_' . $i;
             $newEvent->setId($eventId);
             $newEvent->setSubject($event->getSubject());
             $newEvent->setTimeStart($timeStart);
             $newEvent->setTimeEnd($timeEnd);
             $newEvent->setCalendarId($event->getCalendarId());
             $newEvent->setIsAllDay($event->getIsAllDay());
             $newEvent->setRepetition($event->getRepetition());
             $newEvent->setRepeatType($event->getRepeatType());
             $newEvent->setLocation($event->getLocation());
             $newEvent->setDescription($event->getDescription());
             $newEvent->setFinalType($event->getFinalType());
             $newEvent->setFinalValue($event->getFinalValue());
             //$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 {
         $event->reSetId($updatedUrl);
         $newRepeatEventArr[] = $event;
     }
     // print_r($newRepeatEventArr); die;
     return $newRepeatEventArr;
 }