CRM-9394
[civicrm-core.git] / CRM / Report / Form / Member / Summary.php
1 <?php
2 // $Id$
3
4 /*
5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
11 | |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
20 | |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
28 */
29
30 /**
31 *
32 * @package CRM
33 * @copyright CiviCRM LLC (c) 2004-2013
34 * $Id$
35 *
36 */
37 class CRM_Report_Form_Member_Summary extends CRM_Report_Form {
38
39 protected $_summary = NULL;
40 protected $_interval = NULL;
41 protected $_charts = array(
42 '' => 'Tabular',
43 'barChart' => 'Bar Chart',
44 'pieChart' => 'Pie Chart',
45 );
46 protected $_add2groupSupported = FALSE;
47
48 protected $_customGroupExtends = array('Membership');
49 protected $_customGroupGroupBy = FALSE;
50 public $_drilldownReport = array('member/detail' => 'Link to Detail Report');
51
52 function __construct() {
53 // UI for selecting columns to appear in the report list
54 // array conatining the columns, group_bys and filters build and provided to Form
55
56 $this->_columns = array(
57 'civicrm_membership' =>
58 array(
59 'dao' => 'CRM_Member_DAO_MembershipType',
60 'grouping' => 'member-fields',
61 'fields' =>
62 array(
63 'membership_type_id' =>
64 array(
65 'title' => 'Membership Type',
66 'required' => TRUE,
67 ),
68 ),
69 'filters' =>
70 array(
71 'join_date' =>
72 array('title' => ts('Member Since'),
73 'type' => CRM_Utils_Type::T_DATE,
74 'operatorType' => CRM_Report_Form::OP_DATE,
75 ),
76 'membership_start_date' =>
77 array(
78 'name' => 'start_date',
79 'title' => ts('Membership Start Date'),
80 'type' => CRM_Utils_Type::T_DATE,
81 'operatorType' => CRM_Report_Form::OP_DATE,
82 ),
83 'membership_end_date' =>
84 array(
85 'name' => 'end_date',
86 'title' => ts('Membership End Date'),
87 'type' => CRM_Utils_Type::T_DATE,
88 'operatorType' => CRM_Report_Form::OP_DATE,
89 ),
90 'membership_type_id' =>
91 array('title' => ts('Membership Type'),
92 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
93 'options' => CRM_Member_PseudoConstant::membershipType(),
94 ),
95 'status_id' =>
96 array('title' => ts('Membership Status'),
97 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
98 'options' => CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'),
99 ),
100 ),
101 'group_bys' =>
102 array(
103 'join_date' =>
104 array('title' => ts('Member Since'),
105 'default' => TRUE,
106 'frequency' => TRUE,
107 'chart' => TRUE,
108 'type' => 12,
109 ),
110 'membership_type_id' =>
111 array(
112 'title' => 'Membership Type',
113 'default' => TRUE,
114 'chart' => TRUE,
115 ),
116 ),
117 ),
118 'civicrm_contact' =>
119 array(
120 'dao' => 'CRM_Contact_DAO_Contact',
121 'fields' =>
122 array(
123 'contact_id' =>
124 array(
125 'no_display' => TRUE,
126 ),
127 ),
128 ),
129 'civicrm_contribution' =>
130 array(
131 'dao' => 'CRM_Contribute_DAO_Contribution',
132 'fields' =>
133 array(
134 'currency' =>
135 array('required' => TRUE,
136 'no_display' => TRUE,
137 ),
138 'total_amount' =>
139 array('title' => ts('Amount Statistics'),
140 'required' => TRUE,
141 'statistics' =>
142 array('sum' => ts('Total Payments Made'),
143 'count' => ts('Contribution Count'),
144 'avg' => ts('Average'),
145 ),
146 ),
147 ),
148 'filters' =>
149 array(
150 'currency' =>
151 array('title' => 'Currency',
152 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
153 'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
154 'default' => NULL,
155 'type' => CRM_Utils_Type::T_STRING,
156 ),
157 'contribution_status_id' =>
158 array('title' => ts('Contribution Status'),
159 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
160 'options' => CRM_Contribute_PseudoConstant::contributionStatus(),
161 ),
162 ),
163 'grouping' => 'member-fields',
164 ),
165 );
166 $this->_tagFilter = TRUE;
167 $this->_groupFilter = TRUE;
168 $this->_currencyColumn = 'civicrm_contribution_currency';
169 parent::__construct();
170 }
171
172 function select() {
173 $select = array();
174 $groupBys = FALSE;
175 $this->_columnHeaders = array();
176 $select[] = " COUNT( DISTINCT {$this->_aliases['civicrm_membership']}.id ) as civicrm_membership_member_count";
177 $select['joinDate'] = " {$this->_aliases['civicrm_membership']}.join_date as civicrm_membership_member_join_date";
178 $this->_columnHeaders["civicrm_membership_member_join_date"] = array('title' => ts('Member Since'),
179 'type' => CRM_Utils_Type::T_DATE,
180 );
181 foreach ($this->_columns as $tableName => $table) {
182 if (array_key_exists('group_bys', $table)) {
183 foreach ($table['group_bys'] as $fieldName => $field) {
184 if (CRM_Utils_Array::value($fieldName, $this->_params['group_bys'])) {
185
186 switch (CRM_Utils_Array::value($fieldName, $this->_params['group_bys_freq'])) {
187 case 'YEARWEEK':
188 $select[] = "DATE_SUB({$field['dbAlias']}, INTERVAL WEEKDAY({$field['dbAlias']}) DAY) AS {$tableName}_{$fieldName}_start";
189
190 $select[] = "YEARWEEK({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
191 $select[] = "WEEKOFYEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
192 $field['title'] = 'Week';
193 break;
194
195 case 'YEAR':
196 $select[] = "MAKEDATE(YEAR({$field['dbAlias']}), 1) AS {$tableName}_{$fieldName}_start";
197 $select[] = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
198 $select[] = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
199 $field['title'] = 'Year';
200 break;
201
202 case 'MONTH':
203 $select[] = "DATE_SUB({$field['dbAlias']}, INTERVAL (DAYOFMONTH({$field['dbAlias']})-1) DAY) as {$tableName}_{$fieldName}_start";
204 $select[] = "MONTH({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
205 $select[] = "MONTHNAME({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
206 $field['title'] = 'Month';
207 break;
208
209 case 'QUARTER':
210 $select[] = "STR_TO_DATE(CONCAT( 3 * QUARTER( {$field['dbAlias']} ) -2 , '/', '1', '/', YEAR( {$field['dbAlias']} ) ), '%m/%d/%Y') AS {$tableName}_{$fieldName}_start";
211 $select[] = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
212 $select[] = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
213 $field['title'] = 'Quarter';
214 break;
215 }
216 if (CRM_Utils_Array::value($fieldName, $this->_params['group_bys_freq'])) {
217 $this->_interval = $field['title'];
218 $this->_columnHeaders["{$tableName}_{$fieldName}_start"]['title'] = $field['title'] . ' Beginning';
219 $this->_columnHeaders["{$tableName}_{$fieldName}_start"]['type'] = $field['type'];
220 $this->_columnHeaders["{$tableName}_{$fieldName}_start"]['group_by'] = $this->_params['group_bys_freq'][$fieldName];
221
222 // just to make sure these values are transfered to rows.
223 // since we need that for calculation purpose,
224 // e.g making subtotals look nicer or graphs
225 $this->_columnHeaders["{$tableName}_{$fieldName}_interval"] = array('no_display' => TRUE);
226 $this->_columnHeaders["{$tableName}_{$fieldName}_subtotal"] = array('no_display' => TRUE);
227 }
228 $groupBys = TRUE;
229 }
230 }
231 }
232 // end of select
233
234 if (array_key_exists('fields', $table)) {
235 foreach ($table['fields'] as $fieldName => $field) {
236 if (CRM_Utils_Array::value('required', $field) ||
237 CRM_Utils_Array::value($fieldName, $this->_params['fields'])
238 ) {
239
240 // only include statistics columns if set
241 if (CRM_Utils_Array::value('statistics', $field)) {
242 $this->_statFields[] = 'civicrm_membership_member_count';
243 foreach ($field['statistics'] as $stat => $label) {
244 switch (strtolower($stat)) {
245 case 'sum':
246 $select[] = "IFNULL(SUM({$field['dbAlias']}), 0) as {$tableName}_{$fieldName}_{$stat}";
247 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
248 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
249 $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
250 break;
251
252 case 'count':
253 $select[] = "COUNT({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
254 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type::T_INT;
255 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
256 $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
257 break;
258
259 case 'avg':
260 $select[] = "IFNULL(ROUND(AVG({$field['dbAlias']}),2), 0) as {$tableName}_{$fieldName}_{$stat}";
261 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
262 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
263 $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
264 break;
265 }
266 }
267 }
268 elseif ($fieldName == 'membership_type_id') {
269 if (!CRM_Utils_Array::value('membership_type_id', $this->_params['group_bys']) &&
270 CRM_Utils_Array::value('join_date', $this->_params['group_bys'])
271 ) {
272 $select[] = "GROUP_CONCAT(DISTINCT {$field['dbAlias']} ORDER BY {$field['dbAlias']} ) as {$tableName}_{$fieldName}";
273 }
274 else {
275 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
276 }
277 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
278 $this->_columnHeaders["{$tableName}_{$fieldName}"]['operatorType'] = CRM_Utils_Array::value('operatorType', $field);
279 }
280 else {
281 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
282 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
283 $this->_columnHeaders["{$tableName}_{$fieldName}"]['operatorType'] = CRM_Utils_Array::value('operatorType', $field);
284 }
285 }
286 }
287 }
288 $this->_columnHeaders["civicrm_membership_member_count"] = array('title' => ts('Member Count'),
289 'type' => CRM_Utils_Type::T_INT,
290 );
291 }
292 //If grouping is availabled then remove join date from field
293 if ($groupBys) {
294 unset($select['joinDate']);
295 unset($this->_columnHeaders["civicrm_membership_member_join_date"]);
296 }
297 $this->_select = "SELECT " . implode(', ', $select) . " ";
298 }
299
300 function from() {
301 $this->_from = "
302 FROM civicrm_membership {$this->_aliases['civicrm_membership']}
303
304 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']} ON ( {$this->_aliases['civicrm_membership']}.contact_id = {$this->_aliases['civicrm_contact']}.id )
305
306 LEFT JOIN civicrm_membership_status
307 ON ({$this->_aliases['civicrm_membership']}.status_id = civicrm_membership_status.id )
308 LEFT JOIN civicrm_membership_payment payment
309 ON ( {$this->_aliases['civicrm_membership']}.id = payment.membership_id )
310 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
311 ON payment.contribution_id = {$this->_aliases['civicrm_contribution']}.id";
312 }
313 // end of from
314
315 function where() {
316 $clauses = array();
317 foreach ($this->_columns as $tableName => $table) {
318 if (array_key_exists('filters', $table)) {
319 foreach ($table['filters'] as $fieldName => $field) {
320 $clause = NULL;
321
322 if ($field['operatorType'] & CRM_Utils_Type::T_DATE) {
323 $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
324 $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
325 $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
326
327 if ($relative || $from || $to) {
328 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
329 }
330 }
331 else {
332 $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
333 if ($op) {
334 $clause = $this->whereClause($field,
335 $op,
336 CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
337 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
338 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
339 );
340 }
341 }
342 if (!empty($clause)) {
343 $clauses[$fieldName] = $clause;
344 }
345 }
346 }
347 }
348
349 if (!empty($clauses)) {
350 $this->_where = "WHERE {$this->_aliases['civicrm_membership']}.is_test = 0 AND " . implode(' AND ', $clauses);
351 }
352 else {
353 $this->_where = "WHERE {$this->_aliases['civicrm_membership']}.is_test = 0";
354 }
355 }
356
357 function groupBy() {
358 $this->_groupBy = "";
359 if (is_array($this->_params['group_bys']) &&
360 !empty($this->_params['group_bys'])
361 ) {
362 foreach ($this->_columns as $tableName => $table) {
363 if (array_key_exists('group_bys', $table)) {
364 foreach ($table['group_bys'] as $fieldName => $field) {
365 if (CRM_Utils_Array::value($fieldName, $this->_params['group_bys'])) {
366 if (CRM_Utils_Array::value('chart', $field)) {
367 $this->assign('chartSupported', TRUE);
368 }
369 if (CRM_Utils_Array::value('frequency', $table['group_bys'][$fieldName]) &&
370 CRM_Utils_Array::value($fieldName, $this->_params['group_bys_freq'])
371 ) {
372
373 $append = "YEAR({$field['dbAlias']}),";
374 if (in_array(strtolower($this->_params['group_bys_freq'][$fieldName]),
375 array('year')
376 )) {
377 $append = '';
378 }
379 $this->_groupBy[] = "$append {$this->_params['group_bys_freq'][$fieldName]}({$field['dbAlias']})";
380 $append = TRUE;
381 }
382 else {
383 $this->_groupBy[] = $field['dbAlias'];
384 }
385 }
386 }
387 }
388 }
389
390 $this->_rollup = ' WITH ROLLUP';
391 $this->_groupBy = 'GROUP BY ' . implode(', ', $this->_groupBy) . " {$this->_rollup} ";
392 }
393 else {
394 $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_membership']}.join_date";
395 }
396 }
397
398 function statistics(&$rows) {
399 $statistics = parent::statistics($rows);
400 $select = "
401 SELECT COUNT({$this->_aliases['civicrm_contribution']}.total_amount ) as count,
402 IFNULL(SUM({$this->_aliases['civicrm_contribution']}.total_amount ), 0) as amount,
403 IFNULL(ROUND(AVG({$this->_aliases['civicrm_contribution']}.total_amount), 2),0) as avg,
404 COUNT( DISTINCT {$this->_aliases['civicrm_membership']}.id ) as memberCount,
405 {$this->_aliases['civicrm_contribution']}.currency as currency
406 ";
407
408 $sql = "{$select} {$this->_from} {$this->_where}
409 GROUP BY {$this->_aliases['civicrm_contribution']}.currency
410 ";
411
412 $dao = CRM_Core_DAO::executeQuery($sql);
413
414 $totalAmount = $average = array();
415 $count = $memberCount = 0;
416 while ($dao->fetch()) {
417 $totalAmount[] = CRM_Utils_Money::format($dao->amount, $dao->currency)."(".$dao->count.")";
418 $average[] = CRM_Utils_Money::format($dao->avg, $dao->currency);
419 $count += $dao->count;
420 $memberCount += $dao->memberCount;
421 }
422 $statistics['counts']['amount'] = array(
423 'title' => ts('Total Amount'),
424 'value' => implode(', ', $totalAmount),
425 'type' => CRM_Utils_Type::T_STRING,
426 );
427 $statistics['counts']['count'] = array(
428 'title' => ts('Total Donations'),
429 'value' => $count,
430 );
431 $statistics['counts']['memberCount'] = array(
432 'title' => ts('Total Members'),
433 'value' => $memberCount,
434 );
435 $statistics['counts']['avg'] = array(
436 'title' => ts('Average'),
437 'value' => implode(', ', $average),
438 'type' => CRM_Utils_Type::T_STRING,
439 );
440
441 if (!(int)$statistics['counts']['amount']['value']) {
442 //if total amount is zero then hide Chart Options
443 $this->assign('chartSupported', FALSE);
444 }
445
446 return $statistics;
447 }
448
449 function postProcess() {
450 parent::postProcess();
451 }
452
453 function buildChart(&$rows) {
454 $graphRows = array();
455 $count = 0;
456 $membershipTypeValues = CRM_Member_PseudoConstant::membershipType();
457 $isMembershipType = CRM_Utils_Array::value('membership_type_id', $this->_params['group_bys']);
458 $isJoiningDate = CRM_Utils_Array::value('join_date', $this->_params['group_bys']);
459 if (CRM_Utils_Array::value('charts', $this->_params)) {
460 foreach ($rows as $key => $row) {
461 if (!($row['civicrm_membership_join_date_subtotal'] &&
462 $row['civicrm_membership_membership_type_id']
463 )) {
464 continue;
465 }
466 if ($isMembershipType) {
467 $join_date = CRM_Utils_Array::value('civicrm_membership_join_date_start', $row);
468 $displayInterval = CRM_Utils_Array::value('civicrm_membership_join_date_interval', $row);
469 if ($join_date) {
470 list($year, $month) = explode('-', $join_date);
471 }
472 if (CRM_Utils_Array::value('civicrm_membership_join_date_subtotal', $row)) {
473
474 switch ($this->_interval) {
475 case 'Month':
476 $displayRange = $displayInterval . ' ' . $year;
477 break;
478
479 case 'Quarter':
480 $displayRange = 'Quarter ' . $displayInterval . ' of ' . $year;
481 break;
482
483 case 'Week':
484 $displayRange = 'Week ' . $displayInterval . ' of ' . $year;
485 break;
486
487 case 'Year':
488 $displayRange = $year;
489 break;
490 }
491 $membershipType = $displayRange . "-" . $membershipTypeValues[$row['civicrm_membership_membership_type_id']];
492 }
493 else {
494
495 $membershipType = $membershipTypeValues[$row['civicrm_membership_membership_type_id']];
496 }
497
498 $interval[$membershipType] = $membershipType;
499 $display[$membershipType] = $row['civicrm_contribution_total_amount_sum'];
500 }
501 else {
502 $graphRows['receive_date'][] = CRM_Utils_Array::value('civicrm_membership_join_date_start', $row);
503 $graphRows[$this->_interval][] = CRM_Utils_Array::value('civicrm_membership_join_date_interval', $row);
504 $graphRows['value'][] = $row['civicrm_contribution_total_amount_sum'];
505 $count++;
506 }
507 }
508
509 // build chart.
510 if ($isMembershipType) {
511 $graphRows['value'] = $display;
512 $chartInfo = array(
513 'legend' => 'Membership Summary',
514 'xname' => 'Member Since / Member Type',
515 'yname' => 'Fees',
516 );
517 CRM_Utils_OpenFlashChart::reportChart($graphRows, $this->_params['charts'], $interval, $chartInfo);
518 }
519 else {
520 CRM_Utils_OpenFlashChart::chart($graphRows, $this->_params['charts'], $this->_interval);
521 }
522 }
523 $this->assign('chartType', $this->_params['charts']);
524 }
525
526 function alterDisplay(&$rows) {
527 // custom code to alter rows
528 $entryFound = FALSE;
529 foreach ($rows as $rowNum => $row) {
530 // make count columns point to detail report
531 if (CRM_Utils_Array::value('join_date', $this->_params['group_bys']) &&
532 CRM_Utils_Array::value('civicrm_membership_join_date_start', $row) &&
533 $row['civicrm_membership_join_date_start'] &&
534 $row['civicrm_membership_join_date_subtotal']
535 ) {
536
537 $dateStart = CRM_Utils_Date::customFormat($row['civicrm_membership_join_date_start'], '%Y%m%d');
538 $endDate = new DateTime($dateStart);
539 $dateEnd = array();
540
541 list($dateEnd['Y'], $dateEnd['M'], $dateEnd['d']) = explode(':', $endDate->format('Y:m:d'));
542
543 switch (strtolower($this->_params['group_bys_freq']['join_date'])) {
544 case 'month':
545 $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'] + 1,
546 $dateEnd['d'] - 1, $dateEnd['Y']
547 ));
548 break;
549
550 case 'year':
551 $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'],
552 $dateEnd['d'] - 1, $dateEnd['Y'] + 1
553 ));
554 break;
555
556 case 'yearweek':
557 $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'],
558 $dateEnd['d'] + 6, $dateEnd['Y']
559 ));
560 break;
561
562 case 'quarter':
563 $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'] + 3,
564 $dateEnd['d'] - 1, $dateEnd['Y']
565 ));
566 break;
567 }
568 $typeUrl = '';
569 if (CRM_Utils_Array::value('membership_type_id', $this->_params['group_bys']) &&
570 $typeID = $row['civicrm_membership_membership_type_id']
571 ) {
572 $typeUrl = "&tid_op=in&tid_value={$typeID}";
573 }
574 $statusUrl = '';
575 if (!empty($this->_params['status_id_value'])) {
576 $statusUrl = "&sid_op=in&sid_value=" . implode(",", $this->_params['status_id_value']);
577 }
578 $url = CRM_Report_Utils_Report::getNextUrl('member/detail',
579 "reset=1&force=1&join_date_from={$dateStart}&join_date_to={$dateEnd}{$typeUrl}{$statusUrl}",
580 $this->_absoluteUrl, $this->_id, $this->_drilldownReport
581 );
582 $row['civicrm_membership_join_date_start'] = CRM_Utils_Date::format($row['civicrm_membership_join_date_start']);
583 $rows[$rowNum]['civicrm_membership_join_date_start_link'] = $url;
584 $rows[$rowNum]['civicrm_membership_join_date_start_hover'] = ts("Lists Summary of Memberships for this date unit.");
585
586 $entryFound = TRUE;
587 }
588
589 // handle Membership Types
590 if (array_key_exists('civicrm_membership_membership_type_id', $row)) {
591 if ($value = $row['civicrm_membership_membership_type_id']) {
592 $value = explode(',', $value);
593 foreach ($value as $key => $id) {
594 $value[$key] = CRM_Member_PseudoConstant::membershipType($id, FALSE);
595 }
596 $rows[$rowNum]['civicrm_membership_membership_type_id'] = implode(' , ', $value);
597 }
598 $entryFound = TRUE;
599 }
600
601 // make subtotals look nicer
602 if (array_key_exists('civicrm_membership_join_date_subtotal', $row) &&
603 !$row['civicrm_membership_join_date_subtotal']
604 ) {
605 $this->fixSubTotalDisplay($rows[$rowNum], $this->_statFields);
606 $entryFound = TRUE;
607 }
608 elseif (array_key_exists('civicrm_membership_join_date_subtotal', $row) &&
609 $row['civicrm_membership_join_date_subtotal'] &&
610 !$row['civicrm_membership_membership_type_id']
611 ) {
612 $this->fixSubTotalDisplay($rows[$rowNum], $this->_statFields, FALSE);
613 $rows[$rowNum]['civicrm_membership_membership_type_id'] = '<b>SubTotal</b>';
614 $entryFound = TRUE;
615 }
616
617 // skip looking further in rows, if first row itself doesn't
618 // have the column we need
619 if (!$entryFound) {
620 break;
621 }
622 }
623 }
624 }
625