5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
33 * @copyright CiviCRM LLC (c) 2004-2013
37 class CRM_Report_Form_Grant_Detail
extends CRM_Report_Form
{
39 protected $_addressField = FALSE;
41 protected $_customGroupExtends = array(
44 function __construct() {
45 $this->_columns
= array(
48 'dao' => 'CRM_Contact_DAO_Contact',
52 array('title' => ts('Contact Name'),
62 'grouping' => 'contact-fields',
66 array('title' => ts('Contact Name'),
70 array('title' => ts('Gender'),
71 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
72 'options' => CRM_Core_PseudoConstant
::gender(),
75 array('title' => ts('Contact ID'),
82 'dao' => 'CRM_Core_DAO_Address',
86 array('title' => ts('Country'),
87 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
88 'options' => CRM_Core_PseudoConstant
::country(),
90 'state_province_id' =>
91 array('title' => ts('State/Province'),
92 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
93 'options' => CRM_Core_PseudoConstant
::stateProvince(),
99 'dao' => 'CRM_Grant_DAO_Grant',
104 'name' => 'grant_type_id',
105 'title' => ts('Grant Type'),
109 'name' => 'status_id',
110 'title' => ts('Grant Status'),
114 'name' => 'amount_total',
115 'title' => ts('Amount Requested'),
116 'type' => CRM_Utils_Type
::T_MONEY
,
120 'name' => 'amount_granted',
121 'title' => ts('Amount Granted'),
123 'application_received_date' =>
125 'name' => 'application_received_date',
126 'title' => ts('Application Received'),
129 'money_transfer_date' =>
131 'name' => 'money_transfer_date',
132 'title' => ts('Money Transfer Date'),
133 'type' => CRM_Utils_Type
::T_DATE
,
137 'name' => 'grant_due_date',
138 'title' => ts('Grant Report Due'),
139 'type' => CRM_Utils_Type
::T_DATE
,
143 'name' => 'decision_date',
144 'title' => ts('Grant Decision Date'),
145 'type' => CRM_Utils_Type
::T_DATE
,
149 'name' => 'rationale',
150 'title' => ts('Rationale'),
152 'grant_report_received' =>
154 'name' => 'grant_report_received',
155 'title' => ts('Grant Report Received'),
162 'name' => 'grant_type_id',
163 'title' => ts('Grant Type'),
164 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
165 'options' => CRM_Grant_PseudoConstant
::grantType(),
169 'name' => 'status_id',
170 'title' => ts('Grant Status'),
171 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
172 'options' => CRM_Grant_PseudoConstant
::grantStatus(),
176 'title' => ts('Amount Granted'),
177 'operatorType' => CRM_Report_Form
::OP_INT
,
181 'title' => ts('Amount Requested'),
182 'operatorType' => CRM_Report_Form
::OP_INT
,
184 'application_received_date' =>
186 'title' => ts('Application Received'),
187 'operatorType' => CRM_Report_Form
::OP_DATE
,
189 'money_transfer_date' =>
191 'title' => ts('Money Transfer Date'),
192 'operatorType' => CRM_Report_Form
::OP_DATE
,
196 'title' => ts('Grant Report Due'),
197 'operatorType' => CRM_Report_Form
::OP_DATE
,
198 'type' => CRM_Report_Form
::OP_DATE
,
202 'title' => ts('Grant Decision Date'),
203 'operatorType' => CRM_Report_Form
::OP_DATE
,
204 'type' => CRM_Utils_Type
::T_DATE
,
211 'title' => ts('Grant Type'),
215 'title' => ts('Grant Status'),
219 'title' => ts('Amount Requested'),
223 'title' => ts('Amount Granted'),
225 'application_received_date' =>
227 'title' => ts('Application Received Date'),
229 'money_transfer_date' =>
231 'title' => ts('Money Transfer Date'),
235 'title' => ts('Grant Decision Date'),
241 parent
::__construct();
247 $this->_columnHeaders
= array();
248 foreach ($this->_columns
as $tableName => $table) {
249 if ($tableName == 'civicrm_address') {
250 $this->_addressField
= TRUE;
252 if (array_key_exists('fields', $table)) {
253 foreach ($table['fields'] as $fieldName => $field) {
254 if (CRM_Utils_Array
::value('required', $field) ||
255 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
258 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
260 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
261 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
267 $this->_select
= "SELECT " . implode(', ', $select) . " ";
272 FROM civicrm_grant {$this->_aliases['civicrm_grant']}
273 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
274 ON ({$this->_aliases['civicrm_grant']}.contact_id = {$this->_aliases['civicrm_contact']}.id ) ";
275 if ($this->_addressField
) {
277 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
278 ON {$this->_aliases['civicrm_contact']}.id =
279 {$this->_aliases['civicrm_address']}.contact_id AND
280 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
287 foreach ($this->_columns
as $tableName => $table) {
288 if (array_key_exists('filters', $table)) {
289 foreach ($table['filters'] as $fieldName => $field) {
292 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
293 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
294 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
295 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
297 if ($relative ||
$from ||
$to) {
298 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
302 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
304 $clause = $this->whereClause($field,
306 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
307 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
308 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
312 if (!empty($clause)) {
313 $clauses[] = $clause;
314 $this->_where
= "WHERE " . implode(' AND ', $clauses);
322 $this->_groupBy
= "";
323 if (CRM_Utils_Array
::value('group_bys', $this->_params
) &&
324 is_array($this->_params
['group_bys']) &&
325 !empty($this->_params
['group_bys'])
327 foreach ($this->_columns
as $tableName => $table) {
328 if (array_key_exists('group_bys', $table)) {
329 foreach ($table['group_bys'] as $fieldName => $field) {
330 if (CRM_Utils_Array
::value($fieldName, $this->_params
['group_bys'])) {
331 $this->_groupBy
[] = $field['dbAlias'];
337 if (!empty($this->_groupBy
)) {
338 $this->_groupBy
= "ORDER BY " . implode(', ', $this->_groupBy
) . ", {$this->_aliases['civicrm_contact']}.sort_name";
341 $this->_groupBy
= "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name";
345 function alterDisplay(&$rows) {
346 // custom code to alter rows
348 foreach ($rows as $rowNum => $row) {
349 // convert display name to links
350 if (array_key_exists('civicrm_contact_sort_name', $row) &&
351 array_key_exists('civicrm_contact_id', $row)
353 $url = CRM_Utils_System
::url('civicrm/contact/view',
354 'reset=1&cid=' . $row['civicrm_contact_id'],
357 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
358 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View contact details for this record.");
362 if (array_key_exists('civicrm_grant_grant_type_id', $row)) {
363 if ($value = $row['civicrm_grant_grant_type_id']) {
364 $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Grant_PseudoConstant
::grantType($value);
368 if (array_key_exists('civicrm_grant_status_id', $row)) {
369 if ($value = $row['civicrm_grant_status_id']) {
370 $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Grant_PseudoConstant
::grantStatus($value);
374 if (array_key_exists('civicrm_grant_grant_report_received', $row)) {
375 if ($value = $row['civicrm_grant_grant_report_received']) {
382 $rows[$rowNum]['civicrm_grant_grant_report_received'] = $value;