+--------------------------------------------------------------------+
| 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$
*
*/
static $_values = array();
static $_cache = array();
- /*
+ /**
* $_domainIDGroups array maintains the list of option groups for whom
* domainID is to be considered.
- *
*/
static $_domainIDGroups = array(
'from_email_address',
*
* @return array
*/
- static function &valuesCommon(
+ public static function &valuesCommon(
$dao, $flip = FALSE, $grouping = FALSE,
$localize = FALSE, $valueColumnName = 'label'
) {
* (radio, select, checkbox etc). OptionGroups for most cases have the
* 'label' in the label colum and the 'id' or 'name' in the value column
*
- * @param $name
- * String name of the option group.
- * @param $flip
- * Boolean results are return in id => label format if false.
+ * @param string $name
+ * name of the option group.
+ * @param bool $flip
+ * results are return in id => label format if false.
* if true, the results are reversed
- * @param $grouping
- * Boolean if true, return the value in 'grouping' column.
- * @param $localize
- * Boolean if true, localize the results before returning.
- * @param $condition
- * String add another condition to the sql query.
- * @param $labelColumnName
- * String the column to use for 'label'.
- * @param $onlyActive
- * Boolean return only the action option values.
- * @param $fresh
- * Boolean ignore cache entries and go back to DB.
- * @param $keyColumnName
- * String the column to use for 'key'.
+ * @param bool $grouping
+ * if true, return the value in 'grouping' column.
+ * @param bool $localize
+ * if true, localize the results before returning.
+ * @param string $condition
+ * add another condition to the sql query.
+ * @param string $labelColumnName
+ * the column to use for 'label'.
+ * @param bool $onlyActive
+ * return only the action option values.
+ * @param bool $fresh
+ * ignore cache entries and go back to DB.
+ * @param string $keyColumnName
+ * the column to use for 'key'.
*
- * @return array the values as specified by the above params
- * @static
+ * @return array
+ * the values as specified by the above params
* @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'
}
/**
- * 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
*
- * @param $id
- * Integer id of the option group.
- * @param $flip
- * Boolean results are return in id => label format if false.
- * if true, the results are reversed
- * @param $grouping
- * Boolean if true, return the value in 'grouping' column.
- * @param $localize
- * Boolean if true, localize the results before returning.
- * @param $labelColumnName
- * String the column to use for 'label'.
- *
+ * @param int $id
+ * id of the option group.
+ * @param bool $flip
+ * results are return in id => label format if false.
+ * if true, the results are reversed
+ * @param bool $grouping
+ * if true, return the value in 'grouping' column.
+ * @param bool $localize
+ * if true, localize the results before returning.
+ * @param string $labelColumnName
+ * the column to use for 'label'.
* @param bool $onlyActive
* @param bool $fresh
*
- * @return array the values as specified by the above params
- * @static
+ * @return array
+ * Array of values as specified by the above params
* @void
*/
public static function &valuesByID($id, $flip = FALSE, $grouping = FALSE, $localize = FALSE, $labelColumnName = 'label', $onlyActive = TRUE, $fresh = FALSE) {
*
* @param array $params
* Reference array of values submitted by the form. Based on.
- * $flip, creates new elements in $params for each field in
- * the $names array.
- * If $flip = false, adds root field name => title
- * If $flip = true, adds actual field name => id
+ * $flip, creates new elements in $params for each field in
+ * the $names array.
+ * If $flip = false, adds root field name => title
+ * If $flip = true, adds actual field name => id
*
* @param array $names
* Reference array of fieldnames we want transformed.
- * Array key = 'postName' (field name submitted by form in $params).
- * Array value = array(
- 'newName' => $newName, 'groupName' => $groupName).
+ * Array key = 'postName' (field name submitted by form in $params).
+ * Array value = array('newName' => $newName, 'groupName' => $groupName).
*
*
* @param bool $flip
*
* @return void
*
- * @static
*/
public static function lookupValues(&$params, &$names, $flip = FALSE) {
foreach ($names as $postName => $value) {
}
if ($flip) {
- $p = array(1 => array($postValue, 'String'));
+ $p = array(1 => array($postValue, 'String'));
$lookupBy = 'v.label= %1';
- $select = "v.value";
+ $select = "v.value";
}
else {
- $p = array(1 => array($postValue, 'Integer'));
+ $p = array(1 => array($postValue, 'Integer'));
$lookupBy = 'v.value = %1';
- $select = "v.label";
+ $select = "v.label";
}
$p[2] = array($value['groupName'], 'String');
$query .= " AND v.is_active = 1 ";
}
$p = array(
- 1 => array($groupName, 'String'),
+ 1 => array($groupName, 'String'),
2 => array($value, 'Integer'),
);
$dao = CRM_Core_DAO::executeQuery($query, $p);
*
* @return null
*/
- static function getValue(
+ public static function getValue(
$groupName,
$label,
$labelField = 'label',
";
$p = array(
- 1 => array($groupName, 'String'),
+ 1 => array($groupName, 'String'),
2 => array($label, $labelType),
);
$dao = CRM_Core_DAO::executeQuery($query, $p);
* @param string $groupName
* The name of the option group.
*
- * @static
*
- * @return string the value from the row where is_default = true
+ * @return string
+ * the value from the row where is_default = true
*/
public static function getDefaultValue($groupName) {
if (empty($groupName)) {
}
/**
- * 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
*
* @param null $groupTitle
* The optional label of the option group else set to group name.
*
- * @static
*
- * @return int the option group ID
+ * @return int
+ * the option group ID
*/
public static function createAssoc($groupName, &$values, &$defaultID, $groupTitle = NULL) {
self::deleteAssoc($groupName);
if (!empty($values)) {
- $group = new CRM_Core_DAO_OptionGroup();
- $group->name = $groupName;
- $group->title = empty($groupTitle) ? $groupName : $groupTitle;
+ $group = new CRM_Core_DAO_OptionGroup();
+ $group->name = $groupName;
+ $group->title = empty($groupTitle) ? $groupName : $groupTitle;
$group->is_reserved = 1;
- $group->is_active = 1;
+ $group->is_active = 1;
$group->save();
foreach ($values as $v) {
AND g.name = %1
AND v.value = %2";
$params = array(
- 1 => array($groupName, 'String'),
+ 1 => array($groupName, 'String'),
2 => array($value, 'String'),
);
return CRM_Core_DAO::singleValueQuery($query, $params);
* @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
}
$p = array(
- 1 => array($groupName, 'String'),
+ 1 => array($groupName, 'String'),
2 => array($fieldValue, $fieldType),
);
$dao = CRM_Core_DAO::executeQuery($query, $p);
if ($dao->fetch()) {
foreach (array(
- 'id', 'name', 'value', 'label', 'weight', 'description') as $fld) {
+ 'id',
+ 'name',
+ 'value',
+ 'label',
+ 'weight',
+ '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
* (for example CRM_Contribution_Pseudoconstant::paymentInstrument doesn't specify isActive
* which is part of the cache key
* will do a couple of variations & aspire to someone cleaning it up later
- */
- /**
- * @param $name
+ *
+ * @param string $name
* @param array $params
*/
public static function flush($name, $params = array()) {
self::$_cache = array();
CRM_Utils_Cache::singleton()->flush();
}
+
}