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