1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
<?php // phpcs:ignoreFile
namespace AutomateWoo\Admin\Controllers;
use AutomateWoo\Clean; use AutomateWoo\Customer_Factory; use AutomateWoo\Guest_Factory; use AutomateWoo\Report_Guests; use AutomateWoo\Guest;
if ( ! defined( 'ABSPATH' ) ) exit;
/** * @class Guests */ class Guests extends Base {
function handle() {
$action = $this->get_current_action();
switch ( $action ) {
case 'view': $this->heading = __( 'Guest details', 'automatewoo' ); $this->output_view_single(); break;
case 'delete': $this->action_delete(); break;
case 'bulk_delete': $this->action_bulk_edit( str_replace( 'bulk_', '', $action ) ); $this->output_list_table(); break;
default: if ( aw_request( 'did-action' ) ) { $this->load_stored_responses(); } $this->output_list_table(); break; } }
function output_view_single() {
if ( ! $guest = $this->get_current_guest() ) { $this->output_no_guest(); }
$this->output_view( 'page-guest-details', [ 'guest' => $guest, 'customer' => Customer_Factory::get_by_guest_id( $guest->get_id() ) ] ); }
function output_no_guest() { wp_die( __( 'Missing guest data.', 'automatewoo' ) ); }
protected function output_list_table() { $table = new Report_Guests(); $table->prepare_items(); $table->nonce_action = $this->get_nonce_action();
$sidebar_content = '<p>' . __( 'Guest data is stored here when a customer places an order but does not create an account. ' . 'Or, if you have enabled pre-submit capturing, guest data can also be captured from a form on your website before an order is placed.', 'automatewoo' ) . '</p>';
$this->output_view( 'page-table-with-sidebar', [ 'table' => $table, 'sidebar_content' => $sidebar_content ]); }
/** * @param $action */ protected function action_bulk_edit( $action ) {
$this->verify_nonce_action();
$ids = Clean::ids( aw_request( 'guest_ids' ) );
if ( empty( $ids ) ) { $this->add_error( __( 'Please select some guests to bulk edit.', 'automatewoo' ) ); return; }
foreach ( $ids as $id ) {
if ( ! $guest = Guest_Factory::get( $id ) ) { continue; }
switch ( $action ) { case 'delete': $guest->delete(); break; } }
$this->add_message( __( 'Bulk edit completed.', 'automatewoo' ) ); }
/** * Delete guest action */ protected function action_delete() {
$this->verify_nonce_action();
if ( ! $guest = $this->get_current_guest() ) { $this->output_no_guest(); }
$guest->delete();
$this->add_message( __( 'Guest successfully deleted.', 'automatewoo' ) );
$this->redirect_after_action(); }
/** * @return Guest|false */ function get_current_guest() { return Guest_Factory::get( Clean::id( aw_request( 'guest_id' ) ) ); }
}
return new Guests();
|