Merge branch 4.5 into 4.6
[civicrm-core.git] / CRM / Price / Form / Field.php
index 82b70b392638e488f29da9b1479eb5795309e720..93352c624d891d9224dd9b6b7a13ff3e767af210 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        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -44,7 +44,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
   const NUM_OPTION = 15;
 
   /**
-   * The custom set id saved to the session for an update
+   * The custom set id saved to the session for an update.
    *
    * @var int
    */
@@ -58,29 +58,25 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
   protected $_fid;
 
   /**
-   * The extended component Id
+   * The extended component Id.
    *
    * @var array
    */
   protected $_extendComponentId;
 
   /**
-   * Variable is set if price set is used for membership
+   * Variable is set if price set is used for membership.
    */
   protected $_useForMember;
 
   /**
-   * Set variables up before form is built
-   *
-   * @param null
-   *
-   * @return void
+   * Set variables up before form is built.
    */
   public function preProcess() {
 
     $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this, FALSE, NULL, 'REQUEST');
     $this->_fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE, NULL, 'REQUEST');
-    $url        = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}");
+    $url = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}");
     $breadCrumb = array(array('title' => ts('Price Set Fields'), 'url' => $url));
 
     $this->_extendComponentId = array();
@@ -98,9 +94,8 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
    * Set default values for the form. Note that in edit/view mode
    * the default values are retrieved from the database
    *
-   * @param null
-   *
-   * @return array    array of default values
+   * @return array
+   *   array of default values
    */
   public function setDefaultValues() {
     $defaults = array();
@@ -124,13 +119,13 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
       if (!empty($defaults['active_on'])) {
         list($defaults['active_on'],
           $defaults['active_on_time']
-        ) = CRM_Utils_Date::setDateDefaults($defaults['active_on'], 'activityDateTime');
+          ) = CRM_Utils_Date::setDateDefaults($defaults['active_on'], 'activityDateTime');
       }
 
       if (!empty($defaults['expire_on'])) {
         list($defaults['expire_on'],
           $defaults['expire_on_time']
-        ) = CRM_Utils_Date::setDateDefaults($defaults['expire_on'], 'activityDateTime');
+          ) = CRM_Utils_Date::setDateDefaults($defaults['expire_on'], 'activityDateTime');
       }
     }
     else {
@@ -149,8 +144,8 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
     }
     $enabledComponents = CRM_Core_Component::getEnabledComponents();
     $eventComponentId = NULL;
-    if (array_key_exists('CiviEvent',$enabledComponents)) {
-      $eventComponentId  = CRM_Core_Component::getComponentID('CiviEvent');
+    if (array_key_exists('CiviEvent', $enabledComponents)) {
+      $eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
     }
 
     if (isset($this->_sid) && $this->_action == CRM_Core_Action::ADD) {
@@ -164,11 +159,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
   }
 
   /**
-   * Build the form object
-   *
-   * @param null
-   *
-   * @return void
+   * Build the form object.
    */
   public function buildQuickForm() {
     // lets trim all the whitespace
@@ -196,18 +187,18 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
     }
     $enabledComponents = CRM_Core_Component::getEnabledComponents();
     $eventComponentId = $memberComponentId = NULL;
-    if (array_key_exists('CiviEvent',$enabledComponents)) {
-      $eventComponentId  = CRM_Core_Component::getComponentID('CiviEvent');
+    if (array_key_exists('CiviEvent', $enabledComponents)) {
+      $eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
     }
-    if (array_key_exists('CiviMember',$enabledComponents)) {
+    if (array_key_exists('CiviMember', $enabledComponents)) {
       $memberComponentId = CRM_Core_Component::getComponentID('CiviMember');
     }
 
-    $attributes        = CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceFieldValue');
+    $attributes = CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceFieldValue');
 
     $this->add('select', 'financial_type_id',
       ts('Financial Type'),
-      array(' '=> ts('- select -')) + $financialType
+      array(' ' => ts('- select -')) + $financialType
     );
 
     $this->assign('useForMember', FALSE);
@@ -269,7 +260,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
       //Financial Type
       $this->add(
         'select',
-        'option_financial_type_id['.$i.']',
+        'option_financial_type_id[' . $i . ']',
         ts('Financial Type'),
         array('' => ts('- select -')) + $financialType
       );
@@ -290,9 +281,8 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
         $js = array('onchange' => "calculateRowValues( $i );");
 
         $this->add('select', 'membership_type_id[' . $i . ']', ts('Membership Type'),
-          array(
-            '' => ' ') + $membershipTypes, FALSE, $js
-          );
+          array('' => ' ') + $membershipTypes, FALSE, $js
+        );
         $this->add('text', 'membership_num_terms[' . $i . ']', ts('Number of Terms'), CRM_Utils_Array::value('membership_num_terms', $attributes));
       }
 
@@ -382,16 +372,17 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
   }
 
   /**
-   * Global validation rules for the form
+   * Global validation rules for the form.
    *
-   * @param array $fields posted values of the form
+   * @param array $fields
+   *   Posted values of the form.
    *
    * @param $files
    * @param CRM_Core_Form $form
    *
-   * @return array    if errors then list of errors to be posted back to the form,
+   * @return array
+   *   if errors then list of errors to be posted back to the form,
    *                  true otherwise
-   * @static
    */
   public static function formRule($fields, $files, $form) {
 
@@ -409,7 +400,8 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
     }
 
     if (($form->_action & CRM_Core_Action::ADD || $form->_action & CRM_Core_Action::UPDATE) &&
-         $fields['html_type'] == 'Text' && $fields['financial_type_id'] == '') {
+      $fields['html_type'] == 'Text' && $fields['financial_type_id'] == ''
+    ) {
       $errors['financial_type_id'] = ts('Financial Type is a required field');
     }
 
@@ -532,21 +524,21 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
         if (!empty($memTypesIDS)) {
           // check for checkboxes allowing user to select multiple memberships from same membership organization
           if ($fields['html_type'] == 'CheckBox') {
-          $foundDuplicate = FALSE;
-          $orgIds = array();
-          foreach ($memTypesIDS as $key => $val) {
-            $org = CRM_Member_BAO_MembershipType::getMembershipTypeOrganization($val);
-            if (in_array($org[$val], $orgIds)) {
-              $foundDuplicate = TRUE;
-              break;
-            }
-            $orgIds[$val] = $org[$val];
+            $foundDuplicate = FALSE;
+            $orgIds = array();
+            foreach ($memTypesIDS as $key => $val) {
+              $org = CRM_Member_BAO_MembershipType::getMembershipTypeOrganization($val);
+              if (in_array($org[$val], $orgIds)) {
+                $foundDuplicate = TRUE;
+                break;
+              }
+              $orgIds[$val] = $org[$val];
 
+            }
+            if ($foundDuplicate) {
+              $errors['_qf_default'] = ts('You have selected multiple memberships for the same organization or entity. Please review your selections and choose only one membership per entity.');
+            }
           }
-          if ($foundDuplicate) {
-            $errors['_qf_default'] = ts('You have selected multiple memberships for the same organization or entity. Please review your selections and choose only one membership per entity.');
-          }
-        }
 
           // CRM-10390 - Only one price field in a set can include auto-renew membership options
           $foundAutorenew = FALSE;
@@ -599,11 +591,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
   }
 
   /**
-   * Process the form
-   *
-   * @param null
-   *
-   * @return void
+   * Process the form.
    */
   public function postProcess() {
     // store the submitted values in an array
@@ -613,7 +601,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
     $params['is_display_amounts'] = CRM_Utils_Array::value('is_display_amounts', $params, FALSE);
     $params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
-    $params['financial_type_id']  = CRM_Utils_Array::value('financial_type_id', $params, false);
+    $params['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params, FALSE);
     if (isset($params['active_on'])) {
       $params['active_on'] = CRM_Utils_Date::processDate($params['active_on'],
         CRM_Utils_Array::value('active_on_time', $params),
@@ -683,4 +671,5 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
       $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
     }
   }
+
 }