Merge pull request #8615 from bsilvern/crm-18805
[civicrm-core.git] / CRM / Report / Form / Mailing / Summary.php
CommitLineData
6a488035 1<?php
6a488035
TO
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 */
35class CRM_Report_Form_Mailing_Summary extends CRM_Report_Form {
36
37 protected $_summary = NULL;
38
6a488035
TO
39 protected $_customGroupExtends = array();
40
c233c222
BS
41 protected $_add2groupSupported = FALSE;
42
6c288074 43 public $_drilldownReport = array('mailing/detail' => 'Link to Detail Report');
6a488035
TO
44
45 protected $_charts = array(
46 '' => 'Tabular',
47 'bar_3dChart' => 'Bar Chart',
48 );
49
84178120 50 public $campaignEnabled = FALSE;
baff85dd 51
74cf4551 52 /**
74cf4551
EM
53 */
54 /**
74cf4551 55 */
00be9182 56 public function __construct() {
6a488035
TO
57 $this->_columns = array();
58
59 $this->_columns['civicrm_mailing'] = array(
60 'dao' => 'CRM_Mailing_DAO_Mailing',
61 'fields' => array(
6c288074
PN
62 'id' => array(
63 'name' => 'id',
64 'title' => ts('Mailing ID'),
65 'required' => TRUE,
66 'no_display' => TRUE,
67 ),
6a488035
TO
68 'name' => array(
69 'title' => ts('Mailing Name'),
70 'required' => TRUE,
71 ),
72 'created_date' => array(
73 'title' => ts('Date Created'),
74 ),
180d3835 75 'subject' => array(
76 'title' => ts('Subject'),
77 ),
6a488035
TO
78 ),
79 'filters' => array(
80 'is_completed' => array(
81 'title' => ts('Mailing Status'),
82 'operatorType' => CRM_Report_Form::OP_SELECT,
83 'type' => CRM_Utils_Type::T_INT,
84 'options' => array(
85 0 => 'Incomplete',
86 1 => 'Complete',
87 ),
88 //'operator' => 'like',
89 'default' => 1,
90 ),
91 'mailing_name' => array(
92 'name' => 'name',
93 'title' => ts('Mailing'),
94 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
95 'type' => CRM_Utils_Type::T_STRING,
96 'options' => self::mailing_select(),
97 'operator' => 'like',
98 ),
99 ),
100 );
101
102 $this->_columns['civicrm_mailing_job'] = array(
cbe30f5a 103 'dao' => 'CRM_Mailing_DAO_MailingJob',
6a488035
TO
104 'fields' => array(
105 'start_date' => array(
106 'title' => ts('Start Date'),
107 ),
108 'end_date' => array(
109 'title' => ts('End Date'),
110 ),
111 ),
112 'filters' => array(
113 'status' => array(
114 'type' => CRM_Utils_Type::T_STRING,
115 'default' => 'Complete',
116 'no_display' => TRUE,
117 ),
118 'is_test' => array(
119 'type' => CRM_Utils_Type::T_INT,
120 'default' => 0,
121 'no_display' => TRUE,
122 ),
123 'start_date' => array(
124 'title' => ts('Start Date'),
125 'default' => 'this.year',
126 'operatorType' => CRM_Report_Form::OP_DATE,
127 'type' => CRM_Utils_Type::T_DATE,
128 ),
129 'end_date' => array(
130 'title' => ts('End Date'),
131 'default' => 'this.year',
132 'operatorType' => CRM_Report_Form::OP_DATE,
133 'type' => CRM_Utils_Type::T_DATE,
134 ),
135 ),
136 );
137
138 $this->_columns['civicrm_mailing_event_queue'] = array(
139 'dao' => 'CRM_Mailing_DAO_Mailing',
140 'fields' => array(
141 'queue_count' => array(
142 'name' => 'id',
143 'title' => ts('Intended Recipients'),
144 ),
145 ),
146 );
147
148 $this->_columns['civicrm_mailing_event_delivered'] = array(
149 'dao' => 'CRM_Mailing_DAO_Mailing',
150 'fields' => array(
151 'delivered_count' => array(
7ff385e8 152 'name' => 'event_queue_id',
6a488035
TO
153 'title' => ts('Delivered'),
154 ),
155 'accepted_rate' => array(
156 'title' => 'Accepted Rate',
157 'statistics' => array(
158 'calc' => 'PERCENTAGE',
159 'top' => 'civicrm_mailing_event_delivered.delivered_count',
160 'base' => 'civicrm_mailing_event_queue.queue_count',
161 ),
162 ),
163 ),
164 );
165
166 $this->_columns['civicrm_mailing_event_bounce'] = array(
167 'dao' => 'CRM_Mailing_DAO_Mailing',
168 'fields' => array(
169 'bounce_count' => array(
7ff385e8 170 'name' => 'event_queue_id',
6a488035
TO
171 'title' => ts('Bounce'),
172 ),
173 'bounce_rate' => array(
174 'title' => 'Bounce Rate',
175 'statistics' => array(
176 'calc' => 'PERCENTAGE',
177 'top' => 'civicrm_mailing_event_bounce.bounce_count',
178 'base' => 'civicrm_mailing_event_queue.queue_count',
179 ),
180 ),
181 ),
182 );
183
184 $this->_columns['civicrm_mailing_event_opened'] = array(
185 'dao' => 'CRM_Mailing_DAO_Mailing',
186 'fields' => array(
aa6b3363
PN
187 'unique_open_count' => array(
188 'name' => 'id',
189 'alias' => 'mailing_event_opened_civireport',
190 'dbAlias' => 'mailing_event_opened_civireport.event_queue_id',
191 'title' => ts('Unique Opens'),
192 ),
193 'unique_open_rate' => array(
194 'title' => 'Unique Open Rate',
195 'statistics' => array(
196 'calc' => 'PERCENTAGE',
197 'top' => 'civicrm_mailing_event_opened.unique_open_count',
198 'base' => 'civicrm_mailing_event_delivered.delivered_count',
199 ),
200 ),
6a488035 201 'open_count' => array(
7ff385e8 202 'name' => 'event_queue_id',
aa6b3363 203 'title' => ts('Total Opens'),
6a488035
TO
204 ),
205 'open_rate' => array(
aa6b3363 206 'title' => 'Total Open Rate',
6a488035
TO
207 'statistics' => array(
208 'calc' => 'PERCENTAGE',
209 'top' => 'civicrm_mailing_event_opened.open_count',
210 'base' => 'civicrm_mailing_event_delivered.delivered_count',
211 ),
212 ),
213 ),
214 );
215
216 $this->_columns['civicrm_mailing_event_trackable_url_open'] = array(
217 'dao' => 'CRM_Mailing_DAO_Mailing',
218 'fields' => array(
219 'click_count' => array(
7ff385e8 220 'name' => 'event_queue_id',
6a488035
TO
221 'title' => ts('Clicks'),
222 ),
223 'CTR' => array(
224 'title' => 'Click through Rate',
225 'default' => 0,
226 'statistics' => array(
227 'calc' => 'PERCENTAGE',
228 'top' => 'civicrm_mailing_event_trackable_url_open.click_count',
229 'base' => 'civicrm_mailing_event_delivered.delivered_count',
230 ),
231 ),
232 'CTO' => array(
233 'title' => 'Click to Open Rate',
234 'default' => 0,
235 'statistics' => array(
236 'calc' => 'PERCENTAGE',
237 'top' => 'civicrm_mailing_event_trackable_url_open.click_count',
238 'base' => 'civicrm_mailing_event_opened.open_count',
239 ),
240 ),
241 ),
242 );
243
244 $this->_columns['civicrm_mailing_event_unsubscribe'] = array(
245 'dao' => 'CRM_Mailing_DAO_Mailing',
246 'fields' => array(
247 'unsubscribe_count' => array(
248 'name' => 'id',
249 'title' => ts('Unsubscribe'),
aa6b3363
PN
250 'alias' => 'mailing_event_unsubscribe_civireport',
251 'dbAlias' => 'mailing_event_unsubscribe_civireport.event_queue_id',
6a488035 252 ),
a1ad2b04
PN
253 'optout_count' => array(
254 'name' => 'id',
255 'title' => ts('Opt-outs'),
256 'alias' => 'mailing_event_optout_civireport',
257 'dbAlias' => 'mailing_event_optout_civireport.event_queue_id',
258 ),
6a488035
TO
259 ),
260 );
b4dfc663
JM
261 $this->_columns['civicrm_mailing_group'] = array(
262 'dao' => 'CRM_Mailing_DAO_MailingGroup',
263 'filters' => array(
264 'entity_id' => array(
265 'title' => ts('Groups Included in Mailing'),
266 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
267 'type' => CRM_Utils_Type::T_INT,
268 'options' => CRM_Core_PseudoConstant::group(),
269 ),
270 ),
271 );
baff85dd 272 $config = CRM_Core_Config::singleton();
273 $this->campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
274 if ($this->campaignEnabled) {
275 $this->_columns['civicrm_campaign'] = array(
276 'dao' => 'CRM_Campaign_DAO_Campaign',
277 'fields' => array(
278 'title' => array(
279 'title' => ts('Campaign Name'),
280 ),
281 ),
282 'filters' => array(
283 'title' => array(
284 'type' => CRM_Utils_Type::T_STRING,
285 ),
286 ),
287 );
288 }
6a488035
TO
289 parent::__construct();
290 }
291
74cf4551
EM
292 /**
293 * @return array
294 */
00be9182 295 public function mailing_select() {
6a488035
TO
296
297 $data = array();
298
299 $mailing = new CRM_Mailing_BAO_Mailing();
300 $query = "SELECT name FROM civicrm_mailing WHERE sms_provider_id IS NULL";
301 $mailing->query($query);
302
303 while ($mailing->fetch()) {
304 $data[mysql_real_escape_string($mailing->name)] = $mailing->name;
305 }
306
307 return $data;
308 }
309
00be9182 310 public function preProcess() {
6a488035
TO
311 $this->assign('chartSupported', TRUE);
312 parent::preProcess();
313 }
314
546b78fa 315 /**
fe482240 316 * manipulate the select function to query count functions.
546b78fa 317 */
00be9182 318 public function select() {
6a488035
TO
319
320 $count_tables = array(
321 'civicrm_mailing_event_queue',
322 'civicrm_mailing_event_delivered',
323 'civicrm_mailing_event_opened',
324 'civicrm_mailing_event_bounce',
325 'civicrm_mailing_event_trackable_url_open',
326 'civicrm_mailing_event_unsubscribe',
327 );
328
329 $select = array();
330 $this->_columnHeaders = array();
331 foreach ($this->_columns as $tableName => $table) {
332 if (array_key_exists('fields', $table)) {
333 foreach ($table['fields'] as $fieldName => $field) {
8cc574cf 334 if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
6a488035
TO
335
336 # for statistics
a7488080 337 if (!empty($field['statistics'])) {
6a488035
TO
338 switch ($field['statistics']['calc']) {
339 case 'PERCENTAGE':
340 $base_table_column = explode('.', $field['statistics']['base']);
341 $top_table_column = explode('.', $field['statistics']['top']);
342
343 $select[] = "CONCAT(round(
344 count(DISTINCT {$this->_columns[$top_table_column[0]]['fields'][$top_table_column[1]]['dbAlias']}) /
345 count(DISTINCT {$this->_columns[$base_table_column[0]]['fields'][$base_table_column[1]]['dbAlias']}) * 100, 2
346 ), '%') as {$tableName}_{$fieldName}";
347 break;
348 }
349 }
350 else {
351 if (in_array($tableName, $count_tables)) {
352 $select[] = "count(DISTINCT {$field['dbAlias']}) as {$tableName}_{$fieldName}";
353 }
354 else {
355 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
356 }
357 }
358 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
359 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
360 }
361 }
362 }
363 }
364
365 $this->_select = "SELECT " . implode(', ', $select) . " ";
366 //print_r($this->_select);
367 }
368
00be9182 369 public function from() {
6a488035
TO
370
371 $this->_from = "
372 FROM civicrm_mailing {$this->_aliases['civicrm_mailing']}
373 LEFT JOIN civicrm_mailing_job {$this->_aliases['civicrm_mailing_job']}
374 ON {$this->_aliases['civicrm_mailing']}.id = {$this->_aliases['civicrm_mailing_job']}.mailing_id
375 LEFT JOIN civicrm_mailing_event_queue {$this->_aliases['civicrm_mailing_event_queue']}
376 ON {$this->_aliases['civicrm_mailing_event_queue']}.job_id = {$this->_aliases['civicrm_mailing_job']}.id
377 LEFT JOIN civicrm_mailing_event_bounce {$this->_aliases['civicrm_mailing_event_bounce']}
378 ON {$this->_aliases['civicrm_mailing_event_bounce']}.event_queue_id = {$this->_aliases['civicrm_mailing_event_queue']}.id
379 LEFT JOIN civicrm_mailing_event_delivered {$this->_aliases['civicrm_mailing_event_delivered']}
380 ON {$this->_aliases['civicrm_mailing_event_delivered']}.event_queue_id = {$this->_aliases['civicrm_mailing_event_queue']}.id
381 AND {$this->_aliases['civicrm_mailing_event_bounce']}.id IS null
382 LEFT JOIN civicrm_mailing_event_opened {$this->_aliases['civicrm_mailing_event_opened']}
383 ON {$this->_aliases['civicrm_mailing_event_opened']}.event_queue_id = {$this->_aliases['civicrm_mailing_event_queue']}.id
384 LEFT JOIN civicrm_mailing_event_trackable_url_open {$this->_aliases['civicrm_mailing_event_trackable_url_open']}
385 ON {$this->_aliases['civicrm_mailing_event_trackable_url_open']}.event_queue_id = {$this->_aliases['civicrm_mailing_event_queue']}.id
386 LEFT JOIN civicrm_mailing_event_unsubscribe {$this->_aliases['civicrm_mailing_event_unsubscribe']}
a1ad2b04
PN
387 ON {$this->_aliases['civicrm_mailing_event_unsubscribe']}.event_queue_id = {$this->_aliases['civicrm_mailing_event_queue']}.id AND {$this->_aliases['civicrm_mailing_event_unsubscribe']}.org_unsubscribe = 0
388 LEFT JOIN civicrm_mailing_event_unsubscribe mailing_event_optout_civireport
389 ON mailing_event_optout_civireport.event_queue_id = {$this->_aliases['civicrm_mailing_event_queue']}.id AND mailing_event_optout_civireport.org_unsubscribe = 1";
baff85dd 390
07ac16aa 391 if ($this->isTableSelected('civicrm_mailing_group')) {
392 $this->_from .= "
393 LEFT JOIN civicrm_mailing_group {$this->_aliases['civicrm_mailing_group']}
394 ON {$this->_aliases['civicrm_mailing_group']}.mailing_id = {$this->_aliases['civicrm_mailing']}.id";
395 }
baff85dd 396 if ($this->campaignEnabled) {
397 $this->_from .= "
398 LEFT JOIN civicrm_campaign {$this->_aliases['civicrm_campaign']}
399 ON {$this->_aliases['civicrm_campaign']}.id = {$this->_aliases['civicrm_mailing']}.campaign_id";
400 }
401
6a488035
TO
402 // need group by and order by
403
404 //print_r($this->_from);
405 }
406
00be9182 407 public function where() {
6a488035
TO
408 $clauses = array();
409 //to avoid the sms listings
410 $clauses[] = "{$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL";
411
412 foreach ($this->_columns as $tableName => $table) {
413 if (array_key_exists('filters', $table)) {
414 foreach ($table['filters'] as $fieldName => $field) {
415 $clause = NULL;
416 if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
417 $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
353ffa53
TO
418 $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
419 $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
6a488035 420
baff85dd 421 $clause = $this->dateClause($this->_aliases[$tableName] . '.' . $field['name'], $relative, $from, $to, $field['type']);
6a488035
TO
422 }
423 else {
424 $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
425
426 if ($op) {
427 if ($fieldName == 'relationship_type_id') {
428 $clause = "{$this->_aliases['civicrm_relationship']}.relationship_type_id=" . $this->relationshipId;
429 }
430 else {
431 $clause = $this->whereClause($field,
432 $op,
433 CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
434 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
435 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
436 );
437 }
438 }
439 }
440
441 if (!empty($clause)) {
442 $clauses[] = $clause;
443 }
444 }
445 }
446 }
447
448 if (empty($clauses)) {
449 $this->_where = "WHERE ( 1 )";
450 }
451 else {
452 $this->_where = "WHERE " . implode(' AND ', $clauses);
453 }
454
455 // if ( $this->_aclWhere ) {
456 // $this->_where .= " AND {$this->_aclWhere} ";
457 // }
458 }
459
00be9182 460 public function groupBy() {
6a488035
TO
461 $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_mailing']}.id";
462 }
463
00be9182 464 public function orderBy() {
6a488035
TO
465 $this->_orderBy = " ORDER BY {$this->_aliases['civicrm_mailing_job']}.end_date DESC ";
466 }
467
00be9182 468 public function postProcess() {
6a488035
TO
469
470 $this->beginPostProcess();
471
472 // get the acl clauses built before we assemble the query
473 $this->buildACLClause(CRM_Utils_Array::value('civicrm_contact', $this->_aliases));
474
475 $sql = $this->buildQuery(TRUE);
476
477 // print_r($sql);
478
479 $rows = $graphRows = array();
480 $this->buildRows($sql, $rows);
481
482 $this->formatDisplay($rows);
483 $this->doTemplateAssignment($rows);
484 $this->endPostProcess($rows);
485 }
486
74cf4551
EM
487 /**
488 * @return array
489 */
00be9182 490 public static function getChartCriteria() {
84178120 491 return array(
353ffa53
TO
492 'count' => array(
493 'civicrm_mailing_event_delivered_delivered_count' => ts('Delivered'),
6a488035 494 'civicrm_mailing_event_bounce_bounce_count' => ts('Bounce'),
aa6b3363
PN
495 'civicrm_mailing_event_opened_open_count' => ts('Total Opens'),
496 'civicrm_mailing_event_opened_unique_open_count' => ts('Unique Opens'),
6a488035
TO
497 'civicrm_mailing_event_trackable_url_open_click_count' => ts('Clicks'),
498 'civicrm_mailing_event_unsubscribe_unsubscribe_count' => ts('Unsubscribe'),
499 ),
84178120 500 'rate' => array(
353ffa53 501 'civicrm_mailing_event_delivered_accepted_rate' => ts('Accepted Rate'),
6a488035 502 'civicrm_mailing_event_bounce_bounce_rate' => ts('Bounce Rate'),
aa6b3363
PN
503 'civicrm_mailing_event_opened_open_rate' => ts('Total Open Rate'),
504 'civicrm_mailing_event_opened_unique_open_rate' => ts('Unique Open Rate'),
6a488035
TO
505 'civicrm_mailing_event_trackable_url_open_CTR' => ts('Click through Rate'),
506 'civicrm_mailing_event_trackable_url_open_CTO' => ts('Click to Open Rate'),
507 ),
508 );
509 }
510
74cf4551
EM
511 /**
512 * @param $fields
513 * @param $files
514 * @param $self
515 *
516 * @return array
517 */
6fb2b7f1 518 public static function formRule($fields, $files, $self) {
6a488035
TO
519 $errors = array();
520
a7488080 521 if (empty($fields['charts'])) {
6a488035
TO
522 return $errors;
523 }
524
b44e3f84 525 $criteria = self::getChartCriteria();
6a488035
TO
526 $isError = TRUE;
527 foreach ($fields['fields'] as $fld => $isActive) {
528 if (in_array($fld, array(
353ffa53
TO
529 'delivered_count',
530 'bounce_count',
531 'open_count',
532 'click_count',
533 'unsubscribe_count',
534 'accepted_rate',
535 'bounce_rate',
536 'open_rate',
537 'CTR',
389bcebf 538 'CTO',
36497f43 539 'unique_open_rate',
aa6b3363 540 'unique_open_count',
353ffa53 541 ))) {
6a488035
TO
542 $isError = FALSE;
543 }
544 }
545
546 if ($isError) {
353ffa53 547 $errors['_qf_default'] = ts('For Chart view, please select at least one field from %1 OR %2.', array(
b44e3f84
DS
548 1 => implode(', ', $criteria['count']),
549 2 => implode(', ', $criteria['rate']),
353ffa53 550 ));
6a488035
TO
551 }
552
553 return $errors;
554 }
555
74cf4551
EM
556 /**
557 * @param $rows
558 */
00be9182 559 public function buildChart(&$rows) {
6a488035
TO
560 if (empty($rows)) {
561 return;
562 }
563
b44e3f84 564 $criteria = self::getChartCriteria();
6a488035 565
84178120 566 $chartInfo = array(
353ffa53 567 'legend' => ts('Mail Summary'),
6a488035
TO
568 'xname' => ts('Mailing'),
569 'yname' => ts('Statistics'),
570 'xLabelAngle' => 20,
571 'tip' => array(),
572 );
573
574 $plotRate = $plotCount = TRUE;
575 foreach ($rows as $row) {
576 $chartInfo['values'][$row['civicrm_mailing_name']] = array();
577 if ($plotCount) {
b44e3f84 578 foreach ($criteria['count'] as $criteria => $label) {
6a488035
TO
579 if (isset($row[$criteria])) {
580 $chartInfo['values'][$row['civicrm_mailing_name']][$label] = $row[$criteria];
581 $chartInfo['tip'][$label] = "{$label} #val#";
582 $plotRate = FALSE;
583 }
b44e3f84
DS
584 elseif (isset($criteria['count'][$criteria])) {
585 unset($criteria['count'][$criteria]);
6a488035
TO
586 }
587 }
588 }
589 if ($plotRate) {
b44e3f84 590 foreach ($criteria['rate'] as $criteria => $label) {
6a488035
TO
591 if (isset($row[$criteria])) {
592 $chartInfo['values'][$row['civicrm_mailing_name']][$label] = $row[$criteria];
593 $chartInfo['tip'][$label] = "{$label} #val#";
594 $plotCount = FALSE;
595 }
b44e3f84
DS
596 elseif (isset($criteria['rate'][$criteria])) {
597 unset($criteria['rate'][$criteria]);
6a488035
TO
598 }
599 }
600 }
601 }
602
603 if ($plotCount) {
b44e3f84 604 $criteria = $criteria['count'];
6a488035
TO
605 }
606 else {
b44e3f84 607 $criteria = $criteria['rate'];
6a488035
TO
608 }
609
b44e3f84 610 $chartInfo['criteria'] = array_values($criteria);
6a488035
TO
611
612 // dynamically set the graph size
b44e3f84 613 $chartInfo['xSize'] = ((count($rows) * 125) + (count($rows) * count($criteria) * 40));
6a488035
TO
614
615 // build the chart.
616 CRM_Utils_OpenFlashChart::buildChart($chartInfo, $this->_params['charts']);
617 $this->assign('chartType', $this->_params['charts']);
618 }
619
74cf4551 620 /**
ced9bfed
EM
621 * Alter display of rows.
622 *
623 * Iterate through the rows retrieved via SQL and make changes for display purposes,
624 * such as rendering contacts as links.
625 *
626 * @param array $rows
627 * Rows generated by SQL, with an array for each row.
74cf4551 628 */
00be9182 629 public function alterDisplay(&$rows) {
6a488035
TO
630 $entryFound = FALSE;
631 foreach ($rows as $rowNum => $row) {
6c288074
PN
632 // CRM-16506
633 if (array_key_exists('civicrm_mailing_name', $row) &&
634 array_key_exists('civicrm_mailing_id', $row)
635 ) {
636 $rows[$rowNum]['civicrm_mailing_name_link'] = CRM_Report_Utils_Report::getNextUrl('mailing/detail',
637 'reset=1&force=1&mailing_id_op=eq&mailing_id_value=' . $row['civicrm_mailing_id'],
638 $this->_absoluteUrl, $this->_id, $this->_drilldownReport
639 );
640 $rows[$rowNum]['civicrm_mailing_name_hover'] = ts('View Mailing details for this mailing');
641 $entryFound = TRUE;
642 }
6a488035
TO
643 // skip looking further in rows, if first row itself doesn't
644 // have the column we need
645 if (!$entryFound) {
646 break;
647 }
648 }
649 }
96025800 650
6a488035 651}