3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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;
63 function __construct() {
64 parent
::__construct();
66 $check = CRM_Core_Permission
::check('access Contact Dashboard');
69 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/dashboard', 'reset=1'));
72 $this->_contactId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
74 $session = CRM_Core_Session
::singleton();
75 $userID = $session->get('userID');
77 if (!$this->_contactId
) {
78 $this->_contactId
= $userID;
80 elseif ($this->_contactId
!= $userID) {
81 if (!CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::VIEW
)) {
82 CRM_Core_Error
::fatal(ts('You do not have permission to access this contact.'));
84 if (!CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::EDIT
)) {
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.
97 function preProcess() {
98 if (!$this->_contactId
) {
99 CRM_Core_Error
::fatal(ts('You must be logged in to view this page.'));
102 list($displayName, $contactImage) = CRM_Contact_BAO_Contact
::getDisplayAndImage($this->_contactId
);
104 $this->set('displayName', $displayName);
105 $this->set('contactImage', $contactImage);
107 CRM_Utils_System
::setTitle(ts('Dashboard - %1', array(1 => $displayName)));
109 $this->assign('recentlyViewed', FALSE);
113 * build user dashboard
118 function buildUserDashBoard() {
119 //build component selectors
120 $dashboardElements = array();
121 $config = CRM_Core_Config
::singleton();
123 $this->_userOptions
= CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
124 'user_dashboard_options'
127 $components = CRM_Core_Component
::getEnabledComponents();
128 $this->assign('contactId', $this->_contactId
);
129 foreach ($components as $name => $component) {
130 $elem = $component->getUserDashboardElement();
135 if (!empty($this->_userOptions
[$name]) &&
136 (CRM_Core_Permission
::access($component->name
) ||
137 CRM_Core_Permission
::check($elem['perm'][0])
141 $userDashboard = $component->getUserDashboardObject();
142 $dashboardElements[] = array(
143 'class' => 'crm-dashboard-' . strtolower($component->name
),
144 'sectionTitle' => $elem['title'],
145 'templatePath' => $userDashboard->getTemplateFileName(),
146 'weight' => $elem['weight'],
148 $userDashboard->run();
152 if (!empty($this->_userOptions
['Permissioned Orgs'])) {
153 $dashboardElements[] = array(
154 'class' => 'crm-dashboard-permissionedOrgs',
155 'templatePath' => 'CRM/Contact/Page/View/RelationshipSelector.tpl',
156 'sectionTitle' => ts('Your Contacts / Organizations'),
162 if (!empty($this->_userOptions
['PCP'])) {
163 $dashboardElements[] = array(
164 'class' => 'crm-dashboard-pcp',
165 'templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl',
166 'sectionTitle' => ts('Personal Campaign Pages'),
169 list($pcpBlock, $pcpInfo) = CRM_PCP_BAO_PCP
::getPcpDashboardInfo($this->_contactId
);
170 $this->assign('pcpBlock', $pcpBlock);
171 $this->assign('pcpInfo', $pcpInfo);
174 if (!empty($this->_userOptions
['Assigned Activities'])) {
175 // Assigned Activities section
176 $dashboardElements[] = array(
177 'class' => 'crm-dashboard-assignedActivities',
178 'templatePath' => 'CRM/Activity/Page/UserDashboard.tpl',
179 'sectionTitle' => ts('Your Assigned Activities'),
182 $userDashboard = new CRM_Activity_Page_UserDashboard
;
183 $userDashboard->run();
186 usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc'));
187 $this->assign('dashboardElements', $dashboardElements);
189 // return true when 'Invoices / Credit Notes' checkbox is checked
190 $this->assign('invoices', $this->_userOptions
['Invoices / Credit Notes']);
192 if (!empty($this->_userOptions
['Groups'])) {
193 $this->assign('showGroup', TRUE);
194 //build group selector
195 $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
199 $this->assign('showGroup', FALSE);
204 * perform actions and display for user dashboard
212 $this->buildUserDashBoard();
213 return parent
::run();
219 * @return array (reference) of action links
224 if (!(self
::$_links)) {
225 $disableExtra = ts('Are you sure you want to disable this relationship?');
227 self
::$_links = array(
228 CRM_Core_Action
::UPDATE
=> array(
229 'name' => ts('Edit Contact Information'),
230 'url' => 'civicrm/contact/relatedcontact',
231 'qs' => 'action=update&reset=1&cid=%%cbid%%&rcid=%%cid%%',
232 'title' => ts('Edit Relationship'),
234 CRM_Core_Action
::VIEW
=> array(
235 'name' => ts('Dashboard'),
236 'url' => 'civicrm/user',
237 'qs' => 'reset=1&id=%%cbid%%',
238 'title' => ts('View Relationship'),
243 if (CRM_Core_Permission
::check('access CiviCRM')) {
244 self
::$_links = array_merge(self
::$_links, array(
245 CRM_Core_Action
::DISABLE
=> array(
246 'name' => ts('Disable'),
247 'url' => 'civicrm/contact/view/rel',
248 'qs' => 'action=disable&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel&context=dashboard',
249 'extra' => 'onclick = "return confirm(\'' . $disableExtra . '\');"',
250 'title' => ts('Disable Relationship'),
256 // call the hook so we can modify it
257 CRM_Utils_Hook
::links('view.contact.userDashBoard',
259 CRM_Core_DAO
::$_nullObject,
261 CRM_Core_DAO
::$_nullObject,
262 CRM_Core_DAO
::$_nullObject
264 return self
::$_links;