Merge pull request #13905 from civicrm/5.12
[civicrm-core.git] / CRM / Report / Form / Grant / Detail.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 */
33class CRM_Report_Form_Grant_Detail extends CRM_Report_Form {
34
6a488035 35 protected $_customGroupExtends = array(
343f3bea
AH
36 'Contact',
37 'Individual',
38 'Household',
39 'Organization',
21dfd5f5 40 'Grant',
9d72cede 41 );
6a488035 42
74cf4551 43 /**
73b448bf 44 * Class constructor.
74cf4551 45 */
00be9182 46 public function __construct() {
6305d9b1
AH
47 $contactCols = $this->getColumns('Contact', array(
48 'order_bys_defaults' => array('sort_name' => 'ASC '),
49 'fields_defaults' => ['sort_name'],
2422c481
AH
50 'fields_excluded' => ['id'],
51 'fields_required' => ['id'],
6305d9b1
AH
52 'filters_defaults' => array('is_deleted' => 0),
53 'no_field_disambiguation' => TRUE,
54 ));
55 $specificCols = array(
343f3bea
AH
56 'civicrm_email' => array(
57 'dao' => 'CRM_Core_DAO_Email',
58 'fields' => array(
59 'email' => array(
60 'title' => ts('Email'),
61 ),
62 ),
63 'grouping' => 'contact-fields',
64 ),
65 'civicrm_phone' => array(
66 'dao' => 'CRM_Core_DAO_Phone',
67 'fields' => array(
68 'phone' => array(
69 'title' => ts('Phone'),
70 ),
71 ),
72 'grouping' => 'contact-fields',
73 ),
9d72cede 74 'civicrm_grant' => array(
6a488035 75 'dao' => 'CRM_Grant_DAO_Grant',
9d72cede
EM
76 'fields' => array(
77 'grant_type_id' => array(
6a488035
TO
78 'name' => 'grant_type_id',
79 'title' => ts('Grant Type'),
80 ),
9d72cede 81 'status_id' => array(
6a488035
TO
82 'name' => 'status_id',
83 'title' => ts('Grant Status'),
84 ),
9d72cede 85 'amount_total' => array(
6a488035
TO
86 'name' => 'amount_total',
87 'title' => ts('Amount Requested'),
88 'type' => CRM_Utils_Type::T_MONEY,
89 ),
9d72cede 90 'amount_granted' => array(
6a488035
TO
91 'name' => 'amount_granted',
92 'title' => ts('Amount Granted'),
93 ),
9d72cede 94 'application_received_date' => array(
6a488035
TO
95 'name' => 'application_received_date',
96 'title' => ts('Application Received'),
97 'default' => TRUE,
6305d9b1 98 'type' => CRM_Utils_Type::T_DATE,
6a488035 99 ),
9d72cede 100 'money_transfer_date' => array(
6a488035
TO
101 'name' => 'money_transfer_date',
102 'title' => ts('Money Transfer Date'),
103 'type' => CRM_Utils_Type::T_DATE,
104 ),
9d72cede 105 'grant_due_date' => array(
6a488035
TO
106 'name' => 'grant_due_date',
107 'title' => ts('Grant Report Due'),
108 'type' => CRM_Utils_Type::T_DATE,
109 ),
9d72cede 110 'decision_date' => array(
6a488035
TO
111 'name' => 'decision_date',
112 'title' => ts('Grant Decision Date'),
113 'type' => CRM_Utils_Type::T_DATE,
114 ),
9d72cede 115 'rationale' => array(
6a488035
TO
116 'name' => 'rationale',
117 'title' => ts('Rationale'),
118 ),
9d72cede 119 'grant_report_received' => array(
6a488035
TO
120 'name' => 'grant_report_received',
121 'title' => ts('Grant Report Received'),
122 ),
123 ),
9d72cede
EM
124 'filters' => array(
125 'grant_type' => array(
6a488035
TO
126 'name' => 'grant_type_id',
127 'title' => ts('Grant Type'),
128 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
fb1fd730 129 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id'),
6a488035 130 ),
9d72cede 131 'status_id' => array(
6a488035
TO
132 'name' => 'status_id',
133 'title' => ts('Grant Status'),
09b5cdcf 134 'type' => CRM_Utils_Type::T_INT,
6a488035 135 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
fb1fd730 136 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'),
6a488035 137 ),
9d72cede 138 'amount_granted' => array(
6a488035
TO
139 'title' => ts('Amount Granted'),
140 'operatorType' => CRM_Report_Form::OP_INT,
141 ),
9d72cede 142 'amount_total' => array(
6a488035
TO
143 'title' => ts('Amount Requested'),
144 'operatorType' => CRM_Report_Form::OP_INT,
145 ),
9d72cede 146 'application_received_date' => array(
6a488035
TO
147 'title' => ts('Application Received'),
148 'operatorType' => CRM_Report_Form::OP_DATE,
0e214fe2 149 'type' => CRM_Utils_Type::T_DATE,
6a488035 150 ),
9d72cede 151 'money_transfer_date' => array(
6a488035
TO
152 'title' => ts('Money Transfer Date'),
153 'operatorType' => CRM_Report_Form::OP_DATE,
0e214fe2 154 'type' => CRM_Utils_Type::T_DATE,
6a488035 155 ),
9d72cede 156 'grant_due_date' => array(
6a488035
TO
157 'title' => ts('Grant Report Due'),
158 'operatorType' => CRM_Report_Form::OP_DATE,
0e214fe2 159 'type' => CRM_Utils_Type::T_DATE,
6a488035 160 ),
9d72cede 161 'decision_date' => array(
6a488035
TO
162 'title' => ts('Grant Decision Date'),
163 'operatorType' => CRM_Report_Form::OP_DATE,
164 'type' => CRM_Utils_Type::T_DATE,
165 ),
166 ),
9d72cede 167 'group_bys' => array(
6305d9b1
AH
168 'grant_type_id' => array(
169 'title' => ts('Grant Type'),
170 ),
171 'status_id' => array(
172 'title' => ts('Grant Status'),
173 ),
174 'application_received_date' => array(
175 'title' => ts('Application Received Date'),
176 ),
177 'money_transfer_date' => array(
178 'title' => ts('Money Transfer Date'),
179 ),
180 'decision_date' => array(
181 'title' => ts('Grant Decision Date'),
182 ),
183 ),
184 'order_bys' => array(
9d72cede 185 'grant_type_id' => array(
6a488035
TO
186 'title' => ts('Grant Type'),
187 ),
9d72cede 188 'status_id' => array(
6a488035
TO
189 'title' => ts('Grant Status'),
190 ),
9d72cede 191 'amount_total' => array(
6a488035
TO
192 'title' => ts('Amount Requested'),
193 ),
9d72cede 194 'amount_granted' => array(
6a488035
TO
195 'title' => ts('Amount Granted'),
196 ),
9d72cede 197 'application_received_date' => array(
6a488035
TO
198 'title' => ts('Application Received Date'),
199 ),
9d72cede 200 'money_transfer_date' => array(
6a488035
TO
201 'title' => ts('Money Transfer Date'),
202 ),
9d72cede 203 'decision_date' => array(
6a488035
TO
204 'title' => ts('Grant Decision Date'),
205 ),
206 ),
207 ),
208 );
209
6305d9b1
AH
210 $this->_columns = array_merge($contactCols, $specificCols, $this->addAddressFields(FALSE));
211
6a488035
TO
212 parent::__construct();
213 }
214
00be9182 215 public function from() {
343f3bea
AH
216 $this->setFromBase('civicrm_contact');
217 $this->_from .= <<<HERESQL
218 INNER JOIN civicrm_grant {$this->_aliases['civicrm_grant']}
219 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_grant']}.contact_id
220HERESQL;
221
222 $this->joinEmailFromContact();
223 $this->joinPhoneFromContact();
6d81d64a 224 $this->joinAddressFromContact();
6a488035
TO
225 }
226
74cf4551 227 /**
ced9bfed
EM
228 * Alter display of rows.
229 *
230 * Iterate through the rows retrieved via SQL and make changes for display purposes,
231 * such as rendering contacts as links.
232 *
233 * @param array $rows
234 * Rows generated by SQL, with an array for each row.
74cf4551 235 */
00be9182 236 public function alterDisplay(&$rows) {
6a488035
TO
237 $entryFound = FALSE;
238 foreach ($rows as $rowNum => $row) {
239 // convert display name to links
240 if (array_key_exists('civicrm_contact_sort_name', $row) &&
241 array_key_exists('civicrm_contact_id', $row)
242 ) {
243 $url = CRM_Utils_System::url('civicrm/contact/view',
b2708486 244 'reset=1&cid=' . $row['civicrm_contact_id'],
6a488035
TO
245 $this->_absoluteUrl
246 );
247 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
2422c481 248 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");
6a488035
TO
249 $entryFound = TRUE;
250 }
251
252 if (array_key_exists('civicrm_grant_grant_type_id', $row)) {
253 if ($value = $row['civicrm_grant_grant_type_id']) {
a8c23526 254 $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Grant_DAO_Grant', 'grant_type_id', $value);
6a488035
TO
255 }
256 $entryFound = TRUE;
257 }
6a488035
TO
258 if (array_key_exists('civicrm_grant_status_id', $row)) {
259 if ($value = $row['civicrm_grant_status_id']) {
a8c23526 260 $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Grant_DAO_Grant', 'status_id', $value);
6a488035
TO
261 }
262 $entryFound = TRUE;
263 }
6a488035
TO
264 if (!$entryFound) {
265 break;
266 }
267 }
268 }
96025800 269
6a488035 270}