Commit | Line | Data |
---|---|---|
2aa397bc TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
2aa397bc | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
2aa397bc TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
2aa397bc TO |
27 | |
28 | /** | |
29 | * | |
30 | * | |
31 | * @package CRM | |
8c9251b3 | 32 | * @copyright CiviCRM LLC (c) 2004-2018 |
2aa397bc | 33 | */ |
353ffa53 | 34 | |
2aa397bc | 35 | /** |
8eedd10a | 36 | * This class generates form components for processing Entity. |
2aa397bc TO |
37 | */ |
38 | class CRM_Core_Form_RecurringEntity { | |
39 | /** | |
40 | * Current entity id | |
41 | */ | |
42 | protected static $_entityId = NULL; | |
43 | ||
44 | /** | |
45 | * Schedule Reminder ID | |
46 | */ | |
47 | protected static $_scheduleReminderID = NULL; | |
48 | ||
49 | /** | |
50 | * Schedule Reminder data | |
51 | */ | |
52 | protected static $_scheduleReminderDetails = array(); | |
53 | ||
54 | /** | |
55 | * Parent Entity ID | |
56 | */ | |
57 | protected static $_parentEntityId = NULL; | |
58 | ||
59 | /** | |
60 | * Exclude date information | |
61 | */ | |
62 | public static $_excludeDateInfo = array(); | |
63 | ||
64 | /** | |
65 | * Entity Table | |
66 | */ | |
67 | public static $_entityTable; | |
68 | ||
69 | /** | |
70 | * Checks current entityID has parent | |
71 | */ | |
72 | public static $_hasParent = FALSE; | |
73 | ||
7a9ab499 EM |
74 | /** |
75 | * @param $entityTable | |
76 | */ | |
2aa397bc TO |
77 | public static function preProcess($entityTable) { |
78 | self::$_entityId = (int) CRM_Utils_Request::retrieve('id', 'Positive'); | |
79 | self::$_entityTable = $entityTable; | |
80 | ||
81 | if (self::$_entityId && $entityTable) { | |
82 | $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor(self::$_entityId, $entityTable); | |
83 | if ($checkParentExistsForThisId) { | |
84 | self::$_hasParent = TRUE; | |
85 | self::$_parentEntityId = $checkParentExistsForThisId; | |
86 | self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, $entityTable); | |
87 | } | |
88 | else { | |
89 | self::$_parentEntityId = self::$_entityId; | |
90 | self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId(self::$_entityId, $entityTable); | |
91 | } | |
92 | if (property_exists(self::$_scheduleReminderDetails, 'id')) { | |
93 | self::$_scheduleReminderID = self::$_scheduleReminderDetails->id; | |
94 | } | |
95 | } | |
b1e18356 CW |
96 | CRM_Core_OptionValue::getValues(array('name' => $entityTable . '_repeat_exclude_dates_' . self::$_parentEntityId), $optionValue); |
97 | $excludeOptionValues = array(); | |
98 | if (!empty($optionValue)) { | |
99 | foreach ($optionValue as $key => $val) { | |
9cc21021 | 100 | $excludeOptionValues[$val['value']] = substr(CRM_Utils_Date::mysqlToIso($val['value']), 0, 10); |
2aa397bc | 101 | } |
b1e18356 | 102 | self::$_excludeDateInfo = $excludeOptionValues; |
2aa397bc | 103 | } |
b1e18356 CW |
104 | |
105 | // Assign variables | |
106 | $entityType = CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getClassForTable($entityTable)); | |
107 | $tpl = CRM_Core_Smarty::singleton(); | |
108 | $tpl->assign('recurringEntityType', ts($entityType)); | |
109 | $tpl->assign('currentEntityId', self::$_entityId); | |
110 | $tpl->assign('entityTable', self::$_entityTable); | |
111 | $tpl->assign('scheduleReminderId', self::$_scheduleReminderID); | |
112 | $tpl->assign('hasParent', self::$_hasParent); | |
2aa397bc TO |
113 | } |
114 | ||
115 | /** | |
116 | * Set default values for the form. For edit/view mode | |
117 | * the default values are retrieved from the database | |
118 | * | |
119 | * | |
16b10e64 | 120 | * @return array |
2aa397bc TO |
121 | */ |
122 | public static function setDefaultValues() { | |
d2a4c29b CW |
123 | // Defaults for new entity |
124 | $defaults = array( | |
125 | 'repetition_frequency_unit' => 'week', | |
126 | ); | |
127 | ||
128 | // Default for existing entity | |
2aa397bc TO |
129 | if (self::$_scheduleReminderID) { |
130 | $defaults['repetition_frequency_unit'] = self::$_scheduleReminderDetails->repetition_frequency_unit; | |
131 | $defaults['repetition_frequency_interval'] = self::$_scheduleReminderDetails->repetition_frequency_interval; | |
132 | $defaults['start_action_condition'] = array_flip(explode(",", self::$_scheduleReminderDetails->start_action_condition)); | |
22e263ad | 133 | foreach ($defaults['start_action_condition'] as $key => $val) { |
2aa397bc TO |
134 | $val = 1; |
135 | $defaults['start_action_condition'][$key] = $val; | |
136 | } | |
137 | $defaults['start_action_offset'] = self::$_scheduleReminderDetails->start_action_offset; | |
138 | if (self::$_scheduleReminderDetails->start_action_offset) { | |
139 | $defaults['ends'] = 1; | |
140 | } | |
141 | list($defaults['repeat_absolute_date']) = CRM_Utils_Date::setDateDefaults(self::$_scheduleReminderDetails->absolute_date); | |
142 | if (self::$_scheduleReminderDetails->absolute_date) { | |
143 | $defaults['ends'] = 2; | |
144 | } | |
145 | $defaults['limit_to'] = self::$_scheduleReminderDetails->limit_to; | |
146 | if (self::$_scheduleReminderDetails->limit_to) { | |
147 | $defaults['repeats_by'] = 1; | |
148 | } | |
2aa397bc TO |
149 | if (self::$_scheduleReminderDetails->entity_status) { |
150 | $explodeStartActionCondition = explode(" ", self::$_scheduleReminderDetails->entity_status); | |
151 | $defaults['entity_status_1'] = $explodeStartActionCondition[0]; | |
152 | $defaults['entity_status_2'] = $explodeStartActionCondition[1]; | |
153 | } | |
154 | if (self::$_scheduleReminderDetails->entity_status) { | |
155 | $defaults['repeats_by'] = 2; | |
156 | } | |
530dd28b CW |
157 | if (self::$_excludeDateInfo) { |
158 | $defaults['exclude_date_list'] = implode(',', self::$_excludeDateInfo); | |
159 | } | |
2aa397bc TO |
160 | } |
161 | return $defaults; | |
162 | } | |
163 | ||
2e2605fe EM |
164 | /** |
165 | * Build form. | |
166 | * | |
530dd28b | 167 | * @param CRM_Core_Form $form |
2e2605fe | 168 | */ |
2aa397bc | 169 | public static function buildQuickForm(&$form) { |
1ef73b88 CW |
170 | // FIXME: this is using the following as keys rather than the standard numeric keys returned by CRM_Utils_Date |
171 | $dayOfTheWeek = array(); | |
172 | $dayKeys = array( | |
b1e18356 CW |
173 | 'sunday', |
174 | 'monday', | |
175 | 'tuesday', | |
176 | 'wednesday', | |
177 | 'thursday', | |
178 | 'friday', | |
179 | 'saturday', | |
353ffa53 | 180 | ); |
1ef73b88 CW |
181 | foreach (CRM_Utils_Date::getAbbrWeekdayNames() as $k => $label) { |
182 | $dayOfTheWeek[$dayKeys[$k]] = $label; | |
183 | } | |
8fe4b69f | 184 | $form->add('select', 'repetition_frequency_unit', ts('Repeats every'), CRM_Core_SelectValues::getRecurringFrequencyUnits(), FALSE, array('class' => 'required')); |
2aa397bc | 185 | $numericOptions = CRM_Core_SelectValues::getNumericOptions(1, 30); |
d2a4c29b | 186 | $form->add('select', 'repetition_frequency_interval', NULL, $numericOptions, FALSE, array('class' => 'required')); |
2aa397bc | 187 | $form->addDateTime('repetition_start_date', ts('Repetition Start Date'), FALSE, array('formatType' => 'activityDateTime')); |
22e263ad | 188 | foreach ($dayOfTheWeek as $key => $val) { |
b1e18356 | 189 | $startActionCondition[] = $form->createElement('checkbox', $key, NULL, $val); |
2aa397bc TO |
190 | } |
191 | $form->addGroup($startActionCondition, 'start_action_condition', ts('Repeats on')); | |
192 | $roptionTypes = array( | |
353ffa53 TO |
193 | '1' => ts('day of the month'), |
194 | '2' => ts('day of the week'), | |
195 | ); | |
d2a4c29b CW |
196 | $form->addRadio('repeats_by', ts("Repeats by"), $roptionTypes, array('required' => TRUE), NULL); |
197 | $form->add('select', 'limit_to', '', CRM_Core_SelectValues::getNumericOptions(1, 31)); | |
2aa397bc | 198 | $dayOfTheWeekNo = array( |
b1e18356 CW |
199 | 'first' => ts('First'), |
200 | 'second' => ts('Second'), | |
201 | 'third' => ts('Third'), | |
202 | 'fourth' => ts('Fourth'), | |
203 | 'last' => ts('Last'), | |
353ffa53 | 204 | ); |
b1e18356 CW |
205 | $form->add('select', 'entity_status_1', '', $dayOfTheWeekNo); |
206 | $form->add('select', 'entity_status_2', '', $dayOfTheWeek); | |
2aa397bc | 207 | $eoptionTypes = array( |
353ffa53 TO |
208 | '1' => ts('After'), |
209 | '2' => ts('On'), | |
210 | ); | |
d2a4c29b | 211 | $form->addRadio('ends', ts("Ends"), $eoptionTypes, array('class' => 'required'), NULL); |
575a65d9 CW |
212 | // Offset options gets key=>val pairs like 1=>2 because the BAO wants to know the number of |
213 | // children while it makes more sense to the user to see the total number including the parent. | |
214 | $offsetOptions = range(1, 30); | |
215 | unset($offsetOptions[0]); | |
216 | $form->add('select', 'start_action_offset', NULL, $offsetOptions, FALSE); | |
2aa397bc TO |
217 | $form->addFormRule(array('CRM_Core_Form_RecurringEntity', 'formRule')); |
218 | $form->addDate('repeat_absolute_date', ts('On'), FALSE, array('formatType' => 'mailing')); | |
530dd28b CW |
219 | $form->add('text', 'exclude_date_list', ts('Exclude Dates'), array( |
220 | 'class' => 'twenty', | |
353ffa53 | 221 | )); |
2aa397bc TO |
222 | $form->addElement('hidden', 'allowRepeatConfigToSubmit', '', array('id' => 'allowRepeatConfigToSubmit')); |
223 | $form->addButtons(array( | |
224 | array( | |
225 | 'type' => 'submit', | |
226 | 'name' => ts('Save'), | |
227 | 'isDefault' => TRUE, | |
228 | ), | |
229 | array( | |
230 | 'type' => 'cancel', | |
21dfd5f5 | 231 | 'name' => ts('Cancel'), |
2aa397bc TO |
232 | ), |
233 | ) | |
234 | ); | |
8fe4b69f CW |
235 | // For client-side pluralization |
236 | $form->assign('recurringFrequencyOptions', array( | |
237 | 'single' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::getRecurringFrequencyUnits()), | |
238 | 'plural' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::getRecurringFrequencyUnits(2)), | |
239 | )); | |
2aa397bc TO |
240 | } |
241 | ||
242 | /** | |
fe482240 | 243 | * Global validation rules for the form. |
2aa397bc | 244 | * |
a1a2a83d TO |
245 | * @param array $values |
246 | * Posted values of the form. | |
2aa397bc | 247 | * |
a6c01b45 CW |
248 | * @return array |
249 | * list of errors to be posted back to the form | |
2aa397bc TO |
250 | */ |
251 | public static function formRule($values) { | |
252 | $errors = array(); | |
253 | //Process this function only when you get this variable | |
254 | if ($values['allowRepeatConfigToSubmit'] == 1) { | |
255 | $dayOfTheWeek = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'); | |
256 | //Repeats | |
b53cbfbc | 257 | if (empty($values['repetition_frequency_unit'])) { |
2aa397bc TO |
258 | $errors['repetition_frequency_unit'] = ts('This is a required field'); |
259 | } | |
260 | //Repeats every | |
b53cbfbc | 261 | if (empty($values['repetition_frequency_interval'])) { |
2aa397bc TO |
262 | $errors['repetition_frequency_interval'] = ts('This is a required field'); |
263 | } | |
264 | //Ends | |
b53cbfbc | 265 | if (!empty($values['ends'])) { |
2aa397bc TO |
266 | if ($values['ends'] == 1) { |
267 | if (empty($values['start_action_offset'])) { | |
268 | $errors['start_action_offset'] = ts('This is a required field'); | |
269 | } | |
4c9b6178 | 270 | elseif ($values['start_action_offset'] > 30) { |
2aa397bc TO |
271 | $errors['start_action_offset'] = ts('Occurrences should be less than or equal to 30'); |
272 | } | |
273 | } | |
274 | if ($values['ends'] == 2) { | |
b53cbfbc | 275 | if (!empty($values['repeat_absolute_date'])) { |
2aa397bc TO |
276 | $entityStartDate = CRM_Utils_Date::processDate($values['repetition_start_date']); |
277 | $end = CRM_Utils_Date::processDate($values['repeat_absolute_date']); | |
278 | if (($end < $entityStartDate) && ($end != 0)) { | |
279 | $errors['repeat_absolute_date'] = ts('End date should be after current entity\'s start date'); | |
280 | } | |
281 | } | |
282 | else { | |
283 | $errors['repeat_absolute_date'] = ts('This is a required field'); | |
284 | } | |
285 | } | |
286 | } | |
287 | else { | |
288 | $errors['ends'] = ts('This is a required field'); | |
289 | } | |
290 | ||
291 | //Repeats BY | |
b53cbfbc | 292 | if (!empty($values['repeats_by'])) { |
2aa397bc | 293 | if ($values['repeats_by'] == 1) { |
b53cbfbc | 294 | if (!empty($values['limit_to'])) { |
2aa397bc TO |
295 | if ($values['limit_to'] < 1 && $values['limit_to'] > 31) { |
296 | $errors['limit_to'] = ts('Invalid day of the month'); | |
297 | } | |
298 | } | |
299 | else { | |
300 | $errors['limit_to'] = ts('Invalid day of the month'); | |
301 | } | |
302 | } | |
303 | if ($values['repeats_by'] == 2) { | |
b53cbfbc | 304 | if (!empty($values['entity_status_1'])) { |
5c97b65f | 305 | $dayOfTheWeekNo = array('first', 'second', 'third', 'fourth', 'last'); |
2aa397bc TO |
306 | if (!in_array($values['entity_status_1'], $dayOfTheWeekNo)) { |
307 | $errors['entity_status_1'] = ts('Invalid option'); | |
308 | } | |
309 | } | |
310 | else { | |
311 | $errors['entity_status_1'] = ts('Invalid option'); | |
312 | } | |
b53cbfbc | 313 | if (!empty($values['entity_status_2'])) { |
2aa397bc TO |
314 | if (!in_array($values['entity_status_2'], $dayOfTheWeek)) { |
315 | $errors['entity_status_2'] = ts('Invalid day name'); | |
316 | } | |
317 | } | |
318 | else { | |
319 | $errors['entity_status_2'] = ts('Invalid day name'); | |
320 | } | |
321 | } | |
322 | } | |
323 | } | |
324 | return $errors; | |
325 | } | |
326 | ||
327 | /** | |
fe482240 | 328 | * Process the form submission. |
54957108 | 329 | * |
330 | * @param array $params | |
331 | * @param string $type | |
332 | * @param array $linkedEntities | |
333 | * | |
334 | * @throws \CiviCRM_API3_Exception | |
2aa397bc TO |
335 | */ |
336 | public static function postProcess($params = array(), $type, $linkedEntities = array()) { | |
337 | //Check entity_id not present in params take it from class variable | |
b53cbfbc | 338 | if (empty($params['entity_id'])) { |
2aa397bc TO |
339 | $params['entity_id'] = self::$_entityId; |
340 | } | |
341 | //Process this function only when you get this variable | |
342 | if ($params['allowRepeatConfigToSubmit'] == 1) { | |
c65ce939 | 343 | if (!empty($params['entity_table']) && !empty($params['entity_id']) && $type) { |
2aa397bc | 344 | $params['used_for'] = $type; |
b53cbfbc | 345 | if (empty($params['parent_entity_id'])) { |
2aa397bc TO |
346 | $params['parent_entity_id'] = self::$_parentEntityId; |
347 | } | |
b53cbfbc | 348 | if (!empty($params['schedule_reminder_id'])) { |
2aa397bc TO |
349 | $params['id'] = $params['schedule_reminder_id']; |
350 | } | |
351 | else { | |
352 | $params['id'] = self::$_scheduleReminderID; | |
353 | } | |
354 | ||
355 | //Save post params to the schedule reminder table | |
356 | $recurobj = new CRM_Core_BAO_RecurringEntity(); | |
357 | $dbParams = $recurobj->mapFormValuesToDB($params); | |
358 | ||
359 | //Delete repeat configuration and rebuild | |
b53cbfbc | 360 | if (!empty($params['id'])) { |
2aa397bc TO |
361 | CRM_Core_BAO_ActionSchedule::del($params['id']); |
362 | unset($params['id']); | |
363 | } | |
364 | $actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams); | |
365 | ||
366 | //exclude dates | |
367 | $excludeDateList = array(); | |
530dd28b | 368 | if (CRM_Utils_Array::value('exclude_date_list', $params) && CRM_Utils_Array::value('parent_entity_id', $params) && $actionScheduleObj->entity_value) { |
2aa397bc | 369 | //Since we get comma separated values lets get them in array |
530dd28b | 370 | $excludeDates = explode(",", $params['exclude_date_list']); |
2aa397bc TO |
371 | |
372 | //Check if there exists any values for this option group | |
373 | $optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', | |
353ffa53 TO |
374 | $type . '_repeat_exclude_dates_' . $params['parent_entity_id'], |
375 | 'id', | |
376 | 'name' | |
377 | ); | |
2aa397bc TO |
378 | if ($optionGroupIdExists) { |
379 | CRM_Core_BAO_OptionGroup::del($optionGroupIdExists); | |
380 | } | |
6c552737 TO |
381 | $optionGroupParams = array( |
382 | 'name' => $type . '_repeat_exclude_dates_' . $actionScheduleObj->entity_value, | |
383 | 'title' => $type . ' recursion', | |
384 | 'is_reserved' => 0, | |
385 | 'is_active' => 1, | |
386 | ); | |
2aa397bc TO |
387 | $opGroup = CRM_Core_BAO_OptionGroup::add($optionGroupParams); |
388 | if ($opGroup->id) { | |
389 | $oldWeight = 0; | |
390 | $fieldValues = array('option_group_id' => $opGroup->id); | |
22e263ad | 391 | foreach ($excludeDates as $val) { |
6c552737 TO |
392 | $optionGroupValue = array( |
393 | 'option_group_id' => $opGroup->id, | |
394 | 'label' => CRM_Utils_Date::processDate($val), | |
395 | 'value' => CRM_Utils_Date::processDate($val), | |
396 | 'name' => $opGroup->name, | |
397 | 'description' => 'Used for recurring ' . $type, | |
398 | 'weight' => CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues), | |
399 | 'is_active' => 1, | |
400 | ); | |
2aa397bc | 401 | $excludeDateList[] = $optionGroupValue['value']; |
bcbbb3a9 | 402 | CRM_Core_BAO_OptionValue::create($optionGroupValue); |
2aa397bc TO |
403 | } |
404 | } | |
405 | } | |
406 | ||
407 | //Set type for API | |
2aa397bc TO |
408 | $apiEntityType = explode("_", $type); |
409 | if (!empty($apiEntityType[1])) { | |
410 | $apiType = $apiEntityType[1]; | |
411 | } | |
412 | //Delete relations if any from recurring entity tables before inserting new relations for this entity id | |
413 | if ($params['entity_id']) { | |
414 | //If entity has any pre delete function, consider that first | |
415 | if (CRM_Utils_Array::value('pre_delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && | |
353ffa53 TO |
416 | CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) |
417 | ) { | |
71670adc | 418 | $preDeleteResult = call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func'], array($params['entity_id'])); |
deded1cf | 419 | if (!empty($preDeleteResult)) { |
71670adc | 420 | call_user_func(array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'], $preDeleteResult)); |
deded1cf | 421 | } |
2aa397bc TO |
422 | } |
423 | //Ready to execute delete on entities if it has delete function set | |
424 | if (CRM_Utils_Array::value('delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && | |
353ffa53 TO |
425 | CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) |
426 | ) { | |
2aa397bc TO |
427 | //Check if pre delete function has some ids to be deleted |
428 | if (!empty(CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted)) { | |
429 | foreach (CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted as $eid) { | |
430 | $result = civicrm_api3( | |
431 | ucfirst(strtolower($apiType)), | |
432 | CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], | |
433 | array( | |
434 | 'sequential' => 1, | |
435 | 'id' => $eid, | |
436 | ) | |
437 | ); | |
438 | if ($result['error']) { | |
439 | CRM_Core_Error::statusBounce('Error creating recurring list'); | |
440 | } | |
441 | } | |
442 | } | |
443 | else { | |
444 | $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table'], FALSE); | |
445 | foreach ($getRelatedEntities as $key => $value) { | |
446 | $result = civicrm_api3( | |
447 | ucfirst(strtolower($apiType)), | |
448 | CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], | |
449 | array( | |
450 | 'sequential' => 1, | |
451 | 'id' => $value['id'], | |
452 | ) | |
453 | ); | |
454 | if ($result['error']) { | |
455 | CRM_Core_Error::statusBounce('Error creating recurring list'); | |
456 | } | |
457 | } | |
458 | } | |
459 | } | |
460 | ||
461 | // find all entities from the recurring set. At this point we 'll get entities which were not deleted | |
462 | // for e.g due to participants being present. We need to delete them from recurring tables anyway. | |
463 | $pRepeatingEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table']); | |
22e263ad | 464 | foreach ($pRepeatingEntities as $val) { |
2aa397bc TO |
465 | CRM_Core_BAO_RecurringEntity::delEntity($val['id'], $val['table'], TRUE); |
466 | } | |
467 | } | |
468 | ||
469 | $recursion = new CRM_Core_BAO_RecurringEntity(); | |
353ffa53 TO |
470 | $recursion->dateColumns = $params['dateColumns']; |
471 | $recursion->scheduleId = $actionScheduleObj->id; | |
2aa397bc TO |
472 | |
473 | if (!empty($excludeDateList)) { | |
474 | $recursion->excludeDates = $excludeDateList; | |
475 | $recursion->excludeDateRangeColumns = $params['excludeDateRangeColumns']; | |
476 | } | |
b53cbfbc | 477 | if (!empty($params['intervalDateColumns'])) { |
2aa397bc TO |
478 | $recursion->intervalDateColumns = $params['intervalDateColumns']; |
479 | } | |
480 | $recursion->entity_id = $params['entity_id']; | |
481 | $recursion->entity_table = $params['entity_table']; | |
482 | if (!empty($linkedEntities)) { | |
483 | $recursion->linkedEntities = $linkedEntities; | |
484 | } | |
485 | ||
b1e18356 | 486 | $recursion->generate(); |
2aa397bc TO |
487 | |
488 | $status = ts('Repeat Configuration has been saved'); | |
489 | CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); | |
490 | } | |
491 | } | |
492 | } | |
493 | ||
494 | /** | |
495 | * Return a descriptive name for the page, used in wizard header | |
496 | * | |
497 | * @return string | |
498 | */ | |
499 | public function getTitle() { | |
500 | return ts('Repeat Entity'); | |
501 | } | |
502 | ||
503 | } |