Author: Jan Schneider (jan@horde.org)
Inheritance: implements Serializable
示例#1
0
文件: Sql.php 项目: horde/horde
 /**
  * Imports a backend specific event object.
  *
  * @param array $event  Backend specific event object that this object
  *                      will represent.
  */
 public function fromDriver($SQLEvent)
 {
     $driver = $this->getDriver();
     if (isset($SQLEvent['event_timezone'])) {
         $this->timezone = $SQLEvent['event_timezone'];
     }
     $tz_local = date_default_timezone_get();
     $this->allday = (bool) $SQLEvent['event_allday'];
     if (!$this->allday && $driver->getParam('utc')) {
         $this->start = new Horde_Date($SQLEvent['event_start'], 'UTC');
         $this->start->setTimezone($tz_local);
         $this->end = new Horde_Date($SQLEvent['event_end'], 'UTC');
         $this->end->setTimezone($tz_local);
     } else {
         $this->start = new Horde_Date($SQLEvent['event_start']);
         $this->end = new Horde_Date($SQLEvent['event_end']);
         if ($this->end->hour == 23 && $this->end->min == 59) {
             $this->end->hour = $this->end->min = $this->end->sec = 0;
             $this->end->mday++;
         }
     }
     $this->durMin = ($this->end->timestamp() - $this->start->timestamp()) / 60;
     $this->title = $driver->convertFromDriver($SQLEvent['event_title']);
     $this->id = $SQLEvent['event_id'];
     $this->uid = $SQLEvent['event_uid'];
     $this->creator = $SQLEvent['event_creator_id'];
     $this->organizer = $SQLEvent['event_organizer'];
     if (!empty($SQLEvent['event_recurtype'])) {
         $this->recurrence = new Horde_Date_Recurrence($this->start);
         $this->recurrence->setRecurType((int) $SQLEvent['event_recurtype']);
         $this->recurrence->setRecurInterval((int) $SQLEvent['event_recurinterval']);
         if (isset($SQLEvent['event_recurenddate']) && $SQLEvent['event_recurenddate'] != '9999-12-31 23:59:59') {
             if ($driver->getParam('utc')) {
                 $recur_end = new Horde_Date($SQLEvent['event_recurenddate'], 'UTC');
                 if ($recur_end->min == 0) {
                     /* Old recurrence end date format. */
                     $recur_end = new Horde_Date($SQLEvent['event_recurenddate']);
                     $recur_end->hour = 23;
                     $recur_end->min = 59;
                     $recur_end->sec = 59;
                 } else {
                     $recur_end->setTimezone(date_default_timezone_get());
                 }
             } else {
                 $recur_end = new Horde_Date($SQLEvent['event_recurenddate']);
                 $recur_end->hour = 23;
                 $recur_end->min = 59;
                 $recur_end->sec = 59;
             }
             $this->recurrence->setRecurEnd($recur_end);
         }
         if (isset($SQLEvent['event_recurcount'])) {
             $this->recurrence->setRecurCount((int) $SQLEvent['event_recurcount']);
         }
         if (isset($SQLEvent['event_recurdays'])) {
             $this->recurrence->recurData = (int) $SQLEvent['event_recurdays'];
         }
         if (!empty($SQLEvent['event_exceptions'])) {
             $this->recurrence->exceptions = explode(',', $SQLEvent['event_exceptions']);
         }
     }
     if (isset($SQLEvent['event_location'])) {
         $this->location = $driver->convertFromDriver($SQLEvent['event_location']);
     }
     if (isset($SQLEvent['event_url'])) {
         $this->url = $SQLEvent['event_url'];
     }
     if (isset($SQLEvent['event_private'])) {
         $this->private = (bool) $SQLEvent['event_private'];
     }
     if (isset($SQLEvent['event_status'])) {
         $this->status = (int) $SQLEvent['event_status'];
     }
     if (isset($SQLEvent['event_attendees'])) {
         $attendees = unserialize($SQLEvent['event_attendees']);
         if ($attendees) {
             if (!is_object($attendees)) {
                 $this->attendees = new Kronolith_Attendee_List();
                 foreach ($attendees as $email => $attendee) {
                     $this->attendees->add(Kronolith_Attendee::migrate($email, $driver->convertFromDriver($attendee)));
                 }
             } else {
                 $this->attendees = new Kronolith_Attendee_List(iterator_to_array($attendees));
             }
         }
     }
     if (isset($SQLEvent['event_resources'])) {
         $resources = unserialize($SQLEvent['event_resources']);
         if ($resources) {
             $this->_resources = array_change_key_case($driver->convertFromDriver($resources));
         }
     }
     if (isset($SQLEvent['event_description'])) {
         $this->description = $driver->convertFromDriver($SQLEvent['event_description']);
     }
     if (isset($SQLEvent['event_alarm'])) {
         $this->alarm = (int) $SQLEvent['event_alarm'];
     }
     if (isset($SQLEvent['event_alarm_methods'])) {
         $methods = unserialize($SQLEvent['event_alarm_methods']);
         if ($methods) {
             $this->methods = $driver->convertFromDriver($methods);
         }
     }
     if (isset($SQLEvent['event_baseid'])) {
         $this->baseid = $SQLEvent['event_baseid'];
     }
     if (isset($SQLEvent['event_exceptionoriginaldate'])) {
         if ($driver->getParam('utc')) {
             $this->exceptionoriginaldate = new Horde_Date($SQLEvent['event_exceptionoriginaldate'], 'UTC');
             $this->exceptionoriginaldate->setTimezone($tz_local);
         } else {
             $this->exceptionoriginaldate = new Horde_Date($SQLEvent['event_exceptionoriginaldate']);
         }
     }
     $this->initialized = true;
     $this->stored = true;
 }
示例#2
0
 public function testMigrate()
 {
     $attendees = array(Kronolith_Attendee::migrate('*****@*****.**', array('attendance' => Kronolith::PART_REQUIRED, 'response' => Kronolith::RESPONSE_NONE, 'name' => 'Jürgen Doe')), Kronolith_Attendee::migrate('Jane Doe', array('attendance' => Kronolith::PART_OPTIONAL, 'response' => Kronolith::RESPONSE_ACCEPTED, 'name' => 'Jane Doe')), Kronolith_Attendee::migrate('*****@*****.**', array('attendance' => Kronolith::PART_NONE, 'response' => Kronolith::RESPONSE_DECLINED, 'name' => 'Jack Doe')), Kronolith_Attendee::migrate('*****@*****.**', array('attendance' => Kronolith::PART_NONE, 'response' => Kronolith::RESPONSE_TENTATIVE)));
     $this->_testAttendees($attendees, true);
 }