@@ -17,252 +17,252 @@ |
||
17 | 17 | |
18 | 18 | class ExpiredTransactionCheck extends CronJob |
19 | 19 | { |
20 | - private ?EE_Payment_Processor $payment_processor = null; |
|
21 | - |
|
22 | - private ?EE_Transaction_Processor $transaction_processor = null; |
|
23 | - |
|
24 | - /** |
|
25 | - * array of TXN IDs |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected array $expired_transactions = []; |
|
30 | - |
|
31 | - |
|
32 | - private function loadTransactionProcessor() |
|
33 | - { |
|
34 | - $this->transaction_processor = $this->loader->getShared(EE_Transaction_Processor::class); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - private function loadPaymentProcessor() |
|
39 | - { |
|
40 | - $this->payment_processor = $this->loader->getShared(EE_Payment_Processor::class); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - public function setHooks(): void |
|
45 | - { |
|
46 | - add_action( |
|
47 | - 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
48 | - [$this, 'expiredTransactionCheck'] |
|
49 | - ); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * schedule_expired_transaction_check |
|
55 | - * sets a wp_schedule_single_event() for following up on TXNs after their session has expired |
|
56 | - * |
|
57 | - * @param int $timestamp |
|
58 | - * @param int $TXN_ID |
|
59 | - */ |
|
60 | - public static function scheduleExpiredTransactionCheck( |
|
61 | - int $timestamp, |
|
62 | - int $TXN_ID |
|
63 | - ): void { |
|
64 | - // validate $TXN_ID and $timestamp |
|
65 | - $TXN_ID = absint($TXN_ID); |
|
66 | - $timestamp = absint($timestamp); |
|
67 | - if ($TXN_ID && $timestamp) { |
|
68 | - wp_schedule_single_event( |
|
69 | - $timestamp, |
|
70 | - 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
71 | - [$TXN_ID] |
|
72 | - ); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * this is the callback for the action hook: |
|
79 | - * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check' |
|
80 | - * which is utilized by wp_schedule_single_event() |
|
81 | - * in \EED_Single_Page_Checkout::_initialize_transaction(). |
|
82 | - * The passed TXN_ID gets added to an array, and then the |
|
83 | - * process_expired_transactions() function is hooked into |
|
84 | - * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
85 | - * processing of any failed transactions, because doing so now would be |
|
86 | - * too early and the required resources may not be available |
|
87 | - * |
|
88 | - * @param int $TXN_ID |
|
89 | - */ |
|
90 | - public function expiredTransactionCheck(int $TXN_ID = 0): void |
|
91 | - { |
|
92 | - if (absint($TXN_ID)) { |
|
93 | - $this->expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
94 | - add_action( |
|
95 | - 'shutdown', |
|
96 | - [$this, 'processExpiredTransactions'], |
|
97 | - 5 |
|
98 | - ); |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * loops through the $this->expired_transactions array and processes any failed TXNs |
|
105 | - * |
|
106 | - * @throws EE_Error |
|
107 | - * @throws ReflectionException |
|
108 | - * @throws DomainException |
|
109 | - * @throws RuntimeException |
|
110 | - */ |
|
111 | - public function processExpiredTransactions(): void |
|
112 | - { |
|
113 | - if ( |
|
114 | - // are there any TXNs that need cleaning up ? |
|
115 | - empty($this->expired_transactions) |
|
116 | - // reschedule the cron if we can't hit the db right now |
|
117 | - || CronUtilities::rescheduleCronForTransactions( |
|
118 | - [ExpiredTransactionCheck::class, 'scheduleExpiredTransactionCheck'], |
|
119 | - $this->expired_transactions |
|
120 | - ) |
|
121 | - ) { |
|
122 | - return; |
|
123 | - } |
|
124 | - $this->loadTransactionProcessor(); |
|
125 | - // set revisit flag for txn processor |
|
126 | - $this->transaction_processor->set_revisit(); |
|
127 | - foreach ($this->expired_transactions as $TXN_ID) { |
|
128 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
129 | - // verify transaction and whether it is failed or not |
|
130 | - if ($transaction instanceof EE_Transaction) { |
|
131 | - switch ($transaction->status_ID()) { |
|
132 | - |
|
133 | - case EEM_Transaction::complete_status_code: |
|
134 | - $this->processCompletedTransaction($transaction); |
|
135 | - break; |
|
136 | - |
|
137 | - case EEM_Transaction::overpaid_status_code: |
|
138 | - $this->processOverpaidTransaction($transaction); |
|
139 | - break; |
|
140 | - |
|
141 | - case EEM_Transaction::incomplete_status_code: |
|
142 | - $this->processIncompletedTransaction($transaction); |
|
143 | - break; |
|
144 | - |
|
145 | - case EEM_Transaction::abandoned_status_code: |
|
146 | - $this->processAbandonedTransaction($transaction); |
|
147 | - break; |
|
148 | - |
|
149 | - case EEM_Transaction::failed_status_code: |
|
150 | - $this->processFailedTransaction($transaction); |
|
151 | - break; |
|
152 | - } |
|
153 | - } |
|
154 | - unset($this->expired_transactions[ $TXN_ID ]); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * @param EE_Transaction $transaction |
|
161 | - * @return void |
|
162 | - * @throws EE_Error |
|
163 | - * @throws ReflectionException |
|
164 | - */ |
|
165 | - private function processCompletedTransaction(EE_Transaction $transaction) |
|
166 | - { |
|
167 | - // Don't update the transaction/registrations if the Primary Registration is Not Approved. |
|
168 | - $primary_registration = $transaction->primary_registration(); |
|
169 | - if ( |
|
170 | - $primary_registration instanceof EE_Registration |
|
171 | - && $primary_registration->status_ID() !== RegStatus::AWAITING_REVIEW |
|
172 | - ) { |
|
173 | - $this->transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
174 | - $transaction, |
|
175 | - $transaction->last_payment() |
|
176 | - ); |
|
177 | - do_action( |
|
178 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', |
|
179 | - $transaction |
|
180 | - ); |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @param EE_Transaction $transaction |
|
187 | - * @return void |
|
188 | - */ |
|
189 | - private function processOverpaidTransaction(EE_Transaction $transaction) |
|
190 | - { |
|
191 | - do_action( |
|
192 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', |
|
193 | - $transaction |
|
194 | - ); |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * @param EE_Transaction $transaction |
|
200 | - * @return void |
|
201 | - */ |
|
202 | - private function processIncompletedTransaction(EE_Transaction $transaction) |
|
203 | - { |
|
204 | - do_action( |
|
205 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
206 | - $transaction |
|
207 | - ); |
|
208 | - // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @param EE_Transaction $transaction |
|
214 | - * @return void |
|
215 | - * @throws EE_Error |
|
216 | - * @throws ReflectionException |
|
217 | - */ |
|
218 | - private function processAbandonedTransaction(EE_Transaction $transaction) |
|
219 | - { |
|
220 | - // run hook before updating transaction, primarily so |
|
221 | - // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets |
|
222 | - do_action( |
|
223 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
224 | - $transaction |
|
225 | - ); |
|
226 | - // don't finalize the TXN if it has already been completed |
|
227 | - if ($transaction->all_reg_steps_completed() !== true) { |
|
228 | - $this->loadPaymentProcessor(); |
|
229 | - // let's simulate an IPN here which will trigger any notifications that need to go out |
|
230 | - $this->payment_processor->update_txn_based_on_payment( |
|
231 | - $transaction, |
|
232 | - $transaction->last_payment(), |
|
233 | - true, |
|
234 | - true |
|
235 | - ); |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * @param EE_Transaction $transaction |
|
242 | - * @return void |
|
243 | - */ |
|
244 | - private function processFailedTransaction(EE_Transaction $transaction) |
|
245 | - { |
|
246 | - do_action( |
|
247 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
248 | - $transaction |
|
249 | - ); |
|
250 | - // todo : |
|
251 | - // perform garbage collection here and remove clean_out_junk_transactions() |
|
252 | - // $registrations = $transaction->registrations(); |
|
253 | - // if (! empty($registrations)) { |
|
254 | - // foreach ($registrations as $registration) { |
|
255 | - // if ($registration instanceof EE_Registration) { |
|
256 | - // $delete_registration = true; |
|
257 | - // if ($registration->attendee() instanceof EE_Attendee) { |
|
258 | - // $delete_registration = false; |
|
259 | - // } |
|
260 | - // if ($delete_registration) { |
|
261 | - // $registration->delete_permanently(); |
|
262 | - // $registration->delete_related_permanently(); |
|
263 | - // } |
|
264 | - // } |
|
265 | - // } |
|
266 | - // } |
|
267 | - } |
|
20 | + private ?EE_Payment_Processor $payment_processor = null; |
|
21 | + |
|
22 | + private ?EE_Transaction_Processor $transaction_processor = null; |
|
23 | + |
|
24 | + /** |
|
25 | + * array of TXN IDs |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected array $expired_transactions = []; |
|
30 | + |
|
31 | + |
|
32 | + private function loadTransactionProcessor() |
|
33 | + { |
|
34 | + $this->transaction_processor = $this->loader->getShared(EE_Transaction_Processor::class); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + private function loadPaymentProcessor() |
|
39 | + { |
|
40 | + $this->payment_processor = $this->loader->getShared(EE_Payment_Processor::class); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + public function setHooks(): void |
|
45 | + { |
|
46 | + add_action( |
|
47 | + 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
48 | + [$this, 'expiredTransactionCheck'] |
|
49 | + ); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * schedule_expired_transaction_check |
|
55 | + * sets a wp_schedule_single_event() for following up on TXNs after their session has expired |
|
56 | + * |
|
57 | + * @param int $timestamp |
|
58 | + * @param int $TXN_ID |
|
59 | + */ |
|
60 | + public static function scheduleExpiredTransactionCheck( |
|
61 | + int $timestamp, |
|
62 | + int $TXN_ID |
|
63 | + ): void { |
|
64 | + // validate $TXN_ID and $timestamp |
|
65 | + $TXN_ID = absint($TXN_ID); |
|
66 | + $timestamp = absint($timestamp); |
|
67 | + if ($TXN_ID && $timestamp) { |
|
68 | + wp_schedule_single_event( |
|
69 | + $timestamp, |
|
70 | + 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
71 | + [$TXN_ID] |
|
72 | + ); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * this is the callback for the action hook: |
|
79 | + * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check' |
|
80 | + * which is utilized by wp_schedule_single_event() |
|
81 | + * in \EED_Single_Page_Checkout::_initialize_transaction(). |
|
82 | + * The passed TXN_ID gets added to an array, and then the |
|
83 | + * process_expired_transactions() function is hooked into |
|
84 | + * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
85 | + * processing of any failed transactions, because doing so now would be |
|
86 | + * too early and the required resources may not be available |
|
87 | + * |
|
88 | + * @param int $TXN_ID |
|
89 | + */ |
|
90 | + public function expiredTransactionCheck(int $TXN_ID = 0): void |
|
91 | + { |
|
92 | + if (absint($TXN_ID)) { |
|
93 | + $this->expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
94 | + add_action( |
|
95 | + 'shutdown', |
|
96 | + [$this, 'processExpiredTransactions'], |
|
97 | + 5 |
|
98 | + ); |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * loops through the $this->expired_transactions array and processes any failed TXNs |
|
105 | + * |
|
106 | + * @throws EE_Error |
|
107 | + * @throws ReflectionException |
|
108 | + * @throws DomainException |
|
109 | + * @throws RuntimeException |
|
110 | + */ |
|
111 | + public function processExpiredTransactions(): void |
|
112 | + { |
|
113 | + if ( |
|
114 | + // are there any TXNs that need cleaning up ? |
|
115 | + empty($this->expired_transactions) |
|
116 | + // reschedule the cron if we can't hit the db right now |
|
117 | + || CronUtilities::rescheduleCronForTransactions( |
|
118 | + [ExpiredTransactionCheck::class, 'scheduleExpiredTransactionCheck'], |
|
119 | + $this->expired_transactions |
|
120 | + ) |
|
121 | + ) { |
|
122 | + return; |
|
123 | + } |
|
124 | + $this->loadTransactionProcessor(); |
|
125 | + // set revisit flag for txn processor |
|
126 | + $this->transaction_processor->set_revisit(); |
|
127 | + foreach ($this->expired_transactions as $TXN_ID) { |
|
128 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
129 | + // verify transaction and whether it is failed or not |
|
130 | + if ($transaction instanceof EE_Transaction) { |
|
131 | + switch ($transaction->status_ID()) { |
|
132 | + |
|
133 | + case EEM_Transaction::complete_status_code: |
|
134 | + $this->processCompletedTransaction($transaction); |
|
135 | + break; |
|
136 | + |
|
137 | + case EEM_Transaction::overpaid_status_code: |
|
138 | + $this->processOverpaidTransaction($transaction); |
|
139 | + break; |
|
140 | + |
|
141 | + case EEM_Transaction::incomplete_status_code: |
|
142 | + $this->processIncompletedTransaction($transaction); |
|
143 | + break; |
|
144 | + |
|
145 | + case EEM_Transaction::abandoned_status_code: |
|
146 | + $this->processAbandonedTransaction($transaction); |
|
147 | + break; |
|
148 | + |
|
149 | + case EEM_Transaction::failed_status_code: |
|
150 | + $this->processFailedTransaction($transaction); |
|
151 | + break; |
|
152 | + } |
|
153 | + } |
|
154 | + unset($this->expired_transactions[ $TXN_ID ]); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * @param EE_Transaction $transaction |
|
161 | + * @return void |
|
162 | + * @throws EE_Error |
|
163 | + * @throws ReflectionException |
|
164 | + */ |
|
165 | + private function processCompletedTransaction(EE_Transaction $transaction) |
|
166 | + { |
|
167 | + // Don't update the transaction/registrations if the Primary Registration is Not Approved. |
|
168 | + $primary_registration = $transaction->primary_registration(); |
|
169 | + if ( |
|
170 | + $primary_registration instanceof EE_Registration |
|
171 | + && $primary_registration->status_ID() !== RegStatus::AWAITING_REVIEW |
|
172 | + ) { |
|
173 | + $this->transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
174 | + $transaction, |
|
175 | + $transaction->last_payment() |
|
176 | + ); |
|
177 | + do_action( |
|
178 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', |
|
179 | + $transaction |
|
180 | + ); |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @param EE_Transaction $transaction |
|
187 | + * @return void |
|
188 | + */ |
|
189 | + private function processOverpaidTransaction(EE_Transaction $transaction) |
|
190 | + { |
|
191 | + do_action( |
|
192 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', |
|
193 | + $transaction |
|
194 | + ); |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * @param EE_Transaction $transaction |
|
200 | + * @return void |
|
201 | + */ |
|
202 | + private function processIncompletedTransaction(EE_Transaction $transaction) |
|
203 | + { |
|
204 | + do_action( |
|
205 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
206 | + $transaction |
|
207 | + ); |
|
208 | + // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @param EE_Transaction $transaction |
|
214 | + * @return void |
|
215 | + * @throws EE_Error |
|
216 | + * @throws ReflectionException |
|
217 | + */ |
|
218 | + private function processAbandonedTransaction(EE_Transaction $transaction) |
|
219 | + { |
|
220 | + // run hook before updating transaction, primarily so |
|
221 | + // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets |
|
222 | + do_action( |
|
223 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
224 | + $transaction |
|
225 | + ); |
|
226 | + // don't finalize the TXN if it has already been completed |
|
227 | + if ($transaction->all_reg_steps_completed() !== true) { |
|
228 | + $this->loadPaymentProcessor(); |
|
229 | + // let's simulate an IPN here which will trigger any notifications that need to go out |
|
230 | + $this->payment_processor->update_txn_based_on_payment( |
|
231 | + $transaction, |
|
232 | + $transaction->last_payment(), |
|
233 | + true, |
|
234 | + true |
|
235 | + ); |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * @param EE_Transaction $transaction |
|
242 | + * @return void |
|
243 | + */ |
|
244 | + private function processFailedTransaction(EE_Transaction $transaction) |
|
245 | + { |
|
246 | + do_action( |
|
247 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
248 | + $transaction |
|
249 | + ); |
|
250 | + // todo : |
|
251 | + // perform garbage collection here and remove clean_out_junk_transactions() |
|
252 | + // $registrations = $transaction->registrations(); |
|
253 | + // if (! empty($registrations)) { |
|
254 | + // foreach ($registrations as $registration) { |
|
255 | + // if ($registration instanceof EE_Registration) { |
|
256 | + // $delete_registration = true; |
|
257 | + // if ($registration->attendee() instanceof EE_Attendee) { |
|
258 | + // $delete_registration = false; |
|
259 | + // } |
|
260 | + // if ($delete_registration) { |
|
261 | + // $registration->delete_permanently(); |
|
262 | + // $registration->delete_related_permanently(); |
|
263 | + // } |
|
264 | + // } |
|
265 | + // } |
|
266 | + // } |
|
267 | + } |
|
268 | 268 | } |
@@ -19,55 +19,55 @@ |
||
19 | 19 | */ |
20 | 20 | class CancelRegistrationService |
21 | 21 | { |
22 | - /** |
|
23 | - * @var CancelTicketLineItemService $cancel_ticket_line_item_service |
|
24 | - */ |
|
25 | - private $cancel_ticket_line_item_service; |
|
22 | + /** |
|
23 | + * @var CancelTicketLineItemService $cancel_ticket_line_item_service |
|
24 | + */ |
|
25 | + private $cancel_ticket_line_item_service; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * Command constructor |
|
30 | - * |
|
31 | - * @param CancelTicketLineItemService $cancel_ticket_line_item_service |
|
32 | - */ |
|
33 | - public function __construct(CancelTicketLineItemService $cancel_ticket_line_item_service) |
|
34 | - { |
|
35 | - $this->cancel_ticket_line_item_service = $cancel_ticket_line_item_service; |
|
36 | - } |
|
28 | + /** |
|
29 | + * Command constructor |
|
30 | + * |
|
31 | + * @param CancelTicketLineItemService $cancel_ticket_line_item_service |
|
32 | + */ |
|
33 | + public function __construct(CancelTicketLineItemService $cancel_ticket_line_item_service) |
|
34 | + { |
|
35 | + $this->cancel_ticket_line_item_service = $cancel_ticket_line_item_service; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @param EE_Registration $registration |
|
41 | - * @param bool $cancel_ticket_line_item |
|
42 | - * @throws EE_Error |
|
43 | - * @throws ReflectionException |
|
44 | - */ |
|
45 | - public function cancelRegistrationAndTicketLineItem(EE_Registration $registration, $cancel_ticket_line_item = true) |
|
46 | - { |
|
47 | - // first cancel the original line item for the registration's ticket |
|
48 | - if ($cancel_ticket_line_item) { |
|
49 | - $this->cancel_ticket_line_item_service->forRegistration($registration); |
|
50 | - } |
|
51 | - $this->cancelRegistrationOnly($registration); |
|
52 | - } |
|
39 | + /** |
|
40 | + * @param EE_Registration $registration |
|
41 | + * @param bool $cancel_ticket_line_item |
|
42 | + * @throws EE_Error |
|
43 | + * @throws ReflectionException |
|
44 | + */ |
|
45 | + public function cancelRegistrationAndTicketLineItem(EE_Registration $registration, $cancel_ticket_line_item = true) |
|
46 | + { |
|
47 | + // first cancel the original line item for the registration's ticket |
|
48 | + if ($cancel_ticket_line_item) { |
|
49 | + $this->cancel_ticket_line_item_service->forRegistration($registration); |
|
50 | + } |
|
51 | + $this->cancelRegistrationOnly($registration); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * @param EE_Registration $registration |
|
57 | - * @throws EE_Error |
|
58 | - * @throws ReflectionException |
|
59 | - */ |
|
60 | - public function cancelRegistrationOnly(EE_Registration $registration) |
|
61 | - { |
|
62 | - // now cancel the registration itself |
|
63 | - $registration->set_status( |
|
64 | - RegStatus::CANCELLED, |
|
65 | - false, |
|
66 | - new Context( |
|
67 | - __METHOD__, |
|
68 | - esc_html__('Executed when a registration is cancelled.', 'event_espresso') |
|
69 | - ) |
|
70 | - ); |
|
71 | - $registration->save(); |
|
72 | - } |
|
55 | + /** |
|
56 | + * @param EE_Registration $registration |
|
57 | + * @throws EE_Error |
|
58 | + * @throws ReflectionException |
|
59 | + */ |
|
60 | + public function cancelRegistrationOnly(EE_Registration $registration) |
|
61 | + { |
|
62 | + // now cancel the registration itself |
|
63 | + $registration->set_status( |
|
64 | + RegStatus::CANCELLED, |
|
65 | + false, |
|
66 | + new Context( |
|
67 | + __METHOD__, |
|
68 | + esc_html__('Executed when a registration is cancelled.', 'event_espresso') |
|
69 | + ) |
|
70 | + ); |
|
71 | + $registration->save(); |
|
72 | + } |
|
73 | 73 | } |
@@ -30,233 +30,233 @@ |
||
30 | 30 | */ |
31 | 31 | class RegForm extends EE_Form_Section_Proper |
32 | 32 | { |
33 | - public EE_Registration_Config $reg_config; |
|
33 | + public EE_Registration_Config $reg_config; |
|
34 | 34 | |
35 | - public EE_SPCO_Reg_Step_Attendee_Information $reg_step; |
|
35 | + public EE_SPCO_Reg_Step_Attendee_Information $reg_step; |
|
36 | 36 | |
37 | - private bool $print_copy_info = false; |
|
37 | + private bool $print_copy_info = false; |
|
38 | 38 | |
39 | - protected int $reg_form_count = 0; |
|
39 | + protected int $reg_form_count = 0; |
|
40 | 40 | |
41 | - private array $required_questions = []; |
|
41 | + private array $required_questions = []; |
|
42 | 42 | |
43 | - private array $template_args = []; |
|
43 | + private array $template_args = []; |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * RegForm constructor. |
|
48 | - * |
|
49 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
50 | - * @param EE_Registration_Config $reg_config |
|
51 | - * @throws ReflectionException |
|
52 | - * @throws EE_Error |
|
53 | - */ |
|
54 | - public function __construct( |
|
55 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
56 | - EE_Registration_Config $reg_config |
|
57 | - ) { |
|
58 | - $this->reg_step = $reg_step; |
|
59 | - $this->reg_config = $reg_config; |
|
60 | - // setup some classes so that they are ready for loading during construction of other classes |
|
61 | - LoaderFactory::getShared(CountryOptions::class, [$this->reg_step->checkout->action]); |
|
62 | - LoaderFactory::getShared(StateOptions::class, [$this->reg_step->checkout->action]); |
|
63 | - LoaderFactory::getShared(RegFormQuestionFactory::class, [[$this, 'addRequiredQuestion']]); |
|
64 | - parent::__construct( |
|
65 | - [ |
|
66 | - 'name' => $this->reg_step->reg_form_name(), |
|
67 | - 'html_id' => $this->reg_step->reg_form_name(), |
|
68 | - 'subsections' => $this->generateSubsections(), |
|
69 | - 'layout_strategy' => new EE_Template_Layout( |
|
70 | - [ |
|
71 | - 'layout_template_file' => $this->reg_step->template(), // layout_template |
|
72 | - 'template_args' => $this->template_args, |
|
73 | - ] |
|
74 | - ), |
|
75 | - ] |
|
76 | - ); |
|
77 | - } |
|
46 | + /** |
|
47 | + * RegForm constructor. |
|
48 | + * |
|
49 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
50 | + * @param EE_Registration_Config $reg_config |
|
51 | + * @throws ReflectionException |
|
52 | + * @throws EE_Error |
|
53 | + */ |
|
54 | + public function __construct( |
|
55 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
56 | + EE_Registration_Config $reg_config |
|
57 | + ) { |
|
58 | + $this->reg_step = $reg_step; |
|
59 | + $this->reg_config = $reg_config; |
|
60 | + // setup some classes so that they are ready for loading during construction of other classes |
|
61 | + LoaderFactory::getShared(CountryOptions::class, [$this->reg_step->checkout->action]); |
|
62 | + LoaderFactory::getShared(StateOptions::class, [$this->reg_step->checkout->action]); |
|
63 | + LoaderFactory::getShared(RegFormQuestionFactory::class, [[$this, 'addRequiredQuestion']]); |
|
64 | + parent::__construct( |
|
65 | + [ |
|
66 | + 'name' => $this->reg_step->reg_form_name(), |
|
67 | + 'html_id' => $this->reg_step->reg_form_name(), |
|
68 | + 'subsections' => $this->generateSubsections(), |
|
69 | + 'layout_strategy' => new EE_Template_Layout( |
|
70 | + [ |
|
71 | + 'layout_template_file' => $this->reg_step->template(), // layout_template |
|
72 | + 'template_args' => $this->template_args, |
|
73 | + ] |
|
74 | + ), |
|
75 | + ] |
|
76 | + ); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * @return void |
|
82 | - */ |
|
83 | - public function enablePrintCopyInfo(): void |
|
84 | - { |
|
85 | - $this->print_copy_info = true; |
|
86 | - } |
|
80 | + /** |
|
81 | + * @return void |
|
82 | + */ |
|
83 | + public function enablePrintCopyInfo(): void |
|
84 | + { |
|
85 | + $this->print_copy_info = true; |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function printCopyInfo(): bool |
|
93 | - { |
|
94 | - return $this->print_copy_info; |
|
95 | - } |
|
89 | + /** |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function printCopyInfo(): bool |
|
93 | + { |
|
94 | + return $this->print_copy_info; |
|
95 | + } |
|
96 | 96 | |
97 | 97 | |
98 | - /** |
|
99 | - * @return int |
|
100 | - */ |
|
101 | - public function regFormCount(): int |
|
102 | - { |
|
103 | - return $this->reg_form_count; |
|
104 | - } |
|
98 | + /** |
|
99 | + * @return int |
|
100 | + */ |
|
101 | + public function regFormCount(): int |
|
102 | + { |
|
103 | + return $this->reg_form_count; |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | - /** |
|
108 | - * @return array |
|
109 | - */ |
|
110 | - public function requiredQuestions(): array |
|
111 | - { |
|
112 | - return $this->required_questions; |
|
113 | - } |
|
107 | + /** |
|
108 | + * @return array |
|
109 | + */ |
|
110 | + public function requiredQuestions(): array |
|
111 | + { |
|
112 | + return $this->required_questions; |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * @param string $identifier |
|
118 | - * @param string $required_question |
|
119 | - */ |
|
120 | - public function addRequiredQuestion(string $identifier, string $required_question): void |
|
121 | - { |
|
122 | - $this->required_questions[ $identifier ] = $required_question; |
|
123 | - } |
|
116 | + /** |
|
117 | + * @param string $identifier |
|
118 | + * @param string $required_question |
|
119 | + */ |
|
120 | + public function addRequiredQuestion(string $identifier, string $required_question): void |
|
121 | + { |
|
122 | + $this->required_questions[ $identifier ] = $required_question; |
|
123 | + } |
|
124 | 124 | |
125 | 125 | |
126 | - /** |
|
127 | - * @return EE_Form_Section_Proper[] |
|
128 | - * @throws DomainException |
|
129 | - * @throws EE_Error |
|
130 | - * @throws InvalidArgumentException |
|
131 | - * @throws ReflectionException |
|
132 | - * @throws EntityNotFoundException |
|
133 | - * @throws InvalidDataTypeException |
|
134 | - * @throws InvalidInterfaceException |
|
135 | - */ |
|
136 | - private function generateSubsections(): array |
|
137 | - { |
|
138 | - // Init reg forms count. |
|
139 | - $this->reg_form_count = 0; |
|
126 | + /** |
|
127 | + * @return EE_Form_Section_Proper[] |
|
128 | + * @throws DomainException |
|
129 | + * @throws EE_Error |
|
130 | + * @throws InvalidArgumentException |
|
131 | + * @throws ReflectionException |
|
132 | + * @throws EntityNotFoundException |
|
133 | + * @throws InvalidDataTypeException |
|
134 | + * @throws InvalidInterfaceException |
|
135 | + */ |
|
136 | + private function generateSubsections(): array |
|
137 | + { |
|
138 | + // Init reg forms count. |
|
139 | + $this->reg_form_count = 0; |
|
140 | 140 | |
141 | - $primary_registrant = null; |
|
142 | - // autoload Line_Item_Display classes |
|
143 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
144 | - $Line_Item_Display = new EE_Line_Item_Display(); |
|
145 | - // calculate taxes |
|
146 | - $Line_Item_Display->display_line_item( |
|
147 | - $this->reg_step->checkout->cart->get_grand_total(), |
|
148 | - ['set_tax_rate' => true] |
|
149 | - ); |
|
150 | - $extra_inputs_section = $this->reg_step->reg_step_hidden_inputs(); |
|
151 | - $this->addPrivacyConsentCheckbox($extra_inputs_section); |
|
152 | - $subsections = [ |
|
153 | - 'default_hidden_inputs' => $extra_inputs_section, |
|
154 | - ]; |
|
141 | + $primary_registrant = null; |
|
142 | + // autoload Line_Item_Display classes |
|
143 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
144 | + $Line_Item_Display = new EE_Line_Item_Display(); |
|
145 | + // calculate taxes |
|
146 | + $Line_Item_Display->display_line_item( |
|
147 | + $this->reg_step->checkout->cart->get_grand_total(), |
|
148 | + ['set_tax_rate' => true] |
|
149 | + ); |
|
150 | + $extra_inputs_section = $this->reg_step->reg_step_hidden_inputs(); |
|
151 | + $this->addPrivacyConsentCheckbox($extra_inputs_section); |
|
152 | + $subsections = [ |
|
153 | + 'default_hidden_inputs' => $extra_inputs_section, |
|
154 | + ]; |
|
155 | 155 | |
156 | - $this->template_args = [ |
|
157 | - 'revisit' => $this->reg_step->checkout->revisit, |
|
158 | - 'registrations' => [], |
|
159 | - 'ticket_count' => [], |
|
160 | - ]; |
|
161 | - // grab the saved registrations from the transaction |
|
162 | - $registrations = $this->reg_step->checkout->transaction->registrations( |
|
163 | - $this->reg_step->checkout->reg_cache_where_params |
|
164 | - ); |
|
165 | - if ($registrations) { |
|
166 | - foreach ($registrations as $registration) { |
|
167 | - // can this registration be processed during this visit ? |
|
168 | - if ( |
|
169 | - $registration instanceof EE_Registration |
|
170 | - && $this->reg_step->checkout->visit_allows_processing_of_this_registration($registration) |
|
171 | - ) { |
|
172 | - $reg_url_link = $registration->reg_url_link(); |
|
173 | - /** @var RegistrantForm $registrant_form */ |
|
174 | - $registrant_form = LoaderFactory::getNew( |
|
175 | - RegistrantForm::class, |
|
176 | - [ |
|
177 | - $registration, |
|
178 | - $this->reg_config->copyAttendeeInfo(), |
|
179 | - [$this, 'enablePrintCopyInfo'], |
|
180 | - $this->reg_step, |
|
181 | - ] |
|
182 | - ); |
|
183 | - // Increment the reg forms number if form is valid. |
|
184 | - if ($registrant_form->hasQuestions()) { |
|
185 | - $this->reg_form_count++; |
|
186 | - $subsections[ $reg_url_link ] = $registrant_form; |
|
187 | - } else { |
|
188 | - // or just add a blank section if there are no questions |
|
189 | - $subsections[ $reg_url_link ] = new EE_Form_Section_HTML(); |
|
190 | - } |
|
156 | + $this->template_args = [ |
|
157 | + 'revisit' => $this->reg_step->checkout->revisit, |
|
158 | + 'registrations' => [], |
|
159 | + 'ticket_count' => [], |
|
160 | + ]; |
|
161 | + // grab the saved registrations from the transaction |
|
162 | + $registrations = $this->reg_step->checkout->transaction->registrations( |
|
163 | + $this->reg_step->checkout->reg_cache_where_params |
|
164 | + ); |
|
165 | + if ($registrations) { |
|
166 | + foreach ($registrations as $registration) { |
|
167 | + // can this registration be processed during this visit ? |
|
168 | + if ( |
|
169 | + $registration instanceof EE_Registration |
|
170 | + && $this->reg_step->checkout->visit_allows_processing_of_this_registration($registration) |
|
171 | + ) { |
|
172 | + $reg_url_link = $registration->reg_url_link(); |
|
173 | + /** @var RegistrantForm $registrant_form */ |
|
174 | + $registrant_form = LoaderFactory::getNew( |
|
175 | + RegistrantForm::class, |
|
176 | + [ |
|
177 | + $registration, |
|
178 | + $this->reg_config->copyAttendeeInfo(), |
|
179 | + [$this, 'enablePrintCopyInfo'], |
|
180 | + $this->reg_step, |
|
181 | + ] |
|
182 | + ); |
|
183 | + // Increment the reg forms number if form is valid. |
|
184 | + if ($registrant_form->hasQuestions()) { |
|
185 | + $this->reg_form_count++; |
|
186 | + $subsections[ $reg_url_link ] = $registrant_form; |
|
187 | + } else { |
|
188 | + // or just add a blank section if there are no questions |
|
189 | + $subsections[ $reg_url_link ] = new EE_Form_Section_HTML(); |
|
190 | + } |
|
191 | 191 | |
192 | - $this->template_args['registrations'][ $reg_url_link ] = $registration; |
|
193 | - $this->template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
194 | - $this->template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
195 | - ) |
|
196 | - ? $this->template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
197 | - : 1; |
|
198 | - $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
199 | - $this->reg_step->checkout->cart->get_grand_total(), |
|
200 | - 'Ticket', |
|
201 | - [$registration->ticket()->ID()] |
|
202 | - ); |
|
203 | - $ticket_line_item = reset($ticket_line_item); |
|
204 | - $this->template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
205 | - $ticket_line_item instanceof EE_Line_Item |
|
206 | - ? $Line_Item_Display->display_line_item($ticket_line_item) |
|
207 | - : ''; |
|
208 | - if ($registration->is_primary_registrant()) { |
|
209 | - $primary_registrant = $reg_url_link; |
|
210 | - } |
|
211 | - } |
|
212 | - } |
|
192 | + $this->template_args['registrations'][ $reg_url_link ] = $registration; |
|
193 | + $this->template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
194 | + $this->template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
195 | + ) |
|
196 | + ? $this->template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
197 | + : 1; |
|
198 | + $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
199 | + $this->reg_step->checkout->cart->get_grand_total(), |
|
200 | + 'Ticket', |
|
201 | + [$registration->ticket()->ID()] |
|
202 | + ); |
|
203 | + $ticket_line_item = reset($ticket_line_item); |
|
204 | + $this->template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
205 | + $ticket_line_item instanceof EE_Line_Item |
|
206 | + ? $Line_Item_Display->display_line_item($ticket_line_item) |
|
207 | + : ''; |
|
208 | + if ($registration->is_primary_registrant()) { |
|
209 | + $primary_registrant = $reg_url_link; |
|
210 | + } |
|
211 | + } |
|
212 | + } |
|
213 | 213 | |
214 | - if ($primary_registrant && count($registrations) > 1) { |
|
215 | - if ( |
|
216 | - isset($subsections[ $primary_registrant ]) |
|
217 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
218 | - ) { |
|
219 | - $copy_options['spco_copy_attendee_chk'] = $this->print_copy_info |
|
220 | - ? new CopyAttendeeInfoForm($registrations, $this->reg_step->slug()) |
|
221 | - : new AutoCopyAttendeeInfoForm($this->reg_step->slug()); |
|
222 | - $subsections[ $primary_registrant ]->add_subsections( |
|
223 | - $copy_options, |
|
224 | - 'primary_registrant', |
|
225 | - false |
|
226 | - ); |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
214 | + if ($primary_registrant && count($registrations) > 1) { |
|
215 | + if ( |
|
216 | + isset($subsections[ $primary_registrant ]) |
|
217 | + && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
218 | + ) { |
|
219 | + $copy_options['spco_copy_attendee_chk'] = $this->print_copy_info |
|
220 | + ? new CopyAttendeeInfoForm($registrations, $this->reg_step->slug()) |
|
221 | + : new AutoCopyAttendeeInfoForm($this->reg_step->slug()); |
|
222 | + $subsections[ $primary_registrant ]->add_subsections( |
|
223 | + $copy_options, |
|
224 | + 'primary_registrant', |
|
225 | + false |
|
226 | + ); |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | 230 | |
231 | - // Set the registration form template (default: one form per ticket details table). |
|
232 | - // We decide the template to used based on the number of forms. |
|
233 | - $template = $this->reg_form_count > 1 |
|
234 | - ? SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_main.template.php' |
|
235 | - : SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_single.template.php'; |
|
236 | - $this->reg_step->setTemplate($template); |
|
231 | + // Set the registration form template (default: one form per ticket details table). |
|
232 | + // We decide the template to used based on the number of forms. |
|
233 | + $template = $this->reg_form_count > 1 |
|
234 | + ? SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_main.template.php' |
|
235 | + : SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_single.template.php'; |
|
236 | + $this->reg_step->setTemplate($template); |
|
237 | 237 | |
238 | - return $subsections; |
|
239 | - } |
|
238 | + return $subsections; |
|
239 | + } |
|
240 | 240 | |
241 | 241 | |
242 | - /** |
|
243 | - * @param EE_Form_Section_Proper $extra_inputs_section |
|
244 | - * @throws EE_Error |
|
245 | - */ |
|
246 | - private function addPrivacyConsentCheckbox(EE_Form_Section_Proper $extra_inputs_section) |
|
247 | - { |
|
248 | - // if this isn't a revisit, and they have the privacy consent box enabled, add it |
|
249 | - if (! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) { |
|
250 | - $extra_inputs_section->add_subsections( |
|
251 | - [ |
|
252 | - 'consent_box' => new PrivacyConsentCheckboxForm( |
|
253 | - $this->reg_step->slug(), |
|
254 | - $this->reg_config->getConsentCheckboxLabelText() |
|
255 | - ) |
|
256 | - ], |
|
257 | - null, |
|
258 | - false |
|
259 | - ); |
|
260 | - } |
|
261 | - } |
|
242 | + /** |
|
243 | + * @param EE_Form_Section_Proper $extra_inputs_section |
|
244 | + * @throws EE_Error |
|
245 | + */ |
|
246 | + private function addPrivacyConsentCheckbox(EE_Form_Section_Proper $extra_inputs_section) |
|
247 | + { |
|
248 | + // if this isn't a revisit, and they have the privacy consent box enabled, add it |
|
249 | + if (! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) { |
|
250 | + $extra_inputs_section->add_subsections( |
|
251 | + [ |
|
252 | + 'consent_box' => new PrivacyConsentCheckboxForm( |
|
253 | + $this->reg_step->slug(), |
|
254 | + $this->reg_config->getConsentCheckboxLabelText() |
|
255 | + ) |
|
256 | + ], |
|
257 | + null, |
|
258 | + false |
|
259 | + ); |
|
260 | + } |
|
261 | + } |
|
262 | 262 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function addRequiredQuestion(string $identifier, string $required_question): void |
121 | 121 | { |
122 | - $this->required_questions[ $identifier ] = $required_question; |
|
122 | + $this->required_questions[$identifier] = $required_question; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | |
@@ -183,17 +183,17 @@ discard block |
||
183 | 183 | // Increment the reg forms number if form is valid. |
184 | 184 | if ($registrant_form->hasQuestions()) { |
185 | 185 | $this->reg_form_count++; |
186 | - $subsections[ $reg_url_link ] = $registrant_form; |
|
186 | + $subsections[$reg_url_link] = $registrant_form; |
|
187 | 187 | } else { |
188 | 188 | // or just add a blank section if there are no questions |
189 | - $subsections[ $reg_url_link ] = new EE_Form_Section_HTML(); |
|
189 | + $subsections[$reg_url_link] = new EE_Form_Section_HTML(); |
|
190 | 190 | } |
191 | 191 | |
192 | - $this->template_args['registrations'][ $reg_url_link ] = $registration; |
|
193 | - $this->template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
194 | - $this->template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
192 | + $this->template_args['registrations'][$reg_url_link] = $registration; |
|
193 | + $this->template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
194 | + $this->template_args['ticket_count'][$registration->ticket()->ID()] |
|
195 | 195 | ) |
196 | - ? $this->template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
196 | + ? $this->template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
197 | 197 | : 1; |
198 | 198 | $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
199 | 199 | $this->reg_step->checkout->cart->get_grand_total(), |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | [$registration->ticket()->ID()] |
202 | 202 | ); |
203 | 203 | $ticket_line_item = reset($ticket_line_item); |
204 | - $this->template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
204 | + $this->template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
205 | 205 | $ticket_line_item instanceof EE_Line_Item |
206 | 206 | ? $Line_Item_Display->display_line_item($ticket_line_item) |
207 | 207 | : ''; |
@@ -213,13 +213,13 @@ discard block |
||
213 | 213 | |
214 | 214 | if ($primary_registrant && count($registrations) > 1) { |
215 | 215 | if ( |
216 | - isset($subsections[ $primary_registrant ]) |
|
217 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
216 | + isset($subsections[$primary_registrant]) |
|
217 | + && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
218 | 218 | ) { |
219 | 219 | $copy_options['spco_copy_attendee_chk'] = $this->print_copy_info |
220 | 220 | ? new CopyAttendeeInfoForm($registrations, $this->reg_step->slug()) |
221 | 221 | : new AutoCopyAttendeeInfoForm($this->reg_step->slug()); |
222 | - $subsections[ $primary_registrant ]->add_subsections( |
|
222 | + $subsections[$primary_registrant]->add_subsections( |
|
223 | 223 | $copy_options, |
224 | 224 | 'primary_registrant', |
225 | 225 | false |
@@ -231,8 +231,8 @@ discard block |
||
231 | 231 | // Set the registration form template (default: one form per ticket details table). |
232 | 232 | // We decide the template to used based on the number of forms. |
233 | 233 | $template = $this->reg_form_count > 1 |
234 | - ? SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_main.template.php' |
|
235 | - : SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_single.template.php'; |
|
234 | + ? SPCO_REG_STEPS_PATH . $this->reg_step->slug().'/attendee_info_main.template.php' |
|
235 | + : SPCO_REG_STEPS_PATH.$this->reg_step->slug().'/attendee_info_single.template.php'; |
|
236 | 236 | $this->reg_step->setTemplate($template); |
237 | 237 | |
238 | 238 | return $subsections; |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | private function addPrivacyConsentCheckbox(EE_Form_Section_Proper $extra_inputs_section) |
247 | 247 | { |
248 | 248 | // if this isn't a revisit, and they have the privacy consent box enabled, add it |
249 | - if (! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) { |
|
249 | + if ( ! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) { |
|
250 | 250 | $extra_inputs_section->add_subsections( |
251 | 251 | [ |
252 | 252 | 'consent_box' => new PrivacyConsentCheckboxForm( |
@@ -27,104 +27,104 @@ |
||
27 | 27 | */ |
28 | 28 | class CreateRegistrationService extends DomainService |
29 | 29 | { |
30 | - /** |
|
31 | - * @param EE_Event $event |
|
32 | - * @param EE_Transaction $transaction |
|
33 | - * @param EE_Ticket $ticket |
|
34 | - * @param EE_Line_Item $ticket_line_item |
|
35 | - * @param int $reg_count |
|
36 | - * @param int $reg_group_size |
|
37 | - * @param string $reg_status |
|
38 | - * @return EE_Registration |
|
39 | - * @throws OutOfRangeException |
|
40 | - * @throws EE_Error |
|
41 | - * @throws UnexpectedEntityException |
|
42 | - * @throws ReflectionException |
|
43 | - */ |
|
44 | - public function create( |
|
45 | - EE_Event $event, |
|
46 | - EE_Transaction $transaction, |
|
47 | - EE_Ticket $ticket, |
|
48 | - EE_Line_Item $ticket_line_item, |
|
49 | - int $reg_count, |
|
50 | - int $reg_group_size, |
|
51 | - string $reg_status = RegStatus::INCOMPLETE |
|
52 | - ): EE_Registration { |
|
53 | - $registrations = $transaction->registrations(); |
|
54 | - $reg_count = $reg_count ?: count($registrations) + 1; |
|
55 | - $reg_url_link = new RegUrlLink($reg_count, $ticket_line_item); |
|
56 | - $reg_code = new RegCode($reg_url_link, $transaction, $ticket); |
|
57 | - // generate new EE_Registration |
|
58 | - $registration = EE_Registration::new_instance( |
|
59 | - array( |
|
60 | - 'EVT_ID' => $event->ID(), |
|
61 | - 'TXN_ID' => $transaction->ID(), |
|
62 | - 'TKT_ID' => $ticket->ID(), |
|
63 | - 'STS_ID' => $reg_status, |
|
64 | - 'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item), |
|
65 | - 'REG_session' => EE_Registry::instance()->SSN->id(), |
|
66 | - 'REG_count' => $reg_count, |
|
67 | - 'REG_group_size' => $reg_group_size ?: $this->incrementRegGroupSize($registrations), |
|
68 | - 'REG_url_link' => $reg_url_link, |
|
69 | - 'REG_code' => $reg_code, |
|
70 | - ) |
|
71 | - ); |
|
72 | - if (! $registration instanceof EE_Registration) { |
|
73 | - throw new UnexpectedEntityException($registration, 'EE_Registration'); |
|
74 | - } |
|
75 | - // save registration so that we have an ID |
|
76 | - $registration->save(); |
|
77 | - // track reservation on reg but don't adjust ticket and datetime reserved counts |
|
78 | - // because that is done as soon as the tickets are added/removed from the cart |
|
79 | - $registration->reserve_ticket(false, 'CreateRegistrationService:' . __LINE__); |
|
80 | - $registration->_add_relation_to($event, 'Event', array(), $event->ID()); |
|
81 | - $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID()); |
|
82 | - $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID()); |
|
83 | - $registration->save(); |
|
84 | - return $registration; |
|
85 | - } |
|
30 | + /** |
|
31 | + * @param EE_Event $event |
|
32 | + * @param EE_Transaction $transaction |
|
33 | + * @param EE_Ticket $ticket |
|
34 | + * @param EE_Line_Item $ticket_line_item |
|
35 | + * @param int $reg_count |
|
36 | + * @param int $reg_group_size |
|
37 | + * @param string $reg_status |
|
38 | + * @return EE_Registration |
|
39 | + * @throws OutOfRangeException |
|
40 | + * @throws EE_Error |
|
41 | + * @throws UnexpectedEntityException |
|
42 | + * @throws ReflectionException |
|
43 | + */ |
|
44 | + public function create( |
|
45 | + EE_Event $event, |
|
46 | + EE_Transaction $transaction, |
|
47 | + EE_Ticket $ticket, |
|
48 | + EE_Line_Item $ticket_line_item, |
|
49 | + int $reg_count, |
|
50 | + int $reg_group_size, |
|
51 | + string $reg_status = RegStatus::INCOMPLETE |
|
52 | + ): EE_Registration { |
|
53 | + $registrations = $transaction->registrations(); |
|
54 | + $reg_count = $reg_count ?: count($registrations) + 1; |
|
55 | + $reg_url_link = new RegUrlLink($reg_count, $ticket_line_item); |
|
56 | + $reg_code = new RegCode($reg_url_link, $transaction, $ticket); |
|
57 | + // generate new EE_Registration |
|
58 | + $registration = EE_Registration::new_instance( |
|
59 | + array( |
|
60 | + 'EVT_ID' => $event->ID(), |
|
61 | + 'TXN_ID' => $transaction->ID(), |
|
62 | + 'TKT_ID' => $ticket->ID(), |
|
63 | + 'STS_ID' => $reg_status, |
|
64 | + 'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item), |
|
65 | + 'REG_session' => EE_Registry::instance()->SSN->id(), |
|
66 | + 'REG_count' => $reg_count, |
|
67 | + 'REG_group_size' => $reg_group_size ?: $this->incrementRegGroupSize($registrations), |
|
68 | + 'REG_url_link' => $reg_url_link, |
|
69 | + 'REG_code' => $reg_code, |
|
70 | + ) |
|
71 | + ); |
|
72 | + if (! $registration instanceof EE_Registration) { |
|
73 | + throw new UnexpectedEntityException($registration, 'EE_Registration'); |
|
74 | + } |
|
75 | + // save registration so that we have an ID |
|
76 | + $registration->save(); |
|
77 | + // track reservation on reg but don't adjust ticket and datetime reserved counts |
|
78 | + // because that is done as soon as the tickets are added/removed from the cart |
|
79 | + $registration->reserve_ticket(false, 'CreateRegistrationService:' . __LINE__); |
|
80 | + $registration->_add_relation_to($event, 'Event', array(), $event->ID()); |
|
81 | + $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID()); |
|
82 | + $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID()); |
|
83 | + $registration->save(); |
|
84 | + return $registration; |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * @param EE_Transaction $transaction |
|
90 | - * @param EE_Ticket $ticket |
|
91 | - * @param EE_Line_Item $ticket_line_item |
|
92 | - * @return float |
|
93 | - * @throws EE_Error |
|
94 | - * @throws OutOfRangeException |
|
95 | - * @throws ReflectionException |
|
96 | - */ |
|
97 | - protected function resolveFinalPrice( |
|
98 | - EE_Transaction $transaction, |
|
99 | - EE_Ticket $ticket, |
|
100 | - EE_Line_Item $ticket_line_item |
|
101 | - ): float { |
|
102 | - $final_price = EEH_Line_Item::calculate_final_price_for_ticket_line_item( |
|
103 | - $transaction->total_line_item(), |
|
104 | - $ticket_line_item |
|
105 | - ); |
|
106 | - return $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes(); |
|
107 | - } |
|
88 | + /** |
|
89 | + * @param EE_Transaction $transaction |
|
90 | + * @param EE_Ticket $ticket |
|
91 | + * @param EE_Line_Item $ticket_line_item |
|
92 | + * @return float |
|
93 | + * @throws EE_Error |
|
94 | + * @throws OutOfRangeException |
|
95 | + * @throws ReflectionException |
|
96 | + */ |
|
97 | + protected function resolveFinalPrice( |
|
98 | + EE_Transaction $transaction, |
|
99 | + EE_Ticket $ticket, |
|
100 | + EE_Line_Item $ticket_line_item |
|
101 | + ): float { |
|
102 | + $final_price = EEH_Line_Item::calculate_final_price_for_ticket_line_item( |
|
103 | + $transaction->total_line_item(), |
|
104 | + $ticket_line_item |
|
105 | + ); |
|
106 | + return $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes(); |
|
107 | + } |
|
108 | 108 | |
109 | 109 | |
110 | - /** |
|
111 | - * @param EE_Registration[] $registrations |
|
112 | - * @param boolean $update_existing_registrations |
|
113 | - * @return int |
|
114 | - * @throws EE_Error |
|
115 | - * @throws ReflectionException |
|
116 | - */ |
|
117 | - protected function incrementRegGroupSize(array $registrations, bool $update_existing_registrations = true): int |
|
118 | - { |
|
119 | - $new_reg_group_size = count($registrations) + 1; |
|
120 | - if ($update_existing_registrations) { |
|
121 | - foreach ($registrations as $registration) { |
|
122 | - if ($registration instanceof EE_Registration) { |
|
123 | - $registration->set_group_size($new_reg_group_size); |
|
124 | - $registration->save(); |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - return $new_reg_group_size; |
|
129 | - } |
|
110 | + /** |
|
111 | + * @param EE_Registration[] $registrations |
|
112 | + * @param boolean $update_existing_registrations |
|
113 | + * @return int |
|
114 | + * @throws EE_Error |
|
115 | + * @throws ReflectionException |
|
116 | + */ |
|
117 | + protected function incrementRegGroupSize(array $registrations, bool $update_existing_registrations = true): int |
|
118 | + { |
|
119 | + $new_reg_group_size = count($registrations) + 1; |
|
120 | + if ($update_existing_registrations) { |
|
121 | + foreach ($registrations as $registration) { |
|
122 | + if ($registration instanceof EE_Registration) { |
|
123 | + $registration->set_group_size($new_reg_group_size); |
|
124 | + $registration->save(); |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + return $new_reg_group_size; |
|
129 | + } |
|
130 | 130 | } |
@@ -11,102 +11,102 @@ |
||
11 | 11 | */ |
12 | 12 | class RegStatus |
13 | 13 | { |
14 | - /** |
|
15 | - * Status ID (STS_ID on esp_status table) to indicate an APPROVED registration. |
|
16 | - * the TXN may or may not be completed ( paid in full ) |
|
17 | - * Payments are allowed. |
|
18 | - * A space IS reserved. |
|
19 | - * Registration is active |
|
20 | - */ |
|
21 | - public const APPROVED = 'RAP'; |
|
14 | + /** |
|
15 | + * Status ID (STS_ID on esp_status table) to indicate an APPROVED registration. |
|
16 | + * the TXN may or may not be completed ( paid in full ) |
|
17 | + * Payments are allowed. |
|
18 | + * A space IS reserved. |
|
19 | + * Registration is active |
|
20 | + */ |
|
21 | + public const APPROVED = 'RAP'; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Status ID (STS_ID on esp_status table) to indicate an UNAPPROVED registration. |
|
25 | - * Payments are NOT allowed. |
|
26 | - * Event Admin must manually toggle STS_ID for it to change |
|
27 | - * No space reserved. |
|
28 | - * Registration is active |
|
29 | - */ |
|
30 | - public const AWAITING_REVIEW = 'RNA'; |
|
23 | + /** |
|
24 | + * Status ID (STS_ID on esp_status table) to indicate an UNAPPROVED registration. |
|
25 | + * Payments are NOT allowed. |
|
26 | + * Event Admin must manually toggle STS_ID for it to change |
|
27 | + * No space reserved. |
|
28 | + * Registration is active |
|
29 | + */ |
|
30 | + public const AWAITING_REVIEW = 'RNA'; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Status ID (STS_ID on esp_status table) to indicate a registration was CANCELLED by the attendee. |
|
34 | - * Payments are NOT allowed. |
|
35 | - * NO space reserved. |
|
36 | - * Registration is NOT active |
|
37 | - */ |
|
38 | - public const CANCELLED = 'RCN'; |
|
32 | + /** |
|
33 | + * Status ID (STS_ID on esp_status table) to indicate a registration was CANCELLED by the attendee. |
|
34 | + * Payments are NOT allowed. |
|
35 | + * NO space reserved. |
|
36 | + * Registration is NOT active |
|
37 | + */ |
|
38 | + public const CANCELLED = 'RCN'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Status ID (STS_ID on esp_status table) to indicate a registration was DECLINED by the Event Admin |
|
42 | - * Payments are NOT allowed. |
|
43 | - * No space reserved. |
|
44 | - * Registration is NOT active |
|
45 | - */ |
|
46 | - public const DECLINED = 'RDC'; |
|
40 | + /** |
|
41 | + * Status ID (STS_ID on esp_status table) to indicate a registration was DECLINED by the Event Admin |
|
42 | + * Payments are NOT allowed. |
|
43 | + * No space reserved. |
|
44 | + * Registration is NOT active |
|
45 | + */ |
|
46 | + public const DECLINED = 'RDC'; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Status ID (STS_ID on esp_status table) to indicate an INCOMPLETE registration. |
|
50 | - * Initial status for registrations when they are first created |
|
51 | - * Payments are NOT allowed. |
|
52 | - * Automatically toggled to whatever the default Event registration status is upon completion of the attendee |
|
53 | - * information reg step NO space reserved. Registration is NOT active |
|
54 | - */ |
|
55 | - public const INCOMPLETE = 'RIC'; |
|
48 | + /** |
|
49 | + * Status ID (STS_ID on esp_status table) to indicate an INCOMPLETE registration. |
|
50 | + * Initial status for registrations when they are first created |
|
51 | + * Payments are NOT allowed. |
|
52 | + * Automatically toggled to whatever the default Event registration status is upon completion of the attendee |
|
53 | + * information reg step NO space reserved. Registration is NOT active |
|
54 | + */ |
|
55 | + public const INCOMPLETE = 'RIC'; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Status ID (STS_ID on esp_status table) to indicate registration is PENDING_PAYMENT . |
|
59 | - * Payments are allowed. |
|
60 | - * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee |
|
61 | - * No space reserved. |
|
62 | - * Registration is active |
|
63 | - */ |
|
64 | - public const PENDING_PAYMENT = 'RPP'; |
|
57 | + /** |
|
58 | + * Status ID (STS_ID on esp_status table) to indicate registration is PENDING_PAYMENT . |
|
59 | + * Payments are allowed. |
|
60 | + * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee |
|
61 | + * No space reserved. |
|
62 | + * Registration is active |
|
63 | + */ |
|
64 | + public const PENDING_PAYMENT = 'RPP'; |
|
65 | 65 | |
66 | - /** |
|
67 | - * Status ID (STS_ID on esp_status table) to indicate registration is on the WAIT_LIST . |
|
68 | - * Payments are allowed. |
|
69 | - * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee |
|
70 | - * No space reserved. |
|
71 | - * Registration is active |
|
72 | - */ |
|
73 | - public const WAIT_LIST = 'RWL'; |
|
66 | + /** |
|
67 | + * Status ID (STS_ID on esp_status table) to indicate registration is on the WAIT_LIST . |
|
68 | + * Payments are allowed. |
|
69 | + * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee |
|
70 | + * No space reserved. |
|
71 | + * Registration is active |
|
72 | + */ |
|
73 | + public const WAIT_LIST = 'RWL'; |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * returns an array of ALL Reg statuses for use in comparisons |
|
78 | - * |
|
79 | - * @return string[] |
|
80 | - */ |
|
81 | - public static function validRegStatuses(): array |
|
82 | - { |
|
83 | - return [ |
|
84 | - RegStatus::APPROVED, |
|
85 | - RegStatus::AWAITING_REVIEW, |
|
86 | - RegStatus::CANCELLED, |
|
87 | - RegStatus::DECLINED, |
|
88 | - RegStatus::INCOMPLETE, |
|
89 | - RegStatus::PENDING_PAYMENT, |
|
90 | - RegStatus::WAIT_LIST, |
|
91 | - ]; |
|
92 | - } |
|
76 | + /** |
|
77 | + * returns an array of ALL Reg statuses for use in comparisons |
|
78 | + * |
|
79 | + * @return string[] |
|
80 | + */ |
|
81 | + public static function validRegStatuses(): array |
|
82 | + { |
|
83 | + return [ |
|
84 | + RegStatus::APPROVED, |
|
85 | + RegStatus::AWAITING_REVIEW, |
|
86 | + RegStatus::CANCELLED, |
|
87 | + RegStatus::DECLINED, |
|
88 | + RegStatus::INCOMPLETE, |
|
89 | + RegStatus::PENDING_PAYMENT, |
|
90 | + RegStatus::WAIT_LIST, |
|
91 | + ]; |
|
92 | + } |
|
93 | 93 | |
94 | 94 | |
95 | - public static function isValidStatus(string $status, bool $throw_exception = true): bool |
|
96 | - { |
|
97 | - $valid = in_array($status, RegStatus::validRegStatuses(), true); |
|
98 | - if (! $valid && $throw_exception) { |
|
99 | - throw new InvalidArgumentException( |
|
100 | - sprintf( |
|
101 | - esc_html__( |
|
102 | - 'Invalid registration status "%1$s" provided. Valid statuses are: %2$s', |
|
103 | - 'event_espresso' |
|
104 | - ), |
|
105 | - $status, |
|
106 | - implode(', ', RegStatus::validRegStatuses()) |
|
107 | - ) |
|
108 | - ); |
|
109 | - } |
|
110 | - return $valid; |
|
111 | - } |
|
95 | + public static function isValidStatus(string $status, bool $throw_exception = true): bool |
|
96 | + { |
|
97 | + $valid = in_array($status, RegStatus::validRegStatuses(), true); |
|
98 | + if (! $valid && $throw_exception) { |
|
99 | + throw new InvalidArgumentException( |
|
100 | + sprintf( |
|
101 | + esc_html__( |
|
102 | + 'Invalid registration status "%1$s" provided. Valid statuses are: %2$s', |
|
103 | + 'event_espresso' |
|
104 | + ), |
|
105 | + $status, |
|
106 | + implode(', ', RegStatus::validRegStatuses()) |
|
107 | + ) |
|
108 | + ); |
|
109 | + } |
|
110 | + return $valid; |
|
111 | + } |
|
112 | 112 | } |
@@ -95,7 +95,7 @@ |
||
95 | 95 | public static function isValidStatus(string $status, bool $throw_exception = true): bool |
96 | 96 | { |
97 | 97 | $valid = in_array($status, RegStatus::validRegStatuses(), true); |
98 | - if (! $valid && $throw_exception) { |
|
98 | + if ( ! $valid && $throw_exception) { |
|
99 | 99 | throw new InvalidArgumentException( |
100 | 100 | sprintf( |
101 | 101 | esc_html__( |
@@ -26,158 +26,158 @@ |
||
26 | 26 | */ |
27 | 27 | class CreateRegistrationCommand extends Command implements CommandRequiresCapCheckInterface |
28 | 28 | { |
29 | - /** |
|
30 | - * @var EE_Transaction $transaction |
|
31 | - */ |
|
32 | - private $transaction; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var EE_Ticket $ticket |
|
36 | - */ |
|
37 | - private $ticket; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var EE_Line_Item $ticket_line_item |
|
41 | - */ |
|
42 | - private $ticket_line_item; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var int $reg_count |
|
46 | - */ |
|
47 | - private $reg_count; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var int $reg_group_size |
|
51 | - */ |
|
52 | - private $reg_group_size; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var string $reg_status |
|
56 | - */ |
|
57 | - private $reg_status; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var EE_Registration $registration |
|
61 | - */ |
|
62 | - protected $registration; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * CreateRegistrationCommand constructor. |
|
67 | - * |
|
68 | - * @param EE_Transaction $transaction |
|
69 | - * @param EE_Line_Item $ticket_line_item |
|
70 | - * @param int $reg_count |
|
71 | - * @param int $reg_group_size |
|
72 | - * @param string $reg_status |
|
73 | - * @param EE_Ticket|null $ticket |
|
74 | - * @throws InvalidEntityException |
|
75 | - * @throws EE_Error |
|
76 | - */ |
|
77 | - public function __construct( |
|
78 | - EE_Transaction $transaction, |
|
79 | - EE_Line_Item $ticket_line_item, |
|
80 | - $reg_count = 1, |
|
81 | - $reg_group_size = 0, |
|
82 | - $reg_status = RegStatus::INCOMPLETE, |
|
83 | - EE_Ticket $ticket = null |
|
84 | - ) { |
|
85 | - defined('EVENT_ESPRESSO_VERSION') || exit; |
|
86 | - $this->transaction = $transaction; |
|
87 | - $this->ticket_line_item = $ticket_line_item; |
|
88 | - $this->reg_count = absint($reg_count); |
|
89 | - $this->reg_group_size = absint($reg_group_size); |
|
90 | - $this->reg_status = $reg_status; |
|
91 | - // grab the related ticket object for this line_item if one wasn't already supplied |
|
92 | - $this->ticket = $ticket instanceof EE_Ticket ? $ticket : $this->ticket_line_item->ticket(); |
|
93 | - if (! $this->ticket instanceof EE_Ticket) { |
|
94 | - throw new InvalidEntityException( |
|
95 | - is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
96 | - 'EE_Ticket', |
|
97 | - sprintf( |
|
98 | - esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
99 | - $ticket_line_item->ID() |
|
100 | - ) |
|
101 | - ); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return CapCheckInterface |
|
108 | - * @throws InvalidDataTypeException |
|
109 | - */ |
|
110 | - public function getCapCheck() |
|
111 | - { |
|
112 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
113 | - // need cap for non-AJAX admin requests |
|
114 | - $this->cap_check = ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin() |
|
115 | - ? new CapCheck('ee_edit_registrations', 'create_new_registration') |
|
116 | - : new PublicCapabilities('', 'create_new_registration'); |
|
117 | - } |
|
118 | - return $this->cap_check; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return EE_Transaction |
|
124 | - */ |
|
125 | - public function transaction() |
|
126 | - { |
|
127 | - return $this->transaction; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @return EE_Ticket |
|
133 | - */ |
|
134 | - public function ticket() |
|
135 | - { |
|
136 | - return $this->ticket; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @return EE_Line_Item |
|
142 | - */ |
|
143 | - public function ticketLineItem() |
|
144 | - { |
|
145 | - return $this->ticket_line_item; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @return int |
|
151 | - */ |
|
152 | - public function regCount() |
|
153 | - { |
|
154 | - return $this->reg_count; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @return int |
|
160 | - */ |
|
161 | - public function regGroupSize() |
|
162 | - { |
|
163 | - return $this->reg_group_size; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function regStatus() |
|
171 | - { |
|
172 | - return $this->reg_status; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @return EE_Registration |
|
178 | - */ |
|
179 | - public function registration() |
|
180 | - { |
|
181 | - return $this->registration; |
|
182 | - } |
|
29 | + /** |
|
30 | + * @var EE_Transaction $transaction |
|
31 | + */ |
|
32 | + private $transaction; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var EE_Ticket $ticket |
|
36 | + */ |
|
37 | + private $ticket; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var EE_Line_Item $ticket_line_item |
|
41 | + */ |
|
42 | + private $ticket_line_item; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var int $reg_count |
|
46 | + */ |
|
47 | + private $reg_count; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var int $reg_group_size |
|
51 | + */ |
|
52 | + private $reg_group_size; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var string $reg_status |
|
56 | + */ |
|
57 | + private $reg_status; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var EE_Registration $registration |
|
61 | + */ |
|
62 | + protected $registration; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * CreateRegistrationCommand constructor. |
|
67 | + * |
|
68 | + * @param EE_Transaction $transaction |
|
69 | + * @param EE_Line_Item $ticket_line_item |
|
70 | + * @param int $reg_count |
|
71 | + * @param int $reg_group_size |
|
72 | + * @param string $reg_status |
|
73 | + * @param EE_Ticket|null $ticket |
|
74 | + * @throws InvalidEntityException |
|
75 | + * @throws EE_Error |
|
76 | + */ |
|
77 | + public function __construct( |
|
78 | + EE_Transaction $transaction, |
|
79 | + EE_Line_Item $ticket_line_item, |
|
80 | + $reg_count = 1, |
|
81 | + $reg_group_size = 0, |
|
82 | + $reg_status = RegStatus::INCOMPLETE, |
|
83 | + EE_Ticket $ticket = null |
|
84 | + ) { |
|
85 | + defined('EVENT_ESPRESSO_VERSION') || exit; |
|
86 | + $this->transaction = $transaction; |
|
87 | + $this->ticket_line_item = $ticket_line_item; |
|
88 | + $this->reg_count = absint($reg_count); |
|
89 | + $this->reg_group_size = absint($reg_group_size); |
|
90 | + $this->reg_status = $reg_status; |
|
91 | + // grab the related ticket object for this line_item if one wasn't already supplied |
|
92 | + $this->ticket = $ticket instanceof EE_Ticket ? $ticket : $this->ticket_line_item->ticket(); |
|
93 | + if (! $this->ticket instanceof EE_Ticket) { |
|
94 | + throw new InvalidEntityException( |
|
95 | + is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
96 | + 'EE_Ticket', |
|
97 | + sprintf( |
|
98 | + esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
99 | + $ticket_line_item->ID() |
|
100 | + ) |
|
101 | + ); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return CapCheckInterface |
|
108 | + * @throws InvalidDataTypeException |
|
109 | + */ |
|
110 | + public function getCapCheck() |
|
111 | + { |
|
112 | + if (! $this->cap_check instanceof CapCheckInterface) { |
|
113 | + // need cap for non-AJAX admin requests |
|
114 | + $this->cap_check = ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin() |
|
115 | + ? new CapCheck('ee_edit_registrations', 'create_new_registration') |
|
116 | + : new PublicCapabilities('', 'create_new_registration'); |
|
117 | + } |
|
118 | + return $this->cap_check; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return EE_Transaction |
|
124 | + */ |
|
125 | + public function transaction() |
|
126 | + { |
|
127 | + return $this->transaction; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @return EE_Ticket |
|
133 | + */ |
|
134 | + public function ticket() |
|
135 | + { |
|
136 | + return $this->ticket; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @return EE_Line_Item |
|
142 | + */ |
|
143 | + public function ticketLineItem() |
|
144 | + { |
|
145 | + return $this->ticket_line_item; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @return int |
|
151 | + */ |
|
152 | + public function regCount() |
|
153 | + { |
|
154 | + return $this->reg_count; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @return int |
|
160 | + */ |
|
161 | + public function regGroupSize() |
|
162 | + { |
|
163 | + return $this->reg_group_size; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function regStatus() |
|
171 | + { |
|
172 | + return $this->reg_status; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @return EE_Registration |
|
178 | + */ |
|
179 | + public function registration() |
|
180 | + { |
|
181 | + return $this->registration; |
|
182 | + } |
|
183 | 183 | } |
@@ -27,58 +27,58 @@ |
||
27 | 27 | */ |
28 | 28 | class CancelRegistrationAndTicketLineItemCommandHandler extends CommandHandler |
29 | 29 | { |
30 | - /** |
|
31 | - * @var CancelTicketLineItemService $cancel_ticket_line_item_service |
|
32 | - */ |
|
33 | - private $cancel_ticket_line_item_service; |
|
30 | + /** |
|
31 | + * @var CancelTicketLineItemService $cancel_ticket_line_item_service |
|
32 | + */ |
|
33 | + private $cancel_ticket_line_item_service; |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * Command constructor |
|
38 | - * |
|
39 | - * @param CancelTicketLineItemService $cancel_ticket_line_item_service |
|
40 | - */ |
|
41 | - public function __construct(CancelTicketLineItemService $cancel_ticket_line_item_service) |
|
42 | - { |
|
43 | - defined('EVENT_ESPRESSO_VERSION') || exit; |
|
44 | - $this->cancel_ticket_line_item_service = $cancel_ticket_line_item_service; |
|
45 | - } |
|
36 | + /** |
|
37 | + * Command constructor |
|
38 | + * |
|
39 | + * @param CancelTicketLineItemService $cancel_ticket_line_item_service |
|
40 | + */ |
|
41 | + public function __construct(CancelTicketLineItemService $cancel_ticket_line_item_service) |
|
42 | + { |
|
43 | + defined('EVENT_ESPRESSO_VERSION') || exit; |
|
44 | + $this->cancel_ticket_line_item_service = $cancel_ticket_line_item_service; |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * @param CommandInterface|CancelRegistrationAndTicketLineItemCommand $command |
|
50 | - * @return boolean |
|
51 | - * @throws DomainException |
|
52 | - * @throws EE_Error |
|
53 | - * @throws EntityNotFoundException |
|
54 | - * @throws InvalidDataTypeException |
|
55 | - * @throws InvalidEntityException |
|
56 | - * @throws InvalidInterfaceException |
|
57 | - * @throws InvalidArgumentException |
|
58 | - * @throws ReflectionException |
|
59 | - * @throws RuntimeException |
|
60 | - */ |
|
61 | - public function handle(CommandInterface $command) |
|
62 | - { |
|
63 | - /** @var CancelRegistrationAndTicketLineItemCommand $command */ |
|
64 | - if (! $command instanceof CancelRegistrationAndTicketLineItemCommand) { |
|
65 | - throw new InvalidEntityException(get_class($command), 'CancelRegistrationAndTicketLineItemCommand'); |
|
66 | - } |
|
67 | - $registration = $command->registration(); |
|
68 | - $this->cancel_ticket_line_item_service->forRegistration($registration); |
|
69 | - // cancel original registration |
|
70 | - $registration->set_status( |
|
71 | - RegStatus::CANCELLED, |
|
72 | - false, |
|
73 | - new Context( |
|
74 | - 'cancel-registration-and-ticket-line-item-command-handler', |
|
75 | - esc_html__( |
|
76 | - 'Executed when the registration status is updated via CancelRegistrationAndTicketLineItemCommandHandler.', |
|
77 | - 'event_espresso' |
|
78 | - ) |
|
79 | - ) |
|
80 | - ); |
|
81 | - $registration->save(); |
|
82 | - return true; |
|
83 | - } |
|
48 | + /** |
|
49 | + * @param CommandInterface|CancelRegistrationAndTicketLineItemCommand $command |
|
50 | + * @return boolean |
|
51 | + * @throws DomainException |
|
52 | + * @throws EE_Error |
|
53 | + * @throws EntityNotFoundException |
|
54 | + * @throws InvalidDataTypeException |
|
55 | + * @throws InvalidEntityException |
|
56 | + * @throws InvalidInterfaceException |
|
57 | + * @throws InvalidArgumentException |
|
58 | + * @throws ReflectionException |
|
59 | + * @throws RuntimeException |
|
60 | + */ |
|
61 | + public function handle(CommandInterface $command) |
|
62 | + { |
|
63 | + /** @var CancelRegistrationAndTicketLineItemCommand $command */ |
|
64 | + if (! $command instanceof CancelRegistrationAndTicketLineItemCommand) { |
|
65 | + throw new InvalidEntityException(get_class($command), 'CancelRegistrationAndTicketLineItemCommand'); |
|
66 | + } |
|
67 | + $registration = $command->registration(); |
|
68 | + $this->cancel_ticket_line_item_service->forRegistration($registration); |
|
69 | + // cancel original registration |
|
70 | + $registration->set_status( |
|
71 | + RegStatus::CANCELLED, |
|
72 | + false, |
|
73 | + new Context( |
|
74 | + 'cancel-registration-and-ticket-line-item-command-handler', |
|
75 | + esc_html__( |
|
76 | + 'Executed when the registration status is updated via CancelRegistrationAndTicketLineItemCommandHandler.', |
|
77 | + 'event_espresso' |
|
78 | + ) |
|
79 | + ) |
|
80 | + ); |
|
81 | + $registration->save(); |
|
82 | + return true; |
|
83 | + } |
|
84 | 84 | } |
@@ -15,236 +15,236 @@ |
||
15 | 15 | */ |
16 | 16 | class RequestTypeContextChecker extends ContextChecker implements RequestTypeContextCheckerInterface |
17 | 17 | { |
18 | - private RequestTypeContext $request_type; |
|
19 | - |
|
20 | - |
|
21 | - /** |
|
22 | - * RequestTypeContextChecker constructor. |
|
23 | - * |
|
24 | - * @param RequestTypeContext $request_type |
|
25 | - */ |
|
26 | - public function __construct(RequestTypeContext $request_type) |
|
27 | - { |
|
28 | - $this->request_type = $request_type; |
|
29 | - parent::__construct( |
|
30 | - 'RequestTypeContextChecker', |
|
31 | - $this->request_type->validRequestTypes() |
|
32 | - ); |
|
33 | - } |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * true if the current request involves some form of activation |
|
38 | - * |
|
39 | - * @return bool |
|
40 | - */ |
|
41 | - public function isActivation(): bool |
|
42 | - { |
|
43 | - return ($this->request_type->slug() === RequestTypeContext::ACTIVATION || $this->request_type->isActivation()) |
|
44 | - && ! $this->request_type->isUnitTesting(); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param $is_activation |
|
50 | - */ |
|
51 | - public function setIsActivation($is_activation) |
|
52 | - { |
|
53 | - $this->request_type->setIsActivation($is_activation); |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * true if the current request is for the admin and is not being made via AJAX |
|
59 | - * |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - public function isAdmin(): bool |
|
63 | - { |
|
64 | - return $this->request_type->slug() === RequestTypeContext::ADMIN && ! $this->isActivation(); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * true if the current request is for the admin AND is being made via AJAX |
|
70 | - * |
|
71 | - * @return bool |
|
72 | - */ |
|
73 | - public function isAdminAjax(): bool |
|
74 | - { |
|
75 | - return $this->request_type->slug() === RequestTypeContext::AJAX_ADMIN && ! $this->isActivation(); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * true if the current request is being made via AJAX... any AJAX |
|
81 | - * |
|
82 | - * @return bool |
|
83 | - */ |
|
84 | - public function isAjax(): bool |
|
85 | - { |
|
86 | - return $this->isEeAjax() || $this->isOtherAjax(); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
92 | - * |
|
93 | - * @return bool |
|
94 | - */ |
|
95 | - public function isEeAjax(): bool |
|
96 | - { |
|
97 | - return $this->isAdminAjax() || $this->isFrontAjax(); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * true if the current request is being made via AJAX but is NOT for EE related logic |
|
103 | - * |
|
104 | - * @return bool |
|
105 | - */ |
|
106 | - public function isOtherAjax(): bool |
|
107 | - { |
|
108 | - return $this->request_type->slug() === RequestTypeContext::AJAX_OTHER && ! $this->isActivation(); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * true if the current request is for the EE REST API |
|
113 | - * |
|
114 | - * @return bool |
|
115 | - */ |
|
116 | - public function isApi(): bool |
|
117 | - { |
|
118 | - return $this->request_type->slug() === RequestTypeContext::API && ! $this->isActivation(); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * true if the current request is from the command line |
|
124 | - * |
|
125 | - * @return bool |
|
126 | - */ |
|
127 | - public function isCli(): bool |
|
128 | - { |
|
129 | - return $this->request_type->slug() === RequestTypeContext::CLI && ! $this->isActivation(); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * true if the current request is for a WP_Cron |
|
135 | - * |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - public function isCron(): bool |
|
139 | - { |
|
140 | - return $this->request_type->slug() === RequestTypeContext::CRON && ! $this->isActivation(); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * true if the current request is for a feed (ie: RSS) |
|
146 | - * |
|
147 | - * @return bool |
|
148 | - */ |
|
149 | - public function isFeed(): bool |
|
150 | - { |
|
151 | - return $this->request_type->slug() === RequestTypeContext::FEED && ! $this->isActivation(); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * true if the current request is for the frontend and is not being made via AJAX |
|
157 | - * |
|
158 | - * @return bool |
|
159 | - */ |
|
160 | - public function isFrontend(): bool |
|
161 | - { |
|
162 | - return $this->request_type->slug() === RequestTypeContext::FRONTEND && ! $this->isActivation(); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * true if the current request is for the frontend AND is being made via AJAX |
|
168 | - * |
|
169 | - * @return bool |
|
170 | - */ |
|
171 | - public function isFrontAjax(): bool |
|
172 | - { |
|
173 | - return $this->request_type->slug() === RequestTypeContext::AJAX_FRONT && ! $this->isActivation(); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * true if the current request is for the EE GraphQL manager |
|
179 | - * |
|
180 | - * @return bool |
|
181 | - */ |
|
182 | - public function isGQL(): bool |
|
183 | - { |
|
184 | - return $this->request_type->slug() === RequestTypeContext::GQL && ! $this->isActivation(); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * true if the current request is for content that is to be displayed within an iframe |
|
190 | - * |
|
191 | - * @return bool |
|
192 | - */ |
|
193 | - public function isIframe(): bool |
|
194 | - { |
|
195 | - return $this->request_type->slug() === RequestTypeContext::IFRAME && ! $this->isActivation(); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * true if the current request is occurring while unit testing |
|
201 | - * |
|
202 | - * @return bool |
|
203 | - */ |
|
204 | - public function isUnitTesting(): bool |
|
205 | - { |
|
206 | - return $this->request_type->isUnitTesting() && ! $this->request_type->isActivation(); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * true if the current request is for the WP REST API |
|
212 | - * |
|
213 | - * @return bool |
|
214 | - */ |
|
215 | - public function isWordPressApi(): bool |
|
216 | - { |
|
217 | - return $this->request_type->slug() === RequestTypeContext::WP_API && ! $this->isActivation(); |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * true if the current request is being made via AJAX for the WP Heartbeat |
|
223 | - * |
|
224 | - * @return bool |
|
225 | - */ |
|
226 | - public function isWordPressHeartbeat(): bool |
|
227 | - { |
|
228 | - return $this->request_type->slug() === RequestTypeContext::AJAX_HEARTBEAT && ! $this->isActivation(); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * true if the current request is a loopback sent from WP core to test for errors |
|
234 | - * |
|
235 | - * @return bool |
|
236 | - */ |
|
237 | - public function isWordPressScrape(): bool |
|
238 | - { |
|
239 | - return $this->request_type->slug() === RequestTypeContext::WP_SCRAPE; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - public function slug(): string |
|
247 | - { |
|
248 | - return $this->request_type->slug(); |
|
249 | - } |
|
18 | + private RequestTypeContext $request_type; |
|
19 | + |
|
20 | + |
|
21 | + /** |
|
22 | + * RequestTypeContextChecker constructor. |
|
23 | + * |
|
24 | + * @param RequestTypeContext $request_type |
|
25 | + */ |
|
26 | + public function __construct(RequestTypeContext $request_type) |
|
27 | + { |
|
28 | + $this->request_type = $request_type; |
|
29 | + parent::__construct( |
|
30 | + 'RequestTypeContextChecker', |
|
31 | + $this->request_type->validRequestTypes() |
|
32 | + ); |
|
33 | + } |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * true if the current request involves some form of activation |
|
38 | + * |
|
39 | + * @return bool |
|
40 | + */ |
|
41 | + public function isActivation(): bool |
|
42 | + { |
|
43 | + return ($this->request_type->slug() === RequestTypeContext::ACTIVATION || $this->request_type->isActivation()) |
|
44 | + && ! $this->request_type->isUnitTesting(); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param $is_activation |
|
50 | + */ |
|
51 | + public function setIsActivation($is_activation) |
|
52 | + { |
|
53 | + $this->request_type->setIsActivation($is_activation); |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * true if the current request is for the admin and is not being made via AJAX |
|
59 | + * |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + public function isAdmin(): bool |
|
63 | + { |
|
64 | + return $this->request_type->slug() === RequestTypeContext::ADMIN && ! $this->isActivation(); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * true if the current request is for the admin AND is being made via AJAX |
|
70 | + * |
|
71 | + * @return bool |
|
72 | + */ |
|
73 | + public function isAdminAjax(): bool |
|
74 | + { |
|
75 | + return $this->request_type->slug() === RequestTypeContext::AJAX_ADMIN && ! $this->isActivation(); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * true if the current request is being made via AJAX... any AJAX |
|
81 | + * |
|
82 | + * @return bool |
|
83 | + */ |
|
84 | + public function isAjax(): bool |
|
85 | + { |
|
86 | + return $this->isEeAjax() || $this->isOtherAjax(); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
92 | + * |
|
93 | + * @return bool |
|
94 | + */ |
|
95 | + public function isEeAjax(): bool |
|
96 | + { |
|
97 | + return $this->isAdminAjax() || $this->isFrontAjax(); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * true if the current request is being made via AJAX but is NOT for EE related logic |
|
103 | + * |
|
104 | + * @return bool |
|
105 | + */ |
|
106 | + public function isOtherAjax(): bool |
|
107 | + { |
|
108 | + return $this->request_type->slug() === RequestTypeContext::AJAX_OTHER && ! $this->isActivation(); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * true if the current request is for the EE REST API |
|
113 | + * |
|
114 | + * @return bool |
|
115 | + */ |
|
116 | + public function isApi(): bool |
|
117 | + { |
|
118 | + return $this->request_type->slug() === RequestTypeContext::API && ! $this->isActivation(); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * true if the current request is from the command line |
|
124 | + * |
|
125 | + * @return bool |
|
126 | + */ |
|
127 | + public function isCli(): bool |
|
128 | + { |
|
129 | + return $this->request_type->slug() === RequestTypeContext::CLI && ! $this->isActivation(); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * true if the current request is for a WP_Cron |
|
135 | + * |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + public function isCron(): bool |
|
139 | + { |
|
140 | + return $this->request_type->slug() === RequestTypeContext::CRON && ! $this->isActivation(); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * true if the current request is for a feed (ie: RSS) |
|
146 | + * |
|
147 | + * @return bool |
|
148 | + */ |
|
149 | + public function isFeed(): bool |
|
150 | + { |
|
151 | + return $this->request_type->slug() === RequestTypeContext::FEED && ! $this->isActivation(); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * true if the current request is for the frontend and is not being made via AJAX |
|
157 | + * |
|
158 | + * @return bool |
|
159 | + */ |
|
160 | + public function isFrontend(): bool |
|
161 | + { |
|
162 | + return $this->request_type->slug() === RequestTypeContext::FRONTEND && ! $this->isActivation(); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * true if the current request is for the frontend AND is being made via AJAX |
|
168 | + * |
|
169 | + * @return bool |
|
170 | + */ |
|
171 | + public function isFrontAjax(): bool |
|
172 | + { |
|
173 | + return $this->request_type->slug() === RequestTypeContext::AJAX_FRONT && ! $this->isActivation(); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * true if the current request is for the EE GraphQL manager |
|
179 | + * |
|
180 | + * @return bool |
|
181 | + */ |
|
182 | + public function isGQL(): bool |
|
183 | + { |
|
184 | + return $this->request_type->slug() === RequestTypeContext::GQL && ! $this->isActivation(); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * true if the current request is for content that is to be displayed within an iframe |
|
190 | + * |
|
191 | + * @return bool |
|
192 | + */ |
|
193 | + public function isIframe(): bool |
|
194 | + { |
|
195 | + return $this->request_type->slug() === RequestTypeContext::IFRAME && ! $this->isActivation(); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * true if the current request is occurring while unit testing |
|
201 | + * |
|
202 | + * @return bool |
|
203 | + */ |
|
204 | + public function isUnitTesting(): bool |
|
205 | + { |
|
206 | + return $this->request_type->isUnitTesting() && ! $this->request_type->isActivation(); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * true if the current request is for the WP REST API |
|
212 | + * |
|
213 | + * @return bool |
|
214 | + */ |
|
215 | + public function isWordPressApi(): bool |
|
216 | + { |
|
217 | + return $this->request_type->slug() === RequestTypeContext::WP_API && ! $this->isActivation(); |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * true if the current request is being made via AJAX for the WP Heartbeat |
|
223 | + * |
|
224 | + * @return bool |
|
225 | + */ |
|
226 | + public function isWordPressHeartbeat(): bool |
|
227 | + { |
|
228 | + return $this->request_type->slug() === RequestTypeContext::AJAX_HEARTBEAT && ! $this->isActivation(); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * true if the current request is a loopback sent from WP core to test for errors |
|
234 | + * |
|
235 | + * @return bool |
|
236 | + */ |
|
237 | + public function isWordPressScrape(): bool |
|
238 | + { |
|
239 | + return $this->request_type->slug() === RequestTypeContext::WP_SCRAPE; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + public function slug(): string |
|
247 | + { |
|
248 | + return $this->request_type->slug(); |
|
249 | + } |
|
250 | 250 | } |
@@ -4,90 +4,90 @@ |
||
4 | 4 | |
5 | 5 | class LicenseStatus |
6 | 6 | { |
7 | - public static function statusNotice(?string $license_status): string |
|
8 | - { |
|
9 | - if (empty($license_status)) { |
|
10 | - return "<span class='ee-status-pill'></span>"; |
|
11 | - } |
|
12 | - $class = self::statusClass($license_status); |
|
13 | - $icon = self::statusIcon($license_status); |
|
14 | - $notice = self::statusMessage($license_status); |
|
15 | - return "<span class='ee-status-pill ee-status-bg--$class'><span class='ee-license-status'>$notice</span> <span class='dashicons dashicons-$icon'></span></span>"; |
|
16 | - } |
|
7 | + public static function statusNotice(?string $license_status): string |
|
8 | + { |
|
9 | + if (empty($license_status)) { |
|
10 | + return "<span class='ee-status-pill'></span>"; |
|
11 | + } |
|
12 | + $class = self::statusClass($license_status); |
|
13 | + $icon = self::statusIcon($license_status); |
|
14 | + $notice = self::statusMessage($license_status); |
|
15 | + return "<span class='ee-status-pill ee-status-bg--$class'><span class='ee-license-status'>$notice</span> <span class='dashicons dashicons-$icon'></span></span>"; |
|
16 | + } |
|
17 | 17 | |
18 | - public static function statusMessages(): array |
|
19 | - { |
|
20 | - return [ |
|
21 | - "deactivated" => esc_html__("license key deactivated", 'event_espresso'), |
|
22 | - "disabled" => esc_html__("license key revoked", 'event_espresso'), |
|
23 | - "expired" => esc_html__("license has expired", 'event_espresso'), |
|
24 | - "inactive" => esc_html__("inactive license key", 'event_espresso'), |
|
25 | - "invalid" => esc_html__("invalid license key", 'event_espresso'), |
|
26 | - "invalid_item_id" => esc_html__("invalid item ID", 'event_espresso'), |
|
27 | - "item_name_mismatch" => esc_html__("invalid license for plugin", 'event_espresso'), |
|
28 | - "key_mismatch" => esc_html__("invalid license for plugin", 'event_espresso'), |
|
29 | - "license_not_activable" => esc_html__("attempting to activate a bundle's parent license", 'event_espresso'), |
|
30 | - "missing" => esc_html__("no license found", 'event_espresso'), |
|
31 | - "missing_url" => esc_html__("site URL not found", 'event_espresso'), |
|
32 | - "no_activations_left" => esc_html__("no activations left", 'event_espresso'), |
|
33 | - "site_inactive" => esc_html__("site is not active for this license", 'event_espresso'), |
|
34 | - "valid" => esc_html__("valid license key", 'event_espresso'), |
|
35 | - ]; |
|
36 | - } |
|
18 | + public static function statusMessages(): array |
|
19 | + { |
|
20 | + return [ |
|
21 | + "deactivated" => esc_html__("license key deactivated", 'event_espresso'), |
|
22 | + "disabled" => esc_html__("license key revoked", 'event_espresso'), |
|
23 | + "expired" => esc_html__("license has expired", 'event_espresso'), |
|
24 | + "inactive" => esc_html__("inactive license key", 'event_espresso'), |
|
25 | + "invalid" => esc_html__("invalid license key", 'event_espresso'), |
|
26 | + "invalid_item_id" => esc_html__("invalid item ID", 'event_espresso'), |
|
27 | + "item_name_mismatch" => esc_html__("invalid license for plugin", 'event_espresso'), |
|
28 | + "key_mismatch" => esc_html__("invalid license for plugin", 'event_espresso'), |
|
29 | + "license_not_activable" => esc_html__("attempting to activate a bundle's parent license", 'event_espresso'), |
|
30 | + "missing" => esc_html__("no license found", 'event_espresso'), |
|
31 | + "missing_url" => esc_html__("site URL not found", 'event_espresso'), |
|
32 | + "no_activations_left" => esc_html__("no activations left", 'event_espresso'), |
|
33 | + "site_inactive" => esc_html__("site is not active for this license", 'event_espresso'), |
|
34 | + "valid" => esc_html__("valid license key", 'event_espresso'), |
|
35 | + ]; |
|
36 | + } |
|
37 | 37 | |
38 | - public static function statusMessage(?string $license_status): string |
|
39 | - { |
|
40 | - $license_statuses = self::statusMessages(); |
|
41 | - return $license_statuses[ $license_status ] ?? esc_html__("An unknown error occurred", 'event_espresso'); |
|
42 | - } |
|
38 | + public static function statusMessage(?string $license_status): string |
|
39 | + { |
|
40 | + $license_statuses = self::statusMessages(); |
|
41 | + return $license_statuses[ $license_status ] ?? esc_html__("An unknown error occurred", 'event_espresso'); |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - public static function statusClass(?string $license_status): string |
|
46 | - { |
|
47 | - switch ( $license_status ) { |
|
48 | - case "valid": |
|
49 | - return "active"; |
|
45 | + public static function statusClass(?string $license_status): string |
|
46 | + { |
|
47 | + switch ( $license_status ) { |
|
48 | + case "valid": |
|
49 | + return "active"; |
|
50 | 50 | |
51 | - case "deactivated": |
|
52 | - case "expired": |
|
53 | - case "inactive": |
|
54 | - case "site_inactive": |
|
55 | - return "inactive"; |
|
51 | + case "deactivated": |
|
52 | + case "expired": |
|
53 | + case "inactive": |
|
54 | + case "site_inactive": |
|
55 | + return "inactive"; |
|
56 | 56 | |
57 | - case "no_activations_left": |
|
58 | - return "attention"; |
|
57 | + case "no_activations_left": |
|
58 | + return "attention"; |
|
59 | 59 | |
60 | - case "disabled": |
|
61 | - case "revoked": |
|
62 | - case "invalid": |
|
63 | - case "item_name_mismatch": |
|
64 | - case "missing": |
|
65 | - default: |
|
66 | - return "error"; |
|
67 | - } |
|
68 | - } |
|
60 | + case "disabled": |
|
61 | + case "revoked": |
|
62 | + case "invalid": |
|
63 | + case "item_name_mismatch": |
|
64 | + case "missing": |
|
65 | + default: |
|
66 | + return "error"; |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - public static function statusIcon(?string $license_status): string |
|
72 | - { |
|
73 | - switch ( $license_status ) { |
|
74 | - case "valid": |
|
75 | - return "yes-alt"; |
|
71 | + public static function statusIcon(?string $license_status): string |
|
72 | + { |
|
73 | + switch ( $license_status ) { |
|
74 | + case "valid": |
|
75 | + return "yes-alt"; |
|
76 | 76 | |
77 | - case "expired": |
|
78 | - case "site_inactive": |
|
79 | - return "clock"; |
|
77 | + case "expired": |
|
78 | + case "site_inactive": |
|
79 | + return "clock"; |
|
80 | 80 | |
81 | - case "disabled": |
|
82 | - case "revoked": |
|
83 | - case "invalid": |
|
84 | - case "item_name_mismatch": |
|
85 | - case "no_activations_left": |
|
86 | - return "warning"; |
|
81 | + case "disabled": |
|
82 | + case "revoked": |
|
83 | + case "invalid": |
|
84 | + case "item_name_mismatch": |
|
85 | + case "no_activations_left": |
|
86 | + return "warning"; |
|
87 | 87 | |
88 | - case "missing": |
|
89 | - default: |
|
90 | - return "editor-help"; |
|
91 | - } |
|
92 | - } |
|
88 | + case "missing": |
|
89 | + default: |
|
90 | + return "editor-help"; |
|
91 | + } |
|
92 | + } |
|
93 | 93 | } |
@@ -38,13 +38,13 @@ discard block |
||
38 | 38 | public static function statusMessage(?string $license_status): string |
39 | 39 | { |
40 | 40 | $license_statuses = self::statusMessages(); |
41 | - return $license_statuses[ $license_status ] ?? esc_html__("An unknown error occurred", 'event_espresso'); |
|
41 | + return $license_statuses[$license_status] ?? esc_html__("An unknown error occurred", 'event_espresso'); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | |
45 | 45 | public static function statusClass(?string $license_status): string |
46 | 46 | { |
47 | - switch ( $license_status ) { |
|
47 | + switch ($license_status) { |
|
48 | 48 | case "valid": |
49 | 49 | return "active"; |
50 | 50 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | public static function statusIcon(?string $license_status): string |
72 | 72 | { |
73 | - switch ( $license_status ) { |
|
73 | + switch ($license_status) { |
|
74 | 74 | case "valid": |
75 | 75 | return "yes-alt"; |
76 | 76 |