Refactor gender pseudoconstant to use generic get method CRM-12464
authorColeman Watts <coleman@civicrm.org>
Tue, 30 Apr 2013 20:59:04 +0000 (13:59 -0700)
committerColeman Watts <coleman@civicrm.org>
Wed, 29 May 2013 21:32:23 +0000 (14:32 -0700)
----------------------------------------
* CRM-12464: Search improvements in 4.4
  http://issues.civicrm.org/jira/browse/CRM-12464

18 files changed:
CRM/Contact/BAO/Contact.php
CRM/Contact/Form/Edit/Demographics.php
CRM/Contact/Form/Search/Criteria.php
CRM/Contact/Import/Parser/Contact.php
CRM/Contact/Page/Inline/Demographics.php
CRM/Contact/Page/View/Summary.php
CRM/Core/BAO/UFGroup.php
CRM/Core/PseudoConstant.php
CRM/Event/BAO/Event.php
CRM/Logging/Differ.php
CRM/Report/Form/Case/Demographics.php
CRM/Report/Form/Contact/CurrentEmployer.php
CRM/Report/Form/Grant/Detail.php
CRM/Report/Form/Grant/Statistics.php
CRM/Utils/DeprecatedUtils.php
api/v3/Contact.php
tests/phpunit/CRM/Contact/BAO/ContactTest.php
tools/extensions/org.civicrm.report.grant/Grant.php

index acf604d1dbb4cbf602f2c6d5aace8578040787c6..f0777d4168cb9c10177f8164fe4e481e68b2a12e 100644 (file)
@@ -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) {
index 6be0f7759762a32867248d4402fa90ece38c7680..23b4a162e322fb0d4dac9ea9a196d615d7ca23e1 100644 (file)
@@ -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,
index b79ce20edab13042094b7ae1243fad310124af0f..a26658000298f80661a84623f0ed7b89b31f2797 100644 (file)
@@ -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,
index 1516e919f9ee13c981a9fc7d9ae25e698b12241e..107665015ebaaf17088f7eb38ba7351a8c7a2f9c 100644 (file)
@@ -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;
index 057c39308570d9a38f3106f2b3b136773c045b98..8745b838b69a360d17fe64e90786b752c44929da 100644 (file)
@@ -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)];
     }
 
index 76f41682f966a2b21d39997cce70d2c236792fe3..827e6665bb33f57b83f94aa47f0efbc7d91cbc7a 100644 (file)
@@ -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)];
     }
 
index 95ca8641ae8411132a3f52823f774a6b84cf7a9a..8029cc6c3b7941f1854daeb0321073ba88d67ce7 100644 (file)
@@ -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);
       }
index af418b4d6b7ad2126b1dd0a7160588977956c84a..78be8ceaa72a0147e33270b8dac757af431a301a 100644 (file)
@@ -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.
    *
index 01c04c91bc2271c17437cfed9b099a5e36d41006..534c278fd35ec3d24370f4375956921c65d68e82 100644 (file)
@@ -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)) {
index fe22bc955284658bf050993ea3ad9bd42dbd78df..04d9a00b2604b7d51e36e74a997e2d61b2417c5e 100644 (file)
@@ -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(),
index 6ae1919c71589c08e2a4ef5672df1409ba565f3e..a86a8dea7afb9f1dca2f817dde0ddbaf84e03321 100644 (file)
@@ -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();
   }
index add585c0245ffb4e19f13516bf0c9074a6b83571..51405776b121b4be99661936e4d6f04f3a65b36d 100644 (file)
@@ -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;
index bb0e82a20a2129281ffbdb62d4858ac0b067a793..bc34d6cf272410d8a459aa1df728083e7614b7e6 100644 (file)
@@ -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'),
index 88515cf2992c6bab0af02982a459b7aa98c3f76b..26d693aecf27f2190208549cee5bd30806faf5f5 100644 (file)
@@ -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 ,
index 89ad87d6516a76b0bac0977af789f4894622b4ed..143ca2725fe36f7612e14c841cce29a6a7621cfe 100644 (file)
@@ -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 {
index b42f968bde4a1861db7188563b097cf7d1b8e0ed..bab650d5d8a84cb471e79f962af0a86e24c808e0 100644 (file)
@@ -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);
index ee2fd9e2b3559d8a6c2f3d521f6075653b31d8e6..582e7028b7ee638763b0178b3963d4f9a1e578db 100644 (file)
@@ -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.');
index 408259b584f8c7e9871be653cdb70506e43e772f..cbc24b57b98f6912587c76cc338065d5cf3e9ddd 100644 (file)
@@ -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'),
           ),
         ),
       ),