Merge pull request #5255 from totten/master-replyto-setting
[civicrm-core.git] / CRM / Price / BAO / PriceField.php
index 6e33a0b1da68ebd613acc5702c182deafa68086a..d9bf0668b3926f9b3d443c9f629564b74213cef0 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        |
   +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -42,7 +42,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
   protected $_options;
 
   /**
-   * Takes an associative array and creates a price field object
+   * Takes an associative array and creates a price field object.
    *
    * the function extract all the params it needs to initialize the create a
    * price field object. the params array could contain additional unused name/value
@@ -67,7 +67,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
   }
 
   /**
-   * Takes an associative array and creates a price field object
+   * Takes an associative array and creates a price field object.
    *
    * This function is invoked from within the web form layer and also from the api layer
    *
@@ -168,7 +168,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
   }
 
   /**
-   * Fetch object based on array of properties
+   * Fetch object based on array of properties.
    *
    * @param array $params
    *   (reference ) an assoc array of name/value pairs.
@@ -182,7 +182,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
   }
 
   /**
-   * Update the is_active flag in the db
+   * Update the is_active flag in the db.
    *
    * @param int $id
    *   Id of the database record.
@@ -190,18 +190,25 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
    *   Value we want to set the is_active field.
    *
    * @return Object
-   *   DAO object on sucess, null otherwise
-   *
+   *   DAO object on success, null otherwise.
    */
   public static function setIsActive($id, $is_active) {
     return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceField', $id, 'is_active', $is_active);
   }
 
+  /**
+   * Freeze form if the event is full.
+   *
+   * @param $element
+   * @param $fieldOptions
+   *
+   * @return null
+   */
   public static function freezeIfEnabled(&$element, $fieldOptions) {
     if (!empty($fieldOptions['is_full'])) {
       $element->freeze();
     }
-    return;
+    return NULL;
   }
 
   /**
@@ -219,7 +226,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
   }
 
   /**
-   * This function for building custom fields
+   * This function for building custom fields.
    *
    * @param CRM_Core_Form $qf
    *   Form object (reference).
@@ -309,7 +316,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
         $priceVal = implode($seperator, array(
             $customOption[$optionKey][$valueFieldName] + $taxAmount,
             $count,
-            $max_value
+            $max_value,
           ));
 
         $extra = array();
@@ -326,7 +333,8 @@ 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'];
         }
 
@@ -345,7 +353,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
 
         // CRM-6902 - Add "max" option for a price set field
         if (in_array($optionKey, $freezeOptions)) {
-          self::freezeIfEnabled($element, $freezeOptions);
+          self::freezeIfEnabled($element, $fieldOptions[$optionKey]);
           // CRM-14696 - Improve display for sold out price set options
           $element->setLabel($label . '&nbsp;<span class="sold-out-option">' . ts('Sold out') . '</span>');
         }
@@ -480,7 +488,6 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
             }
           }
 
-          $selectOption[$opt['id']] = $opt['label'];
           $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value));
 
           if (!in_array($opt['id'], $freezeOptions)) {
@@ -488,6 +495,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
           }
           // CRM-14696 - Improve display for sold out price set options
           else {
+            $opt['id'] = 'crm_disabled_opt-' . $opt['id'];
             $opt['label'] = $opt['label'] . ' (' . ts('Sold out') . ')';
           }
 
@@ -500,10 +508,10 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
 
         $element = &$qf->add('select', $elementName, $label,
           array(
-            '' => ts('- select -')
+            '' => ts('- select -'),
           ) + $selectOption,
           $useRequired && $field->is_required,
-          array('price' => json_encode($priceVal))
+          array('price' => json_encode($priceVal), 'class' => 'crm-select2')
         );
 
         // CRM-6902 - Add "max" option for a price set field
@@ -561,7 +569,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
   }
 
   /**
-   * Retrieve a list of options for the specified field
+   * Retrieve a list of options for the specified field.
    *
    * @param int $fieldId
    *   Price field ID.
@@ -622,7 +630,7 @@ WHERE
 
     $dao = CRM_Core_DAO::executeQuery($query, array(
         1 => array($optionGroupName, 'String'),
-        2 => array($optionLabel, 'String')
+        2 => array($optionLabel, 'String'),
       ));
 
     while ($dao->fetch()) {
@@ -636,7 +644,7 @@ WHERE
    * @param int $id
    *   Field Id.
    *
-   * @return boolean
+   * @return bool
    *
    */
   public static function deleteField($id) {
@@ -676,7 +684,7 @@ WHERE
   }
 
   /**
-   * Validate the priceset
+   * Validate the priceset.
    *
    * @param int $priceSetId
    *   , array $fields.
@@ -688,7 +696,6 @@ WHERE
    * @param bool $allowNoneSelection
    *
    */
-
   public static function priceSetValidation($priceSetId, $fields, &$error, $allowNoneSelection = FALSE) {
     // check for at least one positive
     // amount price field should be selected.
@@ -803,4 +810,5 @@ WHERE  id IN (" . implode(',', array_keys($priceFields)) . ')';
 
     return $label;
   }
+
 }