3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Contact_Page_View_GroupContact
extends CRM_Core_Page
{
20 * Called when action is browse.
22 public function browse() {
24 $count = CRM_Contact_BAO_GroupContact
::getContactGroup($this->_contactId
, NULL, NULL, TRUE, FALSE, FALSE, TRUE, NULL, TRUE);
26 $in = CRM_Contact_BAO_GroupContact
::getContactGroup($this->_contactId
, 'Added', NULL, FALSE, FALSE, FALSE, TRUE, NULL, TRUE);
27 $pending = CRM_Contact_BAO_GroupContact
::getContactGroup($this->_contactId
, 'Pending', NULL, FALSE, FALSE, FALSE, TRUE, NULL, TRUE);
28 $out = CRM_Contact_BAO_GroupContact
::getContactGroup($this->_contactId
, 'Removed', NULL, FALSE, FALSE, FALSE, TRUE, NULL, TRUE);
30 // keep track of all 'added' contact groups so we can remove them from the smart group
34 foreach ($in as $group) {
35 $staticGroups[$group['group_id']] = 1;
39 $this->assign('groupCount', $count);
40 $this->assign_by_ref('groupIn', $in);
41 $this->assign_by_ref('groupPending', $pending);
42 $this->assign_by_ref('groupOut', $out);
44 // get the info on contact smart groups
45 $contactSmartGroupSettings = Civi
::settings()->get('contact_smart_group_display');
46 $this->assign('contactSmartGroupSettings', $contactSmartGroupSettings);
48 $this->ajaxResponse
['tabCount'] = count($in);
52 * called when action is update.
57 public function edit($groupId = NULL) {
58 $controller = new CRM_Core_Controller_Simple(
59 'CRM_Contact_Form_GroupContact',
60 ts('Contact\'s Groups'),
63 $controller->setEmbedded(TRUE);
65 // set the userContext stack
66 $session = CRM_Core_Session
::singleton();
68 $session->pushUserContext(
69 CRM_Utils_System
::url(
70 'civicrm/contact/view',
71 "action=browse&selectedChild=group&cid={$this->_contactId}"
77 $controller->set('contactId', $this->_contactId
);
78 $controller->set('groupId', $groupId);
80 $controller->process();
84 public function preProcess() {
85 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
86 $this->assign('contactId', $this->_contactId
);
88 // check logged in url permission
89 CRM_Contact_Page_View
::checkUserPermission($this);
91 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
92 $this->assign('action', $this->_action
);
96 * the main function that is called
97 * when the page loads, it decides the which action has
98 * to be taken for the page.
102 public function run() {
105 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
106 $this->assign('displayName', $displayName);
108 if ($this->_action
== CRM_Core_Action
::DELETE
) {
109 $groupContactId = CRM_Utils_Request
::retrieve('gcid', 'Positive', CRM_Core_DAO
::$_nullObject, TRUE);
110 $status = CRM_Utils_Request
::retrieve('st', 'String', CRM_Core_DAO
::$_nullObject, TRUE);
111 if (is_numeric($groupContactId) && $status) {
112 $this->del($groupContactId, $status, $this->_contactId
);
114 $session = CRM_Core_Session
::singleton();
115 CRM_Utils_System
::redirect($session->popUserContext());
118 $this->edit(NULL, CRM_Core_Action
::ADD
);
120 return parent
::run();
124 * Remove/ rejoin the group
126 * @param int $groupContactId
127 * Id of crm_group_contact.
128 * @param string $status
129 * This is the status that should be updated.
132 * @param int $contactID
136 public static function del($groupContactId, $status, $contactID) {
137 $groupId = CRM_Contact_BAO_GroupContact
::getGroupId($groupContactId);
141 $groupStatus = 'Added';
145 $groupStatus = 'Pending';
149 $groupStatus = 'Removed';
153 $groupStatus = 'Deleted';
157 $groupNum = CRM_Contact_BAO_GroupContact
::getContactGroup($contactID, 'Added', NULL, TRUE, TRUE);
158 if ($groupNum == 1 && $groupStatus == 'Removed' && Civi
::settings()->get('is_enabled')) {
159 CRM_Core_Session
::setStatus(ts('Please ensure at least one contact group association is maintained.'), ts('Could Not Remove'));
166 $session = CRM_Core_Session
::singleton();
167 $userID = $session->get('userID');
169 if ($userID == $contactID) {
173 CRM_Contact_BAO_GroupContact
::removeContactsFromGroup($ids, $groupId, $method, $groupStatus);