3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.1 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2011 |
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-2011
36 require_once 'CRM/Report/Form.php';
37 class org_civicrm_report_grant
extends CRM_Report_Form
{
39 protected $_addressField = FALSE;
41 function __construct() {
42 $this->_columns
= array(
44 array('dao' => 'CRM_Contact_DAO_Contact',
46 array('display_name' =>
47 array('title' => ts('Contact Name'),
52 'grouping' => 'contact-fields',
54 array('display_name' =>
55 array('title' => ts('Contact Name'),
59 array('title' => ts('Gender'),
60 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
61 'options' => CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id'),
66 array('dao' => 'CRM_Core_DAO_Address',
69 array('title' => ts('Country'),
70 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
71 'options' => CRM_Core_PseudoConstant
::country(),
73 'state_province_id' =>
74 array('title' => ts('State/Province'),
75 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
76 'options' => CRM_Core_PseudoConstant
::stateProvince(),
81 array('dao' => 'CRM_Grant_DAO_Grant',
86 'name' => 'grant_type_id',
87 'title' => ts('Grant Type'),
91 'name' => 'status_id',
92 'title' => ts('Grant Status'),
96 'name' => 'amount_requested',
97 'title' => ts('Amount Requested'),
98 'type' => CRM_Utils_Type
::T_MONEY
,
102 'name' => 'amount_granted',
103 'title' => ts('Amount Granted'),
105 'application_received_date' =>
107 'name' => 'application_received_date',
108 'title' => ts('Application Received Date'),
111 'money_transfer_date' =>
113 'name' => 'money_transfer_date',
114 'title' => ts('Money Transfer Date'),
115 'type' => CRM_Utils_Type
::T_DATE
,
119 'name' => 'grant_due_date',
120 'title' => ts('Grant Due Date'),
121 'type' => CRM_Utils_Type
::T_DATE
,
125 'name' => 'rationale',
126 'title' => ts('Rationale'),
128 'grant_report_received' =>
130 'name' => 'grant_report_received',
131 'title' => ts('Grant Report Received'),
135 array('grant_type' =>
137 'name' => 'grant_type_id',
138 'title' => ts('Grant Type'),
139 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
140 'options' => CRM_Core_PseudoConstant
::get('CRM_Grant_DAO_Grant', 'grant_type_id'),
144 'name' => 'status_id',
145 'title' => ts('Grant Status'),
146 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
147 'options' => CRM_Core_PseudoConstant
::get('CRM_Grant_DAO_Grant', 'status_id'),
151 'title' => ts('Amount Granted'),
152 'operatorType' => CRM_Report_Form
::OP_INT
,
154 'amount_requested' =>
156 'title' => ts('Amount Requested'),
157 'operatorType' => CRM_Report_Form
::OP_INT
,
159 'application_received_date' =>
161 'title' => ts('Application Received Date'),
162 'operatorType' => CRM_Report_Form
::OP_DATE
,
164 'money_transfer_date' =>
166 'title' => ts('Money Transfer Date'),
167 'operatorType' => CRM_Report_Form
::OP_DATE
,
171 'title' => ts('Grant Due Date'),
172 'operatorType' => CRM_Report_Form
::OP_DATE
,
173 'type' => CRM_Report_Form
::OP_DATE
,
180 'title' => ts('Grant Type'),
184 'title' => ts('Grant Status'),
186 'amount_requested' =>
188 'title' => ts('Amount Requested'),
192 'title' => ts('Amount Granted'),
194 'application_received_date' =>
196 'title' => ts('Application Received Date'),
198 'money_transfer_date' =>
200 'title' => ts('Money Transfer Date'),
206 parent
::__construct();
212 $this->_columnHeaders
= array();
213 foreach ($this->_columns
as $tableName => $table) {
214 if ($tableName == 'civicrm_address') {
215 $this->_addressField
= TRUE;
217 if (array_key_exists('fields', $table)) {
218 foreach ($table['fields'] as $fieldName => $field) {
219 if (CRM_Utils_Array
::value('required', $field) ||
220 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
223 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
225 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
226 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
232 $this->_select
= "SELECT " . implode(', ', $select) . " ";
237 FROM civicrm_grant {$this->_aliases['civicrm_grant']}
238 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
239 ON ({$this->_aliases['civicrm_grant']}.contact_id = {$this->_aliases['civicrm_contact']}.id ) ";
240 if ($this->_addressField
) {
242 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
243 ON {$this->_aliases['civicrm_contact']}.id =
244 {$this->_aliases['civicrm_address']}.contact_id AND
245 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
251 foreach ($this->_columns
as $tableName => $table) {
252 if (array_key_exists('filters', $table)) {
253 foreach ($table['filters'] as $fieldName => $field) {
256 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
257 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
258 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
259 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
261 if ($relative ||
$from ||
$to) {
262 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
266 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
268 $clause = $this->whereClause($field,
270 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
271 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
272 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
276 if (!empty($clause)) {
277 $clauses[] = $clause;
278 $this->_where
= "WHERE" . implode(' AND ', $clauses);
286 $this->_groupBy
= "";
287 if (CRM_Utils_Array
::value('group_bys', $this->_params
) &&
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 (CRM_Utils_Array
::value($fieldName, $this->_params
['group_bys'])) {
295 $this->_groupBy
[] = $field['dbAlias'];
301 if (!empty($this->_groupBy
)) {
302 $this->_groupBy
= "ORDER BY " . implode(', ', $this->_groupBy
) . ", {$this->_aliases['civicrm_contact']}.sort_name";
306 function alterDisplay(&$rows) {
307 // custom code to alter rows
309 foreach ($rows as $rowNum => $row) {
310 if (array_key_exists('civicrm_grant_grant_type_id', $row)) {
311 if ($value = $row['civicrm_grant_grant_type_id']) {
312 $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Core_PseudoConstant
::getLabel('CRM_Grant_DAO_Grant', 'grant_type_id', $value);
316 if (array_key_exists('civicrm_grant_status_id', $row)) {
317 if ($value = $row['civicrm_grant_status_id']) {
318 $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Core_PseudoConstant
::getLabel('CRM_Grant_DAO_Grant', 'status_id', $value);
322 if (array_key_exists('civicrm_grant_grant_report_received', $row)) {
323 if ($value = $row['civicrm_grant_grant_report_received']) {
330 $rows[$rowNum]['civicrm_grant_grant_report_received'] = $value;