| 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_UserDashBoard_GroupContact extends CRM_Contact_Page_View_UserDashBoard { |
| 36 | |
| 37 | /** |
| 38 | * This function is called when action is browse |
| 39 | * |
| 40 | * return null |
| 41 | * @access public |
| 42 | */ |
| 43 | function browse() { |
| 44 | $count = CRM_Contact_BAO_GroupContact::getContactGroup( |
| 45 | $this->_contactId, |
| 46 | NULL, |
| 47 | NULL, TRUE, TRUE, |
| 48 | $this->_onlyPublicGroups |
| 49 | ); |
| 50 | |
| 51 | $in =& CRM_Contact_BAO_GroupContact::getContactGroup( |
| 52 | $this->_contactId, |
| 53 | 'Added', |
| 54 | NULL, FALSE, TRUE, |
| 55 | $this->_onlyPublicGroups |
| 56 | ); |
| 57 | |
| 58 | $pending =& CRM_Contact_BAO_GroupContact::getContactGroup( |
| 59 | $this->_contactId, |
| 60 | 'Pending', |
| 61 | NULL, FALSE, TRUE, |
| 62 | $this->_onlyPublicGroups |
| 63 | ); |
| 64 | |
| 65 | $out =& CRM_Contact_BAO_GroupContact::getContactGroup( |
| 66 | $this->_contactId, |
| 67 | 'Removed', |
| 68 | NULL, FALSE, TRUE, |
| 69 | $this->_onlyPublicGroups |
| 70 | ); |
| 71 | |
| 72 | $this->assign('groupCount', $count); |
| 73 | $this->assign_by_ref('groupIn', $in); |
| 74 | $this->assign_by_ref('groupPending', $pending); |
| 75 | $this->assign_by_ref('groupOut', $out); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * This function is called when action is update |
| 80 | * |
| 81 | * @param int $groupID group id |
| 82 | * |
| 83 | * return null |
| 84 | * @access public |
| 85 | */ |
| 86 | function edit($groupId = NULL) { |
| 87 | $this->assign('edit', $this->_edit); |
| 88 | if (!$this->_edit) { |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | $action = CRM_Utils_Request::retrieve('action', 'String', |
| 93 | CRM_Core_DAO::$_nullObject, |
| 94 | FALSE, 'browse' |
| 95 | ); |
| 96 | |
| 97 | if ($action == CRM_Core_Action::DELETE) { |
| 98 | $groupContactId = |
| 99 | CRM_Utils_Request::retrieve('gcid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE); |
| 100 | $status = |
| 101 | CRM_Utils_Request::retrieve('st', 'String', CRM_Core_DAO::$_nullObject, TRUE); |
| 102 | if (is_numeric($groupContactId) && $status) { |
| 103 | CRM_Contact_Page_View_GroupContact::del($groupContactId, $status, $this->_contactId); |
| 104 | } |
| 105 | |
| 106 | $url = CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}"); |
| 107 | CRM_Utils_System::redirect($url); |
| 108 | } |
| 109 | |
| 110 | $controller = new CRM_Core_Controller_Simple( |
| 111 | 'CRM_Contact_Form_GroupContact', |
| 112 | ts("Contact's Groups"), |
| 113 | CRM_Core_Action::ADD, |
| 114 | FALSE, FALSE, TRUE, FALSE |
| 115 | ); |
| 116 | $controller->setEmbedded(TRUE); |
| 117 | |
| 118 | $session = CRM_Core_Session::singleton(); |
| 119 | $session->pushUserContext( |
| 120 | CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}"), |
| 121 | FALSE |
| 122 | ); |
| 123 | |
| 124 | $controller->reset(); |
| 125 | $controller->set('contactId', $this->_contactId); |
| 126 | $controller->set('groupId', $groupId); |
| 127 | $controller->set('context', 'user'); |
| 128 | $controller->set('onlyPublicGroups', $this->_onlyPublicGroups); |
| 129 | $controller->process(); |
| 130 | $controller->run(); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * This function is the main function that is called when the page loads, |
| 135 | * it decides the which action has to be taken for the page. |
| 136 | * |
| 137 | * return null |
| 138 | * @access public |
| 139 | */ |
| 140 | function run() { |
| 141 | $this->edit(); |
| 142 | $this->browse(); |
| 143 | } |
| 144 | } |
| 145 | |