From 729e3a33d987e0e5e2af6d801577d2bb96493cb5 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 22 Jun 2016 10:40:07 +1200 Subject: [PATCH] Port missing function in 4.6. Also some minor code style syncs. --- CRM/Core/BAO/OptionGroup.php | 32 +++++++++++++++++++++++++++++--- CRM/Core/OptionGroup.php | 15 +++++++-------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/CRM/Core/BAO/OptionGroup.php b/CRM/Core/BAO/OptionGroup.php index 276d9b25c0..995db1522f 100644 --- a/CRM/Core/BAO/OptionGroup.php +++ b/CRM/Core/BAO/OptionGroup.php @@ -3,7 +3,7 @@ +--------------------------------------------------------------------+ | CiviCRM version 4.6 | +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2015 | + | Copyright CiviCRM LLC (c) 2004-2016 | +--------------------------------------------------------------------+ | This file is a part of CiviCRM. | | | @@ -28,7 +28,7 @@ /** * * @package CRM - * @copyright CiviCRM LLC (c) 2004-2015 + * @copyright CiviCRM LLC (c) 2004-2016 * $Id$ * */ @@ -70,7 +70,7 @@ class CRM_Core_BAO_OptionGroup extends CRM_Core_DAO_OptionGroup { * Value we want to set the is_active field. * * @return Object - * DAO object on sucess, null otherwise + * DAO object on success, null otherwise */ public static function setIsActive($id, $is_active) { return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_OptionGroup', $id, 'is_active', $is_active); @@ -141,4 +141,30 @@ class CRM_Core_BAO_OptionGroup extends CRM_Core_DAO_OptionGroup { return $optionGroup->name; } + /** + * Ensure an option group exists. + * + * This function is intended to be called from the upgrade script to ensure + * that an option group exists, without hitting an error if it already exists. + * + * This is sympathetic to sites who might pre-add it. + * + * @param array $params + * + * @return int + * ID of the option group. + */ + public static function ensureOptionGroupExists($params) { + $existingValues = civicrm_api3('OptionGroup', 'get', array( + 'name' => $params['name'], + )); + if (!$existingValues['count']) { + $result = civicrm_api3('OptionGroup', 'create', $params); + return $result['id']; + } + else { + return $existingValues['id']; + } + } + } diff --git a/CRM/Core/OptionGroup.php b/CRM/Core/OptionGroup.php index 9756837f5e..fd9475571a 100644 --- a/CRM/Core/OptionGroup.php +++ b/CRM/Core/OptionGroup.php @@ -28,9 +28,7 @@ /** * * @package CRM - * @copyright CiviCRM LLC (c) 2004-2015 - * $Id$ - * + * @copyright CiviCRM LLC (c) 2004-2016 */ class CRM_Core_OptionGroup { static $_values = array(); @@ -89,7 +87,7 @@ class CRM_Core_OptionGroup { * This function retrieves all the values for the specific option group by name * 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 + * 'label' in the label column and the 'id' or 'name' in the value column * * @param string $name * name of the option group. @@ -201,7 +199,7 @@ WHERE v.option_group_id = g.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 + * 'label' in the label column and the 'id' or 'name' in the value column * * @param int $id * id of the option group. @@ -272,9 +270,6 @@ WHERE v.option_group_id = g.id * * * @param bool $flip - * - * @return void - * */ public static function lookupValues(&$params, &$names, $flip = FALSE) { foreach ($names as $postName => $value) { @@ -368,6 +363,10 @@ WHERE v.option_group_id = g.id } /** + * @deprecated + * + * This function is not cached. + * * @param string $groupName * @param $label * @param string $labelField -- 2.25.1