3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 public 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.
96 public 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 * Build user dashboard
116 public function buildUserDashBoard() {
117 //build component selectors
118 $dashboardElements = array();
119 $config = CRM_Core_Config
::singleton();
121 $this->_userOptions
= CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
122 'user_dashboard_options'
125 $components = CRM_Core_Component
::getEnabledComponents();
126 $this->assign('contactId', $this->_contactId
);
127 foreach ($components as $name => $component) {
128 $elem = $component->getUserDashboardElement();
133 if (!empty($this->_userOptions
[$name]) &&
134 (CRM_Core_Permission
::access($component->name
) ||
135 CRM_Core_Permission
::check($elem['perm'][0])
139 $userDashboard = $component->getUserDashboardObject();
140 $dashboardElements[] = array(
141 'class' => 'crm-dashboard-' . strtolower($component->name
),
142 'sectionTitle' => $elem['title'],
143 'templatePath' => $userDashboard->getTemplateFileName(),
144 'weight' => $elem['weight'],
146 $userDashboard->run();
150 if (!empty($this->_userOptions
['Permissioned Orgs'])) {
151 $dashboardElements[] = array(
152 'class' => 'crm-dashboard-permissionedOrgs',
153 'templatePath' => 'CRM/Contact/Page/View/RelationshipSelector.tpl',
154 'sectionTitle' => ts('Your Contacts / Organizations'),
160 if (!empty($this->_userOptions
['PCP'])) {
161 $dashboardElements[] = array(
162 'class' => 'crm-dashboard-pcp',
163 'templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl',
164 'sectionTitle' => ts('Personal Campaign Pages'),
167 list($pcpBlock, $pcpInfo) = CRM_PCP_BAO_PCP
::getPcpDashboardInfo($this->_contactId
);
168 $this->assign('pcpBlock', $pcpBlock);
169 $this->assign('pcpInfo', $pcpInfo);
172 if (!empty($this->_userOptions
['Assigned Activities'])) {
173 // Assigned Activities section
174 $dashboardElements[] = array(
175 'class' => 'crm-dashboard-assignedActivities',
176 'templatePath' => 'CRM/Activity/Page/UserDashboard.tpl',
177 'sectionTitle' => ts('Your Assigned Activities'),
180 $userDashboard = new CRM_Activity_Page_UserDashboard
;
181 $userDashboard->run();
184 usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc'));
185 $this->assign('dashboardElements', $dashboardElements);
187 // return true when 'Invoices / Credit Notes' checkbox is checked
188 $this->assign('invoices', $this->_userOptions
['Invoices / Credit Notes']);
190 if (!empty($this->_userOptions
['Groups'])) {
191 $this->assign('showGroup', TRUE);
192 //build group selector
193 $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
197 $this->assign('showGroup', FALSE);
202 * Perform actions and display for user dashboard
206 public function run() {
208 $this->buildUserDashBoard();
209 return parent
::run();
216 * (reference) of action links
220 public function &links() {
221 if (!(self
::$_links)) {
222 $disableExtra = ts('Are you sure you want to disable this relationship?');
224 self
::$_links = array(
225 CRM_Core_Action
::UPDATE
=> array(
226 'name' => ts('Edit Contact Information'),
227 'url' => 'civicrm/contact/relatedcontact',
228 'qs' => 'action=update&reset=1&cid=%%cbid%%&rcid=%%cid%%',
229 'title' => ts('Edit Relationship'),
231 CRM_Core_Action
::VIEW
=> array(
232 'name' => ts('Dashboard'),
233 'url' => 'civicrm/user',
234 'class' => 'no-popup',
235 'qs' => 'reset=1&id=%%cbid%%',
236 'title' => ts('View Relationship'),
240 if (CRM_Core_Permission
::check('access CiviCRM')) {
241 self
::$_links = array_merge(self
::$_links, array(
242 CRM_Core_Action
::DISABLE
=> array(
243 'name' => ts('Disable'),
244 'url' => 'civicrm/contact/view/rel',
245 'qs' => 'action=disable&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel&context=dashboard',
246 'extra' => 'onclick = "return confirm(\'' . $disableExtra . '\');"',
247 'title' => ts('Disable Relationship'),
253 // call the hook so we can modify it
254 CRM_Utils_Hook
::links('view.contact.userDashBoard',
256 CRM_Core_DAO
::$_nullObject,
258 CRM_Core_DAO
::$_nullObject,
259 CRM_Core_DAO
::$_nullObject
261 return self
::$_links;