From: Allen Shaw Date: Thu, 2 May 2013 00:33:22 +0000 (-0700) Subject: Refactored out of CRM_Core_PseudoConstant: locationVcardName(), locationDisplayName... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8f785c9e9cec4402a6c71a3e400e64e15122903f;p=civicrm-core.git Refactored out of CRM_Core_PseudoConstant: locationVcardName(), locationDisplayName(), component(). CRM-12464 ---------------------------------------- * CRM-12464: http://issues.civicrm.org/jira/browse/CRM-12464 --- diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 129831576a..ba1d3de031 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -545,7 +545,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); if ($name == 'address') { // FIXME: lookupValue doesn't work for vcard_name if (CRM_Utils_Array::value('location_type_id', $values)) { - $vcardNames = CRM_Core_PseudoConstant::locationVcardName(); + $vcardNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'vcard_name')); $values['vcard_name'] = $vcardNames[$values['location_type_id']]; } diff --git a/CRM/Contact/Page/Inline/Address.php b/CRM/Contact/Page/Inline/Address.php index 5385408801..8cc436d9c2 100644 --- a/CRM/Contact/Page/Inline/Address.php +++ b/CRM/Contact/Page/Inline/Address.php @@ -56,7 +56,7 @@ class CRM_Contact_Page_Inline_Address extends CRM_Core_Page { $address = array(); if ( $addressId > 0 ) { - $locationTypes = CRM_Core_PseudoConstant::locationDisplayName(); + $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')); $entityBlock = array('id' => $addressId); $address = CRM_Core_BAO_Address::getValues($entityBlock, FALSE, 'id'); diff --git a/CRM/Contact/Page/Inline/Email.php b/CRM/Contact/Page/Inline/Email.php index f679bf0ccd..caaae2ab49 100644 --- a/CRM/Contact/Page/Inline/Email.php +++ b/CRM/Contact/Page/Inline/Email.php @@ -52,7 +52,7 @@ class CRM_Contact_Page_Inline_Email extends CRM_Core_Page { // get the emails for this contact $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); - $locationTypes = CRM_Core_PseudoConstant::locationDisplayName(); + $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')); $entityBlock = array('contact_id' => $contactId); $emails = CRM_Core_BAO_Email::getValues($entityBlock); diff --git a/CRM/Contact/Page/Inline/IM.php b/CRM/Contact/Page/Inline/IM.php index f2bfd6698b..b7defce668 100644 --- a/CRM/Contact/Page/Inline/IM.php +++ b/CRM/Contact/Page/Inline/IM.php @@ -52,7 +52,7 @@ class CRM_Contact_Page_Inline_IM extends CRM_Core_Page { // get the emails for this contact $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); - $locationTypes = CRM_Core_PseudoConstant::locationDisplayName(); + $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')); $IMProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); $entityBlock = array('contact_id' => $contactId); diff --git a/CRM/Contact/Page/Inline/OpenID.php b/CRM/Contact/Page/Inline/OpenID.php index fc04626b12..1317a40c63 100644 --- a/CRM/Contact/Page/Inline/OpenID.php +++ b/CRM/Contact/Page/Inline/OpenID.php @@ -52,7 +52,7 @@ class CRM_Contact_Page_Inline_OpenID extends CRM_Core_Page { // get the emails for this contact $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); - $locationTypes = CRM_Core_PseudoConstant::locationDisplayName(); + $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')); $entityBlock = array('contact_id' => $contactId); $openids = CRM_Core_BAO_OpenID::getValues($entityBlock); diff --git a/CRM/Contact/Page/Inline/Phone.php b/CRM/Contact/Page/Inline/Phone.php index 142b055acc..0685362a17 100644 --- a/CRM/Contact/Page/Inline/Phone.php +++ b/CRM/Contact/Page/Inline/Phone.php @@ -52,7 +52,7 @@ class CRM_Contact_Page_Inline_Phone extends CRM_Core_Page { // get the emails for this contact $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); - $locationTypes = CRM_Core_PseudoConstant::locationDisplayName(); + $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')); $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $entityBlock = array('contact_id' => $contactId); diff --git a/CRM/Contact/Page/View/Summary.php b/CRM/Contact/Page/View/Summary.php index 827e6665bb..17b2c1d654 100644 --- a/CRM/Contact/Page/View/Summary.php +++ b/CRM/Contact/Page/View/Summary.php @@ -170,7 +170,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { foreach ($communicationType as $key => $value) { if (CRM_Utils_Array::value($key, $defaults)) { foreach ($defaults[$key] as & $val) { - CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::locationDisplayName(), FALSE); + CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')), FALSE); if (!CRM_Utils_Array::value('skip', $value)) { eval('$pseudoConst = CRM_Core_PseudoConstant::' . $value['type'] . '();'); CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, FALSE); diff --git a/CRM/Contact/Page/View/Vcard.php b/CRM/Contact/Page/View/Vcard.php index 0566b494b4..1f07abad8e 100644 --- a/CRM/Contact/Page/View/Vcard.php +++ b/CRM/Contact/Page/View/Vcard.php @@ -60,7 +60,7 @@ class CRM_Contact_Page_View_Vcard extends CRM_Contact_Page_View { // now that we have the contact's data - let's build the vCard // TODO: non-US-ASCII support (requires changes to the Contact_Vcard_Build class) - $vcardNames = CRM_Core_PseudoConstant::locationVcardName(); + $vcardNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'vcard_name')); $vcard = new Contact_Vcard_Build('2.1'); if ($defaults['contact_type'] == 'Individual') { diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index a3ba2413b7..01619183b6 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -56,20 +56,6 @@ class CRM_Core_PseudoConstant { */ private static $cache; - /** - * location vCard name - * @var array - * @static - */ - private static $locationVcardName; - - /** - * location display name - * @var array - * @static - */ - private static $locationDisplayName; - /** * activity type * @var array @@ -84,13 +70,6 @@ class CRM_Core_PseudoConstant { */ private static $billingMode; - /** - * component - * @var array - * @static - */ - private static $component; - /** * states, provinces * @var array @@ -462,46 +441,6 @@ class CRM_Core_PseudoConstant { } } - /** - * Get all location vCard names. - * - * The static array locationVcardName is returned - * - * @access public - * @static - * - * @param boolean $all - get All location vCard names - default is to get only active ones. - * - * @return array - array reference of all location vCard names. - * - */ - public static function &locationVcardName($all = FALSE) { - if (!self::$locationVcardName) { - self::populate(self::$locationVcardName, 'CRM_Core_DAO_LocationType', $all, 'vcard_name'); - } - return self::$locationVcardName; - } - - /** - * Get all location Display names. - * - * The static array locationDisplayName is returned - * - * @access public - * @static - * - * @param boolean $all - get All location display names - default is to get only active ones. - * - * @return array - array reference of all location display names. - * - */ - public static function &locationDisplayName($all = FALSE) { - if (!self::$locationDisplayName) { - self::populate(self::$locationDisplayName, 'CRM_Core_DAO_LocationType', $all, 'display_name'); - } - return self::$locationDisplayName; - } - /** * Get all Activty types. * @@ -593,22 +532,6 @@ class CRM_Core_PseudoConstant { } return self::$billingMode; } - - /** - * Get all component names - * - * @access public - * @static - * - * @return array - array reference of all location display names. - * - */ - public static function &component() { - if (!self::$component) { - self::populate(self::$component, 'CRM_Core_DAO_Component', TRUE, 'name'); - } - return self::$component; - } /** * Get all the State/Province from database. @@ -1060,13 +983,15 @@ WHERE id = %1"; * * @return array - array reference of all Currency Symbols * @static + * + * FIXME: this is not stored as an optionValue, and it's not tied to a single DB column; + * FIXME: It's used for a setting stored in option group 'currencies_enabled'. What to do? */ public static function ¤cySymbols($name = 'symbol', $key = 'id') { $cacheKey = "{$name}_{$key}"; if (!isset(self::$currencySymbols[$cacheKey])) { self::populate(self::$currencySymbols[$cacheKey], 'CRM_Financial_DAO_Currency', TRUE, $name, NULL, NULL, 'name', $key); } - return self::$currencySymbols[$cacheKey]; } diff --git a/api/v3/ReportTemplate.php b/api/v3/ReportTemplate.php index 84cb499a25..5129dec728 100644 --- a/api/v3/ReportTemplate.php +++ b/api/v3/ReportTemplate.php @@ -39,7 +39,8 @@ function civicrm_api3_report_template_create($params) { 'CRM_Core_DAO_OptionGroup', 'report_template', 'id', 'name' ); if (!empty($params['component_id']) && !is_numeric($params['component_id'])) { - $params['component_id'] = array_search($params['component_id'], CRM_Core_PseudoConstant::component()); + $components = CRM_Core_PseudoConstant::get('CRM_Core_DAO_OptionValue', 'component_id', array('onlyActive' => FALSE, 'labelColumn' => 'name')); + $params['component_id'] = array_search($params['component_id'], $components); } return civicrm_api3_option_value_create($params); } diff --git a/tests/phpunit/CRM/Core/PseudoConstantTest.php b/tests/phpunit/CRM/Core/PseudoConstantTest.php index b4fe50ce8f..c3194df480 100644 --- a/tests/phpunit/CRM/Core/PseudoConstantTest.php +++ b/tests/phpunit/CRM/Core/PseudoConstantTest.php @@ -50,6 +50,12 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { // - sample: Any one value which is expected in the list of option values. // - max: integer (default = 10) maximum number of option values expected. $fields = array( + 'CRM_Core_DAO_OptionValue' => array( + array( + 'fieldName' => 'component_id', + 'sample' => 'CiviContribute', + ), + ), 'CRM_Project_DAO_Task' => array( array( 'fieldName' => 'priority_id', diff --git a/xml/schema/Core/Cache.xml b/xml/schema/Core/Cache.xml index d8725983fe..8368ad228a 100644 --- a/xml/schema/Core/Cache.xml +++ b/xml/schema/Core/Cache.xml @@ -54,10 +54,15 @@ 2.1 - component_id - int unsigned - Component that this menu item belongs to - 2.1 + component_id + int unsigned + Component that this menu item belongs to + 2.1 + + civicrm_component
+ id + name +
component_id diff --git a/xml/schema/Core/Menu.xml b/xml/schema/Core/Menu.xml index df61305673..09d1786e6d 100644 --- a/xml/schema/Core/Menu.xml +++ b/xml/schema/Core/Menu.xml @@ -103,10 +103,15 @@ 2.1 - component_id - int unsigned - Component that this menu item belongs to - 2.1 + component_id + int unsigned + Component that this menu item belongs to + 2.1 + + civicrm_component
+ id + name +
component_id diff --git a/xml/schema/Core/OptionValue.xml b/xml/schema/Core/OptionValue.xml index a417fc3b53..783810d6c7 100644 --- a/xml/schema/Core/OptionValue.xml +++ b/xml/schema/Core/OptionValue.xml @@ -125,7 +125,6 @@ Component that this option value belongs/caters to. 2.0 - component civicrm_component
id name diff --git a/xml/schema/Core/Setting.xml b/xml/schema/Core/Setting.xml index a10836128f..0d22f70a25 100644 --- a/xml/schema/Core/Setting.xml +++ b/xml/schema/Core/Setting.xml @@ -77,10 +77,15 @@ 4.1 - component_id - int unsigned - Component that this menu item belongs to - 4.1 + component_id + int unsigned + Component that this menu item belongs to + 4.1 + + civicrm_component
+ id + name +
component_id