From 61e8082bf588c1d345cac44f2ad8ea181ac928d6 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 18 Mar 2022 13:34:21 +1300 Subject: [PATCH] [REF] Deprecate BAO_Contact::retrieve This removes 2 calls to BAO_Contact::retrieve and marks it as deprecated. It is a surprisingly complex function and all the calls to it only use parts of what it does - in general just having the code 'do the thing' is better. In this case it turns out there is no need for the contact objects. There is also some pretty funky handling for the location keys in the next section so making it clearer what is in them should make it possible to simplify that.... --- CRM/Contact/BAO/Contact.php | 3 +++ CRM/Contact/Form/Contact.php | 16 +++++++--------- CRM/Contact/Page/View/Summary.php | 28 +++++++++++++++++----------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 940393715b..f89c33b142 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -868,6 +868,9 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); /** * Fetch object based on array of properties. * + * @deprecated This is called from a few places but creates rather than solves + * complexity. + * * @param array $params * (reference ) an assoc array of name/value pairs. * @param array $defaults diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index 47330cf50e..e3526541e6 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -254,15 +254,13 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { $this->_values = $values; } else { - $params = [ - 'id' => $this->_contactId, - 'contact_id' => $this->_contactId, - 'noRelationships' => TRUE, - 'noNotes' => TRUE, - 'noGroups' => TRUE, - ]; - - $contact = CRM_Contact_BAO_Contact::retrieve($params, $this->_values, TRUE); + CRM_Contact_BAO_Contact::getValues(['contact_id' => $this->_contactId], $this->_values); + $this->_values['im'] = CRM_Core_BAO_IM::getValues(['contact_id' => $this->_contactId]); + $this->_values['email'] = CRM_Core_BAO_Email::getValues(['contact_id' => $this->_contactId]); + $this->_values['openid'] = CRM_Core_BAO_OpenID::getValues(['contact_id' => $this->_contactId]); + $this->_values['phone'] = CRM_Core_BAO_Phone::getValues(['contact_id' => $this->_contactId]); + $this->_values['address'] = CRM_Core_BAO_Address::getValues(['contact_id' => $this->_contactId], TRUE); + CRM_Core_BAO_Website::getValues(['contact_id' => $this->_contactId], $this->_values); $this->set('values', $this->_values); } } diff --git a/CRM/Contact/Page/View/Summary.php b/CRM/Contact/Page/View/Summary.php index 0408f9a114..e6fe5b3af3 100644 --- a/CRM/Contact/Page/View/Summary.php +++ b/CRM/Contact/Page/View/Summary.php @@ -103,6 +103,8 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { /** * View summary details of a contact. + * + * @throws \CRM_Core_Exception */ public function view() { // Add js for tabs, in-place editing, and jstree for tags @@ -146,9 +148,21 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { 'website' => [], ]; - $params['id'] = $params['contact_id'] = $this->_contactId; - $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = TRUE; - $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE); + $params['contact_id'] = $this->_contactId; + + CRM_Contact_BAO_Contact::getValues($params, $defaults); + $defaults['im'] = CRM_Core_BAO_IM::getValues(['contact_id' => $params['contact_id']]); + $defaults['email'] = CRM_Core_BAO_Email::getValues(['contact_id' => $params['contact_id']]); + $defaults['openid'] = CRM_Core_BAO_OpenID::getValues(['contact_id' => $params['contact_id']]); + $defaults['phone'] = CRM_Core_BAO_Phone::getValues(['contact_id' => $params['contact_id']]); + $defaults['address'] = CRM_Core_BAO_Address::getValues(['contact_id' => $params['contact_id']], TRUE); + CRM_Core_BAO_Website::getValues($params, $defaults); + // Copy employer fields to the current_employer keys. + if (($defaults['contact_type'] === 'Individual') && $defaults['employer_id'] && $defaults['organization_name']) { + $defaults['current_employer'] = $defaults['organization_name']; + $defaults['current_employer_id'] = $defaults['employer_id']; + } + // Let summary page know if outbound mail is disabled so email links can be built conditionally $mailingBackend = Civi::settings()->get('mailing_backend'); $this->assign('mailingOutboundOption', $mailingBackend['outBound_option']); @@ -258,14 +272,6 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { } $this->assign('sharedAddresses', $sharedAddresses); - //get the current employer name - if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') { - if ($contact->employer_id && $contact->organization_name) { - $defaults['current_employer'] = $contact->organization_name; - $defaults['current_employer_id'] = $contact->employer_id; - } - } - $this->assign($defaults); // FIXME: when we sort out TZ isssues with DATETIME/TIMESTAMP, we can skip next query -- 2.25.1