Commit | Line | Data |
---|---|---|
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 | */ | |
35 | class 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 | ||
d1641c51 | 365 | $this->_selectClauses = $select; |
6a488035 TO |
366 | $this->_select = "SELECT " . implode(', ', $select) . " "; |
367 | //print_r($this->_select); | |
368 | } | |
369 | ||
00be9182 | 370 | public function from() { |
6a488035 TO |
371 | |
372 | $this->_from = " | |
373 | FROM civicrm_mailing {$this->_aliases['civicrm_mailing']} | |
374 | LEFT JOIN civicrm_mailing_job {$this->_aliases['civicrm_mailing_job']} | |
375 | ON {$this->_aliases['civicrm_mailing']}.id = {$this->_aliases['civicrm_mailing_job']}.mailing_id | |
376 | LEFT JOIN civicrm_mailing_event_queue {$this->_aliases['civicrm_mailing_event_queue']} | |
377 | ON {$this->_aliases['civicrm_mailing_event_queue']}.job_id = {$this->_aliases['civicrm_mailing_job']}.id | |
378 | LEFT JOIN civicrm_mailing_event_bounce {$this->_aliases['civicrm_mailing_event_bounce']} | |
379 | ON {$this->_aliases['civicrm_mailing_event_bounce']}.event_queue_id = {$this->_aliases['civicrm_mailing_event_queue']}.id | |
380 | LEFT JOIN civicrm_mailing_event_delivered {$this->_aliases['civicrm_mailing_event_delivered']} | |
381 | ON {$this->_aliases['civicrm_mailing_event_delivered']}.event_queue_id = {$this->_aliases['civicrm_mailing_event_queue']}.id | |
382 | AND {$this->_aliases['civicrm_mailing_event_bounce']}.id IS null | |
383 | LEFT JOIN civicrm_mailing_event_opened {$this->_aliases['civicrm_mailing_event_opened']} | |
384 | ON {$this->_aliases['civicrm_mailing_event_opened']}.event_queue_id = {$this->_aliases['civicrm_mailing_event_queue']}.id | |
385 | LEFT JOIN civicrm_mailing_event_trackable_url_open {$this->_aliases['civicrm_mailing_event_trackable_url_open']} | |
386 | ON {$this->_aliases['civicrm_mailing_event_trackable_url_open']}.event_queue_id = {$this->_aliases['civicrm_mailing_event_queue']}.id | |
387 | LEFT JOIN civicrm_mailing_event_unsubscribe {$this->_aliases['civicrm_mailing_event_unsubscribe']} | |
a1ad2b04 PN |
388 | 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 |
389 | LEFT JOIN civicrm_mailing_event_unsubscribe mailing_event_optout_civireport | |
390 | ON mailing_event_optout_civireport.event_queue_id = {$this->_aliases['civicrm_mailing_event_queue']}.id AND mailing_event_optout_civireport.org_unsubscribe = 1"; | |
baff85dd | 391 | |
07ac16aa | 392 | if ($this->isTableSelected('civicrm_mailing_group')) { |
393 | $this->_from .= " | |
394 | LEFT JOIN civicrm_mailing_group {$this->_aliases['civicrm_mailing_group']} | |
d1641c51 | 395 | ON {$this->_aliases['civicrm_mailing_group']}.mailing_id = {$this->_aliases['civicrm_mailing']}.id"; |
07ac16aa | 396 | } |
baff85dd | 397 | if ($this->campaignEnabled) { |
398 | $this->_from .= " | |
399 | LEFT JOIN civicrm_campaign {$this->_aliases['civicrm_campaign']} | |
400 | ON {$this->_aliases['civicrm_campaign']}.id = {$this->_aliases['civicrm_mailing']}.campaign_id"; | |
401 | } | |
402 | ||
6a488035 TO |
403 | // need group by and order by |
404 | ||
405 | //print_r($this->_from); | |
406 | } | |
407 | ||
00be9182 | 408 | public function where() { |
6a488035 TO |
409 | $clauses = array(); |
410 | //to avoid the sms listings | |
411 | $clauses[] = "{$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL"; | |
412 | ||
413 | foreach ($this->_columns as $tableName => $table) { | |
414 | if (array_key_exists('filters', $table)) { | |
415 | foreach ($table['filters'] as $fieldName => $field) { | |
416 | $clause = NULL; | |
417 | if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) { | |
418 | $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params); | |
353ffa53 TO |
419 | $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params); |
420 | $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params); | |
6a488035 | 421 | |
baff85dd | 422 | $clause = $this->dateClause($this->_aliases[$tableName] . '.' . $field['name'], $relative, $from, $to, $field['type']); |
6a488035 TO |
423 | } |
424 | else { | |
425 | $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params); | |
426 | ||
427 | if ($op) { | |
428 | if ($fieldName == 'relationship_type_id') { | |
429 | $clause = "{$this->_aliases['civicrm_relationship']}.relationship_type_id=" . $this->relationshipId; | |
430 | } | |
431 | else { | |
432 | $clause = $this->whereClause($field, | |
433 | $op, | |
434 | CRM_Utils_Array::value("{$fieldName}_value", $this->_params), | |
435 | CRM_Utils_Array::value("{$fieldName}_min", $this->_params), | |
436 | CRM_Utils_Array::value("{$fieldName}_max", $this->_params) | |
437 | ); | |
438 | } | |
439 | } | |
440 | } | |
441 | ||
442 | if (!empty($clause)) { | |
443 | $clauses[] = $clause; | |
444 | } | |
445 | } | |
446 | } | |
447 | } | |
448 | ||
449 | if (empty($clauses)) { | |
450 | $this->_where = "WHERE ( 1 )"; | |
451 | } | |
452 | else { | |
453 | $this->_where = "WHERE " . implode(' AND ', $clauses); | |
454 | } | |
455 | ||
456 | // if ( $this->_aclWhere ) { | |
457 | // $this->_where .= " AND {$this->_aclWhere} "; | |
458 | // } | |
459 | } | |
460 | ||
00be9182 | 461 | public function groupBy() { |
6a488035 | 462 | $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_mailing']}.id"; |
d1641c51 | 463 | $this->_groupBy .= CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, "{$this->_aliases['civicrm_mailing']}.id"); |
6a488035 TO |
464 | } |
465 | ||
00be9182 | 466 | public function orderBy() { |
6a488035 TO |
467 | $this->_orderBy = " ORDER BY {$this->_aliases['civicrm_mailing_job']}.end_date DESC "; |
468 | } | |
469 | ||
00be9182 | 470 | public function postProcess() { |
6a488035 TO |
471 | |
472 | $this->beginPostProcess(); | |
473 | ||
474 | // get the acl clauses built before we assemble the query | |
475 | $this->buildACLClause(CRM_Utils_Array::value('civicrm_contact', $this->_aliases)); | |
476 | ||
477 | $sql = $this->buildQuery(TRUE); | |
478 | ||
479 | // print_r($sql); | |
480 | ||
481 | $rows = $graphRows = array(); | |
482 | $this->buildRows($sql, $rows); | |
483 | ||
484 | $this->formatDisplay($rows); | |
485 | $this->doTemplateAssignment($rows); | |
486 | $this->endPostProcess($rows); | |
487 | } | |
488 | ||
74cf4551 EM |
489 | /** |
490 | * @return array | |
491 | */ | |
00be9182 | 492 | public static function getChartCriteria() { |
84178120 | 493 | return array( |
353ffa53 TO |
494 | 'count' => array( |
495 | 'civicrm_mailing_event_delivered_delivered_count' => ts('Delivered'), | |
6a488035 | 496 | 'civicrm_mailing_event_bounce_bounce_count' => ts('Bounce'), |
aa6b3363 PN |
497 | 'civicrm_mailing_event_opened_open_count' => ts('Total Opens'), |
498 | 'civicrm_mailing_event_opened_unique_open_count' => ts('Unique Opens'), | |
6a488035 TO |
499 | 'civicrm_mailing_event_trackable_url_open_click_count' => ts('Clicks'), |
500 | 'civicrm_mailing_event_unsubscribe_unsubscribe_count' => ts('Unsubscribe'), | |
501 | ), | |
84178120 | 502 | 'rate' => array( |
353ffa53 | 503 | 'civicrm_mailing_event_delivered_accepted_rate' => ts('Accepted Rate'), |
6a488035 | 504 | 'civicrm_mailing_event_bounce_bounce_rate' => ts('Bounce Rate'), |
aa6b3363 PN |
505 | 'civicrm_mailing_event_opened_open_rate' => ts('Total Open Rate'), |
506 | 'civicrm_mailing_event_opened_unique_open_rate' => ts('Unique Open Rate'), | |
6a488035 TO |
507 | 'civicrm_mailing_event_trackable_url_open_CTR' => ts('Click through Rate'), |
508 | 'civicrm_mailing_event_trackable_url_open_CTO' => ts('Click to Open Rate'), | |
509 | ), | |
510 | ); | |
511 | } | |
512 | ||
74cf4551 EM |
513 | /** |
514 | * @param $fields | |
515 | * @param $files | |
516 | * @param $self | |
517 | * | |
518 | * @return array | |
519 | */ | |
6fb2b7f1 | 520 | public static function formRule($fields, $files, $self) { |
6a488035 TO |
521 | $errors = array(); |
522 | ||
a7488080 | 523 | if (empty($fields['charts'])) { |
6a488035 TO |
524 | return $errors; |
525 | } | |
526 | ||
b44e3f84 | 527 | $criteria = self::getChartCriteria(); |
6a488035 TO |
528 | $isError = TRUE; |
529 | foreach ($fields['fields'] as $fld => $isActive) { | |
530 | if (in_array($fld, array( | |
353ffa53 TO |
531 | 'delivered_count', |
532 | 'bounce_count', | |
533 | 'open_count', | |
534 | 'click_count', | |
535 | 'unsubscribe_count', | |
536 | 'accepted_rate', | |
537 | 'bounce_rate', | |
538 | 'open_rate', | |
539 | 'CTR', | |
389bcebf | 540 | 'CTO', |
36497f43 | 541 | 'unique_open_rate', |
aa6b3363 | 542 | 'unique_open_count', |
353ffa53 | 543 | ))) { |
6a488035 TO |
544 | $isError = FALSE; |
545 | } | |
546 | } | |
547 | ||
548 | if ($isError) { | |
353ffa53 | 549 | $errors['_qf_default'] = ts('For Chart view, please select at least one field from %1 OR %2.', array( |
b44e3f84 DS |
550 | 1 => implode(', ', $criteria['count']), |
551 | 2 => implode(', ', $criteria['rate']), | |
353ffa53 | 552 | )); |
6a488035 TO |
553 | } |
554 | ||
555 | return $errors; | |
556 | } | |
557 | ||
74cf4551 EM |
558 | /** |
559 | * @param $rows | |
560 | */ | |
00be9182 | 561 | public function buildChart(&$rows) { |
6a488035 TO |
562 | if (empty($rows)) { |
563 | return; | |
564 | } | |
565 | ||
b44e3f84 | 566 | $criteria = self::getChartCriteria(); |
6a488035 | 567 | |
84178120 | 568 | $chartInfo = array( |
353ffa53 | 569 | 'legend' => ts('Mail Summary'), |
6a488035 TO |
570 | 'xname' => ts('Mailing'), |
571 | 'yname' => ts('Statistics'), | |
572 | 'xLabelAngle' => 20, | |
573 | 'tip' => array(), | |
574 | ); | |
575 | ||
576 | $plotRate = $plotCount = TRUE; | |
577 | foreach ($rows as $row) { | |
578 | $chartInfo['values'][$row['civicrm_mailing_name']] = array(); | |
579 | if ($plotCount) { | |
b44e3f84 | 580 | foreach ($criteria['count'] as $criteria => $label) { |
6a488035 TO |
581 | if (isset($row[$criteria])) { |
582 | $chartInfo['values'][$row['civicrm_mailing_name']][$label] = $row[$criteria]; | |
583 | $chartInfo['tip'][$label] = "{$label} #val#"; | |
584 | $plotRate = FALSE; | |
585 | } | |
b44e3f84 DS |
586 | elseif (isset($criteria['count'][$criteria])) { |
587 | unset($criteria['count'][$criteria]); | |
6a488035 TO |
588 | } |
589 | } | |
590 | } | |
591 | if ($plotRate) { | |
b44e3f84 | 592 | foreach ($criteria['rate'] as $criteria => $label) { |
6a488035 TO |
593 | if (isset($row[$criteria])) { |
594 | $chartInfo['values'][$row['civicrm_mailing_name']][$label] = $row[$criteria]; | |
595 | $chartInfo['tip'][$label] = "{$label} #val#"; | |
596 | $plotCount = FALSE; | |
597 | } | |
b44e3f84 DS |
598 | elseif (isset($criteria['rate'][$criteria])) { |
599 | unset($criteria['rate'][$criteria]); | |
6a488035 TO |
600 | } |
601 | } | |
602 | } | |
603 | } | |
604 | ||
605 | if ($plotCount) { | |
b44e3f84 | 606 | $criteria = $criteria['count']; |
6a488035 TO |
607 | } |
608 | else { | |
b44e3f84 | 609 | $criteria = $criteria['rate']; |
6a488035 TO |
610 | } |
611 | ||
b44e3f84 | 612 | $chartInfo['criteria'] = array_values($criteria); |
6a488035 TO |
613 | |
614 | // dynamically set the graph size | |
b44e3f84 | 615 | $chartInfo['xSize'] = ((count($rows) * 125) + (count($rows) * count($criteria) * 40)); |
6a488035 TO |
616 | |
617 | // build the chart. | |
618 | CRM_Utils_OpenFlashChart::buildChart($chartInfo, $this->_params['charts']); | |
619 | $this->assign('chartType', $this->_params['charts']); | |
620 | } | |
621 | ||
74cf4551 | 622 | /** |
ced9bfed EM |
623 | * Alter display of rows. |
624 | * | |
625 | * Iterate through the rows retrieved via SQL and make changes for display purposes, | |
626 | * such as rendering contacts as links. | |
627 | * | |
628 | * @param array $rows | |
629 | * Rows generated by SQL, with an array for each row. | |
74cf4551 | 630 | */ |
00be9182 | 631 | public function alterDisplay(&$rows) { |
6a488035 TO |
632 | $entryFound = FALSE; |
633 | foreach ($rows as $rowNum => $row) { | |
6c288074 PN |
634 | // CRM-16506 |
635 | if (array_key_exists('civicrm_mailing_name', $row) && | |
636 | array_key_exists('civicrm_mailing_id', $row) | |
637 | ) { | |
638 | $rows[$rowNum]['civicrm_mailing_name_link'] = CRM_Report_Utils_Report::getNextUrl('mailing/detail', | |
639 | 'reset=1&force=1&mailing_id_op=eq&mailing_id_value=' . $row['civicrm_mailing_id'], | |
640 | $this->_absoluteUrl, $this->_id, $this->_drilldownReport | |
641 | ); | |
642 | $rows[$rowNum]['civicrm_mailing_name_hover'] = ts('View Mailing details for this mailing'); | |
643 | $entryFound = TRUE; | |
644 | } | |
6a488035 TO |
645 | // skip looking further in rows, if first row itself doesn't |
646 | // have the column we need | |
647 | if (!$entryFound) { | |
648 | break; | |
649 | } | |
650 | } | |
651 | } | |
96025800 | 652 | |
6a488035 | 653 | } |