From b4f964d9b59efe2f9def7e12121da79dde9123fa Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 30 Apr 2013 15:07:34 -0700 Subject: [PATCH] Refactor phone type CRM-12464 ---------------------------------------- * CRM-12464: Search improvements in 4.4 http://issues.civicrm.org/jira/browse/CRM-12464 --- CRM/Contact/BAO/Contact.php | 2 +- CRM/Contact/Form/Edit/Phone.php | 2 +- CRM/Contact/Form/Search/Criteria.php | 2 +- CRM/Contact/Import/Form/MapField.php | 4 ++-- CRM/Contact/Import/Form/Preview.php | 2 +- CRM/Contact/Import/ImportJob.php | 2 +- CRM/Contact/Page/Inline/Phone.php | 2 +- CRM/Core/BAO/Mapping.php | 2 +- CRM/Core/BAO/Phone.php | 4 ++-- CRM/Core/PseudoConstant.php | 27 ------------------------- CRM/Export/BAO/Export.php | 2 +- CRM/Logging/Differ.php | 2 +- CRM/SMS/Provider.php | 30 +++++++++++++++------------- CRM/UF/Form/Field.php | 2 +- CRM/UF/Page/ProfileEditor.php | 2 +- 15 files changed, 31 insertions(+), 56 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index ebd47655d0..c721066b01 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -618,7 +618,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); if ($name == 'phone') { CRM_Utils_Array::lookupValue($values, 'phone_type', - CRM_Core_PseudoConstant::phoneType(), + CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'), $reverse ); } diff --git a/CRM/Contact/Form/Edit/Phone.php b/CRM/Contact/Form/Edit/Phone.php index 1cd598eb2b..c767282e16 100644 --- a/CRM/Contact/Form/Edit/Phone.php +++ b/CRM/Contact/Form/Edit/Phone.php @@ -61,7 +61,7 @@ class CRM_Contact_Form_Edit_Phone { $form->applyFilter('__ALL__', 'trim'); //phone type select - $form->addElement('select', "phone[$blockId][phone_type_id]", ts('Phone'), CRM_Core_PseudoConstant::phoneType()); + $form->addElement('select', "phone[$blockId][phone_type_id]", ts('Phone'), CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id')); //main phone number with crm_phone class $form->addElement('text', "phone[$blockId][phone]", ts('Phone'), array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'), array('class' => 'crm_phone twelve'))); diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index a266580002..d95e97c50c 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -260,7 +260,7 @@ class CRM_Contact_Form_Search_Criteria { // Phone search $form->addElement('text', 'phone_numeric', ts('Phone Number'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone')); $locationType = CRM_Core_PseudoConstant::locationType(); - $phoneType = CRM_Core_PseudoConstant::phoneType(); + $phoneType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $form->add('select', 'phone_location_type_id', ts('Phone Location'), array('' => ts('- any -')) + $locationType); $form->add('select', 'phone_phone_type_id', ts('Phone Type'), array('' => ts('- any -')) + $phoneType); } diff --git a/CRM/Contact/Import/Form/MapField.php b/CRM/Contact/Import/Form/MapField.php index 113bc6e9ae..42b2ed1546 100644 --- a/CRM/Contact/Import/Form/MapField.php +++ b/CRM/Contact/Import/Form/MapField.php @@ -353,7 +353,7 @@ class CRM_Contact_Import_Form_MapField extends CRM_Core_Form { $sel1 = $this->_mapperFields; $sel2[''] = NULL; - $phoneTypes = CRM_Core_PseudoConstant::phoneType(); + $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $imProviders = CRM_Core_PseudoConstant::IMProvider(); $websiteTypes = CRM_Core_PseudoConstant::websiteType(); @@ -761,7 +761,7 @@ class CRM_Contact_Import_Form_MapField extends CRM_Core_Form { $mapperKeys = $this->controller->exportValue($this->_name, 'mapper'); $mapperKeysMain = array(); - $phoneTypes = CRM_Core_PseudoConstant::phoneType(); + $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $imProviders = CRM_Core_PseudoConstant::IMProvider(); $websiteTypes = CRM_Core_PseudoConstant::websiteType(); $locationTypes = CRM_Core_PseudoConstant::locationType(); diff --git a/CRM/Contact/Import/Form/Preview.php b/CRM/Contact/Import/Form/Preview.php index 16d67500e4..cba79d017c 100644 --- a/CRM/Contact/Import/Form/Preview.php +++ b/CRM/Contact/Import/Form/Preview.php @@ -412,7 +412,7 @@ class CRM_Contact_Import_Form_Preview extends CRM_Core_Form { $mapFields = $this->get('fields'); $locationTypes = CRM_Core_PseudoConstant::locationType(); - $phoneTypes = CRM_Core_PseudoConstant::phoneType(); + $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); foreach ($mapper as $key => $value) { $header = array(); diff --git a/CRM/Contact/Import/ImportJob.php b/CRM/Contact/Import/ImportJob.php index fdf8283157..ceeac286e8 100644 --- a/CRM/Contact/Import/ImportJob.php +++ b/CRM/Contact/Import/ImportJob.php @@ -144,7 +144,7 @@ class CRM_Contact_Import_ImportJob { public function runImport(&$form, $timeout = 55) { $mapper = $this->_mapper; $mapperFields = array(); - $phoneTypes = CRM_Core_PseudoConstant::phoneType(); + $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $imProviders = CRM_Core_PseudoConstant::IMProvider(); $websiteTypes = CRM_Core_PseudoConstant::websiteType(); $locationTypes = CRM_Core_PseudoConstant::locationType(); diff --git a/CRM/Contact/Page/Inline/Phone.php b/CRM/Contact/Page/Inline/Phone.php index b93e6d043e..142b055acc 100644 --- a/CRM/Contact/Page/Inline/Phone.php +++ b/CRM/Contact/Page/Inline/Phone.php @@ -53,7 +53,7 @@ class CRM_Contact_Page_Inline_Phone extends CRM_Core_Page { $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); $locationTypes = CRM_Core_PseudoConstant::locationDisplayName(); - $phoneTypes = CRM_Core_PseudoConstant::phoneType(); + $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $entityBlock = array('contact_id' => $contactId); $phones = CRM_Core_BAO_Phone::getValues($entityBlock); diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index 8f1094059f..326f4443e4 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -565,7 +565,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping { $sel3[''] = NULL; $sel5[''] = NULL; - $phoneTypes = CRM_Core_PseudoConstant::phoneType(); + $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $imProviders = CRM_Core_PseudoConstant::IMProvider(); asort($phoneTypes); diff --git a/CRM/Core/BAO/Phone.php b/CRM/Core/BAO/Phone.php index 14572de4e2..4189aa0653 100644 --- a/CRM/Core/BAO/Phone.php +++ b/CRM/Core/BAO/Phone.php @@ -109,7 +109,7 @@ class CRM_Core_BAO_Phone extends CRM_Core_DAO_Phone { $cond = NULL; if ($type) { - $phoneTypeId = array_search($type, CRM_Core_PseudoConstant::phoneType()); + $phoneTypeId = array_search($type, CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id')); if ($phoneTypeId) { $cond = " AND civicrm_phone.phone_type_id = $phoneTypeId"; } @@ -179,7 +179,7 @@ ORDER BY civicrm_phone.is_primary DESC, phone_id ASC "; $cond = NULL; if ($type) { - $phoneTypeId = array_search($type, CRM_Core_PseudoConstant::phoneType()); + $phoneTypeId = array_search($type, CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id')); if ($phoneTypeId) { $cond = " AND civicrm_phone.phone_type_id = $phoneTypeId"; } diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 42eb63d852..6bd6d44bc5 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -280,13 +280,6 @@ class CRM_Core_PseudoConstant { */ private static $mappingType; - /** - * Phone Types - * @var array - * @static - */ - private static $phoneType; - /** * Visibility * @var array @@ -710,26 +703,6 @@ class CRM_Core_PseudoConstant { return self::$component; } - /** - * Get all phone type - * The static array phoneType is returned - * - * @access public - * @static - * - * @param boolean $all - get All phone type - default is to get - * only active ones. - * - * @return array - array reference of all phone types. - * - */ - public static function &phoneType() { - if (!self::$phoneType) { - self::$phoneType = CRM_Core_OptionGroup::values('phone_type'); - } - return self::$phoneType; - } - /** * Get all the IM Providers from database. * diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 1c03b59303..f4f73c5986 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -83,7 +83,7 @@ class CRM_Export_BAO_Export { $allCampaigns = array(); $exportCampaign = FALSE; - $phoneTypes = CRM_Core_PseudoConstant::phoneType(); + $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $imProviders = CRM_Core_PseudoConstant::IMProvider(); $contactRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType( NULL, diff --git a/CRM/Logging/Differ.php b/CRM/Logging/Differ.php index e723280ffb..74c6447f1d 100644 --- a/CRM/Logging/Differ.php +++ b/CRM/Logging/Differ.php @@ -237,7 +237,7 @@ WHERE log_conn_id = %1 AND '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(), + 'phone_type_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'), 'preferred_communication_method' => CRM_Core_PseudoConstant::pcm(), 'preferred_language' => CRM_Core_PseudoConstant::languages(), 'prefix_id' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'), diff --git a/CRM/SMS/Provider.php b/CRM/SMS/Provider.php index e26afced8d..f524ec68c0 100644 --- a/CRM/SMS/Provider.php +++ b/CRM/SMS/Provider.php @@ -168,21 +168,23 @@ INNER JOIN civicrm_mailing_job mj ON mj.mailing_id = m.id AND mj.id = %1"; // unknown mobile sender -- create new contact // use fake @mobile.sms email address for new contact since civi // requires email or name for all contacts - $locationTypes =& CRM_Core_PseudoConstant::locationType(); - $phoneTypes =& CRM_Core_PseudoConstant::phoneType(); - $phoneloc = array_search( 'Home', $locationTypes ); - $phonetype = array_search( 'Mobile', $phoneTypes ); + $locationTypes = CRM_Core_PseudoConstant::locationType(); + $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); + $phoneloc = array_search('Home', $locationTypes); + $phonetype = array_search('Mobile', $phoneTypes); $stripFrom = $this->stripPhone($from); - $contactparams = - Array ( 'contact_type' => 'Individual', - 'email' => Array ( 1 => Array ( 'location_type_id' => $phoneloc, - 'email' => $stripFrom . '@mobile.sms' ) - ), - 'phone' => Array ( 1 => Array( 'phone_type_id' => $phonetype, - 'location_type_id' => $phoneloc, - 'phone' => $stripFrom ) - ) - ); + $contactparams = array( + 'contact_type' => 'Individual', + 'email' => array(1 => array( + 'location_type_id' => $phoneloc, + 'email' => $stripFrom . '@mobile.sms' + )), + 'phone' => array(1 => array( + 'phone_type_id' => $phonetype, + 'location_type_id' => $phoneloc, + 'phone' => $stripFrom + )), + ); $fromContact = CRM_Contact_BAO_Contact::create($contactparams, FALSE, TRUE, FALSE); $fromContactID = $fromContact->id; } diff --git a/CRM/UF/Form/Field.php b/CRM/UF/Form/Field.php index bde9c82a7e..ba6c29b0c9 100644 --- a/CRM/UF/Form/Field.php +++ b/CRM/UF/Form/Field.php @@ -331,7 +331,7 @@ class CRM_UF_Form_Field extends CRM_Core_Form { } } $sel3[''] = NULL; - $phoneTypes = CRM_Core_PseudoConstant::phoneType(); + $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); ksort($phoneTypes); foreach ($sel1 as $k => $sel) { diff --git a/CRM/UF/Page/ProfileEditor.php b/CRM/UF/Page/ProfileEditor.php index 5dc05d059e..fd1dda2f34 100644 --- a/CRM/UF/Page/ProfileEditor.php +++ b/CRM/UF/Page/ProfileEditor.php @@ -23,7 +23,7 @@ class CRM_UF_Page_ProfileEditor extends CRM_Core_Page { return array( 'PseudoConstant' => array( 'locationType' => CRM_Core_PseudoConstant::locationType(), - 'phoneType' => CRM_Core_PseudoConstant::phoneType(), + 'phoneType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'), ), 'initialProfileList' => civicrm_api('UFGroup', 'get', array( 'version' => 3, -- 2.25.1