Merge pull request #20308 from masetto/master
[civicrm-core.git] / CRM / Case / Page / DashBoard.php
CommitLineData
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/**
67d19299 19 * This page is for Case Dashboard.
6a488035
TO
20 */
21class CRM_Case_Page_DashBoard extends CRM_Core_Page {
22
a4400196
CW
23 public $useLivePageJS = TRUE;
24
6a488035 25 /**
67d19299 26 * Heart of the viewing process.
6a488035 27 *
67d19299 28 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
6a488035 29 */
00be9182 30 public function preProcess() {
6a488035
TO
31 //check for civicase access.
32 if (!CRM_Case_BAO_Case::accessCiviCase()) {
beb414cc 33 CRM_Core_Error::statusBounce(ts('You are not authorized to access this page.'));
6a488035
TO
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();
5f1c8c57 45 $allCases = CRM_Utils_Request::retrieve('all', 'Positive', $this);
6a488035
TO
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')) {
5f1c8c57 53 $allCases = 0;
6a488035
TO
54 CRM_Core_Session::setStatus(ts('You are not authorized to access all cases and activities.'), ts('Sorry'), 'error');
55 }
5f1c8c57 56 $this->assign('all', $allCases);
6a488035
TO
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 }
5f1c8c57 70 $summary = CRM_Case_BAO_Case::getCasesSummary($allCases);
be2fb01f
CW
71 $upcoming = CRM_Case_BAO_Case::getCases($allCases, [], 'dashboard', TRUE);
72 $recent = CRM_Case_BAO_Case::getCases($allCases, ['type' => 'recent'], 'dashboard', TRUE);
6a488035
TO
73
74 $this->assign('casesSummary', $summary);
4a54ff16 75 $this->assign('upcomingCases', !empty($upcoming));
76 $this->assign('recentCases', !empty($recent));
5f1c8c57 77
78 $controller = new CRM_Core_Controller_Simple('CRM_Case_Form_Search',
79 ts('Case'), CRM_Core_Action::BROWSE,
80 NULL,
81 FALSE, FALSE, TRUE
82 );
83 $controller->set('context', 'dashboard');
84 $controller->setEmbedded(TRUE);
85 $controller->process();
86 $controller->run();
6a488035
TO
87 }
88
89 /**
dc195289 90 * the main function that is called when the page loads,
6a488035
TO
91 * it decides the which action has to be taken for the page.
92 *
76e7a76c 93 * @return null
6a488035 94 */
00be9182 95 public function run() {
6a488035
TO
96 $this->preProcess();
97
98 return parent::run();
99 }
96025800 100
6a488035 101}