Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
0f57ba7a | 19 | * This class provides the functionality for batch profile update for events. |
6a488035 TO |
20 | */ |
21 | class CRM_Event_Form_Task_Batch extends CRM_Event_Form_Task { | |
22 | ||
23 | /** | |
eceb18cc | 24 | * The title of the group. |
6a488035 TO |
25 | * |
26 | * @var string | |
27 | */ | |
28 | protected $_title; | |
29 | ||
30 | /** | |
eceb18cc | 31 | * Maximum profile fields that will be displayed. |
90b461f1 | 32 | * @var int |
6a488035 TO |
33 | */ |
34 | protected $_maxFields = 9; | |
35 | ||
36 | /** | |
eceb18cc | 37 | * Variable to store redirect path. |
90b461f1 | 38 | * @var string |
6a488035 TO |
39 | */ |
40 | protected $_userContext; | |
41 | ||
42 | /** | |
100fef9d | 43 | * Variable to store previous status id. |
90b461f1 | 44 | * @var array |
6a488035 TO |
45 | */ |
46 | protected $_fromStatusIds; | |
47 | ||
48 | /** | |
eceb18cc | 49 | * Build all the data structures needed to build the form. |
6a488035 TO |
50 | * |
51 | * @return void | |
03e04002 | 52 | */ |
00be9182 | 53 | public function preProcess() { |
353ffa53 TO |
54 | /* |
55 | * initialize the task and row fields | |
56 | */ | |
6a488035 TO |
57 | parent::preProcess(); |
58 | ||
59 | //get the contact read only fields to display. | |
be2fb01f | 60 | $readOnlyFields = array_merge(['sort_name' => ts('Name')], |
6a488035 TO |
61 | CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
62 | 'contact_autocomplete_options', | |
63 | TRUE, NULL, FALSE, 'name', TRUE | |
64 | ) | |
65 | ); | |
66 | //get the read only field data. | |
67 | $returnProperties = array_fill_keys(array_keys($readOnlyFields), 1); | |
68 | $contactDetails = CRM_Contact_BAO_Contact_Utils::contactDetails($this->_participantIds, | |
69 | 'CiviEvent', $returnProperties | |
70 | ); | |
71 | $this->assign('contactDetails', $contactDetails); | |
72 | $this->assign('readOnlyFields', $readOnlyFields); | |
73 | } | |
74 | ||
75 | /** | |
eceb18cc | 76 | * Build the form object. |
6a488035 | 77 | * |
d81bc485 | 78 | * @throws \CRM_Core_Exception |
6a488035 | 79 | */ |
00be9182 | 80 | public function buildQuickForm() { |
6a488035 | 81 | $ufGroupId = $this->get('ufGroupId'); |
6a488035 | 82 | if (!$ufGroupId) { |
d81bc485 | 83 | CRM_Core_Error::statusBounce('ufGroupId is missing'); |
6a488035 TO |
84 | } |
85 | ||
b581842f | 86 | $this->_title = ts('Update multiple participants') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId); |
6a488035 TO |
87 | CRM_Utils_System::setTitle($this->_title); |
88 | $this->addDefaultButtons(ts('Save')); | |
d81bc485 | 89 | |
6a488035 | 90 | $this->_fields = CRM_Core_BAO_UFGroup::getFields($ufGroupId, FALSE, CRM_Core_Action::VIEW); |
f72db5fa | 91 | if (array_key_exists('participant_status', $this->_fields)) { |
3ea7ca33 | 92 | $this->assign('statusProfile', 1); |
93 | $this->assignToTemplate(); | |
94 | } | |
6a488035 TO |
95 | |
96 | // remove file type field and then limit fields | |
97 | $suppressFields = FALSE; | |
be2fb01f | 98 | $removehtmlTypes = ['File']; |
6a488035 TO |
99 | foreach ($this->_fields as $name => $field) { |
100 | if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name) && | |
101 | in_array($this->_fields[$name]['html_type'], $removehtmlTypes) | |
102 | ) { | |
103 | $suppressFields = TRUE; | |
104 | unset($this->_fields[$name]); | |
105 | } | |
106 | ||
107 | //fix to reduce size as we are using this field in grid | |
108 | if (is_array($field['attributes']) && $this->_fields[$name]['attributes']['size'] > 19) { | |
109 | //shrink class to "form-text-medium" | |
110 | $this->_fields[$name]['attributes']['size'] = 19; | |
111 | } | |
112 | } | |
113 | ||
114 | $this->_fields = array_slice($this->_fields, 0, $this->_maxFields); | |
115 | ||
be2fb01f | 116 | $this->addButtons([ |
90b461f1 SL |
117 | [ |
118 | 'type' => 'submit', | |
119 | 'name' => ts('Update Participant(s)'), | |
120 | 'isDefault' => TRUE, | |
121 | ], | |
122 | [ | |
123 | 'type' => 'cancel', | |
124 | 'name' => ts('Cancel'), | |
125 | ], | |
126 | ]); | |
6a488035 | 127 | |
6a488035 TO |
128 | $this->assign('profileTitle', $this->_title); |
129 | $this->assign('componentIds', $this->_participantIds); | |
130 | $fileFieldExists = FALSE; | |
131 | ||
132 | //load all campaigns. | |
133 | if (array_key_exists('participant_campaign_id', $this->_fields)) { | |
be2fb01f | 134 | $this->_componentCampaigns = []; |
6a488035 TO |
135 | CRM_Core_PseudoConstant::populate($this->_componentCampaigns, |
136 | 'CRM_Event_DAO_Participant', | |
137 | TRUE, 'campaign_id', 'id', | |
138 | ' id IN (' . implode(' , ', array_values($this->_participantIds)) . ' ) ' | |
139 | ); | |
140 | } | |
141 | ||
142 | //fix for CRM-2752 | |
143 | // get the option value for custom data type | |
c460c196 PN |
144 | $customDataType = CRM_Core_OptionGroup::values('custom_data_type', FALSE, FALSE, FALSE, NULL, 'name'); |
145 | $this->_roleCustomDataTypeID = array_search('ParticipantRole', $customDataType); | |
146 | $this->_eventNameCustomDataTypeID = array_search('ParticipantEventName', $customDataType); | |
147 | $this->_eventTypeCustomDataTypeID = array_search('ParticipantEventType', $customDataType); | |
6a488035 TO |
148 | |
149 | // build custom data getFields array | |
150 | $customFieldsRole = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, $this->_roleCustomDataTypeID); | |
151 | ||
152 | $customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, $this->_eventNameCustomDataTypeID); | |
d623de42 M |
153 | $customFieldsEventType = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, $this->_eventTypeCustomDataTypeID); |
154 | ||
6a488035 TO |
155 | $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole, |
156 | CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE) | |
157 | ); | |
d623de42 | 158 | $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEventType, $customFields); |
6a488035 TO |
159 | $this->_customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields); |
160 | ||
161 | foreach ($this->_participantIds as $participantId) { | |
162 | $roleId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'role_id'); | |
163 | $eventId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'event_id'); | |
d623de42 | 164 | $eventTypeId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $eventId, 'event_type_id'); |
6a488035 TO |
165 | foreach ($this->_fields as $name => $field) { |
166 | if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) { | |
9c1bc317 | 167 | $customValue = $this->_customFields[$customFieldID] ?? NULL; |
be2fb01f | 168 | $entityColumnValue = []; |
a7488080 | 169 | if (!empty($customValue['extends_entity_column_value'])) { |
6a488035 TO |
170 | $entityColumnValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, |
171 | $customValue['extends_entity_column_value'] | |
172 | ); | |
173 | } | |
6a488035 | 174 | if (($this->_roleCustomDataTypeID == $customValue['extends_entity_column_id']) && |
d711dda7 | 175 | in_array($roleId, $entityColumnValue) |
6a488035 TO |
176 | ) { |
177 | CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId); | |
178 | } | |
179 | elseif (($this->_eventNameCustomDataTypeID == $customValue['extends_entity_column_id']) && | |
d711dda7 | 180 | in_array($eventId, $entityColumnValue) |
6a488035 TO |
181 | ) { |
182 | CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId); | |
183 | } | |
d623de42 | 184 | elseif ($this->_eventTypeCustomDataTypeID == $customValue['extends_entity_column_id'] && |
d711dda7 | 185 | in_array($eventTypeId, $entityColumnValue) |
d623de42 M |
186 | ) { |
187 | CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId); | |
188 | } | |
d711dda7 | 189 | elseif (CRM_Utils_System::isNull($entityColumnValue)) { |
6a488035 TO |
190 | CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId); |
191 | } | |
192 | } | |
193 | else { | |
d81bc485 | 194 | if ($field['name'] === 'participant_role') { |
6a488035 TO |
195 | $field['is_multiple'] = TRUE; |
196 | } | |
197 | // handle non custom fields | |
198 | CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId); | |
199 | } | |
200 | } | |
201 | } | |
202 | ||
203 | $this->assign('fields', $this->_fields); | |
204 | ||
205 | // don't set the status message when form is submitted. | |
206 | $buttonName = $this->controller->getButtonName('submit'); | |
207 | ||
d81bc485 | 208 | if ($suppressFields && $buttonName !== '_qf_Batch_next') { |
657c89d9 | 209 | CRM_Core_Session::setStatus(ts("File type field(s) in the selected profile are not supported for Update multiple participants."), ts('Unsupported Field Type'), 'info'); |
6a488035 TO |
210 | } |
211 | ||
212 | $this->addDefaultButtons(ts('Update Participant(s)')); | |
213 | } | |
214 | ||
215 | /** | |
c490a46a | 216 | * Set default values for the form. |
6a488035 | 217 | * |
d81bc485 | 218 | * @return array |
6a488035 | 219 | */ |
00be9182 | 220 | public function setDefaultValues() { |
6a488035 | 221 | if (empty($this->_fields)) { |
d81bc485 | 222 | return []; |
6a488035 TO |
223 | } |
224 | ||
be2fb01f | 225 | $defaults = []; |
6a488035 | 226 | foreach ($this->_participantIds as $participantId) { |
be2fb01f | 227 | $details[$participantId] = []; |
6a488035 TO |
228 | |
229 | $details[$participantId] = CRM_Event_BAO_Participant::participantDetails($participantId); | |
230 | CRM_Core_BAO_UFGroup::setProfileDefaults(NULL, $this->_fields, $defaults, FALSE, $participantId, 'Event'); | |
231 | ||
232 | //get the from status ids, CRM-4323 | |
233 | if (array_key_exists('participant_status', $this->_fields)) { | |
9c1bc317 | 234 | $this->_fromStatusIds[$participantId] = $defaults["field[$participantId][participant_status]"] ?? NULL; |
6a488035 TO |
235 | } |
236 | if (array_key_exists('participant_role', $this->_fields)) { | |
237 | if ($defaults["field[{$participantId}][participant_role]"]) { | |
238 | $roles = $defaults["field[{$participantId}][participant_role]"]; | |
239 | foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, $roles) as $k => $v) { | |
240 | $defaults["field[$participantId][participant_role][{$v}]"] = 1; | |
241 | } | |
242 | unset($defaults["field[{$participantId}][participant_role]"]); | |
243 | } | |
244 | } | |
245 | } | |
246 | ||
247 | $this->assign('details', $details); | |
248 | return $defaults; | |
249 | } | |
250 | ||
251 | /** | |
eceb18cc | 252 | * Process the form after the input has been submitted and validated. |
6a488035 TO |
253 | */ |
254 | public function postProcess() { | |
255 | $params = $this->exportValues(); | |
0f57ba7a | 256 | $this->submit($params); |
6a488035 | 257 | } |
6a488035 | 258 | |
0cf587a7 | 259 | /** |
100fef9d CW |
260 | * @param int $participantId |
261 | * @param int $statusId | |
0cf587a7 | 262 | * |
90b461f1 | 263 | * @return mixed |
d81bc485 | 264 | * @throws \CRM_Core_Exception |
265 | * @throws \CiviCRM_API3_Exception | |
0cf587a7 | 266 | */ |
00be9182 | 267 | public static function updatePendingOnlineContribution($participantId, $statusId) { |
6a488035 | 268 | if (!$participantId || !$statusId) { |
28a04ea9 | 269 | return NULL; |
6a488035 TO |
270 | } |
271 | ||
272 | $contributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($participantId, | |
273 | 'Event' | |
274 | ); | |
275 | if (!$contributionId) { | |
276 | return; | |
277 | } | |
278 | ||
279 | //status rules. | |
280 | //1. participant - positive => contribution - completed. | |
281 | //2. participant - negative => contribution - cancelled. | |
282 | ||
283 | $positiveStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Positive'"); | |
284 | $negativeStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"); | |
285 | $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); | |
286 | ||
287 | $contributionStatusId = NULL; | |
288 | if (array_key_exists($statusId, $positiveStatuses)) { | |
289 | $contributionStatusId = array_search('Completed', $contributionStatuses); | |
290 | } | |
291 | if (array_key_exists($statusId, $negativeStatuses)) { | |
292 | $contributionStatusId = array_search('Cancelled', $contributionStatuses); | |
293 | } | |
294 | ||
295 | if (!$contributionStatusId) { | |
296 | return; | |
297 | } | |
298 | ||
be2fb01f | 299 | $params = [ |
6a488035 TO |
300 | 'component_id' => $participantId, |
301 | 'componentName' => 'Event', | |
302 | 'contribution_id' => $contributionId, | |
303 | 'contribution_status_id' => $contributionStatusId, | |
0bad10e7 | 304 | 'IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved' => 1, |
be2fb01f | 305 | ]; |
6a488035 TO |
306 | |
307 | //change related contribution status. | |
e577770c | 308 | $updatedStatusId = self::updateContributionStatus($params); |
6a488035 TO |
309 | |
310 | return $updatedStatusId; | |
311 | } | |
96025800 | 312 | |
e577770c EM |
313 | /** |
314 | * Update contribution status. | |
315 | * | |
d81bc485 | 316 | * @param array $params |
317 | * | |
318 | * @return NULL|int | |
319 | * @throws \CRM_Core_Exception | |
320 | * @throws \CiviCRM_API3_Exception | |
321 | * @throws \Exception | |
322 | * | |
e577770c EM |
323 | * @deprecated |
324 | * This is only called from one place in the code & | |
325 | * it is unclear whether it is a function on the way in or on the way out | |
326 | * | |
e577770c EM |
327 | */ |
328 | public static function updateContributionStatus($params) { | |
329 | // get minimum required values. | |
9c1bc317 CW |
330 | $statusId = $params['contribution_status_id'] ?? NULL; |
331 | $componentId = $params['component_id'] ?? NULL; | |
332 | $componentName = $params['componentName'] ?? NULL; | |
333 | $contributionId = $params['contribution_id'] ?? NULL; | |
e577770c EM |
334 | |
335 | if (!$contributionId || !$componentId || !$componentName || !$statusId) { | |
336 | return NULL; | |
337 | } | |
338 | ||
be2fb01f | 339 | $input = $ids = $objects = []; |
e577770c EM |
340 | |
341 | //get the required ids. | |
342 | $ids['contribution'] = $contributionId; | |
343 | ||
344 | if (!$ids['contact'] = CRM_Utils_Array::value('contact_id', $params)) { | |
345 | $ids['contact'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', | |
346 | $contributionId, | |
347 | 'contact_id' | |
348 | ); | |
349 | } | |
350 | ||
d81bc485 | 351 | if ($componentName === 'Event') { |
e577770c EM |
352 | $name = 'event'; |
353 | $ids['participant'] = $componentId; | |
354 | ||
355 | if (!$ids['event'] = CRM_Utils_Array::value('event_id', $params)) { | |
356 | $ids['event'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', | |
357 | $componentId, | |
358 | 'event_id' | |
359 | ); | |
360 | } | |
361 | } | |
362 | ||
d81bc485 | 363 | if ($componentName === 'Membership') { |
e577770c EM |
364 | $name = 'contribute'; |
365 | $ids['membership'] = $componentId; | |
366 | } | |
367 | $ids['contributionPage'] = NULL; | |
368 | $ids['contributionRecur'] = NULL; | |
369 | $input['component'] = $name; | |
370 | ||
371 | $baseIPN = new CRM_Core_Payment_BaseIPN(); | |
e577770c EM |
372 | |
373 | // reset template values. | |
374 | $template = CRM_Core_Smarty::singleton(); | |
375 | $template->clearTemplateVars(); | |
376 | ||
377 | if (!$baseIPN->validateData($input, $ids, $objects, FALSE)) { | |
d81bc485 | 378 | throw new CRM_Core_Exception('validation error'); |
e577770c EM |
379 | } |
380 | ||
381 | $contribution = &$objects['contribution']; | |
382 | ||
be2fb01f | 383 | $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', [ |
e577770c EM |
384 | 'labelColumn' => 'name', |
385 | 'flip' => 1, | |
be2fb01f | 386 | ]); |
9c1bc317 | 387 | $input['IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved'] = $params['IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved'] ?? NULL; |
e577770c | 388 | if ($statusId == $contributionStatuses['Cancelled']) { |
8f6fb3fa | 389 | $transaction = new CRM_Core_Transaction(); |
e577770c EM |
390 | $baseIPN->cancelled($objects, $transaction, $input); |
391 | $transaction->commit(); | |
392 | return $statusId; | |
393 | } | |
394 | elseif ($statusId == $contributionStatuses['Failed']) { | |
8f6fb3fa | 395 | $transaction = new CRM_Core_Transaction(); |
e577770c EM |
396 | $baseIPN->failed($objects, $transaction, $input); |
397 | $transaction->commit(); | |
398 | return $statusId; | |
399 | } | |
400 | ||
401 | // status is not pending | |
402 | if ($contribution->contribution_status_id != $contributionStatuses['Pending']) { | |
e577770c EM |
403 | return; |
404 | } | |
405 | ||
406 | //set values for ipn code. | |
be2fb01f | 407 | foreach ([ |
90b461f1 SL |
408 | 'fee_amount', |
409 | 'check_number', | |
410 | 'payment_instrument_id', | |
411 | ] as $field) { | |
e577770c EM |
412 | if (!$input[$field] = CRM_Utils_Array::value($field, $params)) { |
413 | $input[$field] = $contribution->$field; | |
414 | } | |
415 | } | |
416 | if (!$input['trxn_id'] = CRM_Utils_Array::value('trxn_id', $params)) { | |
417 | $input['trxn_id'] = $contribution->invoice_id; | |
418 | } | |
419 | if (!$input['amount'] = CRM_Utils_Array::value('total_amount', $params)) { | |
420 | $input['amount'] = $contribution->total_amount; | |
421 | } | |
422 | $input['is_test'] = $contribution->is_test; | |
423 | $input['net_amount'] = $contribution->net_amount; | |
424 | if (!empty($input['fee_amount']) && !empty($input['amount'])) { | |
425 | $input['net_amount'] = $input['amount'] - $input['fee_amount']; | |
426 | } | |
427 | ||
428 | //complete the contribution. | |
2ea48796 | 429 | // @todo use the api - ie civicrm_api3('Contribution', 'completetransaction', $input); |
430 | // as this method is not preferred / supported. | |
8f6fb3fa | 431 | CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects); |
e577770c EM |
432 | |
433 | // reset template values before processing next transactions | |
434 | $template->clearTemplateVars(); | |
435 | ||
436 | return $statusId; | |
437 | } | |
438 | ||
3ea7ca33 | 439 | /** |
440 | * Assign the minimal set of variables to the template. | |
441 | */ | |
442 | public function assignToTemplate() { | |
be2fb01f | 443 | $notifyingStatuses = ['Pending from waitlist', 'Pending from approval', 'Expired', 'Cancelled']; |
3ea7ca33 | 444 | $notifyingStatuses = array_intersect($notifyingStatuses, CRM_Event_PseudoConstant::participantStatus()); |
1aa1efef | 445 | $this->assign('status', TRUE); |
3ea7ca33 | 446 | if (!empty($notifyingStatuses)) { |
4a64b915 AH |
447 | $s = '<em>' . implode('</em>, <em>', $notifyingStatuses) . '</em>'; |
448 | $this->assign('notifyingStatuses', $s); | |
3ea7ca33 | 449 | } |
3ea7ca33 | 450 | } |
451 | ||
0f57ba7a | 452 | /** |
d81bc485 | 453 | * @param array $params |
454 | * | |
455 | * @throws \CRM_Core_Exception | |
456 | * @throws \CiviCRM_API3_Exception | |
0f57ba7a | 457 | */ |
458 | public function submit($params) { | |
459 | $statusClasses = CRM_Event_PseudoConstant::participantStatusClass(); | |
460 | if (isset($params['field'])) { | |
461 | foreach ($params['field'] as $key => $value) { | |
462 | ||
463 | //check for custom data | |
464 | $value['custom'] = CRM_Core_BAO_CustomField::postProcess($value, | |
465 | $key, | |
466 | 'Participant' | |
467 | ); | |
a4f468b6 | 468 | foreach (array_keys($value) as $fieldName) { |
469 | // Unset the original custom field now that it has been formatting to the 'custom' | |
470 | // array as it may not be in the right format for the api as is (notably for | |
471 | // multiple checkbox values). | |
3eb99314 | 472 | // @todo extract submit functions on other Batch update classes & |
473 | // extend CRM_Event_Form_Task_BatchTest::testSubmit with a data provider to test them. | |
a4f468b6 | 474 | if (substr($fieldName, 0, 7) === 'custom_') { |
475 | unset($value[$fieldName]); | |
476 | } | |
477 | } | |
0f57ba7a | 478 | |
479 | $value['id'] = $key; | |
480 | ||
481 | if (!empty($value['participant_role'])) { | |
482 | if (is_array($value['participant_role'])) { | |
483 | $value['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($value['participant_role'])); | |
484 | } | |
485 | else { | |
486 | $value['role_id'] = $value['participant_role']; | |
487 | } | |
488 | } | |
489 | ||
490 | //need to send mail when status change | |
491 | $statusChange = FALSE; | |
492 | $relatedStatusChange = FALSE; | |
493 | if (!empty($value['participant_status'])) { | |
494 | $value['status_id'] = $value['participant_status']; | |
9c1bc317 | 495 | $fromStatusId = $this->_fromStatusIds[$key] ?? NULL; |
0f57ba7a | 496 | if (!$fromStatusId) { |
497 | $fromStatusId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $key, 'status_id'); | |
498 | } | |
499 | ||
500 | if ($fromStatusId != $value['status_id']) { | |
501 | $relatedStatusChange = TRUE; | |
502 | } | |
503 | if ($statusClasses[$fromStatusId] != $statusClasses[$value['status_id']]) { | |
504 | $statusChange = TRUE; | |
505 | } | |
506 | } | |
507 | ||
508 | unset($value['participant_status']); | |
509 | ||
510 | civicrm_api3('Participant', 'create', $value); | |
511 | ||
512 | //need to trigger mails when we change status | |
513 | if ($statusChange) { | |
be2fb01f | 514 | CRM_Event_BAO_Participant::transitionParticipants([$key], $value['status_id'], $fromStatusId); |
0f57ba7a | 515 | } |
516 | if ($relatedStatusChange) { | |
517 | //update related contribution status, CRM-4395 | |
518 | self::updatePendingOnlineContribution($key, $value['status_id']); | |
519 | } | |
520 | } | |
521 | CRM_Core_Session::setStatus(ts('The updates have been saved.'), ts('Saved'), 'success'); | |
522 | } | |
523 | else { | |
524 | CRM_Core_Session::setStatus(ts('No updates have been saved.'), ts('Not Saved'), 'alert'); | |
525 | } | |
526 | } | |
527 | ||
6a488035 | 528 | } |