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 / Admin / SettingsPages / Membership / CustomersPage / CustomerWPListTable.php
wp-user-avatar / src / Admin / SettingsPages / Membership / CustomersPage Last commit date
CustomerWPListTable.php 1 year ago SettingsPage.php 5 months ago index.php 3 years ago
CustomerWPListTable.php
345 lines
1 <?php
2
3 namespace ProfilePress\Core\Admin\SettingsPages\Membership\CustomersPage;
4
5 use ProfilePress\Core\Admin\SettingsPages\Membership\SubscriptionsPage\SubscriptionWPListTable;
6 use ProfilePress\Core\Membership\Models\Customer\CustomerEntity;
7 use ProfilePress\Core\Membership\Models\Customer\CustomerStatus;
8 use ProfilePress\Core\Membership\Models\Plan\PlanFactory;
9 use ProfilePress\Core\Membership\Models\Subscription\SubscriptionStatus;
10 use ProfilePress\Core\Membership\Repositories\CustomerRepository;
11 use ProfilePress\Core\Membership\Repositories\SubscriptionRepository;
12 use ProfilePress\Core\Membership\Services\CustomerService;
13 use ProfilePress\Core\Membership\Services\OrderService;
14 use ProfilePressVendor\Carbon\CarbonImmutable;
15
16 class CustomerWPListTable extends \WP_List_Table
17 {
18 private $views_count = [];
19
20 public function __construct()
21 {
22 parent::__construct([
23 'singular' => 'ppress-customer',
24 'plural' => 'ppress-customers',
25 'ajax' => false
26 ]);
27
28 $statuses = array_keys(CustomerStatus::get_all());
29 $statuses[] = 'all';
30
31 foreach ($statuses as $id) {
32
33 if ('all' == $id) {
34 $this->views_count[$id] = CustomerRepository::init()->record_count();
35 } else {
36 $this->views_count[$id] = CustomerRepository::init()->get_count_by_status($id);
37 }
38 }
39 }
40
41 public function no_items()
42 {
43 _e('No customers found.', 'wp-user-avatar');
44 }
45
46 public function get_columns()
47 {
48 $columns = [
49 'cb' => '<input type="checkbox" />',
50 'customer_name' => esc_html__('Name', 'wp-user-avatar'),
51 'customer_email' => esc_html__('Email', 'wp-user-avatar'),
52 'customer_subscriptions' => esc_html__('Active Subscriptions', 'wp-user-avatar'),
53 'customer_since' => esc_html__('Customer Since', 'wp-user-avatar'),
54 'customer_last_login' => esc_html__('Last Login', 'wp-user-avatar'),
55 ];
56
57 return $columns;
58 }
59
60 public static function delete_customer_url($customer_id)
61 {
62 $nonce_delete = wp_create_nonce('pp_customer_delete_rule');
63
64 return add_query_arg(['ppress_customer_action' => 'delete', 'id' => $customer_id, '_wpnonce' => $nonce_delete], PPRESS_MEMBERSHIP_CUSTOMERS_SETTINGS_PAGE);
65 }
66
67 public static function view_customer_url($customer_id)
68 {
69 return add_query_arg(['ppress_customer_action' => 'view', 'id' => $customer_id], PPRESS_MEMBERSHIP_CUSTOMERS_SETTINGS_PAGE);
70 }
71
72 /**
73 * @param CustomerEntity $customer
74 *
75 * @return string
76 */
77 public function column_customer_name($customer)
78 {
79 $customer_id = absint($customer->id);
80
81 $view_link = esc_url(self::view_customer_url($customer_id));
82 $orders_link = OrderService::init()->get_customer_orders_url($customer->id);
83 $subs_link = add_query_arg(['by_ci' => $customer_id], PPRESS_MEMBERSHIP_SUBSCRIPTIONS_SETTINGS_PAGE);
84
85 $actions = [
86 'view_customer' => sprintf('<a href="%s">%s</a>', $view_link, esc_html__('Edit', 'wp-user-avatar')),
87 'view_orders' => sprintf('<a href="%s">%s</a>', $orders_link, esc_html__('View Orders', 'wp-user-avatar')),
88 'view_subscriptions' => sprintf('<a href="%s">%s</a>', $subs_link, esc_html__('View Subscriptions', 'wp-user-avatar')),
89 ];
90
91 $customer_name = $customer->get_name();
92
93 $title = sprintf('<a class="row-title" href="%s">%s</a>', $view_link, $customer_name);
94
95 return $title . $this->row_actions($actions);
96 }
97
98 /**
99 * @param CustomerEntity $customer
100 *
101 * @return string
102 */
103 public function column_customer_email($customer)
104 {
105 return ! empty($customer->get_email()) ? $customer->get_email() : '&mdash;&mdash;&mdash;';
106 }
107
108 /**
109 * @param CustomerEntity $customer
110 *
111 * @return string
112 */
113 public function column_customer_since($customer)
114 {
115 return $customer->get_date_created();
116 }
117
118 /**
119 * @param CustomerEntity $customer
120 *
121 * @return string
122 */
123 public function column_customer_last_login($customer)
124 {
125 $data = $customer->get_last_login();
126
127 return ! empty($data) ? $data : '&mdash;&mdash;&mdash;';
128 }
129
130 /**
131 * @param CustomerEntity $customer
132 *
133 * @return string
134 */
135 public function column_customer_subscriptions($customer)
136 {
137 $subs = $customer->get_active_subscriptions();
138
139 if (empty($subs)) return '&mdash;&mdash;&mdash;';
140
141 $subs = array_map(function ($sub) {
142
143 return sprintf(
144 '<a target="_blank" href="%s">%s</a>',
145 SubscriptionWPListTable::view_edit_subscription_url($sub->id),
146 PlanFactory::fromId($sub->get_plan_id())->get_name()
147 );
148 }, $subs);
149
150 return sprintf('%s', implode(', ', $subs));
151 }
152
153 public function get_views()
154 {
155 $views = [];
156
157 $args = ['all' => esc_html__('All', 'wp-user-avatar')] + CustomerStatus::get_all();
158
159 foreach ($args as $id => $status) {
160
161 $url = $id == 'all' ? PPRESS_MEMBERSHIP_CUSTOMERS_SETTINGS_PAGE : add_query_arg(['status' => $id], PPRESS_MEMBERSHIP_CUSTOMERS_SETTINGS_PAGE);
162
163 $views[$id] = sprintf(
164 '<a href="%s"%s>%s <span class="count">(%s)</span></a>',
165 $url,
166 ppressGET_var('status', 'all') == $id ? ' class="current"' : '',
167 $status,
168 $this->views_count[$id]
169 );
170 }
171
172 return $views;
173 }
174
175 /**
176 * Render the bulk edit checkbox
177 *
178 * @param CustomerEntity $customer
179 *
180 * @return string
181 */
182 public function column_cb($customer)
183 {
184 return sprintf('<input type="checkbox" name="customer_id[]" value="%s" />', $customer->id);
185 }
186
187 public function record_count()
188 {
189 $status = ppressGET_var('status', 'all');
190
191 if ($status != 'all') {
192 return $this->views_count[$status];
193 }
194
195 return SubscriptionRepository::init()->record_count();
196 }
197
198 public function prepare_items()
199 {
200 $this->_column_headers = $this->get_column_info();
201
202 $this->process_bulk_action();
203
204 $per_page = $this->get_items_per_page('customers_per_page', 10);
205 $current_page = $this->get_pagenum();
206 $offset = ($current_page - 1) * $per_page;
207
208 $search = ! empty($_GET['s']) ? sanitize_text_field($_GET['s']) : '';
209
210 $start_date = ppressGET_var('start_date');
211 $end_date = ppressGET_var('end_date');
212 $status = ppressGET_var('status');
213
214 $query_args = [
215 'number' => $per_page,
216 'offset' => $offset,
217 'search' => $search,
218 'status' => $status
219 ];
220
221 if ( ! empty($start_date)) {
222 $query_args['start_date'] = CarbonImmutable::parse($start_date, wp_timezone())->startOfDay()->utc()->toDateTimeString();
223 }
224
225 if ( ! empty($end_date)) {
226 $query_args['end_date'] = CarbonImmutable::parse($end_date, wp_timezone())->endOfDay()->utc()->toDateTimeString();
227 }
228
229 $this->items = CustomerRepository::init()->retrieveBy($query_args);
230
231 $total_items = CustomerRepository::init()->retrieveBy($query_args, true);
232
233 $this->set_pagination_args([
234 'total_items' => $total_items,
235 'per_page' => $per_page
236 ]);
237 }
238
239 public function current_action()
240 {
241 if (isset($_REQUEST['filter_action']) && ! empty($_REQUEST['filter_action'])) {
242 return false;
243 }
244
245 if (isset($_REQUEST['action']) && -1 != $_REQUEST['action']) {
246 return $_REQUEST['action'];
247 }
248
249 if (isset($_REQUEST['ppress_customer_action']) && -1 != $_REQUEST['ppress_customer_action']) {
250 return $_REQUEST['ppress_customer_action'];
251 }
252
253 return false;
254 }
255
256 public function get_bulk_actions()
257 {
258 $actions = [
259 'bulk-delete' => esc_html__('Delete', 'wp-user-avatar')
260 ];
261
262 return $actions;
263 }
264
265 public function process_bulk_action()
266 {
267 $customer_id = absint(ppress_var($_GET, 'id', 0));
268
269 if ( ! current_user_can('manage_options')) return;
270
271 if ('delete' === $this->current_action()) {
272
273 check_admin_referer('pp_customer_delete_rule');
274
275 if ( ! current_user_can('manage_options')) return;
276
277 CustomerService::init()->delete_customer($customer_id);
278 }
279
280 if ('bulk-delete' === $this->current_action()) {
281
282 check_admin_referer('bulk-' . $this->_args['plural']);
283
284 if ( ! current_user_can('manage_options')) return;
285
286 $customer_ids = array_map('absint', $_GET['customer_id']);
287
288 foreach ($customer_ids as $customer_id) {
289 CustomerService::init()->delete_customer($customer_id);
290 }
291 }
292
293 if ($this->current_action() !== false) {
294 ppress_do_admin_redirect(PPRESS_MEMBERSHIP_CUSTOMERS_SETTINGS_PAGE);
295 }
296 }
297
298 public function filter_bar()
299 {
300 $start_date = isset($_GET['start_date']) ? sanitize_text_field($_GET['start_date']) : null;
301 $end_date = isset($_GET['end_date']) ? sanitize_text_field($_GET['end_date']) : null;
302
303 $status = ppressGET_var('status');
304 $clear_url = PPRESS_MEMBERSHIP_CUSTOMERS_SETTINGS_PAGE;
305
306 echo '<div class="wp-filter" id="ppress-filters">';
307 echo '<div class="filter-items">';
308 ?>
309
310 <span id="ppress-date-filters" class="ppress-from-to-wrapper">
311 <span class="ppress-start-date-wrap">
312 <input type="text" name="start_date" id="start-date" placeholder="<?= _x('From', 'date filter', 'wp-user-avatar') ?>" value="<?= $start_date ?>" class="ppress_datepicker">
313 </span>
314 <span id="ppress-end-date-wrap">
315 <input type="text" name="end_date" id="end-date" value="<?= $end_date ?>" placeholder="<?= _x('To', 'date filter', 'wp-user-avatar') ?>" class="ppress_datepicker">
316 </span>
317 </span>
318
319 <span id="ppress-after-core-filters">
320 <input type="submit" class="button button-secondary" value="<?php esc_html_e('Filter', 'wp-user-avatar'); ?>"/>
321
322 <?php if ( ! empty($_GET['s']) || ! empty($start_date) || ! empty($end_date)) : ?>
323 <a href="<?php echo esc_url($clear_url); ?>" class="button-secondary">
324 <?php esc_html_e('Clear', 'wp-user-avatar'); ?>
325 </a>
326 <?php endif; ?>
327 </span>
328
329 <?php if ( ! empty($status)) : ?>
330 <input type="hidden" name="status" value="<?php echo esc_attr($status); ?>"/>
331 <?php endif;
332 echo '</div>';
333 $this->search_box(__('Search Customers', 'wp-user-avatar'), 'ppress_customer_search');
334 echo '</div>';
335 }
336
337 /**
338 * @return array List of CSS classes for the table tag.
339 */
340 public function get_table_classes()
341 {
342 return array('widefat', 'fixed', 'striped', 'customer', 'ppview');
343 }
344 }
345