3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class is used to retrieve and display a range of
38 * contacts that match the given criteria (specifically for
39 * results of advanced search options.
42 class CRM_Mailing_Selector_Event
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
45 * Array of supported links, currenly null
49 static $_links = NULL;
52 * What event type are we browsing?
57 * Should we only count distinct contacts?
59 private $_is_distinct;
62 * Which mailing are we browsing events from?
67 * Do we want events tied to a specific job?
72 * For click-through events, do we only want those from a specific url?
77 * We use desc to remind us what that column is, name is used in the tpl
81 public $_columnHeaders;
86 * @param string $event
87 * The event type (queue/delivered/open...).
88 * @param bool $distinct
89 * Count only distinct contact events?.
91 * ID of the mailing to query.
93 * ID of the job to query. If null, all jobs from $mailing are queried.
95 * If the event type is a click-through, do we want only those from a specific url?.
97 * @return \CRM_Mailing_Selector_Event
99 public function __construct($event, $distinct, $mailing, $job = NULL, $url = NULL) {
100 $this->_event_type
= $event;
101 $this->_is_distinct
= $distinct;
102 $this->_mailing_id
= $mailing;
103 $this->_job_id
= $job;
104 $this->_url_id
= $url;
108 * This method returns the links that are given for each search row.
112 public static function &links() {
113 return self
::$_links;
117 * Getter for array of the parameters required for creating pager.
120 * @param array $params
122 public function getPagerParams($action, &$params) {
123 $params['csvString'] = NULL;
124 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
125 $params['status'] = ts('%1 %%StatusMessage%%', array(1 => $this->eventToTitle()));
126 $params['buttonTop'] = 'PagerTopButton';
127 $params['buttonBottom'] = 'PagerBottomButton';
131 * Returns the column headers as an array of tuples:
132 * (name, sortName (key to the sort array))
134 * @param string $action
135 * The action being performed.
136 * @param string $output
137 * What should the result set include (web/email/csv).
140 * the column headers that need to be displayed
142 public function &getColumnHeaders($action = NULL, $output = NULL) {
143 $mailing = CRM_Mailing_BAO_Mailing
::getTableName();
145 $contact = CRM_Contact_BAO_Contact
::getTableName();
147 $email = CRM_Core_BAO_Email
::getTableName();
149 $job = CRM_Mailing_BAO_MailingJob
::getTableName();
150 if (!isset($this->_columnHeaders
)) {
152 $this->_columnHeaders
= array(
153 'sort_name' => array(
154 'name' => ts('Contact'),
155 'sort' => $contact . '.sort_name',
156 'direction' => CRM_Utils_Sort
::ASCENDING
,
159 'name' => ts('Email Address'),
160 'sort' => $email . '.email',
161 'direction' => CRM_Utils_Sort
::DONTCARE
,
165 switch ($this->_event_type
) {
167 $dateSort = $job . '.start_date';
171 $this->_columnHeaders
= array(
172 'contact_id' => array(
173 'name' => ts('Internal Contact ID'),
174 'sort' => $contact . '.id',
175 'direction' => CRM_Utils_Sort
::ASCENDING
,
177 ) +
$this->_columnHeaders
;
178 $dateSort = CRM_Mailing_Event_BAO_Delivered
::getTableName() . '.time_stamp';
182 $dateSort = CRM_Mailing_Event_BAO_Opened
::getTableName() . '.time_stamp';
186 $dateSort = CRM_Mailing_Event_BAO_Bounce
::getTableName() . '.time_stamp';
187 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
190 'name' => ts('Bounce Type'),
193 'name' => ts('Bounce Reason'),
200 $dateSort = CRM_Mailing_Event_BAO_Forward
::getTableName() . '.time_stamp';
202 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
205 'name' => ts('Forwarded Email'),
212 $dateSort = CRM_Mailing_Event_BAO_Reply
::getTableName() . '.time_stamp';
216 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
217 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
219 'name' => ts('Unsubscribe'),
225 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
226 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
228 'name' => ts('Opt-Out'),
234 $dateSort = CRM_Mailing_Event_BAO_TrackableURLOpen
::getTableName() . '.time_stamp';
235 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
246 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
248 'name' => ts('Date'),
250 'direction' => CRM_Utils_Sort
::DESCENDING
,
254 return $this->_columnHeaders
;
258 * Returns total number of rows for the query.
263 * Total number of rows
265 public function getTotalCount($action) {
266 switch ($this->_event_type
) {
268 $event = new CRM_Mailing_Event_BAO_Queue();
269 $result = $event->getTotalCount($this->_mailing_id
,
275 $event = new CRM_Mailing_Event_BAO_Delivered();
276 $result = $event->getTotalCount($this->_mailing_id
,
283 $event = new CRM_Mailing_Event_BAO_Opened();
284 $result = $event->getTotalCount($this->_mailing_id
,
291 $event = new CRM_Mailing_Event_BAO_Bounce();
292 $result = $event->getTotalCount($this->_mailing_id
,
299 $event = new CRM_Mailing_Event_BAO_Forward();
300 $result = $event->getTotalCount($this->_mailing_id
,
307 $event = new CRM_Mailing_Event_BAO_Reply();
308 $result = $event->getTotalCount($this->_mailing_id
,
315 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
316 $result = $event->getTotalCount($this->_mailing_id
,
323 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
324 $result = $event->getTotalCount($this->_mailing_id
,
332 $event = new CRM_Mailing_Event_BAO_TrackableURLOpen();
333 $result = $event->getTotalCount($this->_mailing_id
,
346 * Returns all the rows in the given offset and rowCount.
348 * @param string $action
349 * The action being performed.
351 * The row number to start from.
352 * @param int $rowCount
353 * The number of rows to return.
354 * @param string $sort
355 * The sql string that describes the sort order.
356 * @param string $output
357 * What should the result set include (web/email/csv).
360 * the total number of rows for this action
362 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
363 switch ($this->_event_type
) {
365 $rows = CRM_Mailing_Event_BAO_Queue
::getRows($this->_mailing_id
,
366 $this->_job_id
, $offset, $rowCount, $sort
371 $rows = CRM_Mailing_Event_BAO_Delivered
::getRows($this->_mailing_id
,
372 $this->_job_id
, $this->_is_distinct
,
373 $offset, $rowCount, $sort
378 $rows = CRM_Mailing_Event_BAO_Opened
::getRows($this->_mailing_id
,
379 $this->_job_id
, $this->_is_distinct
,
380 $offset, $rowCount, $sort
385 $rows = CRM_Mailing_Event_BAO_Bounce
::getRows($this->_mailing_id
,
386 $this->_job_id
, $this->_is_distinct
,
387 $offset, $rowCount, $sort
392 $rows = CRM_Mailing_Event_BAO_Forward
::getRows($this->_mailing_id
,
393 $this->_job_id
, $this->_is_distinct
,
394 $offset, $rowCount, $sort
399 $rows = CRM_Mailing_Event_BAO_Reply
::getRows($this->_mailing_id
,
400 $this->_job_id
, $this->_is_distinct
,
401 $offset, $rowCount, $sort
406 $rows = CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
407 $this->_job_id
, $this->_is_distinct
,
408 $offset, $rowCount, $sort, TRUE
413 $rows = CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
414 $this->_job_id
, $this->_is_distinct
,
415 $offset, $rowCount, $sort, FALSE
420 $rows = CRM_Mailing_Event_BAO_TrackableURLOpen
::getRows(
421 $this->_mailing_id
, $this->_job_id
,
422 $this->_is_distinct
, $this->_url_id
,
423 $offset, $rowCount, $sort
433 * Name of export file.
435 * @param string $output
438 * @return string|NULL
441 public function getExportFileName($output = 'csv') {
445 public function eventToTitle() {
446 static $events = NULL;
448 if (empty($events)) {
450 'queue' => ts('Intended Recipients'),
451 'delivered' => ts('Successful Deliveries'),
452 'bounce' => ts('Bounces'),
453 'forward' => ts('Forwards'),
454 'reply' => $this->_is_distinct ?
ts('Unique Replies') : ts('Replies'),
455 'unsubscribe' => ts('Unsubscribe Requests'),
456 'optout' => ts('Opt-out Requests'),
457 'click' => $this->_is_distinct ?
ts('Unique Click-throughs') : ts('Click-throughs'),
458 'opened' => $this->_is_distinct ?
ts('Unique Tracked Opens') : ts('Tracked Opens'),
461 return $events[$this->_event_type
];
464 public function getTitle() {
465 return $this->eventToTitle();