Merge in 5.48
[civicrm-core.git] / CRM / Contact / Page / View / UserDashBoard / GroupContact.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17class CRM_Contact_Page_View_UserDashBoard_GroupContact extends CRM_Contact_Page_View_UserDashBoard {
18
19 /**
95cdcc0f 20 * Called when action is browse.
6a488035 21 */
00be9182 22 public function browse() {
9f6f062c
DL
23 $count = CRM_Contact_BAO_GroupContact::getContactGroup(
24 $this->_contactId,
6a488035
TO
25 NULL,
26 NULL, TRUE, TRUE,
ec6d2df4 27 $this->_onlyPublicGroups,
be44418d 28 NULL, NULL, TRUE, TRUE
6a488035
TO
29 );
30
f078bc70 31 $in = CRM_Contact_BAO_GroupContact::getContactGroup(
9f6f062c 32 $this->_contactId,
6a488035
TO
33 'Added',
34 NULL, FALSE, TRUE,
ec6d2df4 35 $this->_onlyPublicGroups,
be44418d 36 NULL, NULL, TRUE, TRUE
6a488035 37 );
9f6f062c 38
f078bc70 39 $pending = CRM_Contact_BAO_GroupContact::getContactGroup(
9f6f062c 40 $this->_contactId,
6a488035
TO
41 'Pending',
42 NULL, FALSE, TRUE,
ec6d2df4 43 $this->_onlyPublicGroups,
be44418d 44 NULL, NULL, TRUE, TRUE
6a488035 45 );
9f6f062c 46
f078bc70 47 $out = CRM_Contact_BAO_GroupContact::getContactGroup(
9f6f062c 48 $this->_contactId,
6a488035
TO
49 'Removed',
50 NULL, FALSE, TRUE,
ec6d2df4 51 $this->_onlyPublicGroups,
be44418d 52 NULL, NULL, TRUE, TRUE
6a488035
TO
53 );
54
55 $this->assign('groupCount', $count);
56 $this->assign_by_ref('groupIn', $in);
57 $this->assign_by_ref('groupPending', $pending);
58 $this->assign_by_ref('groupOut', $out);
59 }
60
61 /**
fe482240 62 * called when action is update.
6a488035 63 *
c490a46a 64 * @param int $groupId
6a488035 65 *
76e7a76c 66 * @return null
6a488035 67 */
00be9182 68 public function edit($groupId = NULL) {
6a488035
TO
69 $this->assign('edit', $this->_edit);
70 if (!$this->_edit) {
408b79bf 71 return NULL;
6a488035
TO
72 }
73
74 $action = CRM_Utils_Request::retrieve('action', 'String',
75 CRM_Core_DAO::$_nullObject,
76 FALSE, 'browse'
77 );
78
79 if ($action == CRM_Core_Action::DELETE) {
408b79bf 80 $groupContactId = CRM_Utils_Request::retrieve('gcid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
81 $status = CRM_Utils_Request::retrieve('st', 'String', CRM_Core_DAO::$_nullObject, TRUE);
6a488035
TO
82 if (is_numeric($groupContactId) && $status) {
83 CRM_Contact_Page_View_GroupContact::del($groupContactId, $status, $this->_contactId);
84 }
85
9f6f062c 86 $url = CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}");
6a488035
TO
87 CRM_Utils_System::redirect($url);
88 }
89
9f6f062c
DL
90 $controller = new CRM_Core_Controller_Simple(
91 'CRM_Contact_Form_GroupContact',
6a488035 92 ts("Contact's Groups"),
9f6f062c
DL
93 CRM_Core_Action::ADD,
94 FALSE, FALSE, TRUE, FALSE
6a488035
TO
95 );
96 $controller->setEmbedded(TRUE);
97
98 $session = CRM_Core_Session::singleton();
9f6f062c
DL
99 $session->pushUserContext(
100 CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}"),
6a488035
TO
101 FALSE
102 );
103
104 $controller->reset();
105 $controller->set('contactId', $this->_contactId);
106 $controller->set('groupId', $groupId);
107 $controller->set('context', 'user');
108 $controller->set('onlyPublicGroups', $this->_onlyPublicGroups);
109 $controller->process();
110 $controller->run();
111 }
112
113 /**
95cdcc0f 114 * The main function that is called when the page loads.
6a488035 115 *
95cdcc0f 116 * It decides the which action has to be taken for the page.
6a488035 117 */
00be9182 118 public function run() {
6a488035
TO
119 $this->edit();
120 $this->browse();
121 }
96025800 122
6a488035 123}