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 / CouponRepository.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
CouponRepository.php
186 lines
1 <?php
2
3 namespace ProfilePress\Core\Membership\Repositories;
4
5 use ProfilePress\Core\Base;
6 use ProfilePress\Core\Membership\Models\Coupon\CouponEntity;
7 use ProfilePress\Core\Membership\Models\Coupon\CouponFactory;
8 use ProfilePress\Core\Membership\Models\ModelInterface;
9
10 class CouponRepository extends BaseRepository
11 {
12 protected $table;
13
14 public function __construct()
15 {
16 $this->table = Base::coupons_db_table();
17 }
18
19 /**
20 * @param CouponEntity $data
21 *
22 * @return false|int
23 */
24 public function add(ModelInterface $data)
25 {
26 $result = $this->wpdb()->insert(
27 $this->table,
28 array(
29 'code' => $data->code,
30 'description' => $data->description,
31 'coupon_type' => $data->coupon_type,
32 'coupon_application' => $data->coupon_application,
33 'is_onetime_use' => $data->is_onetime_use,
34 'amount' => $data->amount,
35 'unit' => $data->unit,
36 'plan_ids' => $data->plan_ids,
37 'usage_limit' => $data->usage_limit,
38 'status' => $data->status,
39 'start_date' => $data->start_date,
40 'end_date' => $data->end_date
41 ),
42 array(
43 '%s',
44 '%s',
45 '%s',
46 '%s',
47 '%s',
48 '%s',
49 '%s',
50 '%s',
51 '%d',
52 '%s',
53 '%s',
54 '%s',
55 )
56 );
57
58 return ! $result ? false : $this->wpdb()->insert_id;
59 }
60
61 /**
62 * @param CouponEntity $data
63 *
64 * @return false|int
65 */
66 public function update(ModelInterface $data)
67 {
68 $result = $this->wpdb()->update(
69 $this->table,
70 [
71 'code' => $data->code,
72 'description' => $data->description,
73 'coupon_type' => $data->coupon_type,
74 'coupon_application' => $data->coupon_application,
75 'is_onetime_use' => $data->is_onetime_use,
76 'amount' => $data->amount,
77 'unit' => $data->unit,
78 'plan_ids' => $data->plan_ids,
79 'usage_limit' => $data->usage_limit,
80 'status' => $data->status,
81 'start_date' => $data->start_date,
82 'end_date' => $data->end_date
83 ],
84 ['id' => $data->id],
85 [
86 '%s',
87 '%s',
88 '%s',
89 '%s',
90 '%s',
91 '%s',
92 '%s',
93 '%s',
94 '%d',
95 '%s',
96 '%s',
97 '%s',
98 ],
99 ['%d']
100 );
101
102 return $result === false ? false : $data->id;
103 }
104
105 /**
106 * @param $id
107 *
108 * @return int|false
109 */
110 public function delete($id)
111 {
112 return $this->wpdb()->delete($this->table, ['id' => $id], ['%d']);
113 }
114
115 /**
116 * @param $code
117 *
118 * @return CouponEntity
119 */
120 public function retrieveByCode($code)
121 {
122 $result = $this->wpdb()->get_row(
123 $this->wpdb()->prepare(
124 "SELECT * FROM $this->table WHERE code = %s",
125 $code
126 ),
127 ARRAY_A
128 );
129
130 if ( ! $result) $result = [];
131
132 return CouponFactory::make($result);
133 }
134
135 /**
136 * @param $id
137 *
138 * @return CouponEntity
139 */
140 public function retrieve($id)
141 {
142 $result = $this->wpdb()->get_row(
143 $this->wpdb()->prepare(
144 "SELECT * FROM $this->table WHERE id = %d",
145 $id
146 ),
147 ARRAY_A
148 );
149
150 if ( ! $result) $result = [];
151
152 return CouponFactory::make($result);
153 }
154
155 /**
156 * @param int $limit
157 * @param int $current_page
158 *
159 * @return CouponEntity[]|array
160 */
161 public function retrieveAll($limit = 0, $current_page = 1)
162 {
163 $replacement = [1];
164 $sql = "SELECT * FROM $this->table";
165 $sql .= " WHERE 1=%d"; // fixes Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder
166 $sql .= " ORDER BY id DESC";
167
168 if ($limit > 0) {
169 $sql .= " LIMIT %d";
170 $replacement[] = $limit;
171 }
172
173 if ($current_page > 1) {
174 $sql .= " OFFSET %d";
175 $replacement[] = ($current_page - 1) * $limit;
176 }
177
178 $result = $this->wpdb()->get_results($this->wpdb()->prepare($sql, $replacement), 'ARRAY_A');
179
180 if (is_array($result) && ! empty($result)) {
181 return array_map([CouponFactory::class, 'make'], $result);
182 }
183
184 return [];
185 }
186 }