Exemplo n.º 1
0
 /** 
  * global form rule 
  * 
  * @param array $fields  the input form values 
  * @param array $files   the uploaded files if any 
  * @param array $options additional user data 
  * 
  * @return true if no errors, else array of errors 
  * @access public 
  * @static 
  */
 static function formRule(&$fields, &$files, &$self)
 {
     $errors = array();
     //get the button name.
     $button = substr($self->controller->getButtonName(), -4);
     if ($button != 'skip') {
         //Additional Participant can also register for an event only once
         require_once 'CRM/Event/Form/Registration/Register.php';
         $isRegistered = CRM_Event_Form_Registration_Register::checkRegistration($fields, $self, true);
         if ($isRegistered) {
             $errors["email-{$self->_bltID}"] = ts('A person with this email address is already registered for this event.');
         }
         //get the complete params.
         $params = $self->get('params');
         //take the participant instance.
         $addParticipantNum = substr($self->_name, 12);
         if (is_array($params) && $self->_values['event']['allow_same_participant_emails'] != 1) {
             foreach ($params as $key => $value) {
                 if ($value["email-{$self->_bltID}"] == $fields["email-{$self->_bltID}"] && $key != $addParticipantNum) {
                     $errors["email-{$self->_bltID}"] = ts('The email address must be unique for each participant.');
                     break;
                 }
             }
         }
         //check for atleast one pricefields should be selected
         if (CRM_Utils_Array::value('priceSetId', $fields)) {
             $priceField = new CRM_Price_DAO_Field();
             $priceField->price_set_id = $fields['priceSetId'];
             $priceField->find();
             $check = array();
             while ($priceField->fetch()) {
                 if (!empty($fields["price_{$priceField->id}"])) {
                     $check[] = $priceField->id;
                 }
             }
             if (empty($check)) {
                 $errors['_qf_default'] = ts("Select at least one option from Event Fee(s).");
             }
         }
     }
     return $errors;
 }
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     //get the button name.
     $button = substr($this->controller->getButtonName(), -4);
     //take the participant instance.
     $addParticipantNum = substr($this->_name, 12);
     //user submitted params.
     $params = $this->controller->exportValues($this->_name);
     if (!$this->_allowConfirmation) {
         // check if the participant is already registered
         $params['contact_id'] = CRM_Event_Form_Registration_Register::checkRegistration($params, $this, TRUE, TRUE);
     }
     //carry campaign to partcipants.
     if (array_key_exists('participant_campaign_id', $params)) {
         $params['campaign_id'] = $params['participant_campaign_id'];
     } else {
         $params['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
     }
     // if waiting is enabled
     if (!$this->_allowConfirmation && is_numeric($this->_availableRegistrations)) {
         $this->_allowWaitlist = FALSE;
         //get the current page count.
         $currentCount = self::getParticipantCount($this, $params);
         if ($button == 'skip') {
             $currentCount = 'skip';
         }
         //get the total count.
         $previousCount = self::getParticipantCount($this, $this->_params, TRUE);
         $totalParticipants = $previousCount;
         if (is_numeric($currentCount)) {
             $totalParticipants += $currentCount;
         }
         if (!empty($this->_values['event']['has_waitlist']) && $totalParticipants > $this->_availableRegistrations) {
             $this->_allowWaitlist = TRUE;
         }
         $this->set('allowWaitlist', $this->_allowWaitlist);
         $this->_lineItemParticipantsCount[$addParticipantNum] = $currentCount;
     }
     if ($button == 'skip') {
         //hack for free/zero amount event.
         if ($this->_resetAllowWaitlist) {
             $this->_allowWaitlist = FALSE;
             $this->set('allowWaitlist', FALSE);
             if ($this->_requireApproval) {
                 $status = ts("You have skipped last participant and which result into event having enough spaces, but your registration require approval, Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process.");
             } else {
                 $status = ts("You have skipped last participant and which result into event having enough spaces, hence your group become as register participants though you selected on wait list.");
             }
             CRM_Core_Session::setStatus($status);
         }
         $this->_params[$addParticipantNum] = 'skip';
         if (isset($this->_lineItem)) {
             $this->_lineItem[$addParticipantNum] = 'skip';
             $this->_lineItemParticipantsCount[$addParticipantNum] = 'skip';
         }
     } else {
         $config = CRM_Core_Config::singleton();
         $params['currencyID'] = $config->defaultCurrency;
         if ($this->_values['event']['is_monetary']) {
             //added for discount
             $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
             if (!empty($this->_values['discount'][$discountId])) {
                 $params['discount_id'] = $discountId;
                 $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
                 $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
             } elseif (empty($params['priceSetId'])) {
                 $params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
                 $params['amount'] = $this->_values['fee'][$params['amount']]['value'];
             } else {
                 $lineItem = array();
                 CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem);
                 //build line item array..
                 //if requireApproval/waitlist is enabled we hide fees for primary participant
                 // (and not for additional participant which might be is a bug)
                 //lineItem are not correctly build for primary participant
                 //this results in redundancy since now lineItems for additional participant will be build against primary participantNum
                 //therefore lineItems must always be build against current participant No
                 $this->_lineItem[$addParticipantNum] = $lineItem;
             }
         }
         if (array_key_exists('participant_role', $params)) {
             $params['participant_role_id'] = $params['participant_role'];
         }
         if (empty($params['participant_role_id']) && $this->_values['event']['default_role_id']) {
             $params['participant_role_id'] = $this->_values['event']['default_role_id'];
         }
         if (!empty($this->_params[0]['is_pay_later'])) {
             $params['is_pay_later'] = 1;
         }
         //carry additional participant id, contact id if pre-registered.
         if ($this->_allowConfirmation && $this->_additionalParticipantId) {
             $params['contact_id'] = $this->_contactId;
             $params['participant_id'] = $this->_additionalParticipantId;
         }
         //build the params array.
         $this->_params[$addParticipantNum] = $params;
     }
     //finally set the params.
     $this->set('params', $this->_params);
     //set the line item.
     if ($this->_lineItem) {
         $this->set('lineItem', $this->_lineItem);
         $this->set('lineItemParticipantsCount', $this->_lineItemParticipantsCount);
     }
     $participantNo = count($this->_params);
     if ($button != 'skip') {
         $statusMsg = ts('Registration information for participant %1 has been saved.', array(1 => $participantNo));
         CRM_Core_Session::setStatus($statusMsg, ts('Registration Saved'), 'success');
     }
     // Check whether to process the registration now, calling processRegistration()
     if (!$this->_values['event']['is_confirm_enabled'] && !$this->_values['event']['is_monetary'] && CRM_Utils_Array::value('additional_participants', $this->_params[0]) && $this->isLastParticipant()) {
         CRM_Event_Form_Registration_Register::processRegistration($this->_params, NULL);
     }
 }
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     //get the button name.
     $button = substr($this->controller->getButtonName(), -4);
     //take the participant instance.
     $addParticipantNum = substr($this->_name, 12);
     //user submitted params.
     $params = $this->controller->exportValues($this->_name);
     if (!$this->_allowConfirmation) {
         // check if the participant is already registered
         $params['contact_id'] = CRM_Event_Form_Registration_Register::checkRegistration($params, $this, true, true);
     }
     // if waiting is enabled
     if (!$this->_allowConfirmation && is_numeric($this->_availableRegistrations)) {
         $this->_allowWaitlist = false;
         //get the current page count.
         $currentCount = self::getParticipantCount($this, $params);
         if ($button == 'skip') {
             $currentCount = 'skip';
         }
         //get the total count.
         $previousCount = self::getParticipantCount($this, $this->_params, true);
         $totalParticipants = $previousCount;
         if (is_numeric($currentCount)) {
             $totalParticipants += $currentCount;
         }
         if (CRM_Utils_Array::value('has_waitlist', $this->_values['event']) && $totalParticipants > $this->_availableRegistrations) {
             $this->_allowWaitlist = true;
         }
         $this->set('allowWaitlist', $this->_allowWaitlist);
         $this->_lineItemParticipantsCount[$addParticipantNum] = $currentCount;
     }
     if ($button == 'skip') {
         //hack for free/zero amount event.
         if ($this->_resetAllowWaitlist) {
             $this->_allowWaitlist = false;
             $this->set('allowWaitlist', false);
             if ($this->_requireApproval) {
                 $status = ts("You have skipped last participant and which result into event having enough spaces, but your registration require approval, Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process.");
             } else {
                 $status = ts("You have skipped last participant and which result into event having enough spaces, hence your group become as register participants though you selected on wait list.");
             }
             CRM_Core_Session::setStatus($status);
         }
         $this->_params[$addParticipantNum] = 'skip';
         if (isset($this->_lineItem)) {
             $this->_lineItem[$addParticipantNum] = 'skip';
             $this->_lineItemParticipantsCount[$addParticipantNum] = 'skip';
         }
     } else {
         $config = CRM_Core_Config::singleton();
         $params['currencyID'] = $config->defaultCurrency;
         if ($this->_values['event']['is_monetary']) {
             //added for discount
             require_once 'CRM/Core/BAO/Discount.php';
             $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
             if (!empty($this->_values['discount'][$discountId])) {
                 $params['discount_id'] = $discountId;
                 $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
                 $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
             } else {
                 if (empty($params['priceSetId'])) {
                     $params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
                     $params['amount'] = $this->_values['fee'][$params['amount']]['value'];
                 } else {
                     $lineItem = array();
                     require_once 'CRM/Price/BAO/Set.php';
                     CRM_Price_BAO_Set::processAmount($this->_values['fee'], $params, $lineItem);
                     //build the line item..
                     if (array_key_exists($addParticipantNum, $this->_lineItem)) {
                         $this->_lineItem[$addParticipantNum] = $lineItem;
                     } else {
                         $this->_lineItem[] = $lineItem;
                     }
                 }
             }
         }
         if (!CRM_Utils_Array::value('participant_role_id', $params) && $this->_values['event']['default_role_id']) {
             $params['participant_role_id'] = $this->_values['event']['default_role_id'];
         }
         if (CRM_Utils_Array::value('is_pay_later', $this->_params[0])) {
             $params['is_pay_later'] = 1;
         }
         //carry additional participant id, contact id if pre-registered.
         if ($this->_allowConfirmation && $this->_additionalParticipantId) {
             $params['contact_id'] = $this->_contactId;
             $params['participant_id'] = $this->_additionalParticipantId;
         }
         //build the params array.
         if (array_key_exists($addParticipantNum, $this->_params)) {
             $this->_params[$addParticipantNum] = $params;
         } else {
             $this->_params[] = $params;
         }
     }
     //finally set the params.
     $this->set('params', $this->_params);
     //set the line item.
     if ($this->_lineItem) {
         $this->set('lineItem', $this->_lineItem);
         $this->set('lineItemParticipantsCount', $this->_lineItemParticipantsCount);
     }
     $participantNo = count($this->_params);
     if ($button != 'skip') {
         require_once "CRM/Core/Session.php";
         $statusMsg = ts('Registration information for participant %1 has been saved.', array(1 => $participantNo));
         CRM_Core_Session::setStatus("{$statusMsg}");
     }
     //to check whether call processRegistration()
     if (!$this->_values['event']['is_monetary'] && CRM_Utils_Array::value('additional_participants', $this->_params[0]) && $this->isLastParticipant()) {
         require_once 'CRM/Event/Form/Registration/Register.php';
         CRM_Event_Form_Registration_Register::processRegistration($this->_params, null);
     }
 }