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