Merge pull request #23015 from ginkgomzd/php8-unsupported-operand
[civicrm-core.git] / CRM / Contact / Page / View / ContactSmartGroup.php
CommitLineData
926dcf00
KJ
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
926dcf00 5 | |
bc77d7c0
TO
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 |
926dcf00 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
926dcf00
KJ
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
926dcf00
KJ
16 */
17class CRM_Contact_Page_View_ContactSmartGroup extends CRM_Core_Page {
18
559865a0 19 /**
9f266042 20 * Contact id.
21 *
22 * @var int
559865a0
KJ
23 */
24 public $_contactId;
25
926dcf00 26 /**
9f266042 27 * Called when action is browse.
926dcf00 28 */
00be9182 29 public function browse() {
559865a0 30 $in = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added');
926dcf00
KJ
31
32 // keep track of all 'added' contact groups so we can remove them from the smart group
33 // section
be2fb01f 34 $staticGroups = [];
926dcf00
KJ
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);
ce80b209 42 $this->assign('groupSmart', NULL);
559865a0 43 $this->assign('groupParent', NULL);
926dcf00
KJ
44
45 if (!empty($allGroup)) {
be2fb01f 46 $smart = $parent = [];
926dcf00
KJ
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
00be9182 69 public function preProcess() {
2b549d90 70 $this->_contactId = (int) CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
926dcf00
KJ
71 $this->assign('contactId', $this->_contactId);
72
559865a0
KJ
73 $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
74 $this->assign('displayName', $displayName);
75
926dcf00
KJ
76 // check logged in url permission
77 CRM_Contact_Page_View::checkUserPermission($this);
926dcf00
KJ
78 }
79
80 /**
dc195289 81 * the main function that is called
926dcf00
KJ
82 * when the page loads, it decides the which action has
83 * to be taken for the page.
84 *
76e7a76c 85 * @return null
926dcf00 86 */
00be9182 87 public function run() {
926dcf00
KJ
88 $this->preProcess();
89 $this->browse();
90 return parent::run();
91 }
96025800 92
232624b1 93}