3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class is used to build User Dashboard
21 class CRM_Contact_Page_View_UserDashBoard
extends CRM_Core_Page
{
22 public $_contactId = NULL;
25 * Always show public groups.
28 public $_onlyPublicGroups = TRUE;
33 * The action links that we need to display for the browse screen.
37 public static $_links = NULL;
42 public function __construct() {
43 parent
::__construct();
45 if (!CRM_Core_Permission
::check('access Contact Dashboard')) {
46 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/dashboard', 'reset=1'));
49 $this->_contactId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
50 $userID = CRM_Core_Session
::getLoggedInContactID();
52 $userChecksum = $this->getUserChecksum();
55 $this->assign('userChecksum', $userChecksum);
56 $validUser = CRM_Contact_BAO_Contact_Utils
::validChecksum($this->_contactId
, $userChecksum);
57 $this->_isChecksumUser
= $validUser;
60 if (!$this->_contactId
) {
61 $this->_contactId
= $userID;
63 elseif ($this->_contactId
!= $userID && !$validUser) {
64 if (!CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::VIEW
)) {
65 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this contact.'));
67 if (!CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::EDIT
)) {
74 * Heart of the viewing process.
76 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
78 public function preProcess() {
79 if (!$this->_contactId
) {
80 throw new CRM_Core_Exception(ts('You must be logged in to view this page.'));
83 list($displayName, $contactImage) = CRM_Contact_BAO_Contact
::getDisplayAndImage($this->_contactId
);
85 $this->set('displayName', $displayName);
86 $this->set('contactImage', $contactImage);
88 CRM_Utils_System
::setTitle(ts('Dashboard - %1', [1 => $displayName]));
90 $this->assign('recentlyViewed', FALSE);
94 * Build user dashboard.
96 public function buildUserDashBoard() {
97 //build component selectors
98 $dashboardElements = [];
100 $dashboardOptions = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
101 'user_dashboard_options'
104 $components = CRM_Core_Component
::getEnabledComponents();
105 $this->assign('contactId', $this->_contactId
);
106 foreach ($components as $name => $component) {
107 $elem = $component->getUserDashboardElement();
112 if (!empty($dashboardOptions[$name]) &&
113 (CRM_Core_Permission
::access($component->name
) ||
114 CRM_Core_Permission
::check($elem['perm'][0])
118 $userDashboard = $component->getUserDashboardObject();
119 $dashboardElements[] = [
120 'class' => 'crm-dashboard-' . strtolower($component->name
),
121 'sectionTitle' => $elem['title'],
122 'templatePath' => $userDashboard->getTemplateFileName(),
123 'weight' => $elem['weight'],
125 $userDashboard->run();
129 // CRM-16512 - Hide related contact table if user lacks permission to view self
130 if (!empty($dashboardOptions['Permissioned Orgs']) && CRM_Core_Permission
::check('view my contact')) {
131 $columnHeaders = CRM_Contact_BAO_Relationship
::getColumnHeaders();
132 $contactRelationships = $selector = NULL;
133 CRM_Utils_Hook
::searchColumns('relationship.columns', $columnHeaders, $contactRelationships, $selector);
134 $this->assign('columnHeaders', $columnHeaders);
135 $dashboardElements[] = [
136 'class' => 'crm-dashboard-permissionedOrgs',
137 'templatePath' => 'CRM/Contact/Page/View/RelationshipSelector.tpl',
138 'sectionTitle' => ts('Your Contacts / Organizations'),
144 if (!empty($dashboardOptions['PCP'])) {
145 $dashboardElements[] = [
146 'class' => 'crm-dashboard-pcp',
147 'templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl',
148 'sectionTitle' => ts('Personal Campaign Pages'),
151 list($pcpBlock, $pcpInfo) = CRM_PCP_BAO_PCP
::getPcpDashboardInfo($this->_contactId
);
152 $this->assign('pcpBlock', $pcpBlock);
153 $this->assign('pcpInfo', $pcpInfo);
156 if (!empty($dashboardOptions['Assigned Activities']) && empty($this->_isChecksumUser
)) {
157 // Assigned Activities section
158 $dashboardElements[] = [
159 'class' => 'crm-dashboard-assignedActivities',
160 'templatePath' => 'CRM/Activity/Page/UserDashboard.tpl',
161 'sectionTitle' => ts('Your Assigned Activities'),
164 $userDashboard = new CRM_Activity_Page_UserDashboard();
165 $userDashboard->run();
168 usort($dashboardElements, ['CRM_Utils_Sort', 'cmpFunc']);
169 $this->assign('dashboardElements', $dashboardElements);
171 if (!empty($dashboardOptions['Groups'])) {
172 $this->assign('showGroup', TRUE);
173 //build group selector
174 $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
178 $this->assign('showGroup', FALSE);
183 * Perform actions and display for user dashboard.
185 public function run() {
187 $this->buildUserDashBoard();
188 return parent
::run();
195 * (reference) of action links
197 public static function &links() {
198 if (!(self
::$_links)) {
199 $disableExtra = ts('Are you sure you want to disable this relationship?');
202 CRM_Core_Action
::UPDATE
=> [
203 'name' => ts('Edit Contact Information'),
204 'url' => 'civicrm/contact/relatedcontact',
205 'qs' => 'action=update&reset=1&cid=%%cbid%%&rcid=%%cid%%',
206 'title' => ts('Edit Contact Information'),
208 CRM_Core_Action
::VIEW
=> [
209 'name' => ts('Dashboard'),
210 'url' => 'civicrm/user',
211 'class' => 'no-popup',
212 'qs' => 'reset=1&id=%%cbid%%',
213 'title' => ts('View Contact Dashboard'),
217 if (CRM_Core_Permission
::check('access CiviCRM')) {
219 CRM_Core_Action
::DISABLE
=> [
220 'name' => ts('Disable'),
221 'url' => 'civicrm/contact/view/rel',
222 'qs' => 'action=disable&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel&context=dashboard',
223 'extra' => 'onclick = "return confirm(\'' . $disableExtra . '\');"',
224 'title' => ts('Disable Relationship'),
230 // call the hook so we can modify it
231 CRM_Utils_Hook
::links('view.contact.userDashBoard',
233 CRM_Core_DAO
::$_nullObject,
236 return self
::$_links;
240 * Get the user checksum from the url to use in links.
244 protected function getUserChecksum() {
245 $userChecksum = CRM_Utils_Request
::retrieve('cs', 'String', $this);
246 if (empty($userID) && $this->_contactId
) {
247 return $userChecksum;