Exemplo n.º 1
0
 /**
  * Convert a Rrule object from an Icalendar Rrule string.
  * 
  * Set the values of this object from the latest version of an Icalendar Rrule
  */
 private function _parseRruleIcalendar($rrule)
 {
     $params = explode(';', $rrule);
     while ($param = array_shift($params)) {
         $param_arr = explode('=', $param);
         if (isset($param_arr[0]) && isset($param_arr[1])) {
             $rrule_arr[strtoupper(trim($param_arr[0]))] = strtoupper(trim($param_arr[1]));
         }
     }
     $this->_byday = !empty($rrule_arr['BYDAY']) ? explode(',', $rrule_arr['BYDAY']) : array();
     $this->_bymonth = !empty($rrule_arr['BYMONTH']) ? intval($rrule_arr['BYMONTH']) : 0;
     $this->_bymonthday = !empty($rrule_arr['BYMONTHDAY']) ? intval($rrule_arr['BYMONTHDAY']) : 0;
     $this->_freq = !empty($rrule_arr['FREQ']) ? $rrule_arr['FREQ'] : '';
     $this->_until = isset($rrule_arr['UNTIL']) ? intval(\GO\Base\Util\Date::parseIcalDate($rrule_arr['UNTIL'])) : 0;
     $this->_count = !empty($rrule_arr['COUNT']) ? intval($rrule_arr['COUNT']) : 0;
     $this->_interval = !empty($rrule_arr['INTERVAL']) ? intval($rrule_arr['INTERVAL']) : 1;
     $this->_bysetpos = !empty($rrule_arr['BYSETPOS']) ? intval($rrule_arr['BYSETPOS']) : 0;
     //fix for thundebird sending: RRULE:FREQ=DAILY;UNTIL=20150326T080000Z;BYDAY=MO,TU,WE,TH,FR
     //it should work as RRULE:FREQ=WEEKLY;UNTIL=20150326T080000Z;BYDAY=MO,TU,WE,TH,FR
     if (!empty($this->_byday) && $this->_freq == 'DAILY') {
         $this->_freq = 'WEEKLY';
     }
     if ($this->_bysetpos < 0) {
         throw new \Exception("'Last X of month' recurrence pattern currently not supported by Group-Office.");
     }
     $this->_splitDaysAndSetPos();
     //if rrule is passed like this: RRULE:INTERVAL=1;FREQ=WEEKLY;BYDAY=
     //then assume days should be the event start time day.
     if (isset($rrule_arr['BYDAY']) && empty($this->_byday)) {
         $this->_byday = array($this->_days[gmdate('w', $this->_eventstarttime)]);
     }
     //		if($this->_freq == 'YEARLY' && (!empty($this->_bymonth) || !empty($this->_bymonth))) {
     //			throw new \Exception("Sorry, this recurrence pattern is not supported by Group-Office");
     //		}
     //figure out end time of event
     if ($this->_count > 0 && empty($this->_until)) {
         $this->_until = $until = 0;
         for ($i = 0; $i < $this->_count; $i++) {
             $until = $this->getNextRecurrence();
         }
         $this->_until = $until;
     }
     return true;
 }