From 26cf88b561cc3ccdc7f9cbbed8dbc1bb06bd3dc1 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 30 Apr 2013 13:59:04 -0700 Subject: [PATCH] Refactor gender pseudoconstant to use generic get method CRM-12464 ---------------------------------------- * CRM-12464: Search improvements in 4.4 http://issues.civicrm.org/jira/browse/CRM-12464 --- CRM/Contact/BAO/Contact.php | 2 +- CRM/Contact/Form/Edit/Demographics.php | 2 +- CRM/Contact/Form/Search/Criteria.php | 2 +- CRM/Contact/Import/Parser/Contact.php | 2 +- CRM/Contact/Page/Inline/Demographics.php | 2 +- CRM/Contact/Page/View/Summary.php | 2 +- CRM/Core/BAO/UFGroup.php | 2 +- CRM/Core/PseudoConstant.php | 34 ++++--------------- CRM/Event/BAO/Event.php | 2 +- CRM/Logging/Differ.php | 2 +- CRM/Report/Form/Case/Demographics.php | 2 +- CRM/Report/Form/Contact/CurrentEmployer.php | 2 +- CRM/Report/Form/Grant/Detail.php | 2 +- CRM/Report/Form/Grant/Statistics.php | 4 +-- CRM/Utils/DeprecatedUtils.php | 2 +- api/v3/Contact.php | 2 +- tests/phpunit/CRM/Contact/BAO/ContactTest.php | 2 +- .../org.civicrm.report.grant/Grant.php | 2 +- 18 files changed, 25 insertions(+), 45 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index acf604d1db..f0777d4168 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -520,7 +520,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); CRM_Utils_Array::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::individualPrefix(), $reverse); CRM_Utils_Array::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::individualSuffix(), $reverse); - CRM_Utils_Array::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::gender(), $reverse); + CRM_Utils_Array::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), $reverse); //lookup value of email/postal greeting, addressee, CRM-4575 foreach (self::$_greetingTypes as $greeting) { diff --git a/CRM/Contact/Form/Edit/Demographics.php b/CRM/Contact/Form/Edit/Demographics.php index 6be0f77597..23b4a162e3 100644 --- a/CRM/Contact/Form/Edit/Demographics.php +++ b/CRM/Contact/Form/Edit/Demographics.php @@ -50,7 +50,7 @@ class CRM_Contact_Form_Edit_Demographics { static function buildQuickForm(&$form) { // radio button for gender $genderOptions = array(); - $gender = CRM_Core_PseudoConstant::gender(TRUE); + $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id', array('localize' => TRUE)); foreach ($gender as $key => $var) { $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key, diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index b79ce20eda..a266580002 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -470,7 +470,7 @@ class CRM_Contact_Form_Search_Criteria { $form->add('hidden', 'hidden_demographics', 1); // radio button for gender $genderOptions = array(); - $gender = CRM_Core_PseudoConstant::gender(); + $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); foreach ($gender as $key => $var) { $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key, diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 1516e919f9..107665015e 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -1305,7 +1305,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser { return FALSE; } - $allGenders = CRM_Core_PseudoConstant::gender(); + $allGenders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); foreach ($allGenders as $key => $value) { if (strlen($gender) > strlen($value)) { continue; diff --git a/CRM/Contact/Page/Inline/Demographics.php b/CRM/Contact/Page/Inline/Demographics.php index 057c393085..8745b838b6 100644 --- a/CRM/Contact/Page/Inline/Demographics.php +++ b/CRM/Contact/Page/Inline/Demographics.php @@ -58,7 +58,7 @@ class CRM_Contact_Page_Inline_Demographics extends CRM_Core_Page { CRM_Contact_BAO_Contact::getValues( $params, $defaults ); if (CRM_Utils_Array::value('gender_id', $defaults)) { - $gender = CRM_Core_PseudoConstant::gender(); + $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)]; } diff --git a/CRM/Contact/Page/View/Summary.php b/CRM/Contact/Page/View/Summary.php index 76f41682f9..827e6665bb 100644 --- a/CRM/Contact/Page/View/Summary.php +++ b/CRM/Contact/Page/View/Summary.php @@ -198,7 +198,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { } if (CRM_Utils_Array::value('gender_id', $defaults)) { - $gender = CRM_Core_PseudoConstant::gender(TRUE); + $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id', array('localize' => TRUE)); $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)]; } diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 95ca8641ae..8029cc6c3b 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -1831,7 +1831,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) } elseif ($fieldName === 'gender') { $genderOptions = array(); - $gender = CRM_Core_PseudoConstant::gender(); + $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); foreach ($gender as $key => $var) { $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key); } diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index af418b4d6b..78be8ceaa7 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -56,6 +56,13 @@ class CRM_Core_PseudoConstant { */ private static $cache; + /** + * static cache for pseudoconstant arrays + * @var array + * @static + */ + private static $cache; + /** * location type * @var array @@ -112,13 +119,6 @@ class CRM_Core_PseudoConstant { */ private static $individualSuffix; - /** - * gender - * @var array - * @static - */ - private static $gender; - /** * im protocols * @var array @@ -792,26 +792,6 @@ class CRM_Core_PseudoConstant { return self::$individualSuffix; } - /** - * Get all Gender. - * - * The static array gender is returned - * - * @access public - * @static - * - * @param boolean $all - get All Gender - default is to get only active ones. - * - * @return array - array reference of all gender. - * - */ - public static function &gender($localize = FALSE) { - if (!self::$gender) { - self::$gender = CRM_Core_OptionGroup::values('gender', FALSE, FALSE, $localize); - } - return self::$gender; - } - /** * Get all the IM Providers from database. * diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 01c04c91bc..534c278fd3 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -1380,7 +1380,7 @@ WHERE civicrm_event.is_active = 1 } } elseif ('gender' == substr($name, 0, 6)) { - $gender = CRM_Core_PseudoConstant::gender(); + $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); $values[$index] = $gender[$params[$name]]; } elseif ('individual_prefix' == substr($name, 0, 17)) { diff --git a/CRM/Logging/Differ.php b/CRM/Logging/Differ.php index fe22bc9552..04d9a00b26 100644 --- a/CRM/Logging/Differ.php +++ b/CRM/Logging/Differ.php @@ -234,7 +234,7 @@ WHERE log_conn_id = %1 AND 'contribution_status_id' => CRM_Contribute_PseudoConstant::contributionStatus(), 'financial_type_id' => CRM_Contribute_PseudoConstant::financialType(), 'country_id' => CRM_Core_PseudoConstant::country(), - 'gender_id' => CRM_Core_PseudoConstant::gender(), + 'gender_id' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), 'location_type_id' => CRM_Core_PseudoConstant::locationType(), 'payment_instrument_id' => CRM_Contribute_PseudoConstant::paymentInstrument(), 'phone_type_id' => CRM_Core_PseudoConstant::phoneType(), diff --git a/CRM/Report/Form/Case/Demographics.php b/CRM/Report/Form/Case/Demographics.php index 6ae1919c71..a86a8dea7a 100644 --- a/CRM/Report/Form/Case/Demographics.php +++ b/CRM/Report/Form/Case/Demographics.php @@ -234,7 +234,7 @@ where (cg.extends='Contact' OR cg.extends='Individual' OR cg.extends_entity_colu ); } - $this->_genders = CRM_Core_PseudoConstant::gender(); + $this->_genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); parent::__construct(); } diff --git a/CRM/Report/Form/Contact/CurrentEmployer.php b/CRM/Report/Form/Contact/CurrentEmployer.php index add585c024..51405776b1 100644 --- a/CRM/Report/Form/Contact/CurrentEmployer.php +++ b/CRM/Report/Form/Contact/CurrentEmployer.php @@ -331,7 +331,7 @@ FROM civicrm_contact {$this->_aliases['civicrm_contact']} //handle gender if (array_key_exists('civicrm_contact_gender_id', $row)) { if ($value = $row['civicrm_contact_gender_id']) { - $gender = CRM_Core_PseudoConstant::gender(); + $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); $rows[$rowNum]['civicrm_contact_gender_id'] = $gender[$value]; } $entryFound = TRUE; diff --git a/CRM/Report/Form/Grant/Detail.php b/CRM/Report/Form/Grant/Detail.php index bb0e82a20a..bc34d6cf27 100644 --- a/CRM/Report/Form/Grant/Detail.php +++ b/CRM/Report/Form/Grant/Detail.php @@ -68,7 +68,7 @@ class CRM_Report_Form_Grant_Detail extends CRM_Report_Form { 'gender_id' => array('title' => ts('Gender'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Core_PseudoConstant::gender(), + 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), ), 'id' => array('title' => ts('Contact ID'), diff --git a/CRM/Report/Form/Grant/Statistics.php b/CRM/Report/Form/Grant/Statistics.php index 88515cf299..26d693aecf 100644 --- a/CRM/Report/Form/Grant/Statistics.php +++ b/CRM/Report/Form/Grant/Statistics.php @@ -174,7 +174,7 @@ class CRM_Report_Form_Grant_Statistics extends CRM_Report_Form { 'name' => 'gender_id', 'title' => ts('Gender'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Core_PseudoConstant::gender(), + 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), ), 'contact_type' => array( @@ -383,7 +383,7 @@ WHERE {$this->_aliases['civicrm_grant']}.amount_total IS NOT NULL $grantTypes = CRM_Grant_PseudoConstant::grantType(); $countries = CRM_Core_PseudoConstant::country(); - $gender = CRM_Core_PseudoConstant::gender(); + $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); $grantAmountTotal = " SELECT COUNT({$this->_aliases['civicrm_grant']}.id) as count , diff --git a/CRM/Utils/DeprecatedUtils.php b/CRM/Utils/DeprecatedUtils.php index 89ad87d651..143ca2725f 100644 --- a/CRM/Utils/DeprecatedUtils.php +++ b/CRM/Utils/DeprecatedUtils.php @@ -868,7 +868,7 @@ function _civicrm_api3_deprecated_add_formatted_param(&$values, &$params) { if (isset($values['gender'])) { if (CRM_Utils_Array::value('gender_id', $params)) { $genders = array(); - $genders = CRM_Core_PseudoConstant::gender(); + $genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); $params['gender'] = $genders[$params['gender_id']]; } else { diff --git a/api/v3/Contact.php b/api/v3/Contact.php index b42f968bde..bab650d5d8 100644 --- a/api/v3/Contact.php +++ b/api/v3/Contact.php @@ -94,7 +94,7 @@ function civicrm_api3_contact_create($params) { } if (isset($params['gender_id']) && !(is_numeric($params['gender_id']))) { - $params['gender_id'] = array_search($params['gender_id'], CRM_Core_PseudoConstant::gender()); + $params['gender_id'] = array_search($params['gender_id'], CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id')); } $error = _civicrm_api3_greeting_format_params($params); diff --git a/tests/phpunit/CRM/Contact/BAO/ContactTest.php b/tests/phpunit/CRM/Contact/BAO/ContactTest.php index ee2fd9e2b3..582e7028b7 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactTest.php @@ -522,7 +522,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { CRM_Contact_BAO_Contact::resolveDefaults($params); //check the resolve values. - $genders = CRM_Core_PseudoConstant::gender(); + $genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); $this->assertEquals($genders[$params['gender_id']], $params['gender'], 'Check for gender.'); $prefix = CRM_Core_PseudoConstant::individualPrefix(); $this->assertEquals($prefix[$params['prefix_id']], $params['prefix'], 'Check for prefix.'); diff --git a/tools/extensions/org.civicrm.report.grant/Grant.php b/tools/extensions/org.civicrm.report.grant/Grant.php index 408259b584..cbc24b57b9 100644 --- a/tools/extensions/org.civicrm.report.grant/Grant.php +++ b/tools/extensions/org.civicrm.report.grant/Grant.php @@ -57,7 +57,7 @@ class org_civicrm_report_grant extends CRM_Report_Form { 'gender_id' => array('title' => ts('Gender'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Core_PseudoConstant::gender(), + 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), ), ), ), -- 2.25.1