Skip to content

Commit

Permalink
[REF] Deprecate BAO_Contact::retrieve
Browse files Browse the repository at this point in the history
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....
  • Loading branch information
eileenmcnaughton committed Mar 18, 2022
1 parent a96ab6d commit 9469949
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,9 @@ public static function resolveDefaults(&$defaults, $reverse = FALSE) {
/**
* 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
Expand Down
16 changes: 7 additions & 9 deletions CRM/Contact/Form/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,13 @@ public function preProcess() {
$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);
}
}
Expand Down
28 changes: 17 additions & 11 deletions CRM/Contact/Page/View/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public function edit() {

/**
* View summary details of a contact.
*
* @throws \CRM_Core_Exception
*/
public function view() {
// Add js for tabs, in-place editing, and jstree for tags
Expand Down Expand Up @@ -146,9 +148,21 @@ public function 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']);
Expand Down Expand Up @@ -258,14 +272,6 @@ public function 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
Expand Down

0 comments on commit 9469949

Please sign in to comment.