Commit | Line | Data |
---|---|---|
926dcf00 KJ |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | class CRM_Contact_Page_View_ContactSmartGroup extends CRM_Core_Page { | |
36 | ||
37 | /** | |
38 | * This function is called when action is browse | |
39 | * | |
40 | * return null | |
41 | * @access public | |
42 | */ | |
43 | function browse() { | |
44 | $in = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added'); | |
45 | ||
46 | // keep track of all 'added' contact groups so we can remove them from the smart group | |
47 | // section | |
48 | $staticGroups = array(); | |
49 | if (!empty($in)) { | |
50 | foreach ($in as $group) { | |
51 | $staticGroups[$group['group_id']] = 1; | |
52 | } | |
53 | } | |
54 | ||
55 | $allGroup = CRM_Contact_BAO_GroupContactCache::contactGroup($this->_contactId); | |
56 | $this->assign('groupSmart' , null); | |
57 | $this->assign('groupParent', null); | |
58 | ||
59 | if (!empty($allGroup)) { | |
60 | $smart = $parent = array( ); | |
61 | foreach ($allGroup['group'] as $group) { | |
62 | // delete all smart groups which are also in static groups | |
63 | if (isset($staticGroups[$group['id']])) { | |
64 | continue; | |
65 | } | |
66 | if (empty($group['children'])) { | |
67 | $smart[] = $group; | |
68 | } | |
69 | else { | |
70 | $parent[] = $group; | |
71 | } | |
72 | } | |
73 | ||
74 | if (!empty($smart)) { | |
75 | $this->assign_by_ref('groupSmart', $smart); | |
76 | } | |
77 | if (!empty($parent)) { | |
78 | $this->assign_by_ref('groupParent', $parent); | |
79 | } | |
80 | } | |
81 | } | |
82 | ||
83 | function preProcess() { | |
84 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); | |
85 | $this->assign('contactId', $this->_contactId); | |
86 | ||
87 | // check logged in url permission | |
88 | CRM_Contact_Page_View::checkUserPermission($this); | |
89 | ||
90 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); | |
91 | $this->assign('action', $this->_action); | |
92 | } | |
93 | ||
94 | /** | |
95 | * This function is the main function that is called | |
96 | * when the page loads, it decides the which action has | |
97 | * to be taken for the page. | |
98 | * | |
99 | * return null | |
100 | * @access public | |
101 | */ | |
102 | function run() { | |
103 | $this->preProcess(); | |
104 | $this->browse(); | |
105 | return parent::run(); | |
106 | } | |
107 | } |