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 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 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.
110 public static function &links() {
111 return self
::$_links;
115 * Getter for array of the parameters required for creating pager.
118 * @param array $params
121 public function getPagerParams($action, &$params) {
122 $params['csvString'] = NULL;
123 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
124 $params['status'] = ts('%1 %%StatusMessage%%', array(1 => $this->eventToTitle()));
125 $params['buttonTop'] = 'PagerTopButton';
126 $params['buttonBottom'] = 'PagerBottomButton';
130 * Returns the column headers as an array of tuples:
131 * (name, sortName (key to the sort array))
133 * @param string $action the action being performed
134 * @param enum $output what should the result set include (web/email/csv)
136 * @return array the column headers that need to be displayed
138 public function &getColumnHeaders($action = NULL, $output = NULL) {
139 $mailing = CRM_Mailing_BAO_Mailing
::getTableName();
141 $contact = CRM_Contact_BAO_Contact
::getTableName();
143 $email = CRM_Core_BAO_Email
::getTableName();
145 $job = CRM_Mailing_BAO_MailingJob
::getTableName();
146 if (!isset($this->_columnHeaders
)) {
148 $this->_columnHeaders
= array(
150 'name' => ts('Contact'),
151 'sort' => $contact . '.sort_name',
152 'direction' => CRM_Utils_Sort
::ASCENDING
,
155 'name' => ts('Email Address'),
156 'sort' => $email . '.email',
157 'direction' => CRM_Utils_Sort
::DONTCARE
,
161 switch ($this->_event_type
) {
163 $dateSort = $job . '.start_date';
167 $dateSort = CRM_Mailing_Event_BAO_Delivered
::getTableName() . '.time_stamp';
171 $dateSort = CRM_Mailing_Event_BAO_Opened
::getTableName() . '.time_stamp';
175 $dateSort = CRM_Mailing_Event_BAO_Bounce
::getTableName() . '.time_stamp';
176 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
179 'name' => ts('Bounce Type'),
182 'name' => ts('Bounce Reason'),
189 $dateSort = CRM_Mailing_Event_BAO_Forward
::getTableName() . '.time_stamp';
191 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
194 'name' => ts('Forwarded Email'),
201 $dateSort = CRM_Mailing_Event_BAO_Reply
::getTableName() . '.time_stamp';
205 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
206 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
208 'name' => ts('Unsubscribe'),
214 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe
::getTableName() . '.time_stamp';
215 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
217 'name' => ts('Opt-Out'),
223 $dateSort = CRM_Mailing_Event_BAO_TrackableURLOpen
::getTableName() . '.time_stamp';
224 $this->_columnHeaders
= array_merge($this->_columnHeaders
, array(
235 $this->_columnHeaders
= array_merge($this->_columnHeaders
,
238 'name' => ts('Date'),
240 'direction' => CRM_Utils_Sort
::DESCENDING
,
245 return $this->_columnHeaders
;
249 * Returns total number of rows for the query.
253 * @return int Total number of rows
255 public function getTotalCount($action) {
256 switch ($this->_event_type
) {
258 $event = new CRM_Mailing_Event_BAO_Queue();
259 return $event->getTotalCount($this->_mailing_id
,
265 $event = new CRM_Mailing_Event_BAO_Delivered();
266 return $event->getTotalCount($this->_mailing_id
,
273 $event = new CRM_Mailing_Event_BAO_Opened();
274 return $event->getTotalCount($this->_mailing_id
,
281 $event = new CRM_Mailing_Event_BAO_Bounce();
282 return $event->getTotalCount($this->_mailing_id
,
289 $event = new CRM_Mailing_Event_BAO_Forward();
290 return $event->getTotalCount($this->_mailing_id
,
297 $event = new CRM_Mailing_Event_BAO_Reply();
298 return $event->getTotalCount($this->_mailing_id
,
305 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
306 return $event->getTotalCount($this->_mailing_id
,
313 $event = new CRM_Mailing_Event_BAO_Unsubscribe();
314 return $event->getTotalCount($this->_mailing_id
,
322 $event = new CRM_Mailing_Event_BAO_TrackableURLOpen();
323 return $event->getTotalCount($this->_mailing_id
,
336 * Returns all the rows in the given offset and rowCount
338 * @param enum $action the action being performed
339 * @param int $offset the row number to start from
340 * @param int $rowCount the number of rows to return
341 * @param string $sort the sql string that describes the sort order
342 * @param enum $output what should the result set include (web/email/csv)
344 * @return int the total number of rows for this action
346 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
347 switch ($this->_event_type
) {
349 return CRM_Mailing_Event_BAO_Queue
::getRows($this->_mailing_id
,
350 $this->_job_id
, $offset, $rowCount, $sort
355 return CRM_Mailing_Event_BAO_Delivered
::getRows($this->_mailing_id
,
356 $this->_job_id
, $this->_is_distinct
,
357 $offset, $rowCount, $sort
362 return CRM_Mailing_Event_BAO_Opened
::getRows($this->_mailing_id
,
363 $this->_job_id
, $this->_is_distinct
,
364 $offset, $rowCount, $sort
369 return CRM_Mailing_Event_BAO_Bounce
::getRows($this->_mailing_id
,
370 $this->_job_id
, $this->_is_distinct
,
371 $offset, $rowCount, $sort
376 return CRM_Mailing_Event_BAO_Forward
::getRows($this->_mailing_id
,
377 $this->_job_id
, $this->_is_distinct
,
378 $offset, $rowCount, $sort
382 return CRM_Mailing_Event_BAO_Reply
::getRows($this->_mailing_id
,
383 $this->_job_id
, $this->_is_distinct
,
384 $offset, $rowCount, $sort
389 return CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
390 $this->_job_id
, $this->_is_distinct
,
391 $offset, $rowCount, $sort, TRUE
396 return CRM_Mailing_Event_BAO_Unsubscribe
::getRows($this->_mailing_id
,
397 $this->_job_id
, $this->_is_distinct
,
398 $offset, $rowCount, $sort, FALSE
403 return CRM_Mailing_Event_BAO_TrackableURLOpen
::getRows(
404 $this->_mailing_id
, $this->_job_id
,
405 $this->_is_distinct
, $this->_url_id
,
406 $offset, $rowCount, $sort
416 * Name of export file.
418 * @param string $output type of output
420 * @return string name of the file
422 public function getExportFileName($output = 'csv') {}
424 public function eventToTitle() {
425 static $events = NULL;
427 if (empty($events)) {
429 'queue' => ts('Intended Recipients'),
430 'delivered' => ts('Successful Deliveries'),
431 'bounce' => ts('Bounces'),
432 'forward' => ts('Forwards'),
433 'reply' => $this->_is_distinct
434 ?
ts('Unique Replies')
436 'unsubscribe' => ts('Unsubscribe Requests'),
437 'optout' => ts('Opt-out Requests'),
438 'click' => $this->_is_distinct
439 ?
ts('Unique Click-throughs')
440 : ts('Click-throughs'),
441 'opened' => $this->_is_distinct
442 ?
ts('Unique Tracked Opens')
443 : ts('Tracked Opens'),
446 return $events[$this->_event_type
];
449 public function getTitle() {
450 return $this->eventToTitle();