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