Merge pull request #5983 from relldoesphp/CRM-16544
[civicrm-core.git] / CRM / Core / OptionGroup.php
index ff6037dcabc88edc808c0df96dde15e04d56ac51..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.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -54,7 +54,7 @@ class CRM_Core_OptionGroup {
    *
    * @return array
    */
-  static function &valuesCommon(
+  public static function &valuesCommon(
     $dao, $flip = FALSE, $grouping = FALSE,
     $localize = FALSE, $valueColumnName = 'label'
   ) {
@@ -113,10 +113,9 @@ class CRM_Core_OptionGroup {
    *
    * @return array
    *   the values as specified by the above params
-   * @static
    * @void
    */
-  static function &values(
+  public static function &values(
     $name, $flip = FALSE, $grouping = FALSE,
     $localize = FALSE, $condition = NULL,
     $labelColumnName = 'label', $onlyActive = TRUE, $fresh = FALSE, $keyColumnName = 'value'
@@ -199,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
@@ -220,7 +219,6 @@ WHERE  v.option_group_id = g.id
    *
    * @return array
    *   Array of values as specified by the above params
-   * @static
    * @void
    */
   public static function &valuesByID($id, $flip = FALSE, $grouping = FALSE, $localize = FALSE, $labelColumnName = 'label', $onlyActive = TRUE, $fresh = FALSE) {
@@ -277,7 +275,6 @@ WHERE  v.option_group_id = g.id
    *
    * @return void
    *
-   * @static
    */
   public static function lookupValues(&$params, &$names, $flip = FALSE) {
     foreach ($names as $postName => $value) {
@@ -377,7 +374,7 @@ WHERE  v.option_group_id = g.id
    *
    * @return null
    */
-  static function getValue(
+  public static function getValue(
     $groupName,
     $label,
     $labelField = 'label',
@@ -418,7 +415,6 @@ WHERE  v.option_group_id = g.id
    * @param string $groupName
    *   The name of the option group.
    *
-   * @static
    *
    * @return string
    *   the value from the row where is_default = true
@@ -446,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
    *
@@ -467,7 +463,6 @@ WHERE  v.option_group_id = g.id
    * @param null $groupTitle
    *   The optional label of the option group else set to group name.
    *
-   * @static
    *
    * @return int
    *   the option group ID
@@ -596,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
    */
-  static function getRowValues(
+  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,16 +628,23 @@ WHERE  v.option_group_id = g.id
                  'value',
                  'label',
                  'weight',
-                 'description'
+                 'description',
                ) as $fld) {
         $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
@@ -688,4 +692,5 @@ WHERE  v.option_group_id = g.id
     self::$_cache = array();
     CRM_Utils_Cache::singleton()->flush();
   }
+
 }