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
50 static $_links = NULL;
53 * What event type are we browsing?
58 * Should we only count distinct contacts?
60 private $_is_distinct;
63 * Which mailing are we browsing events from?
68 * Do we want events tied to a specific job?
73 * For click-through events, do we only want those from a specific url?
78 * We use desc to remind us what that column is, name is used in the tpl
82 public $_columnHeaders;
87 * @param string $event
88 * The event type (queue/delivered/open...).
89 * @param bool $distinct
90 * Count only distinct contact events?.
92 * ID of the mailing to query.
94 * ID of the job to query. If null, all jobs from $mailing are queried.
96 * If the event type is a click-through, do we want only those from a specific url?.
98 * @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.
115 public static function &links() {
116 return self
::$_links;
120 * Getter for array of the parameters required for creating pager.
123 * @param array $params
125 public function getPagerParams($action, &$params) {
126 $params['csvString'] = NULL;
127 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
128 $params['status'] = ts('%1 %%StatusMessage%%', array(1 => $this->eventToTitle()));
129 $params['buttonTop'] = 'PagerTopButton';
130 $params['buttonBottom'] = 'PagerBottomButton';
134 * Returns the column headers as an array of tuples:
135 * (name, sortName (key to the sort array))
137 * @param string $action
138 * The action being performed.
139 * @param enum $output
140 * What should the result set include (web/email/csv).
143 * the column headers that need to be displayed
145 public function &getColumnHeaders($action = NULL, $output = NULL) {
146 $mailing = CRM_Mailing_BAO_Mailing
::getTableName();
148 $contact = CRM_Contact_BAO_Contact
::getTableName();
150 $email = CRM_Core_BAO_Email
::getTableName();
152 $job = CRM_Mailing_BAO_MailingJob
::getTableName();
153 if (!isset($this->_columnHeaders
)) {
155 $this->_columnHeaders
= array(
157 'name' => ts('Contact'),
158 'sort' => $contact . '.sort_name',
159 'direction' => CRM_Utils_Sort
::ASCENDING
,
162 'name' => ts('Email Address'),
163 'sort' => $email . '.email',
164 'direction' => CRM_Utils_Sort
::DONTCARE
,
168 switch ($this->_event_type
) {
170 $dateSort = $job . '.start_date';
174 $dateSort = CRM_Mailing_Event_BAO_Delivered
::getTableName() . '.time_stamp';
178 $dateSort = CRM_Mailing_Event_BAO_Opened
::getTableName() . '.time_stamp';
182 $dateSort = CRM_Mailing_Event_BAO_Bounce
::getTableName() . '.time_stamp';
183 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
186 'name' => ts('Bounce Type'),
189 'name' => ts('Bounce Reason'),
196 $dateSort = CRM_Mailing_Event_BAO_Forward
::getTableName() . '.time_stamp';
198 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
201 'name' => ts('Forwarded Email'),
208 $dateSort = CRM_Mailing_Event_BAO_Reply
::getTableName() . '.time_stamp';
212 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
213 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
215 'name' => ts('Unsubscribe'),
221 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
222 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
224 'name' => ts('Opt-Out'),
230 $dateSort = CRM_Mailing_Event_BAO_TrackableURLOpen
::getTableName() . '.time_stamp';
231 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
242 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
245 'name' => ts('Date'),
247 'direction' => CRM_Utils_Sort
::DESCENDING
,
252 return $this->_columnHeaders
;
256 * Returns total number of rows for the query.
261 * Total number of rows
263 public function getTotalCount($action) {
264 switch ($this->_event_type
) {
266 $event = new CRM_Mailing_Event_BAO_Queue();
267 return $event->getTotalCount($this->_mailing_id
,
273 $event = new CRM_Mailing_Event_BAO_Delivered();
274 return $event->getTotalCount($this->_mailing_id
,
281 $event = new CRM_Mailing_Event_BAO_Opened();
282 return $event->getTotalCount($this->_mailing_id
,
289 $event = new CRM_Mailing_Event_BAO_Bounce();
290 return $event->getTotalCount($this->_mailing_id
,
297 $event = new CRM_Mailing_Event_BAO_Forward();
298 return $event->getTotalCount($this->_mailing_id
,
305 $event = new CRM_Mailing_Event_BAO_Reply();
306 return $event->getTotalCount($this->_mailing_id
,
313 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
314 return $event->getTotalCount($this->_mailing_id
,
321 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
322 return $event->getTotalCount($this->_mailing_id
,
330 $event = new CRM_Mailing_Event_BAO_TrackableURLOpen();
331 return $event->getTotalCount($this->_mailing_id
,
344 * Returns all the rows in the given offset and rowCount
346 * @param enum $action
347 * The action being performed.
349 * The row number to start from.
350 * @param int $rowCount
351 * The number of rows to return.
352 * @param string $sort
353 * The sql string that describes the sort order.
354 * @param enum $output
355 * What should the result set include (web/email/csv).
358 * the total number of rows for this action
360 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
361 switch ($this->_event_type
) {
363 return CRM_Mailing_Event_BAO_Queue
::getRows($this->_mailing_id
,
364 $this->_job_id
, $offset, $rowCount, $sort
369 return CRM_Mailing_Event_BAO_Delivered
::getRows($this->_mailing_id
,
370 $this->_job_id
, $this->_is_distinct
,
371 $offset, $rowCount, $sort
376 return CRM_Mailing_Event_BAO_Opened
::getRows($this->_mailing_id
,
377 $this->_job_id
, $this->_is_distinct
,
378 $offset, $rowCount, $sort
383 return CRM_Mailing_Event_BAO_Bounce
::getRows($this->_mailing_id
,
384 $this->_job_id
, $this->_is_distinct
,
385 $offset, $rowCount, $sort
390 return CRM_Mailing_Event_BAO_Forward
::getRows($this->_mailing_id
,
391 $this->_job_id
, $this->_is_distinct
,
392 $offset, $rowCount, $sort
396 return CRM_Mailing_Event_BAO_Reply
::getRows($this->_mailing_id
,
397 $this->_job_id
, $this->_is_distinct
,
398 $offset, $rowCount, $sort
403 return CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
404 $this->_job_id
, $this->_is_distinct
,
405 $offset, $rowCount, $sort, TRUE
410 return CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
411 $this->_job_id
, $this->_is_distinct
,
412 $offset, $rowCount, $sort, FALSE
417 return 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
438 public function getExportFileName($output = 'csv') {}
440 public function eventToTitle() {
441 static $events = NULL;
443 if (empty($events)) {
445 'queue' => ts('Intended Recipients'),
446 'delivered' => ts('Successful Deliveries'),
447 'bounce' => ts('Bounces'),
448 'forward' => ts('Forwards'),
449 'reply' => $this->_is_distinct
450 ?
ts('Unique Replies')
452 'unsubscribe' => ts('Unsubscribe Requests'),
453 'optout' => ts('Opt-out Requests'),
454 'click' => $this->_is_distinct
455 ?
ts('Unique Click-throughs')
456 : ts('Click-throughs'),
457 'opened' => $this->_is_distinct
458 ?
ts('Unique Tracked Opens')
459 : ts('Tracked Opens'),
462 return $events[$this->_event_type
];
465 public function getTitle() {
466 return $this->eventToTitle();