Esempio n. 1
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);
         }
     }
 }
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     if (isset($params['field'])) {
         foreach ($params['field'] as $key => $value) {
             //check for custom data
             $value['custom'] = CRM_Core_BAO_CustomField::postProcess($value, CRM_Core_DAO::$_nullObject, $key, 'Participant');
             $value['id'] = $key;
             if (CRM_Utils_Array::value('participant_register_date', $value)) {
                 $value['register_date'] = CRM_Utils_Date::processDate($value['participant_register_date'], $value['participant_register_date_time']);
             }
             if (CRM_Utils_Array::value('participant_role', $value)) {
                 $participantRoles = CRM_Event_PseudoConstant::participantRole();
                 if (is_array($value['participant_role'])) {
                     $value['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($value['participant_role']));
                 } else {
                     $value['role_id'] = $value['participant_role'];
                 }
             }
             //need to send mail when status change
             $statusChange = FALSE;
             if (CRM_Utils_Array::value('participant_status', $value)) {
                 $value['status_id'] = $value['participant_status'];
                 $fromStatusId = CRM_Utils_Array::value($key, $this->_fromStatusIds);
                 if (!$fromStatusId) {
                     $fromStatusId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $key, 'status_id');
                 }
                 if ($fromStatusId != $value['status_id']) {
                     $statusChange = TRUE;
                 }
             }
             if (CRM_Utils_Array::value('participant_source', $value)) {
                 $value['source'] = $value['participant_source'];
             }
             unset($value['participant_register_date']);
             unset($value['participant_status']);
             unset($value['participant_source']);
             CRM_Event_BAO_Participant::create($value);
             //need to trigger mails when we change status
             if ($statusChange) {
                 CRM_Event_BAO_Participant::transitionParticipants(array($key), $value['status_id'], $fromStatusId);
                 //update related contribution status, CRM-4395
                 self::updatePendingOnlineContribution($key, $value['status_id']);
             }
         }
         CRM_Core_Session::setStatus(ts('The updates have been saved.'));
     } else {
         CRM_Core_Session::setStatus(ts('No updates have been saved.'));
     }
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     //get the button.
     $buttonName = $this->controller->getButtonName();
     $participantId = $this->_participantId;
     if ($buttonName == '_qf_ParticipantConfirm_next') {
         //lets get contact id in session.
         $session = CRM_Core_Session::singleton();
         $session->set('userID', $this->_csContactID);
         $this->postProcessHook();
         //check user registration status is from pending class
         $url = CRM_Utils_System::url('civicrm/event/register', "reset=1&id={$this->_eventId}&participantId={$participantId}");
         CRM_Utils_System::redirect($url);
     } elseif ($buttonName == '_qf_ParticipantConfirm_submit') {
         //need to registration status to 'cancelled'.
         $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
         $additionalParticipantIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId);
         $participantIds = array_merge(array($participantId), $additionalParticipantIds);
         $results = CRM_Event_BAO_Participant::transitionParticipants($participantIds, $cancelledId, NULL, TRUE);
         if (count($participantIds) > 1) {
             $statusMessage = ts("%1 Event registration(s) have been cancelled.", array(1 => count($participantIds)));
         } else {
             $statusMessage = ts("Your event registration has been cancelled.");
         }
         if (!empty($results['mailedParticipants'])) {
             foreach ($results['mailedParticipants'] as $key => $displayName) {
                 $statusMessage .= "<br />" . ts("Email has been sent to : %1", array(1 => $displayName));
             }
         }
         $this->postProcessHook();
         CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_eventId}&noFullMsg=1", FALSE, NULL, FALSE, TRUE));
     }
 }
 public function updateParticipantStatus()
 {
     require_once 'CRM/Event/PseudoConstant.php';
     $participantRole = CRM_Event_PseudoConstant::participantRole();
     $pendingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'");
     $expiredStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'");
     $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
     //build the required status ids.
     $statusIds = '(' . implode(',', array_merge(array_keys($pendingStatuses), array_keys($waitingStatuses))) . ')';
     $participantDetails = $fullEvents = array();
     $expiredParticipantCount = $waitingConfirmCount = $waitingApprovalCount = 0;
     //get all participant who's status in class pending and waiting
     $query = "SELECT * FROM civicrm_participant WHERE status_id IN {$statusIds} ORDER BY register_date";
     $query = "\n   SELECT  participant.id,\n           participant.contact_id,\n           participant.status_id,\n           participant.register_date,\n           participant.registered_by_id,\n           participant.event_id,\n           event.title as eventTitle,\n           event.registration_start_date,\n           event.registration_end_date,\n           event.end_date,\n           event.expiration_time,\n           event.requires_approval\n     FROM  civicrm_participant participant\nLEFT JOIN  civicrm_event event ON ( event.id = participant.event_id )\n    WHERE  participant.status_id IN {$statusIds}\n     AND   (event.end_date > now() OR event.end_date IS NULL)\n     AND   event.is_active = 1 \n ORDER BY  participant.register_date, participant.id \n";
     $dao = CRM_Core_DAO::executeQuery($query);
     while ($dao->fetch()) {
         $participantDetails[$dao->id] = array('id' => $dao->id, 'event_id' => $dao->event_id, 'status_id' => $dao->status_id, 'contact_id' => $dao->contact_id, 'register_date' => $dao->register_date, 'registered_by_id' => $dao->registered_by_id, 'eventTitle' => $dao->eventTitle, 'registration_start_date' => $dao->registration_start_date, 'registration_end_date' => $dao->registration_end_date, 'end_date' => $dao->end_date, 'expiration_time' => $dao->expiration_time, 'requires_approval' => $dao->requires_approval);
     }
     if (!empty($participantDetails)) {
         //cron 1. move participant from pending to expire if needed
         foreach ($participantDetails as $participantId => $values) {
             //process the additional participant at the time of
             //primary participant, don't process separately.
             if (CRM_Utils_Array::value('registered_by_id', $values)) {
                 continue;
             }
             $expirationTime = CRM_Utils_Array::value('expiration_time', $values);
             if ($expirationTime && array_key_exists($values['status_id'], $pendingStatuses)) {
                 //get the expiration and registration pending time.
                 $expirationSeconds = $expirationTime * 3600;
                 $registrationPendingSeconds = CRM_Utils_Date::unixTime($values['register_date']);
                 // expired registration since registration cross allow confirmation time.
                 if ($expirationSeconds + $registrationPendingSeconds < time()) {
                     //lets get the transaction mechanism.
                     require_once 'CRM/Core/Transaction.php';
                     $transaction = new CRM_Core_Transaction();
                     require_once 'CRM/Event/BAO/Participant.php';
                     $ids = array($participantId);
                     $expiredId = array_search('Expired', $expiredStatuses);
                     $results = CRM_Event_BAO_Participant::transitionParticipants($ids, $expiredId, $values['status_id'], TRUE, TRUE);
                     $transaction->commit();
                     if (!empty($results)) {
                         //diaplay updated participants
                         if (is_array($results['updatedParticipantIds']) && !empty($results['updatedParticipantIds'])) {
                             foreach ($results['updatedParticipantIds'] as $processedId) {
                                 $expiredParticipantCount += 1;
                                 echo "<br /><br />- status updated to: Expired";
                                 //mailed participants.
                                 if (is_array($results['mailedParticipants']) && array_key_exists($processedId, $results['mailedParticipants'])) {
                                     echo "<br />Expiration Mail sent to: {$results['mailedParticipants'][$processedId]}";
                                 }
                             }
                         }
                     }
                 }
             }
         }
         //cron 1 end.
         //cron 2. lets move participants from waiting list to pending status
         foreach ($participantDetails as $participantId => $values) {
             //process the additional participant at the time of
             //primary participant, don't process separately.
             if (CRM_Utils_Array::value('registered_by_id', $values)) {
                 continue;
             }
             if (array_key_exists($values['status_id'], $waitingStatuses) && !array_key_exists($values['event_id'], $fullEvents)) {
                 if ($waitingStatuses[$values['status_id']] == 'On waitlist' && CRM_Event_BAO_Event::validRegistrationDate($values)) {
                     //check the target event having space.
                     require_once 'CRM/Event/BAO/Participant.php';
                     $eventOpenSpaces = CRM_Event_BAO_Participant::eventFull($values['event_id'], TRUE, FALSE);
                     if ($eventOpenSpaces && is_numeric($eventOpenSpaces) || $eventOpenSpaces === NULL) {
                         //get the additional participant if any.
                         $additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId);
                         $allIds = array($participantId);
                         if (!empty($additionalIds)) {
                             $allIds = array_merge($allIds, $additionalIds);
                         }
                         $pClause = ' participant.id IN ( ' . implode(' , ', $allIds) . ' )';
                         $requiredSpaces = CRM_Event_BAO_Event::eventTotalSeats($values['event_id'], $pClause);
                         //need to check as to see if event has enough speces
                         if ($requiredSpaces <= $eventOpenSpaces || $eventOpenSpaces === NULL) {
                             require_once 'CRM/Core/Transaction.php';
                             $transaction = new CRM_Core_Transaction();
                             require_once 'CRM/Event/BAO/Participant.php';
                             $ids = array($participantId);
                             $updateStatusId = array_search('Pending from waitlist', $pendingStatuses);
                             //lets take a call to make pending or need approval
                             if ($values['requires_approval']) {
                                 $updateStatusId = array_search('Awaiting approval', $waitingStatuses);
                             }
                             $results = CRM_Event_BAO_Participant::transitionParticipants($ids, $updateStatusId, $values['status_id'], TRUE, TRUE);
                             //commit the transaction.
                             $transaction->commit();
                             if (!empty($results)) {
                                 //diaplay updated participants
                                 if (is_array($results['updatedParticipantIds']) && !empty($results['updatedParticipantIds'])) {
                                     foreach ($results['updatedParticipantIds'] as $processedId) {
                                         if ($values['requires_approval']) {
                                             $waitingApprovalCount += 1;
                                             echo "<br /><br />- status updated to: Awaiting approval";
                                             echo "<br />Will send you Confirmation Mail when registration get approved.";
                                         } else {
                                             $waitingConfirmCount += 1;
                                             echo "<br /><br />- status updated to: Pending from waitlist";
                                             if (is_array($results['mailedParticipants']) && array_key_exists($processedId, $results['mailedParticipants'])) {
                                                 echo "<br />Confirmation Mail sent to: {$results['mailedParticipants'][$processedId]}";
                                             }
                                         }
                                     }
                                 }
                             }
                         } else {
                             //target event is full.
                             $fullEvents[$values['event_id']] = $values['eventTitle'];
                         }
                     } else {
                         //target event is full.
                         $fullEvents[$values['event_id']] = $values['eventTitle'];
                     }
                 }
             }
         }
         //cron 2 ends.
     }
     echo "<br /><br />Number of Expired registration(s) = {$expiredParticipantCount}";
     echo "<br />Number of registration(s) require approval =  {$waitingApprovalCount}";
     echo "<br />Number of registration changed to Pending from waitlist = {$waitingConfirmCount}<br /><br />";
     if (!empty($fullEvents)) {
         foreach ($fullEvents as $eventId => $title) {
             echo "Full Event : {$title}<br />";
         }
     }
 }
Esempio n. 5
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);
         }
     }
 }
Esempio n. 6
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     require_once 'CRM/Event/BAO/Participant.php';
     $config =& CRM_Core_Config::singleton();
     $session =& CRM_Core_Session::singleton();
     $contactID = $session->get('userID');
     $now = date('YmdHis');
     $this->_params = $this->get('params');
     // if a discount has been applied, lets now deduct it from the amount
     // and fix the fee level
     if (CRM_Utils_Array::value('discount', $this->_params[0]) && CRM_Utils_Array::value('applied', $this->_params[0]['discount'])) {
         foreach ($this->_params as $k => $v) {
             if (CRM_Utils_Array::value('amount', $this->_params[$k]) > 0 && CRM_Utils_Array::value('discountAmount', $this->_params[$k])) {
                 $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;
     $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';
         } else {
             if ($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;
     foreach ($params as $key => $value) {
         $this->_values['params'] = array();
         $this->fixLocationFields($value, $fields);
         //unset the billing parameters if it is pay later mode
         //to avoid creation of billing location
         if ($this->_allowWaitlist || $this->_requireApproval || CRM_Utils_Array::value('is_pay_later', $value) || !CRM_Utils_Array::value('is_primary', $value)) {
             $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 (CRM_Utils_Array::value('is_pay_later', $value)) {
                 $this->_values['params']['is_pay_later'] = true;
             }
         }
         //Unset ContactID for additional participants and set RegisterBy Id.
         if (!CRM_Utils_Array::value('is_primary', $value)) {
             $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 =& $this->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);
         }
         $value['description'] = ts('Online Event Registration') . ': ' . $this->_values['event']['title'];
         $value['accountingCode'] = CRM_Utils_Array::value('accountingCode', $this->_values['event']);
         // required only if paid event
         if ($this->_values['event']['is_monetary']) {
             require_once 'CRM/Core/Payment.php';
             if (is_array($this->_paymentProcessor)) {
                 $payment =& CRM_Core_Payment::singleton($this->_mode, 'Event', $this->_paymentProcessor, $this);
             }
             $pending = false;
             $result = null;
             require_once 'CRM/Event/PseudoConstant.php';
             if ($this->_allowWaitlist || $this->_requireApproval) {
                 //get the participant statuses.
                 $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(null, "class = 'Waiting'");
                 if ($this->_allowWaitlist) {
                     $value['participant_status_id'] = array_search('On waitlist', $waitingStatuses);
                 } else {
                     $value['participant_status_id'] = 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;
             } else {
                 if (CRM_Utils_Array::value('is_pay_later', $value) || $value['amount'] == 0 || $this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') {
                     if ($value['amount'] != 0) {
                         $pending = true;
                         //get the participant statuses.
                         require_once 'CRM/Event/PseudoConstant.php';
                         $pendingStatuses = CRM_Event_PseudoConstant::participantStatus(null, "class = 'Pending'");
                         $status = CRM_Utils_Array::value('is_pay_later', $value) ? 'Pending from pay later' : 'Pending from incomplete transaction';
                         $value['participant_status_id'] = array_search($status, $pendingStatuses);
                     }
                 } else {
                     if ($this->_contributeMode == 'express' && CRM_Utils_Array::value('is_primary', $value)) {
                         $result =& $payment->doExpressCheckout($value);
                     } else {
                         if (CRM_Utils_Array::value('is_primary', $value)) {
                             require_once 'CRM/Core/Payment/Form.php';
                             CRM_Core_Payment_Form::mapParams($this->_bltID, $value, $value, true);
                             $result =& $payment->doDirectPayment($value);
                         }
                     }
                 }
             }
             if (is_a($result, 'CRM_Core_Error')) {
                 CRM_Core_Error::displaySessionError($result);
                 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}"));
             }
             if ($result) {
                 $value = array_merge($value, $result);
             }
             $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 && CRM_Utils_Array::value('is_primary', $value) && !$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->contribution_type_id;
                 $value['receive_date'] = $contribution->receive_date;
                 $value['trxn_id'] = $contribution->trxn_id;
                 $value['contributionID'] = $contribution->id;
                 $value['contributionTypeID'] = $contribution->contribution_type_id;
             }
             $value['contactID'] = $contactID;
             $value['eventID'] = $this->_eventId;
             $value['item_name'] = $value['description'];
         }
         //CRM-4453.
         if (CRM_Utils_Array::value('is_primary', $value)) {
             $primaryCurrencyID = CRM_Utils_Array::value('currencyID', $value);
         }
         if (!CRM_Utils_Array::value('currencyID', $value)) {
             $value['currencyID'] = $primaryCurrencyID;
         }
         if (!$pending && CRM_Utils_Array::value('is_primary', $value) && !$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'] = $value['amount'];
         $this->set('value', $value);
         // handle register date CRM-4320
         if ($this->_allowConfirmation) {
             $registerDate = $params['participant_register_date'];
         } else {
             if (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');
     }
     // create line items, CRM-5313
     if ($this->_priceSetId && !empty($this->_lineItem)) {
         require_once 'CRM/Price/BAO/LineItem.php';
         // 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';
         foreach ($this->_lineItem as $key => $value) {
             if ($value != 'skip' && ($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);
                 }
                 // create line.
                 foreach ($value as $line) {
                     $line['entity_id'] = $entityId;
                     $line['entity_table'] = $entityTable;
                     CRM_Price_BAO_LineItem::create($line);
                 }
             }
         }
     }
     //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);
     }
     $isTest = false;
     if ($this->_action & CRM_Core_Action::PREVIEW) {
         $isTest = true;
     }
     // for Transfer checkout.
     require_once "CRM/Event/BAO/Event.php";
     if (($this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') && !CRM_Utils_Array::value('is_pay_later', $params[0]) && !$this->_allowWaitlist && !$this->_requireApproval && $this->_totalAmount > 0) {
         $primaryParticipant = $this->get('primaryParticipant');
         if (!CRM_Utils_Array::value('participantID', $primaryParticipant)) {
             $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 && $payment) {
             $payment->doTransferCheckout($primaryParticipant);
         }
     } else {
         //otherwise send mail Confirmation/Receipt
         $primaryContactId = $this->get('primaryContactId');
         //build an array of cId/pId of participants
         require_once "CRM/Event/BAO/Event.php";
         $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);
         foreach ($additionalIDs as $participantID => $contactId) {
             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 ($paticipantNum = array_search('participant', $participantCount)) {
                     unset($participantCount[$paticipantNum]);
                 }
                 $this->assign('isPrimary', 0);
                 $this->assign('customProfile', null);
                 //Additional Participant should get only it's payment information
                 if ($this->_amount) {
                     $amount = array();
                     $params = $this->get('params');
                     $amount[$paticipantNum]['label'] = $params[$paticipantNum]['amount_level'];
                     $amount[$paticipantNum]['amount'] = $params[$paticipantNum]['amount'];
                     $this->assign('amount', $amount);
                 }
                 if ($this->_lineItem) {
                     $lineItems = $this->_lineItem;
                     $lineItem = array();
                     $lineItem[] = CRM_Utils_Array::value($paticipantNum, $lineItems);
                     $this->assign('lineItem', $lineItem);
                 }
                 $this->_values['params']['additionalParticipant'] = true;
             }
             //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);
         }
     }
 }
Esempio n. 7
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);
         }
     }
 }
Esempio n. 8
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     $dates = array('participant_register_date');
     if (isset($params['field'])) {
         foreach ($params['field'] as $key => $value) {
             foreach ($dates as $d) {
                 if (!CRM_Utils_System::isNull($value[$d])) {
                     $value[$d]['H'] = '00';
                     $value[$d]['i'] = '00';
                     $value[$d]['s'] = '00';
                     $value[$d] = CRM_Utils_Date::format($value[$d]);
                 }
             }
             //check for custom data
             $value['custom'] = CRM_Core_BAO_CustomField::postProcess($value, CRM_Core_DAO::$_nullObject, $key, 'Participant');
             $value['id'] = $key;
             if ($value['participant_register_date']) {
                 $value['register_date'] = $value['participant_register_date'];
             }
             if ($value['participant_role_id']) {
                 $value['role_id'] = $value['participant_role_id'];
             }
             //need to send mail when status change
             $statusChange = false;
             if ($value['participant_status_id']) {
                 $value['status_id'] = $value['participant_status_id'];
                 $fromStatusId = CRM_Utils_Array::value($key, $this->_fromStatusIds);
                 if (!$fromStatusId) {
                     $fromStatusId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $key, 'status_id');
                 }
                 if ($fromStatusId != $value['status_id']) {
                     $statusChange = true;
                 }
             }
             if ($value['participant_source']) {
                 $value['source'] = $value['participant_source'];
             }
             unset($value['participant_register_date']);
             unset($value['participant_status_id']);
             unset($value['participant_source']);
             CRM_Event_BAO_Participant::create($value);
             //need to trigger mails when we change status
             if ($statusChange) {
                 CRM_Event_BAO_Participant::transitionParticipants(array($key), $value['status_id'], $fromStatusId);
                 //update related contribution status, CRM-4395
                 self::updatePendingOnlineContribution($key, $value['status_id']);
             }
         }
         CRM_Core_Session::setStatus(ts('The updates have been saved.'));
     } else {
         CRM_Core_Session::setStatus(ts('No updates have been saved.'));
     }
 }