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 require_once 'CRM/Grant/PseudoConstant.php';
38 class org_civicrm_report_grant
extends CRM_Report_Form
{
40 protected $_addressField = FALSE;
42 function __construct() {
43 $this->_columns
= array(
45 array('dao' => 'CRM_Contact_DAO_Contact',
47 array('display_name' =>
48 array('title' => ts('Contact Name'),
53 'grouping' => 'contact-fields',
55 array('display_name' =>
56 array('title' => ts('Contact Name'),
60 array('title' => ts('Gender'),
61 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
62 'options' => CRM_Core_PseudoConstant
::gender(),
67 array('dao' => 'CRM_Core_DAO_Address',
70 array('title' => ts('Country'),
71 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
72 'options' => CRM_Core_PseudoConstant
::country(),
74 'state_province_id' =>
75 array('title' => ts('State/Province'),
76 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
77 'options' => CRM_Core_PseudoConstant
::stateProvince(),
82 array('dao' => 'CRM_Grant_DAO_Grant',
87 'name' => 'grant_type_id',
88 'title' => ts('Grant Type'),
92 'name' => 'status_id',
93 'title' => ts('Grant Status'),
97 'name' => 'amount_requested',
98 'title' => ts('Amount Requested'),
99 'type' => CRM_Utils_Type
::T_MONEY
,
103 'name' => 'amount_granted',
104 'title' => ts('Amount Granted'),
106 'application_received_date' =>
108 'name' => 'application_received_date',
109 'title' => ts('Application Received Date'),
112 'money_transfer_date' =>
114 'name' => 'money_transfer_date',
115 'title' => ts('Money Transfer Date'),
116 'type' => CRM_Utils_Type
::T_DATE
,
120 'name' => 'grant_due_date',
121 'title' => ts('Grant Due Date'),
122 'type' => CRM_Utils_Type
::T_DATE
,
126 'name' => 'rationale',
127 'title' => ts('Rationale'),
129 'grant_report_received' =>
131 'name' => 'grant_report_received',
132 'title' => ts('Grant Report Received'),
136 array('grant_type' =>
138 'name' => 'grant_type_id',
139 'title' => ts('Grant Type'),
140 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
141 'options' => CRM_Grant_PseudoConstant
::grantType(),
145 'name' => 'status_id',
146 'title' => ts('Grant Status'),
147 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
148 'options' => CRM_Grant_PseudoConstant
::grantStatus(),
152 'title' => ts('Amount Granted'),
153 'operatorType' => CRM_Report_Form
::OP_INT
,
155 'amount_requested' =>
157 'title' => ts('Amount Requested'),
158 'operatorType' => CRM_Report_Form
::OP_INT
,
160 'application_received_date' =>
162 'title' => ts('Application Received Date'),
163 'operatorType' => CRM_Report_Form
::OP_DATE
,
165 'money_transfer_date' =>
167 'title' => ts('Money Transfer Date'),
168 'operatorType' => CRM_Report_Form
::OP_DATE
,
172 'title' => ts('Grant Due Date'),
173 'operatorType' => CRM_Report_Form
::OP_DATE
,
174 'type' => CRM_Report_Form
::OP_DATE
,
181 'title' => ts('Grant Type'),
185 'title' => ts('Grant Status'),
187 'amount_requested' =>
189 'title' => ts('Amount Requested'),
193 'title' => ts('Amount Granted'),
195 'application_received_date' =>
197 'title' => ts('Application Received Date'),
199 'money_transfer_date' =>
201 'title' => ts('Money Transfer Date'),
207 parent
::__construct();
213 $this->_columnHeaders
= array();
214 foreach ($this->_columns
as $tableName => $table) {
215 if ($tableName == 'civicrm_address') {
216 $this->_addressField
= TRUE;
218 if (array_key_exists('fields', $table)) {
219 foreach ($table['fields'] as $fieldName => $field) {
220 if (CRM_Utils_Array
::value('required', $field) ||
221 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
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) . " ";
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 if ($this->_addressField
) {
243 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
244 ON {$this->_aliases['civicrm_contact']}.id =
245 {$this->_aliases['civicrm_address']}.contact_id AND
246 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
252 foreach ($this->_columns
as $tableName => $table) {
253 if (array_key_exists('filters', $table)) {
254 foreach ($table['filters'] as $fieldName => $field) {
257 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
258 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
259 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
260 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
262 if ($relative ||
$from ||
$to) {
263 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
267 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
269 $clause = $this->whereClause($field,
271 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
272 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
273 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
277 if (!empty($clause)) {
278 $clauses[] = $clause;
279 $this->_where
= "WHERE" . implode(' AND ', $clauses);
287 $this->_groupBy
= "";
288 if (CRM_Utils_Array
::value('group_bys', $this->_params
) &&
289 is_array($this->_params
['group_bys']) &&
290 !empty($this->_params
['group_bys'])
292 foreach ($this->_columns
as $tableName => $table) {
293 if (array_key_exists('group_bys', $table)) {
294 foreach ($table['group_bys'] as $fieldName => $field) {
295 if (CRM_Utils_Array
::value($fieldName, $this->_params
['group_bys'])) {
296 $this->_groupBy
[] = $field['dbAlias'];
302 if (!empty($this->_groupBy
)) {
303 $this->_groupBy
= "ORDER BY " . implode(', ', $this->_groupBy
) . ", {$this->_aliases['civicrm_contact']}.sort_name";
307 function alterDisplay(&$rows) {
308 // custom code to alter rows
310 foreach ($rows as $rowNum => $row) {
311 if (array_key_exists('civicrm_grant_grant_type_id', $row)) {
312 if ($value = $row['civicrm_grant_grant_type_id']) {
313 $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Grant_PseudoConstant
::grantType($value);
317 if (array_key_exists('civicrm_grant_status_id', $row)) {
318 if ($value = $row['civicrm_grant_status_id']) {
319 $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Grant_PseudoConstant
::grantStatus($value);
323 if (array_key_exists('civicrm_grant_grant_report_received', $row)) {
324 if ($value = $row['civicrm_grant_grant_report_received']) {
331 $rows[$rowNum]['civicrm_grant_grant_report_received'] = $value;