Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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. | | |
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 along with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
25 | */ | |
26 | ||
27 | /** | |
28 | * | |
29 | * @package CRM | |
06b69b18 | 30 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
31 | * $Id$ |
32 | * | |
33 | */ | |
34 | class CRM_Mailing_BAO_Query { | |
35 | ||
36 | static $_mailingFields = NULL; | |
37 | ||
e0ef6999 EM |
38 | /** |
39 | * @return array|null | |
40 | */ | |
00be9182 | 41 | public static function &getFields() { |
6a488035 TO |
42 | if (!self::$_mailingFields) { |
43 | self::$_mailingFields = array(); | |
44 | $_mailingFields['mailing_id'] = array( | |
45 | 'name' => 'mailing_id', | |
46 | 'title' => 'Mailing ID', | |
47 | 'where' => 'civicrm_mailing.id', | |
48 | ); | |
49 | } | |
50 | return self::$_mailingFields; | |
51 | } | |
52 | ||
53 | /** | |
100fef9d | 54 | * If mailings are involved, add the specific Mailing fields |
6a488035 | 55 | * |
77b97be7 EM |
56 | * @param $query |
57 | * | |
6a488035 | 58 | * @return void |
6a488035 | 59 | */ |
00be9182 | 60 | public static function select(&$query) { |
6a488035 TO |
61 | // if Mailing mode add mailing id |
62 | if ($query->_mode & CRM_Contact_BAO_Query::MODE_MAILING) { | |
63 | $query->_select['mailing_id'] = "civicrm_mailing.id as mailing_id"; | |
64 | $query->_element['mailing_id'] = 1; | |
2cc569f2 | 65 | |
335038eb PJ |
66 | // base table is contact, so join recipients to it |
67 | $query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = | |
68 | " INNER JOIN civicrm_mailing_recipients ON civicrm_mailing_recipients.contact_id = contact_a.id "; | |
2cc569f2 | 69 | |
335038eb | 70 | $query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1; |
2cc569f2 PJ |
71 | |
72 | // get mailing name | |
a7488080 | 73 | if (!empty($query->_returnProperties['mailing_name'])) { |
2cc569f2 PJ |
74 | $query->_select['mailing_name'] = "civicrm_mailing.name as mailing_name"; |
75 | $query->_element['mailing_name'] = 1; | |
76 | } | |
77 | ||
78 | // get mailing subject | |
a7488080 | 79 | if (!empty($query->_returnProperties['mailing_subject'])) { |
2cc569f2 PJ |
80 | $query->_select['mailing_subject'] = "civicrm_mailing.subject as mailing_subject"; |
81 | $query->_element['mailing_subject'] = 1; | |
82 | } | |
83 | ||
84 | // get mailing status | |
a7488080 | 85 | if (!empty($query->_returnProperties['mailing_job_status'])) { |
335038eb | 86 | $query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = |
eb6a4756 | 87 | " LEFT JOIN civicrm_mailing_job ON civicrm_mailing_job.mailing_id = civicrm_mailing.id AND civicrm_mailing_job.parent_id IS NULL AND civicrm_mailing_job.is_test != 1 "; |
2cc569f2 PJ |
88 | $query->_select['mailing_job_status'] = "civicrm_mailing_job.status as mailing_job_status"; |
89 | $query->_element['mailing_job_status'] = 1; | |
90 | } | |
91 | ||
92 | // get email on hold | |
a7488080 | 93 | if (!empty($query->_returnProperties['email_on_hold'])) { |
2cc569f2 PJ |
94 | $query->_select['email_on_hold'] = "recipient_email.on_hold as email_on_hold"; |
95 | $query->_element['email_on_hold'] = 1; | |
96 | $query->_tables['recipient_email'] = $query->_whereTables['recipient_email'] = 1; | |
97 | } | |
98 | ||
99 | // get recipient email | |
a7488080 | 100 | if (!empty($query->_returnProperties['email'])) { |
2cc569f2 PJ |
101 | $query->_select['email'] = "recipient_email.email as email"; |
102 | $query->_element['email'] = 1; | |
103 | $query->_tables['recipient_email'] = $query->_whereTables['recipient_email'] = 1; | |
104 | } | |
105 | ||
106 | // get user opt out | |
a7488080 | 107 | if (!empty($query->_returnProperties['contact_opt_out'])) { |
2cc569f2 PJ |
108 | $query->_select['contact_opt_out'] = "contact_a.is_opt_out as contact_opt_out"; |
109 | $query->_element['contact_opt_out'] = 1; | |
110 | } | |
111 | ||
112 | // mailing job end date / completed date | |
a7488080 | 113 | if (!empty($query->_returnProperties['mailing_job_end_date'])) { |
335038eb | 114 | $query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = |
eb6a4756 | 115 | " LEFT JOIN civicrm_mailing_job ON civicrm_mailing_job.mailing_id = civicrm_mailing.id AND civicrm_mailing_job.parent_id IS NULL AND civicrm_mailing_job.is_test != 1 "; |
2cc569f2 PJ |
116 | $query->_select['mailing_job_end_date'] = "civicrm_mailing_job.end_date as mailing_job_end_date"; |
117 | $query->_element['mailing_job_end_date'] = 1; | |
118 | } | |
47546fcf | 119 | |
a7488080 | 120 | if (!empty($query->_returnProperties['mailing_recipients_id'])) { |
335038eb PJ |
121 | $query->_select['mailing_recipients_id'] = " civicrm_mailing_recipients.id as mailing_recipients_id"; |
122 | $query->_element['mailing_recipients_id'] = 1; | |
47546fcf | 123 | } |
6a488035 TO |
124 | } |
125 | } | |
126 | ||
e0ef6999 EM |
127 | /** |
128 | * @param $query | |
129 | */ | |
00be9182 | 130 | public static function where(&$query) { |
6a488035 TO |
131 | $grouping = NULL; |
132 | foreach (array_keys($query->_params) as $id) { | |
a7488080 | 133 | if (empty($query->_params[$id][0])) { |
6a488035 TO |
134 | continue; |
135 | } | |
136 | if (substr($query->_params[$id][0], 0, 8) == 'mailing_') { | |
137 | if ($query->_mode == CRM_Contact_BAO_QUERY::MODE_CONTACTS) { | |
138 | $query->_useDistinct = TRUE; | |
139 | } | |
140 | $grouping = $query->_params[$id][3]; | |
141 | self::whereClauseSingle($query->_params[$id], $query); | |
142 | } | |
143 | } | |
144 | } | |
145 | ||
e0ef6999 | 146 | /** |
100fef9d | 147 | * @param string $name |
e0ef6999 EM |
148 | * @param $mode |
149 | * @param $side | |
150 | * | |
151 | * @return null|string | |
152 | */ | |
00be9182 | 153 | public static function from($name, $mode, $side) { |
6a488035 | 154 | $from = NULL; |
335038eb | 155 | |
6a488035 | 156 | switch ($name) { |
335038eb PJ |
157 | case 'civicrm_mailing_recipients': |
158 | $from = " $side JOIN civicrm_mailing_recipients ON civicrm_mailing_recipients.contact_id = contact_a.id"; | |
6a488035 TO |
159 | break; |
160 | ||
335038eb PJ |
161 | case 'civicrm_mailing_event_queue': |
162 | // this is tightly binded so as to do a check WRT actual job recipients ('child' type jobs) | |
163 | $from = " INNER JOIN civicrm_mailing_event_queue ON | |
164 | civicrm_mailing_event_queue.contact_id = civicrm_mailing_recipients.contact_id | |
165 | AND civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id AND civicrm_mailing_job.job_type = 'child'"; | |
6a488035 TO |
166 | break; |
167 | ||
168 | case 'civicrm_mailing': | |
335038eb PJ |
169 | $from = " $side JOIN civicrm_mailing ON civicrm_mailing.id = civicrm_mailing_recipients.mailing_id "; |
170 | break; | |
171 | ||
172 | case 'civicrm_mailing_job': | |
eb6a4756 | 173 | $from = " $side JOIN civicrm_mailing_job ON civicrm_mailing_job.mailing_id = civicrm_mailing.id AND civicrm_mailing_job.is_test != 1 "; |
6a488035 TO |
174 | break; |
175 | ||
176 | case 'civicrm_mailing_event_bounce': | |
177 | case 'civicrm_mailing_event_delivered': | |
178 | case 'civicrm_mailing_event_opened': | |
179 | case 'civicrm_mailing_event_reply': | |
180 | case 'civicrm_mailing_event_unsubscribe': | |
181 | case 'civicrm_mailing_event_forward': | |
182 | case 'civicrm_mailing_event_trackable_url_open': | |
183 | $from = " $side JOIN $name ON $name.event_queue_id = civicrm_mailing_event_queue.id"; | |
184 | break; | |
2cc569f2 PJ |
185 | |
186 | case 'recipient_email': | |
335038eb PJ |
187 | $from = " $side JOIN civicrm_email recipient_email ON recipient_email.id = civicrm_mailing_recipients.email_id"; |
188 | break; | |
6a488035 TO |
189 | } |
190 | ||
191 | return $from; | |
192 | } | |
193 | ||
e0ef6999 EM |
194 | /** |
195 | * @param $mode | |
196 | * @param bool $includeCustomFields | |
197 | * | |
198 | * @return array|null | |
199 | */ | |
6a488035 TO |
200 | static function defaultReturnProperties($mode, |
201 | $includeCustomFields = TRUE | |
202 | ) { | |
203 | ||
204 | $properties = NULL; | |
205 | if ($mode & CRM_Contact_BAO_Query::MODE_MAILING) { | |
2cc569f2 PJ |
206 | $properties = array( |
207 | 'mailing_id' => 1, | |
208 | 'mailing_name' => 1, | |
209 | 'sort_name' => 1, | |
210 | 'email' => 1, | |
211 | 'mailing_subject' => 1, | |
212 | 'email_on_hold' => 1, | |
213 | 'contact_opt_out' => 1, | |
214 | 'mailing_job_status' => 1, | |
215 | 'mailing_job_end_date' => 1, | |
216 | 'contact_type' => 1, | |
47546fcf | 217 | 'contact_sub_type' => 1, |
335038eb | 218 | 'mailing_recipients_id' => 1 |
2cc569f2 | 219 | ); |
6a488035 TO |
220 | } |
221 | return $properties; | |
222 | } | |
223 | ||
e0ef6999 EM |
224 | /** |
225 | * @param $values | |
226 | * @param $query | |
227 | */ | |
00be9182 | 228 | public static function whereClauseSingle(&$values, &$query) { |
6a488035 TO |
229 | list($name, $op, $value, $grouping, $wildcard) = $values; |
230 | ||
231 | $fields = array(); | |
232 | $fields = self::getFields(); | |
335038eb | 233 | |
6a488035 TO |
234 | switch ($name) { |
235 | case 'mailing_id': | |
236 | $selectedMailings = array_flip($value); | |
6a488035 TO |
237 | $value = "(" . implode(',', $value) . ")"; |
238 | $op = 'IN'; | |
239 | $query->_where[$grouping][] = "civicrm_mailing.id $op $value"; | |
240 | ||
241 | $mailings = CRM_Mailing_BAO_Mailing::getMailingsList(); | |
242 | foreach ($selectedMailings as $id => $dnc) { | |
243 | $selectedMailings[$id] = $mailings[$id]; | |
244 | } | |
245 | $selectedMailings = implode(' or ', $selectedMailings); | |
246 | ||
247 | $query->_qill[$grouping][] = "Mailing Name $op \"$selectedMailings\""; | |
6a488035 | 248 | $query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1; |
335038eb | 249 | $query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1; |
6a488035 TO |
250 | return; |
251 | ||
252 | case 'mailing_name': | |
253 | $value = strtolower( addslashes( $value ) ); | |
254 | if ( $wildcard ) { | |
255 | $value = "%$value%"; | |
256 | $op = 'LIKE'; | |
257 | } | |
258 | $query->_where[$grouping][] = "LOWER(civicrm_mailing.name) $op '$value'"; | |
335038eb | 259 | $query->_qill[$grouping][] = "Mailing Namename $op \"$value\""; |
6a488035 | 260 | $query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1; |
335038eb | 261 | $query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1; |
6a488035 TO |
262 | return; |
263 | ||
264 | case 'mailing_date': | |
265 | case 'mailing_date_low': | |
266 | case 'mailing_date_high': | |
267 | // process to / from date | |
335038eb | 268 | $query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1; |
6a488035 TO |
269 | $query->_tables['civicrm_mailing_event_queue'] = $query->_whereTables['civicrm_mailing_event_queue'] = 1; |
270 | $query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = 1; | |
335038eb | 271 | $query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1; |
6a488035 TO |
272 | $query->dateQueryBuilder($values, |
273 | 'civicrm_mailing_job', 'mailing_date', 'start_date', 'Mailing Delivery Date' | |
274 | ); | |
275 | return; | |
276 | ||
277 | case 'mailing_delivery_status': | |
278 | $options = CRM_Mailing_PseudoConstant::yesNoOptions('delivered'); | |
279 | ||
280 | list($name, $op, $value, $grouping, $wildcard) = $values; | |
281 | if ($value == 'Y') { | |
282 | self::mailingEventQueryBuilder($query, $values, | |
283 | 'civicrm_mailing_event_delivered', | |
284 | 'mailing_delivery_status', | |
285 | ts('Mailing Delivery'), | |
286 | $options | |
287 | ); | |
288 | } | |
289 | elseif ($value == 'N') { | |
290 | $options['Y'] = $options['N']; | |
291 | $values = array($name, $op, 'Y', $grouping, $wildcard); | |
292 | self::mailingEventQueryBuilder($query, $values, | |
293 | 'civicrm_mailing_event_bounce', | |
294 | 'mailing_delivery_status', | |
295 | ts('Mailing Delivery'), | |
296 | $options | |
297 | ); | |
298 | } | |
299 | return; | |
300 | ||
111b2847 | 301 | case 'mailing_bounce_types': |
302 | $op = 'IN'; | |
303 | $values = array($name, $op, $value, $grouping, $wildcard); | |
304 | self::mailingEventQueryBuilder($query, $values, | |
305 | 'civicrm_mailing_event_bounce', | |
306 | 'bounce_type_id', | |
307 | ts('Bounce type(s)'), | |
308 | CRM_Core_PseudoConstant::get('CRM_Mailing_Event_DAO_Bounce', 'bounce_type_id', array('keyColumn' => 'id', 'labelColumn' => 'name')) | |
309 | ); | |
310 | return; | |
311 | ||
6a488035 TO |
312 | case 'mailing_open_status': |
313 | self::mailingEventQueryBuilder($query, $values, | |
314 | 'civicrm_mailing_event_opened', 'mailing_open_status', ts('Mailing: Trackable Opens'), CRM_Mailing_PseudoConstant::yesNoOptions('open') | |
315 | ); | |
316 | return; | |
317 | ||
318 | case 'mailing_click_status': | |
319 | self::mailingEventQueryBuilder($query, $values, | |
320 | 'civicrm_mailing_event_trackable_url_open', 'mailing_click_status', ts('Mailing: Trackable URL Clicks'), CRM_Mailing_PseudoConstant::yesNoOptions('click') | |
321 | ); | |
322 | return; | |
323 | ||
324 | case 'mailing_reply_status': | |
325 | self::mailingEventQueryBuilder($query, $values, | |
326 | 'civicrm_mailing_event_reply', 'mailing_reply_status', ts('Mailing: Trackable Replies'), CRM_Mailing_PseudoConstant::yesNoOptions('reply') | |
327 | ); | |
328 | return; | |
329 | ||
330 | case 'mailing_optout': | |
331 | $valueTitle = array(1 => ts('Opt-out Requests')); | |
332 | // include opt-out events only | |
333 | $query->_where[$grouping][] = "civicrm_mailing_event_unsubscribe.org_unsubscribe = 1"; | |
334 | self::mailingEventQueryBuilder($query, $values, | |
335 | 'civicrm_mailing_event_unsubscribe', 'mailing_unsubscribe', | |
336 | ts('Mailing: '), $valueTitle | |
337 | ); | |
338 | return; | |
339 | ||
340 | case 'mailing_unsubscribe': | |
341 | $valueTitle = array(1 => ts('Unsubscribe Requests')); | |
342 | // exclude opt-out events | |
343 | $query->_where[$grouping][] = "civicrm_mailing_event_unsubscribe.org_unsubscribe = 0"; | |
344 | self::mailingEventQueryBuilder($query, $values, | |
345 | 'civicrm_mailing_event_unsubscribe', 'mailing_unsubscribe', | |
346 | ts('Mailing: '), $valueTitle | |
347 | ); | |
348 | return; | |
349 | ||
350 | case 'mailing_forward': | |
351 | $valueTitle = array('Y' => ts('Forwards')); | |
352 | // since its a checkbox | |
353 | $values[2] = 'Y'; | |
354 | self::mailingEventQueryBuilder($query, $values, | |
355 | 'civicrm_mailing_event_forward', 'mailing_forward', | |
356 | ts('Mailing: '), $valueTitle | |
357 | ); | |
358 | return; | |
335038eb PJ |
359 | |
360 | case 'mailing_job_status': | |
361 | if (!empty($value)) { | |
362 | if ($value != 'Scheduled' && $value != 'Canceled') { | |
363 | $query->_tables['civicrm_mailing_event_queue'] = $query->_whereTables['civicrm_mailing_event_queue'] = 1; | |
364 | } | |
365 | $query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1; | |
366 | $query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = 1; | |
367 | $query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1; | |
368 | ||
369 | $query->_where[$grouping][] = " civicrm_mailing_job.status = '{$value}' "; | |
370 | $query->_qill[$grouping][] = "Mailing Job Status IS \"$value\""; | |
371 | } | |
372 | return; | |
6a488035 TO |
373 | } |
374 | } | |
375 | ||
376 | /** | |
100fef9d | 377 | * Add all the elements shared between Mailing search and advnaced search |
6a488035 | 378 | * |
6a488035 | 379 | * |
100fef9d | 380 | * @param CRM_Core_Form $form |
6a488035 TO |
381 | * @return void |
382 | * @static | |
383 | */ | |
00be9182 | 384 | public static function buildSearchForm(&$form) { |
6a488035 TO |
385 | // mailing selectors |
386 | $mailings = CRM_Mailing_BAO_Mailing::getMailingsList(); | |
387 | ||
388 | if (!empty($mailings)) { | |
389 | $form->add('select', 'mailing_id', ts('Mailing Name(s)'), $mailings, FALSE, | |
ab345ca5 | 390 | array('id' => 'mailing_id', 'multiple' => 'multiple', 'class' => 'crm-select2') |
6a488035 TO |
391 | ); |
392 | } | |
393 | ||
bc3f7f04 | 394 | CRM_Core_Form_Date::buildDateRange($form, 'mailing_date', 1, '_low', '_high', ts('From'), FALSE); |
6a488035 | 395 | |
335038eb PJ |
396 | $mailingJobStatuses = array( |
397 | '' => ts('- select -'), | |
398 | 'Complete' => 'Complete', | |
399 | 'Scheduled' => 'Scheduled', | |
400 | 'Running' => 'Running', | |
401 | 'Canceled' => 'Canceled' | |
402 | ); | |
403 | $form->addElement('select', 'mailing_job_status', ts('Mailing Job Status'), $mailingJobStatuses, FALSE); | |
404 | ||
111b2847 | 405 | $mailingBounceTypes = CRM_Core_PseudoConstant::get( |
406 | 'CRM_Mailing_Event_DAO_Bounce', 'bounce_type_id', | |
407 | array('keyColumn' => 'id', 'labelColumn' => 'name') | |
408 | ); | |
c9fd7217 | 409 | $form->add('select', 'mailing_bounce_types', ts('Bounce Types'), $mailingBounceTypes, FALSE, |
ab345ca5 | 410 | array('id' => 'mailing_bounce_types', 'multiple' => 'multiple', 'class' => 'crm-select2') |
c9fd7217 | 411 | ); |
111b2847 | 412 | |
6a488035 | 413 | // event filters |
b847e6e7 CW |
414 | $form->addRadio('mailing_delivery_status', ts('Delivery Status'), CRM_Mailing_PseudoConstant::yesNoOptions('delivered'), array('allowClear' => TRUE)); |
415 | $form->addRadio('mailing_open_status', ts('Trackable Opens'), CRM_Mailing_PseudoConstant::yesNoOptions('open'), array('allowClear' => TRUE)); | |
416 | $form->addRadio('mailing_click_status', ts('Trackable URLs'), CRM_Mailing_PseudoConstant::yesNoOptions('click'), array('allowClear' => TRUE)); | |
417 | $form->addRadio('mailing_reply_status', ts('Trackable Replies'), CRM_Mailing_PseudoConstant::yesNoOptions('reply'), array('allowClear' => TRUE)); | |
6a488035 TO |
418 | |
419 | $form->add('checkbox', 'mailing_unsubscribe', ts('Unsubscribe Requests')); | |
420 | $form->add('checkbox', 'mailing_optout', ts('Opt-out Requests')); | |
421 | $form->add('checkbox', 'mailing_forward', ts('Forwards')); | |
422 | ||
423 | $form->assign('validCiviMailing', TRUE); | |
6a488035 TO |
424 | } |
425 | ||
e0ef6999 EM |
426 | /** |
427 | * @param $row | |
100fef9d | 428 | * @param int $id |
e0ef6999 | 429 | */ |
00be9182 | 430 | public static function searchAction(&$row, $id) {} |
6a488035 | 431 | |
e0ef6999 EM |
432 | /** |
433 | * @param $tables | |
434 | */ | |
00be9182 | 435 | public static function tableNames(&$tables) { |
337750c9 | 436 | } |
6a488035 TO |
437 | |
438 | /** | |
439 | * Filter query results based on which contacts do (not) have a particular mailing event in their history. | |
440 | * | |
441 | * @param $query | |
442 | * @param $values | |
100fef9d CW |
443 | * @param string $tableName |
444 | * @param string $fieldName | |
6a488035 TO |
445 | * @param $fieldTitle |
446 | * | |
77b97be7 EM |
447 | * @param $valueTitles |
448 | * | |
6a488035 TO |
449 | * @return void |
450 | */ | |
00be9182 | 451 | public static function mailingEventQueryBuilder(&$query, &$values, $tableName, $fieldName, $fieldTitle, &$valueTitles) { |
6a488035 TO |
452 | list($name, $op, $value, $grouping, $wildcard) = $values; |
453 | ||
454 | if (empty($value) || $value == 'A') { | |
455 | // don't do any filtering | |
456 | return; | |
457 | } | |
458 | ||
459 | if ($value == 'Y') { | |
460 | $query->_where[$grouping][] = $tableName . ".id is not null "; | |
461 | } | |
462 | elseif ($value == 'N') { | |
463 | $query->_where[$grouping][] = $tableName . ".id is null "; | |
464 | } | |
465 | ||
111b2847 | 466 | if (is_array($value)) { |
467 | $query->_where[$grouping][] = "$tableName.$fieldName $op (" . implode(',', $value) . ")"; | |
468 | $query->_qill[$grouping][] = "$fieldTitle $op ". implode(', ', array_intersect_key($valueTitles, array_flip($value))); | |
469 | } | |
470 | else { | |
471 | $query->_qill[$grouping][] = $fieldTitle . ' - ' . $valueTitles[$value]; | |
472 | } | |
473 | ||
dd879954 | 474 | $query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1; |
335038eb | 475 | $query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = 1; |
6a488035 | 476 | $query->_tables['civicrm_mailing_event_queue'] = $query->_whereTables['civicrm_mailing_event_queue'] = 1; |
335038eb | 477 | $query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1; |
6a488035 TO |
478 | $query->_tables[$tableName] = $query->_whereTables[$tableName] = 1; |
479 | } | |
480 | } |