| <?php |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| namespace Eluceo\iCal\Property\Event; |
|
|
| use Eluceo\iCal\ParameterBag; |
| use Eluceo\iCal\Property\ValueInterface; |
| use InvalidArgumentException; |
|
|
| |
| |
| |
| |
| |
| class RecurrenceRule implements ValueInterface |
| { |
| const FREQ_YEARLY = 'YEARLY'; |
| const FREQ_MONTHLY = 'MONTHLY'; |
| const FREQ_WEEKLY = 'WEEKLY'; |
| const FREQ_DAILY = 'DAILY'; |
| const FREQ_HOURLY = 'HOURLY'; |
| const FREQ_MINUTELY = 'MINUTELY'; |
| const FREQ_SECONDLY = 'SECONDLY'; |
|
|
| const WEEKDAY_SUNDAY = 'SU'; |
| const WEEKDAY_MONDAY = 'MO'; |
| const WEEKDAY_TUESDAY = 'TU'; |
| const WEEKDAY_WEDNESDAY = 'WE'; |
| const WEEKDAY_THURSDAY = 'TH'; |
| const WEEKDAY_FRIDAY = 'FR'; |
| const WEEKDAY_SATURDAY = 'SA'; |
|
|
| |
| |
| |
| |
| |
| protected $freq = self::FREQ_YEARLY; |
|
|
| |
| |
| |
| |
| |
| protected $canUseBySetPos = false; |
|
|
| |
| |
| |
| protected $interval = 1; |
|
|
| |
| |
| |
| protected $count = null; |
|
|
| |
| |
| |
| protected $until = null; |
|
|
| |
| |
| |
| protected $wkst; |
|
|
| |
| |
| |
| protected $bySetPos = null; |
|
|
| |
| |
| |
| protected $byMonth; |
|
|
| |
| |
| |
| protected $byWeekNo; |
|
|
| |
| |
| |
| protected $byYearDay; |
|
|
| |
| |
| |
| protected $byMonthDay; |
|
|
| |
| |
| |
| protected $byDay; |
|
|
| |
| |
| |
| protected $byHour; |
|
|
| |
| |
| |
| protected $byMinute; |
|
|
| |
| |
| |
| protected $bySecond; |
|
|
| public function getEscapedValue(): string |
| { |
| return $this->buildParameterBag()->toString(); |
| } |
|
|
| |
| |
| |
| protected function buildParameterBag() |
| { |
| $parameterBag = new ParameterBag(); |
|
|
| $parameterBag->setParam('FREQ', $this->freq); |
|
|
| if (null !== $this->interval) { |
| $parameterBag->setParam('INTERVAL', $this->interval); |
| } |
|
|
| if (null !== $this->count) { |
| $parameterBag->setParam('COUNT', $this->count); |
| } |
|
|
| if (null != $this->until) { |
| $parameterBag->setParam('UNTIL', $this->until->format('Ymd\THis\Z')); |
| } |
|
|
| if (null !== $this->wkst) { |
| $parameterBag->setParam('WKST', $this->wkst); |
| } |
|
|
| if (null !== $this->bySetPos && $this->canUseBySetPos) { |
| $parameterBag->setParam('BYSETPOS', $this->bySetPos); |
| } |
|
|
| if (null !== $this->byMonth) { |
| $parameterBag->setParam('BYMONTH', explode(',', $this->byMonth)); |
| } |
|
|
| if (null !== $this->byWeekNo) { |
| $parameterBag->setParam('BYWEEKNO', explode(',', $this->byWeekNo)); |
| } |
|
|
| if (null !== $this->byYearDay) { |
| $parameterBag->setParam('BYYEARDAY', explode(',', $this->byYearDay)); |
| } |
|
|
| if (null !== $this->byMonthDay) { |
| $parameterBag->setParam('BYMONTHDAY', explode(',', $this->byMonthDay)); |
| } |
|
|
| if (null !== $this->byDay) { |
| $parameterBag->setParam('BYDAY', explode(',', $this->byDay)); |
| } |
|
|
| if (null !== $this->byHour) { |
| $parameterBag->setParam('BYHOUR', explode(',', $this->byHour)); |
| } |
|
|
| if (null !== $this->byMinute) { |
| $parameterBag->setParam('BYMINUTE', explode(',', $this->byMinute)); |
| } |
|
|
| if (null !== $this->bySecond) { |
| $parameterBag->setParam('BYSECOND', explode(',', $this->bySecond)); |
| } |
|
|
| return $parameterBag; |
| } |
|
|
| |
| |
| |
| |
| |
| public function setCount($count) |
| { |
| $this->count = $count; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| public function getCount() |
| { |
| return $this->count; |
| } |
|
|
| |
| |
| |
| public function setUntil(\DateTimeInterface $until = null) |
| { |
| $this->until = $until; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| public function getUntil() |
| { |
| return $this->until; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function setFreq($freq) |
| { |
| if (@constant('static::FREQ_' . $freq) !== null) { |
| $this->freq = $freq; |
| } else { |
| throw new \InvalidArgumentException("The Frequency {$freq} is not supported."); |
| } |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| public function getFreq() |
| { |
| return $this->freq; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public function setInterval($interval) |
| { |
| $this->interval = $interval; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| public function getInterval() |
| { |
| return $this->interval; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public function setWkst($value) |
| { |
| $this->wkst = $value; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function setBySetPos($value) |
| { |
| if (null === $value) { |
| $this->bySetPos = $value; |
|
|
| return $this; |
| } |
|
|
| if (!(is_string($value) || is_array($value) || is_int($value))) { |
| throw new InvalidArgumentException('Invalid value for BYSETPOS'); |
| } |
|
|
| $list = $value; |
|
|
| if (is_int($value)) { |
| if ($value === 0 || $value < -366 || $value > 366) { |
| throw new InvalidArgumentException('Invalid value for BYSETPOS'); |
| } |
| $this->bySetPos = [$value]; |
|
|
| return $this; |
| } |
|
|
| if (is_string($value)) { |
| $list = explode(',', $value); |
| } |
|
|
| $output = []; |
|
|
| foreach ($list as $item) { |
| if (is_string($item)) { |
| if (!preg_match('/^ *-?[0-9]* *$/', $item)) { |
| throw new InvalidArgumentException('Invalid value for BYSETPOS'); |
| } |
| $item = intval($item); |
| } |
|
|
| if (!is_int($item) || $item === 0 || $item < -366 || $item > 366) { |
| throw new InvalidArgumentException('Invalid value for BYSETPOS'); |
| } |
|
|
| $output[] = $item; |
| } |
|
|
| $this->bySetPos = $output; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function setByMonth($month) |
| { |
| if (!is_integer($month) || $month <= 0 || $month > 12) { |
| throw new InvalidArgumentException('Invalid value for BYMONTH'); |
| } |
|
|
| $this->byMonth = $month; |
|
|
| $this->canUseBySetPos = true; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function setByWeekNo($value) |
| { |
| if (!is_integer($value) || $value > 53 || $value < -53 || $value === 0) { |
| throw new InvalidArgumentException('Invalid value for BYWEEKNO'); |
| } |
|
|
| $this->byWeekNo = $value; |
|
|
| $this->canUseBySetPos = true; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function setByYearDay($day) |
| { |
| if (!is_integer($day) || $day > 366 || $day < -366 || $day === 0) { |
| throw new InvalidArgumentException('Invalid value for BYYEARDAY'); |
| } |
|
|
| $this->byYearDay = $day; |
|
|
| $this->canUseBySetPos = true; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function setByMonthDay($day) |
| { |
| if (!is_integer($day) || $day > 31 || $day < -31 || $day === 0) { |
| throw new InvalidArgumentException('Invalid value for BYMONTHDAY'); |
| } |
|
|
| $this->byMonthDay = $day; |
|
|
| $this->canUseBySetPos = true; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function setByDay(string $day) |
| { |
| $this->byDay = $day; |
|
|
| $this->canUseBySetPos = true; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function setByHour($value) |
| { |
| if (!is_integer($value) || $value < 0 || $value > 23) { |
| throw new \InvalidArgumentException('Invalid value for BYHOUR'); |
| } |
|
|
| $this->byHour = $value; |
|
|
| $this->canUseBySetPos = true; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function setByMinute($value) |
| { |
| if (!is_integer($value) || $value < 0 || $value > 59) { |
| throw new \InvalidArgumentException('Invalid value for BYMINUTE'); |
| } |
|
|
| $this->byMinute = $value; |
|
|
| $this->canUseBySetPos = true; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function setBySecond($value) |
| { |
| if (!is_integer($value) || $value < 0 || $value > 60) { |
| throw new \InvalidArgumentException('Invalid value for BYSECOND'); |
| } |
|
|
| $this->bySecond = $value; |
|
|
| $this->canUseBySetPos = true; |
|
|
| return $this; |
| } |
| } |
|
|