PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / trunk
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress vtrunk
4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / Membership / Repositories / PlanRepository.php
wp-user-avatar / src / Membership / Repositories Last commit date
BaseRepository.php 3 years ago CouponRepository.php 2 years ago CustomerRepository.php 1 year ago GroupRepository.php 3 years ago OrderRepository.php 11 months ago PlanRepository.php 2 months ago RepositoryInterface.php 3 years ago SubscriptionRepository.php 3 months ago index.php 3 years ago
PlanRepository.php
184 lines
1 <?php
2
3 namespace ProfilePress\Core\Membership\Repositories;
4
5 use ProfilePress\Core\Base;
6 use ProfilePress\Core\Membership\Models\Plan\PlanFactory;
7 use ProfilePress\Core\Membership\Models\ModelInterface;
8 use ProfilePress\Core\Membership\Models\Plan\PlanEntity;
9
10 class PlanRepository extends BaseRepository
11 {
12 protected $table;
13
14 public function __construct()
15 {
16 $this->table = Base::subscription_plans_db_table();
17 }
18
19 /**
20 * @param PlanEntity $data
21 *
22 * @return false|int
23 */
24 public function add(ModelInterface $data)
25 {
26 global $wpdb;
27
28 $result = $wpdb->insert(
29 $this->table,
30 array(
31 'name' => $data->name,
32 'description' => $data->description,
33 'user_role' => $data->user_role,
34 'order_note' => $data->order_note,
35 'price' => $data->price,
36 'billing_frequency' => $data->billing_frequency,
37 'subscription_length' => $data->subscription_length,
38 'total_payments' => $data->total_payments,
39 'signup_fee' => $data->signup_fee,
40 'free_trial' => $data->free_trial
41 ),
42 array(
43 '%s',
44 '%s',
45 '%s',
46 '%s',
47 '%s',
48 '%s',
49 '%s',
50 '%s',
51 '%d',
52 '%s',
53 '%d',
54 )
55 );
56
57 return ! $result ? false : $wpdb->insert_id;
58 }
59
60 /**
61 * @param PlanEntity $data
62 *
63 * @return false|int
64 */
65 public function update(ModelInterface $data)
66 {
67 global $wpdb;
68
69 $result = $wpdb->update(
70 $this->table,
71 [
72 'name' => $data->name,
73 'description' => $data->description,
74 'user_role' => $data->user_role,
75 'order_note' => $data->order_note,
76 'price' => $data->price,
77 'billing_frequency' => $data->billing_frequency,
78 'subscription_length' => $data->subscription_length,
79 'total_payments' => $data->total_payments,
80 'signup_fee' => $data->signup_fee,
81 'free_trial' => $data->free_trial
82 ],
83 ['id' => $data->id],
84 [
85 '%s',
86 '%s',
87 '%s',
88 '%s',
89 '%s',
90 '%s',
91 '%s',
92 '%d',
93 '%s',
94 '%s',
95 ],
96 ['%d']
97 );
98
99 return $result === false ? false : $data->id;
100 }
101
102 /**
103 * @param $id
104 *
105 * @return int|false
106 */
107 public function delete($id)
108 {
109 global $wpdb;
110
111 return $wpdb->delete($this->table, ['id' => $id], ['%d']);
112 }
113
114 /**
115 * @param $id
116 *
117 * @return PlanEntity
118 */
119 public function retrieve($id)
120 {
121 global $wpdb;
122
123 $result = $wpdb->get_row(
124 $wpdb->prepare(
125 "SELECT * FROM $this->table WHERE id = %d",
126 $id
127 ),
128 ARRAY_A
129 );
130
131 if ( ! $result) $result = [];
132
133 return PlanFactory::make($result);
134 }
135
136 /**
137 * @param int $limit
138 * @param int $current_page
139 *
140 * @return PlanEntity[]|array
141 */
142 public function retrieveAll($limit = 0, $current_page = 1, $status = '')
143 {
144 global $wpdb;
145
146 $replacement = [1];
147 $sql = "SELECT * FROM $this->table";
148 $sql .= " WHERE 1=%d"; // fixes Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder
149
150 if ( ! empty($status)) {
151 $sql .= " AND status = %s";
152 $replacement[] = $status;
153 }
154
155 $sql .= " ORDER BY id DESC";
156 if ($limit > 0) {
157 $sql .= " LIMIT %d";
158 $replacement[] = $limit;
159 }
160
161 if ($current_page > 1) {
162 $sql .= " OFFSET %d";
163 $replacement[] = ($current_page - 1) * $limit;
164 }
165
166 $result = $wpdb->get_results($wpdb->prepare($sql, $replacement), 'ARRAY_A');
167
168 if (is_array($result) && ! empty($result)) {
169 return array_map([PlanFactory::class, 'make'], $result);
170 }
171
172 return [];
173 }
174
175 public function get_count_by_status($status)
176 {
177 return $this->wpdb()->get_var(
178 $this->wpdb()->prepare(
179 "SELECT COUNT(id) FROM $this->table WHERE status = %s",
180 $status
181 )
182 );
183 }
184 }