Merge pull request #17008 from ivan-compucorp/CPS-70-fix-radio-value
[civicrm-core.git] / CRM / Case / Page / DashBoard.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This page is for Case Dashboard.
20 */
21 class CRM_Case_Page_DashBoard extends CRM_Core_Page {
22
23 public $useLivePageJS = TRUE;
24
25 /**
26 * Heart of the viewing process.
27 *
28 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
29 */
30 public function preProcess() {
31 //check for civicase access.
32 if (!CRM_Case_BAO_Case::accessCiviCase()) {
33 CRM_Core_Error::statusBounce(ts('You are not authorized to access this page.'));
34 }
35
36 //validate case configuration.
37 $configured = CRM_Case_BAO_Case::isCaseConfigured();
38 $this->assign('notConfigured', !$configured['configured']);
39 $this->assign('allowToAddNewCase', $configured['allowToAddNewCase']);
40 if (!$configured['configured']) {
41 return;
42 }
43
44 $session = CRM_Core_Session::singleton();
45 $allCases = CRM_Utils_Request::retrieve('all', 'Positive', $this);
46
47 CRM_Utils_System::setTitle(ts('CiviCase Dashboard'));
48
49 $userID = $session->get('userID');
50
51 //validate access for all cases.
52 if ($allCases && !CRM_Core_Permission::check('access all cases and activities')) {
53 $allCases = 0;
54 CRM_Core_Session::setStatus(ts('You are not authorized to access all cases and activities.'), ts('Sorry'), 'error');
55 }
56 $this->assign('all', $allCases);
57 if (!$allCases) {
58 $this->assign('myCases', TRUE);
59 }
60 else {
61 $this->assign('myCases', FALSE);
62 }
63
64 $this->assign('newClient', FALSE);
65 if (CRM_Core_Permission::check('add contacts') &&
66 CRM_Core_Permission::check('access all cases and activities')
67 ) {
68 $this->assign('newClient', TRUE);
69 }
70 $summary = CRM_Case_BAO_Case::getCasesSummary($allCases);
71 $upcoming = CRM_Case_BAO_Case::getCases($allCases, [], 'dashboard', TRUE);
72 $recent = CRM_Case_BAO_Case::getCases($allCases, ['type' => 'recent'], 'dashboard', TRUE);
73
74 $this->assign('casesSummary', $summary);
75 if (!empty($upcoming)) {
76 $this->assign('upcomingCases', TRUE);
77 }
78 if (!empty($recent)) {
79 $this->assign('recentCases', TRUE);
80 }
81
82 $controller = new CRM_Core_Controller_Simple('CRM_Case_Form_Search',
83 ts('Case'), CRM_Core_Action::BROWSE,
84 NULL,
85 FALSE, FALSE, TRUE
86 );
87 $controller->set('context', 'dashboard');
88 $controller->setEmbedded(TRUE);
89 $controller->process();
90 $controller->run();
91 }
92
93 /**
94 * the main function that is called when the page loads,
95 * it decides the which action has to be taken for the page.
96 *
97 * @return null
98 */
99 public function run() {
100 $this->preProcess();
101
102 return parent::run();
103 }
104
105 }