Merge pull request #15382 from totten/5.18-note-event
[civicrm-core.git] / CRM / Price / Form / Field.php
index f7a75cb84a5a866fc43aa1f56afd948cac83db22..08ff9e40afb677af01779a5e23e029bed7eccd7e 100644 (file)
@@ -64,6 +64,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
 
   /**
    * Variable is set if price set is used for membership.
+   * @var bool
    */
   protected $_useForMember;
 
@@ -75,9 +76,9 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
     $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}");
-    $breadCrumb = array(array('title' => ts('Price Set Fields'), 'url' => $url));
+    $breadCrumb = [['title' => ts('Price Set Fields'), 'url' => $url]];
 
-    $this->_extendComponentId = array();
+    $this->_extendComponentId = [];
     $extendComponentId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'extends', 'id');
     if ($extendComponentId) {
       $this->_extendComponentId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $extendComponentId);
@@ -95,10 +96,10 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
    *   array of default values
    */
   public function setDefaultValues() {
-    $defaults = array();
+    $defaults = [];
     // is it an edit operation ?
     if (isset($this->_fid)) {
-      $params = array('id' => $this->_fid);
+      $params = ['id' => $this->_fid];
       $this->assign('fid', $this->_fid);
       CRM_Price_BAO_PriceField::retrieve($params, $defaults);
       $this->_sid = $defaults['price_set_id'];
@@ -106,7 +107,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
       // if text, retrieve price
       if ($defaults['html_type'] == 'Text') {
         $isActive = $defaults['is_active'];
-        $valueParams = array('price_field_id' => $this->_fid);
+        $valueParams = ['price_field_id' => $this->_fid];
 
         CRM_Price_BAO_PriceFieldValue::retrieve($valueParams, $defaults);
 
@@ -126,7 +127,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
     }
 
     if ($this->_action & CRM_Core_Action::ADD) {
-      $fieldValues = array('price_set_id' => $this->_sid);
+      $fieldValues = ['price_set_id' => $this->_sid];
       $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_PriceField', $fieldValues);
       $defaults['options_per_line'] = 1;
       $defaults['is_display_amounts'] = 1;
@@ -199,7 +200,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
 
     $this->add('select', 'financial_type_id',
       ts('Financial Type'),
-      array(' ' => ts('- select -')) + $financialType
+      [' ' => ts('- select -')] + $financialType
     );
 
     $this->assign('useForMember', FALSE);
@@ -267,7 +268,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
         'select',
         'option_financial_type_id[' . $i . ']',
         ts('Financial Type'),
-        array('' => ts('- select -')) + $financialType
+        ['' => ts('- select -')] + $financialType
       );
       if (in_array($eventComponentId, $this->_extendComponentId)) {
         // count
@@ -283,16 +284,16 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
       }
       elseif (in_array($memberComponentId, $this->_extendComponentId)) {
         $membershipTypes = CRM_Member_PseudoConstant::membershipType();
-        $js = array('onchange' => "calculateRowValues( $i );");
+        $js = ['onchange' => "calculateRowValues( $i );"];
 
         $this->add('select', 'membership_type_id[' . $i . ']', ts('Membership Type'),
-          array('' => ' ') + $membershipTypes, FALSE, $js
+          ['' => ' '] + $membershipTypes, FALSE, $js
         );
         $this->add('text', 'membership_num_terms[' . $i . ']', ts('Number of Terms'), CRM_Utils_Array::value('membership_num_terms', $attributes));
       }
 
       // weight
-      $this->add('text', 'option_weight[' . $i . ']', ts('Order'), $attributes['weight']);
+      $this->add('number', 'option_weight[' . $i . ']', ts('Order'), $attributes['weight']);
 
       // is active ?
       $this->add('checkbox', 'option_status[' . $i . ']', ts('Active?'));
@@ -311,7 +312,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
     $this->add('checkbox', 'is_display_amounts', ts('Display Amount?'));
 
     // weight
-    $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'weight'), TRUE);
+    $this->add('number', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'weight'), TRUE);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
 
     // checkbox / radio options per line
@@ -327,10 +328,10 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
       CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'help_post')
     );
 
-    $this->add('datepicker', 'active_on', ts('Active On'), [], FALSE, array('time' => TRUE));
+    $this->add('datepicker', 'active_on', ts('Active On'), [], FALSE, ['time' => TRUE]);
 
     // expire_on
-    $this->add('datepicker', 'expire_on', ts('Expire On'), [], FALSE, array('time' => TRUE));
+    $this->add('datepicker', 'expire_on', ts('Expire On'), [], FALSE, ['time' => TRUE]);
 
     // is required ?
     $this->add('checkbox', 'is_required', ts('Required?'));
@@ -339,27 +340,27 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
     $this->add('checkbox', 'is_active', ts('Active?'));
 
     // add buttons
-    $this->addButtons(array(
-      array(
+    $this->addButtons([
+      [
         'type' => 'next',
         'name' => ts('Save'),
         'isDefault' => TRUE,
-      ),
-      array(
+      ],
+      [
         'type' => 'next',
         'name' => ts('Save and New'),
         'subName' => 'new',
-      ),
-      array(
+      ],
+      [
         'type' => 'cancel',
         'name' => ts('Cancel'),
-      ),
-    ));
+      ],
+    ]);
     // is public?
     $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility());
 
     // add a form rule to check default value
-    $this->addFormRule(array('CRM_Price_Form_Field', 'formRule'), $this);
+    $this->addFormRule(['CRM_Price_Form_Field', 'formRule'], $this);
 
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
@@ -368,7 +369,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
       $this->addElement('button',
         'done',
         ts('Done'),
-        array('onclick' => "location.href='$url'")
+        ['onclick' => "location.href='$url'"]
       );
     }
   }
@@ -389,7 +390,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
   public static function formRule($fields, $files, $form) {
 
     // all option fields are of type "money"
-    $errors = array();
+    $errors = [];
 
     /** Check the option values entered
      *  Appropriate values are required for the selected datatype
@@ -421,7 +422,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
     }
 
     if ((is_numeric(CRM_Utils_Array::value('count', $fields)) &&
-        CRM_Utils_Array::value('count', $fields) == 0
+        empty($fields['count'])
       ) &&
       (CRM_Utils_Array::value('html_type', $fields) == 'Text')
     ) {
@@ -434,7 +435,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
         $publicOptionCount = $_flagOption = $_rowError = 0;
 
         $_showHide = new CRM_Core_ShowHideBlocks('', '');
-        $visibilityOptions = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, array('labelColumn' => 'name'));
+        $visibilityOptions = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, ['labelColumn' => 'name']);
 
         for ($index = 1; $index <= self::NUM_OPTION; $index++) {
 
@@ -533,7 +534,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
           // check for checkboxes allowing user to select multiple memberships from same membership organization
           if ($fields['html_type'] == 'CheckBox') {
             $foundDuplicate = FALSE;
-            $orgIds = array();
+            $orgIds = [];
             foreach ($memTypesIDS as $key => $val) {
               $org = CRM_Member_BAO_MembershipType::getMembershipTypeOrganization($val);
               if (in_array($org[$val], $orgIds)) {
@@ -610,11 +611,11 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
       }
 
       if (empty($fields['option_name'])) {
-        $fields['option_amount'] = array();
+        $fields['option_amount'] = [];
       }
 
       if (empty($fields['option_label'])) {
-        $fields['option_label'] = array();
+        $fields['option_label'] = [];
       }
     }
 
@@ -639,7 +640,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
     $params['price_set_id'] = $this->_sid;
 
     if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
-      $fieldValues = array('price_set_id' => $this->_sid);
+      $fieldValues = ['price_set_id' => $this->_sid];
       $oldWeight = NULL;
       if ($this->_fid) {
         $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $this->_fid, 'weight', 'id');
@@ -658,14 +659,14 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
       $params['is_enter_qty'] = 1;
       // modify params values as per the option group and option
       // value
-      $params['option_amount'] = array(1 => $params['price']);
-      $params['option_label'] = array(1 => $params['label']);
-      $params['option_count'] = array(1 => $params['count']);
-      $params['option_max_value'] = array(1 => CRM_Utils_Array::value('max_value', $params));
+      $params['option_amount'] = [1 => $params['price']];
+      $params['option_label'] = [1 => $params['label']];
+      $params['option_count'] = [1 => $params['count']];
+      $params['option_max_value'] = [1 => CRM_Utils_Array::value('max_value', $params)];
       //$params['option_description']  = array( 1 => $params['description'] );
-      $params['option_weight'] = array(1 => $params['weight']);
-      $params['option_financial_type_id'] = array(1 => $params['financial_type_id']);
-      $params['option_visibility_id'] = array(1 => CRM_Utils_Array::value('visibility_id', $params));
+      $params['option_weight'] = [1 => $params['weight']];
+      $params['option_financial_type_id'] = [1 => $params['financial_type_id']];
+      $params['option_visibility_id'] = [1 => CRM_Utils_Array::value('visibility_id', $params)];
     }
 
     if ($this->_fid) {
@@ -677,7 +678,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
     $priceField = CRM_Price_BAO_PriceField::create($params);
 
     if (!is_a($priceField, 'CRM_Core_Error')) {
-      CRM_Core_Session::setStatus(ts('Price Field \'%1\' has been saved.', array(1 => $priceField->label)), ts('Saved'), 'success');
+      CRM_Core_Session::setStatus(ts('Price Field \'%1\' has been saved.', [1 => $priceField->label]), ts('Saved'), 'success');
     }
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();