From fb1fd730b9e00091b5f32a031faffc3b93c85559 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 4 May 2013 16:29:10 -0700 Subject: [PATCH] Remove grant pseudoconstants CRM-12464 ---------------------------------------- * CRM-12464: Search improvements in 4.4 http://issues.civicrm.org/jira/browse/CRM-12464 --- CRM/Grant/BAO/Grant.php | 4 +- CRM/Grant/Form/GrantView.php | 4 +- CRM/Grant/Form/Task/Update.php | 2 +- CRM/Grant/PseudoConstant.php | 116 ------------------ CRM/Report/Form/Grant/Detail.php | 8 +- CRM/Report/Form/Grant/Statistics.php | 8 +- tests/phpunit/CRM/Core/PseudoConstantTest.php | 10 ++ .../org.civicrm.report.grant/Grant.php | 9 +- xml/schema/Grant/Grant.xml | 6 + 9 files changed, 33 insertions(+), 134 deletions(-) delete mode 100644 CRM/Grant/PseudoConstant.php diff --git a/CRM/Grant/BAO/Grant.php b/CRM/Grant/BAO/Grant.php index 9bf6b0fd34..6edf45df8c 100644 --- a/CRM/Grant/BAO/Grant.php +++ b/CRM/Grant/BAO/Grant.php @@ -65,7 +65,7 @@ class CRM_Grant_BAO_Grant extends CRM_Grant_DAO_Grant { $status = array(); $summary = array(); $summary['total_grants'] = NULL; - $status = CRM_Grant_PseudoConstant::grantStatus(); + $status = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'); foreach ($status as $id => $name) { $stats[$id] = array( @@ -204,7 +204,7 @@ class CRM_Grant_BAO_Grant extends CRM_Grant_DAO_Grant { "action=view&reset=1&id={$grant->id}&cid={$grant->contact_id}&context=home" ); - $grantTypes = CRM_Grant_PseudoConstant::grantType(); + $grantTypes = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id'); if (!CRM_Utils_Array::value('skipRecentView', $params)) { if(!isset($grant->contact_id) || !isset($grant->grant_type_id)){ $grant->find(TRUE); diff --git a/CRM/Grant/Form/GrantView.php b/CRM/Grant/Form/GrantView.php index e2ff039612..ff9be82809 100644 --- a/CRM/Grant/Form/GrantView.php +++ b/CRM/Grant/Form/GrantView.php @@ -54,8 +54,8 @@ class CRM_Grant_Form_GrantView extends CRM_Core_Form { $values = array(); $params['id'] = $this->_id; CRM_Grant_BAO_Grant::retrieve($params, $values); - $grantType = CRM_Grant_PseudoConstant::grantType(); - $grantStatus = CRM_Grant_PseudoConstant::grantStatus(); + $grantType = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id'); + $grantStatus = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'); $this->assign('grantType', $grantType[$values['grant_type_id']]); $this->assign('grantStatus', $grantStatus[$values['status_id']]); $grantTokens = array( diff --git a/CRM/Grant/Form/Task/Update.php b/CRM/Grant/Form/Task/Update.php index 66053c5ef1..243e4578c3 100644 --- a/CRM/Grant/Form/Task/Update.php +++ b/CRM/Grant/Form/Task/Update.php @@ -63,7 +63,7 @@ class CRM_Grant_Form_Task_Update extends CRM_Grant_Form_Task { * @return void */ function buildQuickForm() { - $grantStatus = CRM_Grant_PseudoConstant::grantStatus(); + $grantStatus = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'); $this->addElement('select', 'status_id', ts('Grant Status'), array('' => '') + $grantStatus); $this->addElement('text', 'amount_granted', ts('Amount Granted')); diff --git a/CRM/Grant/PseudoConstant.php b/CRM/Grant/PseudoConstant.php deleted file mode 100644 index baa84dfca9..0000000000 --- a/CRM/Grant/PseudoConstant.php +++ /dev/null @@ -1,116 +0,0 @@ - 'grant_type_id', 'title' => ts('Grant Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Grant_PseudoConstant::grantType(), + 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id'), ), 'status_id' => array( 'name' => 'status_id', 'title' => ts('Grant Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Grant_PseudoConstant::grantStatus(), + 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'), ), 'amount_granted' => array( @@ -360,13 +360,13 @@ class CRM_Report_Form_Grant_Detail extends CRM_Report_Form { if (array_key_exists('civicrm_grant_grant_type_id', $row)) { if ($value = $row['civicrm_grant_grant_type_id']) { - $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Grant_PseudoConstant::grantType($value); + $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Core_PseudoConstant::getValue('CRM_Grant_DAO_Grant', 'grant_type_id', $value); } $entryFound = TRUE; } if (array_key_exists('civicrm_grant_status_id', $row)) { if ($value = $row['civicrm_grant_status_id']) { - $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Grant_PseudoConstant::grantStatus($value); + $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Core_PseudoConstant::getValue('CRM_Grant_DAO_Grant', 'status_id', $value); } $entryFound = TRUE; } diff --git a/CRM/Report/Form/Grant/Statistics.php b/CRM/Report/Form/Grant/Statistics.php index b6b1ac4eb9..22eea407bb 100644 --- a/CRM/Report/Form/Grant/Statistics.php +++ b/CRM/Report/Form/Grant/Statistics.php @@ -114,14 +114,14 @@ class CRM_Report_Form_Grant_Statistics extends CRM_Report_Form { 'name' => 'grant_type_id', 'title' => ts('Grant Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Grant_PseudoConstant::grantType(), + 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id'), ), 'status_id' => array( 'name' => 'status_id', 'title' => ts('Grant Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Grant_PseudoConstant::grantStatus(), + 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'), ), 'amount_requested' => array( @@ -285,7 +285,7 @@ class CRM_Report_Form_Grant_Statistics extends CRM_Report_Form { } function where() { - $approved = array_search( 'Approved', CRM_Grant_PseudoConstant::grantStatus( ) ); + $approved = CRM_Core_PseudoConstant::getKey('CRM_Grant_DAO_Grant', 'status_id', 'Approved', array('labelColumn' => 'name')); $whereClause = " WHERE {$this->_aliases['civicrm_grant']}.amount_total IS NOT NULL AND {$this->_aliases['civicrm_grant']}.amount_total > 0"; @@ -381,7 +381,7 @@ WHERE {$this->_aliases['civicrm_grant']}.amount_total IS NOT NULL $awardedGrantsAmount = $grantsReceived = $totalAmount = $awardedGrants = $grantReportsReceived = 0; $grantStatistics = array(); - $grantTypes = CRM_Grant_PseudoConstant::grantType(); + $grantTypes = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id'); $countries = CRM_Core_PseudoConstant::country(); $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); diff --git a/tests/phpunit/CRM/Core/PseudoConstantTest.php b/tests/phpunit/CRM/Core/PseudoConstantTest.php index aaf724554c..e0a035a61e 100644 --- a/tests/phpunit/CRM/Core/PseudoConstantTest.php +++ b/tests/phpunit/CRM/Core/PseudoConstantTest.php @@ -477,6 +477,16 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { 'sample' => 'Approved', ), ), + 'CRM_Grant_DAO_Grant' => array( + array( + 'fieldName' => 'status_id', + 'sample' => 'Approved', + ), + array( + 'fieldName' => 'grant_type_id', + 'sample' => 'Emergency', + ), + ), ); foreach ($fields as $daoName => $daoFields) { diff --git a/tools/extensions/org.civicrm.report.grant/Grant.php b/tools/extensions/org.civicrm.report.grant/Grant.php index cbc24b57b9..1b05089313 100644 --- a/tools/extensions/org.civicrm.report.grant/Grant.php +++ b/tools/extensions/org.civicrm.report.grant/Grant.php @@ -34,7 +34,6 @@ */ require_once 'CRM/Report/Form.php'; -require_once 'CRM/Grant/PseudoConstant.php'; class org_civicrm_report_grant extends CRM_Report_Form { protected $_addressField = FALSE; function __construct() { @@ -136,14 +135,14 @@ class org_civicrm_report_grant extends CRM_Report_Form { 'name' => 'grant_type_id', 'title' => ts('Grant Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Grant_PseudoConstant::grantType(), + 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id'), ), 'status_id' => array( 'name' => 'status_id', 'title' => ts('Grant Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Grant_PseudoConstant::grantStatus(), + 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'), ), 'amount_granted' => array( @@ -308,13 +307,13 @@ class org_civicrm_report_grant extends CRM_Report_Form { foreach ($rows as $rowNum => $row) { if (array_key_exists('civicrm_grant_grant_type_id', $row)) { if ($value = $row['civicrm_grant_grant_type_id']) { - $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Grant_PseudoConstant::grantType($value); + $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Core_PseudoConstant::getValue('CRM_Grant_DAO_Grant', 'grant_type_id', $value); } $entryFound = TRUE; } if (array_key_exists('civicrm_grant_status_id', $row)) { if ($value = $row['civicrm_grant_status_id']) { - $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Grant_PseudoConstant::grantStatus($value); + $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Core_PseudoConstant::getValue('CRM_Grant_DAO_Grant', 'status_id', $value); } $entryFound = TRUE; } diff --git a/xml/schema/Grant/Grant.xml b/xml/schema/Grant/Grant.xml index 7560a4036b..3199c5a119 100644 --- a/xml/schema/Grant/Grant.xml +++ b/xml/schema/Grant/Grant.xml @@ -92,6 +92,9 @@ index_grant_type_id grant_type_id + + grant_type + 1.8 @@ -163,6 +166,9 @@ true false Id of Grant status. + + grant_status + 1.8 -- 2.25.1