Merge pull request #21902 from eileenmcnaughton/tok
[civicrm-core.git] / CRM / Pledge / 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 the Pledge Dashboard.
20 */
21 class CRM_Pledge_Page_DashBoard extends CRM_Core_Page {
22
23 /**
24 * Heart of the viewing process.
25 *
26 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
27 */
28 public function preProcess() {
29 CRM_Utils_System::setTitle(ts('CiviPledge'));
30
31 $startToDate = [];
32 $yearToDate = [];
33 $monthToDate = [];
34 $previousToDate = [];
35
36 $prefixes = ['start', 'month', 'year', 'previous'];
37 $status = ['Completed', 'Cancelled', 'Pending', 'In Progress', 'Overdue'];
38
39 // cumulative (since inception) - prefix = 'start'
40 $startDate = NULL;
41 $startDateEnd = NULL;
42
43 // current year - prefix = 'year'
44 $yearDate = \Civi::settings()->get('fiscalYearStart');
45 $year = ['Y' => date('Y')];
46 $this->assign('curYear', $year['Y']);
47 $yearDate = array_merge($year, $yearDate);
48 $yearDate = CRM_Utils_Date::format($yearDate);
49 $yearDate = $yearDate . '000000';
50 $yearDateEnd = $year['Y'] . '1231235959';
51
52 // current month - prefix = 'month'
53 $currentMonth = date("F Y", mktime(0, 0, 0, date("m"), 01, date("Y")));
54 $this->assign('currentMonthYear', $currentMonth);
55 $monthDate = date('Ym') . '01000000';
56 $monthDateEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m"), 01, date("Y"))), '%Y%m%d') . '235959';
57
58 // previous month - prefix = 'previous'
59 $previousDate = CRM_Utils_Date::customFormat(date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d') . '000000';
60 $previousDateEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d') . '235959';
61 $previousMonth = date("F Y", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
62 $this->assign('previousMonthYear', $previousMonth);
63
64 foreach ($prefixes as $prefix) {
65 $aName = $prefix . 'ToDate';
66 $startName = $prefix . 'Date';
67 $endName = $prefix . 'DateEnd';
68 foreach ($status as $s) {
69 ${$aName}[str_replace(" ", "", $s)] = CRM_Pledge_BAO_Pledge::getTotalAmountAndCount($s, $$startName, $$endName);
70 }
71 $this->assign($aName, $$aName);
72 }
73 }
74
75 /**
76 * The main function that is called when the page loads.
77 *
78 * it decides which action has to be taken for the page.
79 *
80 * @return null
81 */
82 public function run() {
83 $this->preProcess();
84
85 $controller = new CRM_Core_Controller_Simple('CRM_Pledge_Form_Search',
86 ts('Pledge'),
87 NULL
88 );
89 $controller->setEmbedded(TRUE);
90 $controller->reset();
91 $controller->set('limit', 10);
92 $controller->set('force', 1);
93 $controller->set('context', 'dashboard');
94 $controller->process();
95 $controller->run();
96
97 return parent::run();
98 }
99
100 }