*/
public function generateRecursion() {
// return if already generated
- if (is_a($this->recursion, 'When')) {
+ if (is_a($this->recursion, 'When\When')) {
return $this->recursion;
}
$exRangeEnd = $this->excludeDateRangeColumns[1];
}
+ if (CRM_Core_Config::singleton()->userFramework == 'UnitTests') {
+ $this->recursion->RFC5545_COMPLIANT = When::IGNORE;
+ }
$count = 1;
- try {
- if (CRM_Core_Config::singleton()->userFramework == 'UnitTests') {
- $this->recursion->RFC5545_COMPLIANT = When::IGNORE;
+ $result = $this->recursion_start_date;
+ while ($result = $this->getNextOccurrence($result)) {
+ $skip = FALSE;
+ if ($result == $this->recursion_start_date) {
+ // skip the recursion-start-date from the list we going to generate
+ $skip = TRUE;
}
- $this->recursion->generateOccurrences();
- }
- catch (Exception $e) {
- CRM_Core_Session::setStatus(ts($e->getMessage()));
- return $recursionDates;
- }
- foreach ($this->recursion->occurrences as $result) {
$baseDate = $result->format('YmdHis');
foreach ($this->dateColumns as $col) {
}
}
+ if ($skip) {
+ unset($recursionDates[$count]);
+ if ($initialCount && ($initialCount > 0)) {
+ // lets increase the counter, so we get correct number of occurrences
+ $initialCount++;
+ $this->recursion->count($initialCount);
+ }
+ continue;
+ }
$count++;
}
}
}
$start = new DateTime($currDate);
$this->recursion_start_date = $start;
- if ($scheduleReminderDetails['repetition_frequency_unit']) {
- $repetition_frequency_unit = $scheduleReminderDetails['repetition_frequency_unit'];
- if ($repetition_frequency_unit == "day") {
- $repetition_frequency_unit = "dai";
- }
- $repetition_frequency_unit = $repetition_frequency_unit . 'ly';
- $r->startDate($start)
- ->exclusions([$start])
- ->freq($repetition_frequency_unit);
+ $repetition_frequency_unit = $scheduleReminderDetails['repetition_frequency_unit'];
+ if ($repetition_frequency_unit == "day") {
+ $repetition_frequency_unit = "dai";
}
+ $repetition_frequency_unit = $repetition_frequency_unit . 'ly';
+ $r->startDate($start)
+ ->exclusions([$start])
+ ->freq($repetition_frequency_unit);
if ($scheduleReminderDetails['repetition_frequency_interval']) {
$r->interval($scheduleReminderDetails['repetition_frequency_interval']);
return $finalResult;
}
+ /**
+ * Get next occurrence for the given date
+ *
+ * @param \DateTime $occurDate
+ * @param bool $strictly_after
+ *
+ * @return bool
+ */
+ private function getNextOccurrence($occurDate, $strictly_after = TRUE) {
+ try {
+ return $this->recursion->getNextOccurrence($occurDate, $strictly_after);
+ }
+ catch (Exception $exception) {
+ CRM_Core_Session::setStatus(ts($exception->getMessage()));
+ }
+ return FALSE;
+ }
+
}