From ba6f8b4ceac104c681f2e648142ce4edf73c1951 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 12 Feb 2022 16:31:56 +1300 Subject: [PATCH] [REF] Simplification in Contact::getValues The call to location::getValues takes more lines & is less readable than just doing the thing. Note that 1) I could not find any evidence of 'noWebsite' being passed in so I switched to always add 2) the signature on website:getValues is slightly different (of course). 3) I found that the others that were receiving params as a reference were not altering it so removed those pass-by-refs --- CRM/Contact/BAO/Contact.php | 19 +++++++------------ CRM/Contact/BAO/GroupContact.php | 2 +- CRM/Contact/BAO/Relationship.php | 2 +- CRM/Core/BAO/Note.php | 2 +- CRM/Core/BAO/Website.php | 2 +- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 9667903c3e..96c908eb79 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -890,13 +890,12 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); unset($params['id']); - //get the block information for this contact - $entityBlock = ['contact_id' => $params['contact_id']]; - $blocks = CRM_Core_BAO_Location::getValues($entityBlock, $microformat); - $defaults = array_merge($defaults, $blocks); - foreach ($blocks as $block => $value) { - $contact->$block = $value; - } + $contact->im = $defaults['im'] = CRM_Core_BAO_IM::getValues(['contact_id' => $params['contact_id']]); + $contact->email = $defaults['email'] = CRM_Core_BAO_Email::getValues(['contact_id' => $params['contact_id']]); + $contact->openid = $defaults['openid'] = CRM_Core_BAO_OpenID::getValues(['contact_id' => $params['contact_id']]); + $contact->phone = $defaults['phone'] = CRM_Core_BAO_Phone::getValues(['contact_id' => $params['contact_id']]); + $contact->address = $defaults['address'] = CRM_Core_BAO_Address::getValues(['contact_id' => $params['contact_id']], $microformat); + $contact->website = CRM_Core_BAO_Website::getValues($params, $defaults); if (!isset($params['noNotes'])) { $contact->notes = CRM_Core_BAO_Note::getValues($params, $defaults); @@ -910,10 +909,6 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $contact->groupContact = CRM_Contact_BAO_GroupContact::getValues($params, $defaults); } - if (!isset($params['noWebsite'])) { - $contact->website = CRM_Core_BAO_Website::getValues($params, $defaults); - } - return $contact; } @@ -2616,7 +2611,7 @@ LEFT JOIN civicrm_email ON ( civicrm_contact.id = civicrm_email.contact_id ) * @return CRM_Contact_BAO_Contact|null * The found object or null */ - public static function getValues(&$params, &$values) { + public static function getValues($params, &$values) { $contact = new CRM_Contact_BAO_Contact(); $contact->copyValues($params); diff --git a/CRM/Contact/BAO/GroupContact.php b/CRM/Contact/BAO/GroupContact.php index c6891ebd3d..bfb854818d 100644 --- a/CRM/Contact/BAO/GroupContact.php +++ b/CRM/Contact/BAO/GroupContact.php @@ -76,7 +76,7 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { * @return array * (reference) the values that could be potentially assigned to smarty */ - public static function getValues(&$params, &$values) { + public static function getValues($params, &$values) { if (empty($params)) { return NULL; } diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 3294f08471..17340fbbe9 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -984,7 +984,7 @@ WHERE relationship_type_id = " . CRM_Utils_Type::escape($type, 'Integer'); * @return array * (reference) the values that could be potentially assigned to smarty */ - public static function &getValues(&$params, &$values) { + public static function &getValues($params, &$values) { if (empty($params)) { return NULL; } diff --git a/CRM/Core/BAO/Note.php b/CRM/Core/BAO/Note.php index 3f6080a7a6..1db4a1aebc 100644 --- a/CRM/Core/BAO/Note.php +++ b/CRM/Core/BAO/Note.php @@ -237,7 +237,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note implements \Civi\Test\HookInte * * @return array */ - public static function &getValues(&$params, &$values, $numNotes = self::MAX_NOTES) { + public static function &getValues($params, &$values, $numNotes = self::MAX_NOTES) { if (empty($params)) { return NULL; } diff --git a/CRM/Core/BAO/Website.php b/CRM/Core/BAO/Website.php index 89d658ff76..7436a040fd 100644 --- a/CRM/Core/BAO/Website.php +++ b/CRM/Core/BAO/Website.php @@ -122,7 +122,7 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website { * * @return array */ - public static function &getValues(&$params = [], &$values = []) { + public static function &getValues($params = [], &$values = []) { $websites = []; $website = new CRM_Core_DAO_Website(); $website->contact_id = $params['contact_id']; -- 2.25.1