From e82f3bb887abbaa75782d912b933835218d0a99f Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Thu, 16 Aug 2018 17:46:47 +0100 Subject: [PATCH] Allow modifying parameters of new recurring entities and allow inclusion of date of parent entity --- CRM/Core/BAO/RecurringEntity.php | 19 ++++++++++++++----- CRM/Core/Form/RecurringEntity.php | 8 +++++++- templates/CRM/Core/Form/RecurringEntity.tpl | 3 +++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CRM/Core/BAO/RecurringEntity.php b/CRM/Core/BAO/RecurringEntity.php index a5ab757b7b8c..719d0406d0ff 100644 --- a/CRM/Core/BAO/RecurringEntity.php +++ b/CRM/Core/BAO/RecurringEntity.php @@ -226,10 +226,10 @@ public function mode($mode) { * * @return array */ - public function generate() { + public function generate($newParams = []) { $this->generateRecursiveDates(); - return $this->generateEntities(); + return $this->generateEntities($newParams); } /** @@ -263,7 +263,7 @@ public function generateRecursion() { * * @return array */ - public function generateEntities() { + public function generateEntities($newParams = []) { self::setStatus(self::RUNNING); $newEntities = array(); @@ -285,6 +285,9 @@ public function generateEntities() { $count = 0; foreach ($this->recursionDates as $key => $dateCols) { $newCriteria = $dateCols; + if (isset($newParams[$this->entity_table])) { + $newCriteria = array_merge($dateCols, $newParams[$this->entity_table]); + } foreach ($this->overwriteColumns as $col => $val) { $newCriteria[$col] = $val; } @@ -343,10 +346,16 @@ public function generateRecursiveDates() { $exRangeEnd = $this->excludeDateRangeColumns[1]; } - $count = 1; + if ($this->dontSkipStartDate) { + $count = 0; + $this->recursion->count($initialCount+1); + } + else { + $count = 1; + } while ($result = $this->recursion->next()) { $skip = FALSE; - if ($result == $this->recursion_start_date) { + if ((!$this->dontSkipStartDate) && $result == $this->recursion_start_date) { // skip the recursion-start-date from the list we going to generate $skip = TRUE; } diff --git a/CRM/Core/Form/RecurringEntity.php b/CRM/Core/Form/RecurringEntity.php index d5367e1e9fe6..de834d4dcbc5 100644 --- a/CRM/Core/Form/RecurringEntity.php +++ b/CRM/Core/Form/RecurringEntity.php @@ -481,7 +481,13 @@ public static function postProcess($params = array(), $type, $linkedEntities = a $recursion->linkedEntities = $linkedEntities; } - $recursion->generate(); + if (!empty($params['dont_skip_start_date'])) { + $recursion->dontSkipStartDate = TRUE; + } + if (empty($params['new_params'])) { + $params['new_params'] = []; + } + $recursion->generate($params['new_params']); $status = ts('Repeat Configuration has been saved'); CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); diff --git a/templates/CRM/Core/Form/RecurringEntity.tpl b/templates/CRM/Core/Form/RecurringEntity.tpl index 7097b43d9a54..f9de8d064ed0 100644 --- a/templates/CRM/Core/Form/RecurringEntity.tpl +++ b/templates/CRM/Core/Form/RecurringEntity.tpl @@ -74,6 +74,9 @@ {$form.exclude_date_list.label} {help id="id-exclude-date" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"} {$form.exclude_date_list.html} + {if $dontSkipStartDate} + {$form.dont_skip_start_date.html} + {/if} {if !$recurringFormIsEmbedded}