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