Skip to content

Commit

Permalink
Refactor gender pseudoconstant to use generic get method CRM-12464
Browse files Browse the repository at this point in the history
----------------------------------------
* CRM-12464: Search improvements in 4.4
  http://issues.civicrm.org/jira/browse/CRM-12464
  • Loading branch information
colemanw committed Apr 30, 2013
1 parent 1bd77fe commit c22c6aa
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 45 deletions.
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ static function resolveDefaults(&$defaults, $reverse = FALSE) {

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) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Form/Edit/Demographics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Form/Search/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ static function demographics(&$form) {
$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,
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Page/Inline/Demographics.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function run() {
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)];
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Page/View/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function 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)];
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/BAO/UFGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,7 @@ static function buildProfile(
}
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);
}
Expand Down
34 changes: 7 additions & 27 deletions CRM/Core/PseudoConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -112,13 +119,6 @@ class CRM_Core_PseudoConstant {
*/
private static $individualSuffix;

/**
* gender
* @var array
* @static
*/
private static $gender;

/**
* im protocols
* @var array
Expand Down Expand Up @@ -797,26 +797,6 @@ public static function &individualSuffix() {
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.
*
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/BAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$profile
}
}
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)) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ public function checkGender($gender) {
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;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Logging/Differ.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function titlesAndValuesForTable($table) {
'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(),
Expand Down
2 changes: 1 addition & 1 deletion CRM/Report/Form/Case/Demographics.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function __construct() {
);
}

$this->_genders = CRM_Core_PseudoConstant::gender();
$this->_genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');

parent::__construct();
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Report/Form/Contact/CurrentEmployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ function alterDisplay(&$rows) {
//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;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Report/Form/Grant/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function __construct() {
'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'),
Expand Down
4 changes: 2 additions & 2 deletions CRM/Report/Form/Grant/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function __construct() {
'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(
Expand Down Expand Up @@ -384,7 +384,7 @@ function alterDisplay(&$rows) {

$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 ,
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/DeprecatedUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,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 {
Expand Down
2 changes: 1 addition & 1 deletion api/v3/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Contact/BAO/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ function testResolveDefaults() {
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.');
Expand Down
2 changes: 1 addition & 1 deletion tools/extensions/org.civicrm.report.grant/Grant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
),
),
),
Expand Down

0 comments on commit c22c6aa

Please sign in to comment.