3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
36 require_once 'CRM/Report/Form.php';
39 * Class org_civicrm_report_grant
41 class org_civicrm_report_grant
extends CRM_Report_Form
{
43 protected $_addressField = FALSE;
48 function __construct() {
49 $this->_columns
= array(
51 array('dao' => 'CRM_Contact_DAO_Contact',
53 array('display_name' =>
54 array('title' => ts('Contact Name'),
59 'grouping' => 'contact-fields',
61 array('display_name' =>
62 array('title' => ts('Contact Name'),
66 array('title' => ts('Gender'),
67 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
68 'options' => CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id'),
73 array('dao' => 'CRM_Core_DAO_Address',
76 array('title' => ts('Country'),
77 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
78 'options' => CRM_Core_PseudoConstant
::country(),
80 'state_province_id' =>
81 array('title' => ts('State/Province'),
82 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
83 'options' => CRM_Core_PseudoConstant
::stateProvince(),
88 array('dao' => 'CRM_Grant_DAO_Grant',
93 'name' => 'grant_type_id',
94 'title' => ts('Grant Type'),
98 'name' => 'status_id',
99 'title' => ts('Grant Status'),
101 'amount_requested' =>
103 'name' => 'amount_requested',
104 'title' => ts('Amount Requested'),
105 'type' => CRM_Utils_Type
::T_MONEY
,
109 'name' => 'amount_granted',
110 'title' => ts('Amount Granted'),
112 'application_received_date' =>
114 'name' => 'application_received_date',
115 'title' => ts('Application Received Date'),
118 'money_transfer_date' =>
120 'name' => 'money_transfer_date',
121 'title' => ts('Money Transfer Date'),
122 'type' => CRM_Utils_Type
::T_DATE
,
126 'name' => 'grant_due_date',
127 'title' => ts('Grant Due Date'),
128 'type' => CRM_Utils_Type
::T_DATE
,
132 'name' => 'rationale',
133 'title' => ts('Rationale'),
135 'grant_report_received' =>
137 'name' => 'grant_report_received',
138 'title' => ts('Grant Report Received'),
142 array('grant_type' =>
144 'name' => 'grant_type_id',
145 'title' => ts('Grant Type'),
146 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
147 'options' => CRM_Core_PseudoConstant
::get('CRM_Grant_DAO_Grant', 'grant_type_id'),
151 'name' => 'status_id',
152 'title' => ts('Grant Status'),
153 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
154 'options' => CRM_Core_PseudoConstant
::get('CRM_Grant_DAO_Grant', 'status_id'),
158 'title' => ts('Amount Granted'),
159 'operatorType' => CRM_Report_Form
::OP_INT
,
161 'amount_requested' =>
163 'title' => ts('Amount Requested'),
164 'operatorType' => CRM_Report_Form
::OP_INT
,
166 'application_received_date' =>
168 'title' => ts('Application Received Date'),
169 'operatorType' => CRM_Report_Form
::OP_DATE
,
171 'money_transfer_date' =>
173 'title' => ts('Money Transfer Date'),
174 'operatorType' => CRM_Report_Form
::OP_DATE
,
178 'title' => ts('Grant Due Date'),
179 'operatorType' => CRM_Report_Form
::OP_DATE
,
180 'type' => CRM_Report_Form
::OP_DATE
,
187 'title' => ts('Grant Type'),
191 'title' => ts('Grant Status'),
193 'amount_requested' =>
195 'title' => ts('Amount Requested'),
199 'title' => ts('Amount Granted'),
201 'application_received_date' =>
203 'title' => ts('Application Received Date'),
205 'money_transfer_date' =>
207 'title' => ts('Money Transfer Date'),
213 parent
::__construct();
219 $this->_columnHeaders
= array();
220 foreach ($this->_columns
as $tableName => $table) {
221 if ($tableName == 'civicrm_address') {
222 $this->_addressField
= TRUE;
224 if (array_key_exists('fields', $table)) {
225 foreach ($table['fields'] as $fieldName => $field) {
226 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
228 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
230 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
231 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
237 $this->_select
= "SELECT " . implode(', ', $select) . " ";
242 FROM civicrm_grant {$this->_aliases['civicrm_grant']}
243 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
244 ON ({$this->_aliases['civicrm_grant']}.contact_id = {$this->_aliases['civicrm_contact']}.id ) ";
245 if ($this->_addressField
) {
247 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
248 ON {$this->_aliases['civicrm_contact']}.id =
249 {$this->_aliases['civicrm_address']}.contact_id AND
250 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
256 foreach ($this->_columns
as $tableName => $table) {
257 if (array_key_exists('filters', $table)) {
258 foreach ($table['filters'] as $fieldName => $field) {
261 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
262 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
263 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
264 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
266 if ($relative ||
$from ||
$to) {
267 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
271 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
273 $clause = $this->whereClause($field,
275 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
276 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
277 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
281 if (!empty($clause)) {
282 $clauses[] = $clause;
283 $this->_where
= "WHERE" . implode(' AND ', $clauses);
291 $this->_groupBy
= "";
292 if (!empty($this->_params
['group_bys']) &&
293 is_array($this->_params
['group_bys']) &&
294 !empty($this->_params
['group_bys'])
296 foreach ($this->_columns
as $tableName => $table) {
297 if (array_key_exists('group_bys', $table)) {
298 foreach ($table['group_bys'] as $fieldName => $field) {
299 if (!empty($this->_params
['group_bys'][$fieldName])) {
300 $this->_groupBy
[] = $field['dbAlias'];
306 if (!empty($this->_groupBy
)) {
307 $this->_groupBy
= "ORDER BY " . implode(', ', $this->_groupBy
) . ", {$this->_aliases['civicrm_contact']}.sort_name";
314 function alterDisplay(&$rows) {
315 // custom code to alter rows
317 foreach ($rows as $rowNum => $row) {
318 if (array_key_exists('civicrm_grant_grant_type_id', $row)) {
319 if ($value = $row['civicrm_grant_grant_type_id']) {
320 $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Core_PseudoConstant
::getLabel('CRM_Grant_DAO_Grant', 'grant_type_id', $value);
324 if (array_key_exists('civicrm_grant_status_id', $row)) {
325 if ($value = $row['civicrm_grant_status_id']) {
326 $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Core_PseudoConstant
::getLabel('CRM_Grant_DAO_Grant', 'status_id', $value);
330 if (array_key_exists('civicrm_grant_grant_report_received', $row)) {
331 if ($value = $row['civicrm_grant_grant_report_received']) {
338 $rows[$rowNum]['civicrm_grant_grant_report_received'] = $value;