Merge pull request #13972 from eileenmcnaughton/array_format_5
[civicrm-core.git] / CRM / Report / Form / Grant / Detail.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 class CRM_Report_Form_Grant_Detail extends CRM_Report_Form {
34
35 protected $_customGroupExtends = [
36 'Contact',
37 'Individual',
38 'Household',
39 'Organization',
40 'Grant',
41 ];
42
43 /**
44 * Class constructor.
45 */
46 public function __construct() {
47 $contactCols = $this->getColumns('Contact', [
48 'order_bys_defaults' => ['sort_name' => 'ASC '],
49 'fields_defaults' => ['sort_name'],
50 'fields_excluded' => ['id'],
51 'fields_required' => ['id'],
52 'filters_defaults' => ['is_deleted' => 0],
53 'no_field_disambiguation' => TRUE,
54 ]);
55 $specificCols = [
56 'civicrm_email' => [
57 'dao' => 'CRM_Core_DAO_Email',
58 'fields' => [
59 'email' => [
60 'title' => ts('Email'),
61 ],
62 ],
63 'grouping' => 'contact-fields',
64 ],
65 'civicrm_phone' => [
66 'dao' => 'CRM_Core_DAO_Phone',
67 'fields' => [
68 'phone' => [
69 'title' => ts('Phone'),
70 ],
71 ],
72 'grouping' => 'contact-fields',
73 ],
74 'civicrm_grant' => [
75 'dao' => 'CRM_Grant_DAO_Grant',
76 'fields' => [
77 'grant_type_id' => [
78 'name' => 'grant_type_id',
79 'title' => ts('Grant Type'),
80 ],
81 'status_id' => [
82 'name' => 'status_id',
83 'title' => ts('Grant Status'),
84 ],
85 'amount_total' => [
86 'name' => 'amount_total',
87 'title' => ts('Amount Requested'),
88 'type' => CRM_Utils_Type::T_MONEY,
89 ],
90 'amount_granted' => [
91 'name' => 'amount_granted',
92 'title' => ts('Amount Granted'),
93 ],
94 'application_received_date' => [
95 'name' => 'application_received_date',
96 'title' => ts('Application Received'),
97 'default' => TRUE,
98 'type' => CRM_Utils_Type::T_DATE,
99 ],
100 'money_transfer_date' => [
101 'name' => 'money_transfer_date',
102 'title' => ts('Money Transfer Date'),
103 'type' => CRM_Utils_Type::T_DATE,
104 ],
105 'grant_due_date' => [
106 'name' => 'grant_due_date',
107 'title' => ts('Grant Report Due'),
108 'type' => CRM_Utils_Type::T_DATE,
109 ],
110 'decision_date' => [
111 'name' => 'decision_date',
112 'title' => ts('Grant Decision Date'),
113 'type' => CRM_Utils_Type::T_DATE,
114 ],
115 'rationale' => [
116 'name' => 'rationale',
117 'title' => ts('Rationale'),
118 ],
119 'grant_report_received' => [
120 'name' => 'grant_report_received',
121 'title' => ts('Grant Report Received'),
122 ],
123 ],
124 'filters' => [
125 'grant_type' => [
126 'name' => 'grant_type_id',
127 'title' => ts('Grant Type'),
128 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
129 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id'),
130 ],
131 'status_id' => [
132 'name' => 'status_id',
133 'title' => ts('Grant Status'),
134 'type' => CRM_Utils_Type::T_INT,
135 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
136 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'),
137 ],
138 'amount_granted' => [
139 'title' => ts('Amount Granted'),
140 'operatorType' => CRM_Report_Form::OP_INT,
141 ],
142 'amount_total' => [
143 'title' => ts('Amount Requested'),
144 'operatorType' => CRM_Report_Form::OP_INT,
145 ],
146 'application_received_date' => [
147 'title' => ts('Application Received'),
148 'operatorType' => CRM_Report_Form::OP_DATE,
149 'type' => CRM_Utils_Type::T_DATE,
150 ],
151 'money_transfer_date' => [
152 'title' => ts('Money Transfer Date'),
153 'operatorType' => CRM_Report_Form::OP_DATE,
154 'type' => CRM_Utils_Type::T_DATE,
155 ],
156 'grant_due_date' => [
157 'title' => ts('Grant Report Due'),
158 'operatorType' => CRM_Report_Form::OP_DATE,
159 'type' => CRM_Utils_Type::T_DATE,
160 ],
161 'decision_date' => [
162 'title' => ts('Grant Decision Date'),
163 'operatorType' => CRM_Report_Form::OP_DATE,
164 'type' => CRM_Utils_Type::T_DATE,
165 ],
166 ],
167 'group_bys' => [
168 'grant_type_id' => [
169 'title' => ts('Grant Type'),
170 ],
171 'status_id' => [
172 'title' => ts('Grant Status'),
173 ],
174 'application_received_date' => [
175 'title' => ts('Application Received Date'),
176 ],
177 'money_transfer_date' => [
178 'title' => ts('Money Transfer Date'),
179 ],
180 'decision_date' => [
181 'title' => ts('Grant Decision Date'),
182 ],
183 ],
184 'order_bys' => [
185 'grant_type_id' => [
186 'title' => ts('Grant Type'),
187 ],
188 'status_id' => [
189 'title' => ts('Grant Status'),
190 ],
191 'amount_total' => [
192 'title' => ts('Amount Requested'),
193 ],
194 'amount_granted' => [
195 'title' => ts('Amount Granted'),
196 ],
197 'application_received_date' => [
198 'title' => ts('Application Received Date'),
199 ],
200 'money_transfer_date' => [
201 'title' => ts('Money Transfer Date'),
202 ],
203 'decision_date' => [
204 'title' => ts('Grant Decision Date'),
205 ],
206 ],
207 ],
208 ];
209
210 $this->_columns = array_merge($contactCols, $specificCols, $this->addAddressFields(FALSE));
211
212 parent::__construct();
213 }
214
215 public function from() {
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
220 HERESQL;
221
222 $this->joinEmailFromContact();
223 $this->joinPhoneFromContact();
224 $this->joinAddressFromContact();
225 }
226
227 /**
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.
235 */
236 public function alterDisplay(&$rows) {
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',
244 'reset=1&cid=' . $row['civicrm_contact_id'],
245 $this->_absoluteUrl
246 );
247 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
248 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");
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']) {
254 $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Grant_DAO_Grant', 'grant_type_id', $value);
255 }
256 $entryFound = TRUE;
257 }
258 if (array_key_exists('civicrm_grant_status_id', $row)) {
259 if ($value = $row['civicrm_grant_status_id']) {
260 $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Grant_DAO_Grant', 'status_id', $value);
261 }
262 $entryFound = TRUE;
263 }
264 if (!$entryFound) {
265 break;
266 }
267 }
268 }
269
270 }