Beispiel #1
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     $now = date('YmdHis');
     $this->_params = $this->get('params');
     if (!empty($this->_params[0]['contact_id'])) {
         // unclear when this would be set & whether it could be checked in getContactID.
         // perhaps it relates to when cid is in the url
         //@todo someone who knows add comments on the various contactIDs in this form
         $contactID = $this->_params[0]['contact_id'];
     } else {
         $contactID = $this->getContactID();
     }
     // if a discount has been applied, lets now deduct it from the amount
     // and fix the fee level
     if (!empty($this->_params[0]['discount']) && !empty($this->_params[0]['discount']['applied'])) {
         foreach ($this->_params as $k => $v) {
             if (CRM_Utils_Array::value('amount', $this->_params[$k]) > 0 && !empty($this->_params[$k]['discountAmount'])) {
                 $this->_params[$k]['amount'] -= $this->_params[$k]['discountAmount'];
                 $this->_params[$k]['amount_level'] .= CRM_Utils_Array::value('discountMessage', $this->_params[$k]);
             }
         }
         $this->set('params', $this->_params);
     }
     // CRM-4320, lets build array of cancelled additional participant ids
     // those are drop or skip by primary at the time of confirmation.
     // get all in and then unset those we want to process.
     $cancelledIds = $this->_additionalParticipantIds;
     $params = $this->_params;
     if ($this->_values['event']['is_monetary']) {
         $this->set('finalAmount', $this->_amount);
     }
     $participantCount = array();
     //unset the skip participant from params.
     //build the $participantCount array.
     //maintain record for all participants.
     foreach ($params as $participantNum => $record) {
         if ($record == 'skip') {
             unset($params[$participantNum]);
             $participantCount[$participantNum] = 'skip';
         } elseif ($participantNum) {
             $participantCount[$participantNum] = 'participant';
         }
         //lets get additional participant id to cancel.
         if ($this->_allowConfirmation && is_array($cancelledIds)) {
             $additonalId = CRM_Utils_Array::value('participant_id', $record);
             if ($additonalId && ($key = array_search($additonalId, $cancelledIds))) {
                 unset($cancelledIds[$key]);
             }
         }
     }
     $payment = $registerByID = $primaryCurrencyID = $contribution = NULL;
     $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.');
     $this->participantIDS = array();
     $fields = array();
     foreach ($params as $key => $value) {
         CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields, $this);
         //unset the billing parameters if it is pay later mode
         //to avoid creation of billing location
         // @todo - the reasoning for this is unclear - elsewhere we check what fields are provided by
         // the form & if billing fields exist we create the address, relying on the form to collect
         // only information we intend to store.
         if ($this->_allowWaitlist || $this->_requireApproval || !empty($value['is_pay_later']) && !$this->_isBillingAddressRequiredForPayLater || empty($value['is_primary'])) {
             $billingFields = array("email-{$this->_bltID}", 'billing_first_name', 'billing_middle_name', 'billing_last_name', "billing_street_address-{$this->_bltID}", "billing_city-{$this->_bltID}", "billing_state_province-{$this->_bltID}", "billing_state_province_id-{$this->_bltID}", "billing_postal_code-{$this->_bltID}", "billing_country-{$this->_bltID}", "billing_country_id-{$this->_bltID}", "address_name-{$this->_bltID}");
             foreach ($billingFields as $field) {
                 unset($value[$field]);
             }
             if (!empty($value['is_pay_later'])) {
                 $this->_values['params']['is_pay_later'] = TRUE;
             }
         }
         //Unset ContactID for additional participants and set RegisterBy Id.
         if (empty($value['is_primary'])) {
             $contactID = CRM_Utils_Array::value('contact_id', $value);
             $registerByID = $this->get('registerByID');
             if ($registerByID) {
                 $value['registered_by_id'] = $registerByID;
             }
         } else {
             $value['amount'] = $this->_totalAmount;
         }
         $contactID = CRM_Event_Form_Registration_Confirm::updateContactFields($contactID, $value, $fields, $this);
         // lets store the contactID in the session
         // we dont store in userID in case the user is doing multiple
         // transactions etc
         // for things like tell a friend
         if (!$this->getContactID() && !empty($value['is_primary'])) {
             $session = CRM_Core_Session::singleton();
             $session->set('transaction.userID', $contactID);
         }
         $value['description'] = ts('Online Event Registration') . ': ' . $this->_values['event']['title'];
         $value['accountingCode'] = CRM_Utils_Array::value('accountingCode', $this->_values['event']);
         $pending = FALSE;
         if ($this->_allowWaitlist || $this->_requireApproval) {
             //get the participant statuses.
             $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
             if ($this->_allowWaitlist) {
                 $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses);
             } else {
                 $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses);
             }
             //there might be case user seleted pay later and
             //now becomes part of run time waiting list.
             $value['is_pay_later'] = FALSE;
         }
         // required only if paid event
         if ($this->_values['event']['is_monetary'] && !($this->_allowWaitlist || $this->_requireApproval)) {
             if (is_array($this->_paymentProcessor)) {
                 $payment = $this->_paymentProcessor['object'];
             }
             if (!empty($this->_paymentProcessor) && $this->_paymentProcessor['object']->supports('preApproval')) {
                 $preApprovalParams = $this->_paymentProcessor['object']->getPreApprovalDetails($this->get('pre_approval_parameters'));
                 $value = array_merge($value, $preApprovalParams);
             }
             $result = NULL;
             if (!empty($value['is_pay_later']) || $value['amount'] == 0 || $this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') {
                 if ($value['amount'] != 0) {
                     $pending = TRUE;
                     //get the participant statuses.
                     $pendingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'");
                     $status = !empty($value['is_pay_later']) ? 'Pending from pay later' : 'Pending from incomplete transaction';
                     $value['participant_status_id'] = $value['participant_status'] = array_search($status, $pendingStatuses);
                 }
             } elseif (!empty($value['is_primary'])) {
                 CRM_Core_Payment_Form::mapParams($this->_bltID, $value, $value, TRUE);
                 // payment email param can be empty for _bltID mapping
                 // thus provide mapping for it with a different email value
                 if (empty($value['email'])) {
                     $value['email'] = CRM_Utils_Array::valueByRegexKey('/^email-/', $value);
                 }
                 if (is_object($payment)) {
                     try {
                         $result = $payment->doPayment($value);
                         $value = array_merge($value, $result);
                     } catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
                         CRM_Core_Session::singleton()->setStatus($e->getMessage());
                         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}"));
                     }
                 } else {
                     CRM_Core_Error::fatal($paymentObjError);
                 }
             }
             $value['receive_date'] = $now;
             if ($this->_allowConfirmation) {
                 $value['participant_register_date'] = $this->_values['participant']['register_date'];
             }
             $createContrib = $value['amount'] != 0 ? TRUE : FALSE;
             // force to create zero amount contribution, CRM-5095
             if (!$createContrib && $value['amount'] == 0 && $this->_priceSetId && $this->_lineItem) {
                 $createContrib = TRUE;
             }
             if ($createContrib && !empty($value['is_primary']) && !$this->_allowWaitlist && !$this->_requireApproval) {
                 // if paid event add a contribution record
                 //if primary participant contributing additional amount
                 //append (multiple participants) to its fee level. CRM-4196.
                 $isAdditionalAmount = FALSE;
                 if (count($params) > 1) {
                     $isAdditionalAmount = TRUE;
                 }
                 //passing contribution id is already registered.
                 $contribution = self::processContribution($this, $value, $result, $contactID, $pending, $isAdditionalAmount);
                 $value['contributionID'] = $contribution->id;
                 $value['contributionTypeID'] = $contribution->financial_type_id;
                 $value['receive_date'] = $contribution->receive_date;
                 $value['trxn_id'] = $contribution->trxn_id;
                 $value['contributionID'] = $contribution->id;
                 $value['contributionTypeID'] = $contribution->financial_type_id;
             }
             $value['contactID'] = $contactID;
             $value['eventID'] = $this->_eventId;
             $value['item_name'] = $value['description'];
         }
         if (!empty($value['contributionID'])) {
             $this->_values['contributionId'] = $value['contributionID'];
         }
         //CRM-4453.
         if (!empty($value['is_primary'])) {
             $primaryCurrencyID = CRM_Utils_Array::value('currencyID', $value);
         }
         if (empty($value['currencyID'])) {
             $value['currencyID'] = $primaryCurrencyID;
         }
         // CRM-11182 - Confirmation page might not be monetary
         if ($this->_values['event']['is_monetary']) {
             if (!$pending && !empty($value['is_primary']) && !$this->_allowWaitlist && !$this->_requireApproval) {
                 // transactionID & receive date required while building email template
                 $this->assign('trxn_id', $value['trxn_id']);
                 $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($value['receive_date']));
                 $this->set('receiveDate', CRM_Utils_Date::mysqlToIso($value['receive_date']));
                 $this->set('trxnId', CRM_Utils_Array::value('trxn_id', $value));
             }
         }
         $value['fee_amount'] = CRM_Utils_Array::value('amount', $value);
         $this->set('value', $value);
         // handle register date CRM-4320
         if ($this->_allowConfirmation) {
             $registerDate = CRM_Utils_Array::value('participant_register_date', $params);
         } elseif (!empty($params['participant_register_date']) && is_array($params['participant_register_date']) && !empty($params['participant_register_date'])) {
             $registerDate = CRM_Utils_Date::format($params['participant_register_date']);
         } else {
             $registerDate = date('YmdHis');
         }
         $this->assign('register_date', $registerDate);
         $this->confirmPostProcess($contactID, $contribution, $payment);
     }
     //handle if no additional participant.
     if (!$registerByID) {
         $registerByID = $this->get('registerByID');
     }
     $this->set('participantIDs', $this->_participantIDS);
     // create line items, CRM-5313
     if ($this->_priceSetId && !empty($this->_lineItem)) {
         // take all processed participant ids.
         $allParticipantIds = $this->_participantIDS;
         // when participant re-walk wizard.
         if ($this->_allowConfirmation && !empty($this->_additionalParticipantIds)) {
             $allParticipantIds = array_merge(array($registerByID), $this->_additionalParticipantIds);
         }
         $entityTable = 'civicrm_participant';
         $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
         $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
         $totalTaxAmount = 0;
         $dataArray = array();
         foreach ($this->_lineItem as $key => $value) {
             if ($value == 'skip') {
                 continue;
             }
             if ($entityId = CRM_Utils_Array::value($key, $allParticipantIds)) {
                 // do cleanup line  items if participant re-walking wizard.
                 if ($this->_allowConfirmation) {
                     CRM_Price_BAO_LineItem::deleteLineItems($entityId, $entityTable);
                 }
                 $lineItem[$this->_priceSetId] = $value;
                 CRM_Price_BAO_LineItem::processPriceSet($entityId, $lineItem, $contribution, $entityTable);
             }
             if ($invoicing) {
                 foreach ($value as $line) {
                     if (isset($line['tax_amount']) && isset($line['tax_rate'])) {
                         $totalTaxAmount = $line['tax_amount'] + $totalTaxAmount;
                         if (isset($dataArray[$line['tax_rate']])) {
                             $dataArray[$line['tax_rate']] = $dataArray[$line['tax_rate']] + CRM_Utils_Array::value('tax_amount', $line);
                         } else {
                             $dataArray[$line['tax_rate']] = CRM_Utils_Array::value('tax_amount', $line);
                         }
                     }
                 }
             }
         }
         if ($invoicing) {
             $this->assign('dataArray', $dataArray);
             $this->assign('totalTaxAmount', $totalTaxAmount);
         }
     }
     //update status and send mail to cancelled additional participants, CRM-4320
     if ($this->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) {
         $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
         CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId);
     }
     $isTest = FALSE;
     if ($this->_action & CRM_Core_Action::PREVIEW) {
         $isTest = TRUE;
     }
     // for Transfer checkout.
     // The concept of contributeMode is deprecated.
     if (($this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') && empty($params[0]['is_pay_later']) && !$this->_allowWaitlist && !$this->_requireApproval && $this->_totalAmount > 0) {
         $primaryParticipant = $this->get('primaryParticipant');
         if (empty($primaryParticipant['participantID'])) {
             $primaryParticipant['participantID'] = $registerByID;
         }
         //build an array of custom profile and assigning it to template
         $customProfile = CRM_Event_BAO_Event::buildCustomProfile($registerByID, $this->_values, NULL, $isTest);
         if (count($customProfile)) {
             $this->assign('customProfile', $customProfile);
             $this->set('customProfile', $customProfile);
         }
         // do a transfer only if a monetary payment greater than 0
         if ($this->_values['event']['is_monetary'] && $primaryParticipant) {
             if ($payment && is_object($payment)) {
                 //CRM 14512 provide line items of all participants to payment gateway
                 $primaryContactId = $this->get('primaryContactId');
                 //build an array of cId/pId of participants
                 $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL, $primaryContactId, $isTest, TRUE);
                 //need to copy, since we are unsetting on the way.
                 $copyParticipantCountLines = $participantCount;
                 //lets carry all participant params w/ values.
                 foreach ($additionalIDs as $participantID => $contactId) {
                     $participantNum = NULL;
                     $participantNum = $participantID;
                     if ($participantID == $registerByID) {
                         // This is the is primary participant.
                         $participantNum = 0;
                     } else {
                         if ($participantNum = array_search('participant', $copyParticipantCountLines)) {
                             //if no participant found break.
                             if ($participantNum === NULL) {
                                 break;
                             }
                             //unset current particpant so we don't check them again
                             unset($copyParticipantCountLines[$participantNum]);
                         }
                     }
                     // get values of line items
                     if ($this->_amount) {
                         $amount = array();
                         $amount[$participantNum]['label'] = preg_replace('//', '', $params[$participantNum]['amount_level']);
                         $amount[$participantNum]['amount'] = $params[$participantNum]['amount'];
                         $params[$participantNum]['amounts'] = $amount;
                     }
                     if (!empty($this->_lineItem)) {
                         $lineItems = $this->_lineItem;
                         $lineItem = array();
                         if ($lineItemValue = CRM_Utils_Array::value($participantNum, $lineItems)) {
                             $lineItem[] = $lineItemValue;
                         }
                         $params[$participantNum]['lineItem'] = $lineItem;
                     }
                     //only add additional particpants and not the primary particpant as we already have that
                     //added to $primaryParticipant so that this change doesn't break or require changes to
                     //existing gateway implementations
                     $primaryParticipant['participants_info'][$participantID] = $params[$participantNum];
                 }
                 //get event custom field information
                 $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_eventId, 0, $this->_values['event']['event_type_id']);
                 $primaryParticipant['eventCustomFields'] = $groupTree;
                 // call postprocess hook before leaving
                 $this->postProcessHook();
                 // this does not return
                 $payment->doPayment($primaryParticipant, 'event');
             } else {
                 CRM_Core_Error::fatal($paymentObjError);
             }
         }
     } else {
         //otherwise send mail Confirmation/Receipt
         $primaryContactId = $this->get('primaryContactId');
         //build an array of cId/pId of participants
         $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL, $primaryContactId, $isTest, TRUE);
         //lets send  mails to all with meaningful text, CRM-4320.
         $this->assign('isOnWaitlist', $this->_allowWaitlist);
         $this->assign('isRequireApproval', $this->_requireApproval);
         //need to copy, since we are unsetting on the way.
         $copyParticipantCount = $participantCount;
         //lets carry all paticipant params w/ values.
         foreach ($additionalIDs as $participantID => $contactId) {
             $participantNum = NULL;
             if ($participantID == $registerByID) {
                 $participantNum = 0;
             } else {
                 if ($participantNum = array_search('participant', $copyParticipantCount)) {
                     unset($copyParticipantCount[$participantNum]);
                 }
             }
             if ($participantNum === NULL) {
                 break;
             }
             //carry the participant submitted values.
             $this->_values['params'][$participantID] = $params[$participantNum];
         }
         foreach ($additionalIDs as $participantID => $contactId) {
             $participantNum = 0;
             if ($participantID == $registerByID) {
                 //set as Primary Participant
                 $this->assign('isPrimary', 1);
                 //build an array of custom profile and assigning it to template.
                 $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $this->_values, NULL, $isTest);
                 if (count($customProfile)) {
                     $this->assign('customProfile', $customProfile);
                     $this->set('customProfile', $customProfile);
                 }
                 $this->_values['params']['additionalParticipant'] = FALSE;
             } else {
                 //take the Additional participant number.
                 if ($participantNum = array_search('participant', $participantCount)) {
                     unset($participantCount[$participantNum]);
                 }
                 // Change $this->_values['participant'] to include additional participant values
                 $ids = $participantValues = array();
                 $participantParams = array('id' => $participantID);
                 CRM_Event_BAO_Participant::getValues($participantParams, $participantValues, $ids);
                 $this->_values['participant'] = $participantValues[$participantID];
                 $this->assign('isPrimary', 0);
                 $this->assign('customProfile', NULL);
                 //Additional Participant should get only it's payment information
                 if (!empty($this->_amount)) {
                     $amount = array();
                     $params = $this->get('params');
                     $amount[$participantNum]['label'] = preg_replace('//', '', $params[$participantNum]['amount_level']);
                     $amount[$participantNum]['amount'] = $params[$participantNum]['amount'];
                     $this->assign('amounts', $amount);
                 }
                 if ($this->_lineItem) {
                     $lineItems = $this->_lineItem;
                     $lineItem = array();
                     if ($lineItemValue = CRM_Utils_Array::value($participantNum, $lineItems)) {
                         $lineItem[] = $lineItemValue;
                     }
                     if ($invoicing) {
                         $individual = $this->get('individual');
                         $dataArray[key($dataArray)] = $individual[$participantNum]['totalTaxAmt'];
                         $this->assign('dataArray', $dataArray);
                         $this->assign('totalAmount', $individual[$participantNum]['totalAmtWithTax']);
                         $this->assign('totalTaxAmount', $individual[$participantNum]['totalTaxAmt']);
                         $this->assign('individual', array($individual[$participantNum]));
                     }
                     $this->assign('lineItem', $lineItem);
                 }
                 $this->_values['params']['additionalParticipant'] = TRUE;
                 $this->assign('isAdditionalParticipant', $this->_values['params']['additionalParticipant']);
             }
             //pass these variables since these are run time calculated.
             $this->_values['params']['isOnWaitlist'] = $this->_allowWaitlist;
             $this->_values['params']['isRequireApproval'] = $this->_requireApproval;
             //send mail to primary as well as additional participants.
             $this->assign('contactID', $contactId);
             $this->assign('participantID', $participantID);
             CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest);
         }
     }
 }
Beispiel #2
0
 /**
  * Process Registration of free event.
  *
  * @param array $params
  *   Form values.
  * @param int $contactID
  */
 public function processRegistration($params, $contactID = NULL)
 {
     $session = CRM_Core_Session::singleton();
     $this->_participantInfo = array();
     // CRM-4320, lets build array of cancelled additional participant ids
     // those are drop or skip by primary at the time of confirmation.
     // get all in and then unset those are confirmed.
     $cancelledIds = $this->_additionalParticipantIds;
     $participantCount = array();
     foreach ($params as $participantNum => $record) {
         if ($record == 'skip') {
             $participantCount[$participantNum] = 'skip';
         } elseif ($participantNum) {
             $participantCount[$participantNum] = 'participant';
         }
     }
     $registerByID = NULL;
     foreach ($params as $key => $value) {
         if ($value != 'skip') {
             $fields = NULL;
             // setting register by Id and unset contactId.
             if (empty($value['is_primary'])) {
                 $contactID = NULL;
                 $registerByID = $this->get('registerByID');
                 if ($registerByID) {
                     $value['registered_by_id'] = $registerByID;
                 }
                 // get an email if one exists for the participant
                 $participantEmail = '';
                 foreach (array_keys($value) as $valueName) {
                     if (substr($valueName, 0, 6) == 'email-') {
                         $participantEmail = $value[$valueName];
                     }
                 }
                 if ($participantEmail) {
                     $this->_participantInfo[] = $participantEmail;
                 } else {
                     $this->_participantInfo[] = $value['first_name'] . ' ' . $value['last_name'];
                 }
             } elseif (!empty($value['contact_id'])) {
                 $contactID = $value['contact_id'];
             } else {
                 $contactID = $this->getContactID();
             }
             CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields, $this);
             //for free event or additional participant, dont create billing email address.
             if (empty($value['is_primary']) || !$this->_values['event']['is_monetary']) {
                 unset($value["email-{$this->_bltID}"]);
             }
             $contactID = CRM_Event_Form_Registration_Confirm::updateContactFields($contactID, $value, $fields, $this);
             // lets store the contactID in the session
             // we dont store in userID in case the user is doing multiple
             // transactions etc
             // for things like tell a friend
             if (!$this->getContactID() && !empty($value['is_primary'])) {
                 $session->set('transaction.userID', $contactID);
             }
             //lets get the status if require approval or waiting.
             $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
             if ($this->_allowWaitlist && !$this->_allowConfirmation) {
                 $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses);
             } elseif ($this->_requireApproval && !$this->_allowConfirmation) {
                 $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses);
             }
             $this->set('value', $value);
             $this->confirmPostProcess($contactID, NULL, NULL);
             //lets get additional participant id to cancel.
             if ($this->_allowConfirmation && is_array($cancelledIds)) {
                 $additonalId = CRM_Utils_Array::value('participant_id', $value);
                 if ($additonalId && ($key = array_search($additonalId, $cancelledIds))) {
                     unset($cancelledIds[$key]);
                 }
             }
         }
     }
     // update status and send mail to cancelled additional participants, CRM-4320
     if ($this->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) {
         $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
         CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId);
     }
     //set information about additional participants if exists
     if (count($this->_participantInfo)) {
         $this->set('participantInfo', $this->_participantInfo);
     }
     //send mail Confirmation/Receipt
     if ($this->_contributeMode != 'checkout' || $this->_contributeMode != 'notify') {
         $isTest = FALSE;
         if ($this->_action & CRM_Core_Action::PREVIEW) {
             $isTest = TRUE;
         }
         //handle if no additional participant.
         if (!$registerByID) {
             $registerByID = $this->get('registerByID');
         }
         $primaryContactId = $this->get('primaryContactId');
         //build an array of custom profile and assigning it to template.
         $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL, $primaryContactId, $isTest, TRUE);
         //lets carry all participant params w/ values.
         foreach ($additionalIDs as $participantID => $contactId) {
             $participantNum = NULL;
             if ($participantID == $registerByID) {
                 $participantNum = 0;
             } else {
                 if ($participantNum = array_search('participant', $participantCount)) {
                     unset($participantCount[$participantNum]);
                 }
             }
             if ($participantNum === NULL) {
                 break;
             }
             //carry the participant submitted values.
             $this->_values['params'][$participantID] = $params[$participantNum];
         }
         //lets send  mails to all with meanigful text, CRM-4320.
         $this->assign('isOnWaitlist', $this->_allowWaitlist);
         $this->assign('isRequireApproval', $this->_requireApproval);
         foreach ($additionalIDs as $participantID => $contactId) {
             if ($participantID == $registerByID) {
                 //set as Primary Participant
                 $this->assign('isPrimary', 1);
                 $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $this->_values, NULL, $isTest);
                 if (count($customProfile)) {
                     $this->assign('customProfile', $customProfile);
                     $this->set('customProfile', $customProfile);
                 }
             } else {
                 $this->assign('isPrimary', 0);
                 $this->assign('customProfile', NULL);
             }
             //send Confirmation mail to Primary & additional Participants if exists
             CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest);
         }
     }
 }
Beispiel #3
0
 public function processRegistration($params, $contactID = null)
 {
     $session =& CRM_Core_Session::singleton();
     $contactID = $session->get('userID');
     $this->_participantInfo = array();
     // CRM-4320, lets build array of cancelled additional participant ids
     // those are drop or skip by primary at the time of confirmation.
     // get all in and then unset those are confirmed.
     $cancelledIds = $this->_additionalParticipantIds;
     foreach ($params as $key => $value) {
         if ($value != 'skip') {
             $fields = null;
             // setting register by Id and unset contactId.
             if (!CRM_Utils_Array::value('is_primary', $value)) {
                 $contactID = null;
                 $registerByID = $this->get('registerByID');
                 if ($registerByID) {
                     $value['registered_by_id'] = $registerByID;
                 }
                 if (CRM_Utils_Array::value("email-{$this->_bltID}", $value)) {
                     $this->_participantInfo[] = $value["email-{$this->_bltID}"];
                 } else {
                     $this->_participantInfo[] = $value['first_name'] . ' ' . $value['last_name'];
                 }
             }
             require_once 'CRM/Event/Form/Registration/Confirm.php';
             CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields);
             //for free event or additional participant, dont create billing email address.
             if (!CRM_Utils_Array::value('is_primary', $value) || !$this->_values['event']['is_monetary']) {
                 unset($value["email-{$this->_bltID}"]);
             }
             $contactID =& CRM_Event_Form_Registration_Confirm::updateContactFields($contactID, $value, $fields);
             // lets store the contactID in the session
             // we dont store in userID in case the user is doing multiple
             // transactions etc
             // for things like tell a friend
             if (!$session->get('userID') && CRM_Utils_Array::value('is_primary', $value)) {
                 $session->set('transaction.userID', $contactID);
             }
             //lets get the status if require approval or waiting.
             require_once 'CRM/Event/PseudoConstant.php';
             $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(null, "class = 'Waiting'");
             if ($this->_allowWaitlist && !$this->_allowConfirmation) {
                 $value['participant_status_id'] = array_search('On waitlist', $waitingStatuses);
             } else {
                 if ($this->_requireApproval && !$this->_allowConfirmation) {
                     $value['participant_status_id'] = array_search('Awaiting approval', $waitingStatuses);
                 }
             }
             $this->set('value', $value);
             $this->confirmPostProcess($contactID, null, null);
             //lets get additional participant id to cancel.
             if ($this->_allowConfirmation && is_array($cancelledIds)) {
                 $additonalId = CRM_Utils_Array::value('participant_id', $value);
                 if ($additonalId && ($key = array_search($additonalId, $cancelledIds))) {
                     unset($cancelledIds[$key]);
                 }
             }
         }
     }
     // update status and send mail to cancelled additonal participants, CRM-4320
     if ($this->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) {
         require_once 'CRM/Event/BAO/Participant.php';
         require_once 'CRM/Event/PseudoConstant.php';
         $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(null, "class = 'Negative'"));
         CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId);
     }
     //set information about additional participants if exists
     if (count($this->_participantInfo)) {
         $this->set('participantInfo', $this->_participantInfo);
     }
     //send mail Confirmation/Receipt
     require_once "CRM/Event/BAO/Event.php";
     if ($this->_contributeMode != 'checkout' || $this->_contributeMode != 'notify') {
         $isTest = false;
         if ($this->_action & CRM_Core_Action::PREVIEW) {
             $isTest = true;
         }
         //handle if no additional participant.
         if (!$registerByID) {
             $registerByID = $this->get('registerByID');
         }
         $primaryContactId = $this->get('primaryContactId');
         //build an array of custom profile and assigning it to template.
         $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, null, $primaryContactId, $isTest, true);
         //lets send  mails to all with meanigful text, CRM-4320.
         $this->assign('isOnWaitlist', $this->_allowWaitlist);
         $this->assign('isRequireApproval', $this->_requireApproval);
         foreach ($additionalIDs as $participantID => $contactId) {
             if ($participantID == $registerByID) {
                 //set as Primary Participant
                 $this->assign('isPrimary', 1);
                 $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $this->_values, null, $isTest);
                 if (count($customProfile)) {
                     $this->assign('customProfile', $customProfile);
                     $this->set('customProfile', $customProfile);
                 }
             } else {
                 $this->assign('isPrimary', 0);
                 $this->assign('customProfile', null);
             }
             //send Confirmation mail to Primary & additional Participants if exists
             CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest);
         }
     }
 }