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;
106 * This method returns the links that are given for each search row.
112 static function &links() {
113 return self
::$_links;
118 * getter for array of the parameters required for creating pager.
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';
133 * returns the column headers as an array of tuples:
134 * (name, sortName (key to the sort array))
136 * @param string $action the action being performed
137 * @param enum $output what should the result set include (web/email/csv)
139 * @return array the column headers that need to be displayed
142 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(
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 $dateSort = CRM_Mailing_Event_BAO_Delivered
::getTableName() . '.time_stamp';
175 $dateSort = CRM_Mailing_Event_BAO_Opened
::getTableName() . '.time_stamp';
179 $dateSort = CRM_Mailing_Event_BAO_Bounce
::getTableName() . '.time_stamp';
180 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
183 'name' => ts('Bounce Type'),
186 'name' => ts('Bounce Reason'),
193 $dateSort = CRM_Mailing_Event_BAO_Forward
::getTableName() . '.time_stamp';
195 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
198 'name' => ts('Forwarded Email'),
205 $dateSort = CRM_Mailing_Event_BAO_Reply
::getTableName() . '.time_stamp';
209 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
210 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
212 'name' => ts('Unsubscribe'),
218 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
219 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
221 'name' => ts('Opt-Out'),
227 $dateSort = CRM_Mailing_Event_BAO_TrackableURLOpen
::getTableName() . '.time_stamp';
228 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
239 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
242 'name' => ts('Date'),
244 'direction' => CRM_Utils_Sort
::DESCENDING
,
249 return $this->_columnHeaders
;
253 * Returns total number of rows for the query.
257 * @return int Total number of rows
260 function getTotalCount($action) {
261 switch ($this->_event_type
) {
263 $event = new CRM_Mailing_Event_BAO_Queue();
264 return $event->getTotalCount($this->_mailing_id
,
270 $event = new CRM_Mailing_Event_BAO_Delivered();
271 return $event->getTotalCount($this->_mailing_id
,
278 $event = new CRM_Mailing_Event_BAO_Opened();
279 return $event->getTotalCount($this->_mailing_id
,
286 $event = new CRM_Mailing_Event_BAO_Bounce();
287 return $event->getTotalCount($this->_mailing_id
,
294 $event = new CRM_Mailing_Event_BAO_Forward();
295 return $event->getTotalCount($this->_mailing_id
,
302 $event = new CRM_Mailing_Event_BAO_Reply();
303 return $event->getTotalCount($this->_mailing_id
,
310 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
311 return $event->getTotalCount($this->_mailing_id
,
318 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
319 return $event->getTotalCount($this->_mailing_id
,
327 $event = new CRM_Mailing_Event_BAO_TrackableURLOpen();
328 return $event->getTotalCount($this->_mailing_id
,
341 * returns all the rows in the given offset and rowCount
343 * @param enum $action the action being performed
344 * @param int $offset the row number to start from
345 * @param int $rowCount the number of rows to return
346 * @param string $sort the sql string that describes the sort order
347 * @param enum $output what should the result set include (web/email/csv)
349 * @return int the total number of rows for this action
351 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
352 switch ($this->_event_type
) {
354 return CRM_Mailing_Event_BAO_Queue
::getRows($this->_mailing_id
,
355 $this->_job_id
, $offset, $rowCount, $sort
360 return CRM_Mailing_Event_BAO_Delivered
::getRows($this->_mailing_id
,
361 $this->_job_id
, $this->_is_distinct
,
362 $offset, $rowCount, $sort
367 return CRM_Mailing_Event_BAO_Opened
::getRows($this->_mailing_id
,
368 $this->_job_id
, $this->_is_distinct
,
369 $offset, $rowCount, $sort
374 return CRM_Mailing_Event_BAO_Bounce
::getRows($this->_mailing_id
,
375 $this->_job_id
, $this->_is_distinct
,
376 $offset, $rowCount, $sort
381 return CRM_Mailing_Event_BAO_Forward
::getRows($this->_mailing_id
,
382 $this->_job_id
, $this->_is_distinct
,
383 $offset, $rowCount, $sort
387 return CRM_Mailing_Event_BAO_Reply
::getRows($this->_mailing_id
,
388 $this->_job_id
, $this->_is_distinct
,
389 $offset, $rowCount, $sort
394 return CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
395 $this->_job_id
, $this->_is_distinct
,
396 $offset, $rowCount, $sort, TRUE
401 return CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
402 $this->_job_id
, $this->_is_distinct
,
403 $offset, $rowCount, $sort, FALSE
408 return CRM_Mailing_Event_BAO_TrackableURLOpen
::getRows(
409 $this->_mailing_id
, $this->_job_id
,
410 $this->_is_distinct
, $this->_url_id
,
411 $offset, $rowCount, $sort
421 * name of export file.
423 * @param string $output type of output
425 * @return string name of the file
427 function getExportFileName($output = 'csv') {}
429 function eventToTitle() {
430 static $events = NULL;
432 if (empty($events)) {
434 'queue' => ts('Intended Recipients'),
435 'delivered' => ts('Successful Deliveries'),
436 'bounce' => ts('Bounces'),
437 'forward' => ts('Forwards'),
438 'reply' => $this->_is_distinct
439 ?
ts('Unique Replies')
441 'unsubscribe' => ts('Unsubscribe Requests'),
442 'optout' => ts('Opt-out Requests'),
443 'click' => $this->_is_distinct
444 ?
ts('Unique Click-throughs')
445 : ts('Click-throughs'),
446 'opened' => $this->_is_distinct
447 ?
ts('Unique Tracked Opens')
448 : ts('Tracked Opens'),
451 return $events[$this->_event_type
];
454 function getTitle() {
455 return $this->eventToTitle();