3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 The event type (queue/delivered/open...)
88 * @param boolean $distinct Count only distinct contact events?
89 * @param int $mailing ID of the mailing to query
90 * @param int $job ID of the job to query. If null, all jobs from $mailing are queried.
91 * @param int $url If the event type is a click-through, do we want only those from a specific url?
93 * @return \CRM_Mailing_Selector_Event
96 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.
111 static function &links() {
112 return self
::$_links;
116 * Getter for array of the parameters required for creating pager.
119 * @param array $params
123 function getPagerParams($action, &$params) {
124 $params['csvString'] = NULL;
125 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
126 $params['status'] = ts('%1 %%StatusMessage%%', array(1 => $this->eventToTitle()));
127 $params['buttonTop'] = 'PagerTopButton';
128 $params['buttonBottom'] = 'PagerBottomButton';
132 * Returns the column headers as an array of tuples:
133 * (name, sortName (key to the sort array))
135 * @param string $action the action being performed
136 * @param enum $output what should the result set include (web/email/csv)
138 * @return array the column headers that need to be displayed
141 function &getColumnHeaders($action = NULL, $output = NULL) {
142 $mailing = CRM_Mailing_BAO_Mailing
::getTableName();
144 $contact = CRM_Contact_BAO_Contact
::getTableName();
146 $email = CRM_Core_BAO_Email
::getTableName();
148 $job = CRM_Mailing_BAO_MailingJob
::getTableName();
149 if (!isset($this->_columnHeaders
)) {
151 $this->_columnHeaders
= array(
153 'name' => ts('Contact'),
154 'sort' => $contact . '.sort_name',
155 'direction' => CRM_Utils_Sort
::ASCENDING
,
158 'name' => ts('Email Address'),
159 'sort' => $email . '.email',
160 'direction' => CRM_Utils_Sort
::DONTCARE
,
164 switch ($this->_event_type
) {
166 $dateSort = $job . '.start_date';
170 $dateSort = CRM_Mailing_Event_BAO_Delivered
::getTableName() . '.time_stamp';
174 $dateSort = CRM_Mailing_Event_BAO_Opened
::getTableName() . '.time_stamp';
178 $dateSort = CRM_Mailing_Event_BAO_Bounce
::getTableName() . '.time_stamp';
179 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
182 'name' => ts('Bounce Type'),
185 'name' => ts('Bounce Reason'),
192 $dateSort = CRM_Mailing_Event_BAO_Forward
::getTableName() . '.time_stamp';
194 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
197 'name' => ts('Forwarded Email'),
204 $dateSort = CRM_Mailing_Event_BAO_Reply
::getTableName() . '.time_stamp';
208 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
209 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
211 'name' => ts('Unsubscribe'),
217 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
218 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
220 'name' => ts('Opt-Out'),
226 $dateSort = CRM_Mailing_Event_BAO_TrackableURLOpen
::getTableName() . '.time_stamp';
227 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
238 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
241 'name' => ts('Date'),
243 'direction' => CRM_Utils_Sort
::DESCENDING
,
248 return $this->_columnHeaders
;
252 * Returns total number of rows for the query.
256 * @return int Total number of rows
259 function getTotalCount($action) {
260 switch ($this->_event_type
) {
262 $event = new CRM_Mailing_Event_BAO_Queue();
263 return $event->getTotalCount($this->_mailing_id
,
269 $event = new CRM_Mailing_Event_BAO_Delivered();
270 return $event->getTotalCount($this->_mailing_id
,
277 $event = new CRM_Mailing_Event_BAO_Opened();
278 return $event->getTotalCount($this->_mailing_id
,
285 $event = new CRM_Mailing_Event_BAO_Bounce();
286 return $event->getTotalCount($this->_mailing_id
,
293 $event = new CRM_Mailing_Event_BAO_Forward();
294 return $event->getTotalCount($this->_mailing_id
,
301 $event = new CRM_Mailing_Event_BAO_Reply();
302 return $event->getTotalCount($this->_mailing_id
,
309 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
310 return $event->getTotalCount($this->_mailing_id
,
317 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
318 return $event->getTotalCount($this->_mailing_id
,
326 $event = new CRM_Mailing_Event_BAO_TrackableURLOpen();
327 return $event->getTotalCount($this->_mailing_id
,
340 * Returns all the rows in the given offset and rowCount
342 * @param enum $action the action being performed
343 * @param int $offset the row number to start from
344 * @param int $rowCount the number of rows to return
345 * @param string $sort the sql string that describes the sort order
346 * @param enum $output what should the result set include (web/email/csv)
348 * @return int the total number of rows for this action
350 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
351 switch ($this->_event_type
) {
353 return CRM_Mailing_Event_BAO_Queue
::getRows($this->_mailing_id
,
354 $this->_job_id
, $offset, $rowCount, $sort
359 return CRM_Mailing_Event_BAO_Delivered
::getRows($this->_mailing_id
,
360 $this->_job_id
, $this->_is_distinct
,
361 $offset, $rowCount, $sort
366 return CRM_Mailing_Event_BAO_Opened
::getRows($this->_mailing_id
,
367 $this->_job_id
, $this->_is_distinct
,
368 $offset, $rowCount, $sort
373 return CRM_Mailing_Event_BAO_Bounce
::getRows($this->_mailing_id
,
374 $this->_job_id
, $this->_is_distinct
,
375 $offset, $rowCount, $sort
380 return CRM_Mailing_Event_BAO_Forward
::getRows($this->_mailing_id
,
381 $this->_job_id
, $this->_is_distinct
,
382 $offset, $rowCount, $sort
386 return CRM_Mailing_Event_BAO_Reply
::getRows($this->_mailing_id
,
387 $this->_job_id
, $this->_is_distinct
,
388 $offset, $rowCount, $sort
393 return CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
394 $this->_job_id
, $this->_is_distinct
,
395 $offset, $rowCount, $sort, TRUE
400 return CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
401 $this->_job_id
, $this->_is_distinct
,
402 $offset, $rowCount, $sort, FALSE
407 return CRM_Mailing_Event_BAO_TrackableURLOpen
::getRows(
408 $this->_mailing_id
, $this->_job_id
,
409 $this->_is_distinct
, $this->_url_id
,
410 $offset, $rowCount, $sort
420 * Name of export file.
422 * @param string $output type of output
424 * @return string name of the file
426 function getExportFileName($output = 'csv') {}
428 function eventToTitle() {
429 static $events = NULL;
431 if (empty($events)) {
433 'queue' => ts('Intended Recipients'),
434 'delivered' => ts('Successful Deliveries'),
435 'bounce' => ts('Bounces'),
436 'forward' => ts('Forwards'),
437 'reply' => $this->_is_distinct
438 ?
ts('Unique Replies')
440 'unsubscribe' => ts('Unsubscribe Requests'),
441 'optout' => ts('Opt-out Requests'),
442 'click' => $this->_is_distinct
443 ?
ts('Unique Click-throughs')
444 : ts('Click-throughs'),
445 'opened' => $this->_is_distinct
446 ?
ts('Unique Tracked Opens')
447 : ts('Tracked Opens'),
450 return $events[$this->_event_type
];
453 function getTitle() {
454 return $this->eventToTitle();