4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2013
36 class CRM_Report_Form_Grant_Detail
extends CRM_Report_Form
{
38 protected $_addressField = FALSE;
40 protected $_customGroupExtends = array(
43 function __construct() {
44 $this->_columns
= array(
47 'dao' => 'CRM_Contact_DAO_Contact',
51 array('title' => ts('Contact Name'),
61 'grouping' => 'contact-fields',
65 array('title' => ts('Contact Name'),
69 array('title' => ts('Gender'),
70 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
71 'options' => CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id'),
74 array('title' => ts('Contact ID'),
81 'dao' => 'CRM_Core_DAO_Address',
85 array('title' => ts('Country'),
86 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
87 'options' => CRM_Core_PseudoConstant
::country(),
89 'state_province_id' =>
90 array('title' => ts('State/Province'),
91 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
92 'options' => CRM_Core_PseudoConstant
::stateProvince(),
98 'dao' => 'CRM_Grant_DAO_Grant',
103 'name' => 'grant_type_id',
104 'title' => ts('Grant Type'),
108 'name' => 'status_id',
109 'title' => ts('Grant Status'),
113 'name' => 'amount_total',
114 'title' => ts('Amount Requested'),
115 'type' => CRM_Utils_Type
::T_MONEY
,
119 'name' => 'amount_granted',
120 'title' => ts('Amount Granted'),
122 'application_received_date' =>
124 'name' => 'application_received_date',
125 'title' => ts('Application Received'),
128 'money_transfer_date' =>
130 'name' => 'money_transfer_date',
131 'title' => ts('Money Transfer Date'),
132 'type' => CRM_Utils_Type
::T_DATE
,
136 'name' => 'grant_due_date',
137 'title' => ts('Grant Report Due'),
138 'type' => CRM_Utils_Type
::T_DATE
,
142 'name' => 'decision_date',
143 'title' => ts('Grant Decision Date'),
144 'type' => CRM_Utils_Type
::T_DATE
,
148 'name' => 'rationale',
149 'title' => ts('Rationale'),
151 'grant_report_received' =>
153 'name' => 'grant_report_received',
154 'title' => ts('Grant Report Received'),
161 'name' => 'grant_type_id',
162 'title' => ts('Grant Type'),
163 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
164 'options' => CRM_Core_PseudoConstant
::get('CRM_Grant_DAO_Grant', 'grant_type_id'),
168 'name' => 'status_id',
169 'title' => ts('Grant Status'),
170 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
171 'options' => CRM_Core_PseudoConstant
::get('CRM_Grant_DAO_Grant', 'status_id'),
175 'title' => ts('Amount Granted'),
176 'operatorType' => CRM_Report_Form
::OP_INT
,
180 'title' => ts('Amount Requested'),
181 'operatorType' => CRM_Report_Form
::OP_INT
,
183 'application_received_date' =>
185 'title' => ts('Application Received'),
186 'operatorType' => CRM_Report_Form
::OP_DATE
,
188 'money_transfer_date' =>
190 'title' => ts('Money Transfer Date'),
191 'operatorType' => CRM_Report_Form
::OP_DATE
,
195 'title' => ts('Grant Report Due'),
196 'operatorType' => CRM_Report_Form
::OP_DATE
,
197 'type' => CRM_Report_Form
::OP_DATE
,
201 'title' => ts('Grant Decision Date'),
202 'operatorType' => CRM_Report_Form
::OP_DATE
,
203 'type' => CRM_Utils_Type
::T_DATE
,
210 'title' => ts('Grant Type'),
214 'title' => ts('Grant Status'),
218 'title' => ts('Amount Requested'),
222 'title' => ts('Amount Granted'),
224 'application_received_date' =>
226 'title' => ts('Application Received Date'),
228 'money_transfer_date' =>
230 'title' => ts('Money Transfer Date'),
234 'title' => ts('Grant Decision Date'),
240 parent
::__construct();
246 $this->_columnHeaders
= array();
247 foreach ($this->_columns
as $tableName => $table) {
248 if ($tableName == 'civicrm_address') {
249 $this->_addressField
= TRUE;
251 if (array_key_exists('fields', $table)) {
252 foreach ($table['fields'] as $fieldName => $field) {
253 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
255 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
257 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
258 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
264 $this->_select
= "SELECT " . implode(', ', $select) . " ";
269 FROM civicrm_grant {$this->_aliases['civicrm_grant']}
270 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
271 ON ({$this->_aliases['civicrm_grant']}.contact_id = {$this->_aliases['civicrm_contact']}.id ) ";
272 if ($this->_addressField
) {
274 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
275 ON {$this->_aliases['civicrm_contact']}.id =
276 {$this->_aliases['civicrm_address']}.contact_id AND
277 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
284 foreach ($this->_columns
as $tableName => $table) {
285 if (array_key_exists('filters', $table)) {
286 foreach ($table['filters'] as $fieldName => $field) {
289 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
290 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
291 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
292 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
294 if ($relative ||
$from ||
$to) {
295 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
299 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
301 $clause = $this->whereClause($field,
303 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
304 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
305 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
309 if (!empty($clause)) {
310 $clauses[] = $clause;
311 $this->_where
= "WHERE " . implode(' AND ', $clauses);
319 $this->_groupBy
= "";
320 if (!empty($this->_params
['group_bys']) &&
321 is_array($this->_params
['group_bys']) &&
322 !empty($this->_params
['group_bys'])
324 foreach ($this->_columns
as $tableName => $table) {
325 if (array_key_exists('group_bys', $table)) {
326 foreach ($table['group_bys'] as $fieldName => $field) {
327 if (!empty($this->_params
['group_bys'][$fieldName])) {
328 $this->_groupBy
[] = $field['dbAlias'];
334 if (!empty($this->_groupBy
)) {
335 $this->_groupBy
= "ORDER BY " . implode(', ', $this->_groupBy
) . ", {$this->_aliases['civicrm_contact']}.sort_name";
338 $this->_groupBy
= "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name";
342 function alterDisplay(&$rows) {
343 // custom code to alter rows
345 foreach ($rows as $rowNum => $row) {
346 // convert display name to links
347 if (array_key_exists('civicrm_contact_sort_name', $row) &&
348 array_key_exists('civicrm_contact_id', $row)
350 $url = CRM_Utils_System
::url('civicrm/contact/view',
351 'reset=1&cid=' . $row['civicrm_contact_id'],
354 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
355 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View contact details for this record.");
359 if (array_key_exists('civicrm_grant_grant_type_id', $row)) {
360 if ($value = $row['civicrm_grant_grant_type_id']) {
361 $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Core_PseudoConstant
::getLabel('CRM_Grant_DAO_Grant', 'grant_type_id', $value);
365 if (array_key_exists('civicrm_grant_status_id', $row)) {
366 if ($value = $row['civicrm_grant_status_id']) {
367 $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Core_PseudoConstant
::getLabel('CRM_Grant_DAO_Grant', 'status_id', $value);
371 if (array_key_exists('civicrm_grant_grant_report_received', $row)) {
372 if ($value = $row['civicrm_grant_grant_report_received']) {
379 $rows[$rowNum]['civicrm_grant_grant_report_received'] = $value;