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