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'),
107 'grant_program_id' =>
109 'name' => 'grant_program_id' ,
110 'title' => ts( 'Grant Program' ),
114 'name' => 'status_id',
115 'title' => ts('Grant Status'),
119 'name' => 'amount_total',
120 'title' => ts('Amount Requested'),
121 'type' => CRM_Utils_Type
::T_MONEY
,
125 'name' => 'amount_granted',
126 'title' => ts('Amount Granted'),
128 'application_received_date' =>
130 'name' => 'application_received_date',
131 'title' => ts('Application Received'),
134 'money_transfer_date' =>
136 'name' => 'money_transfer_date',
137 'title' => ts('Money Transfer Date'),
138 'type' => CRM_Utils_Type
::T_DATE
,
142 'name' => 'grant_due_date',
143 'title' => ts('Grant Report Due'),
144 'type' => CRM_Utils_Type
::T_DATE
,
148 'name' => 'decision_date',
149 'title' => ts('Grant Decision Date'),
150 'type' => CRM_Utils_Type
::T_DATE
,
154 'name' => 'rationale',
155 'title' => ts('Rationale'),
157 'grant_report_received' =>
159 'name' => 'grant_report_received',
160 'title' => ts('Grant Report Received'),
167 'name' => 'grant_type_id',
168 'title' => ts('Grant Type'),
169 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
170 'options' => CRM_Grant_PseudoConstant
::grantType(),
174 'name' =>'grant_program_id' ,
175 'title' => ts( 'Grant Program' ),
176 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
177 'options' => CRM_Grant_BAO_GrantProgram
::grantPrograms( ),
181 'name' => 'status_id',
182 'title' => ts('Grant Status'),
183 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
184 'options' => CRM_Grant_PseudoConstant
::grantStatus(),
188 'title' => ts('Amount Granted'),
189 'operatorType' => CRM_Report_Form
::OP_INT
,
193 'title' => ts('Amount Requested'),
194 'operatorType' => CRM_Report_Form
::OP_INT
,
196 'application_received_date' =>
198 'title' => ts('Application Received'),
199 'operatorType' => CRM_Report_Form
::OP_DATE
,
201 'money_transfer_date' =>
203 'title' => ts('Money Transfer Date'),
204 'operatorType' => CRM_Report_Form
::OP_DATE
,
208 'title' => ts('Grant Report Due'),
209 'operatorType' => CRM_Report_Form
::OP_DATE
,
210 'type' => CRM_Report_Form
::OP_DATE
,
214 'title' => ts('Grant Decision Date'),
215 'operatorType' => CRM_Report_Form
::OP_DATE
,
216 'type' => CRM_Utils_Type
::T_DATE
,
223 'title' => ts('Grant Type'),
225 'grant_program_id' =>
227 'title' => ts( 'Grant Program' )
231 'title' => ts('Grant Status'),
235 'title' => ts('Amount Requested'),
239 'title' => ts('Amount Granted'),
241 'application_received_date' =>
243 'title' => ts('Application Received Date'),
245 'money_transfer_date' =>
247 'title' => ts('Money Transfer Date'),
251 'title' => ts('Grant Decision Date'),
257 parent
::__construct();
263 $this->_columnHeaders
= array();
264 foreach ($this->_columns
as $tableName => $table) {
265 if ($tableName == 'civicrm_address') {
266 $this->_addressField
= TRUE;
268 if (array_key_exists('fields', $table)) {
269 foreach ($table['fields'] as $fieldName => $field) {
270 if (CRM_Utils_Array
::value('required', $field) ||
271 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
274 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
276 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
277 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
283 $this->_select
= "SELECT " . implode(', ', $select) . " ";
288 FROM civicrm_grant {$this->_aliases['civicrm_grant']}
289 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
290 ON ({$this->_aliases['civicrm_grant']}.contact_id = {$this->_aliases['civicrm_contact']}.id ) ";
291 if ($this->_addressField
) {
293 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
294 ON {$this->_aliases['civicrm_contact']}.id =
295 {$this->_aliases['civicrm_address']}.contact_id AND
296 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
303 foreach ($this->_columns
as $tableName => $table) {
304 if (array_key_exists('filters', $table)) {
305 foreach ($table['filters'] as $fieldName => $field) {
308 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
309 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
310 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
311 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
313 if ($relative ||
$from ||
$to) {
314 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
318 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
320 $clause = $this->whereClause($field,
322 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
323 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
324 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
328 if (!empty($clause)) {
329 $clauses[] = $clause;
330 $this->_where
= "WHERE " . implode(' AND ', $clauses);
338 $this->_groupBy
= "";
339 if (CRM_Utils_Array
::value('group_bys', $this->_params
) &&
340 is_array($this->_params
['group_bys']) &&
341 !empty($this->_params
['group_bys'])
343 foreach ($this->_columns
as $tableName => $table) {
344 if (array_key_exists('group_bys', $table)) {
345 foreach ($table['group_bys'] as $fieldName => $field) {
346 if (CRM_Utils_Array
::value($fieldName, $this->_params
['group_bys'])) {
347 $this->_groupBy
[] = $field['dbAlias'];
353 if (!empty($this->_groupBy
)) {
354 $this->_groupBy
= "ORDER BY " . implode(', ', $this->_groupBy
) . ", {$this->_aliases['civicrm_contact']}.sort_name";
357 $this->_groupBy
= "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name";
361 function alterDisplay(&$rows) {
362 // custom code to alter rows
364 foreach ($rows as $rowNum => $row) {
365 // convert display name to links
366 if (array_key_exists('civicrm_contact_sort_name', $row) &&
367 array_key_exists('civicrm_contact_id', $row)
369 $url = CRM_Utils_System
::url('civicrm/contact/view',
370 'reset=1&cid=' . $row['civicrm_contact_id'],
373 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
374 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View contact details for this record.");
378 if (array_key_exists('civicrm_grant_grant_type_id', $row)) {
379 if ($value = $row['civicrm_grant_grant_type_id']) {
380 $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Grant_PseudoConstant
::grantType($value);
384 if ( array_key_exists('civicrm_grant_grant_program_id', $row) ) {
385 if ( $value = $row['civicrm_grant_grant_program_id'] ) {
386 $rows[$rowNum]['civicrm_grant_grant_program_id'] = CRM_Grant_BAO_GrantProgram
::grantPrograms( $value );
390 if (array_key_exists('civicrm_grant_status_id', $row)) {
391 if ($value = $row['civicrm_grant_status_id']) {
392 $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Grant_PseudoConstant
::grantStatus($value);
396 if (array_key_exists('civicrm_grant_grant_report_received', $row)) {
397 if ($value = $row['civicrm_grant_grant_report_received']) {
404 $rows[$rowNum]['civicrm_grant_grant_report_received'] = $value;