diff --git a/CRM/Grant/BAO/Grant.php b/CRM/Grant/BAO/Grant.php index 9bf6b0fd349e456e4b32afef59cfdcc828f84b97..6edf45df8cceff03dd811913c8a228608c864d0b 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 e2ff0396120b72a1534888cfbdf622b66794c2df..ff9be828092803f0c41c76a1e3de529651dffa78 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 66053c5ef1a36f3a0c4cb2855cf7a1efd142ffe5..243e4578c31aa960ccf82c77c33c3fce0980ae06 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 baa84dfca9aa5dabdeda140a998620bf9b137d67..0000000000000000000000000000000000000000 --- a/CRM/Grant/PseudoConstant.php +++ /dev/null @@ -1,116 +0,0 @@ -<?php -/* - +--------------------------------------------------------------------+ - | CiviCRM version 4.3 | - +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2013 | - +--------------------------------------------------------------------+ - | This file is a part of CiviCRM. | - | | - | CiviCRM is free software; you can copy, modify, and distribute it | - | under the terms of the GNU Affero General Public License | - | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | - | | - | CiviCRM is distributed in the hope that it will be useful, but | - | WITHOUT ANY WARRANTY; without even the implied warranty of | - | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | - | See the GNU Affero General Public License for more details. | - | | - | You should have received a copy of the GNU Affero General Public | - | License and the CiviCRM Licensing Exception along | - | with this program; if not, contact CiviCRM LLC | - | at info[AT]civicrm[DOT]org. If you have questions about the | - | GNU Affero General Public License or the licensing of CiviCRM, | - | see the CiviCRM license FAQ at http://civicrm.org/licensing | - +--------------------------------------------------------------------+ -*/ - -/** - * - * @package CRM - * @copyright CiviCRM LLC (c) 2004-2013 - * $Id$ - * - */ - -/** - * This class holds all the Pseudo constants that are specific to Grant. This avoids - * polluting the core class and isolates the Grant - */ -class CRM_Grant_PseudoConstant extends CRM_Core_PseudoConstant { - - /** - * Grant Status - * - * @var array - * @static - */ - private static $grantStatus; - - /** - * grant Type - * - * @var array - * @static - */ - private static $grantType; - - /** - * Get all the n grant statuses - * - * @access public - * - * @return array - array reference of all grant statuses if any - * @static - */ - public static function &grantStatus($id = NULL) { - if (!self::$grantStatus) { - self::$grantStatus = array(); - self::$grantStatus = CRM_Core_OptionGroup::values('grant_status'); - } - - if ($id) { - return self::$grantStatus[$id]; - } - - return self::$grantStatus; - } - - /** - * Get all the n grant types - * - * @access public - * - * @return array - array reference of all grant types if any - * @static - */ - public static function &grantType($id = NULL) { - if (!self::$grantType) { - self::$grantType = array(); - self::$grantType = CRM_Core_OptionGroup::values('grant_type'); - } - - If ($id) { - return self::$grantType[$id]; - } - - return self::$grantType; - } - - /** - * Flush given pseudoconstant so it can be reread from db - * nex time it's requested. - * - * @access public - * @static - * - * @param boolean $name pseudoconstant to be flushed - * - */ - public static function flush($name = 'cache') { - if (isset(self::$$name)) { - self::$$name = NULL; - } - } -} - diff --git a/CRM/Report/Form/Grant/Detail.php b/CRM/Report/Form/Grant/Detail.php index bc34d6cf272410d8a459aa1df728083e7614b7e6..edaa9abab4c5d59376031f2f0120543ea80c689e 100644 --- a/CRM/Report/Form/Grant/Detail.php +++ b/CRM/Report/Form/Grant/Detail.php @@ -161,14 +161,14 @@ class CRM_Report_Form_Grant_Detail 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( @@ -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 b6b1ac4eb98284d97a3402da581f1a964f92399b..22eea407bb6030523bb238dfe7c2221680256360 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 aaf724554cda32716dabe3cd37dbc2db8dc35029..e0a035a61e9c1156a4aa279c75ce01b249e8cf66 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 cbc24b57b98f6912587c76cc338065d5cf3e9ddd..1b05089313fe44c51807fb49246f232a6b3cfafb 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 7560a4036bbcf9277922722c6cfb27d6a0bda4b8..3199c5a1190f92b6c2946481fd2e6ead79e02866 100644 --- a/xml/schema/Grant/Grant.xml +++ b/xml/schema/Grant/Grant.xml @@ -92,6 +92,9 @@ <index> <name>index_grant_type_id</name> <fieldName>grant_type_id</fieldName> + <pseudoconstant> + <optionGroupName>grant_type</optionGroupName> + </pseudoconstant> <add>1.8</add> </index> <field> @@ -163,6 +166,9 @@ <import>true</import> <export>false</export> <comment>Id of Grant status.</comment> + <pseudoconstant> + <optionGroupName>grant_status</optionGroupName> + </pseudoconstant> <add>1.8</add> </field> <index>