Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Report_Form_Extended extends CRM_Report_Form { | |
36 | protected $_addressField = FALSE; | |
37 | ||
38 | protected $_emailField = FALSE; | |
39 | ||
40 | protected $_summary = NULL; | |
41 | ||
42 | protected $_customGroupExtends = array(); | |
43 | protected $_baseTable = 'civicrm_contact'; | |
44 | ||
74cf4551 EM |
45 | /** |
46 | * | |
47 | */ | |
48 | /** | |
49 | * | |
50 | */ | |
6a488035 TO |
51 | function __construct() { |
52 | parent::__construct(); | |
53 | } | |
54 | ||
55 | function preProcess() { | |
56 | parent::preProcess(); | |
57 | } | |
58 | ||
59 | function select() { | |
60 | parent::select(); | |
61 | } | |
62 | ||
63 | ||
64 | /* | |
65 | * From clause build where baseTable & fromClauses are defined | |
66 | */ | |
67 | function from() { | |
68 | if (!empty($this->_baseTable)) { | |
69 | $this->buildACLClause($this->_aliases['civicrm_contact']); | |
70 | $this->_from = "FROM {$this->_baseTable} {$this->_aliases[$this->_baseTable]}"; | |
71 | $availableClauses = $this->getAvailableJoins(); | |
72 | foreach ($this->fromClauses() as $fromClause) { | |
73 | $fn = $availableClauses[$fromClause]['callback']; | |
74 | $this->$fn(); | |
75 | } | |
76 | if (strstr($this->_from, 'civicrm_contact')) { | |
77 | $this->_from .= $this->_aclFrom; | |
78 | } | |
79 | } | |
80 | } | |
81 | ||
82 | /* | |
83 | * Define any from clauses in use (child classes to override) | |
84 | */ | |
74cf4551 EM |
85 | /** |
86 | * @return array | |
87 | */ | |
6a488035 TO |
88 | function fromClauses() { |
89 | return array(); | |
90 | } | |
91 | ||
92 | function groupBy() { | |
93 | parent::groupBy(); | |
94 | //@todo - need to re-visit this - bad behaviour from pa | |
95 | if ($this->_groupBy == 'GROUP BY') { | |
96 | $this->_groupBY = NULL; | |
97 | } | |
98 | // if a stat field has been selected the do a group by | |
99 | if (!empty($this->_statFields) && empty($this->_groupBy)) { | |
100 | $this->_groupBy[] = $this->_aliases[$this->_baseTable] . ".id"; | |
101 | } | |
102 | //@todo - this should be in the parent function or at parent level - perhaps build query should do this? | |
103 | if (!empty($this->_groupBy) && is_array($this->_groupBy)) { | |
104 | $this->_groupBy = 'GROUP BY ' . implode(',', $this->_groupBy); | |
105 | } | |
106 | } | |
107 | ||
108 | function orderBy() { | |
109 | parent::orderBy(); | |
110 | } | |
111 | ||
74cf4551 EM |
112 | /** |
113 | * @param $rows | |
114 | * | |
115 | * @return array | |
116 | */ | |
6a488035 TO |
117 | function statistics(&$rows) { |
118 | return parent::statistics($rows); | |
119 | } | |
120 | ||
121 | function postProcess() { | |
8cc574cf | 122 | if (!empty($this->_aclTable) && !empty($this->_aliases[$this->_aclTable])) { |
6a488035 TO |
123 | $this->buildACLClause($this->_aliases[$this->_aclTable]); |
124 | } | |
125 | parent::postProcess(); | |
126 | } | |
127 | ||
74cf4551 EM |
128 | /** |
129 | * @param $rows | |
130 | */ | |
6a488035 TO |
131 | function alterDisplay(&$rows) { |
132 | parent::alterDisplay($rows); | |
133 | ||
134 | //THis is all generic functionality which can hopefully go into the parent class | |
135 | // it introduces the option of defining an alter display function as part of the column definition | |
136 | // @tod tidy up the iteration so it happens in this function | |
137 | list($firstRow) = $rows; | |
138 | // no result to alter | |
139 | if (empty($firstRow)) { | |
140 | return; | |
141 | } | |
142 | $selectedFields = array_keys($firstRow); | |
143 | ||
144 | $alterfunctions = $altermap = array(); | |
145 | foreach ($this->_columns as $tablename => $table) { | |
146 | if (array_key_exists('fields', $table)) { | |
147 | foreach ($table['fields'] as $field => $specs) { | |
9d72cede EM |
148 | if (in_array($tablename . '_' . $field, $selectedFields) && |
149 | array_key_exists('alter_display', $specs) | |
150 | ) { | |
151 | $alterfunctions[$tablename . '_' . | |
152 | $field] = $specs['alter_display']; | |
6a488035 TO |
153 | $altermap[$tablename . '_' . $field] = $field; |
154 | } | |
155 | } | |
156 | } | |
157 | } | |
158 | if (empty($alterfunctions)) { | |
159 | // - no manipulation to be done | |
160 | return; | |
161 | } | |
162 | ||
163 | foreach ($rows as $index => & $row) { | |
164 | foreach ($row as $selectedfield => $value) { | |
165 | if (array_key_exists($selectedfield, $alterfunctions)) { | |
166 | $rows[$index][$selectedfield] = $this->$alterfunctions[$selectedfield]($value, $row, $selectedfield, $altermap[$selectedfield]); | |
167 | } | |
168 | } | |
169 | } | |
170 | } | |
171 | ||
74cf4551 EM |
172 | /** |
173 | * @return array | |
174 | */ | |
6a488035 TO |
175 | function getLineItemColumns() { |
176 | return array( | |
9d72cede | 177 | 'civicrm_line_item' => array( |
6a488035 | 178 | 'dao' => 'CRM_Price_BAO_LineItem', |
9d72cede EM |
179 | 'fields' => array( |
180 | 'qty' => array( | |
181 | 'title' => ts('Quantity'), | |
6a488035 | 182 | 'type' => CRM_Utils_Type::T_INT, |
9d72cede | 183 | 'statistics' => array('sum' => ts('Total Quantity Selected')), |
6a488035 | 184 | ), |
9d72cede EM |
185 | 'unit_price' => array( |
186 | 'title' => ts('Unit Price'), | |
6a488035 | 187 | ), |
9d72cede EM |
188 | 'line_total' => array( |
189 | 'title' => ts('Line Total'), | |
6a488035 | 190 | 'type' => CRM_Utils_Type::T_MONEY, |
9d72cede | 191 | 'statistics' => array('sum' => ts('Total of Line Items')), |
6a488035 TO |
192 | ), |
193 | ), | |
9d72cede EM |
194 | 'participant_count' => array( |
195 | 'title' => ts('Participant Count'), | |
196 | 'statistics' => array('sum' => ts('Total Participants')), | |
6a488035 | 197 | ), |
9d72cede EM |
198 | 'filters' => array( |
199 | 'qty' => array( | |
200 | 'title' => ts('Quantity'), | |
6a488035 TO |
201 | 'type' => CRM_Utils_Type::T_INT, |
202 | 'operator' => CRM_Report_Form::OP_INT, | |
203 | ), | |
204 | ), | |
9d72cede EM |
205 | 'group_bys' => array( |
206 | 'price_field_id' => array( | |
207 | 'title' => ts('Price Field'), | |
6a488035 | 208 | ), |
9d72cede EM |
209 | 'price_field_value_id' => array( |
210 | 'title' => ts('Price Field Option'), | |
6a488035 | 211 | ), |
9d72cede EM |
212 | 'line_item_id' => array( |
213 | 'title' => ts('Individual Line Item'), | |
6a488035 | 214 | 'name' => 'id', |
9d72cede | 215 | ), |
6a488035 TO |
216 | ), |
217 | ), | |
6a488035 TO |
218 | ); |
219 | } | |
220 | ||
74cf4551 EM |
221 | /** |
222 | * @return array | |
223 | */ | |
6a488035 TO |
224 | function getPriceFieldValueColumns() { |
225 | return array( | |
9d72cede | 226 | 'civicrm_price_field_value' => array( |
9da8dc8c | 227 | 'dao' => 'CRM_Price_BAO_PriceFieldValue', |
6a488035 | 228 | 'fields' => array( |
9d72cede EM |
229 | 'price_field_value_label' => array( |
230 | 'title' => ts('Price Field Value Label'), | |
6a488035 TO |
231 | 'name' => 'label', |
232 | ), | |
233 | ), | |
9d72cede EM |
234 | 'filters' => array( |
235 | 'price_field_value_label' => array( | |
236 | 'title' => ts('Price Fields Value Label'), | |
6a488035 TO |
237 | 'type' => CRM_Utils_Type::T_STRING, |
238 | 'operator' => 'like', | |
239 | 'name' => 'label', | |
240 | ), | |
241 | ), | |
9d72cede EM |
242 | 'order_bys' => array( |
243 | 'label' => array( | |
244 | 'title' => ts('Price Field Value Label'), | |
6a488035 TO |
245 | ), |
246 | ), | |
9d72cede | 247 | 'group_bys' => //note that we have a requirement to group by label such that all 'Promo book' lines |
6a488035 TO |
248 | // are grouped together across price sets but there may be a separate need to group |
249 | // by id so that entries in one price set are distinct from others. Not quite sure what | |
250 | // to call the distinction for end users benefit | |
9d72cede EM |
251 | array( |
252 | 'price_field_value_label' => array( | |
253 | 'title' => ts('Price Field Value Label'), | |
254 | 'name' => 'label', | |
255 | ), | |
6a488035 | 256 | ), |
6a488035 TO |
257 | ), |
258 | ); | |
259 | } | |
260 | ||
74cf4551 EM |
261 | /** |
262 | * @return array | |
263 | */ | |
6a488035 TO |
264 | function getPriceFieldColumns() { |
265 | return array( | |
9d72cede | 266 | 'civicrm_price_field' => array( |
9da8dc8c | 267 | 'dao' => 'CRM_Price_BAO_PriceField', |
9d72cede EM |
268 | 'fields' => array( |
269 | 'price_field_label' => array( | |
270 | 'title' => ts('Price Field Label'), | |
6a488035 TO |
271 | 'name' => 'label', |
272 | ), | |
273 | ), | |
9d72cede EM |
274 | 'filters' => array( |
275 | 'price_field_label' => array( | |
276 | 'title' => ts('Price Field Label'), | |
6a488035 TO |
277 | 'type' => CRM_Utils_Type::T_STRING, |
278 | 'operator' => 'like', | |
279 | 'name' => 'label', | |
280 | ), | |
281 | ), | |
9d72cede EM |
282 | 'order_bys' => array( |
283 | 'price_field_label' => array( | |
284 | 'title' => ts('Price Field Label'), | |
285 | 'name' => 'label', | |
6a488035 TO |
286 | ), |
287 | ), | |
9d72cede EM |
288 | 'group_bys' => array( |
289 | 'price_field_label' => array( | |
290 | 'title' => ts('Price Field Label'), | |
6a488035 TO |
291 | 'name' => 'label', |
292 | ), | |
293 | ), | |
294 | ), | |
295 | ); | |
296 | } | |
297 | ||
74cf4551 EM |
298 | /** |
299 | * @return array | |
300 | */ | |
6a488035 TO |
301 | function getParticipantColumns() { |
302 | static $_events = array(); | |
303 | if (!isset($_events['all'])) { | |
304 | CRM_Core_PseudoConstant::populate($_events['all'], 'CRM_Event_DAO_Event', FALSE, 'title', 'is_active', "is_template IS NULL OR is_template = 0", 'end_date DESC'); | |
305 | } | |
306 | return array( | |
9d72cede | 307 | 'civicrm_participant' => array( |
6a488035 | 308 | 'dao' => 'CRM_Event_DAO_Participant', |
9d72cede EM |
309 | 'fields' => array( |
310 | 'participant_id' => array('title' => 'Participant ID'), | |
6a488035 TO |
311 | 'participant_record' => array( |
312 | 'name' => 'id', | |
aa6228f8 | 313 | 'title' => ts('Participant ID'), |
6a488035 | 314 | ), |
9d72cede EM |
315 | 'event_id' => array( |
316 | 'title' => ts('Event ID'), | |
6a488035 TO |
317 | 'type' => CRM_Utils_Type::T_STRING, |
318 | 'alter_display' => 'alterEventID', | |
319 | ), | |
9d72cede EM |
320 | 'status_id' => array( |
321 | 'title' => ts('Status'), | |
6a488035 TO |
322 | 'alter_display' => 'alterParticipantStatus', |
323 | ), | |
9d72cede EM |
324 | 'role_id' => array( |
325 | 'title' => ts('Role'), | |
6a488035 TO |
326 | 'alter_display' => 'alterParticipantRole', |
327 | ), | |
328 | 'participant_fee_level' => NULL, | |
329 | 'participant_fee_amount' => NULL, | |
330 | 'participant_register_date' => array('title' => ts('Registration Date')), | |
331 | ), | |
332 | 'grouping' => 'event-fields', | |
9d72cede EM |
333 | 'filters' => array( |
334 | 'event_id' => array( | |
335 | 'name' => 'event_id', | |
6a488035 TO |
336 | 'title' => ts('Event'), |
337 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
338 | 'options' => $_events['all'], | |
339 | ), | |
340 | 'sid' => array( | |
341 | 'name' => 'status_id', | |
342 | 'title' => ts('Participant Status'), | |
343 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
344 | 'options' => CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'), | |
345 | ), | |
346 | 'rid' => array( | |
347 | 'name' => 'role_id', | |
348 | 'title' => ts('Participant Role'), | |
349 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
350 | 'options' => CRM_Event_PseudoConstant::participantRole(), | |
351 | ), | |
352 | 'participant_register_date' => array( | |
353 | 'title' => ' Registration Date', | |
354 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
355 | ), | |
356 | ), | |
9d72cede EM |
357 | 'order_bys' => array( |
358 | 'event_id' => array( | |
359 | 'title' => ts('Event'), | |
360 | 'default_weight' => '1', | |
361 | 'default_order' => 'ASC' | |
362 | ), | |
6a488035 | 363 | ), |
9d72cede EM |
364 | 'group_bys' => array( |
365 | 'event_id' => array('title' => ts('Event')), | |
6a488035 TO |
366 | ), |
367 | ), | |
368 | ); | |
369 | } | |
370 | ||
74cf4551 EM |
371 | /** |
372 | * @return array | |
373 | */ | |
6a488035 TO |
374 | function getMembershipColumns() { |
375 | return array( | |
376 | 'civicrm_membership' => array( | |
377 | 'dao' => 'CRM_Member_DAO_Membership', | |
378 | 'grouping' => 'member-fields', | |
379 | 'fields' => array( | |
380 | 'membership_type_id' => array( | |
381 | 'title' => 'Membership Type', | |
382 | 'required' => TRUE, | |
383 | 'alter_display' => 'alterMembershipTypeID', | |
384 | ), | |
385 | 'status_id' => array( | |
386 | 'title' => 'Membership Status', | |
387 | 'required' => TRUE, | |
388 | 'alter_display' => 'alterMembershipStatusID', | |
389 | ), | |
390 | 'join_date' => NULL, | |
391 | 'start_date' => array( | |
392 | 'title' => ts('Current Cycle Start Date'), | |
393 | ), | |
394 | 'end_date' => array( | |
395 | 'title' => ts('Current Membership Cycle End Date'), | |
396 | ), | |
397 | ), | |
398 | 'group_bys' => array( | |
399 | 'membership_type_id' => array( | |
400 | 'title' => ts('Membership Type'), | |
401 | ), | |
402 | ), | |
403 | 'filters' => array( | |
404 | 'join_date' => array( | |
405 | 'type' => CRM_Utils_Type::T_DATE, | |
406 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
407 | ), | |
408 | ), | |
409 | ), | |
410 | ); | |
411 | } | |
412 | ||
74cf4551 EM |
413 | /** |
414 | * @return array | |
415 | */ | |
6a488035 TO |
416 | function getMembershipTypeColumns() { |
417 | return array( | |
418 | 'civicrm_membership_type' => array( | |
419 | 'dao' => 'CRM_Member_DAO_MembershipType', | |
420 | 'grouping' => 'member-fields', | |
421 | 'filters' => array( | |
422 | 'gid' => array( | |
423 | 'name' => 'id', | |
424 | 'title' => ts('Membership Types'), | |
425 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
426 | 'type' => CRM_Utils_Type::T_INT + CRM_Utils_Type::T_ENUM, | |
427 | 'options' => CRM_Member_PseudoConstant::membershipType(), | |
428 | ), | |
429 | ), | |
430 | ), | |
431 | ); | |
432 | } | |
433 | ||
74cf4551 EM |
434 | /** |
435 | * @return array | |
436 | */ | |
6a488035 TO |
437 | function getEventColumns() { |
438 | return array( | |
439 | 'civicrm_event' => array( | |
440 | 'dao' => 'CRM_Event_DAO_Event', | |
9d72cede | 441 | 'fields' => array( |
6a488035 TO |
442 | 'id' => array( |
443 | 'no_display' => TRUE, | |
444 | 'required' => TRUE, | |
445 | ), | |
9d72cede EM |
446 | 'title' => array( |
447 | 'title' => ts('Event Title'), | |
6a488035 TO |
448 | 'required' => TRUE, |
449 | ), | |
9d72cede EM |
450 | 'event_type_id' => array( |
451 | 'title' => ts('Event Type'), | |
6a488035 TO |
452 | 'required' => TRUE, |
453 | 'alter_display' => 'alterEventType', | |
454 | ), | |
455 | 'fee_label' => array('title' => ts('Fee Label')), | |
9d72cede EM |
456 | 'event_start_date' => array( |
457 | 'title' => ts('Event Start Date'), | |
458 | ), | |
6a488035 | 459 | 'event_end_date' => array('title' => ts('Event End Date')), |
9d72cede EM |
460 | 'max_participants' => array( |
461 | 'title' => ts('Capacity'), | |
6a488035 TO |
462 | 'type' => CRM_Utils_Type::T_INT, |
463 | ), | |
464 | ), | |
465 | 'grouping' => 'event-fields', | |
466 | 'filters' => array( | |
467 | 'event_type_id' => array( | |
468 | 'name' => 'event_type_id', | |
469 | 'title' => ts('Event Type'), | |
470 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
471 | 'options' => CRM_Core_OptionGroup::values('event_type'), | |
472 | ), | |
473 | 'event_title' => array( | |
474 | 'name' => 'title', | |
475 | 'title' => ts('Event Title'), | |
476 | 'operatorType' => CRM_Report_Form::OP_STRING, | |
477 | ), | |
478 | ), | |
479 | 'order_bys' => array( | |
480 | 'event_type_id' => array( | |
481 | 'title' => ts('Event Type'), | |
482 | 'default_weight' => '2', | |
483 | 'default_order' => 'ASC', | |
484 | ), | |
485 | ), | |
486 | 'group_bys' => array( | |
487 | 'event_type_id' => array( | |
9d72cede EM |
488 | 'title' => ts('Event Type'), |
489 | ), | |
6a488035 TO |
490 | ), |
491 | ), | |
492 | ); | |
493 | } | |
494 | ||
74cf4551 EM |
495 | /** |
496 | * @return array | |
497 | */ | |
6a488035 TO |
498 | function getContributionColumns() { |
499 | return array( | |
9d72cede | 500 | 'civicrm_contribution' => array( |
6a488035 | 501 | 'dao' => 'CRM_Contribute_DAO_Contribution', |
9d72cede | 502 | 'fields' => array( |
6a488035 TO |
503 | 'contribution_id' => array( |
504 | 'name' => 'id', | |
505 | ), | |
9d72cede EM |
506 | 'financial_type_id' => array( |
507 | 'title' => ts('Financial Type'), | |
6a488035 TO |
508 | 'default' => TRUE, |
509 | 'alter_display' => 'alterContributionType', | |
510 | ), | |
9d72cede EM |
511 | 'payment_instrument_id' => array( |
512 | 'title' => ts('Payment Instrument'), | |
6a488035 TO |
513 | 'alter_display' => 'alterPaymentType', |
514 | ), | |
515 | 'source' => array('title' => 'Contribution Source'), | |
516 | 'trxn_id' => NULL, | |
517 | 'receive_date' => array('default' => TRUE), | |
518 | 'receipt_date' => NULL, | |
519 | 'fee_amount' => NULL, | |
520 | 'net_amount' => NULL, | |
9d72cede EM |
521 | 'total_amount' => array( |
522 | 'title' => ts('Amount'), | |
523 | 'statistics' => array('sum' => ts('Total Amount')), | |
6a488035 TO |
524 | 'type' => CRM_Utils_Type::T_MONEY, |
525 | ), | |
526 | ), | |
9d72cede EM |
527 | 'filters' => array( |
528 | 'receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), | |
529 | 'financial_type_id' => array( | |
530 | 'title' => ts('Financial Type'), | |
6a488035 TO |
531 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
532 | 'options' => CRM_Contribute_PseudoConstant::financialType(), | |
533 | ), | |
9d72cede EM |
534 | 'payment_instrument_id' => array( |
535 | 'title' => ts('Payment Type'), | |
6a488035 TO |
536 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
537 | 'options' => CRM_Contribute_PseudoConstant::paymentInstrument(), | |
538 | ), | |
9d72cede EM |
539 | 'contribution_status_id' => array( |
540 | 'title' => ts('Contribution Status'), | |
6a488035 TO |
541 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
542 | 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), | |
543 | ), | |
9d72cede | 544 | 'total_amount' => array('title' => ts('Contribution Amount')), |
6a488035 | 545 | ), |
9d72cede EM |
546 | 'order_bys' => array( |
547 | 'payment_instrument_id' => array( | |
548 | 'title' => ts('Payment Instrument'), | |
549 | ), | |
550 | 'financial_type_id' => array( | |
551 | 'title' => ts('Financial Type'), | |
6a488035 | 552 | ), |
6a488035 | 553 | ), |
9d72cede EM |
554 | 'group_bys' => array( |
555 | 'financial_type_id' => array('title' => ts('Financial Type')), | |
556 | 'payment_instrument_id' => array('title' => ts('Payment Instrument')), | |
557 | 'contribution_id' => array( | |
558 | 'title' => ts('Individual Contribution'), | |
6a488035 | 559 | 'name' => 'id', |
9d72cede | 560 | ), |
6a488035 TO |
561 | 'source' => array('title' => 'Contribution Source'), |
562 | ), | |
563 | 'grouping' => 'contribution-fields', | |
564 | ), | |
565 | ); | |
566 | } | |
567 | ||
74cf4551 EM |
568 | /** |
569 | * @return array | |
570 | */ | |
6a488035 TO |
571 | function getContactColumns() { |
572 | return array( | |
573 | 'civicrm_contact' => array( | |
574 | 'dao' => 'CRM_Contact_DAO_Contact', | |
575 | 'fields' => array( | |
576 | 'display_name' => array( | |
577 | 'title' => ts('Contact Name'), | |
578 | ), | |
579 | 'id' => array( | |
580 | 'title' => ts('Contact ID'), | |
581 | 'alter_display' => 'alterContactID', | |
582 | ), | |
583 | 'first_name' => array( | |
584 | 'title' => ts('First Name'), | |
585 | ), | |
586 | 'last_name' => array( | |
587 | 'title' => ts('Last Name'), | |
588 | ), | |
589 | 'nick_name' => array( | |
590 | 'title' => ts('Nickname'), | |
591 | 'alter_display' => 'alterNickname', | |
592 | ), | |
593 | ), | |
594 | 'filters' => array( | |
595 | 'id' => array( | |
596 | 'title' => ts('Contact ID'), | |
597 | ) | |
9d72cede | 598 | , |
6a488035 TO |
599 | 'sort_name' => array( |
600 | 'title' => ts('Contact Name'), | |
601 | ), | |
602 | ), | |
603 | 'grouping' => 'contact-fields', | |
604 | 'order_bys' => array( | |
605 | 'sort_name' => array( | |
606 | 'title' => ts('Last Name, First Name'), | |
607 | 'default' => '1', | |
608 | 'default_weight' => '0', | |
609 | 'default_order' => 'ASC', | |
610 | ), | |
611 | ), | |
612 | ), | |
613 | ); | |
614 | } | |
615 | ||
74cf4551 EM |
616 | /** |
617 | * @return array | |
618 | */ | |
6a488035 TO |
619 | function getCaseColumns() { |
620 | return array( | |
621 | 'civicrm_case' => array( | |
622 | 'dao' => 'CRM_Case_DAO_Case', | |
623 | 'fields' => array( | |
624 | 'id' => array( | |
625 | 'title' => ts('Case ID'), | |
9d72cede | 626 | 'required' => FALSE |
6a488035 TO |
627 | ), |
628 | 'subject' => array( | |
629 | 'title' => ts('Case Subject'), | |
9d72cede | 630 | 'default' => TRUE |
6a488035 TO |
631 | ), |
632 | 'status_id' => array( | |
633 | 'title' => ts('Status'), | |
9d72cede | 634 | 'default' => TRUE |
6a488035 TO |
635 | ), |
636 | 'case_type_id' => array( | |
637 | 'title' => ts('Case Type'), | |
9d72cede | 638 | 'default' => TRUE |
6a488035 TO |
639 | ), |
640 | 'case_start_date' => array( | |
641 | 'title' => ts('Case Start Date'), | |
642 | 'name' => 'start_date', | |
9d72cede | 643 | 'default' => TRUE |
6a488035 TO |
644 | ), |
645 | 'case_end_date' => array( | |
646 | 'title' => ts('Case End Date'), | |
647 | 'name' => 'end_date', | |
9d72cede | 648 | 'default' => TRUE |
6a488035 TO |
649 | ), |
650 | 'case_duration' => array( | |
651 | 'name' => 'duration', | |
652 | 'title' => ts('Duration (Days)'), | |
9d72cede | 653 | 'default' => FALSE |
6a488035 TO |
654 | ), |
655 | 'case_is_deleted' => array( | |
656 | 'name' => 'is_deleted', | |
657 | 'title' => ts('Case Deleted?'), | |
9d72cede | 658 | 'default' => FALSE, |
6a488035 TO |
659 | 'type' => CRM_Utils_Type::T_INT |
660 | ) | |
661 | ), | |
662 | 'filters' => array( | |
663 | 'case_start_date' => array( | |
664 | 'title' => ts('Case Start Date'), | |
665 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
666 | 'type' => CRM_Utils_Type::T_DATE, | |
667 | 'name' => 'start_date', | |
668 | ), | |
669 | 'case_end_date' => array( | |
670 | 'title' => ts('Case End Date'), | |
671 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
672 | 'type' => CRM_Utils_Type::T_DATE, | |
673 | 'name' => 'end_date' | |
674 | ), | |
675 | 'case_type_id' => array( | |
676 | 'title' => ts('Case Type'), | |
677 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
678 | 'options' => $this->case_types | |
679 | ), | |
680 | 'case_status_id' => array( | |
681 | 'title' => ts('Case Status'), | |
682 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
683 | 'options' => $this->case_statuses, | |
684 | 'name' => 'status_id' | |
685 | ), | |
686 | 'case_is_deleted' => array( | |
687 | 'title' => ts('Case Deleted?'), | |
688 | 'type' => CRM_Report_Form::OP_INT, | |
689 | 'operatorType' => CRM_Report_Form::OP_SELECT, | |
690 | 'options' => $this->deleted_labels, | |
691 | 'default' => 0, | |
692 | 'name' => 'is_deleted' | |
693 | ) | |
694 | ) | |
695 | ) | |
696 | ); | |
697 | } | |
698 | ||
699 | /* | |
c490a46a | 700 | * adding address fields to construct function in reports |
6a488035 TO |
701 | * @param array $options Options for the report |
702 | * - prefix prefix to add (e.g. 'honor' when getting address details for honor contact | |
703 | * - prefix_label optional prefix lable eg. "Honoree " for front end | |
704 | * - group_by enable these fields for group by - default false | |
705 | * - order_by enable these fields for order by | |
706 | * - filters enable these fields for filtering | |
707 | * - defaults - (is this working?) values to pre-populate | |
708 | * @return array address fields for construct clause | |
709 | */ | |
74cf4551 EM |
710 | /** |
711 | * Get address columns to add to array | |
9d72cede | 712 | * |
74cf4551 EM |
713 | * @param array $options |
714 | * - prefix Prefix to add to table (in case of more than one instance of the table) | |
715 | * - prefix_label Label to give columns from this address table instance | |
9d72cede | 716 | * |
74cf4551 EM |
717 | * @return array address columns definition |
718 | */ | |
719 | /** | |
720 | * @param array $options | |
721 | * | |
722 | * @return array | |
723 | */ | |
6a488035 TO |
724 | function getAddressColumns($options = array()) { |
725 | $defaultOptions = array( | |
726 | 'prefix' => '', | |
727 | 'prefix_label' => '', | |
9d72cede EM |
728 | 'group_by' => FALSE, |
729 | 'order_by' => TRUE, | |
730 | 'filters' => TRUE, | |
6a488035 TO |
731 | 'defaults' => array( |
732 | 'country_id' => TRUE | |
733 | ), | |
9d72cede | 734 | ); |
6a488035 | 735 | |
9d72cede | 736 | $options = array_merge($defaultOptions, $options); |
6a488035 TO |
737 | |
738 | $addressFields = array( | |
739 | $options['prefix'] . 'civicrm_address' => array( | |
740 | 'dao' => 'CRM_Core_DAO_Address', | |
741 | 'name' => 'civicrm_address', | |
742 | 'alias' => $options['prefix'] . 'civicrm_address', | |
743 | 'fields' => array( | |
744 | $options['prefix'] . 'name' => array( | |
745 | 'title' => ts($options['prefix_label'] . 'Address Name'), | |
746 | 'default' => CRM_Utils_Array::value('name', $options['defaults'], FALSE), | |
747 | 'name' => 'name', | |
748 | ), | |
749 | $options['prefix'] . 'street_address' => array( | |
750 | 'title' => ts($options['prefix_label'] . 'Street Address'), | |
751 | 'default' => CRM_Utils_Array::value('street_address', $options['defaults'], FALSE), | |
752 | 'name' => 'street_address', | |
753 | ), | |
754 | $options['prefix'] . 'supplemental_address_1' => array( | |
9d72cede EM |
755 | 'title' => ts($options['prefix_label'] . |
756 | 'Supplementary Address Field 1'), | |
6a488035 TO |
757 | 'default' => CRM_Utils_Array::value('supplemental_address_1', $options['defaults'], FALSE), |
758 | 'name' => 'supplemental_address_1', | |
759 | ), | |
760 | $options['prefix'] . 'supplemental_address_2' => array( | |
9d72cede EM |
761 | 'title' => ts($options['prefix_label'] . |
762 | 'Supplementary Address Field 2'), | |
6a488035 TO |
763 | 'default' => CRM_Utils_Array::value('supplemental_address_2', $options['defaults'], FALSE), |
764 | 'name' => 'supplemental_address_2', | |
765 | ), | |
766 | $options['prefix'] . 'street_number' => array( | |
767 | 'name' => 'street_number', | |
768 | 'title' => ts($options['prefix_label'] . 'Street Number'), | |
769 | 'type' => 1, | |
770 | 'default' => CRM_Utils_Array::value('street_number', $options['defaults'], FALSE), | |
771 | 'name' => 'street_number', | |
772 | ), | |
773 | $options['prefix'] . 'street_name' => array( | |
774 | 'name' => 'street_name', | |
775 | 'title' => ts($options['prefix_label'] . 'Street Name'), | |
776 | 'type' => 1, | |
777 | 'default' => CRM_Utils_Array::value('street_name', $options['defaults'], FALSE), | |
778 | 'name' => 'street_name', | |
779 | ), | |
780 | $options['prefix'] . 'street_unit' => array( | |
781 | 'name' => 'street_unit', | |
782 | 'title' => ts($options['prefix_label'] . 'Street Unit'), | |
783 | 'type' => 1, | |
784 | 'default' => CRM_Utils_Array::value('street_unit', $options['defaults'], FALSE), | |
785 | 'name' => 'street_unit', | |
786 | ), | |
787 | $options['prefix'] . 'city' => array( | |
788 | 'title' => ts($options['prefix_label'] . 'City'), | |
789 | 'default' => CRM_Utils_Array::value('city', $options['defaults'], FALSE), | |
790 | 'name' => 'city', | |
791 | ), | |
792 | $options['prefix'] . 'postal_code' => array( | |
793 | 'title' => ts($options['prefix_label'] . 'Postal Code'), | |
794 | 'default' => CRM_Utils_Array::value('postal_code', $options['defaults'], FALSE), | |
795 | 'name' => 'postal_code', | |
796 | ), | |
797 | $options['prefix'] . 'county_id' => array( | |
798 | 'title' => ts($options['prefix_label'] . 'County'), | |
799 | 'default' => CRM_Utils_Array::value('county_id', $options['defaults'], FALSE), | |
800 | 'alter_display' => 'alterCountyID', | |
801 | 'name' => 'county_id', | |
802 | ), | |
803 | $options['prefix'] . 'state_province_id' => array( | |
804 | 'title' => ts($options['prefix_label'] . 'State/Province'), | |
805 | 'default' => CRM_Utils_Array::value('state_province_id', $options['defaults'], FALSE), | |
806 | 'alter_display' => 'alterStateProvinceID', | |
9d72cede | 807 | 'name' => 'state_province_id', |
6a488035 TO |
808 | ), |
809 | $options['prefix'] . 'country_id' => array( | |
810 | 'title' => ts($options['prefix_label'] . 'Country'), | |
811 | 'default' => CRM_Utils_Array::value('country_id', $options['defaults'], FALSE), | |
812 | 'alter_display' => 'alterCountryID', | |
813 | 'name' => 'country_id', | |
814 | ), | |
815 | ), | |
816 | 'grouping' => 'location-fields', | |
817 | ), | |
818 | ); | |
819 | ||
820 | if ($options['filters']) { | |
9d72cede | 821 | $addressFields[$options['prefix'] . 'civicrm_address']['filters'] = array( |
6a488035 TO |
822 | $options['prefix'] . 'street_number' => array( |
823 | 'title' => ts($options['prefix_label'] . 'Street Number'), | |
824 | 'type' => 1, | |
825 | 'name' => 'street_number', | |
826 | ), | |
827 | $options['prefix'] . 'street_name' => array( | |
828 | 'title' => ts($options['prefix_label'] . 'Street Name'), | |
829 | 'name' => $options['prefix'] . 'street_name', | |
830 | 'operator' => 'like', | |
831 | ), | |
832 | $options['prefix'] . 'postal_code' => array( | |
833 | 'title' => ts($options['prefix_label'] . 'Postal Code'), | |
834 | 'type' => 1, | |
835 | 'name' => 'postal_code', | |
836 | ), | |
837 | $options['prefix'] . 'city' => array( | |
838 | 'title' => ts($options['prefix_label'] . 'City'), | |
839 | 'operator' => 'like', | |
840 | 'name' => 'city', | |
841 | ), | |
842 | $options['prefix'] . 'county_id' => array( | |
843 | 'name' => 'county_id', | |
844 | 'title' => ts($options['prefix_label'] . 'County'), | |
845 | 'type' => CRM_Utils_Type::T_INT, | |
846 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
847 | 'options' => CRM_Core_PseudoConstant::county(), | |
848 | ), | |
849 | $options['prefix'] . 'state_province_id' => array( | |
850 | 'name' => 'state_province_id', | |
851 | 'title' => ts($options['prefix_label'] . 'State/Province'), | |
852 | 'type' => CRM_Utils_Type::T_INT, | |
853 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
854 | 'options' => CRM_Core_PseudoConstant::stateProvince(), | |
855 | ), | |
856 | $options['prefix'] . 'country_id' => array( | |
857 | 'name' => 'country_id', | |
858 | 'title' => ts($options['prefix_label'] . 'Country'), | |
859 | 'type' => CRM_Utils_Type::T_INT, | |
860 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
861 | 'options' => CRM_Core_PseudoConstant::country(), | |
862 | ), | |
863 | ); | |
864 | } | |
865 | ||
866 | if ($options['order_by']) { | |
9d72cede EM |
867 | $addressFields[$options['prefix'] . |
868 | 'civicrm_address']['order_bys'] = array( | |
6a488035 TO |
869 | $options['prefix'] . 'street_name' => array( |
870 | 'title' => ts($options['prefix_label'] . 'Street Name'), | |
871 | 'name' => 'street_name', | |
872 | ), | |
873 | $options['prefix'] . 'street_number' => array( | |
874 | 'title' => ts($options['prefix_label'] . 'Odd / Even Street Number'), | |
875 | 'name' => 'street_number', | |
876 | ), | |
877 | $options['prefix'] . 'street_address' => array( | |
878 | 'title' => ts($options['prefix_label'] . 'Street Address'), | |
879 | 'name' => 'street_address', | |
880 | ), | |
881 | $options['prefix'] . 'city' => array( | |
882 | 'title' => ts($options['prefix_label'] . 'City'), | |
883 | 'name' => 'city', | |
884 | ), | |
885 | $options['prefix'] . 'postal_code' => array( | |
886 | 'title' => ts($options['prefix_label'] . 'Post Code'), | |
887 | 'name' => 'postal_code', | |
888 | ), | |
889 | ); | |
890 | } | |
891 | ||
892 | if ($options['group_by']) { | |
893 | $addressFields['civicrm_address']['group_bys'] = array( | |
894 | $options['prefix'] . 'street_address' => array( | |
895 | 'title' => ts($options['prefix_label'] . 'Street Address'), | |
896 | 'name' => 'street_address', | |
897 | ), | |
898 | $options['prefix'] . 'city' => array( | |
899 | 'title' => ts($options['prefix_label'] . 'City'), | |
900 | 'name' => 'city', | |
901 | ), | |
902 | $options['prefix'] . 'postal_code' => array( | |
903 | 'title' => ts($options['prefix_label'] . 'Post Code'), | |
904 | 'name' => 'postal_code', | |
905 | ), | |
906 | $options['prefix'] . 'state_province_id' => array( | |
907 | 'title' => ts($options['prefix_label'] . 'State/Province'), | |
908 | 'name' => 'state_province_id', | |
909 | ), | |
910 | $options['prefix'] . 'country_id' => array( | |
911 | 'title' => ts($options['prefix_label'] . 'Country'), | |
912 | 'name' => 'country_id', | |
913 | ), | |
914 | $options['prefix'] . 'county_id' => array( | |
915 | 'title' => ts($options['prefix_label'] . 'County'), | |
916 | 'name' => 'county_id', | |
917 | ), | |
918 | ); | |
919 | } | |
920 | return $addressFields; | |
921 | } | |
922 | ||
923 | /* | |
924 | * Get Information about advertised Joins | |
925 | */ | |
74cf4551 EM |
926 | /** |
927 | * @return array | |
928 | */ | |
6a488035 TO |
929 | function getAvailableJoins() { |
930 | return array( | |
931 | 'priceFieldValue_from_lineItem' => array( | |
932 | 'leftTable' => 'civicrm_line_item', | |
933 | 'rightTable' => 'civicrm_price_field_value', | |
934 | 'callback' => 'joinPriceFieldValueFromLineItem', | |
935 | ), | |
936 | 'priceField_from_lineItem' => array( | |
937 | 'leftTable' => 'civicrm_line_item', | |
938 | 'rightTable' => 'civicrm_price_field', | |
939 | 'callback' => 'joinPriceFieldFromLineItem', | |
940 | ), | |
941 | 'participant_from_lineItem' => array( | |
942 | 'leftTable' => 'civicrm_line_item', | |
943 | 'rightTable' => 'civicrm_participant', | |
944 | 'callback' => 'joinParticipantFromLineItem', | |
945 | ), | |
946 | 'contribution_from_lineItem' => array( | |
947 | 'leftTable' => 'civicrm_line_item', | |
948 | 'rightTable' => 'civicrm_contribution', | |
949 | 'callback' => 'joinContributionFromLineItem', | |
950 | ), | |
951 | 'membership_from_lineItem' => array( | |
952 | 'leftTable' => 'civicrm_line_item', | |
953 | 'rightTable' => 'civicrm_membership', | |
954 | 'callback' => 'joinMembershipFromLineItem', | |
955 | ), | |
956 | 'contribution_from_participant' => array( | |
957 | 'leftTable' => 'civicrm_participant', | |
958 | 'rightTable' => 'civicrm_contribution', | |
959 | 'callback' => 'joinContributionFromParticipant', | |
960 | ), | |
961 | 'contribution_from_membership' => array( | |
962 | 'leftTable' => 'civicrm_membership', | |
963 | 'rightTable' => 'civicrm_contribution', | |
964 | 'callback' => 'joinContributionFromMembership', | |
965 | ), | |
966 | 'membership_from_contribution' => array( | |
967 | 'leftTable' => 'civicrm_contribution', | |
968 | 'rightTable' => 'civicrm_membership', | |
969 | 'callback' => 'joinMembershipFromContribution', | |
970 | ), | |
971 | 'membershipType_from_membership' => array( | |
972 | 'leftTable' => 'civicrm_membership', | |
973 | 'rightTable' => 'civicrm_membership_type', | |
974 | 'callback' => 'joinMembershipTypeFromMembership', | |
975 | ), | |
976 | 'lineItem_from_contribution' => array( | |
977 | 'leftTable' => 'civicrm_contribution', | |
978 | 'rightTable' => 'civicrm_line_item', | |
979 | 'callback' => 'joinLineItemFromContribution', | |
980 | ), | |
981 | 'lineItem_from_membership' => array( | |
982 | 'leftTable' => 'civicrm_membership', | |
983 | 'rightTable' => 'civicrm_line_item', | |
984 | 'callback' => 'joinLineItemFromMembership', | |
985 | ), | |
986 | 'contact_from_participant' => array( | |
987 | 'leftTable' => 'civicrm_participant', | |
988 | 'rightTable' => 'civicrm_contact', | |
989 | 'callback' => 'joinContactFromParticipant', | |
990 | ), | |
991 | 'contact_from_membership' => array( | |
992 | 'leftTable' => 'civicrm_membership', | |
993 | 'rightTable' => 'civicrm_contact', | |
994 | 'callback' => 'joinContactFromMembership', | |
995 | ), | |
996 | 'contact_from_contribution' => array( | |
997 | 'leftTable' => 'civicrm_contribution', | |
998 | 'rightTable' => 'civicrm_contact', | |
999 | 'callback' => 'joinContactFromContribution', | |
1000 | ), | |
1001 | 'event_from_participant' => array( | |
1002 | 'leftTable' => 'civicrm_participant', | |
1003 | 'rightTable' => 'civicrm_event', | |
1004 | 'callback' => 'joinEventFromParticipant', | |
1005 | ), | |
1006 | 'address_from_contact' => array( | |
1007 | 'leftTable' => 'civicrm_contact', | |
1008 | 'rightTable' => 'civicrm_address', | |
1009 | 'callback' => 'joinAddressFromContact', | |
1010 | ), | |
1011 | ); | |
1012 | } | |
1013 | ||
1014 | /* | |
1015 | * Add join from contact table to address. Prefix will be added to both tables | |
1016 | * as it's assumed you are using it to get address of a secondary contact | |
1017 | */ | |
74cf4551 EM |
1018 | /** |
1019 | * @param string $prefix | |
1020 | */ | |
9d72cede EM |
1021 | function joinAddressFromContact($prefix = '') { |
1022 | $this->_from .= " LEFT JOIN civicrm_address {$this->_aliases[$prefix . | |
1023 | 'civicrm_address']} | |
1024 | ON {$this->_aliases[$prefix . | |
1025 | 'civicrm_address']}.contact_id = {$this->_aliases[$prefix . | |
1026 | 'civicrm_contact']}.id"; | |
6a488035 TO |
1027 | } |
1028 | ||
1029 | function joinPriceFieldValueFromLineItem() { | |
1030 | $this->_from .= " LEFT JOIN civicrm_price_field_value {$this->_aliases['civicrm_price_field_value']} | |
1031 | ON {$this->_aliases['civicrm_line_item']}.price_field_value_id = {$this->_aliases['civicrm_price_field_value']}.id"; | |
1032 | } | |
1033 | ||
1034 | function joinPriceFieldFromLineItem() { | |
1035 | $this->_from .= " | |
1036 | LEFT JOIN civicrm_price_field {$this->_aliases['civicrm_price_field']} | |
1037 | ON {$this->_aliases['civicrm_line_item']}.price_field_id = {$this->_aliases['civicrm_price_field']}.id | |
1038 | "; | |
1039 | } | |
1040 | ||
1041 | /* | |
1042 | * Define join from line item table to participant table | |
1043 | */ | |
1044 | function joinParticipantFromLineItem() { | |
1045 | $this->_from .= " LEFT JOIN civicrm_participant {$this->_aliases['civicrm_participant']} | |
1046 | ON ( {$this->_aliases['civicrm_line_item']}.entity_id = {$this->_aliases['civicrm_participant']}.id | |
1047 | AND {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_participant') | |
1048 | "; | |
1049 | } | |
1050 | ||
1051 | /* | |
1052 | * Define join from line item table to Membership table. Seems to be still via contribution | |
1053 | * as the entity. Have made 'inner' to restrict does that make sense? | |
1054 | */ | |
1055 | function joinMembershipFromLineItem() { | |
1056 | $this->_from .= " INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} | |
1057 | ON ( {$this->_aliases['civicrm_line_item']}.entity_id = {$this->_aliases['civicrm_contribution']}.id | |
1058 | AND {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_contribution') | |
1059 | LEFT JOIN civicrm_membership_payment pp | |
1060 | ON {$this->_aliases['civicrm_contribution']}.id = pp.contribution_id | |
1061 | LEFT JOIN civicrm_membership {$this->_aliases['civicrm_membership']} | |
1062 | ON pp.membership_id = {$this->_aliases['civicrm_membership']}.id | |
1063 | "; | |
1064 | } | |
1065 | ||
1066 | /* | |
1067 | * Define join from Participant to Contribution table | |
1068 | */ | |
1069 | function joinContributionFromParticipant() { | |
1070 | $this->_from .= " LEFT JOIN civicrm_participant_payment pp | |
1071 | ON {$this->_aliases['civicrm_participant']}.id = pp.participant_id | |
1072 | LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} | |
1073 | ON pp.contribution_id = {$this->_aliases['civicrm_contribution']}.id | |
1074 | "; | |
1075 | } | |
1076 | ||
1077 | /* | |
1078 | * Define join from Membership to Contribution table | |
1079 | */ | |
1080 | function joinContributionFromMembership() { | |
1081 | $this->_from .= " LEFT JOIN civicrm_membership_payment pp | |
1082 | ON {$this->_aliases['civicrm_membership']}.id = pp.membership_id | |
1083 | LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} | |
1084 | ON pp.contribution_id = {$this->_aliases['civicrm_contribution']}.id | |
1085 | "; | |
1086 | } | |
1087 | ||
1088 | function joinParticipantFromContribution() { | |
1089 | $this->_from .= " LEFT JOIN civicrm_participant_payment pp | |
1090 | ON {$this->_aliases['civicrm_contribution']}.id = pp.contribution_id | |
1091 | LEFT JOIN civicrm_participant {$this->_aliases['civicrm_participant']} | |
1092 | ON pp.participant_id = {$this->_aliases['civicrm_participant']}.id"; | |
1093 | } | |
1094 | ||
1095 | function joinMembershipFromContribution() { | |
1096 | $this->_from .= " | |
1097 | LEFT JOIN civicrm_membership_payment pp | |
1098 | ON {$this->_aliases['civicrm_contribution']}.id = pp.contribution_id | |
1099 | LEFT JOIN civicrm_membership {$this->_aliases['civicrm_membership']} | |
1100 | ON pp.membership_id = {$this->_aliases['civicrm_membership']}.id"; | |
1101 | } | |
1102 | ||
1103 | function joinMembershipTypeFromMembership() { | |
1104 | $this->_from .= " | |
1105 | LEFT JOIN civicrm_membership_type {$this->_aliases['civicrm_membership_type']} | |
1106 | ON {$this->_aliases['civicrm_membership']}.membership_type_id = {$this->_aliases['civicrm_membership_type']}.id | |
1107 | "; | |
1108 | } | |
1109 | ||
1110 | function joinContributionFromLineItem() { | |
1111 | ||
1112 | // this can be stored as a temp table & indexed for more speed. Not done at this state. | |
1113 | // another option is to cache it but I haven't tried to put that code in yet (have used it before for one hour caching | |
1114 | $this->_from .= " LEFT JOIN (SELECT line_item_civireport.id as lid, contribution_civireport_direct.* | |
1115 | FROM civicrm_line_item line_item_civireport | |
1116 | LEFT JOIN civicrm_contribution contribution_civireport_direct | |
1117 | ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = contribution_civireport_direct.id AND line_item_civireport.entity_table = 'civicrm_contribution') | |
1118 | ||
1119 | ||
1120 | WHERE contribution_civireport_direct.id IS NOT NULL | |
1121 | ||
1122 | UNION SELECT line_item_civireport.id as lid, contribution_civireport.* | |
1123 | FROM civicrm_line_item line_item_civireport | |
1124 | LEFT JOIN civicrm_participant participant_civireport | |
1125 | ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = participant_civireport.id AND line_item_civireport.entity_table = 'civicrm_participant') | |
1126 | ||
1127 | LEFT JOIN civicrm_participant_payment pp | |
1128 | ON participant_civireport.id = pp.participant_id | |
1129 | LEFT JOIN civicrm_contribution contribution_civireport | |
1130 | ON pp.contribution_id = contribution_civireport.id | |
1131 | ||
1132 | UNION SELECT line_item_civireport.id as lid,contribution_civireport.* | |
1133 | FROM civicrm_line_item line_item_civireport | |
1134 | LEFT JOIN civicrm_membership membership_civireport | |
1135 | ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id =membership_civireport.id AND line_item_civireport.entity_table = 'civicrm_membership') | |
1136 | ||
1137 | LEFT JOIN civicrm_membership_payment pp | |
1138 | ON membership_civireport.id = pp.membership_id | |
1139 | LEFT JOIN civicrm_contribution contribution_civireport | |
1140 | ON pp.contribution_id = contribution_civireport.id | |
1141 | ) as {$this->_aliases['civicrm_contribution']} | |
1142 | ON {$this->_aliases['civicrm_contribution']}.lid = {$this->_aliases['civicrm_line_item']}.id | |
1143 | "; | |
1144 | } | |
1145 | ||
1146 | function joinLineItemFromContribution() { | |
1147 | ||
1148 | // this can be stored as a temp table & indexed for more speed. Not done at this stage. | |
1149 | // another option is to cache it but I haven't tried to put that code in yet (have used it before for one hour caching | |
1150 | $this->_from .= " | |
1151 | LEFT JOIN ( | |
1152 | SELECT contribution_civireport_direct.id AS contid, line_item_civireport.* | |
1153 | FROM civicrm_contribution contribution_civireport_direct | |
1154 | LEFT JOIN civicrm_line_item line_item_civireport ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = contribution_civireport_direct.id AND line_item_civireport.entity_table = 'civicrm_contribution') | |
1155 | WHERE line_item_civireport.id IS NOT NULL | |
1156 | ||
1157 | UNION | |
1158 | SELECT contribution_civireport_direct.id AS contid, line_item_civireport.* | |
1159 | FROM civicrm_contribution contribution_civireport_direct | |
1160 | LEFT JOIN civicrm_participant_payment pp ON contribution_civireport_direct.id = pp.contribution_id | |
1161 | LEFT JOIN civicrm_participant p ON pp.participant_id = p.id | |
1162 | LEFT JOIN civicrm_line_item line_item_civireport ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = p.id AND line_item_civireport.entity_table = 'civicrm_participant') | |
1163 | WHERE line_item_civireport.id IS NOT NULL | |
1164 | ||
1165 | UNION | |
1166 | ||
1167 | SELECT contribution_civireport_direct.id AS contid, line_item_civireport.* | |
1168 | FROM civicrm_contribution contribution_civireport_direct | |
1169 | LEFT JOIN civicrm_membership_payment pp ON contribution_civireport_direct.id = pp.contribution_id | |
1170 | LEFT JOIN civicrm_membership p ON pp.membership_id = p.id | |
1171 | LEFT JOIN civicrm_line_item line_item_civireport ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = p.id AND line_item_civireport.entity_table = 'civicrm_membership') | |
2f4c2f5d | 1172 | WHERE line_item_civireport.id IS NOT NULL |
6a488035 TO |
1173 | ) as {$this->_aliases['civicrm_line_item']} |
1174 | ON {$this->_aliases['civicrm_line_item']}.contid = {$this->_aliases['civicrm_contribution']}.id | |
1175 | ||
1176 | ||
1177 | "; | |
1178 | } | |
1179 | ||
1180 | function joinLineItemFromMembership() { | |
1181 | ||
1182 | // this can be stored as a temp table & indexed for more speed. Not done at this stage. | |
1183 | // another option is to cache it but I haven't tried to put that code in yet (have used it before for one hour caching | |
1184 | $this->_from .= " | |
1185 | LEFT JOIN ( | |
1186 | SELECT contribution_civireport_direct.id AS contid, line_item_civireport.* | |
1187 | FROM civicrm_contribution contribution_civireport_direct | |
1188 | LEFT JOIN civicrm_line_item line_item_civireport | |
1189 | ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = contribution_civireport_direct.id AND line_item_civireport.entity_table = 'civicrm_contribution') | |
1190 | ||
2f4c2f5d | 1191 | WHERE line_item_civireport.id IS NOT NULL |
6a488035 TO |
1192 | |
1193 | UNION | |
1194 | ||
1195 | SELECT contribution_civireport_direct.id AS contid, line_item_civireport.* | |
1196 | FROM civicrm_contribution contribution_civireport_direct | |
1197 | LEFT JOIN civicrm_membership_payment pp ON contribution_civireport_direct.id = pp.contribution_id | |
1198 | LEFT JOIN civicrm_membership p ON pp.membership_id = p.id | |
1199 | LEFT JOIN civicrm_line_item line_item_civireport ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = p.id AND line_item_civireport.entity_table = 'civicrm_membership') | |
2f4c2f5d | 1200 | WHERE line_item_civireport.id IS NOT NULL |
6a488035 TO |
1201 | ) as {$this->_aliases['civicrm_line_item']} |
1202 | ON {$this->_aliases['civicrm_line_item']}.contid = {$this->_aliases['civicrm_contribution']}.id | |
1203 | "; | |
1204 | } | |
1205 | ||
1206 | function joinContactFromParticipant() { | |
1207 | $this->_from .= " LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']} | |
1208 | ON {$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id"; | |
1209 | } | |
1210 | ||
1211 | function joinContactFromMembership() { | |
1212 | $this->_from .= " LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']} | |
1213 | ON {$this->_aliases['civicrm_membership']}.contact_id = {$this->_aliases['civicrm_contact']}.id"; | |
1214 | } | |
1215 | ||
1216 | function joinContactFromContribution() { | |
1217 | $this->_from .= " LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']} | |
1218 | ON {$this->_aliases['civicrm_contribution']}.contact_id = {$this->_aliases['civicrm_contact']}.id"; | |
1219 | } | |
1220 | ||
1221 | function joinEventFromParticipant() { | |
1222 | $this->_from .= " LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']} | |
1223 | ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND | |
1224 | ({$this->_aliases['civicrm_event']}.is_template IS NULL OR | |
1225 | {$this->_aliases['civicrm_event']}.is_template = 0)"; | |
1226 | } | |
1227 | ||
1228 | /* | |
1229 | * Retrieve text for financial type from pseudoconstant | |
1230 | */ | |
74cf4551 EM |
1231 | /** |
1232 | * @param $value | |
1233 | * @param $row | |
1234 | * | |
1235 | * @return string | |
1236 | */ | |
6a488035 | 1237 | function alterNickName($value, &$row) { |
9d72cede | 1238 | if (empty($row['civicrm_contact_id'])) { |
6a488035 TO |
1239 | return; |
1240 | } | |
1241 | $contactID = $row['civicrm_contact_id']; | |
1242 | return "<div id=contact-{$contactID} class='crm-entity'> | |
1243 | <span class='crm-editable crmf-nick_name crm-editable-enabled' data-action='create'> | |
1244 | " . $value . "</span></div>"; | |
1245 | } | |
1246 | ||
1247 | /* | |
1248 | * Retrieve text for contribution type from pseudoconstant | |
1249 | */ | |
74cf4551 EM |
1250 | /** |
1251 | * @param $value | |
1252 | * @param $row | |
1253 | * | |
1254 | * @return array|string | |
1255 | */ | |
6a488035 | 1256 | function alterContributionType($value, &$row) { |
b914f4e8 | 1257 | return is_string(CRM_Contribute_PseudoConstant::financialType($value, FALSE)) ? CRM_Contribute_PseudoConstant::financialType($value, FALSE) : ''; |
6a488035 TO |
1258 | } |
1259 | ||
1260 | /* | |
1261 | * Retrieve text for contribution status from pseudoconstant | |
1262 | */ | |
74cf4551 EM |
1263 | /** |
1264 | * @param $value | |
1265 | * @param $row | |
1266 | * | |
1267 | * @return array | |
1268 | */ | |
6a488035 TO |
1269 | function alterContributionStatus($value, &$row) { |
1270 | return CRM_Contribute_PseudoConstant::contributionStatus($value); | |
1271 | } | |
1272 | ||
1273 | /* | |
1274 | * Retrieve text for payment instrument from pseudoconstant | |
1275 | */ | |
74cf4551 EM |
1276 | /** |
1277 | * @param $value | |
1278 | * @param $row | |
1279 | * | |
1280 | * @return array | |
1281 | */ | |
6a488035 TO |
1282 | function alterEventType($value, &$row) { |
1283 | return CRM_Event_PseudoConstant::eventType($value); | |
1284 | } | |
1285 | ||
74cf4551 EM |
1286 | /** |
1287 | * @param $value | |
1288 | * @param $row | |
1289 | * | |
1290 | * @return array|string | |
1291 | */ | |
6a488035 TO |
1292 | function alterEventID($value, &$row) { |
1293 | return is_string(CRM_Event_PseudoConstant::event($value, FALSE)) ? CRM_Event_PseudoConstant::event($value, FALSE) : ''; | |
1294 | } | |
1295 | ||
74cf4551 EM |
1296 | /** |
1297 | * @param $value | |
1298 | * @param $row | |
1299 | * | |
1300 | * @return array|string | |
1301 | */ | |
6a488035 TO |
1302 | function alterMembershipTypeID($value, &$row) { |
1303 | return is_string(CRM_Member_PseudoConstant::membershipType($value, FALSE)) ? CRM_Member_PseudoConstant::membershipType($value, FALSE) : ''; | |
1304 | } | |
1305 | ||
74cf4551 EM |
1306 | /** |
1307 | * @param $value | |
1308 | * @param $row | |
1309 | * | |
1310 | * @return array|string | |
1311 | */ | |
6a488035 TO |
1312 | function alterMembershipStatusID($value, &$row) { |
1313 | return is_string(CRM_Member_PseudoConstant::membershipStatus($value, FALSE)) ? CRM_Member_PseudoConstant::membershipStatus($value, FALSE) : ''; | |
1314 | } | |
1315 | ||
74cf4551 EM |
1316 | /** |
1317 | * @param $value | |
1318 | * @param $row | |
1319 | * @param $selectedfield | |
100fef9d | 1320 | * @param string $criteriaFieldName |
74cf4551 EM |
1321 | * |
1322 | * @return array | |
1323 | */ | |
6a488035 TO |
1324 | function alterCountryID($value, &$row, $selectedfield, $criteriaFieldName) { |
1325 | $url = CRM_Utils_System::url(CRM_Utils_System::currentPath(), "reset=1&force=1&{$criteriaFieldName}_op=in&{$criteriaFieldName}_value={$value}", $this->_absoluteUrl); | |
1326 | $row[$selectedfield . '_link'] = $url; | |
9d72cede EM |
1327 | $row[$selectedfield . |
1328 | '_hover'] = ts("%1 for this country.", array(1 => $value)); | |
1329 | $countries = CRM_Core_PseudoConstant::country($value, FALSE); | |
1330 | if (!is_array($countries)) { | |
6a488035 TO |
1331 | return $countries; |
1332 | } | |
1333 | } | |
1334 | ||
74cf4551 EM |
1335 | /** |
1336 | * @param $value | |
1337 | * @param $row | |
1338 | * @param $selectedfield | |
100fef9d | 1339 | * @param string $criteriaFieldName |
74cf4551 EM |
1340 | * |
1341 | * @return array | |
1342 | */ | |
9d72cede | 1343 | function alterCountyID($value, &$row, $selectedfield, $criteriaFieldName) { |
6a488035 TO |
1344 | $url = CRM_Utils_System::url(CRM_Utils_System::currentPath(), "reset=1&force=1&{$criteriaFieldName}_op=in&{$criteriaFieldName}_value={$value}", $this->_absoluteUrl); |
1345 | $row[$selectedfield . '_link'] = $url; | |
9d72cede EM |
1346 | $row[$selectedfield . |
1347 | '_hover'] = ts("%1 for this county.", array(1 => $value)); | |
6a488035 | 1348 | $counties = CRM_Core_PseudoConstant::county($value, FALSE); |
9d72cede | 1349 | if (!is_array($counties)) { |
6a488035 TO |
1350 | return $counties; |
1351 | } | |
1352 | } | |
1353 | ||
74cf4551 EM |
1354 | /** |
1355 | * @param $value | |
1356 | * @param $row | |
1357 | * @param $selectedfield | |
100fef9d | 1358 | * @param string $criteriaFieldName |
74cf4551 EM |
1359 | * |
1360 | * @return array | |
1361 | */ | |
6a488035 TO |
1362 | function alterStateProvinceID($value, &$row, $selectedfield, $criteriaFieldName) { |
1363 | $url = CRM_Utils_System::url(CRM_Utils_System::currentPath(), "reset=1&force=1&{$criteriaFieldName}_op=in&{$criteriaFieldName}_value={$value}", $this->_absoluteUrl); | |
1364 | $row[$selectedfield . '_link'] = $url; | |
9d72cede EM |
1365 | $row[$selectedfield . |
1366 | '_hover'] = ts("%1 for this state.", array(1 => $value)); | |
6a488035 | 1367 | |
9d72cede EM |
1368 | $states = CRM_Core_PseudoConstant::stateProvince($value, FALSE); |
1369 | if (!is_array($states)) { | |
6a488035 TO |
1370 | return $states; |
1371 | } | |
1372 | } | |
1373 | ||
74cf4551 EM |
1374 | /** |
1375 | * @param $value | |
1376 | * @param $row | |
100fef9d | 1377 | * @param string $fieldname |
74cf4551 EM |
1378 | * |
1379 | * @return mixed | |
1380 | */ | |
6a488035 | 1381 | function alterContactID($value, &$row, $fieldname) { |
9d72cede EM |
1382 | $row[$fieldname . '_link'] = CRM_Utils_System::url("civicrm/contact/view", |
1383 | 'reset=1&cid=' . $value, $this->_absoluteUrl); | |
6a488035 TO |
1384 | return $value; |
1385 | } | |
1386 | ||
74cf4551 EM |
1387 | /** |
1388 | * @param $value | |
1389 | * | |
1390 | * @return array | |
1391 | */ | |
6a488035 TO |
1392 | function alterParticipantStatus($value) { |
1393 | if (empty($value)) { | |
1394 | return; | |
1395 | } | |
1396 | return CRM_Event_PseudoConstant::participantStatus($value, FALSE, 'label'); | |
1397 | } | |
1398 | ||
74cf4551 EM |
1399 | /** |
1400 | * @param $value | |
1401 | * | |
1402 | * @return string | |
1403 | */ | |
6a488035 TO |
1404 | function alterParticipantRole($value) { |
1405 | if (empty($value)) { | |
1406 | return; | |
1407 | } | |
1408 | $roles = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value); | |
1409 | $value = array(); | |
1410 | foreach ($roles as $role) { | |
1411 | $value[$role] = CRM_Event_PseudoConstant::participantRole($role, FALSE); | |
1412 | } | |
1413 | return implode(', ', $value); | |
1414 | } | |
1415 | ||
74cf4551 EM |
1416 | /** |
1417 | * @param $value | |
1418 | * | |
1419 | * @return mixed | |
1420 | */ | |
6a488035 TO |
1421 | function alterPaymentType($value) { |
1422 | $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument(); | |
1423 | return $paymentInstruments[$value]; | |
1424 | } | |
1425 | } | |
1426 |