Merge pull request #5336 from colemanw/recurringFix
[civicrm-core.git] / CRM / Event / Form / Participant.php
index 9a393994026eba0da8155c10a1529755387bf93d..7b6a868fec6591f452da51632ac945f4743dbd2a 100644 (file)
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -43,14 +43,14 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   public $useLivePageJS = TRUE;
 
   /**
-   * The values for the contribution db object
+   * The values for the contribution db object.
    *
    * @var array
    */
   public $_values;
 
   /**
-   * The values for the quickconfig for priceset
+   * The values for the quickconfig for priceset.
    *
    * @var boolean
    */
@@ -64,35 +64,35 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   public $_priceSetId;
 
   /**
-   * Array of fields for the price set
+   * Array of fields for the price set.
    *
    * @var array
    */
   public $_priceSet;
 
   /**
-   * The id of the participation that we are proceessing
+   * The id of the participation that we are proceessing.
    *
    * @var int
    */
   public $_id;
 
   /**
-   * The id of the note
+   * The id of the note.
    *
    * @var int
    */
   protected $_noteId = NULL;
 
   /**
-   * The id of the contact associated with this participation
+   * The id of the contact associated with this participation.
    *
    * @var int
    */
   public $_contactId;
 
   /**
-   * Array of event values
+   * Array of event values.
    *
    * @var array
    */
@@ -107,52 +107,52 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   public $_single = FALSE;
 
   /**
-   * If event is paid or unpaid
+   * If event is paid or unpaid.
    */
   public $_isPaidEvent;
 
   /**
-   * Page action
+   * Page action.
    */
   public $_action;
 
   /**
-   * Role Id
+   * Role Id.
    */
   protected $_roleId = NULL;
 
   /**
-   * Event Type Id
+   * Event Type Id.
    */
   protected $_eventTypeId = NULL;
 
   /**
-   * Participant status Id
+   * Participant status Id.
    */
   protected $_statusId = NULL;
 
   /**
-   * Cache all the participant statuses
+   * Cache all the participant statuses.
    */
   protected $_participantStatuses;
 
   /**
-   * Participant mode
+   * Participant mode.
    */
   public $_mode = NULL;
 
   /**
-   * Event ID preselect
+   * Event ID preselect.
    */
   public $_eID = NULL;
 
   /**
-   * Line Item for Price Set
+   * Line Item for Price Set.
    */
   public $_lineItem = NULL;
 
   /**
-   * Contribution mode for event registration for offline mode
+   * Contribution mode for event registration for offline mode.
    */
   public $_contributeMode = 'direct';
 
@@ -169,12 +169,12 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   protected $_eventNameCustomDataTypeID;
 
   /**
-   * Selected discount id
+   * Selected discount id.
    */
   public $_originalDiscountId = NULL;
 
   /**
-   * Event id
+   * Event id.
    */
   public $_eventId = NULL;
 
@@ -190,7 +190,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   public $_onlinePendingContributionId = NULL;
 
   /**
-   * Set variables up before form is built
+   * Set variables up before form is built.
    *
    * @return void
    */
@@ -290,7 +290,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
           array(
             'title' => ts('CiviEvent Dashboard'),
             'url' => CRM_Utils_System::url('civicrm/event', 'reset=1'),
-          )
+          ),
         );
 
         CRM_Utils_System::appendBreadCrumb($breadCrumbs);
@@ -530,11 +530,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       }
     }
 
-    list($defaults[$this->_id]['register_date'],
-      $defaults[$this->_id]['register_date_time']
-      ) = CRM_Utils_Date::setDateDefaults(
-      CRM_Utils_Array::value('register_date', $defaults[$this->_id]), 'activityDateTime'
-    );
+    list($defaults[$this->_id]['register_date'], $defaults[$this->_id]['register_date_time'])
+      = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('register_date', $defaults[$this->_id]), 'activityDateTime');
 
     //assign event and role id, this is needed for Custom data building
     $sep = CRM_Core_DAO::VALUE_SEPARATOR;
@@ -584,7 +581,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   }
 
   /**
-   * Build the form object
+   * Build the form object.
    *
    * @return void
    */
@@ -643,7 +640,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
     if ($this->_single && $this->_context == 'standalone') {
       $this->addEntityRef('contact_id', ts('Contact'), array(
           'create' => TRUE,
-          'api' => array('extra' => array('email'))
+          'api' => array('extra' => array('email')),
         ), TRUE);
     }
 
@@ -703,8 +700,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
         CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
       );
       $checkCancelledJs = array(
-        'onchange' =>
-          "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
+        'onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
       );
 
       $participantStatusId = array_search('Pending from pay later',
@@ -742,7 +738,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
 
     $this->addSelect('status_id', $checkCancelledJs + array(
         'options' => $statusOptions,
-        'option_url' => 'civicrm/admin/participant_status'
+        'option_url' => 'civicrm/admin/participant_status',
       ), TRUE);
 
     $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
@@ -784,7 +780,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   }
 
   /**
-   * Add local and global form rules
+   * Add local and global form rules.
    *
    *
    * @return void
@@ -794,7 +790,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   }
 
   /**
-   * Global validation rules for the form
+   * Global validation rules for the form.
    *
    * @param array $values
    *   Posted values of the form.
@@ -818,8 +814,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
     $errorMsg = array();
 
     if (!empty($values['payment_processor_id'])) {
-      // make sure that credit card number and cvv are valid
-      CRM_Core_Payment_Form::validateCreditCard($values, $errorMsg);
+      // make sure that payment instrument values (e.g. credit card number and cvv) are valid
+      CRM_Core_Payment_Form::validatePaymentInstrument($values['payment_processor_id'], $values, $errorMsg, $self);
     }
 
     if (!empty($values['record_contribution'])) {
@@ -857,7 +853,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       $contactId = $self->_contactId;
       $eventId = CRM_Utils_Array::value('event_id', $values);
       if (!empty($contactId) && !empty($eventId)) {
-        $dupeCheck = new CRM_Event_BAO_Participant;
+        $dupeCheck = new CRM_Event_BAO_Participant();
         $dupeCheck->contact_id = $contactId;
         $dupeCheck->event_id = $eventId;
         $dupeCheck->find(TRUE);
@@ -870,7 +866,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   }
 
   /**
-   * Process the form submission
+   * Process the form submission.
    */
   public function postProcess() {
     // get the submitted form values.
@@ -907,7 +903,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
         $duplicateContacts = 0;
         while (list($k, $dupeCheckContactId) = each($this->_contactIds)) {
           // Eliminate contacts that have already been assigned to this event.
-          $dupeCheck = new CRM_Event_BAO_Participant;
+          $dupeCheck = new CRM_Event_BAO_Participant();
           $dupeCheck->contact_id = $dupeCheckContactId;
           $dupeCheck->event_id = $event_id;
           $dupeCheck->find(TRUE);
@@ -1078,8 +1074,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
         CRM_Core_Error::fatal(ts('Selected Event is not Paid Event '));
       }
 
-      $eventTitle =
-        CRM_Core_DAO::getFieldValue(
+      $eventTitle
+        CRM_Core_DAO::getFieldValue(
           'CRM_Event_DAO_Event',
           $params['event_id'],
           'title'
@@ -1089,7 +1085,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       if (empty($params['source'])) {
         $this->_params['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(
             1 => $userName,
-            2 => $eventTitle
+            2 => $eventTitle,
           ));
       }
       else {
@@ -1115,8 +1111,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       }
 
       // also add location name to the array
-      $params["address_name-{$this->_bltID}"] =
-        CRM_Utils_Array::value('billing_first_name', $params) . ' ' .
+      $params["address_name-{$this->_bltID}"]
+        CRM_Utils_Array::value('billing_first_name', $params) . ' ' .
         CRM_Utils_Array::value('billing_middle_name', $params) . ' ' .
         CRM_Utils_Array::value('billing_last_name', $params);
 
@@ -1228,8 +1224,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       );
 
       //add contribution record
-      $this->_params['financial_type_id'] =
-        CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
+      $this->_params['financial_type_id']
+        CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
       $this->_params['mode'] = $this->_mode;
 
       //add contribution reocord
@@ -1322,7 +1318,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
           if (empty($params['source'])) {
             $contributionParams['source'] = ts('%1 : Offline registration (by %2)', array(
                 1 => $eventTitle,
-                2 => $userName
+                2 => $userName,
               ));
           }
           else {
@@ -1776,4 +1772,5 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       ));
     }
   }
+
 }