INFRA-132 - phpcbf Drupal.WhiteSpace.ScopeIndent.IncorrectExact
[civicrm-core.git] / CRM / Price / BAO / PriceField.php
index ff67088dc08115d8a74e915dbd6a9e60a8326b73..b837aedd1f2319dceb0b8cdb4c045c84c73ad5d5 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        |
   +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -51,8 +51,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
    * @param array $params
    *   (reference) an assoc array of name/value pairs.
    *
-   * @return CRM_Price_BAO_PriceField object
-   * @static
+   * @return CRM_Price_BAO_PriceField
    */
   public static function add(&$params) {
     $priceFieldBAO = new CRM_Price_BAO_PriceField();
@@ -75,8 +74,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
    * @param array $params
    *   (reference) an assoc array of name/value pairs.
    *
-   * @return CRM_Price_DAO_PriceField object
-   * @static
+   * @return CRM_Price_DAO_PriceField
    */
   public static function create(&$params) {
     if (empty($params['id']) && empty($params['name'])) {
@@ -147,7 +145,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
         }
 
         if (CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_financial_type_id', $params))) {
-          $options['financial_type_id'] =  $params['option_financial_type_id'][$index];
+          $options['financial_type_id'] = $params['option_financial_type_id'][$index];
         }
         elseif (!empty($params['financial_type_id'])) {
           $options['financial_type_id'] = $params['financial_type_id'];
@@ -177,8 +175,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
    * @param array $defaults
    *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return CRM_Price_DAO_PriceField object
-   * @static
+   * @return CRM_Price_DAO_PriceField
    */
   public static function retrieve(&$params, &$defaults) {
     return CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceField', $params, $defaults);
@@ -192,9 +189,9 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
    * @param bool $is_active
    *   Value we want to set the is_active field.
    *
-   * @return   Object            DAO object on sucess, null otherwise
+   * @return Object
+   *   DAO object on sucess, null otherwise
    *
-   * @static
    */
   public static function setIsActive($id, $is_active) {
     return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceField', $id, 'is_active', $is_active);
@@ -204,7 +201,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
     if (!empty($fieldOptions['is_full'])) {
       $element->freeze();
     }
-    return;
+    return NULL;
   }
 
   /**
@@ -213,9 +210,8 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
    * @param int $id
    *   Id of field.
    *
-   * @return string name
-   *
-   * @static
+   * @return string
+   *   name
    *
    */
   public static function getTitle($id) {
@@ -241,7 +237,6 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
    *
    * @return null
    * @internal param bool $search true if used for search else false
-   * @static
    */
   public static function addQuickFormElement(
     &$qf,
@@ -271,7 +266,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
 
     $otherAmount = $qf->get('values');
     $config = CRM_Core_Config::singleton();
-    $currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency',$config->defaultCurrency,'symbol','name');
+    $currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $config->defaultCurrency, 'symbol', 'name');
     $qf->assign('currencySymbol', $currencySymbol);
     // get currency name for price field and option attributes
     $currencyName = $config->defaultCurrency;
@@ -311,7 +306,11 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
           $qf->assign('taxTerm', $taxTerm);
           $qf->assign('invoicing', $invoicing);
         }
-        $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName] + $taxAmount, $count, $max_value));
+        $priceVal = implode($seperator, array(
+            $customOption[$optionKey][$valueFieldName] + $taxAmount,
+            $count,
+            $max_value,
+          ));
 
         $extra = array();
         if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) {
@@ -327,20 +326,22 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
         if (!empty($qf->_membershipBlock) && !empty($qf->_quickConfig) && $field->name == 'other_amount' && empty($qf->_contributionAmount)) {
           $useRequired = 0;
         }
-        elseif (!empty($fieldOptions[$optionKey]['label'])) {      //check for label.
+        elseif (!empty($fieldOptions[$optionKey]['label'])) {
+          //check for label.
           $label = $fieldOptions[$optionKey]['label'];
         }
 
         $element = &$qf->add('text', $elementName, $label,
-                   array_merge($extra,
-                     array('price' => json_encode(array($optionKey, $priceVal)),
-                       'size' => '4',
-                     )
-                   ),
-                   $useRequired && $field->is_required
+          array_merge($extra,
+            array(
+              'price' => json_encode(array($optionKey, $priceVal)),
+              'size' => '4',
+            )
+          ),
+          $useRequired && $field->is_required
         );
         if ($is_pay_later) {
-          $qf->add('text', 'txt-'.$elementName, $label, array('size' => '4'));
+          $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
         }
 
         // CRM-6902 - Add "max" option for a price set field
@@ -376,14 +377,14 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
             $opt['label'] = !empty($opt['label']) ? $opt['label'] . ' - ' : '';
             if (isset($taxAmount) && $invoicing) {
               if ($displayOpt == 'Do_not_show') {
-                $opt['label'] =  '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName] + $taxAmount) . '</span>';
+                $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName] + $taxAmount) . '</span>';
               }
               elseif ($displayOpt == 'Inclusive') {
                 $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName] + $taxAmount) . '</span>';
                 $opt['label'] .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money::format($opt['tax_amount']) . ')</span>';
               }
               else {
-                $opt['label'] =  '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
+                $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
                 $opt['label'] .= '<span class="crm-price-amount-tax"> + ' . CRM_Utils_Money::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';
               }
             }
@@ -394,9 +395,10 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
           $count = CRM_Utils_Array::value('count', $opt, '');
           $max_value = CRM_Utils_Array::value('max_value', $opt, '');
           $priceVal = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value));
-          $extra = array('price' => json_encode(array($elementName, $priceVal)),
-                   'data-amount' => $opt[$valueFieldName],
-                   'data-currency' => $currencyName,
+          $extra = array(
+            'price' => json_encode(array($elementName, $priceVal)),
+            'data-amount' => $opt[$valueFieldName],
+            'data-currency' => $currencyName,
           );
           if (!empty($qf->_quickConfig) && $field->name == 'contribution_amount') {
             $extra += array('onclick' => 'clearAmountOther();');
@@ -406,13 +408,13 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
               'onclick' => "return showHideAutoRenew({$opt['membership_type_id']});",
               'membership-type' => $opt['membership_type_id'],
             );
-            $qf->assign('membershipFieldID',$field->id);
+            $qf->assign('membershipFieldID', $field->id);
           }
 
           $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
 
           if ($is_pay_later) {
-            $qf->add('text', 'txt-'.$elementName, $label, array('size' => '4'));
+            $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
           }
 
           // CRM-6902 - Add "max" option for a price set field
@@ -451,7 +453,8 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
 
         // make contribution field required for quick config when membership block is enabled
         if (($field->name == 'membership_amount' || $field->name == 'contribution_amount')
-          && !empty($qf->_membershipBlock) && !$field->is_required) {
+          && !empty($qf->_membershipBlock) && !$field->is_required
+        ) {
           $useRequired = $field->is_required = TRUE;
         }
 
@@ -470,7 +473,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
 
           if ($field->is_display_amounts) {
             $opt['label'] .= '&nbsp;-&nbsp;';
-            if (isset($taxAmount)  && $invoicing) {
+            if (isset($taxAmount) && $invoicing) {
               $opt['label'] = $opt['label'] . self::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
             }
             else {
@@ -492,16 +495,17 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
           $selectOption[$opt['id']] = $opt['label'];
 
           if ($is_pay_later) {
-            $qf->add('text', 'txt-'.$elementName, $label, array('size' => '4'));
+            $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
           }
         }
 
         $element = &$qf->add('select', $elementName, $label,
           array(
-            '' => ts('- select -')) + $selectOption,
-            $useRequired && $field->is_required,
-            array('price' => json_encode($priceVal))
-          );
+            '' => ts('- select -'),
+          ) + $selectOption,
+          $useRequired && $field->is_required,
+          array('price' => json_encode($priceVal))
+        );
 
         // CRM-6902 - Add "max" option for a price set field
         $button = substr($qf->controller->getButtonName(), -4);
@@ -529,9 +533,10 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
           }
           $priceVal = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value));
           $check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $opt['label'],
-            array('price' => json_encode(array($opt['id'], $priceVal)),
-             'data-amount' => $opt[$valueFieldName],
-             'data-currency' => $currencyName,
+            array(
+              'price' => json_encode(array($opt['id'], $priceVal)),
+              'data-amount' => $opt[$valueFieldName],
+              'data-currency' => $currencyName,
             )
           );
           if ($is_pay_later) {
@@ -566,7 +571,8 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
    * @param bool $reset
    *   Ignore stored values\.
    *
-   * @return array array of options
+   * @return array
+   *   array of options
    */
   public static function getOptions($fieldId, $inactiveNeeded = FALSE, $reset = FALSE) {
     static $options = array();
@@ -583,7 +589,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
         if (isset($priceFieldValues['financial_type_id']) && array_key_exists($priceFieldValues['financial_type_id'], $taxRates)) {
           $options[$fieldId][$priceFieldId]['tax_rate'] = $taxRates[$priceFieldValues['financial_type_id']];
           $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($priceFieldValues['amount'], $options[$fieldId][$priceFieldId]['tax_rate']);
-          $options[$fieldId][$priceFieldId]['tax_amount'] = round($taxAmount['tax_amount'],2);
+          $options[$fieldId][$priceFieldId]['tax_amount'] = round($taxAmount['tax_amount'], 2);
         }
       }
     }
@@ -615,7 +621,10 @@ WHERE
     AND option_group.id = option_value.option_group_id
     AND option_value.label = %2";
 
-    $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($optionGroupName, 'String'), 2 => array($optionLabel, 'String')));
+    $dao = CRM_Core_DAO::executeQuery($query, array(
+        1 => array($optionGroupName, 'String'),
+        2 => array($optionLabel, 'String'),
+      ));
 
     while ($dao->fetch()) {
       return $dao->id;
@@ -628,9 +637,7 @@ WHERE
    * @param int $id
    *   Field Id.
    *
-   * @return  boolean
-   *
-   * @static
+   * @return bool
    *
    */
   public static function deleteField($id) {
@@ -681,9 +688,7 @@ WHERE
    * @param $error
    * @param bool $allowNoneSelection
    *
-   * @static
    */
-
   public static function priceSetValidation($priceSetId, $fields, &$error, $allowNoneSelection = FALSE) {
     // check for at least one positive
     // amount price field should be selected.
@@ -779,9 +784,8 @@ WHERE  id IN (" . implode(',', array_keys($priceFields)) . ')';
    * @param string $displayOpt
    *   Tax display setting option.
    *
-   * @return string $label tax label for custom field
-   *
-   * @static
+   * @return string
+   *   tax label for custom field
    *
    */
   public static function getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm) {
@@ -799,4 +803,5 @@ WHERE  id IN (" . implode(',', array_keys($priceFields)) . ')';
 
     return $label;
   }
+
 }