PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.21.2
GiveWP – Donation Plugin and Fundraising Platform v2.21.2
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / LegacySubscriptions / includes / give-subscriptions-db.php
give / src / LegacySubscriptions / includes Last commit date
give-recurring-cache.php 4 years ago give-recurring-cron.php 4 years ago give-recurring-db-subscription-meta.php 4 years ago give-recurring-helpers.php 4 years ago give-recurring-subscriber.php 4 years ago give-subscription.php 4 years ago give-subscriptions-api.php 4 years ago give-subscriptions-db.php 4 years ago
give-subscriptions-db.php
722 lines
1 <?php
2 /**
3 * Give Recurring Subscription DB
4 *
5 * @package Give
6 * @since 1.0
7 * @license https://opensource.org/licenses/gpl-license GNU Public License
8 * @copyright Copyright (c) 2016, GiveWP
9 */
10
11 // Exit if accessed directly
12 if (!defined('ABSPATH')) {
13 exit;
14 }
15
16 /**
17 * Class Give_Subscriptions_DB
18 *
19 * The Subscriptions DB Class.
20 *
21 * @since 2.19.0 - migrated from give-recurring
22 * @since 1.0
23 */
24 class Give_Subscriptions_DB extends Give_DB
25 {
26 /**
27 * Get things started.
28 *
29 * @access public
30 * @since 1.0
31 */
32 public function __construct()
33 {
34 global $wpdb;
35
36 $this->table_name = $wpdb->prefix . 'give_subscriptions';
37 $this->primary_key = 'id';
38 $this->version = '1.1';
39
40 parent::__construct();
41 }
42
43 /**
44 * Get columns and formats
45 *
46 * @access public
47 * @since 1.0
48 */
49 public function get_columns()
50 {
51 return [
52 'id' => '%d',
53 'customer_id' => '%d',
54 'period' => '%s',
55 'frequency' => '%d',
56 'initial_amount' => '%s',
57 'recurring_amount' => '%s',
58 'recurring_fee_amount' => '%F',
59 'bill_times' => '%d',
60 'transaction_id' => '%s',
61 'parent_payment_id' => '%d',
62 'product_id' => '%d',
63 'created' => '%s',
64 'expiration' => '%s',
65 'status' => '%s',
66 'notes' => '%s',
67 'profile_id' => '%s',
68 ];
69 }
70
71
72 /**
73 * Get default column values
74 *
75 * @access public
76 * @since 1.0
77 */
78 public function get_column_defaults()
79 {
80 return [
81 'customer_id' => 0,
82 'period' => '',
83 'frequency' => 1,
84 'initial_amount' => '',
85 'recurring_amount' => '',
86 'recurring_fee_amount' => 0,
87 'bill_times' => 0,
88 'transaction_id' => '',
89 'parent_payment_id' => 0,
90 'product_id' => 0,
91 'created' => date('Y-m-d H:i:s'),
92 'expiration' => date('Y-m-d H:i:s'),
93 'status' => '',
94 'notes' => '',
95 'profile_id' => '',
96 ];
97 }
98
99 /**
100 * Get subscription by specific data
101 *
102 * @since 1.6
103 *
104 * @param int $row_id
105 *
106 * @param int $column
107 *
108 * @return mixed|object
109 */
110 public function get_by($column, $row_id)
111 {
112 $cache_key = Give_Cache::get_key("{$column}_{$row_id}", [$column, $row_id], false);
113 $subscription = Give_Recurring_Cache::get_subscription($cache_key);
114
115 if (is_null($subscription)) {
116 $subscription = parent::get_by($column, $row_id);
117 Give_Recurring_Cache::set_subscription($cache_key, $subscription);
118 }
119
120 return $subscription;
121 }
122
123 /**
124 * Get subscription
125 *
126 * @since 1.6
127 *
128 * @param int $row_id
129 *
130 * @return mixed|object
131 */
132 public function get($row_id)
133 {
134 $cache_key = Give_Cache::get_key($row_id, '', false);
135 $subscription = Give_Recurring_Cache::get_subscription($cache_key);
136
137 if (is_null($subscription)) {
138 $subscription = parent::get($row_id);
139 Give_Recurring_Cache::set_subscription($cache_key, $subscription);
140 }
141
142 return $subscription;
143 }
144
145 /**
146 * Update subscription
147 *
148 * @since 1.6
149 *
150 * @param array $data
151 * @param string $where
152 *
153 * @param int $row_id
154 *
155 * @return bool
156 */
157 public function update($row_id, $data = [], $where = '')
158 {
159 $status = parent::update($row_id, $data, $where);
160
161 Give_Recurring_Cache::get_instance()->flush_on_subscription_update($status, $row_id, $data, $where);
162
163 /**
164 * Fire the action when subscriptions updated
165 *
166 * @since 1.6
167 */
168 do_action('give_subscription_updated', $status, $row_id, $data, $where);
169
170
171 return $status;
172 }
173
174 /**
175 * Create subscription
176 *
177 * @since 1.6
178 *
179 * @param array $data
180 *
181 * @return int|mixed
182 */
183 public function create($data)
184 {
185 $subcription_id = parent::insert($data, 'subscription');
186
187 /**
188 * Fire the action when subscriptions updated
189 *
190 * @since 1.6
191 */
192 do_action('give_subscription_inserted', $subcription_id, $data);
193
194 return $subcription_id;
195 }
196
197 /**
198 * Delete subscription
199 *
200 * @param int $subscription_id
201 *
202 * @return bool
203 */
204 public function delete($subscription_id = 0)
205 {
206 $subscriptionData = $this->get($subscription_id);
207 $status = parent::delete($subscription_id);
208
209 /**
210 * Fire the action when subscriptions updated
211 *
212 * @since 1.6
213 * @since 1.11.0 Added third parameter
214 */
215 do_action('give_subscription_deleted', $status, $subscription_id, $subscriptionData);
216
217 return $status;
218 }
219
220
221 /**
222 * Retrieve all subscriptions for a donor.
223 *
224 * @since 1.0
225 *
226 * @param array $args
227 *
228 * @access public
229 * @return Give_Subscription[]
230 */
231 public function get_subscriptions($args = [])
232 {
233 global $wpdb;
234
235 $defaults = [
236 'number' => 20,
237 'offset' => 0,
238 'search' => '',
239 'form_id' => 0,
240 'customer_id' => 0,
241 'orderby' => 'id',
242 'order' => 'DESC',
243 ];
244
245 $args = wp_parse_args($args, $defaults);
246
247 if ($args['number'] < 1) {
248 $args['number'] = 999999999999;
249 }
250
251
252 $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby'];
253
254 if ('amount' == $args['orderby']) {
255 $args['orderby'] = 'amount+0';
256 }
257
258 $cache_key = Give_Cache::get_key('give_subscriptions', $args, false);
259 $subscriptions = Give_Recurring_Cache::get_db_query($cache_key);
260
261 // If no cache key, get subscriptions.
262 if (is_null($subscriptions)) {
263 $where = $this->generate_where_clause($args);
264
265 $args['orderby'] = esc_sql($args['orderby']);
266 $args['order'] = esc_sql($args['order']);
267
268 $subscriptions = $wpdb->get_results(
269 $wpdb->prepare(
270 "SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;",
271 absint($args['offset']),
272 absint($args['number'])
273 ),
274 OBJECT
275 );
276
277 if (!empty($subscriptions)) {
278 foreach ($subscriptions as $key => $subscription) {
279 $subscriptions[$key] = new Give_Subscription($subscription);
280 }
281
282 Give_Recurring_Cache::set_db_query($cache_key, $subscriptions);
283 }
284 }
285
286 return $subscriptions;
287 }
288
289
290 /**
291 * Count the total number of subscriptions in the database.
292 *
293 * @param array $args
294 *
295 * @return int|array/null
296 */
297 public function count($args = [])
298 {
299 global $wpdb;
300
301 $cache_key = Give_Cache::get_key('give_subscriptions_count', $args, false);
302 $count = Give_Recurring_Cache::get_db_query($cache_key);
303 $group_by_args = !empty($args['groupBy']) ? $args['groupBy'] : '';
304 $return_count = empty($group_by_args);
305
306 $result = null;
307
308 if (null === $count) {
309 $groupBy = $this->generate_groupby_clause($group_by_args);
310 $where = $this->generate_where_clause($args);
311 $count = $return_count ? "COUNT({$this->primary_key})" : "{$group_by_args}, COUNT({$this->primary_key})";
312 $sql = "SELECT {$count} FROM {$this->table_name} {$where} {$groupBy};";
313
314 $result = $return_count ? $wpdb->get_var($sql) : $wpdb->get_results($sql, ARRAY_A);
315
316 // Simplify result if query for groupBy.
317 if ($group_by_args && $result) {
318 $temp = [];
319 foreach ($result as $data) {
320 $temp[$data[$group_by_args]] = $data['COUNT(id)'];
321 }
322
323 $result = $temp;
324 }
325
326 Give_Recurring_Cache::set_db_query($cache_key, $result);
327 }
328
329 return $return_count ? absint($result) : $result;
330 }
331
332 /**
333 * Create the table.
334 *
335 * @access public
336 * @since 1.0
337 */
338 public function create_table()
339 {
340 global $wpdb;
341
342 if ($wpdb->get_var("SHOW TABLES LIKE '$this->table_name'") !== $this->table_name) {
343 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
344
345 $sql = 'CREATE TABLE ' . $this->table_name . ' (
346 id bigint(20) NOT NULL AUTO_INCREMENT,
347 customer_id bigint(20) NOT NULL,
348 period varchar(20) NOT NULL,
349 frequency bigint(20) DEFAULT "1" NOT NULL,
350 initial_amount decimal(18,10) NOT NULL,
351 recurring_amount decimal(18,10) NOT NULL,
352 recurring_fee_amount decimal(18,10) NOT NULL,
353 bill_times bigint(20) NOT NULL,
354 transaction_id varchar(60) NOT NULL,
355 parent_payment_id bigint(20) NOT NULL,
356 product_id bigint(20) NOT NULL,
357 created datetime NOT NULL,
358 expiration datetime NOT NULL,
359 status varchar(20) NOT NULL,
360 profile_id varchar(60) NOT NULL,
361 notes longtext NOT NULL,
362 PRIMARY KEY (id),
363 KEY profile_id (profile_id),
364 KEY customer (customer_id),
365 KEY transaction (transaction_id),
366 INDEX customer_and_status ( customer_id, status)
367 ) CHARACTER SET utf8 COLLATE utf8_general_ci;';
368
369 dbDelta($sql);
370
371 update_option($this->table_name . '_db_version', $this->version);
372 }
373 }
374
375 /**
376 * Get Renewing Subscriptions
377 *
378 * @param string $period
379 *
380 * @return array|bool|mixed|null|object
381 */
382 public function get_renewing_subscriptions($period = '+1month')
383 {
384 global $wpdb;
385
386 $args = [
387 'number' => 99999,
388 'status' => 'active',
389 'offset' => 0,
390 'orderby' => 'id',
391 'order' => 'DESC',
392 'expiration' => [
393 'start' => date('Y-m-d H:i:s', strtotime($period . ' midnight')),
394 'end' => date('Y-m-d H:i:s', strtotime($period . ' midnight') + (DAY_IN_SECONDS - 1)),
395 ],
396 ];
397
398 $cache_key = Give_Cache::get_key('give_renewing_subscriptions', $args, false);
399 $subscriptions = Give_Recurring_Cache::get_db_query($cache_key);
400
401 if (is_null($subscriptions)) {
402 $where = $this->generate_where_clause($args);
403 $where .= ' AND `bill_times` != 0';
404 $where .= ' AND ( SELECT COUNT(ID) FROM ' . $wpdb->prefix . 'posts WHERE `post_parent` = ' . $this->table_name . '.`parent_payment_id` OR `ID` = ' . $this->table_name . '.`parent_payment_id` ) + 1 < `bill_times`';
405
406 $query = $wpdb->prepare(
407 "SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;",
408 absint($args['offset']),
409 absint($args['number'])
410 );
411 $subscriptions = $wpdb->get_results($query);
412 Give_Recurring_Cache::set_db_query($cache_key, $subscriptions);
413 }
414
415 return $subscriptions;
416 }
417
418 /**
419 * Get expiring subscriptions.
420 *
421 * @param string $period
422 *
423 * @return array|bool|mixed|null|object
424 */
425 public function get_expiring_subscriptions($period = '+1month')
426 {
427 global $wpdb;
428
429 $args = [
430 'number' => 99999,
431 'status' => 'active',
432 'offset' => 0,
433 'orderby' => 'id',
434 'order' => 'DESC',
435 'expiration' => [
436 'start' => date('Y-m-d H:i:s', strtotime($period . ' midnight')),
437 'end' => date('Y-m-d H:i:s', strtotime($period . ' midnight') + (DAY_IN_SECONDS - 1)),
438 ],
439 ];
440
441 $cache_key = Give_Cache::get_key('give_expiring_subscriptions', $args, false);
442 $subscriptions = Give_Recurring_Cache::get_db_query($cache_key);
443
444 if (is_null($subscriptions)) {
445 $where = $this->generate_where_clause($args);
446 $where .= ' AND `bill_times` != 0';
447 $where .= ' AND ( SELECT COUNT(ID) FROM ' . $wpdb->prefix . 'posts WHERE `post_parent` = ' . $this->table_name . '.`parent_payment_id` OR `ID` = ' . $this->table_name . '.`parent_payment_id` ) + 1 >= `bill_times`';
448
449 $query = $wpdb->prepare(
450 "SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;",
451 absint($args['offset']),
452 absint($args['number'])
453 );
454 $subscriptions = $wpdb->get_results($query);
455 Give_Recurring_Cache::set_db_query($cache_key, $subscriptions);
456 }
457
458 return $subscriptions;
459 }
460
461 /**
462 * Generate a cache key from args.
463 *
464 * @deprecated 1.6
465 *
466 * @param $args
467 *
468 * @param $prefix
469 *
470 * @return string
471 */
472 protected function generate_cache_key($prefix, $args)
473 {
474 return md5($prefix . serialize($args));
475 }
476
477 /**
478 * Build the query args for subscriptions.
479 *
480 * @param array $args
481 *
482 * @return string The mysql "where" query part.
483 */
484 public function generate_where_clause($args = [])
485 {
486 $where = ' WHERE 1=1';
487
488 // Specific ID.
489 if (!empty($args['id'])) {
490 if (is_array($args['id'])) {
491 $ids = implode(',', array_map('intval', $args['id']));
492 } else {
493 $ids = intval($args['id']);
494 }
495
496 $where .= " AND `id` IN( {$ids} ) ";
497 }
498
499 // Specific donation forms.
500 if (!empty($args['form_id'])) {
501 if (is_array($args['form_id'])) {
502 $form_ids = implode(',', array_map('intval', $args['form_id']));
503 } else {
504 $form_ids = intval($args['form_id']);
505 }
506
507 $where .= " AND `product_id` IN( {$form_ids} ) ";
508 }
509
510 // Specific parent payments
511 if (!empty($args['parent_payment_id'])) {
512 if (is_array($args['parent_payment_id'])) {
513 $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id']));
514 } else {
515 $parent_payment_ids = intval($args['parent_payment_id']);
516 }
517
518 $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) ";
519 }
520
521 // @TODO: Remove after consolidating terminology.
522 if (isset($args['donor_id']) && !empty($args['donor_id'])) {
523 $args['customer_id'] = $args['donor_id'];
524 }
525
526 // Subscriptions for specific customers/donors
527 if (!empty($args['customer_id'])) {
528 if (is_array($args['customer_id'])) {
529 $customer_ids = implode(',', array_map('intval', $args['customer_id']));
530 } else {
531 $customer_ids = intval($args['customer_id']);
532 }
533
534 $where .= " AND `customer_id` IN( {$customer_ids} ) ";
535 }
536
537 // Subscriptions for specific profile IDs
538 if (!empty($args['profile_id'])) {
539 if (is_array($args['profile_id'])) {
540 $profile_ids = implode('\',\'', $args['profile_id']);
541 } else {
542 $profile_ids = $args['profile_id'];
543 }
544
545 $where .= " AND `profile_id` IN( '{$profile_ids}' ) ";
546 }
547
548 // Specific transaction IDs
549 if (!empty($args['transaction_id'])) {
550 if (is_array($args['transaction_id'])) {
551 $transaction_ids = implode('\',\'', array_map('sanitize_text_field', $args['transaction_id']));
552 } else {
553 $transaction_ids = sanitize_text_field($args['transaction_id']);
554 }
555
556 $where .= " AND `transaction_id` IN( '{$transaction_ids}' ) ";
557 }
558
559 // Subscriptions for specific statuses
560 if (!empty($args['status'])) {
561 if (is_array($args['status'])) {
562 $statuses = implode('\',\'', $args['status']);
563 $where .= " AND `status` IN( '{$statuses}' ) ";
564 } else {
565 $statuses = $args['status'];
566 $where .= " AND `status` = '{$statuses}' ";
567 }
568 }
569
570 if (!empty($args['date'])) {
571 $where .= $this->mysql_where_args_date($args);
572 }
573
574 if (!empty($args['expiration'])) {
575 $where .= $this->mysql_where_args_expiration($args);
576 }
577
578 if (!empty($args['search'])) {
579 $where .= $this->mysql_where_args_search($args);
580 }
581
582 return apply_filters('give_subscriptions_mysql_query', $where);
583 }
584
585 /**
586 * Build the query args for subscriptions.
587 *
588 * @param string $groupby
589 *
590 * @return string The mysql "where" query part.
591 */
592 private function generate_groupby_clause($groupby = '')
593 {
594 if (!$groupby) {
595 return '';
596 }
597
598 return "GROUP BY {$groupby}";
599 }
600
601 /**
602 * @param $args
603 *
604 * @return string
605 */
606 private function mysql_where_args_search($args)
607 {
608 $where = '';
609 $donors_db = new Give_DB_Donors();
610 if (is_email($args['search'])) {
611 $customer = new Give_Donor($args['search']);
612 if ($customer && $customer->id > 0) {
613 $where = " AND `customer_id` = " . absint($customer->id) . "";
614 }
615 } elseif (false !== strpos($args['search'], 'txn:')) {
616 $args['search'] = trim(str_replace('txn:', '', $args['search']));
617 $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";
618 } elseif (false !== strpos($args['search'], 'profile_id:')) {
619 $args['search'] = trim(str_replace('profile_id:', '', $args['search']));
620 $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";
621 } elseif (false !== strpos($args['search'], 'form_id:')) {
622 $args['search'] = trim(str_replace('form_id:', '', $args['search']));
623 $where .= " AND `product_id` = " . absint($args['search']) . "";
624 } elseif (false !== strpos($args['search'], 'product_id:')) {
625 $args['search'] = trim(str_replace('product_id:', '', $args['search']));
626 $where .= " AND `product_id` = " . absint($args['search']) . "";
627 } elseif (false !== strpos($args['search'], 'customer_id:')) {
628 $args['search'] = trim(str_replace('customer_id:', '', $args['search']));
629 $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'";
630 } elseif (false !== strpos($args['search'], 'id:') || is_numeric($args['search'])) {
631 $args['search'] = trim(str_replace('id:', '', $args['search']));
632 $where .= " AND `id` = " . absint($args['search']) . "";
633 } else {
634 // See if search matches a product name
635 $form = get_page_by_title(trim($args['search']), OBJECT, 'give_forms');
636 if ($form) {
637 $args['search'] = $form->ID;
638 $where .= " AND `product_id` = " . absint($args['search']) . "";
639 } else {
640 global $wpdb;
641 $query = $wpdb->prepare(
642 "
643 SELECT id,name FROM {$donors_db->table_name}
644 WHERE name
645 LIKE '%%%s%%'",
646 $args['search']
647 );
648 $subscription_donor_id = [];
649 $donor_ids = $wpdb->get_results($query, ARRAY_A);
650 if (!empty($donor_ids) && count($donor_ids) > 0) {
651 foreach ($donor_ids as $key => $val) {
652 $subscription_donor_id[] = absint($val['id']);
653 }
654 }
655 $subscription_donor_id = implode(',', array_map('intval', $subscription_donor_id));
656 $where .= " AND {$this->table_name}.customer_id IN ({$subscription_donor_id})";
657 }
658 }// End if().
659 return $where;
660 }
661
662 /**
663 * @param $args
664 *
665 * @return string
666 */
667 private function mysql_where_args_date($args)
668 {
669 $where = '';
670 if (is_array($args['date'])) {
671 if (!empty($args['date']['start'])) {
672 $start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
673 $where .= " AND `expiration` >= '{$start}'";
674 }
675 if (!empty($args['date']['end'])) {
676 $end = date('Y-m-d H:i:s', strtotime($args['date']['end']));
677 $where .= " AND `expiration` <= '{$end}'";
678 }
679 } else {
680 $year = date('Y', strtotime($args['date']));
681 $month = date('m', strtotime($args['date']));
682 $day = date('d', strtotime($args['date']));
683 $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )";
684 }
685
686 return $where;
687 }
688
689 /**
690 * @param $args
691 *
692 * @return string
693 */
694 private function mysql_where_args_expiration($args)
695 {
696 $where = '';
697
698 if (is_array($args['expiration'])) {
699 if (!empty($args['expiration']['start'])) {
700 $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start']));
701
702 $where .= " AND `expiration` >= '{$start}'";
703 }
704
705 if (!empty($args['expiration']['end'])) {
706 $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end']));
707
708 $where .= " AND `expiration` <= '{$end}'";
709 }
710 } else {
711 $year = date('Y', strtotime($args['expiration']));
712 $month = date('m', strtotime($args['expiration']));
713 $day = date('d', strtotime($args['expiration']));
714
715 $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )";
716 }
717
718 return $where;
719 }
720
721 }
722