PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.24.0
GiveWP – Donation Plugin and Fundraising Platform v2.24.0
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 3 years ago give-subscription.php 3 years ago give-subscriptions-api.php 4 years ago give-subscriptions-db.php 3 years ago
give-subscriptions-db.php
723 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 *
48 * @since 2.24.0 add payment_mode column
49 * @since 1.0
50 */
51 public function get_columns()
52 {
53 return [
54 'id' => '%d',
55 'customer_id' => '%d',
56 'period' => '%s',
57 'frequency' => '%d',
58 'initial_amount' => '%s',
59 'recurring_amount' => '%s',
60 'recurring_fee_amount' => '%F',
61 'bill_times' => '%d',
62 'transaction_id' => '%s',
63 'parent_payment_id' => '%d',
64 'product_id' => '%d',
65 'created' => '%s',
66 'expiration' => '%s',
67 'payment_mode' => '%s',
68 'status' => '%s',
69 'notes' => '%s',
70 'profile_id' => '%s',
71 ];
72 }
73
74
75 /**
76 * Get default column values
77 *
78 * @access public
79 * @since 1.0
80 */
81 public function get_column_defaults()
82 {
83 return [
84 'customer_id' => 0,
85 'period' => '',
86 'frequency' => 1,
87 'initial_amount' => '',
88 'recurring_amount' => '',
89 'recurring_fee_amount' => 0,
90 'bill_times' => 0,
91 'transaction_id' => '',
92 'parent_payment_id' => 0,
93 'product_id' => 0,
94 'created' => date('Y-m-d H:i:s'),
95 'expiration' => date('Y-m-d H:i:s'),
96 'status' => '',
97 'notes' => '',
98 'profile_id' => '',
99 ];
100 }
101
102 /**
103 * Get subscription by specific data
104 *
105 * @since 1.6
106 *
107 * @param int $row_id
108 *
109 * @param int $column
110 *
111 * @return mixed|object
112 */
113 public function get_by($column, $row_id)
114 {
115 $cache_key = Give_Cache::get_key("{$column}_{$row_id}", [$column, $row_id], false);
116 $subscription = Give_Recurring_Cache::get_subscription($cache_key);
117
118 if (is_null($subscription)) {
119 $subscription = parent::get_by($column, $row_id);
120 Give_Recurring_Cache::set_subscription($cache_key, $subscription);
121 }
122
123 return $subscription;
124 }
125
126 /**
127 * Get subscription
128 *
129 * @since 1.6
130 *
131 * @param int $row_id
132 *
133 * @return mixed|object
134 */
135 public function get($row_id)
136 {
137 $cache_key = Give_Cache::get_key($row_id, '', false);
138 $subscription = Give_Recurring_Cache::get_subscription($cache_key);
139
140 if (is_null($subscription)) {
141 $subscription = parent::get($row_id);
142 Give_Recurring_Cache::set_subscription($cache_key, $subscription);
143 }
144
145 return $subscription;
146 }
147
148 /**
149 * Update subscription
150 *
151 * @since 1.6
152 *
153 * @param array $data
154 * @param string $where
155 *
156 * @param int $row_id
157 *
158 * @return bool
159 */
160 public function update($row_id, $data = [], $where = '')
161 {
162 $status = parent::update($row_id, $data, $where);
163
164 Give_Recurring_Cache::get_instance()->flush_on_subscription_update($status, $row_id, $data, $where);
165
166 /**
167 * Fire the action when subscriptions updated
168 *
169 * @since 1.6
170 */
171 do_action('give_subscription_updated', $status, $row_id, $data, $where);
172
173
174 return $status;
175 }
176
177 /**
178 * Create subscription
179 *
180 * @since 1.6
181 *
182 * @param array $data
183 *
184 * @return int|mixed
185 */
186 public function create($data)
187 {
188 $subcription_id = parent::insert($data, 'subscription');
189
190 /**
191 * Fire the action when subscriptions updated
192 *
193 * @since 1.6
194 */
195 do_action('give_subscription_inserted', $subcription_id, $data);
196
197 return $subcription_id;
198 }
199
200 /**
201 * Delete subscription
202 *
203 * @param int $subscription_id
204 *
205 * @return bool
206 */
207 public function delete($subscription_id = 0)
208 {
209 $subscriptionData = $this->get($subscription_id);
210 $status = parent::delete($subscription_id);
211
212 /**
213 * Fire the action when subscriptions updated
214 *
215 * @since 1.6
216 * @since 1.11.0 Added third parameter
217 */
218 do_action('give_subscription_deleted', $status, $subscription_id, $subscriptionData);
219
220 return $status;
221 }
222
223
224 /**
225 * Retrieve all subscriptions for a donor.
226 *
227 * @since 1.0
228 *
229 * @param array $args
230 *
231 * @access public
232 * @return Give_Subscription[]
233 */
234 public function get_subscriptions($args = [])
235 {
236 global $wpdb;
237
238 $defaults = [
239 'number' => 20,
240 'offset' => 0,
241 'search' => '',
242 'form_id' => 0,
243 'customer_id' => 0,
244 'orderby' => 'id',
245 'order' => 'DESC',
246 ];
247
248 $args = wp_parse_args($args, $defaults);
249
250 if ($args['number'] < 1) {
251 $args['number'] = 999999999999;
252 }
253
254
255 $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby'];
256
257 if ('amount' == $args['orderby']) {
258 $args['orderby'] = 'amount+0';
259 }
260
261 $cache_key = Give_Cache::get_key('give_subscriptions', $args, false);
262 $subscriptions = Give_Recurring_Cache::get_db_query($cache_key);
263
264 // If no cache key, get subscriptions.
265 if (is_null($subscriptions)) {
266 $where = $this->generate_where_clause($args);
267
268 $args['orderby'] = esc_sql($args['orderby']);
269 $args['order'] = esc_sql($args['order']);
270
271 $subscriptions = $wpdb->get_results(
272 $wpdb->prepare(
273 "SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;",
274 absint($args['offset']),
275 absint($args['number'])
276 ),
277 OBJECT
278 );
279
280 if (!empty($subscriptions)) {
281 foreach ($subscriptions as $key => $subscription) {
282 $subscriptions[$key] = new Give_Subscription($subscription);
283 }
284
285 Give_Recurring_Cache::set_db_query($cache_key, $subscriptions);
286 }
287 }
288
289 return $subscriptions;
290 }
291
292
293 /**
294 * Count the total number of subscriptions in the database.
295 *
296 * @param array $args
297 *
298 * @return int|array/null
299 */
300 public function count($args = [])
301 {
302 global $wpdb;
303
304 $cache_key = Give_Cache::get_key('give_subscriptions_count', $args, false);
305 $count = Give_Recurring_Cache::get_db_query($cache_key);
306 $group_by_args = !empty($args['groupBy']) ? $args['groupBy'] : '';
307 $return_count = empty($group_by_args);
308
309 $result = null;
310
311 if (null === $count) {
312 $groupBy = $this->generate_groupby_clause($group_by_args);
313 $where = $this->generate_where_clause($args);
314 $count = $return_count ? "COUNT({$this->primary_key})" : "{$group_by_args}, COUNT({$this->primary_key})";
315 $sql = "SELECT {$count} FROM {$this->table_name} {$where} {$groupBy};";
316
317 $result = $return_count ? $wpdb->get_var($sql) : $wpdb->get_results($sql, ARRAY_A);
318
319 // Simplify result if query for groupBy.
320 if ($group_by_args && $result) {
321 $temp = [];
322 foreach ($result as $data) {
323 $temp[$data[$group_by_args]] = $data['COUNT(id)'];
324 }
325
326 $result = $temp;
327 }
328
329 Give_Recurring_Cache::set_db_query($cache_key, $result);
330 }
331
332 return $return_count ? absint($result) : $result;
333 }
334
335 /**
336 * Create the table.
337 *
338 * @access public
339 * @since 1.0
340 */
341 public function create_table()
342 {
343 global $wpdb;
344
345 if ($wpdb->get_var("SHOW TABLES LIKE '$this->table_name'") !== $this->table_name) {
346 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
347
348 $sql = 'CREATE TABLE ' . $this->table_name . ' (
349 id bigint(20) NOT NULL AUTO_INCREMENT,
350 customer_id bigint(20) NOT NULL,
351 period varchar(20) NOT NULL,
352 frequency bigint(20) DEFAULT "1" NOT NULL,
353 initial_amount decimal(18,10) NOT NULL,
354 recurring_amount decimal(18,10) NOT NULL,
355 recurring_fee_amount decimal(18,10) NOT NULL,
356 bill_times bigint(20) NOT NULL,
357 transaction_id varchar(60) NOT NULL,
358 parent_payment_id bigint(20) NOT NULL,
359 product_id bigint(20) NOT NULL,
360 created datetime NOT NULL,
361 expiration datetime NOT NULL,
362 status varchar(20) NOT NULL,
363 profile_id varchar(60) NOT NULL,
364 notes longtext NOT NULL,
365 PRIMARY KEY (id),
366 KEY profile_id (profile_id),
367 KEY customer (customer_id),
368 KEY transaction (transaction_id),
369 INDEX customer_and_status ( customer_id, status)
370 ) CHARACTER SET utf8 COLLATE utf8_general_ci;';
371
372 dbDelta($sql);
373
374 update_option($this->table_name . '_db_version', $this->version);
375 }
376 }
377
378 /**
379 * Get Renewing Subscriptions
380 *
381 * @param string $period
382 *
383 * @return array|bool|mixed|null|object
384 */
385 public function get_renewing_subscriptions($period = '+1month')
386 {
387 global $wpdb;
388
389 $args = [
390 'number' => 99999,
391 'status' => 'active',
392 'offset' => 0,
393 'orderby' => 'id',
394 'order' => 'DESC',
395 'expiration' => [
396 'start' => date('Y-m-d H:i:s', strtotime($period . ' midnight')),
397 'end' => date('Y-m-d H:i:s', strtotime($period . ' midnight') + (DAY_IN_SECONDS - 1)),
398 ],
399 ];
400
401 $cache_key = Give_Cache::get_key('give_renewing_subscriptions', $args, false);
402 $subscriptions = Give_Recurring_Cache::get_db_query($cache_key);
403
404 if (is_null($subscriptions)) {
405 $where = $this->generate_where_clause($args);
406
407 $query = $wpdb->prepare(
408 "SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;",
409 absint($args['offset']),
410 absint($args['number'])
411 );
412 $subscriptions = $wpdb->get_results($query);
413 Give_Recurring_Cache::set_db_query($cache_key, $subscriptions);
414 }
415
416 return $subscriptions;
417 }
418
419 /**
420 * Get expiring subscriptions.
421 *
422 * @param string $period
423 *
424 * @return array|bool|mixed|null|object
425 */
426 public function get_expiring_subscriptions($period = '+1month')
427 {
428 global $wpdb;
429
430 $args = [
431 'number' => 99999,
432 'status' => 'active',
433 'offset' => 0,
434 'orderby' => 'id',
435 'order' => 'DESC',
436 'expiration' => [
437 'start' => date('Y-m-d H:i:s', strtotime($period . ' midnight')),
438 'end' => date('Y-m-d H:i:s', strtotime($period . ' midnight') + (DAY_IN_SECONDS - 1)),
439 ],
440 ];
441
442 $cache_key = Give_Cache::get_key('give_expiring_subscriptions', $args, false);
443 $subscriptions = Give_Recurring_Cache::get_db_query($cache_key);
444
445 if (is_null($subscriptions)) {
446 $where = $this->generate_where_clause($args);
447 $where .= ' AND `bill_times` != 0';
448 $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`';
449
450 $query = $wpdb->prepare(
451 "SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;",
452 absint($args['offset']),
453 absint($args['number'])
454 );
455 $subscriptions = $wpdb->get_results($query);
456 Give_Recurring_Cache::set_db_query($cache_key, $subscriptions);
457 }
458
459 return $subscriptions;
460 }
461
462 /**
463 * Generate a cache key from args.
464 *
465 * @deprecated 1.6
466 *
467 * @param $args
468 *
469 * @param $prefix
470 *
471 * @return string
472 */
473 protected function generate_cache_key($prefix, $args)
474 {
475 return md5($prefix . serialize($args));
476 }
477
478 /**
479 * Build the query args for subscriptions.
480 *
481 * @param array $args
482 *
483 * @return string The mysql "where" query part.
484 */
485 public function generate_where_clause($args = [])
486 {
487 $where = ' WHERE 1=1';
488
489 // Specific ID.
490 if (!empty($args['id'])) {
491 if (is_array($args['id'])) {
492 $ids = implode(',', array_map('intval', $args['id']));
493 } else {
494 $ids = intval($args['id']);
495 }
496
497 $where .= " AND `id` IN( {$ids} ) ";
498 }
499
500 // Specific donation forms.
501 if (!empty($args['form_id'])) {
502 if (is_array($args['form_id'])) {
503 $form_ids = implode(',', array_map('intval', $args['form_id']));
504 } else {
505 $form_ids = intval($args['form_id']);
506 }
507
508 $where .= " AND `product_id` IN( {$form_ids} ) ";
509 }
510
511 // Specific parent payments
512 if (!empty($args['parent_payment_id'])) {
513 if (is_array($args['parent_payment_id'])) {
514 $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id']));
515 } else {
516 $parent_payment_ids = intval($args['parent_payment_id']);
517 }
518
519 $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) ";
520 }
521
522 // @TODO: Remove after consolidating terminology.
523 if (isset($args['donor_id']) && !empty($args['donor_id'])) {
524 $args['customer_id'] = $args['donor_id'];
525 }
526
527 // Subscriptions for specific customers/donors
528 if (!empty($args['customer_id'])) {
529 if (is_array($args['customer_id'])) {
530 $customer_ids = implode(',', array_map('intval', $args['customer_id']));
531 } else {
532 $customer_ids = intval($args['customer_id']);
533 }
534
535 $where .= " AND `customer_id` IN( {$customer_ids} ) ";
536 }
537
538 // Subscriptions for specific profile IDs
539 if (!empty($args['profile_id'])) {
540 if (is_array($args['profile_id'])) {
541 $profile_ids = implode('\',\'', $args['profile_id']);
542 } else {
543 $profile_ids = $args['profile_id'];
544 }
545
546 $where .= " AND `profile_id` IN( '{$profile_ids}' ) ";
547 }
548
549 // Specific transaction IDs
550 if (!empty($args['transaction_id'])) {
551 if (is_array($args['transaction_id'])) {
552 $transaction_ids = implode('\',\'', array_map('sanitize_text_field', $args['transaction_id']));
553 } else {
554 $transaction_ids = sanitize_text_field($args['transaction_id']);
555 }
556
557 $where .= " AND `transaction_id` IN( '{$transaction_ids}' ) ";
558 }
559
560 // Subscriptions for specific statuses
561 if (!empty($args['status'])) {
562 if (is_array($args['status'])) {
563 $statuses = implode('\',\'', $args['status']);
564 $where .= " AND `status` IN( '{$statuses}' ) ";
565 } else {
566 $statuses = $args['status'];
567 $where .= " AND `status` = '{$statuses}' ";
568 }
569 }
570
571 if (!empty($args['date'])) {
572 $where .= $this->mysql_where_args_date($args);
573 }
574
575 if (!empty($args['expiration'])) {
576 $where .= $this->mysql_where_args_expiration($args);
577 }
578
579 if (!empty($args['search'])) {
580 $where .= $this->mysql_where_args_search($args);
581 }
582
583 return apply_filters('give_subscriptions_mysql_query', $where);
584 }
585
586 /**
587 * Build the query args for subscriptions.
588 *
589 * @param string $groupby
590 *
591 * @return string The mysql "where" query part.
592 */
593 private function generate_groupby_clause($groupby = '')
594 {
595 if (!$groupby) {
596 return '';
597 }
598
599 return "GROUP BY {$groupby}";
600 }
601
602 /**
603 * @param $args
604 *
605 * @return string
606 */
607 private function mysql_where_args_search($args)
608 {
609 $where = '';
610 $donors_db = new Give_DB_Donors();
611 if (is_email($args['search'])) {
612 $customer = new Give_Donor($args['search']);
613 if ($customer && $customer->id > 0) {
614 $where = " AND `customer_id` = " . absint($customer->id) . "";
615 }
616 } elseif (false !== strpos($args['search'], 'txn:')) {
617 $args['search'] = trim(str_replace('txn:', '', $args['search']));
618 $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";
619 } elseif (false !== strpos($args['search'], 'profile_id:')) {
620 $args['search'] = trim(str_replace('profile_id:', '', $args['search']));
621 $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";
622 } elseif (false !== strpos($args['search'], 'form_id:')) {
623 $args['search'] = trim(str_replace('form_id:', '', $args['search']));
624 $where .= " AND `product_id` = " . absint($args['search']) . "";
625 } elseif (false !== strpos($args['search'], 'product_id:')) {
626 $args['search'] = trim(str_replace('product_id:', '', $args['search']));
627 $where .= " AND `product_id` = " . absint($args['search']) . "";
628 } elseif (false !== strpos($args['search'], 'customer_id:')) {
629 $args['search'] = trim(str_replace('customer_id:', '', $args['search']));
630 $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'";
631 } elseif (false !== strpos($args['search'], 'id:') || is_numeric($args['search'])) {
632 $args['search'] = trim(str_replace('id:', '', $args['search']));
633 $where .= " AND `id` = " . absint($args['search']) . "";
634 } else {
635 // See if search matches a product name
636 $form = get_page_by_title(trim($args['search']), OBJECT, 'give_forms');
637 if ($form) {
638 $args['search'] = $form->ID;
639 $where .= " AND `product_id` = " . absint($args['search']) . "";
640 } else {
641 global $wpdb;
642 $query = $wpdb->prepare(
643 "
644 SELECT id,name FROM {$donors_db->table_name}
645 WHERE name
646 LIKE '%s'",
647 '%' . $args['search'] . '%'
648 );
649 $subscription_donor_id = [];
650 $donor_ids = $wpdb->get_results($query, ARRAY_A);
651 if (!empty($donor_ids) && count($donor_ids) > 0) {
652 foreach ($donor_ids as $key => $val) {
653 $subscription_donor_id[] = absint($val['id']);
654 }
655 }
656 $subscription_donor_id = implode(',', array_map('intval', $subscription_donor_id));
657 $where .= " AND {$this->table_name}.customer_id IN ({$subscription_donor_id})";
658 }
659 }// End if().
660 return $where;
661 }
662
663 /**
664 * @param $args
665 *
666 * @return string
667 */
668 private function mysql_where_args_date($args)
669 {
670 $where = '';
671 if (is_array($args['date'])) {
672 if (!empty($args['date']['start'])) {
673 $start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
674 $where .= " AND `expiration` >= '{$start}'";
675 }
676 if (!empty($args['date']['end'])) {
677 $end = date('Y-m-d H:i:s', strtotime($args['date']['end']));
678 $where .= " AND `expiration` <= '{$end}'";
679 }
680 } else {
681 $year = date('Y', strtotime($args['date']));
682 $month = date('m', strtotime($args['date']));
683 $day = date('d', strtotime($args['date']));
684 $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )";
685 }
686
687 return $where;
688 }
689
690 /**
691 * @param $args
692 *
693 * @return string
694 */
695 private function mysql_where_args_expiration($args)
696 {
697 $where = '';
698
699 if (is_array($args['expiration'])) {
700 if (!empty($args['expiration']['start'])) {
701 $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start']));
702
703 $where .= " AND `expiration` >= '{$start}'";
704 }
705
706 if (!empty($args['expiration']['end'])) {
707 $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end']));
708
709 $where .= " AND `expiration` <= '{$end}'";
710 }
711 } else {
712 $year = date('Y', strtotime($args['expiration']));
713 $month = date('m', strtotime($args['expiration']));
714 $day = date('d', strtotime($args['expiration']));
715
716 $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )";
717 }
718
719 return $where;
720 }
721
722 }
723