X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FPage%2FView%2FSummary.php;h=d49f41c691d1da7982793cb254e1425e810d0f2a;hb=269e0a555069731fb0995b1b0d5a82d45b07c1df;hp=b28cfcfa4604be09c56ca7250795495b0fcd5c6b;hpb=cbbc517043cd7ff0778171ec9839d4dbe4a0651b;p=civicrm-core.git diff --git a/CRM/Contact/Page/View/Summary.php b/CRM/Contact/Page/View/Summary.php index b28cfcfa46..d49f41c691 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 @@ -110,10 +112,10 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { ->addScriptFile('civicrm', 'templates/CRM/Contact/Page/View/Summary.js', 2, 'html-header') ->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header') ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header') - ->addSetting(array( - 'summaryPrint' => array('mode' => $this->_print), - 'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $this, FALSE, 'summary')), - )); + ->addSetting([ + 'summaryPrint' => ['mode' => $this->_print], + 'tabSettings' => ['active' => CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $this, FALSE, 'summary')], + ]); $this->assign('summaryPrint', $this->_print); $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); @@ -121,43 +123,78 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { $this->assignFieldMetadataToTemplate('Contact'); $params = []; - $defaults = []; + $defaults = [ + // Set empty default values for these - they will be overwritten when the contact is + // loaded in CRM_Contact_BAO_Contact::retrieve if there are real values + // but since we are not using apiV4 they will be left unset if empty. + // However, the wind up assigned as smarty variables so we ensure they are set to prevent e-notices + // used by ContactInfo.tpl + 'job_title' => '', + 'current_employer_id' => '', + 'nick_name' => '', + 'legal_name' => '', + 'source' => '', + 'sic_code' => '', + 'external_identifier' => '', + // for CommunicationPreferences.tpl + 'postal_greeting_custom' => '', + 'email_greeting_custom' => '', + 'addressee_custom' => '', + 'communication_style_display' => '', + // for Demographics.tpl + 'age' => ['y' => '', 'm' => ''], + 'birth_date' => '', + // for Website.tpl (the others don't seem to enotice for some reason). + 'website' => [], + ]; + + $params['contact_id'] = $this->_contactId; + + CRM_Contact_BAO_Contact::getValues(array_merge(['id' => $this->_contactId], $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') && !empty($defaults['employer_id']) && !empty($defaults['organization_name'])) { + $defaults['current_employer'] = $defaults['organization_name']; + $defaults['current_employer_id'] = $defaults['employer_id']; + } - $params['id'] = $params['contact_id'] = $this->_contactId; - $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = TRUE; - $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE); // 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']); - $communicationType = array( - 'phone' => array( + $communicationType = [ + 'phone' => [ 'type' => 'phoneType', 'id' => 'phone_type', 'daoName' => 'CRM_Core_DAO_Phone', 'fieldName' => 'phone_type_id', - ), - 'im' => array( + ], + 'im' => [ 'type' => 'IMProvider', 'id' => 'provider', 'daoName' => 'CRM_Core_DAO_IM', 'fieldName' => 'provider_id', - ), - 'website' => array( + ], + 'website' => [ 'type' => 'websiteType', 'id' => 'website_type', 'daoName' => 'CRM_Core_DAO_Website', 'fieldName' => 'website_type_id', - ), - 'address' => array('skip' => TRUE, 'customData' => 1), - 'email' => array('skip' => TRUE), - 'openid' => array('skip' => TRUE), - ); + ], + 'address' => ['skip' => TRUE, 'customData' => 1], + 'email' => ['skip' => TRUE], + 'openid' => ['skip' => TRUE], + ]; foreach ($communicationType as $key => $value) { if (!empty($defaults[$key])) { foreach ($defaults[$key] as & $val) { - CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')), FALSE); + CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', ['labelColumn' => 'display_name']), FALSE); if (empty($value['skip'])) { $daoName = $value['daoName']; $pseudoConst = $daoName::buildOptions($value['fieldName'], 'get'); @@ -183,9 +220,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { } } - if (!empty($defaults['gender_id'])) { - $defaults['gender_display'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'gender_id', $defaults['gender_id']); - } + $defaults['gender_display'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'gender_id', $defaults['gender_id'] ?? NULL); $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id'); if (!empty($communicationStyle)) { @@ -203,10 +238,8 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $contactType, ', '); // get contact tags - $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId); - - if (!empty($contactTags)) { - $defaults['contactTag'] = $contactTags; + $defaults['contactTag'] = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId); + if (!empty($defaults['contactTag'])) { $defaults['allTags'] = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE); } @@ -231,23 +264,14 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted'] ) { - $sharedAddresses[$key]['shared_address_display'] = array( + $sharedAddresses[$key]['shared_address_display'] = [ 'address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name'], - ); + ]; } } $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; - } - } - - $defaults['external_identifier'] = $contact->external_identifier; $this->assign($defaults); // FIXME: when we sort out TZ isssues with DATETIME/TIMESTAMP, we can skip next query @@ -442,7 +466,10 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { $tab += array_fill_keys($expectedKeys, NULL); // Get tab counts last to avoid wasting time; if a tab was removed by hook, the count isn't needed. if (!isset($tab['count']) && isset($getCountParams[$tab['id']])) { - $tab['count'] = call_user_func_array(['CRM_Contact_BAO_Contact', 'getCountComponent'], $getCountParams[$tab['id']]); + $tab['count'] = call_user_func_array([ + 'CRM_Contact_BAO_Contact', + 'getCountComponent', + ], $getCountParams[$tab['id']]); } }