3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
35 class CRM_Contact_Page_View_GroupContact
extends CRM_Core_Page
{
38 * This function is called when action is browse
45 $count = CRM_Contact_BAO_GroupContact
::getContactGroup($this->_contactId
, NULL, NULL, TRUE);
47 $in = CRM_Contact_BAO_GroupContact
::getContactGroup($this->_contactId
, 'Added');
48 $pending = CRM_Contact_BAO_GroupContact
::getContactGroup($this->_contactId
, 'Pending');
49 $out = CRM_Contact_BAO_GroupContact
::getContactGroup($this->_contactId
, 'Removed');
51 // keep track of all 'added' contact groups so we can remove them from the smart group
53 $staticGroups = array();
55 foreach ($in as $group) {
56 $staticGroups[$group['group_id']] = 1;
60 $this->assign('groupCount', $count);
61 $this->assign_by_ref('groupIn', $in);
62 $this->assign_by_ref('groupPending', $pending);
63 $this->assign_by_ref('groupOut', $out);
65 // get the info on contact smart groups
66 $contactSmartGroupSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
67 'contact_smart_group_display');
68 $this->assign('contactSmartGroupSettings', $contactSmartGroupSettings);
72 * This function is called when action is update
74 * @param int $groupID group id
79 function edit($groupId = NULL) {
80 $controller = new CRM_Core_Controller_Simple(
81 'CRM_Contact_Form_GroupContact',
82 ts('Contact\'s Groups'),
85 $controller->setEmbedded(TRUE);
87 // set the userContext stack
88 $session = CRM_Core_Session
::singleton();
90 $session->pushUserContext(
91 CRM_Utils_System
::url(
92 'civicrm/contact/view',
93 "action=browse&selectedChild=group&cid={$this->_contactId}"
99 $controller->set('contactId', $this->_contactId
);
100 $controller->set('groupId', $groupId);
102 $controller->process();
106 function preProcess() {
107 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
108 $this->assign('contactId', $this->_contactId
);
110 // check logged in url permission
111 CRM_Contact_Page_View
::checkUserPermission($this);
113 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
114 $this->assign('action', $this->_action
);
118 * This function is the main function that is called
119 * when the page loads, it decides the which action has
120 * to be taken for the page.
128 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
129 $this->assign('displayName', $displayName);
131 if ($this->_action
== CRM_Core_Action
::DELETE
) {
132 $groupContactId = CRM_Utils_Request
::retrieve('gcid', 'Positive', CRM_Core_DAO
::$_nullObject, TRUE);
133 $status = CRM_Utils_Request
::retrieve('st', 'String', CRM_Core_DAO
::$_nullObject, TRUE);
134 if (is_numeric($groupContactId) && $status) {
135 $this->del($groupContactId, $status, $this->_contactId
);
137 $session = CRM_Core_Session
::singleton();
138 CRM_Utils_System
::redirect($session->popUserContext());
141 $this->edit(NULL, CRM_Core_Action
::ADD
);
143 return parent
::run();
147 * function to remove/ rejoin the group
149 * @param int $groupContactId id of crm_group_contact
150 * @param string $status this is the status that should be updated.
154 static function del($groupContactId, $status, $contactID) {
155 $groupId = CRM_Contact_BAO_GroupContact
::getGroupId($groupContactId);
159 $groupStatus = 'Added';
163 $groupStatus = 'Pending';
167 $groupStatus = 'Removed';
171 $groupStatus = 'Deleted';
176 CRM_Contact_BAO_GroupContact
::getContactGroup($contactID, 'Added', NULL, TRUE, TRUE);
177 if ($groupNum == 1 &&
178 $groupStatus == 'Removed' &&
179 CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::MULTISITE_PREFERENCES_NAME
,
183 CRM_Core_Session
::setStatus(ts('Please ensure at least one contact group association is maintained.'), ts('Could Not Remove'));
187 $ids = array($contactID);
190 $session = CRM_Core_Session
::singleton();
191 $userID = $session->get('userID');
193 if ($userID == $contactID) {
197 CRM_Contact_BAO_GroupContact
::removeContactsFromGroup($ids, $groupId, $method, $groupStatus);