/** * Creates the iterator * * You should pass a VCALENDAR component, as well as the UID of the event * we're going to traverse. * * @param Sabre_VObject_Component $comp */ public function __construct(Sabre_VObject_Component $vcal, $uid = null) { if (is_null($uid)) { if ($vcal->name === 'VCALENDAR') { throw new InvalidArgumentException('If you pass a VCALENDAR object, you must pass a uid argument as well'); } $components = array($vcal); $uid = (string) $vcal->uid; } else { $components = $vcal->select('VEVENT'); } foreach ($components as $component) { if ((string) $component->uid == $uid) { if (isset($component->{'RECURRENCE-ID'})) { $this->overriddenEvents[$component->DTSTART->getDateTime()->getTimeStamp()] = $component; $this->overriddenDates[] = $component->{'RECURRENCE-ID'}->getDateTime(); } else { $this->baseEvent = $component; } } } if (!$this->baseEvent) { throw new InvalidArgumentException('Could not find a base event with uid: ' . $uid); } $this->startDate = clone $this->baseEvent->DTSTART->getDateTime(); $this->endDate = null; if (isset($this->baseEvent->DTEND)) { $this->endDate = clone $this->baseEvent->DTEND->getDateTime(); } else { $this->endDate = clone $this->startDate; if (isset($this->baseEvent->DURATION)) { $this->endDate->add(Sabre_VObject_DateTimeParser::parse($this->baseEvent->DURATION->value)); } } $this->currentDate = clone $this->startDate; $rrule = (string) $this->baseEvent->RRULE; $parts = explode(';', $rrule); foreach ($parts as $part) { list($key, $value) = explode('=', $part, 2); switch (strtoupper($key)) { case 'FREQ': if (!in_array(strtolower($value), array('secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly', 'yearly'))) { throw new InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value)); } $this->frequency = strtolower($value); break; case 'UNTIL': $this->until = Sabre_VObject_DateTimeParser::parse($value); break; case 'COUNT': $this->count = (int) $value; break; case 'INTERVAL': $this->interval = (int) $value; break; case 'BYSECOND': $this->bySecond = explode(',', $value); break; case 'BYMINUTE': $this->byMinute = explode(',', $value); break; case 'BYHOUR': $this->byHour = explode(',', $value); break; case 'BYDAY': $this->byDay = explode(',', strtoupper($value)); break; case 'BYMONTHDAY': $this->byMonthDay = explode(',', $value); break; case 'BYYEARDAY': $this->byYearDay = explode(',', $value); break; case 'BYWEEKNO': $this->byWeekNo = explode(',', $value); break; case 'BYMONTH': $this->byMonth = explode(',', $value); break; case 'BYSETPOS': $this->bySetPos = explode(',', $value); break; case 'WKST': $this->weekStart = strtoupper($value); break; } } // Parsing exception dates if (isset($this->baseEvent->EXDATE)) { foreach ($this->baseEvent->EXDATE as $exDate) { foreach (explode(',', (string) $exDate) as $exceptionDate) { $this->exceptionDates[] = Sabre_VObject_DateTimeParser::parse($exceptionDate, $this->startDate->getTimeZone()); } } } }