getExceptions() public method

Return the exceptions for this appointment.
public getExceptions ( ) : array
return array An array of Horde_ActiveSync_Message_Exception objects
Ejemplo n.º 1
0
 /**
  * Imports the values for this event from a MS ActiveSync Message.
  *
  * @see Horde_ActiveSync_Message_Appointment
  */
 public function fromASAppointment(Horde_ActiveSync_Message_Appointment $message)
 {
     /* New event? */
     if ($this->id === null) {
         $this->creator = $GLOBALS['registry']->getAuth();
     }
     if (strlen($title = $message->getSubject())) {
         $this->title = $title;
     }
     if ($message->getProtocolVersion() == Horde_ActiveSync::VERSION_TWOFIVE && strlen($description = $message->getBody())) {
         $this->description = $description;
     } elseif ($message->getProtocolVersion() > Horde_ActiveSync::VERSION_TWOFIVE) {
         if ($message->airsyncbasebody->type == Horde_ActiveSync::BODYPREF_TYPE_HTML) {
             $this->description = Horde_Text_Filter::filter($message->airsyncbasebody->data, 'Html2text');
         } else {
             $this->description = $message->airsyncbasebody->data;
         }
     }
     if (strlen($location = $message->getLocation())) {
         $this->location = $location;
     }
     /* Date/times */
     $tz = $message->getTimezone();
     $dates = $message->getDatetime();
     $this->start = clone $dates['start'];
     $this->start->setTimezone($tz);
     $this->end = clone $dates['end'];
     $this->end->setTimezone($tz);
     $this->allday = $dates['allday'];
     if ($tz != date_default_timezone_get()) {
         $this->timezone = $tz;
     }
     /* Sensitivity */
     $this->private = $message->getSensitivity() == Horde_ActiveSync_Message_Appointment::SENSITIVITY_PRIVATE || $message->getSensitivity() == Horde_ActiveSync_Message_Appointment::SENSITIVITY_CONFIDENTIAL ? true : false;
     /* Busy Status */
     $status = $message->getBusyStatus();
     switch ($status) {
         case Horde_ActiveSync_Message_Appointment::BUSYSTATUS_BUSY:
             $status = Kronolith::STATUS_CONFIRMED;
             break;
         case Horde_ActiveSync_Message_Appointment::BUSYSTATUS_FREE:
             $status = Kronolith::STATUS_FREE;
             break;
         case Horde_ActiveSync_Message_Appointment::BUSYSTATUS_TENTATIVE:
             $status = Kronolith::STATUS_TENTATIVE;
             break;
             // @TODO: not sure how "Out" should show in kronolith...
         // @TODO: not sure how "Out" should show in kronolith...
         case Horde_ActiveSync_Message_Appointment::BUSYSTATUS_OUT:
             $status = Kronolith::STATUS_CONFIRMED;
         default:
             // EAS Specifies default should be free.
             $status = Kronolith::STATUS_FREE;
     }
     $this->status = $status;
     /* Alarm */
     if ($alarm = $message->getReminder()) {
         $this->alarm = $alarm;
     }
     /* Recurrence */
     if ($rrule = $message->getRecurrence()) {
         /* Exceptions */
         /* Since AS keeps exceptions as part of the original event, we need to
          * delete all existing exceptions and re-create them. The only drawback
          * to this is that the UIDs will change.
          */
         $kronolith_driver = Kronolith::getDriver(null, $this->calendar);
         $this->recurrence = $rrule;
         if (!empty($this->uid)) {
             $search = new StdClass();
             $search->start = $rrule->getRecurStart();
             $search->end = $rrule->getRecurEnd();
             $search->baseid = $this->uid;
             $results = $kronolith_driver->search($search);
             foreach ($results as $days) {
                 foreach ($days as $exception) {
                     $kronolith_driver->deleteEvent($exception->id);
                 }
             }
         }
         $erules = $message->getExceptions();
         foreach ($erules as $rule) {
             /* Readd the exception event, but only if not deleted */
             if (!$rule->deleted) {
                 $event = $kronolith_driver->getEvent();
                 $times = $rule->getDatetime();
                 $original = $rule->getExceptionStartTime();
                 $original->setTimezone($tz);
                 $this->recurrence->addException($original->format('Y'), $original->format('m'), $original->format('d'));
                 $event->start = $times['start'];
                 $event->end = $times['end'];
                 $event->start->setTimezone($tz);
                 $event->end->setTimezone($tz);
                 $event->allday = $times['allday'];
                 $event->title = $rule->getSubject();
                 $event->title = empty($event->title) ? $this->title : $event->title;
                 $event->description = $rule->getBody();
                 $event->description = empty($event->description) ? $this->description : $event->description;
                 $event->baseid = $this->uid;
                 $event->exceptionoriginaldate = $original;
                 $event->initialized = true;
                 if ($tz != date_default_timezone_get()) {
                     $event->timezone = $tz;
                 }
                 $event->save();
             } else {
                 /* For exceptions that are deletions, just add the exception */
                 $exceptiondt = $rule->getExceptionStartTime();
                 $exceptiondt->setTimezone($tz);
                 $this->recurrence->addException($exceptiondt->format('Y'), $exceptiondt->format('m'), $exceptiondt->format('d'));
             }
         }
     }
     /* Attendees */
     $attendees = $message->getAttendees();
     foreach ($attendees as $attendee) {
         switch ($attendee->status) {
             case Horde_ActiveSync_Message_Attendee::STATUS_ACCEPT:
                 $response_code = Kronolith::RESPONSE_ACCEPTED;
                 break;
             case Horde_ActiveSync_Message_Attendee::STATUS_DECLINE:
                 $response_code = Kronolith::RESPONSE_DECLINED;
                 break;
             case Horde_ActiveSync_Message_Attendee::STATUS_TENTATIVE:
                 $response_code = Kronolith::RESPONSE_TENTATIVE;
                 break;
             default:
                 $response_code = Kronolith::RESPONSE_NONE;
         }
         switch ($attendee->type) {
             case Horde_ActiveSync_Message_Attendee::TYPE_REQUIRED:
                 $part_type = Kronolith::PART_REQUIRED;
                 break;
             case Horde_ActiveSync_Message_Attendee::TYPE_OPTIONAL:
                 $part_type = Kronolith::PART_OPTIONAL;
                 break;
             case Horde_ActiveSync_Message_Attendee::TYPE_RESOURCE:
                 $part_type = Kronolith::PART_REQUIRED;
         }
         $this->addAttendee($attendee->email, $part_type, $response_code, $attendee->name);
     }
     /* Categories (Tags) */
     $this->_tags = $message->getCategories();
     // 14.1
     if ($message->getProtocolVersion() >= Horde_ActiveSync::VERSION_FOURTEENONE) {
         $this->url = $message->onlinemeetingexternallink;
     }
     /* Flag that we are initialized */
     $this->initialized = true;
 }
Ejemplo n.º 2
0
 public function testDecodingSimpleExceptions()
 {
     $l = new Horde_Test_Log();
     $logger = $l->getLogger();
     // Test Decoding
     $stream = fopen(__DIR__ . '/fixtures/simpleexception.wbxml', 'r+');
     $decoder = new Horde_ActiveSync_Wbxml_Decoder($stream);
     $element = $decoder->getElementStartTag(Horde_ActiveSync::SYNC_DATA);
     $appt = new Horde_ActiveSync_Message_Appointment(array('logger' => $logger));
     $appt->decodeStream($decoder);
     fclose($stream);
     $decoder->getElementEndTag();
     // Same properties that are testing in testDeoding, but test again
     // here to be sure recurrence doesn't mess up the deocder.
     $this->assertEquals('Event Title', $appt->subject);
     $this->assertEquals('Event Description', $appt->body);
     $this->assertEquals('Philadelphia, PA', $appt->location);
     $this->assertEquals(Horde_ActiveSync_Message_Appointment::SENSITIVITY_PERSONAL, (int) $appt->sensitivity);
     $this->assertEquals(Horde_ActiveSync_Message_Appointment::BUSYSTATUS_BUSY, (int) $appt->busystatus);
     $start = clone $appt->starttime;
     // Ensure it's UTC
     $this->assertEquals('UTC', $start->timezone);
     //...and correct.
     $start->setTimezone('America/New_York');
     $this->assertEquals('2011-12-01 15:00:00', (string) $start);
     // Recurrence properties
     $rrule = $appt->getRecurrence();
     $this->assertEquals('2011-12-01 15:00:00', (string) $rrule->getRecurStart()->setTimezone('America/New_York'));
     $this->assertEquals('', (string) $rrule->getRecurEnd());
     $this->assertEquals(Horde_Date_Recurrence::RECUR_WEEKLY, $rrule->getRecurType());
     $this->assertEquals(2, $rrule->getRecurInterval());
     $this->assertEquals(Horde_Date::MASK_THURSDAY, $days = $rrule->getRecurOnDays());
     // Ensure the exception came over (should have one, deleted exception
     // on 2011-12-29)
     $exceptions = $appt->getExceptions();
     $e = array_pop($exceptions);
     $this->assertEquals(true, (bool) $e->deleted);
     $dt = $e->getExceptionStartTime();
     $rrule->addException($dt->format('Y'), $dt->format('m'), $dt->format('d'));
     // This would normally be 2011-12-29, but that's an exception.
     $date = $rrule->nextActiveRecurrence(new Horde_Date('2011-12-16'));
     $this->assertEquals('2012-01-12 15:00:00', (string) $date);
 }