Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
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. | |
40 | * | |
41 | */ | |
42 | class CRM_Mailing_Selector_Event extends CRM_Core_Selector_Base implements CRM_Core_Selector_API { | |
43 | ||
44 | /** | |
45 | * array of supported links, currenly null | |
46 | * | |
47 | * @var array | |
48 | * @static | |
49 | */ | |
50 | static $_links = NULL; | |
51 | ||
52 | /** | |
53 | * what event type are we browsing? | |
54 | */ | |
55 | private $_event; | |
56 | ||
57 | /** | |
58 | * should we only count distinct contacts? | |
59 | */ | |
60 | private $_is_distinct; | |
61 | ||
62 | /** | |
63 | * which mailing are we browsing events from? | |
64 | */ | |
65 | private $_mailing_id; | |
66 | ||
67 | /** | |
68 | * do we want events tied to a specific job? | |
69 | */ | |
70 | private $_job_id; | |
71 | ||
72 | /** | |
73 | * for click-through events, do we only want those from a specific url? | |
74 | */ | |
75 | private $_url_id; | |
76 | ||
77 | /** | |
78 | * we use desc to remind us what that column is, name is used in the tpl | |
79 | * | |
80 | * @var array | |
81 | */ | |
82 | public $_columnHeaders; | |
83 | ||
84 | /** | |
85 | * Class constructor | |
86 | * | |
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? | |
92 | * | |
93 | * @return CRM_Contact_Selector_Profile | |
94 | * @access public | |
95 | */ | |
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; | |
102 | } | |
103 | //end of constructor | |
104 | ||
105 | /** | |
106 | * This method returns the links that are given for each search row. | |
107 | * | |
108 | * @return array | |
109 | * @access public | |
110 | * @static | |
111 | */ | |
112 | static function &links() { | |
113 | return self::$_links; | |
114 | } | |
115 | //end of function | |
116 | ||
117 | /** | |
118 | * getter for array of the parameters required for creating pager. | |
119 | * | |
120 | * @param | |
121 | * @access public | |
122 | */ | |
123 | function getPagerParams($action, &$params) { | |
124 | $params['csvString'] = NULL; | |
125 | $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; | |
10a5be27 | 126 | $params['status'] = ts('%1 %%StatusMessage%%', array(1 => $this->eventToTitle())); |
6a488035 TO |
127 | $params['buttonTop'] = 'PagerTopButton'; |
128 | $params['buttonBottom'] = 'PagerBottomButton'; | |
129 | } | |
130 | //end of function | |
131 | ||
132 | /** | |
133 | * returns the column headers as an array of tuples: | |
134 | * (name, sortName (key to the sort array)) | |
135 | * | |
136 | * @param string $action the action being performed | |
137 | * @param enum $output what should the result set include (web/email/csv) | |
138 | * | |
139 | * @return array the column headers that need to be displayed | |
140 | * @access public | |
141 | */ | |
142 | function &getColumnHeaders($action = NULL, $output = NULL) { | |
143 | $mailing = CRM_Mailing_BAO_Mailing::getTableName(); | |
144 | ||
145 | $contact = CRM_Contact_BAO_Contact::getTableName(); | |
146 | ||
147 | $email = CRM_Core_BAO_Email::getTableName(); | |
148 | ||
9da8dc8c | 149 | $job = CRM_Mailing_BAO_MailingJob::getTableName(); |
6a488035 TO |
150 | if (!isset($this->_columnHeaders)) { |
151 | ||
152 | $this->_columnHeaders = array( | |
153 | array( | |
154 | 'name' => ts('Contact'), | |
155 | 'sort' => $contact . '.sort_name', | |
156 | 'direction' => CRM_Utils_Sort::ASCENDING, | |
157 | ), | |
158 | array( | |
159 | 'name' => ts('Email Address'), | |
160 | 'sort' => $email . '.email', | |
161 | 'direction' => CRM_Utils_Sort::DONTCARE, | |
162 | ), | |
163 | ); | |
164 | ||
165 | switch ($this->_event_type) { | |
166 | case 'queue': | |
167 | $dateSort = $job . '.start_date'; | |
168 | break; | |
169 | ||
170 | case 'delivered': | |
171 | $dateSort = CRM_Mailing_Event_BAO_Delivered::getTableName() . '.time_stamp'; | |
172 | break; | |
173 | ||
174 | case 'opened': | |
175 | $dateSort = CRM_Mailing_Event_BAO_Opened::getTableName() . '.time_stamp'; | |
176 | break; | |
177 | ||
178 | case 'bounce': | |
179 | $dateSort = CRM_Mailing_Event_BAO_Bounce::getTableName() . '.time_stamp'; | |
180 | $this->_columnHeaders = array_merge($this->_columnHeaders, | |
181 | array( | |
182 | array( | |
183 | 'name' => ts('Bounce Type'), | |
184 | ), | |
185 | array( | |
186 | 'name' => ts('Bounce Reason'), | |
187 | ), | |
188 | ) | |
189 | ); | |
190 | break; | |
191 | ||
192 | case 'forward': | |
193 | $dateSort = CRM_Mailing_Event_BAO_Forward::getTableName() . '.time_stamp'; | |
194 | ||
195 | $this->_columnHeaders = array_merge($this->_columnHeaders, | |
196 | array( | |
197 | array( | |
198 | 'name' => ts('Forwarded Email'), | |
199 | ), | |
200 | ) | |
201 | ); | |
202 | break; | |
203 | ||
204 | case 'reply': | |
205 | $dateSort = CRM_Mailing_Event_BAO_Reply::getTableName() . '.time_stamp'; | |
206 | break; | |
207 | ||
208 | case 'unsubscribe': | |
209 | $dateSort = CRM_Mailing_Event_BAO_Unsubscribe::getTableName() . '.time_stamp'; | |
210 | $this->_columnHeaders = array_merge($this->_columnHeaders, array( | |
211 | array( | |
212 | 'name' => ts('Unsubscribe'), | |
213 | ), | |
214 | )); | |
215 | break; | |
216 | ||
217 | case 'optout': | |
218 | $dateSort = CRM_Mailing_Event_BAO_Unsubscribe::getTableName() . '.time_stamp'; | |
219 | $this->_columnHeaders = array_merge($this->_columnHeaders, array( | |
220 | array( | |
221 | 'name' => ts('Opt-Out'), | |
222 | ), | |
223 | )); | |
224 | break; | |
225 | ||
226 | case 'click': | |
227 | $dateSort = CRM_Mailing_Event_BAO_TrackableURLOpen::getTableName() . '.time_stamp'; | |
228 | $this->_columnHeaders = array_merge($this->_columnHeaders, array( | |
229 | array( | |
230 | 'name' => ts('URL'), | |
231 | ), | |
232 | )); | |
233 | break; | |
234 | ||
235 | default: | |
236 | return 0; | |
237 | } | |
238 | ||
239 | $this->_columnHeaders = array_merge($this->_columnHeaders, | |
240 | array( | |
241 | array( | |
242 | 'name' => ts('Date'), | |
243 | 'sort' => $dateSort, | |
244 | 'direction' => CRM_Utils_Sort::DESCENDING, | |
245 | ), | |
246 | ) | |
247 | ); | |
248 | } | |
249 | return $this->_columnHeaders; | |
250 | } | |
251 | ||
252 | /** | |
253 | * Returns total number of rows for the query. | |
254 | * | |
255 | * @param | |
256 | * | |
257 | * @return int Total number of rows | |
258 | * @access public | |
259 | */ | |
260 | function getTotalCount($action) { | |
261 | switch ($this->_event_type) { | |
262 | case 'queue': | |
263 | $event = new CRM_Mailing_Event_BAO_Queue(); | |
264 | return $event->getTotalCount($this->_mailing_id, | |
265 | $this->_job_id | |
266 | ); | |
267 | break; | |
268 | ||
269 | case 'delivered': | |
270 | $event = new CRM_Mailing_Event_BAO_Delivered(); | |
271 | return $event->getTotalCount($this->_mailing_id, | |
272 | $this->_job_id, | |
273 | $this->_is_distinct | |
274 | ); | |
275 | break; | |
276 | ||
277 | case 'opened': | |
278 | $event = new CRM_Mailing_Event_BAO_Opened(); | |
279 | return $event->getTotalCount($this->_mailing_id, | |
280 | $this->_job_id, | |
281 | $this->_is_distinct | |
282 | ); | |
283 | break; | |
284 | ||
285 | case 'bounce': | |
286 | $event = new CRM_Mailing_Event_BAO_Bounce(); | |
287 | return $event->getTotalCount($this->_mailing_id, | |
288 | $this->_job_id, | |
289 | $this->_is_distinct | |
290 | ); | |
291 | break; | |
292 | ||
293 | case 'forward': | |
294 | $event = new CRM_Mailing_Event_BAO_Forward(); | |
295 | return $event->getTotalCount($this->_mailing_id, | |
296 | $this->_job_id, | |
297 | $this->_is_distinct | |
298 | ); | |
299 | break; | |
300 | ||
301 | case 'reply': | |
302 | $event = new CRM_Mailing_Event_BAO_Reply(); | |
303 | return $event->getTotalCount($this->_mailing_id, | |
304 | $this->_job_id, | |
305 | $this->_is_distinct | |
306 | ); | |
307 | break; | |
308 | ||
309 | case 'unsubscribe': | |
310 | $event = new CRM_Mailing_Event_BAO_Unsubscribe(); | |
311 | return $event->getTotalCount($this->_mailing_id, | |
312 | $this->_job_id, | |
313 | $this->_is_distinct | |
314 | ); | |
315 | break; | |
316 | ||
317 | case 'optout': | |
318 | $event = new CRM_Mailing_Event_BAO_Unsubscribe(); | |
319 | return $event->getTotalCount($this->_mailing_id, | |
320 | $this->_job_id, | |
321 | $this->_is_distinct, | |
322 | FALSE | |
323 | ); | |
324 | break; | |
325 | ||
326 | case 'click': | |
327 | $event = new CRM_Mailing_Event_BAO_TrackableURLOpen(); | |
328 | return $event->getTotalCount($this->_mailing_id, | |
329 | $this->_job_id, | |
330 | $this->_is_distinct, | |
331 | $this->_url_id | |
332 | ); | |
333 | break; | |
334 | ||
335 | default: | |
336 | return 0; | |
337 | } | |
338 | } | |
339 | ||
340 | /** | |
341 | * returns all the rows in the given offset and rowCount | |
342 | * | |
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) | |
348 | * | |
349 | * @return int the total number of rows for this action | |
350 | */ | |
351 | function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { | |
352 | switch ($this->_event_type) { | |
353 | case 'queue': | |
354 | return CRM_Mailing_Event_BAO_Queue::getRows($this->_mailing_id, | |
355 | $this->_job_id, $offset, $rowCount, $sort | |
356 | ); | |
357 | break; | |
358 | ||
359 | case 'delivered': | |
360 | return CRM_Mailing_Event_BAO_Delivered::getRows($this->_mailing_id, | |
361 | $this->_job_id, $this->_is_distinct, | |
362 | $offset, $rowCount, $sort | |
363 | ); | |
364 | break; | |
365 | ||
366 | case 'opened': | |
367 | return CRM_Mailing_Event_BAO_Opened::getRows($this->_mailing_id, | |
368 | $this->_job_id, $this->_is_distinct, | |
369 | $offset, $rowCount, $sort | |
370 | ); | |
371 | break; | |
372 | ||
373 | case 'bounce': | |
374 | return CRM_Mailing_Event_BAO_Bounce::getRows($this->_mailing_id, | |
375 | $this->_job_id, $this->_is_distinct, | |
376 | $offset, $rowCount, $sort | |
377 | ); | |
378 | break; | |
379 | ||
380 | case 'forward': | |
381 | return CRM_Mailing_Event_BAO_Forward::getRows($this->_mailing_id, | |
382 | $this->_job_id, $this->_is_distinct, | |
383 | $offset, $rowCount, $sort | |
384 | ); | |
385 | ||
386 | case 'reply': | |
387 | return CRM_Mailing_Event_BAO_Reply::getRows($this->_mailing_id, | |
388 | $this->_job_id, $this->_is_distinct, | |
389 | $offset, $rowCount, $sort | |
390 | ); | |
391 | break; | |
392 | ||
393 | case 'unsubscribe': | |
394 | return CRM_Mailing_Event_BAO_Unsubscribe::getRows($this->_mailing_id, | |
395 | $this->_job_id, $this->_is_distinct, | |
396 | $offset, $rowCount, $sort, TRUE | |
397 | ); | |
398 | break; | |
399 | ||
400 | case 'optout': | |
401 | return CRM_Mailing_Event_BAO_Unsubscribe::getRows($this->_mailing_id, | |
402 | $this->_job_id, $this->_is_distinct, | |
403 | $offset, $rowCount, $sort, FALSE | |
404 | ); | |
405 | break; | |
406 | ||
407 | case 'click': | |
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 | |
412 | ); | |
413 | break; | |
414 | ||
415 | default: | |
416 | return NULL; | |
417 | } | |
418 | } | |
419 | ||
420 | /** | |
421 | * name of export file. | |
422 | * | |
423 | * @param string $output type of output | |
424 | * | |
425 | * @return string name of the file | |
426 | */ | |
427 | function getExportFileName($output = 'csv') {} | |
428 | ||
429 | function eventToTitle() { | |
430 | static $events = NULL; | |
431 | ||
432 | if (empty($events)) { | |
433 | $events = array( | |
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') | |
440 | : ts('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'), | |
449 | ); | |
450 | } | |
451 | return $events[$this->_event_type]; | |
452 | } | |
453 | ||
454 | function getTitle() { | |
455 | return $this->eventToTitle(); | |
456 | } | |
457 | } | |
458 | //end of class | |
459 |