Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
6a488035 | 19 | * This class is used to build User Dashboard |
6a488035 TO |
20 | */ |
21 | class CRM_Contact_Page_View_UserDashBoard extends CRM_Core_Page { | |
22 | public $_contactId = NULL; | |
23 | ||
c490a46a | 24 | /** |
fe482240 | 25 | * Always show public groups. |
c490a46a CW |
26 | * @var bool |
27 | */ | |
6a488035 TO |
28 | public $_onlyPublicGroups = TRUE; |
29 | ||
30 | public $_edit = TRUE; | |
31 | ||
32 | /** | |
fe482240 | 33 | * The action links that we need to display for the browse screen. |
6a488035 TO |
34 | * |
35 | * @var array | |
6a488035 | 36 | */ |
9cd3992e | 37 | public static $_links = NULL; |
430ae6dd | 38 | |
4319322b EM |
39 | /** |
40 | * @throws Exception | |
41 | */ | |
00be9182 | 42 | public function __construct() { |
6a488035 TO |
43 | parent::__construct(); |
44 | ||
83564f94 | 45 | if (!CRM_Core_Permission::check('access Contact Dashboard')) { |
6a488035 | 46 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); |
6a488035 TO |
47 | } |
48 | ||
49 | $this->_contactId = CRM_Utils_Request::retrieve('id', 'Positive', $this); | |
83564f94 | 50 | $userID = CRM_Core_Session::singleton()->getLoggedInContactID(); |
6a488035 | 51 | |
2d97420b | 52 | $userChecksum = $this->getUserChecksum(); |
2b329653 | 53 | $validUser = FALSE; |
2d97420b | 54 | if ($userChecksum) { |
e8401861 | 55 | $this->assign('userChecksum', $userChecksum); |
2b329653 | 56 | $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($this->_contactId, $userChecksum); |
4ded03d2 | 57 | $this->_isChecksumUser = $validUser; |
2b329653 JP |
58 | } |
59 | ||
6a488035 TO |
60 | if (!$this->_contactId) { |
61 | $this->_contactId = $userID; | |
62 | } | |
2b329653 | 63 | elseif ($this->_contactId != $userID && !$validUser) { |
6a488035 | 64 | if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::VIEW)) { |
beb414cc | 65 | CRM_Core_Error::statusBounce(ts('You do not have permission to access this contact.')); |
6a488035 TO |
66 | } |
67 | if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { | |
68 | $this->_edit = FALSE; | |
69 | } | |
70 | } | |
71 | } | |
72 | ||
c490a46a | 73 | /** |
95cdcc0f | 74 | * Heart of the viewing process. |
c490a46a | 75 | * |
95cdcc0f | 76 | * The runner gets all the meta data for the contact and calls the appropriate type of page to view. |
c490a46a | 77 | */ |
00be9182 | 78 | public function preProcess() { |
6a488035 TO |
79 | if (!$this->_contactId) { |
80 | CRM_Core_Error::fatal(ts('You must be logged in to view this page.')); | |
81 | } | |
82 | ||
83 | list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId); | |
84 | ||
85 | $this->set('displayName', $displayName); | |
86 | $this->set('contactImage', $contactImage); | |
87 | ||
be2fb01f | 88 | CRM_Utils_System::setTitle(ts('Dashboard - %1', [1 => $displayName])); |
6a488035 TO |
89 | |
90 | $this->assign('recentlyViewed', FALSE); | |
91 | } | |
92 | ||
93 | /** | |
fe482240 | 94 | * Build user dashboard. |
6a488035 | 95 | */ |
00be9182 | 96 | public function buildUserDashBoard() { |
6a488035 | 97 | //build component selectors |
a50321d2 | 98 | $dashboardElements = []; |
6a488035 | 99 | |
a50321d2 | 100 | $dashboardOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
6a488035 TO |
101 | 'user_dashboard_options' |
102 | ); | |
103 | ||
104 | $components = CRM_Core_Component::getEnabledComponents(); | |
105 | $this->assign('contactId', $this->_contactId); | |
106 | foreach ($components as $name => $component) { | |
107 | $elem = $component->getUserDashboardElement(); | |
108 | if (!$elem) { | |
109 | continue; | |
110 | } | |
111 | ||
a50321d2 | 112 | if (!empty($dashboardOptions[$name]) && |
6a488035 TO |
113 | (CRM_Core_Permission::access($component->name) || |
114 | CRM_Core_Permission::check($elem['perm'][0]) | |
115 | ) | |
116 | ) { | |
117 | ||
118 | $userDashboard = $component->getUserDashboardObject(); | |
be2fb01f | 119 | $dashboardElements[] = [ |
e81ccbf6 | 120 | 'class' => 'crm-dashboard-' . strtolower($component->name), |
6a488035 | 121 | 'sectionTitle' => $elem['title'], |
e81ccbf6 | 122 | 'templatePath' => $userDashboard->getTemplateFileName(), |
6a488035 | 123 | 'weight' => $elem['weight'], |
be2fb01f | 124 | ]; |
6a488035 TO |
125 | $userDashboard->run(); |
126 | } | |
127 | } | |
128 | ||
bb36d17a | 129 | // CRM-16512 - Hide related contact table if user lacks permission to view self |
a50321d2 | 130 | if (!empty($dashboardOptions['Permissioned Orgs']) && CRM_Core_Permission::check('view my contact')) { |
16b745b0 MWMC |
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); | |
be2fb01f | 135 | $dashboardElements[] = [ |
e81ccbf6 | 136 | 'class' => 'crm-dashboard-permissionedOrgs', |
d0592c3d | 137 | 'templatePath' => 'CRM/Contact/Page/View/RelationshipSelector.tpl', |
6a488035 TO |
138 | 'sectionTitle' => ts('Your Contacts / Organizations'), |
139 | 'weight' => 40, | |
be2fb01f | 140 | ]; |
6a488035 | 141 | |
6a488035 TO |
142 | } |
143 | ||
a50321d2 | 144 | if (!empty($dashboardOptions['PCP'])) { |
be2fb01f | 145 | $dashboardElements[] = [ |
e81ccbf6 | 146 | 'class' => 'crm-dashboard-pcp', |
6a488035 TO |
147 | 'templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl', |
148 | 'sectionTitle' => ts('Personal Campaign Pages'), | |
149 | 'weight' => 40, | |
be2fb01f | 150 | ]; |
6a488035 TO |
151 | list($pcpBlock, $pcpInfo) = CRM_PCP_BAO_PCP::getPcpDashboardInfo($this->_contactId); |
152 | $this->assign('pcpBlock', $pcpBlock); | |
153 | $this->assign('pcpInfo', $pcpInfo); | |
154 | } | |
155 | ||
a50321d2 | 156 | if (!empty($dashboardOptions['Assigned Activities']) && empty($this->_isChecksumUser)) { |
6a488035 | 157 | // Assigned Activities section |
be2fb01f | 158 | $dashboardElements[] = [ |
e81ccbf6 | 159 | 'class' => 'crm-dashboard-assignedActivities', |
6a488035 TO |
160 | 'templatePath' => 'CRM/Activity/Page/UserDashboard.tpl', |
161 | 'sectionTitle' => ts('Your Assigned Activities'), | |
162 | 'weight' => 5, | |
be2fb01f | 163 | ]; |
acb1052e | 164 | $userDashboard = new CRM_Activity_Page_UserDashboard(); |
6a488035 TO |
165 | $userDashboard->run(); |
166 | } | |
167 | ||
be2fb01f | 168 | usort($dashboardElements, ['CRM_Utils_Sort', 'cmpFunc']); |
6a488035 TO |
169 | $this->assign('dashboardElements', $dashboardElements); |
170 | ||
a50321d2 | 171 | if (!empty($dashboardOptions['Groups'])) { |
6a488035 TO |
172 | $this->assign('showGroup', TRUE); |
173 | //build group selector | |
174 | $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact(); | |
175 | $gContact->run(); | |
176 | } | |
177 | else { | |
178 | $this->assign('showGroup', FALSE); | |
179 | } | |
180 | } | |
181 | ||
182 | /** | |
fe482240 | 183 | * Perform actions and display for user dashboard. |
6a488035 | 184 | */ |
00be9182 | 185 | public function run() { |
6a488035 TO |
186 | $this->preProcess(); |
187 | $this->buildUserDashBoard(); | |
188 | return parent::run(); | |
189 | } | |
190 | ||
191 | /** | |
fe482240 | 192 | * Get action links. |
6a488035 | 193 | * |
a6c01b45 CW |
194 | * @return array |
195 | * (reference) of action links | |
6a488035 | 196 | */ |
74607358 | 197 | public static function &links() { |
6a488035 TO |
198 | if (!(self::$_links)) { |
199 | $disableExtra = ts('Are you sure you want to disable this relationship?'); | |
200 | ||
be2fb01f CW |
201 | self::$_links = [ |
202 | CRM_Core_Action::UPDATE => [ | |
6a488035 TO |
203 | 'name' => ts('Edit Contact Information'), |
204 | 'url' => 'civicrm/contact/relatedcontact', | |
205 | 'qs' => 'action=update&reset=1&cid=%%cbid%%&rcid=%%cid%%', | |
c99ad28e | 206 | 'title' => ts('Edit Contact Information'), |
be2fb01f CW |
207 | ], |
208 | CRM_Core_Action::VIEW => [ | |
6a488035 TO |
209 | 'name' => ts('Dashboard'), |
210 | 'url' => 'civicrm/user', | |
5940abe4 | 211 | 'class' => 'no-popup', |
6a488035 | 212 | 'qs' => 'reset=1&id=%%cbid%%', |
bc13177a | 213 | 'title' => ts('View Contact Dashboard'), |
be2fb01f CW |
214 | ], |
215 | ]; | |
6a488035 | 216 | |
6a488035 | 217 | if (CRM_Core_Permission::check('access CiviCRM')) { |
be2fb01f CW |
218 | self::$_links += [ |
219 | CRM_Core_Action::DISABLE => [ | |
353ffa53 TO |
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'), | |
be2fb01f CW |
225 | ], |
226 | ]; | |
6a488035 TO |
227 | } |
228 | } | |
229 | ||
230 | // call the hook so we can modify it | |
231 | CRM_Utils_Hook::links('view.contact.userDashBoard', | |
232 | 'Contact', | |
233 | CRM_Core_DAO::$_nullObject, | |
1273d77c | 234 | self::$_links |
6a488035 TO |
235 | ); |
236 | return self::$_links; | |
237 | } | |
96025800 | 238 | |
2d97420b | 239 | /** |
240 | * Get the user checksum from the url to use in links. | |
241 | * | |
242 | * @return string | |
243 | */ | |
244 | protected function getUserChecksum() { | |
245 | $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this); | |
246 | if (empty($userID) && $this->_contactId) { | |
247 | return $userChecksum; | |
248 | } | |
249 | return FALSE; | |
250 | } | |
251 | ||
6a488035 | 252 | } |