41a9fdac32c012f1dc9ae8499e4485d52752adf8
[civicrm-core.git] / CRM / Contact / Page / View / UserDashBoard / GroupContact.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Contact_Page_View_UserDashBoard_GroupContact extends CRM_Contact_Page_View_UserDashBoard {
18
19 /**
20 * Called when action is browse.
21 */
22 public function browse() {
23 $count = CRM_Contact_BAO_GroupContact::getContactGroup(
24 $this->_contactId,
25 NULL,
26 NULL, TRUE, TRUE,
27 $this->_onlyPublicGroups,
28 NULL, NULL, TRUE, TRUE
29 );
30
31 $in = CRM_Contact_BAO_GroupContact::getContactGroup(
32 $this->_contactId,
33 'Added',
34 NULL, FALSE, TRUE,
35 $this->_onlyPublicGroups,
36 NULL, NULL, TRUE, TRUE
37 );
38
39 $pending = CRM_Contact_BAO_GroupContact::getContactGroup(
40 $this->_contactId,
41 'Pending',
42 NULL, FALSE, TRUE,
43 $this->_onlyPublicGroups,
44 NULL, NULL, TRUE, TRUE
45 );
46
47 $out = CRM_Contact_BAO_GroupContact::getContactGroup(
48 $this->_contactId,
49 'Removed',
50 NULL, FALSE, TRUE,
51 $this->_onlyPublicGroups,
52 NULL, NULL, TRUE, TRUE
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 /**
62 * called when action is update.
63 *
64 * @param int $groupId
65 *
66 * @return null
67 */
68 public function edit($groupId = NULL) {
69 $this->assign('edit', $this->_edit);
70 if (!$this->_edit) {
71 return NULL;
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) {
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);
82 if (is_numeric($groupContactId) && $status) {
83 CRM_Contact_Page_View_GroupContact::del($groupContactId, $status, $this->_contactId);
84 }
85
86 $url = CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}");
87 CRM_Utils_System::redirect($url);
88 }
89
90 $controller = new CRM_Core_Controller_Simple(
91 'CRM_Contact_Form_GroupContact',
92 ts("Contact's Groups"),
93 CRM_Core_Action::ADD,
94 FALSE, FALSE, TRUE, FALSE
95 );
96 $controller->setEmbedded(TRUE);
97
98 $session = CRM_Core_Session::singleton();
99 $session->pushUserContext(
100 CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}"),
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 /**
114 * The main function that is called when the page loads.
115 *
116 * It decides the which action has to be taken for the page.
117 */
118 public function run() {
119 $this->edit();
120 $this->browse();
121 }
122
123 }