From 2158332a5db99597790ba3f845f4abd361f6ad3c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 3 May 2013 18:43:12 -0700 Subject: [PATCH] Remove PCP pseudoconstant CRM-12464 ---------------------------------------- * CRM-12464: http://issues.civicrm.org/jira/browse/CRM-12464 --- CRM/Core/DAO.php | 3 +- CRM/Core/PseudoConstant.php | 5 +- CRM/PCP/BAO/PCP.php | 6 +- CRM/PCP/Form/PCP.php | 8 +- CRM/PCP/Page/PCPInfo.php | 2 +- CRM/PCP/PseudoConstant.php | 109 ------------------ tests/phpunit/CRM/Core/FieldOptionsTest.php | 2 +- tests/phpunit/CRM/Core/PseudoConstantTest.php | 24 +++- xml/schema/Event/Event.xml | 2 - xml/schema/Event/Participant.xml | 6 +- xml/schema/PCP/PCP.xml | 5 +- 11 files changed, 45 insertions(+), 127 deletions(-) delete mode 100644 CRM/PCP/PseudoConstant.php diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 23b47be3a5..ecf28df3fc 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -1771,13 +1771,14 @@ EOS; /** * Get options for the called BAO object's field. * This function can be overridden by each BAO to add more logic related to context. + * The overriding function will generally call the lower-level CRM_Core_PseudoConstant::get * * @param String $fieldName * @param String $context: e.g. "search" "edit" "create" "view" * @param Array $props: whatever is known about this bao object */ public static function buildOptions($fieldName, $context = NULL, $props = array()) { - // If a given bao does not override this function, it can still be called on that bao + // If a given bao does not override this function $baoName = get_called_class(); return CRM_Core_PseudoConstant::get($baoName, $fieldName); } diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index e795035c22..b9552da6ef 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -277,8 +277,11 @@ class CRM_Core_PseudoConstant { $output = self::$cache[$cacheKey]; } else { - // Get list of fields for the option table $daoName = CRM_Core_AllCoreTables::getClassForTable($pseudoconstant['table']); + if (!class_exists($daoName)) { + return FALSE; + } + // Get list of fields for the option table $dao = new $daoName; $availableFields = array_keys($dao->fieldKeys()); if (in_array('is_active', $availableFields)) { diff --git a/CRM/PCP/BAO/PCP.php b/CRM/PCP/BAO/PCP.php index edc94d6323..87056f815b 100644 --- a/CRM/PCP/BAO/PCP.php +++ b/CRM/PCP/BAO/PCP.php @@ -452,7 +452,7 @@ WHERE pcp.id = %1 AND cc.contribution_status_id =1 AND cc.is_test = 0"; $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name'); - $pcpStatus = CRM_PCP_PseudoConstant::pcpStatus(); + $pcpStatus = CRM_Core_OptionGroup::values("pcp_status"); $params = array('id' => $pcpId); CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo); @@ -564,7 +564,7 @@ WHERE pcp.id = %1 AND cc.contribution_status_id =1 AND cc.is_test = 0"; $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $id, 'title'); $pcpPageType = CRM_Core_DAO::getFieldValue( 'CRM_PCP_DAO_PCP', $id, 'page_type' ); - $pcpStatus = CRM_PCP_PseudoConstant::pcpStatus(); + $pcpStatus = CRM_Core_OptionGroup::values("pcp_status"); $pcpStatus = $pcpStatus[$is_active]; CRM_Core_Session::setStatus(ts("%1 status has been updated to %2.", array(1 => $pcpTitle, 2 => $pcpStatus)), 'Status Updated', 'success'); @@ -592,7 +592,7 @@ WHERE pcp.id = %1 AND cc.contribution_status_id =1 AND cc.is_test = 0"; * */ static function sendStatusUpdate($pcpId, $newStatus, $isInitial = FALSE, $component = 'contribute') { - $pcpStatus = CRM_PCP_PseudoConstant::pcpStatus(); + $pcpStatus = CRM_Core_OptionGroup::values("pcp_status"); $config = CRM_Core_Config::singleton(); if (!isset($pcpStatus[$newStatus])) { diff --git a/CRM/PCP/Form/PCP.php b/CRM/PCP/Form/PCP.php index 62e45cd366..a0b2e905d2 100644 --- a/CRM/PCP/Form/PCP.php +++ b/CRM/PCP/Form/PCP.php @@ -163,8 +163,12 @@ class CRM_PCP_Form_PCP extends CRM_Core_Form { } else { - $status = array('' => ts('- select -')) + CRM_PCP_PseudoConstant::pcpStatus(); - $types = array('' => ts('- select -')) + CRM_PCP_PseudoConstant::pcpType(); + $status = array('' => ts('- select -')) + CRM_Core_OptionGroup::values("pcp_status"); + $types = array( + '' => ts('- select -'), + 'contribute' => ts('Contribution'), + 'event' => ts('Event'), + ); $contribPages = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(); $eventPages = array('' => ts('- select -')) + CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )"); diff --git a/CRM/PCP/Page/PCPInfo.php b/CRM/PCP/Page/PCPInfo.php index 697140e37b..7c7095363b 100644 --- a/CRM/PCP/Page/PCPInfo.php +++ b/CRM/PCP/Page/PCPInfo.php @@ -78,7 +78,7 @@ class CRM_PCP_Page_PCPInfo extends CRM_Core_Page { CRM_Utils_System::setTitle($pcpInfo['title']); $this->assign('pcp', $pcpInfo); - $pcpStatus = CRM_PCP_PseudoConstant::pcpStatus(); + $pcpStatus = CRM_Core_OptionGroup::values("pcp_status"); $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name'); // check if PCP is created by anonymous user diff --git a/CRM/PCP/PseudoConstant.php b/CRM/PCP/PseudoConstant.php deleted file mode 100644 index 80ac08f512..0000000000 --- a/CRM/PCP/PseudoConstant.php +++ /dev/null @@ -1,109 +0,0 @@ - 'Contribution', - 'event' => 'Event', - ); - } - return self::$pcpType; - } - - /** - * Get all the PCP status - * - * @access public - * - * @return array - array reference of all PCP status - * @static - */ - public static function &pcpStatus() { - self::$pcpStatus = array(); - if (!self::$pcpStatus) { - self::$pcpStatus = CRM_Core_OptionGroup::values("pcp_status"); - } - return self::$pcpStatus; - } - - /** - * 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) { - if (isset(self::$$name)) { - self::$$name = NULL; - } - } -} - diff --git a/tests/phpunit/CRM/Core/FieldOptionsTest.php b/tests/phpunit/CRM/Core/FieldOptionsTest.php index 302947d595..d3441a1443 100644 --- a/tests/phpunit/CRM/Core/FieldOptionsTest.php +++ b/tests/phpunit/CRM/Core/FieldOptionsTest.php @@ -28,7 +28,7 @@ require_once 'CiviTest/CiviUnitTestCase.php'; /** - * Tests for linking to resource files + * Tests for field options */ class CRM_Core_FieldOptionsTest extends CiviUnitTestCase { function get_info() { diff --git a/tests/phpunit/CRM/Core/PseudoConstantTest.php b/tests/phpunit/CRM/Core/PseudoConstantTest.php index 26360f86e4..695191f393 100644 --- a/tests/phpunit/CRM/Core/PseudoConstantTest.php +++ b/tests/phpunit/CRM/Core/PseudoConstantTest.php @@ -28,7 +28,7 @@ require_once 'CiviTest/CiviUnitTestCase.php'; /** - * Tests for linking to resource files + * Tests for pseudoconstant retrieval */ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { function get_info() { @@ -397,6 +397,28 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { 'sample' => 'Yahoo', ), ), + 'CRM_Event_DAO_Participant' => array( + array( + 'fieldName' => 'status_id', + 'sample' => 'Registered', + ), + array( + 'fieldName' => 'role_id', + 'sample' => 'Speaker', + ), + ), + 'CRM_Event_DAO_Event' => array( + array( + 'fieldName' => 'event_type_id', + 'sample' => 'Fundraiser', + ), + ), + 'CRM_PCP_DAO_PCP' => array( + array( + 'fieldName' => 'status_id', + 'sample' => 'Approved', + ), + ), ); foreach ($fields as $daoName => $daoFields) { diff --git a/xml/schema/Event/Event.xml b/xml/schema/Event/Event.xml index 2e3f4aa9a5..3a7f88801c 100644 --- a/xml/schema/Event/Event.xml +++ b/xml/schema/Event/Event.xml @@ -60,9 +60,7 @@ Event Type ID 0 - eventType event_type - CRM_Event_PseudoConstant Event Type ID.Implicit FK to civicrm_option_value where option_group = event_type. 1.7 diff --git a/xml/schema/Event/Participant.xml b/xml/schema/Event/Participant.xml index 1d5a9a3b6e..1d6f07bf0a 100644 --- a/xml/schema/Event/Participant.xml +++ b/xml/schema/Event/Participant.xml @@ -67,11 +67,9 @@ Participant status ID. FK to civicrm_participant_status_type. Default of 1 should map to status = Registered. 1.7 - participantStatus - civicrm_participant_status
+ civicrm_participant_status_type
id name - CRM_Event_PseudoConstant
@@ -90,9 +88,7 @@ participant_role_id Participant Role Id - participantRole participant_role - CRM_Event_PseudoConstant /(participant.)?(role)$/i true diff --git a/xml/schema/PCP/PCP.xml b/xml/schema/PCP/PCP.xml index 5cde13f68b..b009a5e4d7 100644 --- a/xml/schema/PCP/PCP.xml +++ b/xml/schema/PCP/PCP.xml @@ -41,6 +41,9 @@ true int unsigned 2.2 + + pcp_status + title @@ -97,7 +100,7 @@ varchar 64 'contribute' - 2.2 + 2.2 pcp_block_id -- 2.25.1