| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
class FrmTransLiteSubscription extends FrmTransLiteDb { |
| 7 |
|
| 8 |
public $table_name = 'frm_subscriptions'; |
| 9 |
public $singular = 'subscription'; |
| 10 |
|
| 11 |
/** |
| 12 |
* @return array |
| 13 |
*/ |
| 14 |
public function get_defaults() { |
| 15 |
return array( |
| 16 |
'sub_id' => array( |
| 17 |
'sanitize' => 'sanitize_text_field', |
| 18 |
'default' => '', |
| 19 |
), |
| 20 |
'item_id' => array( |
| 21 |
'sanitize' => 'absint', |
| 22 |
'default' => '', |
| 23 |
), |
| 24 |
'amount' => array( |
| 25 |
'sanitize' => 'float', |
| 26 |
'default' => '', |
| 27 |
), |
| 28 |
'first_amount' => array( |
| 29 |
'sanitize' => 'float', |
| 30 |
'default' => '', |
| 31 |
), |
| 32 |
'action_id' => array( |
| 33 |
'sanitize' => 'absint', |
| 34 |
'default' => 0, |
| 35 |
), |
| 36 |
'interval_count' => array( |
| 37 |
'sanitize' => 'absint', |
| 38 |
'default' => 1, |
| 39 |
), |
| 40 |
'time_interval' => array( |
| 41 |
'sanitize' => 'sanitize_text_field', |
| 42 |
'default' => '', |
| 43 |
), |
| 44 |
'end_count' => array( |
| 45 |
'sanitize' => 'absint', |
| 46 |
'default' => 9999, |
| 47 |
), |
| 48 |
'paysys' => array( |
| 49 |
'sanitize' => 'sanitize_text_field', |
| 50 |
'default' => 'manual', |
| 51 |
), |
| 52 |
'status' => array( |
| 53 |
'sanitize' => 'sanitize_text_field', |
| 54 |
'default' => 'pending', |
| 55 |
), |
| 56 |
'fail_count' => array( |
| 57 |
'sanitize' => 'absint', |
| 58 |
'default' => 0, |
| 59 |
), |
| 60 |
'created_at' => array( |
| 61 |
'sanitize' => 'sanitize_text_field', |
| 62 |
'default' => current_time( 'mysql', 1 ), |
| 63 |
), |
| 64 |
'next_bill_date' => array( |
| 65 |
'sanitize' => 'sanitize_text_field', |
| 66 |
'default' => '0000-00-00', |
| 67 |
), |
| 68 |
'meta_value' => array( |
| 69 |
'sanitize' => 'maybe_serialize', |
| 70 |
'default' => '', |
| 71 |
), |
| 72 |
'test' => array( |
| 73 |
'sanitize' => 'sanitize_text_field', |
| 74 |
'default' => null, |
| 75 |
), |
| 76 |
); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* @return array |
| 81 |
*/ |
| 82 |
public function get_overdue_subscriptions() { |
| 83 |
global $wpdb; |
| 84 |
return $wpdb->get_results( |
| 85 |
$wpdb->prepare( |
| 86 |
"SELECT * FROM `{$wpdb->prefix}frm_subscriptions` |
| 87 |
WHERE fail_count < %d |
| 88 |
AND next_bill_date < %s |
| 89 |
AND (status = 'active' OR status = 'future_cancel')", |
| 90 |
3, |
| 91 |
gmdate( 'Y-m-d' ) |
| 92 |
) |
| 93 |
); |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Get all active or future_cancel subscriptions without next_bill_date check. |
| 98 |
* |
| 99 |
* @since 6.32 |
| 100 |
* |
| 101 |
* @return array |
| 102 |
*/ |
| 103 |
public function get_active_subscriptions() { |
| 104 |
global $wpdb; |
| 105 |
return $wpdb->get_results( |
| 106 |
$wpdb->prepare( |
| 107 |
"SELECT * FROM %i WHERE (status = 'active' OR status = 'future_cancel')", |
| 108 |
$wpdb->prefix . 'frm_subscriptions' |
| 109 |
) |
| 110 |
); |
| 111 |
} |
| 112 |
} |
| 113 |
|