3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * This class is used to retrieve and display a range of
36 * contacts that match the given criteria (specifically for
37 * results of advanced search options.
39 class CRM_Mailing_Selector_Event
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
42 * Array of supported links, currently null
46 public static $_links = NULL;
49 * What event type are we browsing?
55 * Should we only count distinct contacts?
58 private $_is_distinct;
61 * Which mailing are we browsing events from?
67 * Do we want events tied to a specific job?
73 * For click-through events, do we only want those from a specific url?
79 * We use desc to remind us what that column is, name is used in the tpl
83 public $_columnHeaders;
88 * @param string $event
89 * The event type (queue/delivered/open...).
90 * @param bool $distinct
91 * Count only distinct contact events?.
93 * ID of the mailing to query.
95 * ID of the job to query. If null, all jobs from $mailing are queried.
97 * If the event type is a click-through, do we want only those from a specific url?.
99 * @return \CRM_Mailing_Selector_Event
101 public function __construct($event, $distinct, $mailing, $job = NULL, $url = NULL) {
102 $this->_event_type
= $event;
103 $this->_is_distinct
= $distinct;
104 $this->_mailing_id
= $mailing;
105 $this->_job_id
= $job;
106 $this->_url_id
= $url;
110 * This method returns the links that are given for each search row.
114 public static function &links() {
115 return self
::$_links;
119 * Getter for array of the parameters required for creating pager.
122 * @param array $params
124 public function getPagerParams($action, &$params) {
125 $params['csvString'] = NULL;
126 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
127 $params['status'] = ts('%1 %%StatusMessage%%', [1 => $this->eventToTitle()]);
128 $params['buttonTop'] = 'PagerTopButton';
129 $params['buttonBottom'] = 'PagerBottomButton';
133 * Returns the column headers as an array of tuples:
134 * (name, sortName (key to the sort array))
136 * @param string $action
137 * The action being performed.
138 * @param string $output
139 * What should the result set include (web/email/csv).
142 * the column headers that need to be displayed
144 public function &getColumnHeaders($action = NULL, $output = NULL) {
145 $mailing = CRM_Mailing_BAO_Mailing
::getTableName();
147 $contact = CRM_Contact_BAO_Contact
::getTableName();
149 $email = CRM_Core_BAO_Email
::getTableName();
151 $job = CRM_Mailing_BAO_MailingJob
::getTableName();
152 if (!isset($this->_columnHeaders
)) {
154 $this->_columnHeaders
= [
156 'name' => ts('Contact'),
157 'sort' => $contact . '.sort_name',
158 'direction' => CRM_Utils_Sort
::ASCENDING
,
161 'name' => ts('Email Address'),
162 'sort' => $email . '.email',
163 'direction' => CRM_Utils_Sort
::DONTCARE
,
167 switch ($this->_event_type
) {
169 $dateSort = $job . '.start_date';
173 $this->_columnHeaders
= [
175 'name' => ts('Internal Contact ID'),
176 'sort' => $contact . '.id',
177 'direction' => CRM_Utils_Sort
::ASCENDING
,
179 ] +
$this->_columnHeaders
;
180 $dateSort = CRM_Mailing_Event_BAO_Delivered
::getTableName() . '.time_stamp';
184 $dateSort = CRM_Mailing_Event_BAO_Opened
::getTableName() . '.time_stamp';
188 $dateSort = CRM_Mailing_Event_BAO_Bounce
::getTableName() . '.time_stamp';
189 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
192 'name' => ts('Bounce Type'),
195 'name' => ts('Bounce Reason'),
202 $dateSort = CRM_Mailing_Event_BAO_Forward
::getTableName() . '.time_stamp';
204 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
207 'name' => ts('Forwarded Email'),
214 $dateSort = CRM_Mailing_Event_BAO_Reply
::getTableName() . '.time_stamp';
218 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
219 $this->_columnHeaders
= array_merge($this->_columnHeaders
, [
221 'name' => ts('Unsubscribe'),
227 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
228 $this->_columnHeaders
= array_merge($this->_columnHeaders
, [
230 'name' => ts('Opt-Out'),
236 $dateSort = CRM_Mailing_Event_BAO_TrackableURLOpen
::getTableName() . '.time_stamp';
237 $this->_columnHeaders
= array_merge($this->_columnHeaders
, [
248 $this->_columnHeaders
= array_merge($this->_columnHeaders
, [
250 'name' => ts('Date'),
252 'direction' => CRM_Utils_Sort
::DESCENDING
,
256 return $this->_columnHeaders
;
260 * Returns total number of rows for the query.
262 * @param string $action
265 * Total number of rows
267 public function getTotalCount($action) {
268 switch ($this->_event_type
) {
270 $event = new CRM_Mailing_Event_BAO_Queue();
271 $result = $event->getTotalCount($this->_mailing_id
,
277 $event = new CRM_Mailing_Event_BAO_Delivered();
278 $result = $event->getTotalCount($this->_mailing_id
,
285 $event = new CRM_Mailing_Event_BAO_Opened();
286 $result = $event->getTotalCount($this->_mailing_id
,
293 $event = new CRM_Mailing_Event_BAO_Bounce();
294 $result = $event->getTotalCount($this->_mailing_id
,
301 $event = new CRM_Mailing_Event_BAO_Forward();
302 $result = $event->getTotalCount($this->_mailing_id
,
309 $event = new CRM_Mailing_Event_BAO_Reply();
310 $result = $event->getTotalCount($this->_mailing_id
,
317 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
318 $result = $event->getTotalCount($this->_mailing_id
,
325 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
326 $result = $event->getTotalCount($this->_mailing_id
,
334 $event = new CRM_Mailing_Event_BAO_TrackableURLOpen();
335 $result = $event->getTotalCount($this->_mailing_id
,
348 * Returns all the rows in the given offset and rowCount.
350 * @param string $action
351 * The action being performed.
353 * The row number to start from.
354 * @param int $rowCount
355 * The number of rows to return.
356 * @param string $sort
357 * The sql string that describes the sort order.
358 * @param string $output
359 * What should the result set include (web/email/csv).
362 * the total number of rows for this action
364 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
365 switch ($this->_event_type
) {
367 $rows = CRM_Mailing_Event_BAO_Queue
::getRows($this->_mailing_id
,
368 $this->_job_id
, $offset, $rowCount, $sort
373 $rows = CRM_Mailing_Event_BAO_Delivered
::getRows($this->_mailing_id
,
374 $this->_job_id
, $this->_is_distinct
,
375 $offset, $rowCount, $sort
380 $rows = CRM_Mailing_Event_BAO_Opened
::getRows($this->_mailing_id
,
381 $this->_job_id
, $this->_is_distinct
,
382 $offset, $rowCount, $sort
387 $rows = CRM_Mailing_Event_BAO_Bounce
::getRows($this->_mailing_id
,
388 $this->_job_id
, $this->_is_distinct
,
389 $offset, $rowCount, $sort
394 $rows = CRM_Mailing_Event_BAO_Forward
::getRows($this->_mailing_id
,
395 $this->_job_id
, $this->_is_distinct
,
396 $offset, $rowCount, $sort
401 $rows = CRM_Mailing_Event_BAO_Reply
::getRows($this->_mailing_id
,
402 $this->_job_id
, $this->_is_distinct
,
403 $offset, $rowCount, $sort
408 $rows = CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
409 $this->_job_id
, $this->_is_distinct
,
410 $offset, $rowCount, $sort, TRUE
415 $rows = CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
416 $this->_job_id
, $this->_is_distinct
,
417 $offset, $rowCount, $sort, FALSE
422 $rows = CRM_Mailing_Event_BAO_TrackableURLOpen
::getRows(
423 $this->_mailing_id
, $this->_job_id
,
424 $this->_is_distinct
, $this->_url_id
,
425 $offset, $rowCount, $sort
435 * Name of export file.
437 * @param string $output
440 * @return string|NULL
443 public function getExportFileName($output = 'csv') {
448 * Get the title for the mailing event type.
452 public function eventToTitle() {
453 static $events = NULL;
455 if (empty($events)) {
457 'queue' => ts('Intended Recipients'),
458 'delivered' => ts('Successful Deliveries'),
459 'bounce' => ts('Bounces'),
460 'forward' => ts('Forwards'),
461 'reply' => $this->_is_distinct ?
ts('Unique Replies') : ts('Replies'),
462 'unsubscribe' => ts('Unsubscribe Requests'),
463 'optout' => ts('Opt-out Requests'),
464 'click' => $this->_is_distinct ?
ts('Unique Click-throughs') : ts('Click-throughs'),
465 'opened' => $this->_is_distinct ?
ts('Unique Tracked Opens') : ts('Total Tracked Opens'),
468 return $events[$this->_event_type
];
472 * Get the title of the event.
476 public function getTitle() {
477 return $this->eventToTitle();