CRM-19213 fix payment_instrument_id on event & add first test (shell really)
[civicrm-core.git] / CRM / Event / Form / Registration / Confirm.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * @package CRM
30 * @copyright CiviCRM LLC (c) 2004-2016
31 */
32
33 /**
34 * This class generates form components for processing Event.
35 */
36 class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
37
38 /**
39 * The values for the contribution db object.
40 *
41 * @var array
42 */
43 public $_values;
44
45 /**
46 * The total amount.
47 *
48 * @var float
49 */
50 public $_totalAmount;
51
52 /**
53 * Set variables up before form is built.
54 */
55 public function preProcess() {
56 parent::preProcess();
57
58 // lineItem isn't set until Register postProcess
59 $this->_lineItem = $this->get('lineItem');
60
61 $this->_params = $this->get('params');
62 $this->_params[0]['tax_amount'] = $this->get('tax_amount');
63
64 $this->_params[0]['is_pay_later'] = $this->get('is_pay_later');
65 $this->assign('is_pay_later', $this->_params[0]['is_pay_later']);
66 if ($this->_params[0]['is_pay_later']) {
67 $this->assign('pay_later_receipt', $this->_values['event']['pay_later_receipt']);
68 }
69
70 CRM_Utils_Hook::eventDiscount($this, $this->_params);
71
72 if (!empty($this->_params[0]['discount']) && !empty($this->_params[0]['discount']['applied'])) {
73 $this->set('hookDiscount', $this->_params[0]['discount']);
74 $this->assign('hookDiscount', $this->_params[0]['discount']);
75 }
76
77 // The concept of contributeMode is deprecated.
78 if ($this->_contributeMode == 'express') {
79 $params = array();
80 // rfp == redirect from paypal
81 // rfp is probably not required - the getPreApprovalDetails should deal with any payment-processor specific 'stuff'
82 $rfp = CRM_Utils_Request::retrieve('rfp', 'Boolean',
83 CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'
84 );
85
86 //we lost rfp in case of additional participant. So set it explicitly.
87 if ($rfp || CRM_Utils_Array::value('additional_participants', $this->_params[0], FALSE)) {
88 if (!empty($this->_paymentProcessor) && $this->_paymentProcessor['object']->supports('preApproval')) {
89 $preApprovalParams = $this->_paymentProcessor['object']->getPreApprovalDetails($this->get('pre_approval_parameters'));
90 $params = array_merge($this->_params, $preApprovalParams);
91 }
92 CRM_Core_Payment_Form::mapParams($this->_bltID, $params, $params, FALSE);
93
94 // set a few other parameters that are not really specific to this method because we don't know what
95 // will break if we change this.
96 $params['amount'] = $this->_params[0]['amount'];
97 if (!empty($this->_params[0]['discount'])) {
98 $params['discount'] = $this->_params[0]['discount'];
99 $params['discountAmount'] = $this->_params[0]['discountAmount'];
100 $params['discountMessage'] = $this->_params[0]['discountMessage'];
101 }
102
103 $params['amount_level'] = $this->_params[0]['amount_level'];
104 $params['currencyID'] = $this->_params[0]['currencyID'];
105
106 // also merge all the other values from the profile fields
107 $values = $this->controller->exportValues('Register');
108 $skipFields = array(
109 'amount',
110 "street_address-{$this->_bltID}",
111 "city-{$this->_bltID}",
112 "state_province_id-{$this->_bltID}",
113 "postal_code-{$this->_bltID}",
114 "country_id-{$this->_bltID}",
115 );
116
117 foreach ($values as $name => $value) {
118 // skip amount field
119 if (!in_array($name, $skipFields)) {
120 $params[$name] = $value;
121 }
122 if (substr($name, 0, 6) == 'price_') {
123 $params[$name] = $this->_params[0][$name];
124 }
125 }
126 $this->set('getExpressCheckoutDetails', $params);
127 }
128 $this->_params[0] = array_merge($this->_params[0], $params);
129 $this->_params[0]['is_primary'] = 1;
130 }
131 else {
132 //process only primary participant params.
133 $registerParams = $this->_params[0];
134 if (isset($registerParams["billing_state_province_id-{$this->_bltID}"])
135 && $registerParams["billing_state_province_id-{$this->_bltID}"]
136 ) {
137 $registerParams["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($registerParams["billing_state_province_id-{$this->_bltID}"]);
138 }
139
140 if (isset($registerParams["billing_country_id-{$this->_bltID}"]) && $registerParams["billing_country_id-{$this->_bltID}"]) {
141 $registerParams["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($registerParams["billing_country_id-{$this->_bltID}"]);
142 }
143 if (isset($registerParams['credit_card_exp_date'])) {
144 $registerParams['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($registerParams);
145 $registerParams['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($registerParams);
146 }
147 if ($this->_values['event']['is_monetary']) {
148 $registerParams['ip_address'] = CRM_Utils_System::ipAddress();
149 $registerParams['currencyID'] = $this->_params[0]['currencyID'];
150 }
151 //assign back primary participant params.
152 $this->_params[0] = $registerParams;
153 }
154
155 if ($this->_values['event']['is_monetary']) {
156 $this->_params[0]['invoiceID'] = $this->get('invoiceID');
157 }
158 $this->assign('defaultRole', FALSE);
159 if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
160 $this->assign('defaultRole', TRUE);
161 }
162
163 if (empty($this->_params[0]['participant_role_id']) &&
164 $this->_values['event']['default_role_id']
165 ) {
166 $this->_params[0]['participant_role_id'] = $this->_values['event']['default_role_id'];
167 }
168
169 if (isset($this->_values['event']['confirm_title'])) {
170 CRM_Utils_System::setTitle($this->_values['event']['confirm_title']);
171 }
172
173 if ($this->_pcpId) {
174 $params = CRM_Contribute_Form_Contribution_Confirm::processPcp($this, $this->_params[0]);
175 $this->_params[0] = $params;
176 }
177
178 $this->set('params', $this->_params);
179 }
180
181 /**
182 * Overwrite action, since we are only showing elements in frozen mode no help display needed.
183 *
184 * @return int
185 */
186 public function getAction() {
187 if ($this->_action & CRM_Core_Action::PREVIEW) {
188 return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW;
189 }
190 else {
191 return CRM_Core_Action::VIEW;
192 }
193 }
194
195 /**
196 * Build the form object.
197 */
198 public function buildQuickForm() {
199 $this->assignToTemplate();
200
201 if ($this->_values['event']['is_monetary'] &&
202 ($this->_params[0]['amount'] || $this->_params[0]['amount'] == 0)
203 ) {
204 $this->_amount = array();
205
206 $taxAmount = 0;
207 foreach ($this->_params as $k => $v) {
208 if ($v == 'skip') {
209 continue;
210 }
211 $individualTaxAmount = 0;
212 //display tax amount on confirmation page
213 $taxAmount += $v['tax_amount'];
214 if (is_array($v)) {
215 foreach (array(
216 'first_name',
217 'last_name',
218 ) as $name) {
219 if (isset($v['billing_' . $name]) &&
220 !isset($v[$name])
221 ) {
222 $v[$name] = $v['billing_' . $name];
223 }
224 }
225
226 if (!empty($v['first_name']) && !empty($v['last_name'])) {
227 $append = $v['first_name'] . ' ' . $v['last_name'];
228 }
229 else {
230 //use an email if we have one
231 foreach ($v as $v_key => $v_val) {
232 if (substr($v_key, 0, 6) == 'email-') {
233 $append = $v[$v_key];
234 }
235 }
236 }
237
238 $this->_amount[$k]['amount'] = $v['amount'];
239 if (!empty($v['discountAmount'])) {
240 $this->_amount[$k]['amount'] -= $v['discountAmount'];
241 }
242
243 $this->_amount[$k]['label'] = preg_replace('/\ 1/', '', $v['amount_level']) . ' - ' . $append;
244 $this->_part[$k]['info'] = CRM_Utils_Array::value('first_name', $v) . ' ' . CRM_Utils_Array::value('last_name', $v);
245 if (empty($v['first_name'])) {
246 $this->_part[$k]['info'] = $append;
247 }
248
249 /*CRM-16320 */
250 $individual[$k]['totalAmtWithTax'] = $this->_amount[$k]['amount'];
251 $individual[$k]['totalTaxAmt'] = $individualTaxAmount + $v['tax_amount'];
252 $this->_totalAmount = $this->_totalAmount + $this->_amount[$k]['amount'];
253 if (!empty($v['is_primary'])) {
254 $this->set('primaryParticipantAmount', $this->_amount[$k]['amount']);
255 }
256 }
257 }
258
259 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
260 $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
261 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
262 if ($invoicing) {
263 $this->assign('totalTaxAmount', $taxAmount);
264 $this->assign('taxTerm', $taxTerm);
265 $this->assign('individual', $individual);
266 $this->set('individual', $individual);
267 }
268
269 $this->assign('part', $this->_part);
270 $this->set('part', $this->_part);
271 $this->assign('amounts', $this->_amount);
272 $this->assign('totalAmount', $this->_totalAmount);
273 $this->set('totalAmount', $this->_totalAmount);
274 }
275
276 if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
277 $lineItemForTemplate = array();
278 $getTaxDetails = FALSE;
279 if (!empty($this->_lineItem) && is_array($this->_lineItem)) {
280 foreach ($this->_lineItem as $key => $value) {
281 if (!empty($value)) {
282 $lineItemForTemplate[$key] = $value;
283 }
284 if ($invoicing) {
285 foreach ($value as $v) {
286 if (isset($v['tax_rate'])) {
287 $getTaxDetails = TRUE;
288 }
289 }
290 }
291 }
292 }
293 if (!empty($lineItemForTemplate)) {
294 $this->assign('lineItem', $lineItemForTemplate);
295 }
296 $this->assign('getTaxDetails', $getTaxDetails);
297 }
298
299 //display additional participants profile.
300 self::assignProfiles($this);
301
302 //consider total amount.
303 $this->assign('isAmountzero', ($this->_totalAmount <= 0) ? TRUE : FALSE);
304
305 $contribButton = ts('Continue');
306 $this->addButtons(array(
307 array(
308 'type' => 'back',
309 'name' => ts('Go Back'),
310 ),
311 array(
312 'type' => 'next',
313 'name' => $contribButton,
314 'isDefault' => TRUE,
315 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"),
316 ),
317 )
318 );
319
320 $defaults = array();
321 $fields = array();
322 if (!empty($this->_fields)) {
323 foreach ($this->_fields as $name => $dontCare) {
324 $fields[$name] = 1;
325 }
326 }
327 $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
328 foreach ($fields as $name => $dontCare) {
329 if (isset($this->_params[0][$name])) {
330 $defaults[$name] = $this->_params[0][$name];
331 if (substr($name, 0, 7) == 'custom_') {
332 $timeField = "{$name}_time";
333 if (isset($this->_params[0][$timeField])) {
334 $defaults[$timeField] = $this->_params[0][$timeField];
335 }
336 if (isset($this->_params[0]["{$name}_id"])) {
337 $defaults["{$name}_id"] = $this->_params[0]["{$name}_id"];
338 }
339 }
340 elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)
341 && !empty($this->_params[0][$name . '_custom'])
342 ) {
343 $defaults[$name . '_custom'] = $this->_params[0][$name . '_custom'];
344 }
345 }
346 }
347
348 $this->setDefaults($defaults);
349 $this->freeze();
350
351 //lets give meaningful status message, CRM-4320.
352 $this->assign('isOnWaitlist', $this->_allowWaitlist);
353 $this->assign('isRequireApproval', $this->_requireApproval);
354
355 // Assign Participant Count to Lineitem Table
356 $this->assign('pricesetFieldsCount', CRM_Price_BAO_PriceSet::getPricesetCount($this->_priceSetId));
357 $this->addFormRule(array('CRM_Event_Form_Registration_Confirm', 'formRule'), $this);
358 }
359
360 /**
361 * Apply form rule.
362 *
363 * @param array $fields
364 * @param array $files
365 * @param CRM_Core_Form $self
366 *
367 * @return array|bool
368 */
369 public static function formRule($fields, $files, $self) {
370 $errors = array();
371 $eventFull = CRM_Event_BAO_Participant::eventFull($self->_eventId, FALSE, CRM_Utils_Array::value('has_waitlist', $self->_values['event']));
372 if ($eventFull && empty($self->_allowConfirmation)) {
373 if (empty($self->_allowWaitlist)) {
374 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "reset=1&id={$self->_eventId}", FALSE, NULL, FALSE, TRUE));
375 }
376 }
377 $self->_feeBlock = $self->_values['fee'];
378 CRM_Event_Form_Registration_Register::formatFieldsForOptionFull($self);
379
380 if (!empty($self->_priceSetId) &&
381 !$self->_requireApproval && !$self->_allowWaitlist
382 ) {
383 $priceSetErrors = self::validatePriceSet($self, $self->_params);
384 if (!empty($priceSetErrors)) {
385 CRM_Core_Session::setStatus(ts('You have been returned to the start of the registration process and any sold out events have been removed from your selections. You will not be able to continue until you review your booking and select different events if you wish.'), ts('Unfortunately some of your options have now sold out for one or more participants.'), 'error');
386 CRM_Core_Session::setStatus(ts('Please note that the options which are marked or selected are sold out for participant being viewed.'), ts('Sold out:'), 'error');
387 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "_qf_Register_display=true&qfKey={$fields['qfKey']}"));
388 }
389 }
390
391 return empty($priceSetErrors) ? TRUE : $priceSetErrors;
392 }
393
394 /**
395 * Process the form submission.
396 */
397 public function postProcess() {
398 $now = date('YmdHis');
399
400 $this->_params = $this->get('params');
401 if (!empty($this->_params[0]['contact_id'])) {
402 // unclear when this would be set & whether it could be checked in getContactID.
403 // perhaps it relates to when cid is in the url
404 //@todo someone who knows add comments on the various contactIDs in this form
405 $contactID = $this->_params[0]['contact_id'];
406 }
407 else {
408 $contactID = $this->getContactID();
409 }
410
411 // if a discount has been applied, lets now deduct it from the amount
412 // and fix the fee level
413 if (!empty($this->_params[0]['discount']) && !empty($this->_params[0]['discount']['applied'])) {
414 foreach ($this->_params as $k => $v) {
415 if (CRM_Utils_Array::value('amount', $this->_params[$k]) > 0 && !empty($this->_params[$k]['discountAmount'])) {
416 $this->_params[$k]['amount'] -= $this->_params[$k]['discountAmount'];
417 $this->_params[$k]['amount_level'] .= CRM_Utils_Array::value('discountMessage', $this->_params[$k]);
418 }
419 }
420 $this->set('params', $this->_params);
421 }
422
423 // CRM-4320, lets build array of cancelled additional participant ids
424 // those are drop or skip by primary at the time of confirmation.
425 // get all in and then unset those we want to process.
426 $cancelledIds = $this->_additionalParticipantIds;
427
428 $params = $this->_params;
429 if ($this->_values['event']['is_monetary']) {
430 $this->set('finalAmount', $this->_amount);
431 }
432 $participantCount = array();
433
434 //unset the skip participant from params.
435 //build the $participantCount array.
436 //maintain record for all participants.
437 foreach ($params as $participantNum => $record) {
438 if ($record == 'skip') {
439 unset($params[$participantNum]);
440 $participantCount[$participantNum] = 'skip';
441 }
442 elseif ($participantNum) {
443 $participantCount[$participantNum] = 'participant';
444 }
445
446 //lets get additional participant id to cancel.
447 if ($this->_allowConfirmation && is_array($cancelledIds)) {
448 $additonalId = CRM_Utils_Array::value('participant_id', $record);
449 if ($additonalId && $key = array_search($additonalId, $cancelledIds)) {
450 unset($cancelledIds[$key]);
451 }
452 }
453 }
454
455 $payment = $registerByID = $primaryCurrencyID = $contribution = NULL;
456 $paymentObjError = ts('The system did not record payment details for this payment and so could not process the transaction. Please report this error to the site administrator.');
457
458 $this->participantIDS = array();
459 $fields = array();
460 foreach ($params as $key => $value) {
461 CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields, $this);
462 //unset the billing parameters if it is pay later mode
463 //to avoid creation of billing location
464 // @todo - the reasoning for this is unclear - elsewhere we check what fields are provided by
465 // the form & if billing fields exist we create the address, relying on the form to collect
466 // only information we intend to store.
467 if ($this->_allowWaitlist
468 || $this->_requireApproval
469 || (!empty($value['is_pay_later']) && !$this->_isBillingAddressRequiredForPayLater)
470 || empty($value['is_primary'])
471 ) {
472 $billingFields = array(
473 "email-{$this->_bltID}",
474 'billing_first_name',
475 'billing_middle_name',
476 'billing_last_name',
477 "billing_street_address-{$this->_bltID}",
478 "billing_city-{$this->_bltID}",
479 "billing_state_province-{$this->_bltID}",
480 "billing_state_province_id-{$this->_bltID}",
481 "billing_postal_code-{$this->_bltID}",
482 "billing_country-{$this->_bltID}",
483 "billing_country_id-{$this->_bltID}",
484 "address_name-{$this->_bltID}",
485 );
486 foreach ($billingFields as $field) {
487 unset($value[$field]);
488 }
489 if (!empty($value['is_pay_later'])) {
490 $this->_values['params']['is_pay_later'] = TRUE;
491 }
492 }
493
494 //Unset ContactID for additional participants and set RegisterBy Id.
495 if (empty($value['is_primary'])) {
496 $contactID = CRM_Utils_Array::value('contact_id', $value);
497 $registerByID = $this->get('registerByID');
498 if ($registerByID) {
499 $value['registered_by_id'] = $registerByID;
500 }
501 }
502 else {
503 $value['amount'] = $this->_totalAmount;
504 }
505
506 $contactID = CRM_Event_Form_Registration_Confirm::updateContactFields($contactID, $value, $fields, $this);
507
508 // lets store the contactID in the session
509 // we dont store in userID in case the user is doing multiple
510 // transactions etc
511 // for things like tell a friend
512 if (!$this->getContactID() && !empty($value['is_primary'])) {
513 $session = CRM_Core_Session::singleton();
514 $session->set('transaction.userID', $contactID);
515 }
516
517 $value['description'] = ts('Online Event Registration') . ': ' . $this->_values['event']['title'];
518 $value['accountingCode'] = CRM_Utils_Array::value('accountingCode',
519 $this->_values['event']
520 );
521
522 $pending = FALSE;
523 if ($this->_allowWaitlist || $this->_requireApproval) {
524 //get the participant statuses.
525 $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
526 if ($this->_allowWaitlist) {
527 $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses);
528 }
529 else {
530 $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses);
531 }
532
533 //there might be case user seleted pay later and
534 //now becomes part of run time waiting list.
535 $value['is_pay_later'] = FALSE;
536 }
537
538 // required only if paid event
539 if ($this->_values['event']['is_monetary'] && !($this->_allowWaitlist || $this->_requireApproval)) {
540 if (is_array($this->_paymentProcessor)) {
541 $payment = $this->_paymentProcessor['object'];
542 }
543 if (!empty($this->_paymentProcessor) && $this->_paymentProcessor['object']->supports('preApproval')) {
544 $preApprovalParams = $this->_paymentProcessor['object']->getPreApprovalDetails($this->get('pre_approval_parameters'));
545 $value = array_merge($value, $preApprovalParams);
546 }
547 $result = NULL;
548
549 if (!empty($value['is_pay_later']) ||
550 $value['amount'] == 0 ||
551 // The concept of contributeMode is deprecated.
552 $this->_contributeMode == 'checkout' ||
553 $this->_contributeMode == 'notify'
554 ) {
555 if ($value['amount'] != 0) {
556 $pending = TRUE;
557 //get the participant statuses.
558 $pendingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'");
559 $status = !empty($value['is_pay_later']) ? 'Pending from pay later' : 'Pending from incomplete transaction';
560 $value['participant_status_id'] = $value['participant_status'] = array_search($status, $pendingStatuses);
561 }
562 }
563 elseif (!empty($value['is_primary'])) {
564 CRM_Core_Payment_Form::mapParams($this->_bltID, $value, $value, TRUE);
565 // payment email param can be empty for _bltID mapping
566 // thus provide mapping for it with a different email value
567 if (empty($value['email'])) {
568 $value['email'] = CRM_Utils_Array::valueByRegexKey('/^email-/', $value);
569 }
570
571 if (is_object($payment)) {
572 try {
573 $result = $payment->doPayment($value);
574 $value = array_merge($value, $result);
575 }
576 catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
577 CRM_Core_Session::singleton()->setStatus($e->getMessage());
578 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}"));
579 }
580 }
581 else {
582 CRM_Core_Error::fatal($paymentObjError);
583 }
584 }
585
586 $value['receive_date'] = $now;
587 if ($this->_allowConfirmation) {
588 $value['participant_register_date'] = $this->_values['participant']['register_date'];
589 }
590
591 $createContrib = ($value['amount'] != 0) ? TRUE : FALSE;
592 // force to create zero amount contribution, CRM-5095
593 if (!$createContrib && ($value['amount'] == 0)
594 && $this->_priceSetId && $this->_lineItem
595 ) {
596 $createContrib = TRUE;
597 }
598
599 if ($createContrib && !empty($value['is_primary']) &&
600 !$this->_allowWaitlist && !$this->_requireApproval
601 ) {
602 // if paid event add a contribution record
603 //if primary participant contributing additional amount
604 //append (multiple participants) to its fee level. CRM-4196.
605 $isAdditionalAmount = FALSE;
606 if (count($params) > 1) {
607 $isAdditionalAmount = TRUE;
608 }
609
610 //passing contribution id is already registered.
611 $contribution = self::processContribution($this, $value, $result, $contactID, $pending, $isAdditionalAmount, $this->_paymentProcessor);
612 $value['contributionID'] = $contribution->id;
613 $value['contributionTypeID'] = $contribution->financial_type_id;
614 $value['receive_date'] = $contribution->receive_date;
615 $value['trxn_id'] = $contribution->trxn_id;
616 $value['contributionID'] = $contribution->id;
617 $value['contributionTypeID'] = $contribution->financial_type_id;
618 }
619 $value['contactID'] = $contactID;
620 $value['eventID'] = $this->_eventId;
621 $value['item_name'] = $value['description'];
622 }
623
624 if (!empty($value['contributionID'])) {
625 $this->_values['contributionId'] = $value['contributionID'];
626 }
627
628 //CRM-4453.
629 if (!empty($value['is_primary'])) {
630 $primaryCurrencyID = CRM_Utils_Array::value('currencyID', $value);
631 }
632 if (empty($value['currencyID'])) {
633 $value['currencyID'] = $primaryCurrencyID;
634 }
635
636 // CRM-11182 - Confirmation page might not be monetary
637 if ($this->_values['event']['is_monetary']) {
638 if (!$pending && !empty($value['is_primary']) &&
639 !$this->_allowWaitlist && !$this->_requireApproval
640 ) {
641 // transactionID & receive date required while building email template
642 $this->assign('trxn_id', $value['trxn_id']);
643 $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($value['receive_date']));
644 $this->set('receiveDate', CRM_Utils_Date::mysqlToIso($value['receive_date']));
645 $this->set('trxnId', CRM_Utils_Array::value('trxn_id', $value));
646 }
647 }
648
649 $value['fee_amount'] = CRM_Utils_Array::value('amount', $value);
650 $this->set('value', $value);
651
652 // handle register date CRM-4320
653 if ($this->_allowConfirmation) {
654 $registerDate = CRM_Utils_Array::value('participant_register_date', $params);
655 }
656 elseif (!empty($params['participant_register_date']) &&
657 is_array($params['participant_register_date']) &&
658 !empty($params['participant_register_date'])
659 ) {
660 $registerDate = CRM_Utils_Date::format($params['participant_register_date']);
661 }
662 else {
663 $registerDate = date('YmdHis');
664 }
665 $this->assign('register_date', $registerDate);
666
667 $this->confirmPostProcess($contactID, $contribution, $payment);
668 }
669
670 //handle if no additional participant.
671 if (!$registerByID) {
672 $registerByID = $this->get('registerByID');
673 }
674
675 $this->set('participantIDs', $this->_participantIDS);
676
677 // create line items, CRM-5313
678 if ($this->_priceSetId &&
679 !empty($this->_lineItem)
680 ) {
681 // take all processed participant ids.
682 $allParticipantIds = $this->_participantIDS;
683
684 // when participant re-walk wizard.
685 if ($this->_allowConfirmation &&
686 !empty($this->_additionalParticipantIds)
687 ) {
688 $allParticipantIds = array_merge(array($registerByID), $this->_additionalParticipantIds);
689 }
690
691 $entityTable = 'civicrm_participant';
692 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
693 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
694 $totalTaxAmount = 0;
695 $dataArray = array();
696 foreach ($this->_lineItem as $key => $value) {
697 if ($value == 'skip') {
698 continue;
699 }
700 if ($entityId = CRM_Utils_Array::value($key, $allParticipantIds)) {
701 // do cleanup line items if participant re-walking wizard.
702 if ($this->_allowConfirmation) {
703 CRM_Price_BAO_LineItem::deleteLineItems($entityId, $entityTable);
704 }
705 $lineItem[$this->_priceSetId] = $value;
706 CRM_Price_BAO_LineItem::processPriceSet($entityId, $lineItem, $contribution, $entityTable);
707 }
708 if ($invoicing) {
709 foreach ($value as $line) {
710 if (isset($line['tax_amount']) && isset($line['tax_rate'])) {
711 $totalTaxAmount = $line['tax_amount'] + $totalTaxAmount;
712 if (isset($dataArray[$line['tax_rate']])) {
713 $dataArray[$line['tax_rate']] = $dataArray[$line['tax_rate']] + CRM_Utils_Array::value('tax_amount', $line);
714 }
715 else {
716 $dataArray[$line['tax_rate']] = CRM_Utils_Array::value('tax_amount', $line);
717 }
718 }
719 }
720 }
721 }
722 if ($invoicing) {
723 $this->assign('dataArray', $dataArray);
724 $this->assign('totalTaxAmount', $totalTaxAmount);
725 }
726 }
727
728 //update status and send mail to cancelled additional participants, CRM-4320
729 if ($this->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) {
730 $cancelledId = array_search('Cancelled',
731 CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'")
732 );
733 CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId);
734 }
735
736 $isTest = FALSE;
737 if ($this->_action & CRM_Core_Action::PREVIEW) {
738 $isTest = TRUE;
739 }
740
741 // for Transfer checkout.
742 // The concept of contributeMode is deprecated.
743 if (($this->_contributeMode == 'checkout' ||
744 $this->_contributeMode == 'notify'
745 ) && empty($params[0]['is_pay_later']) &&
746 !$this->_allowWaitlist && !$this->_requireApproval &&
747 $this->_totalAmount > 0
748 ) {
749
750 $primaryParticipant = $this->get('primaryParticipant');
751
752 if (empty($primaryParticipant['participantID'])) {
753 $primaryParticipant['participantID'] = $registerByID;
754 }
755
756 //build an array of custom profile and assigning it to template
757 $customProfile = CRM_Event_BAO_Event::buildCustomProfile($registerByID, $this->_values, NULL, $isTest);
758 if (count($customProfile)) {
759 $this->assign('customProfile', $customProfile);
760 $this->set('customProfile', $customProfile);
761 }
762
763 // do a transfer only if a monetary payment greater than 0
764 if ($this->_values['event']['is_monetary'] && $primaryParticipant) {
765 if ($payment && is_object($payment)) {
766 //CRM 14512 provide line items of all participants to payment gateway
767 $primaryContactId = $this->get('primaryContactId');
768
769 //build an array of cId/pId of participants
770 $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL, $primaryContactId, $isTest, TRUE);
771
772 //need to copy, since we are unsetting on the way.
773 $copyParticipantCountLines = $participantCount;
774
775 //lets carry all participant params w/ values.
776 foreach ($additionalIDs as $participantID => $contactId) {
777 $participantNum = NULL;
778 $participantNum = $participantID;
779 if ($participantID == $registerByID) {
780 // This is the is primary participant.
781 $participantNum = 0;
782 }
783 else {
784 if ($participantNum = array_search('participant', $copyParticipantCountLines)) {
785 //if no participant found break.
786 if ($participantNum === NULL) {
787 break;
788 }
789 //unset current particpant so we don't check them again
790 unset($copyParticipantCountLines[$participantNum]);
791 }
792 }
793 // get values of line items
794 if ($this->_amount) {
795 $amount = array();
796 $amount[$participantNum]['label'] = preg_replace('/\ 1/', '', $params[$participantNum]['amount_level']);
797 $amount[$participantNum]['amount'] = $params[$participantNum]['amount'];
798 $params[$participantNum]['amounts'] = $amount;
799 }
800
801 if (!empty($this->_lineItem)) {
802 $lineItems = $this->_lineItem;
803 $lineItem = array();
804 if ($lineItemValue = CRM_Utils_Array::value($participantNum, $lineItems)) {
805 $lineItem[] = $lineItemValue;
806 }
807 $params[$participantNum]['lineItem'] = $lineItem;
808 }
809
810 //only add additional particpants and not the primary particpant as we already have that
811 //added to $primaryParticipant so that this change doesn't break or require changes to
812 //existing gateway implementations
813 $primaryParticipant['participants_info'][$participantID] = $params[$participantNum];
814 }
815
816 //get event custom field information
817 $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_eventId, 0, $this->_values['event']['event_type_id']);
818 $primaryParticipant['eventCustomFields'] = $groupTree;
819
820 // call postprocess hook before leaving
821 $this->postProcessHook();
822 // this does not return
823 $payment->doPayment($primaryParticipant, 'event');
824 }
825 else {
826 CRM_Core_Error::fatal($paymentObjError);
827 }
828 }
829 }
830 else {
831 //otherwise send mail Confirmation/Receipt
832 $primaryContactId = $this->get('primaryContactId');
833
834 //build an array of cId/pId of participants
835 $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID,
836 NULL, $primaryContactId, $isTest,
837 TRUE
838 );
839 //lets send mails to all with meaningful text, CRM-4320.
840 $this->assign('isOnWaitlist', $this->_allowWaitlist);
841 $this->assign('isRequireApproval', $this->_requireApproval);
842
843 //need to copy, since we are unsetting on the way.
844 $copyParticipantCount = $participantCount;
845
846 //lets carry all paticipant params w/ values.
847 foreach ($additionalIDs as $participantID => $contactId) {
848 $participantNum = NULL;
849 if ($participantID == $registerByID) {
850 $participantNum = 0;
851 }
852 else {
853 if ($participantNum = array_search('participant', $copyParticipantCount)) {
854 unset($copyParticipantCount[$participantNum]);
855 }
856 }
857 if ($participantNum === NULL) {
858 break;
859 }
860
861 //carry the participant submitted values.
862 $this->_values['params'][$participantID] = $params[$participantNum];
863 }
864
865 foreach ($additionalIDs as $participantID => $contactId) {
866 $participantNum = 0;
867 if ($participantID == $registerByID) {
868 //set as Primary Participant
869 $this->assign('isPrimary', 1);
870 //build an array of custom profile and assigning it to template.
871 $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $this->_values, NULL, $isTest);
872
873 if (count($customProfile)) {
874 $this->assign('customProfile', $customProfile);
875 $this->set('customProfile', $customProfile);
876 }
877 $this->_values['params']['additionalParticipant'] = FALSE;
878 }
879 else {
880 //take the Additional participant number.
881 if ($participantNum = array_search('participant', $participantCount)) {
882 unset($participantCount[$participantNum]);
883 }
884 // Change $this->_values['participant'] to include additional participant values
885 $ids = $participantValues = array();
886 $participantParams = array('id' => $participantID);
887 CRM_Event_BAO_Participant::getValues($participantParams, $participantValues, $ids);
888 $this->_values['participant'] = $participantValues[$participantID];
889
890 $this->assign('isPrimary', 0);
891 $this->assign('customProfile', NULL);
892 //Additional Participant should get only it's payment information
893 if (!empty($this->_amount)) {
894 $amount = array();
895 $params = $this->get('params');
896 $amount[$participantNum]['label'] = preg_replace('/\ 1/', '', $params[$participantNum]['amount_level']);
897 $amount[$participantNum]['amount'] = $params[$participantNum]['amount'];
898 $this->assign('amounts', $amount);
899 }
900 if ($this->_lineItem) {
901 $lineItems = $this->_lineItem;
902 $lineItem = array();
903 if ($lineItemValue = CRM_Utils_Array::value($participantNum, $lineItems)) {
904 $lineItem[] = $lineItemValue;
905 }
906 if ($invoicing) {
907 $individual = $this->get('individual');
908 $dataArray[key($dataArray)] = $individual[$participantNum]['totalTaxAmt'];
909 $this->assign('dataArray', $dataArray);
910 $this->assign('totalAmount', $individual[$participantNum]['totalAmtWithTax']);
911 $this->assign('totalTaxAmount', $individual[$participantNum]['totalTaxAmt']);
912 $this->assign('individual', array($individual[$participantNum]));
913 }
914 $this->assign('lineItem', $lineItem);
915 }
916 $this->_values['params']['additionalParticipant'] = TRUE;
917 $this->assign('isAdditionalParticipant', $this->_values['params']['additionalParticipant']);
918 }
919
920 //pass these variables since these are run time calculated.
921 $this->_values['params']['isOnWaitlist'] = $this->_allowWaitlist;
922 $this->_values['params']['isRequireApproval'] = $this->_requireApproval;
923
924 //send mail to primary as well as additional participants.
925 $this->assign('contactID', $contactId);
926 $this->assign('participantID', $participantID);
927 CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest);
928 }
929 }
930 }
931
932 /**
933 * Process the contribution.
934 *
935 * @param CRM_Core_Form $form
936 * @param array $params
937 * @param array $result
938 * @param int $contactID
939 * @param bool $pending
940 * @param bool $isAdditionalAmount
941 *
942 * @return \CRM_Contribute_BAO_Contribution
943 */
944 public static function processContribution(
945 &$form, $params, $result, $contactID,
946 $pending = FALSE, $isAdditionalAmount = FALSE,
947 $paymentProcessor = NULL
948 ) {
949 $transaction = new CRM_Core_Transaction();
950
951 $now = date('YmdHis');
952 $receiptDate = NULL;
953
954 if (!empty($form->_values['event']['is_email_confirm'])) {
955 $receiptDate = $now;
956 }
957 //CRM-4196
958 if ($isAdditionalAmount) {
959 $params['amount_level'] = $params['amount_level'] . ts(' (multiple participants)') . CRM_Core_DAO::VALUE_SEPARATOR;
960 }
961
962 $contribParams = array(
963 'contact_id' => $contactID,
964 'financial_type_id' => !empty($form->_values['event']['financial_type_id']) ? $form->_values['event']['financial_type_id'] : $params['financial_type_id'],
965 'receive_date' => $now,
966 'total_amount' => $params['amount'],
967 'tax_amount' => $params['tax_amount'],
968 'amount_level' => $params['amount_level'],
969 'invoice_id' => $params['invoiceID'],
970 'currency' => $params['currencyID'],
971 'source' => !empty($params['participant_source']) ? $params['participant_source'] : $params['description'],
972 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0),
973 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params),
974 );
975
976 if ($paymentProcessor) {
977 $contribParams['payment_instrument_id'] = $paymentProcessor['payment_instrument_id'];
978 }
979
980 if (!$pending && $result) {
981 $contribParams += array(
982 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result),
983 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']),
984 'trxn_id' => $result['trxn_id'],
985 'receipt_date' => $receiptDate,
986 );
987 }
988
989 $allStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
990 $contribParams['contribution_status_id'] = array_search('Completed', $allStatuses);
991 if ($pending) {
992 $contribParams['contribution_status_id'] = array_search('Pending', $allStatuses);
993 }
994
995 $contribParams['is_test'] = 0;
996 if ($form->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') {
997 $contribParams['is_test'] = 1;
998 }
999
1000 $contribID = NULL;
1001 if (!empty($contribParams['invoice_id'])) {
1002 $contribID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution',
1003 $contribParams['invoice_id'],
1004 'id',
1005 'invoice_id'
1006 );
1007 }
1008
1009 $ids = array();
1010 if ($contribID) {
1011 $ids['contribution'] = $contribID;
1012 $contribParams['id'] = $contribID;
1013 }
1014
1015 if (CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
1016 $eventStartDate = CRM_Utils_Array::value(
1017 'start_date',
1018 CRM_Utils_Array::value(
1019 'event',
1020 $form->_values
1021 )
1022 );
1023 if ($eventStartDate) {
1024 $contribParams['revenue_recognition_date'] = date('Ymd', strtotime($eventStartDate));
1025 }
1026 }
1027 //create an contribution address
1028 // The concept of contributeMode is deprecated. Elsewhere we use the function processBillingAddress() - although
1029 // currently that is only inherited by back-office forms.
1030 if ($form->_contributeMode != 'notify' && empty($params['is_pay_later'])) {
1031 $contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
1032 }
1033
1034 $contribParams['payment_processor'] = CRM_Utils_Array::value('payment_processor', $params);
1035 $contribParams['skipLineItem'] = 1;
1036 // create contribution record
1037 $contribution = CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
1038 // CRM-11124
1039 CRM_Event_BAO_Participant::createDiscountTrxn($form->_eventId, $contribParams, NULL, CRM_Price_BAO_PriceSet::parseFirstPriceSetValueIDFromParams($params));
1040
1041 // process soft credit / pcp pages
1042 if (!empty($params['pcp_made_through_id'])) {
1043 CRM_Contribute_BAO_ContributionSoft::formatSoftCreditParams($params, $form);
1044 CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
1045 }
1046
1047 $transaction->commit();
1048
1049 return $contribution;
1050 }
1051
1052 /**
1053 * Fix the Location Fields.
1054 *
1055 * @todo Reconcile with the contribution method formatParamsForPaymentProcessor
1056 * rather than adding different logic to check when to keep the billing
1057 * fields. There might be a difference in handling guest/multiple
1058 * participants though.
1059 *
1060 * @param array $params
1061 * @param array $fields
1062 * @param CRM_Core_Form $form
1063 */
1064 public static function fixLocationFields(&$params, &$fields, &$form) {
1065 if (!empty($form->_fields)) {
1066 foreach ($form->_fields as $name => $dontCare) {
1067 $fields[$name] = 1;
1068 }
1069 }
1070
1071 // If there's no 'first_name' in the profile then overwrite the names from
1072 // the billing fields (if they are set)
1073 if (is_array($fields)) {
1074 if (!array_key_exists('first_name', $fields)) {
1075 $nameFields = array('first_name', 'middle_name', 'last_name');
1076 foreach ($nameFields as $name) {
1077 $fields[$name] = 1;
1078 if (array_key_exists("billing_$name", $params)) {
1079 $params[$name] = $params["billing_{$name}"];
1080 $params['preserveDBName'] = TRUE;
1081 }
1082 }
1083 }
1084 }
1085
1086 // Add the billing names to the billing address, if a billing name is set
1087 if (!empty($params['billing_first_name'])) {
1088 $params["address_name-{$form->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
1089 $fields["address_name-{$form->_bltID}"] = 1;
1090 }
1091
1092 $fields["email-{$form->_bltID}"] = 1;
1093 $fields['email-Primary'] = 1;
1094
1095 //if its pay later or additional participant set email address as primary.
1096 if ((!empty($params['is_pay_later']) || empty($params['is_primary']) ||
1097 !$form->_values['event']['is_monetary'] ||
1098 $form->_allowWaitlist ||
1099 $form->_requireApproval
1100 ) && !empty($params["email-{$form->_bltID}"])
1101 ) {
1102 $params['email-Primary'] = $params["email-{$form->_bltID}"];
1103 }
1104 }
1105
1106 /**
1107 * Update contact fields.
1108 *
1109 * @param int $contactID
1110 * @param array $params
1111 * @param array $fields
1112 * @param CRM_Core_Form $form
1113 *
1114 * @return int
1115 */
1116 public static function updateContactFields($contactID, $params, $fields, &$form) {
1117 //add the contact to group, if add to group is selected for a
1118 //particular uf group
1119
1120 // get the add to groups
1121 $addToGroups = array();
1122
1123 if (!empty($form->_fields)) {
1124 foreach ($form->_fields as $key => $value) {
1125 if (!empty($value['add_to_group_id'])) {
1126 $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
1127 }
1128 }
1129 }
1130
1131 // check for profile double opt-in and get groups to be subscribed
1132 $subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID);
1133
1134 foreach ($addToGroups as $k) {
1135 if (array_key_exists($k, $subscribeGroupIds)) {
1136 unset($addToGroups[$k]);
1137 }
1138 }
1139
1140 // since we are directly adding contact to group lets unset it from mailing
1141 if (!empty($addToGroups)) {
1142 foreach ($addToGroups as $groupId) {
1143 if (isset($subscribeGroupIds[$groupId])) {
1144 unset($subscribeGroupIds[$groupId]);
1145 }
1146 }
1147 }
1148 if ($contactID) {
1149 $ctype = CRM_Core_DAO::getFieldValue(
1150 'CRM_Contact_DAO_Contact',
1151 $contactID,
1152 'contact_type'
1153 );
1154
1155 if (array_key_exists('contact_id', $params) && empty($params['contact_id'])) {
1156 // we unset this here because the downstream function ignores the contactID we give it
1157 // if it is set & it is difficult to understand the implications of 'fixing' this downstream
1158 // but if we are passing a contact id into this function it's reasonable to assume we don't
1159 // want it ignored
1160 unset($params['contact_id']);
1161 }
1162
1163 $contactID = CRM_Contact_BAO_Contact::createProfileContact(
1164 $params,
1165 $fields,
1166 $contactID,
1167 $addToGroups,
1168 NULL,
1169 $ctype,
1170 TRUE
1171 );
1172 }
1173 else {
1174
1175 foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
1176 if (!isset($params[$greeting . '_id'])) {
1177 $params[$greeting . '_id'] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting);
1178 }
1179 }
1180
1181 $contactID = CRM_Contact_BAO_Contact::createProfileContact($params,
1182 $fields,
1183 NULL,
1184 $addToGroups,
1185 NULL,
1186 NULL,
1187 TRUE
1188 );
1189 $form->set('contactID', $contactID);
1190 }
1191
1192 //get email primary first if exist
1193 $subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params));
1194 if (!$subscribtionEmail['email']) {
1195 $subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$form->_bltID}", $params);
1196 }
1197 // subscribing contact to groups
1198 if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) {
1199 CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID);
1200 }
1201
1202 return $contactID;
1203 }
1204
1205 /**
1206 * Assign Profiles.
1207 *
1208 * @param CRM_Core_Form $form
1209 */
1210 public static function assignProfiles(&$form) {
1211 $participantParams = $form->_params;
1212 $formattedValues = $profileFields = array();
1213 $count = 1;
1214 foreach ($participantParams as $participantNum => $participantValue) {
1215 if ($participantNum) {
1216 $prefix1 = 'additional';
1217 $prefix2 = 'additional_';
1218 }
1219 else {
1220 $prefix1 = '';
1221 $prefix2 = '';
1222 }
1223 if ($participantValue != 'skip') {
1224 //get the customPre profile info
1225 if (!empty($form->_values[$prefix2 . 'custom_pre_id'])) {
1226 $values = $groupName = array();
1227 CRM_Event_BAO_Event::displayProfile($participantValue,
1228 $form->_values[$prefix2 . 'custom_pre_id'],
1229 $groupName,
1230 $values,
1231 $profileFields
1232 );
1233
1234 if (count($values)) {
1235 $formattedValues[$count][$prefix1 . 'CustomPre'] = $values;
1236 }
1237 $formattedValues[$count][$prefix1 . 'CustomPreGroupTitle'] = CRM_Utils_Array::value('groupTitle', $groupName);
1238 }
1239 //get the customPost profile info
1240 if (!empty($form->_values[$prefix2 . 'custom_post_id'])) {
1241 $values = $groupName = array();
1242 foreach ($form->_values[$prefix2 . 'custom_post_id'] as $gids) {
1243 $val = array();
1244 CRM_Event_BAO_Event::displayProfile($participantValue,
1245 $gids,
1246 $group,
1247 $val,
1248 $profileFields
1249 );
1250 $values[$gids] = $val;
1251 $groupName[$gids] = $group;
1252 }
1253
1254 if (count($values)) {
1255 $formattedValues[$count][$prefix1 . 'CustomPost'] = $values;
1256 }
1257
1258 if (isset($formattedValues[$count][$prefix1 . 'CustomPre'])) {
1259 $formattedValues[$count][$prefix1 . 'CustomPost'] = array_diff_assoc($formattedValues[$count][$prefix1 . 'CustomPost'],
1260 $formattedValues[$count][$prefix1 . 'CustomPre']
1261 );
1262 }
1263
1264 $formattedValues[$count][$prefix1 . 'CustomPostGroupTitle'] = $groupName;
1265 }
1266 $count++;
1267 }
1268 $form->_fields = $profileFields;
1269 }
1270 if (!empty($formattedValues)) {
1271 $form->assign('primaryParticipantProfile', $formattedValues[1]);
1272 $form->set('primaryParticipantProfile', $formattedValues[1]);
1273 if ($count > 2) {
1274 unset($formattedValues[1]);
1275 $form->assign('addParticipantProfile', $formattedValues);
1276 $form->set('addParticipantProfile', $formattedValues);
1277 }
1278 }
1279 }
1280
1281 /**
1282 * Submit in test mode.
1283 *
1284 * @param $params
1285 */
1286 public static function testSubmit($params) {
1287 $form = new CRM_Event_Form_Registration_Confirm();
1288 // This way the mocked up controller ignores the session stuff.
1289 $_SERVER['REQUEST_METHOD'] = 'GET';
1290 $_REQUEST['id'] = $form->_eventId = $params['id'];
1291 $form->controller = new CRM_Event_Controller_Registration();
1292 $form->_params = $params['params'];
1293 $form->set('params', $params['params']);
1294 $form->_values['custom_pre_id'] = array();
1295 $form->_values['custom_post_id'] = array();
1296 $form->_contributeMode = $params['contributeMode'];
1297 $eventParams = array('id' => $params['id']);
1298 CRM_Event_BAO_Event::retrieve($eventParams, $form->_values['event']);
1299 $form->set('registerByID', $params['registerByID']);
1300 $form->postProcess();
1301 }
1302
1303 }