Horde_Date_Recurrence::fromKolab PHP Method

fromKolab() public method

Parses the recurrence data from a Kolab hash.
public fromKolab ( array $hash ) : boolean
$hash array The hash to convert.
return boolean True if the hash seemed valid, false otherwise.
    public function fromKolab($hash)
    {
        $this->reset();
        if (!isset($hash['interval']) || !isset($hash['cycle'])) {
            $this->setRecurType(self::RECUR_NONE);
            return false;
        }
        $this->setRecurInterval((int) $hash['interval']);
        $parse_day = false;
        $set_daymask = false;
        $update_month = false;
        $update_daynumber = false;
        $update_weekday = false;
        $nth_weekday = -1;
        switch ($hash['cycle']) {
            case 'daily':
                $this->setRecurType(self::RECUR_DAILY);
                break;
            case 'weekly':
                $this->setRecurType(self::RECUR_WEEKLY);
                $parse_day = true;
                $set_daymask = true;
                break;
            case 'monthly':
                if (!isset($hash['daynumber'])) {
                    $this->setRecurType(self::RECUR_NONE);
                    return false;
                }
                switch ($hash['type']) {
                    case 'daynumber':
                        $this->setRecurType(self::RECUR_MONTHLY_DATE);
                        $update_daynumber = true;
                        break;
                    case 'weekday':
                        $this->setRecurType(self::RECUR_MONTHLY_WEEKDAY);
                        $nth_weekday = (int) $hash['daynumber'];
                        if ($nth_weekday < 0) {
                            // This is not officially part of the Kolab 2.0 specs.
                            $this->setRecurType(self::RECUR_MONTHLY_LAST_WEEKDAY);
                        }
                        $hash['daynumber'] = 1;
                        $parse_day = true;
                        $update_daynumber = true;
                        $update_weekday = true;
                        break;
                }
                break;
            case 'yearly':
                if (!isset($hash['type'])) {
                    $this->setRecurType(self::RECUR_NONE);
                    return false;
                }
                switch ($hash['type']) {
                    case 'monthday':
                        $this->setRecurType(self::RECUR_YEARLY_DATE);
                        $update_month = true;
                        $update_daynumber = true;
                        break;
                    case 'yearday':
                        if (!isset($hash['daynumber'])) {
                            $this->setRecurType(self::RECUR_NONE);
                            return false;
                        }
                        $this->setRecurType(self::RECUR_YEARLY_DAY);
                        // Start counting days in January.
                        $hash['month'] = 'january';
                        $update_month = true;
                        $update_daynumber = true;
                        break;
                    case 'weekday':
                        if (!isset($hash['daynumber'])) {
                            $this->setRecurType(self::RECUR_NONE);
                            return false;
                        }
                        $this->setRecurType(self::RECUR_YEARLY_WEEKDAY);
                        $nth_weekday = (int) $hash['daynumber'];
                        $hash['daynumber'] = 1;
                        $parse_day = true;
                        $update_month = true;
                        $update_daynumber = true;
                        $update_weekday = true;
                        break;
                }
        }
        if (isset($hash['range-type']) && isset($hash['range'])) {
            switch ($hash['range-type']) {
                case 'number':
                    $this->setRecurCount((int) $hash['range']);
                    break;
                case 'date':
                    $recur_end = new Horde_Date($hash['range']);
                    $recur_end->hour = 23;
                    $recur_end->min = 59;
                    $recur_end->sec = 59;
                    $this->setRecurEnd($recur_end);
                    break;
            }
        }
        // Need to parse <day>?
        $last_found_day = -1;
        if ($parse_day) {
            if (!isset($hash['day'])) {
                $this->setRecurType(self::RECUR_NONE);
                return false;
            }
            $mask = 0;
            $bits = array('monday' => Horde_Date::MASK_MONDAY, 'tuesday' => Horde_Date::MASK_TUESDAY, 'wednesday' => Horde_Date::MASK_WEDNESDAY, 'thursday' => Horde_Date::MASK_THURSDAY, 'friday' => Horde_Date::MASK_FRIDAY, 'saturday' => Horde_Date::MASK_SATURDAY, 'sunday' => Horde_Date::MASK_SUNDAY);
            $days = array('monday' => Horde_Date::DATE_MONDAY, 'tuesday' => Horde_Date::DATE_TUESDAY, 'wednesday' => Horde_Date::DATE_WEDNESDAY, 'thursday' => Horde_Date::DATE_THURSDAY, 'friday' => Horde_Date::DATE_FRIDAY, 'saturday' => Horde_Date::DATE_SATURDAY, 'sunday' => Horde_Date::DATE_SUNDAY);
            foreach ($hash['day'] as $day) {
                // Validity check.
                if (empty($day) || !isset($bits[$day])) {
                    continue;
                }
                $mask |= $bits[$day];
                $last_found_day = $days[$day];
            }
            if ($set_daymask) {
                $this->setRecurOnDay($mask);
            }
        }
        if ($update_month || $update_daynumber || $update_weekday) {
            if ($update_month) {
                $month2number = array('january' => 1, 'february' => 2, 'march' => 3, 'april' => 4, 'may' => 5, 'june' => 6, 'july' => 7, 'august' => 8, 'september' => 9, 'october' => 10, 'november' => 11, 'december' => 12);
                if (isset($month2number[$hash['month']])) {
                    $this->start->month = $month2number[$hash['month']];
                }
            }
            if ($update_daynumber) {
                if (!isset($hash['daynumber'])) {
                    $this->setRecurType(self::RECUR_NONE);
                    return false;
                }
                $this->start->mday = $hash['daynumber'];
            }
            if ($update_weekday) {
                $this->start->setNthWeekday($last_found_day, $nth_weekday);
            }
        }
        // Exceptions.
        if (isset($hash['exclusion'])) {
            foreach ($hash['exclusion'] as $exception) {
                if ($exception instanceof DateTime) {
                    $this->exceptions[] = $exception->format('Ymd');
                }
            }
        }
        if (isset($hash['complete'])) {
            foreach ($hash['complete'] as $completion) {
                if ($exception instanceof DateTime) {
                    $this->completions[] = $completion->format('Ymd');
                }
            }
        }
        return true;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Constructor.
  *
  * @param array $event The event data.
  */
 public function __construct(array $event)
 {
     if (isset($event['uid'])) {
         $this->_event_id = $event['uid'];
     }
     if (!$event['start-date'] instanceof Horde_Date) {
         $this->_start = new Horde_Date($event['start-date']);
     } else {
         $this->_start = $event['start-date'];
     }
     if (!$event['end-date'] instanceof Horde_Date) {
         $this->_end = new Horde_Date($event['end-date']);
     } else {
         $this->_end = $event['end-date'];
     }
     if (isset($event['summary'])) {
         $this->_title = $event['summary'];
     }
     if (isset($event['location'])) {
         $this->_location = $event['location'];
     }
     if (isset($event['sensitivity']) && ($event['sensitivity'] == 'private' || $event['sensitivity'] == 'confidential')) {
         $this->_private = true;
     }
     if (isset($event['show-time-as'])) {
         $this->_status = $event['show-time-as'];
     } else {
         $this->_status = self::STATUS_NONE;
     }
     // Recurrence
     if (isset($event['recurrence'])) {
         $this->_recurrence = new Horde_Date_Recurrence($this->_start);
         $this->_recurrence->fromKolab($event['recurrence']);
     }
 }
All Usage Examples Of Horde_Date_Recurrence::fromKolab