Merge pull request #23015 from ginkgomzd/php8-unsupported-operand
[civicrm-core.git] / CRM / Contact / Page / View / ContactSmartGroup.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 class CRM_Contact_Page_View_ContactSmartGroup extends CRM_Core_Page {
18
19 /**
20 * Contact id.
21 *
22 * @var int
23 */
24 public $_contactId;
25
26 /**
27 * Called when action is browse.
28 */
29 public function browse() {
30 $in = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added');
31
32 // keep track of all 'added' contact groups so we can remove them from the smart group
33 // section
34 $staticGroups = [];
35 if (!empty($in)) {
36 foreach ($in as $group) {
37 $staticGroups[$group['group_id']] = 1;
38 }
39 }
40
41 $allGroup = CRM_Contact_BAO_GroupContactCache::contactGroup($this->_contactId);
42 $this->assign('groupSmart', NULL);
43 $this->assign('groupParent', NULL);
44
45 if (!empty($allGroup)) {
46 $smart = $parent = [];
47 foreach ($allGroup['group'] as $group) {
48 // delete all smart groups which are also in static groups
49 if (isset($staticGroups[$group['id']])) {
50 continue;
51 }
52 if (empty($group['children'])) {
53 $smart[] = $group;
54 }
55 else {
56 $parent[] = $group;
57 }
58 }
59
60 if (!empty($smart)) {
61 $this->assign_by_ref('groupSmart', $smart);
62 }
63 if (!empty($parent)) {
64 $this->assign_by_ref('groupParent', $parent);
65 }
66 }
67 }
68
69 public function preProcess() {
70 $this->_contactId = (int) CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
71 $this->assign('contactId', $this->_contactId);
72
73 $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
74 $this->assign('displayName', $displayName);
75
76 // check logged in url permission
77 CRM_Contact_Page_View::checkUserPermission($this);
78 }
79
80 /**
81 * the main function that is called
82 * when the page loads, it decides the which action has
83 * to be taken for the page.
84 *
85 * @return null
86 */
87 public function run() {
88 $this->preProcess();
89 $this->browse();
90 return parent::run();
91 }
92
93 }