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