Esempio n. 1
0
    public function actionTestVObject($params)
    {
        \GO::session()->runAsRoot();
        $ical_str = 'BEGIN:VCALENDAR
VERSION:1.0
BEGIN:VEVENT
UID:762
SUMMARY:weekly test
DTSTART:20040503T160000Z
DTEND:20040503T170000Z
X-EPOCAGENDAENTRYTYPE:APPOINTMENT
CLASS:PUBLIC
DCREATED:20040502T220000Z
RRULE:W1 MO #0
LAST-MODIFIED:20040503T101900Z
PRIORITY:0
STATUS:NEEDS ACTION
END:VEVENT
END:VCALENDAR';
        $vobject = \GO\Base\VObject\Reader::read($ical_str);
        $event = new \GO\Calendar\Model\Event();
        $event->importVObject($vobject->vevent[0]);
        var_dump($event->getAttributes());
    }
Esempio n. 2
0
 /**
  * Handle's a request from an organizer from another externals system
  * 
  * @param Sabre\VObject\Component $vevent
  * @param type $recurrenceDate
  * @return boolean
  * @throws \GO\Base\Exception\NotFound
  */
 private function _handleIcalendarRequest(\Sabre\VObject\Component $vevent, $recurrenceDate, \GO\Email\Model\Account $account)
 {
     $settings = \GO\Calendar\Model\Settings::model()->getDefault($account->user);
     if (!$settings->calendar) {
         throw new \Exception(GO::t('noDefaultCalendar', 'calendar'));
     }
     $masterEvent = \GO\Calendar\Model\Event::model()->findByUuid((string) $vevent->uid, 0, $settings->calendar_id);
     if (!$settings->calendar->checkPermissionLevel(\GO\Base\Model\Acl::WRITE_PERMISSION)) {
         throw new \Exception(sprintf(\GO::t('cannotHandleInvitation', 'calendar'), $masterEvent->calendar->name));
     }
     //delete existing data
     if (!$recurrenceDate) {
         //if no recurring instance was given delete the master event
         if ($masterEvent) {
             if (!$masterEvent->calendar->checkPermissionLevel(\GO\Base\Model\Acl::DELETE_PERMISSION)) {
                 throw new \Exception(sprintf(\GO::t('cannotHandleInvitation2', 'calendar'), $masterEvent->calendar->name));
             }
             $masterEvent->delete();
         }
     } else {
         if ($masterEvent) {
             $exceptionEvent = $masterEvent->findException($recurrenceDate);
             if ($exceptionEvent) {
                 if (!$masterEvent->calendar->checkPermissionLevel(\GO\Base\Model\Acl::DELETE_PERMISSION)) {
                     throw new \Exception(sprintf(\GO::t('cannotHandleInvitation2', 'calendar'), $masterEvent->calendar->name));
                 }
                 $exceptionEvent->delete();
             } else {
                 $event = $this->findByStartTime($vevent, $settings->calendar_id);
                 if ($event) {
                     $event->delete();
                 }
             }
             $exception = $masterEvent->hasException($recurrenceDate);
             if ($exception) {
                 if (!$masterEvent->calendar->checkPermissionLevel(\GO\Base\Model\Acl::DELETE_PERMISSION)) {
                     throw new \Exception(sprintf(\GO::t('cannotHandleInvitation2', 'calendar'), $masterEvent->calendar->name));
                 }
                 $exception->delete();
             }
         } else {
             //			throw new \Exception("ja");
             $event = $this->findByStartTime($vevent, $settings->calendar_id);
             if ($event) {
                 $event->delete();
             }
         }
     }
     $eventUpdated = !$recurrenceDate && $masterEvent || $recurrenceDate && !empty($exceptionEvent);
     $importAttributes = array('is_organizer' => false, 'calendar_id' => $settings->calendar_id);
     //import it
     $event = new \GO\Calendar\Model\Event();
     $event->importVObject($vevent, $importAttributes, false, true);
     //notify orgnizer
     $participant = $event->getParticipantOfCalendar();
     //		if(!$participant)
     //		{
     //			//this is a bad situation. The import thould have detected a user for one of the participants.
     //			//It uses the E-mail account aliases to determine a user. See \GO\Calendar\Model\Event::importVObject
     //			$participant = new \GO\Calendar\Model\Participant();
     //			$participant->event_id=$event->id;
     //			$participant->user_id=$event->calendar->user_id;
     //			$participant->email=$event->calendar->user->email;
     //			$participant->save();
     //		}
     //		if($status)
     //				$participant->status=$status;
     //			$participant->save();
     //		$event->replyToOrganizer();
     $langKey = $eventUpdated ? 'eventUpdatedIn' : 'eventScheduledIn';
     $response['attendance_event_id'] = $event->id;
     $response['feedback'] = sprintf(\GO::t($langKey, 'calendar'), $event->calendar->name, $participant->statusName);
     $response['success'] = true;
     return $response;
 }