3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
38 * This class is used to build User Dashboard
41 class CRM_Contact_Page_View_UserDashBoard
extends CRM_Core_Page
{
42 public $_contactId = NULL;
45 * always show public groups
48 public $_onlyPublicGroups = TRUE;
53 * The action links that we need to display for the browse screen
58 static $_links = NULL;
60 function __construct() {
61 parent
::__construct();
63 $check = CRM_Core_Permission
::check('access Contact Dashboard');
66 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/dashboard', 'reset=1'));
70 $this->_contactId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
72 $session = CRM_Core_Session
::singleton();
73 $userID = $session->get('userID');
75 if (!$this->_contactId
) {
76 $this->_contactId
= $userID;
78 elseif ($this->_contactId
!= $userID) {
79 if (!CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::VIEW
)) {
80 CRM_Core_Error
::fatal(ts('You do not have permission to view this contact'));
82 if (!CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::EDIT
)) {
89 * Heart of the viewing process. The runner gets all the meta data for
90 * the contact and calls the appropriate type of page to view.
96 function preProcess() {
97 if (!$this->_contactId
) {
98 CRM_Core_Error
::fatal(ts('You must be logged in to view this page.'));
101 list($displayName, $contactImage) = CRM_Contact_BAO_Contact
::getDisplayAndImage($this->_contactId
);
103 $this->set('displayName', $displayName);
104 $this->set('contactImage', $contactImage);
106 CRM_Utils_System
::setTitle(ts('Dashboard - %1', array(1 => $displayName)));
108 $this->assign('recentlyViewed', FALSE);
112 * Function to build user dashboard
117 function buildUserDashBoard() {
118 //build component selectors
119 $dashboardElements = array();
120 $config = CRM_Core_Config
::singleton();
122 $this->_userOptions
= CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
123 'user_dashboard_options'
126 $components = CRM_Core_Component
::getEnabledComponents();
127 $this->assign('contactId', $this->_contactId
);
128 foreach ($components as $name => $component) {
129 $elem = $component->getUserDashboardElement();
134 if (!empty($this->_userOptions
[$name]) &&
135 (CRM_Core_Permission
::access($component->name
) ||
136 CRM_Core_Permission
::check($elem['perm'][0])
140 $userDashboard = $component->getUserDashboardObject();
141 $dashboardElements[] = array(
142 'class' => 'crm-dashboard-' . strtolower($component->name
),
143 'sectionTitle' => $elem['title'],
144 'templatePath' => $userDashboard->getTemplateFileName(),
145 'weight' => $elem['weight'],
147 $userDashboard->run();
151 if (!empty($this->_userOptions
['Permissioned Orgs'])) {
152 $dashboardElements[] = array(
153 'class' => 'crm-dashboard-permissionedOrgs',
154 'templatePath' => 'CRM/Contact/Page/View/Relationship.tpl',
155 'sectionTitle' => ts('Your Contacts / Organizations'),
159 $links = self
::links();
160 $currentRelationships = CRM_Contact_BAO_Relationship
::getRelationship($this->_contactId
,
161 CRM_Contact_BAO_Relationship
::CURRENT
,
165 $this->assign('currentRelationships', $currentRelationships);
168 if (!empty($this->_userOptions
['PCP'])) {
169 $dashboardElements[] = array(
170 'class' => 'crm-dashboard-pcp',
171 'templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl',
172 'sectionTitle' => ts('Personal Campaign Pages'),
175 list($pcpBlock, $pcpInfo) = CRM_PCP_BAO_PCP
::getPcpDashboardInfo($this->_contactId
);
176 $this->assign('pcpBlock', $pcpBlock);
177 $this->assign('pcpInfo', $pcpInfo);
180 if (!empty($this->_userOptions
['Assigned Activities'])) {
181 // Assigned Activities section
182 $dashboardElements[] = array(
183 'class' => 'crm-dashboard-assignedActivities',
184 'templatePath' => 'CRM/Activity/Page/UserDashboard.tpl',
185 'sectionTitle' => ts('Your Assigned Activities'),
188 $userDashboard = new CRM_Activity_Page_UserDashboard
;
189 $userDashboard->run();
192 usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc'));
193 $this->assign('dashboardElements', $dashboardElements);
195 if (!empty($this->_userOptions
['Groups'])) {
196 $this->assign('showGroup', TRUE);
197 //build group selector
198 $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
202 $this->assign('showGroup', FALSE);
207 * perform actions and display for user dashboard
215 $this->buildUserDashBoard();
216 return parent
::run();
222 * @return array (reference) of action links
227 if (!(self
::$_links)) {
228 $disableExtra = ts('Are you sure you want to disable this relationship?');
230 self
::$_links = array(
231 CRM_Core_Action
::UPDATE
=> array(
232 'name' => ts('Edit Contact Information'),
233 'url' => 'civicrm/contact/relatedcontact',
234 'qs' => 'action=update&reset=1&cid=%%cbid%%&rcid=%%cid%%',
235 'title' => ts('Edit Relationship'),
237 CRM_Core_Action
::VIEW
=> array(
238 'name' => ts('Dashboard'),
239 'url' => 'civicrm/user',
240 'qs' => 'reset=1&id=%%cbid%%',
241 'title' => ts('View Relationship'),
246 if (CRM_Core_Permission
::check('access CiviCRM')) {
247 self
::$_links = array_merge(self
::$_links, array(
248 CRM_Core_Action
::DISABLE
=> array(
249 'name' => ts('Disable'),
250 'url' => 'civicrm/contact/view/rel',
251 'qs' => 'action=disable&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel&context=dashboard',
252 'extra' => 'onclick = "return confirm(\'' . $disableExtra . '\');"',
253 'title' => ts('Disable Relationship'),
259 // call the hook so we can modify it
260 CRM_Utils_Hook
::links('view.contact.userDashBoard',
262 CRM_Core_DAO
::$_nullObject,
264 CRM_Core_DAO
::$_nullObject,
265 CRM_Core_DAO
::$_nullObject
267 return self
::$_links;