Commit | Line | Data |
---|---|---|
926dcf00 KJ |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
926dcf00 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
926dcf00 KJ |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
926dcf00 KJ |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
926dcf00 KJ |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Contact_Page_View_ContactSmartGroup extends CRM_Core_Page { | |
36 | ||
559865a0 KJ |
37 | /** |
38 | * @var int contact id | |
39 | */ | |
40 | public $_contactId; | |
41 | ||
926dcf00 | 42 | /** |
fe482240 | 43 | * called when action is browse. |
926dcf00 | 44 | * |
926dcf00 | 45 | */ |
00be9182 | 46 | public function browse() { |
559865a0 | 47 | $in = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added'); |
926dcf00 KJ |
48 | |
49 | // keep track of all 'added' contact groups so we can remove them from the smart group | |
50 | // section | |
51 | $staticGroups = array(); | |
52 | if (!empty($in)) { | |
53 | foreach ($in as $group) { | |
54 | $staticGroups[$group['group_id']] = 1; | |
55 | } | |
56 | } | |
57 | ||
58 | $allGroup = CRM_Contact_BAO_GroupContactCache::contactGroup($this->_contactId); | |
ce80b209 | 59 | $this->assign('groupSmart', NULL); |
559865a0 | 60 | $this->assign('groupParent', NULL); |
926dcf00 KJ |
61 | |
62 | if (!empty($allGroup)) { | |
ce80b209 | 63 | $smart = $parent = array(); |
926dcf00 KJ |
64 | foreach ($allGroup['group'] as $group) { |
65 | // delete all smart groups which are also in static groups | |
66 | if (isset($staticGroups[$group['id']])) { | |
67 | continue; | |
68 | } | |
69 | if (empty($group['children'])) { | |
70 | $smart[] = $group; | |
71 | } | |
72 | else { | |
73 | $parent[] = $group; | |
74 | } | |
75 | } | |
76 | ||
77 | if (!empty($smart)) { | |
78 | $this->assign_by_ref('groupSmart', $smart); | |
79 | } | |
80 | if (!empty($parent)) { | |
81 | $this->assign_by_ref('groupParent', $parent); | |
82 | } | |
83 | } | |
84 | } | |
85 | ||
00be9182 | 86 | public function preProcess() { |
926dcf00 KJ |
87 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); |
88 | $this->assign('contactId', $this->_contactId); | |
89 | ||
559865a0 KJ |
90 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); |
91 | $this->assign('displayName', $displayName); | |
92 | ||
926dcf00 KJ |
93 | // check logged in url permission |
94 | CRM_Contact_Page_View::checkUserPermission($this); | |
926dcf00 KJ |
95 | } |
96 | ||
97 | /** | |
dc195289 | 98 | * the main function that is called |
926dcf00 KJ |
99 | * when the page loads, it decides the which action has |
100 | * to be taken for the page. | |
101 | * | |
76e7a76c | 102 | * @return null |
926dcf00 | 103 | */ |
00be9182 | 104 | public function run() { |
926dcf00 KJ |
105 | $this->preProcess(); |
106 | $this->browse(); | |
107 | return parent::run(); | |
108 | } | |
96025800 | 109 | |
232624b1 | 110 | } |