3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
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 static $_links = NULL;
49 * What event type are we browsing?
54 * Should we only count distinct contacts?
56 private $_is_distinct;
59 * Which mailing are we browsing events from?
64 * Do we want events tied to a specific job?
69 * For click-through events, do we only want those from a specific url?
74 * We use desc to remind us what that column is, name is used in the tpl
78 public $_columnHeaders;
83 * @param string $event
84 * The event type (queue/delivered/open...).
85 * @param bool $distinct
86 * Count only distinct contact events?.
88 * ID of the mailing to query.
90 * ID of the job to query. If null, all jobs from $mailing are queried.
92 * If the event type is a click-through, do we want only those from a specific url?.
94 * @return \CRM_Mailing_Selector_Event
96 public function __construct($event, $distinct, $mailing, $job = NULL, $url = NULL) {
97 $this->_event_type
= $event;
98 $this->_is_distinct
= $distinct;
99 $this->_mailing_id
= $mailing;
100 $this->_job_id
= $job;
101 $this->_url_id
= $url;
105 * This method returns the links that are given for each search row.
109 public static function &links() {
110 return self
::$_links;
114 * Getter for array of the parameters required for creating pager.
117 * @param array $params
119 public function getPagerParams($action, &$params) {
120 $params['csvString'] = NULL;
121 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
122 $params['status'] = ts('%1 %%StatusMessage%%', array(1 => $this->eventToTitle()));
123 $params['buttonTop'] = 'PagerTopButton';
124 $params['buttonBottom'] = 'PagerBottomButton';
128 * Returns the column headers as an array of tuples:
129 * (name, sortName (key to the sort array))
131 * @param string $action
132 * The action being performed.
133 * @param string $output
134 * What should the result set include (web/email/csv).
137 * the column headers that need to be displayed
139 public function &getColumnHeaders($action = NULL, $output = NULL) {
140 $mailing = CRM_Mailing_BAO_Mailing
::getTableName();
142 $contact = CRM_Contact_BAO_Contact
::getTableName();
144 $email = CRM_Core_BAO_Email
::getTableName();
146 $job = CRM_Mailing_BAO_MailingJob
::getTableName();
147 if (!isset($this->_columnHeaders
)) {
149 $this->_columnHeaders
= array(
150 'sort_name' => array(
151 'name' => ts('Contact'),
152 'sort' => $contact . '.sort_name',
153 'direction' => CRM_Utils_Sort
::ASCENDING
,
156 'name' => ts('Email Address'),
157 'sort' => $email . '.email',
158 'direction' => CRM_Utils_Sort
::DONTCARE
,
162 switch ($this->_event_type
) {
164 $dateSort = $job . '.start_date';
168 $this->_columnHeaders
= array(
169 'contact_id' => array(
170 'name' => ts('Internal Contact ID'),
171 'sort' => $contact . '.id',
172 'direction' => CRM_Utils_Sort
::ASCENDING
,
174 ) +
$this->_columnHeaders
;
175 $dateSort = CRM_Mailing_Event_BAO_Delivered
::getTableName() . '.time_stamp';
179 $dateSort = CRM_Mailing_Event_BAO_Opened
::getTableName() . '.time_stamp';
183 $dateSort = CRM_Mailing_Event_BAO_Bounce
::getTableName() . '.time_stamp';
184 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
187 'name' => ts('Bounce Type'),
190 'name' => ts('Bounce Reason'),
197 $dateSort = CRM_Mailing_Event_BAO_Forward
::getTableName() . '.time_stamp';
199 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
202 'name' => ts('Forwarded Email'),
209 $dateSort = CRM_Mailing_Event_BAO_Reply
::getTableName() . '.time_stamp';
213 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
214 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
216 'name' => ts('Unsubscribe'),
222 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
223 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
225 'name' => ts('Opt-Out'),
231 $dateSort = CRM_Mailing_Event_BAO_TrackableURLOpen
::getTableName() . '.time_stamp';
232 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
243 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
245 'name' => ts('Date'),
247 'direction' => CRM_Utils_Sort
::DESCENDING
,
251 return $this->_columnHeaders
;
255 * Returns total number of rows for the query.
257 * @param string $action
260 * Total number of rows
262 public function getTotalCount($action) {
263 switch ($this->_event_type
) {
265 $event = new CRM_Mailing_Event_BAO_Queue();
266 $result = $event->getTotalCount($this->_mailing_id
,
272 $event = new CRM_Mailing_Event_BAO_Delivered();
273 $result = $event->getTotalCount($this->_mailing_id
,
280 $event = new CRM_Mailing_Event_BAO_Opened();
281 $result = $event->getTotalCount($this->_mailing_id
,
288 $event = new CRM_Mailing_Event_BAO_Bounce();
289 $result = $event->getTotalCount($this->_mailing_id
,
296 $event = new CRM_Mailing_Event_BAO_Forward();
297 $result = $event->getTotalCount($this->_mailing_id
,
304 $event = new CRM_Mailing_Event_BAO_Reply();
305 $result = $event->getTotalCount($this->_mailing_id
,
312 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
313 $result = $event->getTotalCount($this->_mailing_id
,
320 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
321 $result = $event->getTotalCount($this->_mailing_id
,
329 $event = new CRM_Mailing_Event_BAO_TrackableURLOpen();
330 $result = $event->getTotalCount($this->_mailing_id
,
343 * Returns all the rows in the given offset and rowCount.
345 * @param string $action
346 * The action being performed.
348 * The row number to start from.
349 * @param int $rowCount
350 * The number of rows to return.
351 * @param string $sort
352 * The sql string that describes the sort order.
353 * @param string $output
354 * What should the result set include (web/email/csv).
357 * the total number of rows for this action
359 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
360 switch ($this->_event_type
) {
362 $rows = CRM_Mailing_Event_BAO_Queue
::getRows($this->_mailing_id
,
363 $this->_job_id
, $offset, $rowCount, $sort
368 $rows = CRM_Mailing_Event_BAO_Delivered
::getRows($this->_mailing_id
,
369 $this->_job_id
, $this->_is_distinct
,
370 $offset, $rowCount, $sort
375 $rows = CRM_Mailing_Event_BAO_Opened
::getRows($this->_mailing_id
,
376 $this->_job_id
, $this->_is_distinct
,
377 $offset, $rowCount, $sort
382 $rows = CRM_Mailing_Event_BAO_Bounce
::getRows($this->_mailing_id
,
383 $this->_job_id
, $this->_is_distinct
,
384 $offset, $rowCount, $sort
389 $rows = CRM_Mailing_Event_BAO_Forward
::getRows($this->_mailing_id
,
390 $this->_job_id
, $this->_is_distinct
,
391 $offset, $rowCount, $sort
396 $rows = CRM_Mailing_Event_BAO_Reply
::getRows($this->_mailing_id
,
397 $this->_job_id
, $this->_is_distinct
,
398 $offset, $rowCount, $sort
403 $rows = CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
404 $this->_job_id
, $this->_is_distinct
,
405 $offset, $rowCount, $sort, TRUE
410 $rows = CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
411 $this->_job_id
, $this->_is_distinct
,
412 $offset, $rowCount, $sort, FALSE
417 $rows = CRM_Mailing_Event_BAO_TrackableURLOpen
::getRows(
418 $this->_mailing_id
, $this->_job_id
,
419 $this->_is_distinct
, $this->_url_id
,
420 $offset, $rowCount, $sort
430 * Name of export file.
432 * @param string $output
435 * @return string|NULL
438 public function getExportFileName($output = 'csv') {
443 * Get the title for the mailing event type.
447 public function eventToTitle() {
448 static $events = NULL;
450 if (empty($events)) {
452 'queue' => ts('Intended Recipients'),
453 'delivered' => ts('Successful Deliveries'),
454 'bounce' => ts('Bounces'),
455 'forward' => ts('Forwards'),
456 'reply' => $this->_is_distinct ?
ts('Unique Replies') : ts('Replies'),
457 'unsubscribe' => ts('Unsubscribe Requests'),
458 'optout' => ts('Opt-out Requests'),
459 'click' => $this->_is_distinct ?
ts('Unique Click-throughs') : ts('Click-throughs'),
460 'opened' => $this->_is_distinct ?
ts('Unique Tracked Opens') : ts('Total Tracked Opens'),
463 return $events[$this->_event_type
];
467 * Get the title of the event.
471 public function getTitle() {
472 return $this->eventToTitle();