REF - Cleanup array key checking to use array_key_exists
[civicrm-core.git] / CRM / Contact / Page / Inline / Address.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Dummy page for details of address.
20 */
21 class CRM_Contact_Page_Inline_Address extends CRM_Core_Page {
22
23 /**
24 * Run the page.
25 *
26 * This method is called after the page is created.
27 */
28 public function run() {
29 // get the emails for this contact
30 $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
31 $locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
32 $addressId = CRM_Utils_Request::retrieve('aid', 'Positive');
33
34 $address = [];
35 if ($addressId > 0) {
36 $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', ['labelColumn' => 'display_name']);
37
38 $entityBlock = ['id' => $addressId];
39 $address = CRM_Core_BAO_Address::getValues($entityBlock, FALSE, 'id');
40 if (!empty($address)) {
41 foreach ($address as $key => & $value) {
42 $value['location_type'] = $locationTypes[$value['location_type_id']];
43 }
44 }
45 }
46
47 // we just need current address block
48 $currentAddressBlock['address'][$locBlockNo] = array_pop($address);
49
50 if (!empty($currentAddressBlock['address'][$locBlockNo])) {
51 // get contact name of shared contact names
52 $sharedAddresses = [];
53 $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($currentAddressBlock['address']);
54 foreach ($currentAddressBlock['address'] as $key => $addressValue) {
55 if (!empty($addressValue['master_id']) &&
56 !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']
57 ) {
58 $sharedAddresses[$key]['shared_address_display'] = [
59 'address' => $addressValue['display'],
60 'name' => $shareAddressContactNames[$addressValue['master_id']]['name'],
61 ];
62 }
63 }
64 $idValue = $currentAddressBlock['address'][$locBlockNo]['id'];
65 if (!empty($currentAddressBlock['address'][$locBlockNo]['master_id'])) {
66 $idValue = $currentAddressBlock['address'][$locBlockNo]['master_id'];
67 }
68
69 // add custom data of type address
70 $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', NULL, $idValue);
71
72 // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
73 $currentAddressBlock['address'][$locBlockNo]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
74 $this->assign("dnc_viewCustomData", NULL);
75
76 $this->assign('add', $currentAddressBlock['address'][$locBlockNo]);
77 $this->assign('sharedAddresses', $sharedAddresses);
78 }
79 $contact = new CRM_Contact_BAO_Contact();
80 $contact->id = $contactId;
81 $contact->find(TRUE);
82 $privacy = [];
83 foreach (CRM_Contact_BAO_Contact::$_commPrefs as $name) {
84 if (isset($contact->$name)) {
85 $privacy[$name] = $contact->$name;
86 }
87 }
88
89 $this->assign('contactId', $contactId);
90 $this->assign('locationIndex', $locBlockNo);
91 $this->assign('addressId', $addressId);
92 $this->assign('privacy', $privacy);
93
94 // check logged in user permission
95 CRM_Contact_Page_View::checkUserPermission($this, $contactId);
96
97 // finally call parent
98 parent::run();
99 }
100
101 }