http://www.ietf.org/rfc/rfc2445.txt Information, not contained in the built/parsed RRULE, necessary to determine the various recurrence instance start time and dates are derived from the DTSTART property (default: \DateTime()). For example, "FREQ=YEARLY;BYMONTH=1" doesn't specify a specific day within the month or a time. This information would be the same as what is specified for DTSTART. BYxxx rule parts modify the recurrence in some manner. BYxxx rule parts for a period of time which is the same or greater than the frequency generally reduce or limit the number of occurrences of the recurrence generated. For example, "FREQ=DAILY;BYMONTH=1" reduces the number of recurrence instances from all days (if BYMONTH tag is not present) to all days in January. BYxxx rule parts for a period of time less than the frequency generally increase or expand the number of occurrences of the recurrence. For example, "FREQ=YEARLY;BYMONTH=1,2" increases the number of days within the yearly recurrence set from 1 (if BYMONTH tag is not present) to 2. If multiple BYxxx rule parts are specified, then after evaluating the specified FREQ and INTERVAL rule parts, the BYxxx rule parts are applied to the current set of evaluated occurrences in the following order: BYMONTH, BYWEEKNO, BYYEARDAY, BYMONTHDAY, BYDAY, BYHOUR, BYMINUTE, BYSECOND and BYSETPOS; then COUNT and UNTIL are evaluated. Here is an example of evaluating multiple BYxxx rule parts. FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;BYMINUTE=30 First, the "INTERVAL=2" would be applied to "FREQ=YEARLY" to arrive at "every other year". Then, "BYMONTH=1" would be applied to arrive at "every January, every other year". Then, "BYDAY=SU" would be applied to arrive at "every Sunday in January, every other year". Then, "BYHOUR=8,9" would be applied to arrive at "every Sunday in January at 8 AM and 9 AM, every other year". Then, "BYMINUTE=30" would be applied to arrive at "every Sunday in January at 8:30 AM and 9:30 AM, every other year". Then, lacking information from RRULE, the second is derived from DTSTART, to end up in "every Sunday in January at 8:30:00 AM and 9:30:00 AM, every other year". Similarly, if the BYMINUTE, BYHOUR, BYDAY, BYMONTHDAY or BYMONTH rule part were missing, the appropriate minute, hour, day or month would have been retrieved from the "DTSTART" property. Example: The following is a rule which specifies 10 meetings which occur every other day: FREQ=DAILY;COUNT=10;INTERVAL=2
Автор: Shaun Simmons (shaun@envysphere.com)
Пример #1
0
 public function testSetExDates()
 {
     $rule = new Rule('FREQ=DAILY;COUNT=3', new \DateTime('2014-06-01'));
     $exDates = array(new DateExclusion(new \DateTime('2014-06-02'), false));
     $rule->setExDates($exDates);
     $computed = $this->transformer->transform($rule);
     $this->assertCount(2, $computed);
     $this->assertEquals(new \DateTime('2014-06-01'), $computed[0]->getStart());
     $this->assertEquals(new \DateTime('2014-06-03'), $computed[1]->getStart());
 }
Пример #2
0
 public function testSetRDates()
 {
     $rule = new Rule('FREQ=DAILY;COUNT=2', new \DateTime('2015-12-10'));
     $rDates = array(new DateInclusion(new \DateTime('2015-12-08'), false));
     $rule->setRDates($rDates);
     $computed = $this->transformer->transform($rule);
     $this->assertCount(3, $computed);
     $this->assertEquals(new \DateTime('2015-12-10'), $computed[0]->getStart());
     $this->assertEquals(new \DateTime('2015-12-11'), $computed[1]->getStart());
     $this->assertEquals(new \DateTime('2015-12-08'), $computed[2]->getStart());
 }
Пример #3
0
 protected function addByDay(Rule $rule)
 {
     $byDay = $rule->getByDay();
     $this->addFragment('on');
     $this->addFragment($this->getByDayAsText($byDay));
 }
Пример #4
0
 /**
  * @param Rule      $rule
  * @param \DateTime $dt
  *
  * @return array
  */
 public static function getTimeSet(Rule $rule, \DateTime $dt)
 {
     $set = array();
     if (null === $rule || $rule->getFreq() >= Frequency::HOURLY) {
         return $set;
     }
     $byHour = $rule->getByHour();
     $byMinute = $rule->getByMinute();
     $bySecond = $rule->getBySecond();
     if (empty($byHour)) {
         $byHour = array($dt->format('G'));
     }
     if (empty($byMinute)) {
         $byMinute = array($dt->format('i'));
     }
     if (empty($bySecond)) {
         $bySecond = array($dt->format('s'));
     }
     foreach ($byHour as $hour) {
         foreach ($byMinute as $minute) {
             foreach ($bySecond as $second) {
                 $set[] = new Time($hour, $minute, $second);
             }
         }
     }
     return $set;
 }
Пример #5
0
 /**
  * Transform a Rule in to an array of \DateTimes
  *
  * @param Rule $rule the Rule
  * @param int|null $virtualLimit imposed upon infinitely recurring events.
  * @param ConstraintInterface|null $constraint Potential recurrences must pass the constraint, else
  *                                             they will not be included in the returned collection.
  *
  * @return RecurrenceCollection
  * @throws MissingData
  */
 public function transform($rule, $virtualLimit = null, ConstraintInterface $constraint = null)
 {
     if (null === $rule) {
         throw new MissingData('Rule has not been set');
     }
     $start = $rule->getStartDate();
     $end = $rule->getEndDate();
     $until = $rule->getUntil();
     if (null === $start) {
         $start = new \DateTime('now', $until instanceof \DateTime ? $until->getTimezone() : null);
     }
     if (null === $end) {
         $end = $start;
     }
     $durationInterval = $start->diff($end);
     $startDay = $start->format('j');
     $startMonthLength = $start->format('t');
     $fixLastDayOfMonth = false;
     $dt = clone $start;
     $maxCount = $rule->getCount();
     $vLimit = !empty($virtualLimit) && is_int($virtualLimit) ? $virtualLimit : $this->getVirtualLimit();
     $freq = $rule->getFreq();
     $weekStart = $rule->getWeekStartAsNum();
     $bySecond = $rule->getBySecond();
     $byMinute = $rule->getByMinute();
     $byHour = $rule->getByHour();
     $byMonth = $rule->getByMonth();
     $byWeekNum = $rule->getByWeekNumber();
     $byYearDay = $rule->getByYearDay();
     $byMonthDay = $rule->getByMonthDay();
     $byMonthDayNeg = array();
     $byWeekDay = $rule->getByDayTransformedToWeekdays();
     $byWeekDayRel = array();
     $bySetPos = $rule->getBySetPosition();
     $implicitByMonthDay = false;
     if (!(!empty($byWeekNum) || !empty($byYearDay) || !empty($byMonthDay) || !empty($byWeekDay))) {
         switch ($freq) {
             case Frequency::YEARLY:
                 if (empty($byMonth)) {
                     $byMonth = array($start->format('n'));
                 }
                 if ($startDay > 28) {
                     $fixLastDayOfMonth = true;
                 }
                 $implicitByMonthDay = true;
                 $byMonthDay = array($startDay);
                 break;
             case Frequency::MONTHLY:
                 if ($startDay > 28) {
                     $fixLastDayOfMonth = true;
                 }
                 $implicitByMonthDay = true;
                 $byMonthDay = array($startDay);
                 break;
             case Frequency::WEEKLY:
                 $byWeekDay = array(new Weekday(DateUtil::getDayOfWeek($start), null));
                 break;
         }
     }
     if (!$this->config->isLastDayOfMonthFixEnabled()) {
         $fixLastDayOfMonth = false;
     }
     if (is_array($byMonthDay) && count($byMonthDay)) {
         foreach ($byMonthDay as $idx => $day) {
             if ($day < 0) {
                 unset($byMonthDay[$idx]);
                 $byMonthDayNeg[] = $day;
             }
         }
     }
     if (!empty($byWeekDay)) {
         foreach ($byWeekDay as $idx => $day) {
             /** @var $day Weekday */
             if (!empty($day->num)) {
                 $byWeekDayRel[] = $day;
                 unset($byWeekDay[$idx]);
             } else {
                 $byWeekDay[$idx] = $day->weekday;
             }
         }
     }
     if (empty($byYearDay)) {
         $byYearDay = null;
     }
     if (empty($byMonthDay)) {
         $byMonthDay = null;
     }
     if (empty($byMonthDayNeg)) {
         $byMonthDayNeg = null;
     }
     if (empty($byWeekDay)) {
         $byWeekDay = null;
     }
     if (!count($byWeekDayRel)) {
         $byWeekDayRel = null;
     }
     $year = $dt->format('Y');
     $month = $dt->format('n');
     $day = $dt->format('j');
     $hour = $dt->format('G');
     $minute = $dt->format('i');
     $second = $dt->format('s');
     $dates = array();
     $total = 1;
     $count = $maxCount;
     $continue = true;
     while ($continue) {
         $dtInfo = DateUtil::getDateInfo($dt);
         $tmp = DateUtil::getDaySet($rule, $dt, $dtInfo, $start);
         $daySet = $tmp->set;
         $daySetStart = $tmp->start;
         $daySetEnd = $tmp->end;
         $wNoMask = array();
         $wDayMaskRel = array();
         $timeSet = DateUtil::getTimeSet($rule, $dt);
         if ($freq >= Frequency::HOURLY) {
             if ($freq >= Frequency::HOURLY && !empty($byHour) && !in_array($hour, $byHour) || $freq >= Frequency::MINUTELY && !empty($byMinute) && !in_array($minute, $byMinute) || $freq >= Frequency::SECONDLY && !empty($bySecond) && !in_array($second, $bySecond)) {
                 $timeSet = array();
             } else {
                 switch ($freq) {
                     case Frequency::HOURLY:
                         $timeSet = DateUtil::getTimeSetOfHour($rule, $dt);
                         break;
                     case Frequency::MINUTELY:
                         $timeSet = DateUtil::getTimeSetOfMinute($rule, $dt);
                         break;
                     case Frequency::SECONDLY:
                         $timeSet = DateUtil::getTimeSetOfSecond($dt);
                         break;
                 }
             }
         }
         // Handle byWeekNum
         if (!empty($byWeekNum)) {
             $no1WeekStart = $firstWeekStart = DateUtil::pymod(7 - $dtInfo->dayOfWeekYearDay1 + $weekStart, 7);
             if ($no1WeekStart >= 4) {
                 $no1WeekStart = 0;
                 $wYearLength = $dtInfo->yearLength + DateUtil::pymod($dtInfo->dayOfWeekYearDay1 - $weekStart, 7);
             } else {
                 $wYearLength = $dtInfo->yearLength - $no1WeekStart;
             }
             $div = floor($wYearLength / 7);
             $mod = DateUtil::pymod($wYearLength, 7);
             $numWeeks = floor($div + $mod / 4);
             foreach ($byWeekNum as $weekNum) {
                 if ($weekNum < 0) {
                     $weekNum += $numWeeks + 1;
                 }
                 if (!(0 < $weekNum && $weekNum <= $numWeeks)) {
                     continue;
                 }
                 if ($weekNum > 1) {
                     $offset = $no1WeekStart + ($weekNum - 1) * 7;
                     if ($no1WeekStart != $firstWeekStart) {
                         $offset -= 7 - $firstWeekStart;
                     }
                 } else {
                     $offset = $no1WeekStart;
                 }
                 for ($i = 0; $i < 7; $i++) {
                     $wNoMask[] = $offset;
                     $offset++;
                     if ($dtInfo->wDayMask[$offset] == $weekStart) {
                         break;
                     }
                 }
             }
             // Check week number 1 of next year as well
             if (in_array(1, $byWeekNum)) {
                 $offset = $no1WeekStart + $numWeeks * 7;
                 if ($no1WeekStart != $firstWeekStart) {
                     $offset -= 7 - $firstWeekStart;
                 }
                 // If week starts in next year, we don't care about it.
                 if ($offset < $dtInfo->yearLength) {
                     for ($k = 0; $k < 7; $k++) {
                         $wNoMask[] = $offset;
                         $offset += 1;
                         if ($dtInfo->wDayMask[$offset] == $weekStart) {
                             break;
                         }
                     }
                 }
             }
             if ($no1WeekStart) {
                 // Check last week number of last year as well.
                 // If $no1WeekStart is 0, either the year started on week start,
                 // or week number 1 got days from last year, so there are no
                 // days from last year's last week number in this year.
                 if (!in_array(-1, $byWeekNum)) {
                     $dtTmp = new \DateTime();
                     $dtTmp->setDate($year - 1, 1, 1);
                     $lastYearWeekDay = DateUtil::getDayOfWeek($dtTmp);
                     $lastYearNo1WeekStart = DateUtil::pymod(7 - $lastYearWeekDay + $weekStart, 7);
                     $lastYearLength = DateUtil::getYearLength($dtTmp);
                     if ($lastYearNo1WeekStart >= 4) {
                         $lastYearNo1WeekStart = 0;
                         $lastYearNumWeeks = floor(52 + DateUtil::pymod($lastYearLength + DateUtil::pymod($lastYearWeekDay - $weekStart, 7), 7) / 4);
                     } else {
                         $lastYearNumWeeks = floor(52 + DateUtil::pymod($dtInfo->yearLength - $no1WeekStart, 7) / 4);
                     }
                 } else {
                     $lastYearNumWeeks = -1;
                 }
                 if (in_array($lastYearNumWeeks, $byWeekNum)) {
                     for ($i = 0; $i < $no1WeekStart; $i++) {
                         $wNoMask[] = $i;
                     }
                 }
             }
         }
         // Handle relative weekdays (e.g. 3rd Friday of month)
         if (!empty($byWeekDayRel)) {
             $ranges = array();
             if (Frequency::YEARLY == $freq) {
                 if (!empty($byMonth)) {
                     foreach ($byMonth as $mo) {
                         $ranges[] = array_slice($dtInfo->mRanges, $mo - 1, 2);
                     }
                 } else {
                     $ranges[] = array(0, $dtInfo->yearLength);
                 }
             } elseif (Frequency::MONTHLY == $freq) {
                 $ranges[] = array_slice($dtInfo->mRanges, $month - 1, 2);
             }
             if (!empty($ranges)) {
                 foreach ($ranges as $range) {
                     $rangeStart = $range[0];
                     $rangeEnd = $range[1];
                     --$rangeEnd;
                     reset($byWeekDayRel);
                     foreach ($byWeekDayRel as $weekday) {
                         /** @var Weekday $weekday */
                         if ($weekday->num < 0) {
                             $i = $rangeEnd + ($weekday->num + 1) * 7;
                             $i -= DateUtil::pymod($dtInfo->wDayMask[$i] - $weekday->weekday, 7);
                         } else {
                             $i = $rangeStart + ($weekday->num - 1) * 7;
                             $i += DateUtil::pymod(7 - $dtInfo->wDayMask[$i] + $weekday->weekday, 7);
                         }
                         if ($rangeStart <= $i && $i <= $rangeEnd) {
                             $wDayMaskRel[] = $i;
                         }
                     }
                 }
             }
         }
         $numMatched = 0;
         foreach ($daySet as $i => $dayOfYear) {
             $dayOfMonth = $dtInfo->mDayMask[$dayOfYear];
             $ifByMonth = $byMonth !== null && !in_array($dtInfo->mMask[$dayOfYear], $byMonth);
             $ifByWeekNum = $byWeekNum !== null && !in_array($i, $wNoMask);
             $ifByYearDay = $byYearDay !== null && ($i < $dtInfo->yearLength && !in_array($i + 1, $byYearDay) && !in_array(-$dtInfo->yearLength + $i, $byYearDay) || $i >= $dtInfo->yearLength && !in_array($i + 1 - $dtInfo->yearLength, $byYearDay) && !in_array(-$dtInfo->nextYearLength + $i - $dtInfo->yearLength, $byYearDay));
             $ifByMonthDay = $byMonthDay !== null && !in_array($dtInfo->mDayMask[$dayOfYear], $byMonthDay);
             // Handle "last day of next month" problem.
             if ($fixLastDayOfMonth && $ifByMonthDay && $implicitByMonthDay && $startMonthLength > $dtInfo->monthLength && $dayOfMonth == $dtInfo->monthLength && $dayOfMonth < $startMonthLength && !$numMatched) {
                 $ifByMonthDay = false;
             }
             $ifByMonthDayNeg = $byMonthDayNeg !== null && !in_array($dtInfo->mDayMaskNeg[$dayOfYear], $byMonthDayNeg);
             $ifByDay = $byWeekDay !== null && count($byWeekDay) && !in_array($dtInfo->wDayMask[$dayOfYear], $byWeekDay);
             $ifWDayMaskRel = $byWeekDayRel !== null && !in_array($dayOfYear, $wDayMaskRel);
             if ($byMonthDay !== null && $byMonthDayNeg !== null) {
                 if ($ifByMonthDay && $ifByMonthDayNeg) {
                     unset($daySet[$i]);
                 }
             } elseif ($ifByMonth || $ifByWeekNum || $ifByYearDay || $ifByMonthDay || $ifByMonthDayNeg || $ifByDay || $ifWDayMaskRel) {
                 unset($daySet[$i]);
             } else {
                 ++$numMatched;
             }
         }
         if (!empty($bySetPos)) {
             $datesAdj = array();
             $tmpDaySet = array_combine($daySet, $daySet);
             foreach ($bySetPos as $setPos) {
                 if ($setPos < 0) {
                     $dayPos = floor($setPos / count($timeSet));
                     $timePos = DateUtil::pymod($setPos, count($timeSet));
                 } else {
                     $dayPos = floor(($setPos - 1) / count($timeSet));
                     $timePos = DateUtil::pymod($setPos - 1, count($timeSet));
                 }
                 $tmp = array();
                 for ($k = $daySetStart; $k <= $daySetEnd; $k++) {
                     if (!array_key_exists($k, $tmpDaySet)) {
                         continue;
                     }
                     $tmp[] = $tmpDaySet[$k];
                 }
                 if ($dayPos < 0) {
                     $nextInSet = array_slice($tmp, $dayPos, 1);
                     $nextInSet = $nextInSet[0];
                 } else {
                     $nextInSet = $tmp[$dayPos];
                 }
                 /** @var Time $time */
                 $time = $timeSet[$timePos];
                 $dtTmp = DateUtil::getDateTimeByDayOfYear($nextInSet, $dt->format('Y'), $start->getTimezone());
                 $dtTmp->setTime($time->hour, $time->minute, $time->second);
                 $datesAdj[] = $dtTmp;
             }
             foreach ($datesAdj as $dtTmp) {
                 if (null !== $until && $dtTmp > $until) {
                     $continue = false;
                     break;
                 }
                 if ($dtTmp < $start) {
                     continue;
                 }
                 if ($constraint instanceof ConstraintInterface && !$constraint->test($dtTmp)) {
                     if ($constraint->stopsTransformer()) {
                         $continue = false;
                         break;
                     } else {
                         continue;
                     }
                 }
                 $dates[] = $dtTmp;
                 if (null !== $count) {
                     --$count;
                     if ($count <= 0) {
                         $continue = false;
                         break;
                     }
                 }
                 ++$total;
                 if ($total > $vLimit) {
                     $continue = false;
                     break;
                 }
             }
         } else {
             foreach ($daySet as $dayOfYear) {
                 $dtTmp = DateUtil::getDateTimeByDayOfYear($dayOfYear, $dt->format('Y'), $start->getTimezone());
                 foreach ($timeSet as $time) {
                     /** @var Time $time */
                     $dtTmp->setTime($time->hour, $time->minute, $time->second);
                     if (null !== $until && $dtTmp > $until) {
                         $continue = false;
                         break;
                     }
                     if ($dtTmp < $start) {
                         continue;
                     }
                     if ($constraint instanceof ConstraintInterface && !$constraint->test($dtTmp)) {
                         if ($constraint->stopsTransformer()) {
                             $continue = false;
                             break;
                         } else {
                             continue;
                         }
                     }
                     $dates[] = clone $dtTmp;
                     if (null !== $count) {
                         --$count;
                         if ($count <= 0) {
                             $continue = false;
                             break;
                         }
                     }
                     ++$total;
                     if ($total > $vLimit) {
                         $continue = false;
                         break;
                     }
                 }
                 if (!$continue) {
                     break;
                 }
             }
             if ($total > $vLimit) {
                 $continue = false;
                 break;
             }
         }
         switch ($freq) {
             case Frequency::YEARLY:
                 $year += $rule->getInterval();
                 $month = $dt->format('n');
                 $day = $dt->format('j');
                 $dt->setDate($year, $month, 1);
                 break;
             case Frequency::MONTHLY:
                 $month += $rule->getInterval();
                 if ($month > 12) {
                     $delta = floor($month / 12);
                     $mod = DateUtil::pymod($month, 12);
                     $month = $mod;
                     $year += $delta;
                     if ($month == 0) {
                         $month = 12;
                         --$year;
                     }
                 }
                 $dt->setDate($year, $month, 1);
                 break;
             case Frequency::WEEKLY:
                 if ($weekStart > $dtInfo->dayOfWeek) {
                     $delta = ($dtInfo->dayOfWeek + 1 + (6 - $weekStart)) * -1 + $rule->getInterval() * 7;
                 } else {
                     $delta = ($dtInfo->dayOfWeek - $weekStart) * -1 + $rule->getInterval() * 7;
                 }
                 $dt->modify("+{$delta} day");
                 $year = $dt->format('Y');
                 $month = $dt->format('n');
                 $day = $dt->format('j');
                 break;
             case Frequency::DAILY:
                 $dt->modify('+' . $rule->getInterval() . ' day');
                 $year = $dt->format('Y');
                 $month = $dt->format('n');
                 $day = $dt->format('j');
                 break;
             case Frequency::HOURLY:
                 $dt->modify('+' . $rule->getInterval() . ' hours');
                 $year = $dt->format('Y');
                 $month = $dt->format('n');
                 $day = $dt->format('j');
                 $hour = $dt->format('G');
                 break;
             case Frequency::MINUTELY:
                 $dt->modify('+' . $rule->getInterval() . ' minutes');
                 $year = $dt->format('Y');
                 $month = $dt->format('n');
                 $day = $dt->format('j');
                 $hour = $dt->format('G');
                 $minute = $dt->format('i');
                 break;
             case Frequency::SECONDLY:
                 $dt->modify('+' . $rule->getInterval() . ' seconds');
                 $year = $dt->format('Y');
                 $month = $dt->format('n');
                 $day = $dt->format('j');
                 $hour = $dt->format('G');
                 $minute = $dt->format('i');
                 $second = $dt->format('s');
                 break;
         }
     }
     /** @var Recurrence[] $recurrences */
     $recurrences = array();
     foreach ($dates as $start) {
         /** @var \DateTime $end */
         $end = clone $start;
         $recurrences[] = new Recurrence($start, $end->add($durationInterval));
     }
     $recurrences = $this->handleExclusions($rule->getExDates(), $recurrences);
     return new RecurrenceCollection($recurrences);
 }
Пример #6
0
 /**
  * @expectedException \Recurr\Exception\InvalidArgument
  */
 public function testBadWeekStart()
 {
     $this->rule->setWeekStart('monday');
 }
Пример #7
0
 public function fromParams($params, $entity_manager)
 {
     $rrule = new RRule();
     $event_data = $params['event'];
     $event_data['is_visible'] = isset($event_data['is_visible']) && $event_data['is_visible'];
     $event_data['is_all_day'] = isset($event_data['is_all_day']) && $event_data['is_all_day'];
     $event_data['is_closed'] = isset($event_data['is_closed']) && $event_data['is_closed'];
     if ($event_data['is_all_day'] || $event_data['is_closed']) {
         $start = new \Datetime($params['event_start_date']);
         $end = new \Datetime($params['event_start_date']);
     } else {
         $start = new \Datetime($event_data['start']);
         $end = new \Datetime($event_data['end']);
     }
     $rrule->setStartDate($start);
     $rrule->setEndDate($end);
     if (isset($params['event_recurrence_rule_custom'])) {
         if (isset($params['event_recurrence_rule_custom']['BYDAY'])) {
             $rrule->setByDay($params['event_recurrence_rule_custom']['BYDAY']);
         }
         if (!empty($params['event_recurrence_rule_custom']['UNTIL'])) {
             $until = clone $start;
             $date = explode('-', $params['event_recurrence_rule_custom']['UNTIL']);
             $until->setDate(intval($date[0]), intval($date[1]), intval($date[2]));
             $rrule->setUntil($until);
         }
         if (isset($params['event_recurrence_rule_custom']['INTERVAL'])) {
             $rrule->setInterval($params['event_recurrence_rule_custom']['INTERVAL']);
         }
     }
     switch ($event_data['recurrence_rule']) {
         case 'CUSTOM':
             // freq rules are in custom fields
             $event_data['is_recurring'] = true;
             $event_data['is_custom_rrule'] = true;
             $rrule->setFreq($params['event_recurrence_rule_custom']['FREQ']);
             break;
         case 'NONE':
             $event_data['is_recurring'] = false;
             $event_data['is_custom_rrule'] = false;
             $rrule->setCount(1);
             break;
         default:
             // freq value is sitting in the recurrence_rule field
             $event_data['is_recurring'] = true;
             $event_data['is_custom_rrule'] = false;
             $rrule->setFreq($event_data['recurrence_rule']);
     }
     if (empty($event_data['title'])) {
         $event_data['title'] = 'New Event';
     }
     if (empty($event_data['category'])) {
         $event_data['category'] = new Category(array('name' => 'None', 'color' => '#ddd000', 'priority' => 9999999999999.0));
     } else {
         $event_data['category'] = $entity_manager->find('\\Hoo\\Model\\Category', intval($event_data['category']));
     }
     $event_data['location'] = $entity_manager->find('\\Hoo\\Model\\Location', intval($event_data['location']));
     $event_data['start'] = $start;
     $event_data['end'] = $end;
     $event_data['recurrence_rule'] = $rrule;
     return $this->fromArray($event_data);
 }
Пример #8
0
 protected function addDayOfWeek(Rule $rule)
 {
     $this->addFragment($this->translator->trans('on'));
     $dayNames = $this->translator->trans('day_names');
     $this->addFragment($dayNames[$rule->getStartDate()->format('w')]);
 }