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