3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
33 class CRM_Report_Form_Grant_Detail
extends CRM_Report_Form
{
35 protected $_customGroupExtends = array(
42 public function __construct() {
43 $this->_columns
= array(
44 'civicrm_contact' => array(
45 'dao' => 'CRM_Contact_DAO_Contact',
48 'title' => ts('Contact Name'),
57 'grouping' => 'contact-fields',
60 'title' => ts('Contact Name'),
64 'title' => ts('Gender'),
65 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
66 'options' => CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id'),
69 'title' => ts('Contact ID'),
74 'civicrm_address' => array(
75 'dao' => 'CRM_Core_DAO_Address',
77 'country_id' => array(
78 'title' => ts('Country'),
79 'type' => CRM_Utils_Type
::T_INT
,
80 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
81 'options' => CRM_Core_PseudoConstant
::country(),
83 'state_province_id' => array(
84 'title' => ts('State/Province'),
85 'type' => CRM_Utils_Type
::T_INT
,
86 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
87 'options' => CRM_Core_PseudoConstant
::stateProvince(),
91 'civicrm_grant' => array(
92 'dao' => 'CRM_Grant_DAO_Grant',
94 'grant_type_id' => array(
95 'name' => 'grant_type_id',
96 'title' => ts('Grant Type'),
99 'name' => 'status_id',
100 'title' => ts('Grant Status'),
102 'amount_total' => array(
103 'name' => 'amount_total',
104 'title' => ts('Amount Requested'),
105 'type' => CRM_Utils_Type
::T_MONEY
,
107 'amount_granted' => array(
108 'name' => 'amount_granted',
109 'title' => ts('Amount Granted'),
111 'application_received_date' => array(
112 'name' => 'application_received_date',
113 'title' => ts('Application Received'),
116 'money_transfer_date' => array(
117 'name' => 'money_transfer_date',
118 'title' => ts('Money Transfer Date'),
119 'type' => CRM_Utils_Type
::T_DATE
,
121 'grant_due_date' => array(
122 'name' => 'grant_due_date',
123 'title' => ts('Grant Report Due'),
124 'type' => CRM_Utils_Type
::T_DATE
,
126 'decision_date' => array(
127 'name' => 'decision_date',
128 'title' => ts('Grant Decision Date'),
129 'type' => CRM_Utils_Type
::T_DATE
,
131 'rationale' => array(
132 'name' => 'rationale',
133 'title' => ts('Rationale'),
135 'grant_report_received' => array(
136 'name' => 'grant_report_received',
137 'title' => ts('Grant Report Received'),
141 'grant_type' => array(
142 'name' => 'grant_type_id',
143 'title' => ts('Grant Type'),
144 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
145 'options' => CRM_Core_PseudoConstant
::get('CRM_Grant_DAO_Grant', 'grant_type_id'),
147 'status_id' => array(
148 'name' => 'status_id',
149 'title' => ts('Grant Status'),
150 'type' => CRM_Utils_Type
::T_INT
,
151 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
152 'options' => CRM_Core_PseudoConstant
::get('CRM_Grant_DAO_Grant', 'status_id'),
154 'amount_granted' => array(
155 'title' => ts('Amount Granted'),
156 'operatorType' => CRM_Report_Form
::OP_INT
,
158 'amount_total' => array(
159 'title' => ts('Amount Requested'),
160 'operatorType' => CRM_Report_Form
::OP_INT
,
162 'application_received_date' => array(
163 'title' => ts('Application Received'),
164 'operatorType' => CRM_Report_Form
::OP_DATE
,
165 'type' => CRM_Utils_Type
::T_DATE
,
167 'money_transfer_date' => array(
168 'title' => ts('Money Transfer Date'),
169 'operatorType' => CRM_Report_Form
::OP_DATE
,
170 'type' => CRM_Utils_Type
::T_DATE
,
172 'grant_due_date' => array(
173 'title' => ts('Grant Report Due'),
174 'operatorType' => CRM_Report_Form
::OP_DATE
,
175 'type' => CRM_Utils_Type
::T_DATE
,
177 'decision_date' => array(
178 'title' => ts('Grant Decision Date'),
179 'operatorType' => CRM_Report_Form
::OP_DATE
,
180 'type' => CRM_Utils_Type
::T_DATE
,
183 'group_bys' => array(
184 'grant_type_id' => array(
185 'title' => ts('Grant Type'),
187 'status_id' => array(
188 'title' => ts('Grant Status'),
190 'amount_total' => array(
191 'title' => ts('Amount Requested'),
193 'amount_granted' => array(
194 'title' => ts('Amount Granted'),
196 'application_received_date' => array(
197 'title' => ts('Application Received Date'),
199 'money_transfer_date' => array(
200 'title' => ts('Money Transfer Date'),
202 'decision_date' => array(
203 'title' => ts('Grant Decision Date'),
209 parent
::__construct();
212 public function select() {
213 // @todo remove this override - seems to do nothing parent doesn't.
216 $this->_columnHeaders
= array();
217 foreach ($this->_columns
as $tableName => $table) {
218 if (array_key_exists('fields', $table)) {
219 foreach ($table['fields'] as $fieldName => $field) {
220 if (!empty($field['required']) ||
221 !empty($this->_params
['fields'][$fieldName])
224 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
226 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
227 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
233 $this->_select
= "SELECT " . implode(', ', $select) . " ";
236 public function from() {
238 FROM civicrm_grant {$this->_aliases['civicrm_grant']}
239 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
240 ON ({$this->_aliases['civicrm_grant']}.contact_id = {$this->_aliases['civicrm_contact']}.id ) ";
241 $this->joinAddressFromContact();
244 public function where() {
245 // @todo this function appears to do nothing more than parent, test & remove
248 foreach ($this->_columns
as $tableName => $table) {
249 if (array_key_exists('filters', $table)) {
250 foreach ($table['filters'] as $fieldName => $field) {
253 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
254 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
255 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
256 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
258 if ($relative ||
$from ||
$to) {
259 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
263 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
265 $clause = $this->whereClause($field,
267 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
268 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
269 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
273 if (!empty($clause)) {
274 $clauses[] = $clause;
279 if (!empty($clauses)) {
280 $this->_where
= "WHERE " . implode(' AND ', $clauses);
284 public function groupBy() {
285 // @todo this function appears to do nothing more than parent, test & remove
286 $this->_groupBy
= "";
287 if (!empty($this->_params
['group_bys']) &&
288 is_array($this->_params
['group_bys']) &&
289 !empty($this->_params
['group_bys'])
291 foreach ($this->_columns
as $tableName => $table) {
292 if (array_key_exists('group_bys', $table)) {
293 foreach ($table['group_bys'] as $fieldName => $field) {
294 if (!empty($this->_params
['group_bys'][$fieldName])) {
295 $this->_groupBy
[] = $field['dbAlias'];
301 if (!empty($this->_groupBy
)) {
302 $this->_groupBy
= "ORDER BY " . implode(', ', $this->_groupBy
) .
303 ", {$this->_aliases['civicrm_contact']}.sort_name";
306 $this->_groupBy
= "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name";
311 * Alter display of rows.
313 * Iterate through the rows retrieved via SQL and make changes for display purposes,
314 * such as rendering contacts as links.
317 * Rows generated by SQL, with an array for each row.
319 public function alterDisplay(&$rows) {
321 foreach ($rows as $rowNum => $row) {
322 // convert display name to links
323 if (array_key_exists('civicrm_contact_sort_name', $row) &&
324 array_key_exists('civicrm_contact_id', $row)
326 $url = CRM_Utils_System
::url('civicrm/contact/view',
327 'reset=1&cid=' . $row['civicrm_contact_id'],
330 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
331 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View contact details for this record.");
335 if (array_key_exists('civicrm_grant_grant_type_id', $row)) {
336 if ($value = $row['civicrm_grant_grant_type_id']) {
337 $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Core_PseudoConstant
::getLabel('CRM_Grant_DAO_Grant', 'grant_type_id', $value);
341 if (array_key_exists('civicrm_grant_status_id', $row)) {
342 if ($value = $row['civicrm_grant_status_id']) {
343 $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Core_PseudoConstant
::getLabel('CRM_Grant_DAO_Grant', 'status_id', $value);
347 if (array_key_exists('civicrm_grant_grant_report_received', $row)) {
348 if ($value = $row['civicrm_grant_grant_report_received']) {
355 $rows[$rowNum]['civicrm_grant_grant_report_received'] = $value;