+--------------------------------------------------------------------+
| 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$
*
*/
class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue {
/**
- * Class constructor
+ * Class constructor.
*/
public function __construct() {
parent::__construct();
* @return object
*/
public static function create($params) {
- if (empty($params['id'])){
+ if (empty($params['id'])) {
self::setDefaults($params);
}
$ids = array();
if (!empty($params['id'])) {
$ids = array('optionValue' => $params['id']);
}
- return CRM_Core_BAO_OptionValue::add($params, $ids);
+ return CRM_Core_BAO_OptionValue::add($params, $ids);
}
+
/**
- * Set default Parameters
+ * Set default Parameters.
* This functions sets default parameters if not set:
* - name & label are set to each other as required (it might make more sense for one
* to be required but this would mean a change to the api level)
*
* @param array $params
*/
- public static function setDefaults(&$params){
- if (CRM_Utils_Array::value('label', $params, NULL) === NULL){
+ public static function setDefaults(&$params) {
+ if (CRM_Utils_Array::value('label', $params, NULL) === NULL) {
$params['label'] = $params['name'];
}
- if (CRM_Utils_Array::value('name', $params, NULL) === NULL){
+ if (CRM_Utils_Array::value('name', $params, NULL) === NULL) {
$params['name'] = $params['label'];
}
- if (CRM_Utils_Array::value('weight', $params, NULL) === NULL){
+ if (CRM_Utils_Array::value('weight', $params, NULL) === NULL) {
$params['weight'] = self::getDefaultWeight($params);
}
- if (CRM_Utils_Array::value('value', $params, NULL) === NULL){
+ if (CRM_Utils_Array::value('value', $params, NULL) === NULL) {
$params['value'] = self::getDefaultValue($params);
}
}
/**
- * Get next available value
+ * Get next available value.
* We will take the highest numeric value (or 0 if no numeric values exist)
* and add one. The calling function is responsible for any
* more complex decision making
*
* @return int
*/
- public static function getDefaultWeight($params){
+ public static function getDefaultWeight($params) {
return (int) CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue',
- array('option_group_id' => $params['option_group_id']));
+ array('option_group_id' => $params['option_group_id']));
}
/**
- * Get next available value
+ * Get next available value.
* We will take the highest numeric value (or 0 if no numeric values exist)
* and add one. The calling function is responsible for any
* more complex decision making
* @param array $params
*/
- public static function getDefaultValue($params){
- $bao = new CRM_Core_BAO_OptionValue();
- $bao->option_group_id = $params['option_group_id'];
- if (isset($params['domain_id'])){
- $bao->domain_id = $params['domain_id'];
- }
- $bao->selectAdd();
- $bao->whereAdd("value REGEXP '^[0-9]+$'");
- $bao->selectAdd('(ROUND(COALESCE(MAX(CONVERT(value, UNSIGNED)),0)) +1) as nextvalue');
- $bao->find(TRUE);
- return $bao->nextvalue;
+ public static function getDefaultValue($params) {
+ $bao = new CRM_Core_BAO_OptionValue();
+ $bao->option_group_id = $params['option_group_id'];
+ if (isset($params['domain_id'])) {
+ $bao->domain_id = $params['domain_id'];
+ }
+ $bao->selectAdd();
+ $bao->whereAdd("value REGEXP '^[0-9]+$'");
+ $bao->selectAdd('(ROUND(COALESCE(MAX(CONVERT(value, UNSIGNED)),0)) +1) as nextvalue');
+ $bao->find(TRUE);
+ return $bao->nextvalue;
}
+
/**
- * 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.
*
- * @return CRM_Core_BAO_OptionValue object
- * @static
+ * @return CRM_Core_BAO_OptionValue
*/
public static function retrieve(&$params, &$defaults) {
$optionValue = new CRM_Core_DAO_OptionValue();
}
/**
- * Update the is_active flag in the db
+ * Update the is_active flag in the db.
*
* @param int $id
* Id of the database record.
* @param bool $is_active
* Value we want to set the is_active field.
*
- * @return Object DAO object on sucess, null otherwise
- * @static
+ * @return Object
+ * DAO object on sucess, null otherwise
*/
public static function setIsActive($id, $is_active) {
return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_OptionValue', $id, 'is_active', $is_active);
}
/**
- * Add an Option Value
+ * Add an Option Value.
*
* @param array $params
* Reference array contains the values submitted by the form.
* @param array $ids
* Reference array contains the id.
*
- * @static
*
* @return CRM_Core_DAO_OptionValue
*/
}
/**
- * Delete Option Value
+ * Delete Option Value.
*
* @param int $optionValueId
*
- * @return boolean
+ * @return bool
*
- * @static
*/
public static function del($optionValueId) {
$optionValue = new CRM_Core_DAO_OptionValue();
}
/**
- * Retrieve activity type label and description
+ * Retrieve activity type label and description.
*
* @param int $activityTypeId
* Activity type id.
*
- * @return array label and description
- * @static
+ * @return array
+ * label and description
*/
public static function getActivityTypeDetails($activityTypeId) {
$query = "SELECT civicrm_option_value.label, civicrm_option_value.description
* @param int $id
* Id of Option Value.
*
- * @return string title
- *
- * @static
+ * @return string
+ * title
*
*/
public static function getTitle($id) {
'gender' => 'gender_id',
'individual_prefix' => 'prefix_id',
'individual_suffix' => 'suffix_id',
- 'communication_style' => 'communication_style_id', // Not only Individuals -- but the code seems to be generic for all contact types, despite the naming...
+ 'communication_style' => 'communication_style_id',
+ // Not only Individuals -- but the code seems to be generic for all contact types, despite the naming...
);
$contributions = array('payment_instrument' => 'payment_instrument_id');
- $activities = array('activity_type' => 'activity_type_id');
- $participant = array('participant_role' => 'role_id');
- $eventType = array('event_type' => 'event_type_id');
- $aclRole = array('acl_role' => 'acl_role_id');
+ $activities = array('activity_type' => 'activity_type_id');
+ $participant = array('participant_role' => 'role_id');
+ $eventType = array('event_type' => 'event_type_id');
+ $aclRole = array('acl_role' => 'acl_role_id');
$all = array_merge($individuals, $contributions, $activities, $participant, $eventType, $aclRole);
$fieldName = '';
* Options value , weight pair.
*
* @return void
- * @static
*/
public static function updateOptionWeights($opGroupId, $opWeights) {
if (!is_array($opWeights) || empty($opWeights)) {
* @param int $optionGroupID
* The option group for which we want the values from.
*
- * @return array an array of array of values for this option group
- * @static
+ * @return array
+ * an array of array of values for this option group
*/
public static function getOptionValuesArray($optionGroupID) {
// check if we can get the field values from the system cache
- $cacheKey = "CRM_Core_BAO_OptionValue_OptionGroupID_{$optionGroupID}";
- $cache = CRM_Utils_Cache::singleton();
+ $cacheKey = "CRM_Core_BAO_OptionValue_OptionGroupID_{$optionGroupID}";
+ $cache = CRM_Utils_Cache::singleton();
$optionValues = $cache->get($cacheKey);
if (empty($optionValues)) {
$dao = new CRM_Core_DAO_OptionValue();
* @param int $optionGroupID
* The option group for which we want the values from.
*
- * @return array an associative array of label, value pairs
- * @static
+ * @return array
+ * an associative array of label, value pairs
*/
public static function getOptionValuesAssocArray($optionGroupID) {
$optionValues = self::getOptionValuesArray($optionGroupID);
}
return $options;
}
+
/**
* Get the values of all option values given an option group Name as a key => value pair
* Use above cached function to make it super efficient
* @param string $optionGroupName
* The option group name for which we want the values from.
*
- * @return array an associative array of label, value pairs
- * @static
+ * @return array
+ * an associative array of label, value pairs
*/
public static function getOptionValuesAssocArrayFromName($optionGroupName) {
$dao = new CRM_Core_DAO_OptionGroup();