getRecurrence() 공개 메소드

Obtain a recurrence object. Note this returns a Horde_Date_Recurrence object, not Horde_ActiveSync_Message_Recurrence.
public getRecurrence ( ) : Horde_Date_Recurrence
리턴 Horde_Date_Recurrence
예제 #1
0
파일: Event.php 프로젝트: DSNS-LAB/Dmail
 /**
  * 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;
 }
예제 #2
0
 public function testRecurrenceDSTSwitch()
 {
     // Recurring event starts 10/1/2011 15:00:00 EDST
     $l = new Horde_Test_Log();
     $logger = $l->getLogger();
     // Test Decoding
     $stream = fopen(__DIR__ . '/fixtures/dst.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();
     $rrule = $appt->getRecurrence();
     // Get the next recurrence, still during EDST
     $next = $rrule->nextActiveRecurrence(new Horde_Date('2011-10-15'));
     $this->assertEquals('2011-10-15 15:00:00', (string) $next->setTimezone('America/New_York'));
     // Now get an occurence after the transition to EST.
     $next = $rrule->nextActiveRecurrence(new Horde_Date('2011-12-01'));
     $this->assertEquals('2011-12-10 15:00:00', (string) $next->setTimezone('America/New_York'));
 }