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