Merge pull request #5983 from relldoesphp/CRM-16544
[civicrm-core.git] / CRM / Core / OptionGroup.php
index b43c2fe6a2dabdbf3f343a200319da1fa742b8ca..7770090bd2bd7a72af7db7dd5be9af361664e53b 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -198,7 +198,7 @@ WHERE  v.option_group_id = g.id
   }
 
   /**
-   * This function retrieves all the values for the specific option group by id
+   * This function retrieves all the values for the specific option group by id.
    * this is primarily used to create various html based form elements
    * (radio, select, checkbox etc). OptionGroups for most cases have the
    * 'label' in the label colum and the 'id' or 'name' in the value column
@@ -442,7 +442,7 @@ WHERE  v.option_group_id = g.id
   }
 
   /**
-   * Creates a new option group with the passed in values
+   * Creates a new option group with the passed in values.
    * @TODO: Should update the group if it already exists intelligently, so multi-lingual is
    * not messed up. Currently deletes the old group
    *
@@ -591,12 +591,14 @@ SELECT v.label
    * @param string $field
    * @param string $fieldType
    * @param bool $active
+   * @param bool $localize
+   *   if true, localize the results before returning.
    *
    * @return array
    */
   public static function getRowValues(
     $groupName, $fieldValue, $field = 'name',
-    $fieldType = 'String', $active = TRUE
+    $fieldType = 'String', $active = TRUE, $localize = FALSE
   ) {
     $query = "
 SELECT v.id, v.label, v.value, v.name, v.weight, v.description
@@ -631,11 +633,18 @@ WHERE  v.option_group_id = g.id
         $row[$fld] = $dao->$fld;
       }
     }
+
+    if ($localize) {
+      foreach (array('label', 'description') as $f) {
+        $row[$f] = ts($row[$f]);
+      }
+    }
+
     return $row;
   }
 
   /**
-   * Wrapper for calling values with fresh set to true to empty the given value
+   * Wrapper for calling values with fresh set to true to empty the given value.
    *
    * Since there appears to be some inconsistency
    * (@todo remove inconsistency) around the pseudoconstant operations