Import from SVN (r45945, r596)
[civicrm-core.git] / CRM / Contact / Page / View / UserDashBoard.php
CommitLineData
6a488035
TO
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
36/**
37 * CMS User Dashboard
38 * This class is used to build User Dashboard
39 *
40 */
41class CRM_Contact_Page_View_UserDashBoard extends CRM_Core_Page {
42 public $_contactId = NULL;
43
44 /*
45 * always show public groups
46 */
47
48 public $_onlyPublicGroups = TRUE;
49
50 public $_edit = TRUE;
51
52 /**
53 * The action links that we need to display for the browse screen
54 *
55 * @var array
56 * @static
57 */
58 static $_links = NULL; function __construct() {
59 parent::__construct();
60
61 $check = CRM_Core_Permission::check('access Contact Dashboard');
62
63 if (!$check) {
64 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
65 break;
66 }
67
68 $this->_contactId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
69
70 $session = CRM_Core_Session::singleton();
71 $userID = $session->get('userID');
72
73 if (!$this->_contactId) {
74 $this->_contactId = $userID;
75 }
76 elseif ($this->_contactId != $userID) {
77 if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::VIEW)) {
78 CRM_Core_Error::fatal(ts('You do not have permission to view this contact'));
79 }
80 if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
81 $this->_edit = FALSE;
82 }
83 }
84 }
85
86 /*
87 * Heart of the viewing process. The runner gets all the meta data for
88 * the contact and calls the appropriate type of page to view.
89 *
90 * @return void
91 * @access public
92 *
93 */
94 function preProcess() {
95 if (!$this->_contactId) {
96 CRM_Core_Error::fatal(ts('You must be logged in to view this page.'));
97 }
98
99 list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId);
100
101 $this->set('displayName', $displayName);
102 $this->set('contactImage', $contactImage);
103
104 CRM_Utils_System::setTitle(ts('Dashboard - %1', array(1 => $displayName)));
105
106 $this->assign('recentlyViewed', FALSE);
107 }
108
109 /**
110 * Function to build user dashboard
111 *
112 * @return none
113 * @access public
114 */
115 function buildUserDashBoard() {
116 //build component selectors
117 $dashboardElements = array();
118 $config = CRM_Core_Config::singleton();
119
120 $this->_userOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
121 'user_dashboard_options'
122 );
123
124 $components = CRM_Core_Component::getEnabledComponents();
125 $this->assign('contactId', $this->_contactId);
126 foreach ($components as $name => $component) {
127 $elem = $component->getUserDashboardElement();
128 if (!$elem) {
129 continue;
130 }
131
132 if (CRM_Utils_Array::value($name, $this->_userOptions) &&
133 (CRM_Core_Permission::access($component->name) ||
134 CRM_Core_Permission::check($elem['perm'][0])
135 )
136 ) {
137
138 $userDashboard = $component->getUserDashboardObject();
139 $dashboardElements[] = array('templatePath' => $userDashboard->getTemplateFileName(),
140 'sectionTitle' => $elem['title'],
141 'weight' => $elem['weight'],
142 );
143 $userDashboard->run();
144 }
145 }
146
147 if (CRM_Utils_Array::value('Permissioned Orgs', $this->_userOptions)) {
148 $dashboardElements[] = array(
149 'templatePath' => 'CRM/Contact/Page/View/Relationship.tpl',
150 'sectionTitle' => ts('Your Contacts / Organizations'),
151 'weight' => 40,
152 );
153
154 $links = self::links();
155 $currentRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId,
156 CRM_Contact_BAO_Relationship::CURRENT,
157 0, 0, 0,
158 $links, NULL, TRUE
159 );
160 $this->assign('currentRelationships', $currentRelationships);
161 }
162
163 if (CRM_Utils_Array::value('PCP', $this->_userOptions)) {
164 $dashboardElements[] = array(
165 'templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl',
166 'sectionTitle' => ts('Personal Campaign Pages'),
167 'weight' => 40,
168 );
169 list($pcpBlock, $pcpInfo) = CRM_PCP_BAO_PCP::getPcpDashboardInfo($this->_contactId);
170 $this->assign('pcpBlock', $pcpBlock);
171 $this->assign('pcpInfo', $pcpInfo);
172 }
173
174 if (CRM_Utils_Array::value('Assigned Activities', $this->_userOptions)) {
175 // Assigned Activities section
176 $dashboardElements[] = array(
177 'templatePath' => 'CRM/Activity/Page/UserDashboard.tpl',
178 'sectionTitle' => ts('Your Assigned Activities'),
179 'weight' => 5,
180 );
181 $userDashboard = new CRM_Activity_Page_UserDashboard;
182 $userDashboard->run();
183 }
184
185 usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc'));
186 $this->assign('dashboardElements', $dashboardElements);
187
188 if (CRM_Utils_Array::value('Groups', $this->_userOptions)) {
189 $this->assign('showGroup', TRUE);
190 //build group selector
191 $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
192 $gContact->run();
193 }
194 else {
195 $this->assign('showGroup', FALSE);
196 }
197 }
198
199 /**
200 * perform actions and display for user dashboard
201 *
202 * @return none
203 *
204 * @access public
205 */
206 function run() {
207 $this->preProcess();
208 $this->buildUserDashBoard();
209 return parent::run();
210 }
211
212 /**
213 * Get action links
214 *
215 * @return array (reference) of action links
216 * @static
217 */
218 static
219 function &links() {
220 if (!(self::$_links)) {
221 $disableExtra = ts('Are you sure you want to disable this relationship?');
222
223 self::$_links = array(
224 CRM_Core_Action::UPDATE => array(
225 'name' => ts('Edit Contact Information'),
226 'url' => 'civicrm/contact/relatedcontact',
227 'qs' => 'action=update&reset=1&cid=%%cbid%%&rcid=%%cid%%',
228 'title' => ts('Edit Relationship'),
229 ),
230 CRM_Core_Action::VIEW => array(
231 'name' => ts('Dashboard'),
232 'url' => 'civicrm/user',
233 'qs' => 'reset=1&id=%%cbid%%',
234 'title' => ts('View Relationship'),
235 ),
236 );
237
238
239 if (CRM_Core_Permission::check('access CiviCRM')) {
240 self::$_links = array_merge(self::$_links, array(
241 CRM_Core_Action::DISABLE => array(
242 'name' => ts('Disable'),
243 'url' => 'civicrm/contact/view/rel',
244 'qs' => 'action=disable&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel%%&context=dashboard',
245 'extra' => 'onclick = "return confirm(\'' . $disableExtra . '\');"',
246 'title' => ts('Disable Relationship'),
247 ),
248 ));
249 }
250 }
251
252 // call the hook so we can modify it
253 CRM_Utils_Hook::links('view.contact.userDashBoard',
254 'Contact',
255 CRM_Core_DAO::$_nullObject,
256 self::$_links,
257 CRM_Core_DAO::$_nullObject
258 );
259 return self::$_links;
260 }
261}
262