Merge pull request #5145 from agh1/case-insensitive-headers
[civicrm-core.git] / CRM / Core / BAO / CustomOption.php
index 07f3172a511c75568a85f30ff6c4c1d571f55b4f..7b01478cdb7a7447e42469251b5ee9d11cd1b7e4 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
 class CRM_Core_BAO_CustomOption {
 
   /**
-   * 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
-   * @param array $defaults (reference ) an assoc array to hold the flattened values
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
+   * @param array $defaults
+   *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return CRM_Core_BAO_CustomOption object
-   * @access public
-   * @static
+   * @return CRM_Core_BAO_CustomOption
    */
-  static function retrieve(&$params, &$defaults) {
+  public static function retrieve(&$params, &$defaults) {
     $customOption = new CRM_Core_DAO_OptionValue();
     $customOption->copyValues($params);
     if ($customOption->find(TRUE)) {
@@ -60,15 +60,17 @@ class CRM_Core_BAO_CustomOption {
   }
 
   /**
-   * Returns all active options ordered by weight for a given field
+   * Returns all active options ordered by weight for a given field.
    *
-   * @param int $fieldID field whose options are needed
-   * @param  boolean $inactiveNeeded do we need inactive options ?
+   * @param int $fieldID
+   *   Field whose options are needed.
+   * @param bool $inactiveNeeded Do we need inactive options ?.
+   *   Do we need inactive options ?.
    *
-   * @return array $customOption all active options for fieldId
-   * @static
+   * @return array
+   *   all active options for fieldId
    */
-  static function getCustomOption(
+  public static function getCustomOption(
     $fieldID,
     $inactiveNeeded = FALSE
   ) {
@@ -107,17 +109,19 @@ class CRM_Core_BAO_CustomOption {
    * Returns the option label for a custom field with a specific value. Handles all
    * custom field data and html types
    *
-   * @param $fieldId  int    the custom field ID
+   * @param int $fieldId
+   *   the custom field ID.
    * @pram  $value    string the value (typically from the DB) of this custom field
    * @param $value
-   * @param $htmlType string the html type of the field (optional)
-   * @param $dataType string the data type of the field (optional)
+   * @param string $htmlType
+   *   the html type of the field (optional).
+   * @param string $dataType
+   *   the data type of the field (optional).
    *
-   * @return string          the label to display for this custom field
-   * @static
-   * @access public
+   * @return string
+   *   the label to display for this custom field
    */
-  static function getOptionLabel($fieldId, $value, $htmlType = NULL, $dataType = NULL) {
+  public static function getOptionLabel($fieldId, $value, $htmlType = NULL, $dataType = NULL) {
     if (!$fieldId) {
       return NULL;
     }
@@ -148,7 +152,10 @@ WHERE  id = %1
       case 'Radio':
       case 'Autocomplete-Select':
         if (!in_array($dataType, array(
-          'Boolean', 'ContactReference'))) {
+          'Boolean',
+          'ContactReference',
+        ))
+        ) {
           $options = self::valuesByID($fieldId);
         }
     }
@@ -161,14 +168,13 @@ WHERE  id = %1
   }
 
   /**
-   * Delete Option
+   * Delete Option.
    *
-   * param $optionId integer option id
+   * @param $optionId integer
+   *   option id
    *
-   * @static
-   * @access public
    */
-  static function del($optionId) {
+  public static function del($optionId) {
     // get the customFieldID
     $query = "
 SELECT f.id as id, f.data_type as dataType
@@ -182,8 +188,8 @@ AND    g.id    = v.option_group_id";
     $dao = CRM_Core_DAO::executeQuery($query, $params);
     if ($dao->fetch()) {
       if (in_array($dao->dataType,
-          array('Int', 'Float', 'Money', 'Boolean')
-        )) {
+        array('Int', 'Float', 'Money', 'Boolean')
+      )) {
         $value = 0;
       }
       else {
@@ -212,7 +218,7 @@ WHERE  id = %1";
    *
    * @throws Exception
    */
-  static function updateCustomValues($params) {
+  public static function updateCustomValues($params) {
     $optionDAO = new CRM_Core_DAO_OptionValue();
     $optionDAO->id = $params['optionId'];
     $optionDAO->find(TRUE);
@@ -249,7 +255,8 @@ WHERE  id = %2";
             $dataType = $dao->dataType;
           }
           $queryParams = array(
-            1 => array($params['value'],
+            1 => array(
+              $params['value'],
               $dataType,
             ),
             2 => array(
@@ -264,10 +271,11 @@ WHERE  id = %2";
         case 'CheckBox':
           $oldString = CRM_Core_DAO::VALUE_SEPARATOR . $oldValue . CRM_Core_DAO::VALUE_SEPARATOR;
           $newString = CRM_Core_DAO::VALUE_SEPARATOR . $params['value'] . CRM_Core_DAO::VALUE_SEPARATOR;
-          $query     = "
+          $query = "
 UPDATE {$dao->tableName}
 SET    {$dao->columnName} = REPLACE( {$dao->columnName}, %1, %2 )";
-          $queryParams = array(1 => array($oldString, 'String'),
+          $queryParams = array(
+            1 => array($oldString, 'String'),
             2 => array($newString, 'String'),
           );
           break;
@@ -285,7 +293,7 @@ SET    {$dao->columnName} = REPLACE( {$dao->columnName}, %1, %2 )";
    *
    * @return array
    */
-  static function valuesByID($customFieldID, $optionGroupID = NULL) {
+  public static function valuesByID($customFieldID, $optionGroupID = NULL) {
     if (!$optionGroupID) {
       $optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField',
         $customFieldID,
@@ -299,5 +307,5 @@ SET    {$dao->columnName} = REPLACE( {$dao->columnName}, %1, %2 )";
 
     return $options;
   }
-}
 
+}