code cleanup
[civicrm-core.git] / CRM / Event / Form / Registration.php
index efd2bf879a3032f753f802e0605cc1ef4539d126..d5afd4e341737fa46de05ae4f1de47065bbbd969 100644 (file)
@@ -46,13 +46,12 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * @var int
    * @const
    */
-  CONST LOCATION_BLOCKS = 1;
+  const LOCATION_BLOCKS = 1;
 
   /**
    * The id of the event we are proceessing
    *
    * @var int
-   * @protected
    */
   public $_eventId;
 
@@ -60,7 +59,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * The array of ids of all the participant we are proceessing
    *
    * @var int
-   * @protected
    */
   protected $_participantIDS = NULL;
 
@@ -68,7 +66,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * The id of the participant we are proceessing
    *
    * @var int
-   * @protected
    */
   protected $_participantId;
 
@@ -76,7 +73,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * Is participant able to walk registration wizard.
    *
    * @var Boolean
-   * @protected
    */
   public $_allowConfirmation;
 
@@ -84,7 +80,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * Is participant requires approval
    *
    * @var Boolean
-   * @public
    */
   public $_requireApproval;
 
@@ -92,7 +87,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * Is event configured for waitlist.
    *
    * @var Boolean
-   * @public
    */
   public $_allowWaitlist;
 
@@ -101,7 +95,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * when there are pre-registered.
    *
    * @var array
-   * @public
    */
   public $_additionalParticipantIds;
 
@@ -117,7 +110,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * The values for the contribution db object
    *
    * @var array
-   * @protected
    */
   public $_values;
 
@@ -125,7 +117,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * The paymentProcessor attributes for this page
    *
    * @var array
-   * @protected
    */
   public $_paymentProcessor;
 
@@ -133,7 +124,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * The params submitted by the form and computed by the app
    *
    * @var array
-   * @protected
    */
   protected $_params;
 
@@ -141,7 +131,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * The fields involved in this contribution page
    *
    * @var array
-   * @protected
    */
   public $_fields;
 
@@ -149,7 +138,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * The billing location id for this contribiution page
    *
    * @var int
-   * @protected
    */
   public $_bltID;
 
@@ -157,7 +145,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * Price Set ID, if the new price set method is used
    *
    * @var int
-   * @protected
    */
   public $_priceSetId = NULL;
 
@@ -165,7 +152,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * Array of fields for the price set
    *
    * @var array
-   * @protected
    */
   public $_priceSet;
 
@@ -176,7 +162,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
   /* Is event already full.
      *
      * @var boolean
-     * @protected
      */
 
   public $_isEventFull;
@@ -193,9 +178,8 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * Set variables up before form is built
    *
    * @return void
-   * @access public
    */
-  function preProcess() {
+  public function preProcess() {
     $this->_eventId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
 
@@ -362,7 +346,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
       );
       list($this->_values['custom_pre_id'],
         $this->_values['custom_post_id']
-      ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
+        ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
 
       // set profiles for additional participants
       if ($this->_values['event']['is_multiple_registrations']) {
@@ -371,7 +355,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
 
         list($this->_values['additional_custom_pre_id'],
           $this->_values['additional_custom_post_id'], $preActive, $postActive
-        ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
+          ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
 
         // CRM-4377: we need to maintain backward compatibility, hence if there is profile for main contact
         // set same profile for additional contacts.
@@ -445,8 +429,8 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
     // Handle PCP
     $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this);
     if ($pcpId) {
-      $pcp             = CRM_PCP_BAO_PCP::handlePcp($pcpId, 'event', $this->_values['event']);
-      $this->_pcpId    = $pcp['pcpId'];
+      $pcp = CRM_PCP_BAO_PCP::handlePcp($pcpId, 'event', $this->_values['event']);
+      $this->_pcpId = $pcp['pcpId'];
       $this->_values['event']['intro_text'] = CRM_Utils_Array::value('intro_text', $pcp['pcpInfo']);
     }
 
@@ -478,9 +462,8 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * Assign the minimal set of variables to the template
    *
    * @return void
-   * @access public
    */
-  function assignToTemplate() {
+  public function assignToTemplate() {
     //process only primary participant params
     $this->_params = $this->get('params');
     if (isset($this->_params[0])) {
@@ -502,8 +485,12 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
     $this->set('name', $name);
 
     $vars = array(
-      'amount', 'currencyID', 'credit_card_type',
-      'trxn_id', 'amount_level', 'receive_date',
+      'amount',
+      'currencyID',
+      'credit_card_type',
+      'trxn_id',
+      'amount_level',
+      'receive_date',
     );
 
     foreach ($vars as $v) {
@@ -578,13 +565,12 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * @param bool $viewOnly
    *
    * @return void
-   * @access public
    */
-  function buildCustom($id, $name, $viewOnly = FALSE) {
+  public function buildCustom($id, $name, $viewOnly = FALSE) {
     if ($id) {
-      $button    = substr($this->controller->getButtonName(), -4);
-      $cid       = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
-      $session   = CRM_Core_Session::singleton();
+      $button = substr($this->controller->getButtonName(), -4);
+      $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
+      $session = CRM_Core_Session::singleton();
       $contactID = $session->get('userID');
 
       // we don't allow conflicting fields to be
@@ -655,7 +641,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
             $field['is_required'] = FALSE;
           }
           // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
-          elseif ($field['add_captcha']  && !$contactID) {
+          elseif ($field['add_captcha'] && !$contactID) {
             // only add captcha for first page
             $addCaptcha = TRUE;
           }
@@ -680,7 +666,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    *
    * @throws Exception
    */
-  static function initEventFee(&$form, $eventID) {
+  public static function initEventFee(&$form, $eventID) {
     // get price info
 
     // retrive all active price set fields.
@@ -697,9 +683,10 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
     }
 
     if (property_exists($form, '_context') && ($form->_context == 'standalone'
-      || $form->_context == 'participant')) {
+        || $form->_context == 'participant')
+    ) {
       $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($eventID, 'civicrm_event');
-      if (is_array( $discountedEvent)) {
+      if (is_array($discountedEvent)) {
         foreach ($discountedEvent as $key => $priceSetId) {
           $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId);
           $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
@@ -740,9 +727,8 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * @param null $payment
    *
    * @return void
-   * @access public
    */
-  function confirmPostProcess($contactID = NULL, $contribution = NULL, $payment = NULL) {
+  public function confirmPostProcess($contactID = NULL, $contribution = NULL, $payment = NULL) {
     // add/update contact information
     $fields = array();
     unset($this->_params['note']);
@@ -809,8 +795,9 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
       $this->_params['contactID'] = $contactID;
 
       if (array_key_exists('email-5', $this->_params)) {
-      $mail = 'email-5';
-      } else {
+        $mail = 'email-5';
+      }
+      else {
         foreach ($this->_params as $name => $dontCare) {
           if (substr($name, 0, 5) == 'email') {
             $mail = $name;
@@ -825,7 +812,8 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
       // 3. waiting list participant.
       // 4. require approval participant.
       if (!empty($this->_params['is_pay_later']) ||
-        $this->_allowWaitlist || $this->_requireApproval || empty($this->_values['event']['is_monetary'])) {
+        $this->_allowWaitlist || $this->_requireApproval || empty($this->_values['event']['is_monetary'])
+      ) {
         $mail = 'email-Primary';
       }
 
@@ -838,11 +826,9 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
   /**
    * Process the participant
    *
-   * @param array $params
+   * @param CRM_Core_Form $form
    * @param int $contactID
-   *
-   * @return void
-   * @access public
+   * @return \CRM_Event_BAO_Participant
    */
   public static function addParticipant(&$form, $contactID) {
     if (empty($form->_params)) {
@@ -881,7 +867,8 @@ WHERE  v.option_group_id = g.id
     }
 
     $participantFields = CRM_Event_DAO_Participant::fields();
-    $participantParams = array('id' => CRM_Utils_Array::value('participant_id', $params),
+    $participantParams = array(
+      'id' => CRM_Utils_Array::value('participant_id', $params),
       'contact_id' => $contactID,
       'event_id' => $form->_eventId ? $form->_eventId : $params['event_id'],
       'status_id' => CRM_Utils_Array::value('participant_status',
@@ -944,10 +931,10 @@ WHERE  v.option_group_id = g.id
 
   /* Calculate the total participant count as per params.
    *
-   * @param  array $params user params.
+   * @param array $params
+   *   User params.
    *
    * @return $totalCount total participant count.
-   * @access public
    */
   /**
    * @param CRM_Core_Form $form
@@ -962,9 +949,9 @@ WHERE  v.option_group_id = g.id
       return $totalCount;
     }
 
-    $priceSetId          = $form->get('priceSetId');
-    $addParticipantNum   = substr($form->_name, 12);
-    $priceSetFields      = $priceSetDetails = array();
+    $priceSetId = $form->get('priceSetId');
+    $addParticipantNum = substr($form->_name, 12);
+    $priceSetFields = $priceSetDetails = array();
     $hasPriceFieldsCount = FALSE;
     if ($priceSetId) {
       $priceSetDetails = $form->get('priceSet');
@@ -1042,11 +1029,12 @@ WHERE  v.option_group_id = g.id
   /* Format user submitted price set params.
    * Convert price set each param as an array.
    *
-   * @param $params an array of user submitted params.
+   * @param array $params
+   *   An array of user submitted params.
    *
    *
-   * @return array $formatted, formatted price set params.
-   * @access public
+   * @return array
+   *   , formatted price set params.
    */
   /**
    * @param CRM_Core_Form $form
@@ -1092,11 +1080,12 @@ WHERE  v.option_group_id = g.id
   /* Calculate total count for each price set options.
    * those are currently selected by user.
    *
-   * @param $form form object.
+   * @param $form
+   *   Form object.
    *
    *
-   * @return array $optionsCount, array of each option w/ count total.
-   * @access public
+   * @return array
+   *   , array of each option w/ count total.
    */
   /**
    * @param $form
@@ -1104,8 +1093,8 @@ WHERE  v.option_group_id = g.id
    * @return array
    */
   public static function getPriceSetOptionCount(&$form) {
-    $params     = $form->get('params');
-    $priceSet   = $form->get('priceSet');
+    $params = $form->get('params');
+    $priceSet = $form->get('priceSet');
     $priceSetId = $form->get('priceSetId');
 
     $optionsCount = array();
@@ -1130,7 +1119,7 @@ WHERE  v.option_group_id = g.id
     $addParticipantNum = substr($form->_name, 12);
     foreach ($params as $pCnt => $values) {
       if ($values == 'skip' ||
-        $pCnt == $addParticipantNum
+        $pCnt === $addParticipantNum
       ) {
         continue;
       }
@@ -1173,7 +1162,7 @@ WHERE  v.option_group_id = g.id
    *
    * @return null|string
    */
-  function checkTemplateFileExists($suffix = '') {
+  public function checkTemplateFileExists($suffix = '') {
     if ($this->_eventId) {
       $templateName = $this->_name;
       if (substr($templateName, 0, 12) == 'Participant_') {
@@ -1192,7 +1181,7 @@ WHERE  v.option_group_id = g.id
   /**
    * @return null|string
    */
-  function getTemplateFileName() {
+  public function getTemplateFileName() {
     $fileName = $this->checkTemplateFileExists();
     return $fileName ? $fileName : parent::getTemplateFileName();
   }
@@ -1200,7 +1189,7 @@ WHERE  v.option_group_id = g.id
   /**
    * @return null|string
    */
-  function overrideExtraTemplateFileName() {
+  public function overrideExtraTemplateFileName() {
     $fileName = $this->checkTemplateFileExists('extra.');
     return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
   }
@@ -1208,11 +1197,13 @@ WHERE  v.option_group_id = g.id
   /**
    * Validate price set submitted params for price option limit,
    * as well as user should select at least one price field option.
-   * @param unknown_type $form
-   * @param unknown_type $params
-   * @return multitype:|Ambigous <multitype:, string, string>
+   *
+   * @param CRM_Core_Form $form
+   * @param array $params
+   *
+   * @return array
    */
-  static function validatePriceSet(&$form, $params) {
+  public static function validatePriceSet(&$form, $params) {
     $errors = array();
     $hasOptMaxValue = FALSE;
     if (!is_array($params) || empty($params)) {
@@ -1315,6 +1306,7 @@ WHERE  v.option_group_id = g.id
         $opDbCount = CRM_Utils_Array::value('db_total_count', $options[$optId], 0);
         $total += $opDbCount;
         if ($optMax && $total > $optMax) {
+          $errors['soldOutOptions'][] = ts('Option %1 has sold out.', array(1 => $feeBlock[$fieldId]['options'][$optId]['label']));
           if ($opDbCount && ($opDbCount >= $optMax)) {
             $errors[$currentParticipantNum]["price_{$fieldId}"] =
               ts('Sorry, this option is currently sold out.');
@@ -1344,11 +1336,12 @@ WHERE  v.option_group_id = g.id
     return $errors;
   }
 
-  // set the first participant ID if not set, CRM-10032
   /**
+   * set the first participant ID if not set, CRM-10032
+   *
    * @param int $participantID
    */
-  function processFirstParticipant($participantID) {
+  public function processFirstParticipant($participantID) {
     $this->_participantId = $participantID;
     $this->set('participantId', $this->_participantId);
 
@@ -1360,9 +1353,9 @@ WHERE  v.option_group_id = g.id
 
     // also set the allow confirmation stuff
     if (array_key_exists(
-        $this->_values['participant']['status_id'],
-        CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'")
-      )) {
+      $this->_values['participant']['status_id'],
+      CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'")
+    )) {
       $this->_allowConfirmation = TRUE;
       $this->set('allowConfirmation', TRUE);
     }
@@ -1375,7 +1368,7 @@ WHERE  v.option_group_id = g.id
    *
    * @param string $redirect
    */
-  function checkValidEvent($redirect = NULL) {
+  public function checkValidEvent($redirect = NULL) {
     // is the event active (enabled)?
     if (!$this->_values['event']['is_active']) {
       // form is inactive, die a fatal death
@@ -1394,8 +1387,8 @@ WHERE  v.option_group_id = g.id
 
     $now = date('YmdHis');
     $startDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('registration_start_date',
-        $this->_values['event']
-      ));
+      $this->_values['event']
+    ));
 
     if (
       $startDate &&
@@ -1405,8 +1398,8 @@ WHERE  v.option_group_id = g.id
     }
 
     $endDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('registration_end_date',
-        $this->_values['event']
-      ));
+      $this->_values['event']
+    ));
     $eventEndDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('event_end_date', $this->_values['event']));
     if (
       $endDate &&
@@ -1419,4 +1412,3 @@ WHERE  v.option_group_id = g.id
     }
   }
 }
-