@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function form($for_display = false) |
173 | 173 | { |
174 | - if (! $this->formIsValid()) { |
|
174 | + if ( ! $this->formIsValid()) { |
|
175 | 175 | return null; |
176 | 176 | } |
177 | 177 | if ($for_display) { |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | */ |
275 | 275 | public function setFormName($form_name) |
276 | 276 | { |
277 | - if (! is_string($form_name)) { |
|
277 | + if ( ! is_string($form_name)) { |
|
278 | 278 | throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
279 | 279 | } |
280 | 280 | $this->form_name = $form_name; |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | */ |
299 | 299 | public function setAdminName($admin_name) |
300 | 300 | { |
301 | - if (! is_string($admin_name)) { |
|
301 | + if ( ! is_string($admin_name)) { |
|
302 | 302 | throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
303 | 303 | } |
304 | 304 | $this->admin_name = $admin_name; |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | */ |
323 | 323 | public function setSlug($slug) |
324 | 324 | { |
325 | - if (! is_string($slug)) { |
|
325 | + if ( ! is_string($slug)) { |
|
326 | 326 | throw new InvalidDataTypeException('$slug', $slug, 'string'); |
327 | 327 | } |
328 | 328 | $this->slug = $slug; |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function setSubmitBtnText($submit_btn_text) |
347 | 347 | { |
348 | - if (! is_string($submit_btn_text)) { |
|
348 | + if ( ! is_string($submit_btn_text)) { |
|
349 | 349 | throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
350 | 350 | } |
351 | 351 | if (empty($submit_btn_text)) { |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | */ |
375 | 375 | public function setFormAction($form_action) |
376 | 376 | { |
377 | - if (! is_string($form_action)) { |
|
377 | + if ( ! is_string($form_action)) { |
|
378 | 378 | throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
379 | 379 | } |
380 | 380 | $this->form_action = $form_action; |
@@ -493,11 +493,11 @@ discard block |
||
493 | 493 | $text = ! empty($text) ? $text : $this->submitBtnText(); |
494 | 494 | return new EE_Submit_Input( |
495 | 495 | array( |
496 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
497 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
496 | + 'html_name' => 'ee-form-submit-'.$this->slug(), |
|
497 | + 'html_id' => 'ee-form-submit-'.$this->slug(), |
|
498 | 498 | 'html_class' => 'ee-form-submit', |
499 | 499 | 'html_label' => ' ', |
500 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
500 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
501 | 501 | 'default' => $text, |
502 | 502 | ) |
503 | 503 | ); |
@@ -513,11 +513,11 @@ discard block |
||
513 | 513 | */ |
514 | 514 | public function appendSubmitButton($text = '') |
515 | 515 | { |
516 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
516 | + if ($this->form->subsection_exists($this->slug().'-submit-btn')) { |
|
517 | 517 | return; |
518 | 518 | } |
519 | 519 | $this->form->add_subsections( |
520 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
520 | + array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)), |
|
521 | 521 | null, |
522 | 522 | false |
523 | 523 | ); |
@@ -534,11 +534,11 @@ discard block |
||
534 | 534 | { |
535 | 535 | $cancel_button = new EE_Submit_Input( |
536 | 536 | array( |
537 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
538 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
537 | + 'html_name' => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!! |
|
538 | + 'html_id' => 'ee-cancel-form-'.$this->slug(), |
|
539 | 539 | 'html_class' => 'ee-cancel-form', |
540 | 540 | 'html_label' => ' ', |
541 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
541 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
542 | 542 | 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
543 | 543 | ) |
544 | 544 | ); |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | $this->form->add_subsections( |
559 | 559 | array( |
560 | 560 | 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
561 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
561 | + EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx() |
|
562 | 562 | ), |
563 | 563 | ), |
564 | 564 | null, |
@@ -644,11 +644,11 @@ discard block |
||
644 | 644 | */ |
645 | 645 | public function process($submitted_form_data = array()) |
646 | 646 | { |
647 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
647 | + if ( ! $this->form()->was_submitted($submitted_form_data)) { |
|
648 | 648 | throw new InvalidFormSubmissionException($this->form_name); |
649 | 649 | } |
650 | 650 | $this->form(true)->receive_form_submission($submitted_form_data); |
651 | - if (! $this->form()->is_valid()) { |
|
651 | + if ( ! $this->form()->is_valid()) { |
|
652 | 652 | throw new InvalidFormSubmissionException( |
653 | 653 | $this->form_name, |
654 | 654 | sprintf( |
@@ -28,642 +28,642 @@ |
||
28 | 28 | */ |
29 | 29 | abstract class FormHandler implements FormHandlerInterface |
30 | 30 | { |
31 | - /** |
|
32 | - * will add opening and closing HTML form tags as well as a submit button |
|
33 | - */ |
|
34 | - const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
35 | - |
|
36 | - /** |
|
37 | - * will add opening and closing HTML form tags but NOT a submit button |
|
38 | - */ |
|
39 | - const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
40 | - |
|
41 | - /** |
|
42 | - * will NOT add opening and closing HTML form tags but will add a submit button |
|
43 | - */ |
|
44 | - const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
45 | - |
|
46 | - /** |
|
47 | - * will NOT add opening and closing HTML form tags NOR a submit button |
|
48 | - */ |
|
49 | - const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
50 | - |
|
51 | - /** |
|
52 | - * if set to false, then this form has no displayable content, |
|
53 | - * and will only be used for processing data sent passed via GET or POST |
|
54 | - * defaults to true ( ie: form has displayable content ) |
|
55 | - * |
|
56 | - * @var boolean $displayable |
|
57 | - */ |
|
58 | - private $displayable = true; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var string $form_name |
|
62 | - */ |
|
63 | - private $form_name; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var string $admin_name |
|
67 | - */ |
|
68 | - private $admin_name; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var string $slug |
|
72 | - */ |
|
73 | - private $slug; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var string $submit_btn_text |
|
77 | - */ |
|
78 | - private $submit_btn_text; |
|
79 | - |
|
80 | - /** |
|
81 | - * @var string $form_action |
|
82 | - */ |
|
83 | - private $form_action; |
|
84 | - |
|
85 | - /** |
|
86 | - * form params in key value pairs |
|
87 | - * can be added to form action URL or as hidden inputs |
|
88 | - * |
|
89 | - * @var array $form_args |
|
90 | - */ |
|
91 | - private $form_args = array(); |
|
92 | - |
|
93 | - /** |
|
94 | - * value of one of the string constant above |
|
95 | - * |
|
96 | - * @var string $form_config |
|
97 | - */ |
|
98 | - private $form_config; |
|
99 | - |
|
100 | - /** |
|
101 | - * whether or not the form was determined to be invalid |
|
102 | - * |
|
103 | - * @var boolean $form_has_errors |
|
104 | - */ |
|
105 | - private $form_has_errors; |
|
106 | - |
|
107 | - /** |
|
108 | - * the absolute top level form section being used on the page |
|
109 | - * |
|
110 | - * @var EE_Form_Section_Proper $form |
|
111 | - */ |
|
112 | - private $form; |
|
113 | - |
|
114 | - /** |
|
115 | - * @var EE_Registry $registry |
|
116 | - */ |
|
117 | - protected $registry; |
|
118 | - |
|
119 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * Form constructor. |
|
124 | - * |
|
125 | - * @param string $form_name |
|
126 | - * @param string $admin_name |
|
127 | - * @param string $slug |
|
128 | - * @param string $form_action |
|
129 | - * @param string $form_config |
|
130 | - * @param EE_Registry|null $registry |
|
131 | - */ |
|
132 | - public function __construct( |
|
133 | - $form_name, |
|
134 | - $admin_name, |
|
135 | - $slug, |
|
136 | - $form_action = '', |
|
137 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
138 | - EE_Registry $registry = null |
|
139 | - ) { |
|
140 | - $this->setFormName($form_name); |
|
141 | - $this->setAdminName($admin_name); |
|
142 | - $this->setSlug($slug); |
|
143 | - $this->setFormAction($form_action); |
|
144 | - $this->setFormConfig($form_config); |
|
145 | - $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
146 | - $this->registry = $registry; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - public static function getFormConfigConstants() |
|
154 | - { |
|
155 | - return array( |
|
156 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
157 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
158 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
159 | - FormHandler::DO_NOT_SETUP_FORM, |
|
160 | - ); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * @param bool $for_display |
|
166 | - * @return EE_Form_Section_Proper |
|
167 | - * @throws EE_Error |
|
168 | - * @throws LogicException |
|
169 | - */ |
|
170 | - public function form($for_display = false) |
|
171 | - { |
|
172 | - if (! $this->formIsValid()) { |
|
173 | - return null; |
|
174 | - } |
|
175 | - if ($for_display) { |
|
176 | - $form_config = $this->formConfig(); |
|
177 | - if ( |
|
178 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
179 | - || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
180 | - ) { |
|
181 | - $this->appendSubmitButton(); |
|
182 | - $this->clearFormButtonFloats(); |
|
183 | - } |
|
184 | - } |
|
185 | - return $this->form; |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * @return boolean |
|
191 | - * @throws LogicException |
|
192 | - */ |
|
193 | - public function formIsValid() |
|
194 | - { |
|
195 | - if ($this->form instanceof EE_Form_Section_Proper) { |
|
196 | - return true; |
|
197 | - } |
|
198 | - $form = apply_filters( |
|
199 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
200 | - $this->generate(), |
|
201 | - $this |
|
202 | - ); |
|
203 | - if ($this->verifyForm($form)) { |
|
204 | - $this->setForm($form); |
|
205 | - } |
|
206 | - return true; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * @param EE_Form_Section_Proper|null $form |
|
212 | - * @return bool |
|
213 | - * @throws LogicException |
|
214 | - */ |
|
215 | - public function verifyForm(EE_Form_Section_Proper $form = null) |
|
216 | - { |
|
217 | - $form = $form !== null ? $form : $this->form; |
|
218 | - if ($form instanceof EE_Form_Section_Proper) { |
|
219 | - return true; |
|
220 | - } |
|
221 | - throw new LogicException( |
|
222 | - sprintf( |
|
223 | - esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
224 | - $this->form_name, |
|
225 | - var_export($form, true) |
|
226 | - ) |
|
227 | - ); |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * @param EE_Form_Section_Proper $form |
|
233 | - */ |
|
234 | - public function setForm(EE_Form_Section_Proper $form) |
|
235 | - { |
|
236 | - $this->form = $form; |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * @return boolean |
|
242 | - */ |
|
243 | - public function displayable() |
|
244 | - { |
|
245 | - return $this->displayable; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * @param boolean $displayable |
|
251 | - */ |
|
252 | - public function setDisplayable($displayable = false) |
|
253 | - { |
|
254 | - $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * a public name for the form that can be displayed on the frontend of a site |
|
260 | - * |
|
261 | - * @return string |
|
262 | - */ |
|
263 | - public function formName() |
|
264 | - { |
|
265 | - return $this->form_name; |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * @param string $form_name |
|
271 | - * @throws InvalidDataTypeException |
|
272 | - */ |
|
273 | - public function setFormName($form_name) |
|
274 | - { |
|
275 | - if (! is_string($form_name)) { |
|
276 | - throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
277 | - } |
|
278 | - $this->form_name = $form_name; |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * a public name for the form that can be displayed, but only in the admin |
|
284 | - * |
|
285 | - * @return string |
|
286 | - */ |
|
287 | - public function adminName() |
|
288 | - { |
|
289 | - return $this->admin_name; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * @param string $admin_name |
|
295 | - * @throws InvalidDataTypeException |
|
296 | - */ |
|
297 | - public function setAdminName($admin_name) |
|
298 | - { |
|
299 | - if (! is_string($admin_name)) { |
|
300 | - throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
301 | - } |
|
302 | - $this->admin_name = $admin_name; |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * a URL friendly string that can be used for identifying the form |
|
308 | - * |
|
309 | - * @return string |
|
310 | - */ |
|
311 | - public function slug() |
|
312 | - { |
|
313 | - return $this->slug; |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * @param string $slug |
|
319 | - * @throws InvalidDataTypeException |
|
320 | - */ |
|
321 | - public function setSlug($slug) |
|
322 | - { |
|
323 | - if (! is_string($slug)) { |
|
324 | - throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
325 | - } |
|
326 | - $this->slug = $slug; |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * @return string |
|
332 | - */ |
|
333 | - public function submitBtnText() |
|
334 | - { |
|
335 | - return $this->submit_btn_text; |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * @param string $submit_btn_text |
|
341 | - * @throws InvalidDataTypeException |
|
342 | - * @throws InvalidArgumentException |
|
343 | - */ |
|
344 | - public function setSubmitBtnText($submit_btn_text) |
|
345 | - { |
|
346 | - if (! is_string($submit_btn_text)) { |
|
347 | - throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
348 | - } |
|
349 | - if (empty($submit_btn_text)) { |
|
350 | - throw new InvalidArgumentException( |
|
351 | - esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
352 | - ); |
|
353 | - } |
|
354 | - $this->submit_btn_text = $submit_btn_text; |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * @return string |
|
360 | - */ |
|
361 | - public function formAction() |
|
362 | - { |
|
363 | - return ! empty($this->form_args) |
|
364 | - ? add_query_arg($this->form_args, $this->form_action) |
|
365 | - : $this->form_action; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * @param string $form_action |
|
371 | - * @throws InvalidDataTypeException |
|
372 | - */ |
|
373 | - public function setFormAction($form_action) |
|
374 | - { |
|
375 | - if (! is_string($form_action)) { |
|
376 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
377 | - } |
|
378 | - $this->form_action = $form_action; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * @param array $form_args |
|
384 | - * @throws InvalidDataTypeException |
|
385 | - * @throws InvalidArgumentException |
|
386 | - */ |
|
387 | - public function addFormActionArgs($form_args = array()) |
|
388 | - { |
|
389 | - if (is_object($form_args)) { |
|
390 | - throw new InvalidDataTypeException( |
|
391 | - '$form_args', |
|
392 | - $form_args, |
|
393 | - 'anything other than an object was expected.' |
|
394 | - ); |
|
395 | - } |
|
396 | - if (empty($form_args)) { |
|
397 | - throw new InvalidArgumentException( |
|
398 | - esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
399 | - ); |
|
400 | - } |
|
401 | - $this->form_args = array_merge($this->form_args, $form_args); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * @return string |
|
407 | - */ |
|
408 | - public function formConfig() |
|
409 | - { |
|
410 | - return $this->form_config; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * @param string $form_config |
|
416 | - * @throws DomainException |
|
417 | - */ |
|
418 | - public function setFormConfig($form_config) |
|
419 | - { |
|
420 | - if ( |
|
421 | - ! in_array( |
|
422 | - $form_config, |
|
423 | - array( |
|
424 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
425 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
426 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
427 | - FormHandler::DO_NOT_SETUP_FORM, |
|
428 | - ), |
|
429 | - true |
|
430 | - ) |
|
431 | - ) { |
|
432 | - throw new DomainException( |
|
433 | - sprintf( |
|
434 | - esc_html__( |
|
435 | - '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
436 | - 'event_espresso' |
|
437 | - ), |
|
438 | - $form_config |
|
439 | - ) |
|
440 | - ); |
|
441 | - } |
|
442 | - $this->form_config = $form_config; |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * called after the form is instantiated |
|
448 | - * and used for performing any logic that needs to occur early |
|
449 | - * before any of the other methods are called. |
|
450 | - * returns true if everything is ok to proceed, |
|
451 | - * and false if no further form logic should be implemented |
|
452 | - * |
|
453 | - * @return boolean |
|
454 | - */ |
|
455 | - public function initialize() |
|
456 | - { |
|
457 | - $this->form_has_errors = EE_Error::has_error(true); |
|
458 | - return true; |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * used for setting up css and js |
|
464 | - * |
|
465 | - * @return void |
|
466 | - * @throws LogicException |
|
467 | - * @throws EE_Error |
|
468 | - */ |
|
469 | - public function enqueueStylesAndScripts() |
|
470 | - { |
|
471 | - $this->form()->enqueue_js(); |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * creates and returns the actual form |
|
477 | - * |
|
478 | - * @return EE_Form_Section_Proper |
|
479 | - */ |
|
480 | - abstract public function generate(); |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
485 | - * |
|
486 | - * @param string $text |
|
487 | - * @return EE_Submit_Input |
|
488 | - */ |
|
489 | - public function generateSubmitButton($text = '') |
|
490 | - { |
|
491 | - $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
492 | - return new EE_Submit_Input( |
|
493 | - array( |
|
494 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
495 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
496 | - 'html_class' => 'ee-form-submit', |
|
497 | - 'html_label' => ' ', |
|
498 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
499 | - 'default' => $text, |
|
500 | - ) |
|
501 | - ); |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - /** |
|
506 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
507 | - * |
|
508 | - * @param string $text |
|
509 | - * @return void |
|
510 | - * @throws EE_Error |
|
511 | - */ |
|
512 | - public function appendSubmitButton($text = '') |
|
513 | - { |
|
514 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
515 | - return; |
|
516 | - } |
|
517 | - $this->form->add_subsections( |
|
518 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
519 | - null, |
|
520 | - false |
|
521 | - ); |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
527 | - * |
|
528 | - * @param string $text |
|
529 | - * @return EE_Submit_Input |
|
530 | - */ |
|
531 | - public function generateCancelButton($text = '') |
|
532 | - { |
|
533 | - $cancel_button = new EE_Submit_Input( |
|
534 | - array( |
|
535 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
536 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
537 | - 'html_class' => 'ee-cancel-form', |
|
538 | - 'html_label' => ' ', |
|
539 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
540 | - 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
541 | - ) |
|
542 | - ); |
|
543 | - $cancel_button->set_button_css_attributes(false); |
|
544 | - return $cancel_button; |
|
545 | - } |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * appends a float clearing div onto end of form |
|
550 | - * |
|
551 | - * @return void |
|
552 | - * @throws EE_Error |
|
553 | - */ |
|
554 | - public function clearFormButtonFloats() |
|
555 | - { |
|
556 | - $this->form->add_subsections( |
|
557 | - array( |
|
558 | - 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
559 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
560 | - ), |
|
561 | - ), |
|
562 | - null, |
|
563 | - false |
|
564 | - ); |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
570 | - * returns a string of HTML that can be directly echoed in a template |
|
571 | - * |
|
572 | - * @return string |
|
573 | - * @throws \InvalidArgumentException |
|
574 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
575 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
576 | - * @throws LogicException |
|
577 | - * @throws EE_Error |
|
578 | - */ |
|
579 | - public function display() |
|
580 | - { |
|
581 | - $form_html = apply_filters( |
|
582 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
583 | - '' |
|
584 | - ); |
|
585 | - $form_config = $this->formConfig(); |
|
586 | - if ( |
|
587 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
588 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
589 | - ) { |
|
590 | - $additional_props = $this->requiresMultipartEnctype() |
|
591 | - ? ' enctype="multipart/form-data"' |
|
592 | - : ''; |
|
593 | - $form_html .= $this->form()->form_open( |
|
594 | - $this->formAction(), |
|
595 | - 'POST', |
|
596 | - $additional_props |
|
597 | - ); |
|
598 | - } |
|
599 | - $form_html .= $this->form(true)->get_html(); |
|
600 | - if ( |
|
601 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
602 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
603 | - ) { |
|
604 | - $form_html .= $this->form()->form_close(); |
|
605 | - } |
|
606 | - $form_html .= apply_filters( |
|
607 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
608 | - '' |
|
609 | - ); |
|
610 | - return $form_html; |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
615 | - * @since 4.9.80.p |
|
616 | - * @return bool |
|
617 | - * @throws EE_Error |
|
618 | - */ |
|
619 | - public function requiresMultipartEnctype() |
|
620 | - { |
|
621 | - foreach ($this->form()->inputs_in_subsections() as $input) { |
|
622 | - if ($input instanceof EE_File_Input) { |
|
623 | - return true; |
|
624 | - } |
|
625 | - } |
|
626 | - return false; |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - /** |
|
631 | - * handles processing the form submission |
|
632 | - * returns true or false depending on whether the form was processed successfully or not |
|
633 | - * |
|
634 | - * @param array $submitted_form_data |
|
635 | - * @return array |
|
636 | - * @throws \InvalidArgumentException |
|
637 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
638 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
639 | - * @throws EE_Error |
|
640 | - * @throws LogicException |
|
641 | - * @throws InvalidFormSubmissionException |
|
642 | - */ |
|
643 | - public function process($submitted_form_data = array()) |
|
644 | - { |
|
645 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
646 | - throw new InvalidFormSubmissionException($this->form_name); |
|
647 | - } |
|
648 | - $this->form(true)->receive_form_submission($submitted_form_data); |
|
649 | - if (! $this->form()->is_valid()) { |
|
650 | - throw new InvalidFormSubmissionException( |
|
651 | - $this->form_name, |
|
652 | - sprintf( |
|
653 | - esc_html__( |
|
654 | - 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
655 | - 'event_espresso' |
|
656 | - ), |
|
657 | - $this->form_name, |
|
658 | - '<br />', |
|
659 | - implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
660 | - ) |
|
661 | - ); |
|
662 | - } |
|
663 | - return apply_filters( |
|
664 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
665 | - $this->form()->valid_data(), |
|
666 | - $this |
|
667 | - ); |
|
668 | - } |
|
31 | + /** |
|
32 | + * will add opening and closing HTML form tags as well as a submit button |
|
33 | + */ |
|
34 | + const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
35 | + |
|
36 | + /** |
|
37 | + * will add opening and closing HTML form tags but NOT a submit button |
|
38 | + */ |
|
39 | + const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
40 | + |
|
41 | + /** |
|
42 | + * will NOT add opening and closing HTML form tags but will add a submit button |
|
43 | + */ |
|
44 | + const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
45 | + |
|
46 | + /** |
|
47 | + * will NOT add opening and closing HTML form tags NOR a submit button |
|
48 | + */ |
|
49 | + const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
50 | + |
|
51 | + /** |
|
52 | + * if set to false, then this form has no displayable content, |
|
53 | + * and will only be used for processing data sent passed via GET or POST |
|
54 | + * defaults to true ( ie: form has displayable content ) |
|
55 | + * |
|
56 | + * @var boolean $displayable |
|
57 | + */ |
|
58 | + private $displayable = true; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var string $form_name |
|
62 | + */ |
|
63 | + private $form_name; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var string $admin_name |
|
67 | + */ |
|
68 | + private $admin_name; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var string $slug |
|
72 | + */ |
|
73 | + private $slug; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var string $submit_btn_text |
|
77 | + */ |
|
78 | + private $submit_btn_text; |
|
79 | + |
|
80 | + /** |
|
81 | + * @var string $form_action |
|
82 | + */ |
|
83 | + private $form_action; |
|
84 | + |
|
85 | + /** |
|
86 | + * form params in key value pairs |
|
87 | + * can be added to form action URL or as hidden inputs |
|
88 | + * |
|
89 | + * @var array $form_args |
|
90 | + */ |
|
91 | + private $form_args = array(); |
|
92 | + |
|
93 | + /** |
|
94 | + * value of one of the string constant above |
|
95 | + * |
|
96 | + * @var string $form_config |
|
97 | + */ |
|
98 | + private $form_config; |
|
99 | + |
|
100 | + /** |
|
101 | + * whether or not the form was determined to be invalid |
|
102 | + * |
|
103 | + * @var boolean $form_has_errors |
|
104 | + */ |
|
105 | + private $form_has_errors; |
|
106 | + |
|
107 | + /** |
|
108 | + * the absolute top level form section being used on the page |
|
109 | + * |
|
110 | + * @var EE_Form_Section_Proper $form |
|
111 | + */ |
|
112 | + private $form; |
|
113 | + |
|
114 | + /** |
|
115 | + * @var EE_Registry $registry |
|
116 | + */ |
|
117 | + protected $registry; |
|
118 | + |
|
119 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * Form constructor. |
|
124 | + * |
|
125 | + * @param string $form_name |
|
126 | + * @param string $admin_name |
|
127 | + * @param string $slug |
|
128 | + * @param string $form_action |
|
129 | + * @param string $form_config |
|
130 | + * @param EE_Registry|null $registry |
|
131 | + */ |
|
132 | + public function __construct( |
|
133 | + $form_name, |
|
134 | + $admin_name, |
|
135 | + $slug, |
|
136 | + $form_action = '', |
|
137 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
138 | + EE_Registry $registry = null |
|
139 | + ) { |
|
140 | + $this->setFormName($form_name); |
|
141 | + $this->setAdminName($admin_name); |
|
142 | + $this->setSlug($slug); |
|
143 | + $this->setFormAction($form_action); |
|
144 | + $this->setFormConfig($form_config); |
|
145 | + $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
146 | + $this->registry = $registry; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + public static function getFormConfigConstants() |
|
154 | + { |
|
155 | + return array( |
|
156 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
157 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
158 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
159 | + FormHandler::DO_NOT_SETUP_FORM, |
|
160 | + ); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * @param bool $for_display |
|
166 | + * @return EE_Form_Section_Proper |
|
167 | + * @throws EE_Error |
|
168 | + * @throws LogicException |
|
169 | + */ |
|
170 | + public function form($for_display = false) |
|
171 | + { |
|
172 | + if (! $this->formIsValid()) { |
|
173 | + return null; |
|
174 | + } |
|
175 | + if ($for_display) { |
|
176 | + $form_config = $this->formConfig(); |
|
177 | + if ( |
|
178 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
179 | + || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
180 | + ) { |
|
181 | + $this->appendSubmitButton(); |
|
182 | + $this->clearFormButtonFloats(); |
|
183 | + } |
|
184 | + } |
|
185 | + return $this->form; |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * @return boolean |
|
191 | + * @throws LogicException |
|
192 | + */ |
|
193 | + public function formIsValid() |
|
194 | + { |
|
195 | + if ($this->form instanceof EE_Form_Section_Proper) { |
|
196 | + return true; |
|
197 | + } |
|
198 | + $form = apply_filters( |
|
199 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
200 | + $this->generate(), |
|
201 | + $this |
|
202 | + ); |
|
203 | + if ($this->verifyForm($form)) { |
|
204 | + $this->setForm($form); |
|
205 | + } |
|
206 | + return true; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * @param EE_Form_Section_Proper|null $form |
|
212 | + * @return bool |
|
213 | + * @throws LogicException |
|
214 | + */ |
|
215 | + public function verifyForm(EE_Form_Section_Proper $form = null) |
|
216 | + { |
|
217 | + $form = $form !== null ? $form : $this->form; |
|
218 | + if ($form instanceof EE_Form_Section_Proper) { |
|
219 | + return true; |
|
220 | + } |
|
221 | + throw new LogicException( |
|
222 | + sprintf( |
|
223 | + esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
224 | + $this->form_name, |
|
225 | + var_export($form, true) |
|
226 | + ) |
|
227 | + ); |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * @param EE_Form_Section_Proper $form |
|
233 | + */ |
|
234 | + public function setForm(EE_Form_Section_Proper $form) |
|
235 | + { |
|
236 | + $this->form = $form; |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * @return boolean |
|
242 | + */ |
|
243 | + public function displayable() |
|
244 | + { |
|
245 | + return $this->displayable; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * @param boolean $displayable |
|
251 | + */ |
|
252 | + public function setDisplayable($displayable = false) |
|
253 | + { |
|
254 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * a public name for the form that can be displayed on the frontend of a site |
|
260 | + * |
|
261 | + * @return string |
|
262 | + */ |
|
263 | + public function formName() |
|
264 | + { |
|
265 | + return $this->form_name; |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * @param string $form_name |
|
271 | + * @throws InvalidDataTypeException |
|
272 | + */ |
|
273 | + public function setFormName($form_name) |
|
274 | + { |
|
275 | + if (! is_string($form_name)) { |
|
276 | + throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
277 | + } |
|
278 | + $this->form_name = $form_name; |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * a public name for the form that can be displayed, but only in the admin |
|
284 | + * |
|
285 | + * @return string |
|
286 | + */ |
|
287 | + public function adminName() |
|
288 | + { |
|
289 | + return $this->admin_name; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * @param string $admin_name |
|
295 | + * @throws InvalidDataTypeException |
|
296 | + */ |
|
297 | + public function setAdminName($admin_name) |
|
298 | + { |
|
299 | + if (! is_string($admin_name)) { |
|
300 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
301 | + } |
|
302 | + $this->admin_name = $admin_name; |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * a URL friendly string that can be used for identifying the form |
|
308 | + * |
|
309 | + * @return string |
|
310 | + */ |
|
311 | + public function slug() |
|
312 | + { |
|
313 | + return $this->slug; |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * @param string $slug |
|
319 | + * @throws InvalidDataTypeException |
|
320 | + */ |
|
321 | + public function setSlug($slug) |
|
322 | + { |
|
323 | + if (! is_string($slug)) { |
|
324 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
325 | + } |
|
326 | + $this->slug = $slug; |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * @return string |
|
332 | + */ |
|
333 | + public function submitBtnText() |
|
334 | + { |
|
335 | + return $this->submit_btn_text; |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * @param string $submit_btn_text |
|
341 | + * @throws InvalidDataTypeException |
|
342 | + * @throws InvalidArgumentException |
|
343 | + */ |
|
344 | + public function setSubmitBtnText($submit_btn_text) |
|
345 | + { |
|
346 | + if (! is_string($submit_btn_text)) { |
|
347 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
348 | + } |
|
349 | + if (empty($submit_btn_text)) { |
|
350 | + throw new InvalidArgumentException( |
|
351 | + esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
352 | + ); |
|
353 | + } |
|
354 | + $this->submit_btn_text = $submit_btn_text; |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * @return string |
|
360 | + */ |
|
361 | + public function formAction() |
|
362 | + { |
|
363 | + return ! empty($this->form_args) |
|
364 | + ? add_query_arg($this->form_args, $this->form_action) |
|
365 | + : $this->form_action; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * @param string $form_action |
|
371 | + * @throws InvalidDataTypeException |
|
372 | + */ |
|
373 | + public function setFormAction($form_action) |
|
374 | + { |
|
375 | + if (! is_string($form_action)) { |
|
376 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
377 | + } |
|
378 | + $this->form_action = $form_action; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * @param array $form_args |
|
384 | + * @throws InvalidDataTypeException |
|
385 | + * @throws InvalidArgumentException |
|
386 | + */ |
|
387 | + public function addFormActionArgs($form_args = array()) |
|
388 | + { |
|
389 | + if (is_object($form_args)) { |
|
390 | + throw new InvalidDataTypeException( |
|
391 | + '$form_args', |
|
392 | + $form_args, |
|
393 | + 'anything other than an object was expected.' |
|
394 | + ); |
|
395 | + } |
|
396 | + if (empty($form_args)) { |
|
397 | + throw new InvalidArgumentException( |
|
398 | + esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
399 | + ); |
|
400 | + } |
|
401 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * @return string |
|
407 | + */ |
|
408 | + public function formConfig() |
|
409 | + { |
|
410 | + return $this->form_config; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * @param string $form_config |
|
416 | + * @throws DomainException |
|
417 | + */ |
|
418 | + public function setFormConfig($form_config) |
|
419 | + { |
|
420 | + if ( |
|
421 | + ! in_array( |
|
422 | + $form_config, |
|
423 | + array( |
|
424 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
425 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
426 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
427 | + FormHandler::DO_NOT_SETUP_FORM, |
|
428 | + ), |
|
429 | + true |
|
430 | + ) |
|
431 | + ) { |
|
432 | + throw new DomainException( |
|
433 | + sprintf( |
|
434 | + esc_html__( |
|
435 | + '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
436 | + 'event_espresso' |
|
437 | + ), |
|
438 | + $form_config |
|
439 | + ) |
|
440 | + ); |
|
441 | + } |
|
442 | + $this->form_config = $form_config; |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * called after the form is instantiated |
|
448 | + * and used for performing any logic that needs to occur early |
|
449 | + * before any of the other methods are called. |
|
450 | + * returns true if everything is ok to proceed, |
|
451 | + * and false if no further form logic should be implemented |
|
452 | + * |
|
453 | + * @return boolean |
|
454 | + */ |
|
455 | + public function initialize() |
|
456 | + { |
|
457 | + $this->form_has_errors = EE_Error::has_error(true); |
|
458 | + return true; |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * used for setting up css and js |
|
464 | + * |
|
465 | + * @return void |
|
466 | + * @throws LogicException |
|
467 | + * @throws EE_Error |
|
468 | + */ |
|
469 | + public function enqueueStylesAndScripts() |
|
470 | + { |
|
471 | + $this->form()->enqueue_js(); |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * creates and returns the actual form |
|
477 | + * |
|
478 | + * @return EE_Form_Section_Proper |
|
479 | + */ |
|
480 | + abstract public function generate(); |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
485 | + * |
|
486 | + * @param string $text |
|
487 | + * @return EE_Submit_Input |
|
488 | + */ |
|
489 | + public function generateSubmitButton($text = '') |
|
490 | + { |
|
491 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
492 | + return new EE_Submit_Input( |
|
493 | + array( |
|
494 | + 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
495 | + 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
496 | + 'html_class' => 'ee-form-submit', |
|
497 | + 'html_label' => ' ', |
|
498 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
499 | + 'default' => $text, |
|
500 | + ) |
|
501 | + ); |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + /** |
|
506 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
507 | + * |
|
508 | + * @param string $text |
|
509 | + * @return void |
|
510 | + * @throws EE_Error |
|
511 | + */ |
|
512 | + public function appendSubmitButton($text = '') |
|
513 | + { |
|
514 | + if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
515 | + return; |
|
516 | + } |
|
517 | + $this->form->add_subsections( |
|
518 | + array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
519 | + null, |
|
520 | + false |
|
521 | + ); |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
527 | + * |
|
528 | + * @param string $text |
|
529 | + * @return EE_Submit_Input |
|
530 | + */ |
|
531 | + public function generateCancelButton($text = '') |
|
532 | + { |
|
533 | + $cancel_button = new EE_Submit_Input( |
|
534 | + array( |
|
535 | + 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
536 | + 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
537 | + 'html_class' => 'ee-cancel-form', |
|
538 | + 'html_label' => ' ', |
|
539 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
540 | + 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
541 | + ) |
|
542 | + ); |
|
543 | + $cancel_button->set_button_css_attributes(false); |
|
544 | + return $cancel_button; |
|
545 | + } |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * appends a float clearing div onto end of form |
|
550 | + * |
|
551 | + * @return void |
|
552 | + * @throws EE_Error |
|
553 | + */ |
|
554 | + public function clearFormButtonFloats() |
|
555 | + { |
|
556 | + $this->form->add_subsections( |
|
557 | + array( |
|
558 | + 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
559 | + EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
560 | + ), |
|
561 | + ), |
|
562 | + null, |
|
563 | + false |
|
564 | + ); |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
570 | + * returns a string of HTML that can be directly echoed in a template |
|
571 | + * |
|
572 | + * @return string |
|
573 | + * @throws \InvalidArgumentException |
|
574 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
575 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
576 | + * @throws LogicException |
|
577 | + * @throws EE_Error |
|
578 | + */ |
|
579 | + public function display() |
|
580 | + { |
|
581 | + $form_html = apply_filters( |
|
582 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
583 | + '' |
|
584 | + ); |
|
585 | + $form_config = $this->formConfig(); |
|
586 | + if ( |
|
587 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
588 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
589 | + ) { |
|
590 | + $additional_props = $this->requiresMultipartEnctype() |
|
591 | + ? ' enctype="multipart/form-data"' |
|
592 | + : ''; |
|
593 | + $form_html .= $this->form()->form_open( |
|
594 | + $this->formAction(), |
|
595 | + 'POST', |
|
596 | + $additional_props |
|
597 | + ); |
|
598 | + } |
|
599 | + $form_html .= $this->form(true)->get_html(); |
|
600 | + if ( |
|
601 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
602 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
603 | + ) { |
|
604 | + $form_html .= $this->form()->form_close(); |
|
605 | + } |
|
606 | + $form_html .= apply_filters( |
|
607 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
608 | + '' |
|
609 | + ); |
|
610 | + return $form_html; |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
615 | + * @since 4.9.80.p |
|
616 | + * @return bool |
|
617 | + * @throws EE_Error |
|
618 | + */ |
|
619 | + public function requiresMultipartEnctype() |
|
620 | + { |
|
621 | + foreach ($this->form()->inputs_in_subsections() as $input) { |
|
622 | + if ($input instanceof EE_File_Input) { |
|
623 | + return true; |
|
624 | + } |
|
625 | + } |
|
626 | + return false; |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + /** |
|
631 | + * handles processing the form submission |
|
632 | + * returns true or false depending on whether the form was processed successfully or not |
|
633 | + * |
|
634 | + * @param array $submitted_form_data |
|
635 | + * @return array |
|
636 | + * @throws \InvalidArgumentException |
|
637 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
638 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
639 | + * @throws EE_Error |
|
640 | + * @throws LogicException |
|
641 | + * @throws InvalidFormSubmissionException |
|
642 | + */ |
|
643 | + public function process($submitted_form_data = array()) |
|
644 | + { |
|
645 | + if (! $this->form()->was_submitted($submitted_form_data)) { |
|
646 | + throw new InvalidFormSubmissionException($this->form_name); |
|
647 | + } |
|
648 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
649 | + if (! $this->form()->is_valid()) { |
|
650 | + throw new InvalidFormSubmissionException( |
|
651 | + $this->form_name, |
|
652 | + sprintf( |
|
653 | + esc_html__( |
|
654 | + 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
655 | + 'event_espresso' |
|
656 | + ), |
|
657 | + $this->form_name, |
|
658 | + '<br />', |
|
659 | + implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
660 | + ) |
|
661 | + ); |
|
662 | + } |
|
663 | + return apply_filters( |
|
664 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
665 | + $this->form()->valid_data(), |
|
666 | + $this |
|
667 | + ); |
|
668 | + } |
|
669 | 669 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | public function setOrder($order) |
114 | 114 | { |
115 | 115 | $order = absint($order); |
116 | - if (! $order > 0) { |
|
116 | + if ( ! $order > 0) { |
|
117 | 117 | throw new InvalidArgumentException( |
118 | 118 | esc_html__('The form order property must be a positive integer.', 'event_espresso') |
119 | 119 | ); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function setRedirectUrl($redirect_url) |
144 | 144 | { |
145 | - if (! is_string($redirect_url)) { |
|
145 | + if ( ! is_string($redirect_url)) { |
|
146 | 146 | throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string'); |
147 | 147 | } |
148 | 148 | if (empty($redirect_url)) { |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | ); |
200 | 200 | } |
201 | 201 | foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) { |
202 | - unset($this->redirect_args[ $redirect_arg_key ]); |
|
202 | + unset($this->redirect_args[$redirect_arg_key]); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 |
@@ -18,224 +18,224 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class SequentialStepForm extends FormHandler implements SequentialStepFormInterface |
20 | 20 | { |
21 | - const REDIRECT_TO_NEXT_STEP = 'redirect_to_next_step'; |
|
22 | - |
|
23 | - const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step'; |
|
24 | - |
|
25 | - const REDIRECT_TO_PREV_STEP = 'redirect_to_prev_step'; |
|
26 | - |
|
27 | - const REDIRECT_TO_OTHER = 'redirect_to_other'; |
|
28 | - |
|
29 | - /** |
|
30 | - * numerical value used for sorting form steps |
|
31 | - * |
|
32 | - * @var int $order |
|
33 | - */ |
|
34 | - private $order = 1; |
|
35 | - |
|
36 | - /** |
|
37 | - * a final URL with all form related parameters added |
|
38 | - * that will be used to advance to the next step |
|
39 | - * |
|
40 | - * @var string $redirect_url |
|
41 | - */ |
|
42 | - private $redirect_url = ''; |
|
43 | - |
|
44 | - /** |
|
45 | - * URL params in key value pairs |
|
46 | - * |
|
47 | - * @var array $redirect_args |
|
48 | - */ |
|
49 | - private $redirect_args = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * Which step should be redirected to after form processing. |
|
53 | - * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP |
|
54 | - * If a form is invalid and requires errors to be corrected, |
|
55 | - * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted |
|
56 | - * Some form handlers do not have a form that is displayable, |
|
57 | - * and only perform data processing, but if an error occurs, |
|
58 | - * then this value needs to be set to REDIRECT_TO_PREV_STEP |
|
59 | - * since the current step has no displayable content. |
|
60 | - * if the form is completely finished, and needs to redirect to somewhere |
|
61 | - * completely different, then this value will be REDIRECT_TO_OTHER |
|
62 | - * |
|
63 | - * @var string $redirect_to |
|
64 | - */ |
|
65 | - private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP; |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * SequentialStepForm constructor |
|
70 | - * |
|
71 | - * @param int $order |
|
72 | - * @param string $form_name |
|
73 | - * @param string $admin_name |
|
74 | - * @param string $slug |
|
75 | - * @param string $form_action |
|
76 | - * @param string $form_config |
|
77 | - * @param EE_Registry|null $registry |
|
78 | - */ |
|
79 | - public function __construct( |
|
80 | - $order, |
|
81 | - $form_name, |
|
82 | - $admin_name, |
|
83 | - $slug, |
|
84 | - $form_action = '', |
|
85 | - $form_config = 'add_form_tags_and_submit', |
|
86 | - EE_Registry $registry = null |
|
87 | - ) { |
|
88 | - $this->setOrder($order); |
|
89 | - parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @return int |
|
96 | - */ |
|
97 | - public function order() |
|
98 | - { |
|
99 | - return $this->order; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @param int $order |
|
106 | - * @throws InvalidArgumentException |
|
107 | - */ |
|
108 | - public function setOrder($order) |
|
109 | - { |
|
110 | - $order = absint($order); |
|
111 | - if (! $order > 0) { |
|
112 | - throw new InvalidArgumentException( |
|
113 | - esc_html__('The form order property must be a positive integer.', 'event_espresso') |
|
114 | - ); |
|
115 | - } |
|
116 | - $this->order = $order; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - public function redirectUrl() |
|
125 | - { |
|
126 | - return ! empty($this->redirect_args) |
|
127 | - ? add_query_arg($this->redirect_args, $this->redirect_url) |
|
128 | - : $this->redirect_url; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @param string $redirect_url |
|
135 | - * @throws InvalidDataTypeException |
|
136 | - * @throws InvalidArgumentException |
|
137 | - */ |
|
138 | - public function setRedirectUrl($redirect_url) |
|
139 | - { |
|
140 | - if (! is_string($redirect_url)) { |
|
141 | - throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string'); |
|
142 | - } |
|
143 | - if (empty($redirect_url)) { |
|
144 | - throw new InvalidArgumentException( |
|
145 | - esc_html__('The redirect URL can not be an empty string.', 'event_espresso') |
|
146 | - ); |
|
147 | - } |
|
148 | - $this->redirect_url = $redirect_url; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param array $redirect_args |
|
155 | - * @throws InvalidDataTypeException |
|
156 | - * @throws InvalidArgumentException |
|
157 | - */ |
|
158 | - public function addRedirectArgs($redirect_args = array()) |
|
159 | - { |
|
160 | - if (is_object($redirect_args)) { |
|
161 | - throw new InvalidDataTypeException( |
|
162 | - '$redirect_args', |
|
163 | - $redirect_args, |
|
164 | - 'anything other than an object was expected.' |
|
165 | - ); |
|
166 | - } |
|
167 | - if (empty($redirect_args)) { |
|
168 | - throw new InvalidArgumentException( |
|
169 | - esc_html__('The redirect argument can not be an empty array.', 'event_espresso') |
|
170 | - ); |
|
171 | - } |
|
172 | - $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args); |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @param array $redirect_arg_keys_to_remove |
|
179 | - * @throws InvalidDataTypeException |
|
180 | - * @throws InvalidArgumentException |
|
181 | - */ |
|
182 | - public function removeRedirectArgs($redirect_arg_keys_to_remove = array()) |
|
183 | - { |
|
184 | - if (is_object($redirect_arg_keys_to_remove)) { |
|
185 | - throw new InvalidDataTypeException( |
|
186 | - '$redirect_arg_keys_to_remove', |
|
187 | - $redirect_arg_keys_to_remove, |
|
188 | - 'anything other than an object was expected.' |
|
189 | - ); |
|
190 | - } |
|
191 | - if (empty($redirect_arg_keys_to_remove)) { |
|
192 | - throw new InvalidArgumentException( |
|
193 | - esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso') |
|
194 | - ); |
|
195 | - } |
|
196 | - foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) { |
|
197 | - unset($this->redirect_args[ $redirect_arg_key ]); |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - public function redirectTo() |
|
207 | - { |
|
208 | - return $this->redirect_to; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * @param string $redirect_to |
|
215 | - * @throws InvalidDataTypeException |
|
216 | - */ |
|
217 | - public function setRedirectTo($redirect_to) |
|
218 | - { |
|
219 | - if ( |
|
220 | - ! in_array( |
|
221 | - $redirect_to, |
|
222 | - array( |
|
223 | - SequentialStepForm::REDIRECT_TO_NEXT_STEP, |
|
224 | - SequentialStepForm::REDIRECT_TO_CURRENT_STEP, |
|
225 | - SequentialStepForm::REDIRECT_TO_PREV_STEP, |
|
226 | - SequentialStepForm::REDIRECT_TO_OTHER, |
|
227 | - ), |
|
228 | - true |
|
229 | - ) |
|
230 | - ) { |
|
231 | - throw new InvalidDataTypeException( |
|
232 | - 'setRedirectTo()', |
|
233 | - $redirect_to, |
|
234 | - 'one of the SequentialStepForm class constants was expected.' |
|
235 | - ); |
|
236 | - } |
|
237 | - $this->redirect_to = $redirect_to; |
|
238 | - } |
|
21 | + const REDIRECT_TO_NEXT_STEP = 'redirect_to_next_step'; |
|
22 | + |
|
23 | + const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step'; |
|
24 | + |
|
25 | + const REDIRECT_TO_PREV_STEP = 'redirect_to_prev_step'; |
|
26 | + |
|
27 | + const REDIRECT_TO_OTHER = 'redirect_to_other'; |
|
28 | + |
|
29 | + /** |
|
30 | + * numerical value used for sorting form steps |
|
31 | + * |
|
32 | + * @var int $order |
|
33 | + */ |
|
34 | + private $order = 1; |
|
35 | + |
|
36 | + /** |
|
37 | + * a final URL with all form related parameters added |
|
38 | + * that will be used to advance to the next step |
|
39 | + * |
|
40 | + * @var string $redirect_url |
|
41 | + */ |
|
42 | + private $redirect_url = ''; |
|
43 | + |
|
44 | + /** |
|
45 | + * URL params in key value pairs |
|
46 | + * |
|
47 | + * @var array $redirect_args |
|
48 | + */ |
|
49 | + private $redirect_args = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * Which step should be redirected to after form processing. |
|
53 | + * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP |
|
54 | + * If a form is invalid and requires errors to be corrected, |
|
55 | + * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted |
|
56 | + * Some form handlers do not have a form that is displayable, |
|
57 | + * and only perform data processing, but if an error occurs, |
|
58 | + * then this value needs to be set to REDIRECT_TO_PREV_STEP |
|
59 | + * since the current step has no displayable content. |
|
60 | + * if the form is completely finished, and needs to redirect to somewhere |
|
61 | + * completely different, then this value will be REDIRECT_TO_OTHER |
|
62 | + * |
|
63 | + * @var string $redirect_to |
|
64 | + */ |
|
65 | + private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP; |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * SequentialStepForm constructor |
|
70 | + * |
|
71 | + * @param int $order |
|
72 | + * @param string $form_name |
|
73 | + * @param string $admin_name |
|
74 | + * @param string $slug |
|
75 | + * @param string $form_action |
|
76 | + * @param string $form_config |
|
77 | + * @param EE_Registry|null $registry |
|
78 | + */ |
|
79 | + public function __construct( |
|
80 | + $order, |
|
81 | + $form_name, |
|
82 | + $admin_name, |
|
83 | + $slug, |
|
84 | + $form_action = '', |
|
85 | + $form_config = 'add_form_tags_and_submit', |
|
86 | + EE_Registry $registry = null |
|
87 | + ) { |
|
88 | + $this->setOrder($order); |
|
89 | + parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @return int |
|
96 | + */ |
|
97 | + public function order() |
|
98 | + { |
|
99 | + return $this->order; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @param int $order |
|
106 | + * @throws InvalidArgumentException |
|
107 | + */ |
|
108 | + public function setOrder($order) |
|
109 | + { |
|
110 | + $order = absint($order); |
|
111 | + if (! $order > 0) { |
|
112 | + throw new InvalidArgumentException( |
|
113 | + esc_html__('The form order property must be a positive integer.', 'event_espresso') |
|
114 | + ); |
|
115 | + } |
|
116 | + $this->order = $order; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + public function redirectUrl() |
|
125 | + { |
|
126 | + return ! empty($this->redirect_args) |
|
127 | + ? add_query_arg($this->redirect_args, $this->redirect_url) |
|
128 | + : $this->redirect_url; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @param string $redirect_url |
|
135 | + * @throws InvalidDataTypeException |
|
136 | + * @throws InvalidArgumentException |
|
137 | + */ |
|
138 | + public function setRedirectUrl($redirect_url) |
|
139 | + { |
|
140 | + if (! is_string($redirect_url)) { |
|
141 | + throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string'); |
|
142 | + } |
|
143 | + if (empty($redirect_url)) { |
|
144 | + throw new InvalidArgumentException( |
|
145 | + esc_html__('The redirect URL can not be an empty string.', 'event_espresso') |
|
146 | + ); |
|
147 | + } |
|
148 | + $this->redirect_url = $redirect_url; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param array $redirect_args |
|
155 | + * @throws InvalidDataTypeException |
|
156 | + * @throws InvalidArgumentException |
|
157 | + */ |
|
158 | + public function addRedirectArgs($redirect_args = array()) |
|
159 | + { |
|
160 | + if (is_object($redirect_args)) { |
|
161 | + throw new InvalidDataTypeException( |
|
162 | + '$redirect_args', |
|
163 | + $redirect_args, |
|
164 | + 'anything other than an object was expected.' |
|
165 | + ); |
|
166 | + } |
|
167 | + if (empty($redirect_args)) { |
|
168 | + throw new InvalidArgumentException( |
|
169 | + esc_html__('The redirect argument can not be an empty array.', 'event_espresso') |
|
170 | + ); |
|
171 | + } |
|
172 | + $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args); |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @param array $redirect_arg_keys_to_remove |
|
179 | + * @throws InvalidDataTypeException |
|
180 | + * @throws InvalidArgumentException |
|
181 | + */ |
|
182 | + public function removeRedirectArgs($redirect_arg_keys_to_remove = array()) |
|
183 | + { |
|
184 | + if (is_object($redirect_arg_keys_to_remove)) { |
|
185 | + throw new InvalidDataTypeException( |
|
186 | + '$redirect_arg_keys_to_remove', |
|
187 | + $redirect_arg_keys_to_remove, |
|
188 | + 'anything other than an object was expected.' |
|
189 | + ); |
|
190 | + } |
|
191 | + if (empty($redirect_arg_keys_to_remove)) { |
|
192 | + throw new InvalidArgumentException( |
|
193 | + esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso') |
|
194 | + ); |
|
195 | + } |
|
196 | + foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) { |
|
197 | + unset($this->redirect_args[ $redirect_arg_key ]); |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + public function redirectTo() |
|
207 | + { |
|
208 | + return $this->redirect_to; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * @param string $redirect_to |
|
215 | + * @throws InvalidDataTypeException |
|
216 | + */ |
|
217 | + public function setRedirectTo($redirect_to) |
|
218 | + { |
|
219 | + if ( |
|
220 | + ! in_array( |
|
221 | + $redirect_to, |
|
222 | + array( |
|
223 | + SequentialStepForm::REDIRECT_TO_NEXT_STEP, |
|
224 | + SequentialStepForm::REDIRECT_TO_CURRENT_STEP, |
|
225 | + SequentialStepForm::REDIRECT_TO_PREV_STEP, |
|
226 | + SequentialStepForm::REDIRECT_TO_OTHER, |
|
227 | + ), |
|
228 | + true |
|
229 | + ) |
|
230 | + ) { |
|
231 | + throw new InvalidDataTypeException( |
|
232 | + 'setRedirectTo()', |
|
233 | + $redirect_to, |
|
234 | + 'one of the SequentialStepForm class constants was expected.' |
|
235 | + ); |
|
236 | + } |
|
237 | + $this->redirect_to = $redirect_to; |
|
238 | + } |
|
239 | 239 | } |
240 | 240 | // End of file SequentialStepForm.php |
241 | 241 | // Location: /SequentialStepForm.php |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | 'LIN_code' |
74 | 74 | ); |
75 | 75 | if ($line_item_code) { |
76 | - if (! isset($this->_line_item_registrations[ $line_item_code ])) { |
|
77 | - $this->_line_item_registrations[ $line_item_code ] = array(); |
|
76 | + if ( ! isset($this->_line_item_registrations[$line_item_code])) { |
|
77 | + $this->_line_item_registrations[$line_item_code] = array(); |
|
78 | 78 | } |
79 | - $this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration; |
|
79 | + $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration; |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | public function process(EEI_Line_Item $line_item) |
94 | 94 | { |
95 | 95 | $this->_adjust_line_item_quantity($line_item); |
96 | - if (! $line_item->children()) { |
|
96 | + if ( ! $line_item->children()) { |
|
97 | 97 | return $line_item; |
98 | 98 | } |
99 | 99 | // the original running total (taking ALL tickets into account) |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $child_line_item->set_total( |
121 | 121 | $running_total_of_children_under_consideration * $percent_of_running_total |
122 | 122 | ); |
123 | - if (! $child_line_item->is_percent()) { |
|
123 | + if ( ! $child_line_item->is_percent()) { |
|
124 | 124 | $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity()); |
125 | 125 | } |
126 | 126 | } elseif ( |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | $quantity = 0; |
178 | 178 | // if this ticket is billable at this moment, then we should have a positive quantity |
179 | 179 | if ( |
180 | - isset($this->_line_item_registrations[ $line_item->code() ]) |
|
181 | - && is_array($this->_line_item_registrations[ $line_item->code() ]) |
|
180 | + isset($this->_line_item_registrations[$line_item->code()]) |
|
181 | + && is_array($this->_line_item_registrations[$line_item->code()]) |
|
182 | 182 | ) { |
183 | 183 | // set quantity based on number of open registrations for this ticket |
184 | - foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) { |
|
184 | + foreach ($this->_line_item_registrations[$line_item->code()] as $registration) { |
|
185 | 185 | if ( |
186 | 186 | $registration instanceof EE_Registration |
187 | 187 | ) { |
@@ -12,186 +12,186 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Specific_Registrations_Line_Item_Filter extends EE_Line_Item_Filter_Base |
14 | 14 | { |
15 | - /** |
|
16 | - * array of line item codes and their corresponding quantities for registrations |
|
17 | - * |
|
18 | - * @type array $_line_item_registrations |
|
19 | - */ |
|
20 | - protected $_line_item_registrations = array(); |
|
15 | + /** |
|
16 | + * array of line item codes and their corresponding quantities for registrations |
|
17 | + * |
|
18 | + * @type array $_line_item_registrations |
|
19 | + */ |
|
20 | + protected $_line_item_registrations = array(); |
|
21 | 21 | |
22 | - /** |
|
23 | - * Just kept in case we want it someday. Currently unused |
|
24 | - * |
|
25 | - * @var EE_Registration[] |
|
26 | - */ |
|
27 | - protected $_registrations = array(); |
|
22 | + /** |
|
23 | + * Just kept in case we want it someday. Currently unused |
|
24 | + * |
|
25 | + * @var EE_Registration[] |
|
26 | + */ |
|
27 | + protected $_registrations = array(); |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var EE_Registration |
|
31 | - */ |
|
32 | - protected $_current_registration; |
|
29 | + /** |
|
30 | + * @var EE_Registration |
|
31 | + */ |
|
32 | + protected $_current_registration; |
|
33 | 33 | |
34 | - /** |
|
35 | - * these reg statuses should NOT increment the line item quantity |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $_closed_reg_statuses = array(); |
|
34 | + /** |
|
35 | + * these reg statuses should NOT increment the line item quantity |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $_closed_reg_statuses = array(); |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * EE_Billable_Line_Item_Filter constructor. |
|
44 | - * |
|
45 | - * @param EE_Registration[] $registrations |
|
46 | - * @throws EE_Error |
|
47 | - */ |
|
48 | - public function __construct($registrations) |
|
49 | - { |
|
50 | - $this->_registrations = $registrations; |
|
51 | - $this->_calculate_registrations_per_line_item_code($registrations); |
|
52 | - // these reg statuses should NOT increment the line item quantity |
|
53 | - $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
54 | - } |
|
42 | + /** |
|
43 | + * EE_Billable_Line_Item_Filter constructor. |
|
44 | + * |
|
45 | + * @param EE_Registration[] $registrations |
|
46 | + * @throws EE_Error |
|
47 | + */ |
|
48 | + public function __construct($registrations) |
|
49 | + { |
|
50 | + $this->_registrations = $registrations; |
|
51 | + $this->_calculate_registrations_per_line_item_code($registrations); |
|
52 | + // these reg statuses should NOT increment the line item quantity |
|
53 | + $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * sets the _line_item_registrations from the provided registrations |
|
59 | - * |
|
60 | - * @param EE_Registration[] $registrations |
|
61 | - * @return void |
|
62 | - * @throws EE_Error |
|
63 | - */ |
|
64 | - protected function _calculate_registrations_per_line_item_code($registrations) |
|
65 | - { |
|
66 | - foreach ($registrations as $registration) { |
|
67 | - $line_item_code = EEM_Line_Item::instance()->get_var( |
|
68 | - EEM_Line_Item::instance()->line_item_for_registration_query_params( |
|
69 | - $registration, |
|
70 | - array('limit' => 1) |
|
71 | - ), |
|
72 | - 'LIN_code' |
|
73 | - ); |
|
74 | - if ($line_item_code) { |
|
75 | - if (! isset($this->_line_item_registrations[ $line_item_code ])) { |
|
76 | - $this->_line_item_registrations[ $line_item_code ] = array(); |
|
77 | - } |
|
78 | - $this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration; |
|
79 | - } |
|
80 | - } |
|
81 | - } |
|
57 | + /** |
|
58 | + * sets the _line_item_registrations from the provided registrations |
|
59 | + * |
|
60 | + * @param EE_Registration[] $registrations |
|
61 | + * @return void |
|
62 | + * @throws EE_Error |
|
63 | + */ |
|
64 | + protected function _calculate_registrations_per_line_item_code($registrations) |
|
65 | + { |
|
66 | + foreach ($registrations as $registration) { |
|
67 | + $line_item_code = EEM_Line_Item::instance()->get_var( |
|
68 | + EEM_Line_Item::instance()->line_item_for_registration_query_params( |
|
69 | + $registration, |
|
70 | + array('limit' => 1) |
|
71 | + ), |
|
72 | + 'LIN_code' |
|
73 | + ); |
|
74 | + if ($line_item_code) { |
|
75 | + if (! isset($this->_line_item_registrations[ $line_item_code ])) { |
|
76 | + $this->_line_item_registrations[ $line_item_code ] = array(); |
|
77 | + } |
|
78 | + $this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration; |
|
79 | + } |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * Creates a duplicate of the line item tree, except only includes billable items |
|
86 | - * and the portion of line items attributed to billable things |
|
87 | - * |
|
88 | - * @param EEI_Line_Item $line_item |
|
89 | - * @return EEI_Line_Item |
|
90 | - * @throws EE_Error |
|
91 | - */ |
|
92 | - public function process(EEI_Line_Item $line_item) |
|
93 | - { |
|
94 | - $this->_adjust_line_item_quantity($line_item); |
|
95 | - if (! $line_item->children()) { |
|
96 | - return $line_item; |
|
97 | - } |
|
98 | - // the original running total (taking ALL tickets into account) |
|
99 | - $running_total_of_children = 0; |
|
100 | - // the new running total (only taking the specified ticket quantities into account) |
|
101 | - $running_total_of_children_under_consideration = 0; |
|
102 | - // let's also track the quantity of tickets that pertain to the registrations |
|
103 | - $total_child_ticket_quantity = 0; |
|
104 | - foreach ($line_item->children() as $child_line_item) { |
|
105 | - $original_li_total = $child_line_item->is_percent() |
|
106 | - ? $running_total_of_children * $child_line_item->percent() / 100 |
|
107 | - : $child_line_item->unit_price() * $child_line_item->quantity(); |
|
108 | - $this->process($child_line_item); |
|
109 | - // If this line item is a normal line item that isn't for a ticket, |
|
110 | - // we want to modify its total (and unit price if not a percentage line item) |
|
111 | - // so it reflects only that portion of the surcharge/discount shared by these registrations |
|
112 | - if ( |
|
113 | - $child_line_item->type() === EEM_Line_Item::type_line_item |
|
114 | - && $child_line_item->OBJ_type() !== 'Ticket' |
|
115 | - ) { |
|
116 | - $percent_of_running_total = $running_total_of_children |
|
117 | - ? $original_li_total / $running_total_of_children |
|
118 | - : 0; |
|
119 | - $child_line_item->set_total( |
|
120 | - $running_total_of_children_under_consideration * $percent_of_running_total |
|
121 | - ); |
|
122 | - if (! $child_line_item->is_percent()) { |
|
123 | - $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity()); |
|
124 | - } |
|
125 | - } elseif ( |
|
84 | + /** |
|
85 | + * Creates a duplicate of the line item tree, except only includes billable items |
|
86 | + * and the portion of line items attributed to billable things |
|
87 | + * |
|
88 | + * @param EEI_Line_Item $line_item |
|
89 | + * @return EEI_Line_Item |
|
90 | + * @throws EE_Error |
|
91 | + */ |
|
92 | + public function process(EEI_Line_Item $line_item) |
|
93 | + { |
|
94 | + $this->_adjust_line_item_quantity($line_item); |
|
95 | + if (! $line_item->children()) { |
|
96 | + return $line_item; |
|
97 | + } |
|
98 | + // the original running total (taking ALL tickets into account) |
|
99 | + $running_total_of_children = 0; |
|
100 | + // the new running total (only taking the specified ticket quantities into account) |
|
101 | + $running_total_of_children_under_consideration = 0; |
|
102 | + // let's also track the quantity of tickets that pertain to the registrations |
|
103 | + $total_child_ticket_quantity = 0; |
|
104 | + foreach ($line_item->children() as $child_line_item) { |
|
105 | + $original_li_total = $child_line_item->is_percent() |
|
106 | + ? $running_total_of_children * $child_line_item->percent() / 100 |
|
107 | + : $child_line_item->unit_price() * $child_line_item->quantity(); |
|
108 | + $this->process($child_line_item); |
|
109 | + // If this line item is a normal line item that isn't for a ticket, |
|
110 | + // we want to modify its total (and unit price if not a percentage line item) |
|
111 | + // so it reflects only that portion of the surcharge/discount shared by these registrations |
|
112 | + if ( |
|
113 | + $child_line_item->type() === EEM_Line_Item::type_line_item |
|
114 | + && $child_line_item->OBJ_type() !== 'Ticket' |
|
115 | + ) { |
|
116 | + $percent_of_running_total = $running_total_of_children |
|
117 | + ? $original_li_total / $running_total_of_children |
|
118 | + : 0; |
|
119 | + $child_line_item->set_total( |
|
120 | + $running_total_of_children_under_consideration * $percent_of_running_total |
|
121 | + ); |
|
122 | + if (! $child_line_item->is_percent()) { |
|
123 | + $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity()); |
|
124 | + } |
|
125 | + } elseif ( |
|
126 | 126 | // make sure this item's quantity and total matches its parent |
127 | - $line_item->type() === EEM_Line_Item::type_line_item |
|
128 | - && $line_item->OBJ_type() === 'Ticket' |
|
129 | - // but not if it's a percentage modifier |
|
130 | - && ! $child_line_item->is_percent() |
|
131 | - && ! ( |
|
132 | - // or a cancellation |
|
133 | - $child_line_item->is_cancelled() |
|
134 | - && ! ( |
|
135 | - // unless it IS a cancellation and the current registration is cancelled |
|
136 | - $child_line_item->is_cancelled() |
|
137 | - && $this->_current_registration instanceof EE_Registration |
|
138 | - && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true) |
|
139 | - ) |
|
140 | - ) |
|
141 | - ) { |
|
142 | - $child_line_item->set_quantity($line_item->quantity()); |
|
143 | - $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity()); |
|
144 | - } |
|
145 | - $running_total_of_children += $original_li_total; |
|
146 | - $running_total_of_children_under_consideration += $child_line_item->total(); |
|
147 | - if ($child_line_item->OBJ_type() === 'Ticket') { |
|
148 | - $total_child_ticket_quantity += $child_line_item->quantity(); |
|
149 | - } |
|
150 | - } |
|
151 | - $line_item->set_total($running_total_of_children_under_consideration); |
|
152 | - if ($line_item->quantity()) { |
|
153 | - $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity()); |
|
154 | - } else { |
|
155 | - $line_item->set_unit_price(0); |
|
156 | - } |
|
157 | - if ($line_item->OBJ_type() === 'Event') { |
|
158 | - $line_item->set_quantity($total_child_ticket_quantity); |
|
159 | - } |
|
160 | - return $line_item; |
|
161 | - } |
|
127 | + $line_item->type() === EEM_Line_Item::type_line_item |
|
128 | + && $line_item->OBJ_type() === 'Ticket' |
|
129 | + // but not if it's a percentage modifier |
|
130 | + && ! $child_line_item->is_percent() |
|
131 | + && ! ( |
|
132 | + // or a cancellation |
|
133 | + $child_line_item->is_cancelled() |
|
134 | + && ! ( |
|
135 | + // unless it IS a cancellation and the current registration is cancelled |
|
136 | + $child_line_item->is_cancelled() |
|
137 | + && $this->_current_registration instanceof EE_Registration |
|
138 | + && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true) |
|
139 | + ) |
|
140 | + ) |
|
141 | + ) { |
|
142 | + $child_line_item->set_quantity($line_item->quantity()); |
|
143 | + $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity()); |
|
144 | + } |
|
145 | + $running_total_of_children += $original_li_total; |
|
146 | + $running_total_of_children_under_consideration += $child_line_item->total(); |
|
147 | + if ($child_line_item->OBJ_type() === 'Ticket') { |
|
148 | + $total_child_ticket_quantity += $child_line_item->quantity(); |
|
149 | + } |
|
150 | + } |
|
151 | + $line_item->set_total($running_total_of_children_under_consideration); |
|
152 | + if ($line_item->quantity()) { |
|
153 | + $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity()); |
|
154 | + } else { |
|
155 | + $line_item->set_unit_price(0); |
|
156 | + } |
|
157 | + if ($line_item->OBJ_type() === 'Event') { |
|
158 | + $line_item->set_quantity($total_child_ticket_quantity); |
|
159 | + } |
|
160 | + return $line_item; |
|
161 | + } |
|
162 | 162 | |
163 | 163 | |
164 | - /** |
|
165 | - * Adjusts quantities for line items for tickets according to the registrations provided |
|
166 | - * in the constructor |
|
167 | - * |
|
168 | - * @param EEI_Line_Item $line_item |
|
169 | - * @return EEI_Line_Item |
|
170 | - */ |
|
171 | - protected function _adjust_line_item_quantity(EEI_Line_Item $line_item) |
|
172 | - { |
|
173 | - // is this a ticket ? |
|
174 | - if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') { |
|
175 | - $this->_current_registration = null; |
|
176 | - $quantity = 0; |
|
177 | - // if this ticket is billable at this moment, then we should have a positive quantity |
|
178 | - if ( |
|
179 | - isset($this->_line_item_registrations[ $line_item->code() ]) |
|
180 | - && is_array($this->_line_item_registrations[ $line_item->code() ]) |
|
181 | - ) { |
|
182 | - // set quantity based on number of open registrations for this ticket |
|
183 | - foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) { |
|
184 | - if ( |
|
185 | - $registration instanceof EE_Registration |
|
186 | - ) { |
|
187 | - $quantity++; |
|
188 | - $this->_current_registration = $registration; |
|
189 | - } |
|
190 | - } |
|
191 | - } |
|
192 | - $line_item->set_quantity($quantity); |
|
193 | - $line_item->set_total($line_item->unit_price() * $line_item->quantity()); |
|
194 | - } |
|
195 | - return $line_item; |
|
196 | - } |
|
164 | + /** |
|
165 | + * Adjusts quantities for line items for tickets according to the registrations provided |
|
166 | + * in the constructor |
|
167 | + * |
|
168 | + * @param EEI_Line_Item $line_item |
|
169 | + * @return EEI_Line_Item |
|
170 | + */ |
|
171 | + protected function _adjust_line_item_quantity(EEI_Line_Item $line_item) |
|
172 | + { |
|
173 | + // is this a ticket ? |
|
174 | + if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') { |
|
175 | + $this->_current_registration = null; |
|
176 | + $quantity = 0; |
|
177 | + // if this ticket is billable at this moment, then we should have a positive quantity |
|
178 | + if ( |
|
179 | + isset($this->_line_item_registrations[ $line_item->code() ]) |
|
180 | + && is_array($this->_line_item_registrations[ $line_item->code() ]) |
|
181 | + ) { |
|
182 | + // set quantity based on number of open registrations for this ticket |
|
183 | + foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) { |
|
184 | + if ( |
|
185 | + $registration instanceof EE_Registration |
|
186 | + ) { |
|
187 | + $quantity++; |
|
188 | + $this->_current_registration = $registration; |
|
189 | + } |
|
190 | + } |
|
191 | + } |
|
192 | + $line_item->set_quantity($quantity); |
|
193 | + $line_item->set_total($line_item->unit_price() * $line_item->quantity()); |
|
194 | + } |
|
195 | + return $line_item; |
|
196 | + } |
|
197 | 197 | } |
@@ -39,17 +39,16 @@ discard block |
||
39 | 39 | */ |
40 | 40 | protected function _remove_unbillable_registrations($registrations = array()) |
41 | 41 | { |
42 | - if (! empty($registrations)) { |
|
42 | + if ( ! empty($registrations)) { |
|
43 | 43 | // these reg statuses require payment (if event is not free) |
44 | 44 | $requires_payment = EEM_Registration::reg_statuses_that_allow_payment(); |
45 | 45 | foreach ($registrations as $key => $registration) { |
46 | - if (! $registration instanceof EE_Registration) { |
|
46 | + if ( ! $registration instanceof EE_Registration) { |
|
47 | 47 | continue; |
48 | 48 | } |
49 | 49 | // are we billing for this registration at this moment ? |
50 | 50 | if ( |
51 | - ! |
|
52 | - $registration->owes_monies_and_can_pay($requires_payment) && |
|
51 | + ! $registration->owes_monies_and_can_pay($requires_payment) && |
|
53 | 52 | ! ( |
54 | 53 | // free registration with valid reg status |
55 | 54 | $registration->final_price() == 0 && |
@@ -57,7 +56,7 @@ discard block |
||
57 | 56 | ) |
58 | 57 | ) { |
59 | 58 | // not billable. remove it |
60 | - unset($registrations[ $key ]); |
|
59 | + unset($registrations[$key]); |
|
61 | 60 | } |
62 | 61 | } |
63 | 62 | } |
@@ -16,49 +16,49 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Billable_Line_Item_Filter extends EE_Specific_Registrations_Line_Item_Filter |
18 | 18 | { |
19 | - /** |
|
20 | - * EE_Billable_Line_Item_Filter constructor. |
|
21 | - * |
|
22 | - * @param EE_Registration[] $registrations |
|
23 | - */ |
|
24 | - public function __construct($registrations) |
|
25 | - { |
|
26 | - parent::__construct($this->_remove_unbillable_registrations($registrations)); |
|
27 | - } |
|
19 | + /** |
|
20 | + * EE_Billable_Line_Item_Filter constructor. |
|
21 | + * |
|
22 | + * @param EE_Registration[] $registrations |
|
23 | + */ |
|
24 | + public function __construct($registrations) |
|
25 | + { |
|
26 | + parent::__construct($this->_remove_unbillable_registrations($registrations)); |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * _calculate_billable_ticket_quantities_from_registrations |
|
32 | - * compiles a list of EE_Tickets for each event in the passed array |
|
33 | - * |
|
34 | - * @access protected |
|
35 | - * @param EE_Registration[] $registrations |
|
36 | - * @return mixed |
|
37 | - */ |
|
38 | - protected function _remove_unbillable_registrations($registrations = array()) |
|
39 | - { |
|
40 | - if (! empty($registrations)) { |
|
41 | - // these reg statuses require payment (if event is not free) |
|
42 | - $requires_payment = EEM_Registration::reg_statuses_that_allow_payment(); |
|
43 | - foreach ($registrations as $key => $registration) { |
|
44 | - if (! $registration instanceof EE_Registration) { |
|
45 | - continue; |
|
46 | - } |
|
47 | - // are we billing for this registration at this moment ? |
|
48 | - if ( |
|
49 | - ! |
|
50 | - $registration->owes_monies_and_can_pay($requires_payment) && |
|
51 | - ! ( |
|
52 | - // free registration with valid reg status |
|
53 | - $registration->final_price() == 0 && |
|
54 | - in_array($registration->status_ID(), $requires_payment) |
|
55 | - ) |
|
56 | - ) { |
|
57 | - // not billable. remove it |
|
58 | - unset($registrations[ $key ]); |
|
59 | - } |
|
60 | - } |
|
61 | - } |
|
62 | - return $registrations; |
|
63 | - } |
|
30 | + /** |
|
31 | + * _calculate_billable_ticket_quantities_from_registrations |
|
32 | + * compiles a list of EE_Tickets for each event in the passed array |
|
33 | + * |
|
34 | + * @access protected |
|
35 | + * @param EE_Registration[] $registrations |
|
36 | + * @return mixed |
|
37 | + */ |
|
38 | + protected function _remove_unbillable_registrations($registrations = array()) |
|
39 | + { |
|
40 | + if (! empty($registrations)) { |
|
41 | + // these reg statuses require payment (if event is not free) |
|
42 | + $requires_payment = EEM_Registration::reg_statuses_that_allow_payment(); |
|
43 | + foreach ($registrations as $key => $registration) { |
|
44 | + if (! $registration instanceof EE_Registration) { |
|
45 | + continue; |
|
46 | + } |
|
47 | + // are we billing for this registration at this moment ? |
|
48 | + if ( |
|
49 | + ! |
|
50 | + $registration->owes_monies_and_can_pay($requires_payment) && |
|
51 | + ! ( |
|
52 | + // free registration with valid reg status |
|
53 | + $registration->final_price() == 0 && |
|
54 | + in_array($registration->status_ID(), $requires_payment) |
|
55 | + ) |
|
56 | + ) { |
|
57 | + // not billable. remove it |
|
58 | + unset($registrations[ $key ]); |
|
59 | + } |
|
60 | + } |
|
61 | + } |
|
62 | + return $registrations; |
|
63 | + } |
|
64 | 64 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public static function load($job_id) |
160 | 160 | { |
161 | - $job_parameter_vars = get_option(JobParameters::wp_option_prefix . $job_id); |
|
161 | + $job_parameter_vars = get_option(JobParameters::wp_option_prefix.$job_id); |
|
162 | 162 | if ( |
163 | 163 | ! is_array($job_parameter_vars) || |
164 | 164 | ! isset($job_parameter_vars['_classname']) || |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | 'event_espresso' |
172 | 172 | ), |
173 | 173 | $job_id, |
174 | - get_option(JobParameters::wp_option_prefix . $job_id) |
|
174 | + get_option(JobParameters::wp_option_prefix.$job_id) |
|
175 | 175 | ) |
176 | 176 | ); |
177 | 177 | } |
@@ -229,8 +229,8 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public function request_datum($key, $default = '') |
231 | 231 | { |
232 | - if (isset($this->_request_data[ $key ])) { |
|
233 | - return $this->_request_data[ $key ]; |
|
232 | + if (isset($this->_request_data[$key])) { |
|
233 | + return $this->_request_data[$key]; |
|
234 | 234 | } else { |
235 | 235 | return $default; |
236 | 236 | } |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function extra_datum($key, $default = '') |
248 | 248 | { |
249 | - if (isset($this->_extra_data[ $key ])) { |
|
250 | - return $this->_extra_data[ $key ]; |
|
249 | + if (isset($this->_extra_data[$key])) { |
|
250 | + return $this->_extra_data[$key]; |
|
251 | 251 | } else { |
252 | 252 | return $default; |
253 | 253 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | */ |
263 | 263 | public function add_extra_data($key, $value) |
264 | 264 | { |
265 | - $this->_extra_data[ $key ] = $value; |
|
265 | + $this->_extra_data[$key] = $value; |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | */ |
386 | 386 | public function option_name() |
387 | 387 | { |
388 | - return JobParameters::wp_option_prefix . $this->job_id(); |
|
388 | + return JobParameters::wp_option_prefix.$this->job_id(); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 |
@@ -14,397 +14,397 @@ |
||
14 | 14 | */ |
15 | 15 | class JobParameters |
16 | 16 | { |
17 | - // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
18 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
19 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
20 | - /** |
|
21 | - * status indicating the job should continue |
|
22 | - */ |
|
23 | - const status_continue = 'continue'; |
|
24 | - |
|
25 | - /** |
|
26 | - * status indicated the job has been completed successfully and should be cleaned up next |
|
27 | - */ |
|
28 | - const status_complete = 'complete'; |
|
29 | - |
|
30 | - /** |
|
31 | - * status indicating there was an error and the job should be cleaned up |
|
32 | - */ |
|
33 | - const status_error = 'error'; |
|
34 | - |
|
35 | - /** |
|
36 | - * status indicating the job has been cleaned up, and so this is probably the last |
|
37 | - * time you'll see this job |
|
38 | - */ |
|
39 | - const status_cleaned_up = 'cleaned_up'; |
|
40 | - |
|
41 | - const wp_option_prefix = 'ee_job_parameters_'; |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * String uniquely identifying the job |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - protected $_job_id; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $_classname; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - protected $_request_data; |
|
60 | - |
|
61 | - /** |
|
62 | - * Array of any extra data we want to remember about this request, that |
|
63 | - * wasn't necessarily past in with the request data |
|
64 | - * |
|
65 | - * @var array |
|
66 | - */ |
|
67 | - protected $_extra_data; |
|
68 | - |
|
69 | - /** |
|
70 | - * Estimate of how many units HAVE been processed |
|
71 | - * |
|
72 | - * @var int |
|
73 | - */ |
|
74 | - protected $_units_processed = 0; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var string |
|
78 | - */ |
|
79 | - protected $_status; |
|
80 | - |
|
81 | - /** |
|
82 | - * The size of the total job in whatever units you want. |
|
83 | - * If you can't provide an estimate leave as 0. |
|
84 | - * Once _units_processed equals _job_size, we should be done |
|
85 | - * |
|
86 | - * @var int |
|
87 | - */ |
|
88 | - protected $_job_size = 0; |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @param string $job_id |
|
93 | - * @param string $classname |
|
94 | - * @param array $request_data |
|
95 | - * @param array $extra_data |
|
96 | - */ |
|
97 | - public function __construct($job_id, $classname, $request_data, $extra_data = array()) |
|
98 | - { |
|
99 | - $this->set_job_id($job_id); |
|
100 | - $this->set_classname($classname); |
|
101 | - $this->set_request_data($request_data); |
|
102 | - $this->set_extra_data($extra_data); |
|
103 | - $this->set_status(JobParameters::status_continue); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Returns the array of strings of valid stati |
|
109 | - * |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public static function valid_stati() |
|
113 | - { |
|
114 | - return array( |
|
115 | - JobParameters::status_complete, |
|
116 | - JobParameters::status_continue, |
|
117 | - JobParameters::status_error, |
|
118 | - JobParameters::status_cleaned_up, |
|
119 | - ); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * Saves this option to the database (wordpress options table) |
|
125 | - * |
|
126 | - * @param boolean $first |
|
127 | - * @return boolean success |
|
128 | - */ |
|
129 | - public function save($first = false) |
|
130 | - { |
|
131 | - $object_vars = get_object_vars($this); |
|
132 | - if ($first) { |
|
133 | - return add_option($this->option_name(), $object_vars, null, 'no'); |
|
134 | - } else { |
|
135 | - return update_option($this->option_name(), $object_vars); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * Deletes the job from teh database, although this object is still usable |
|
142 | - * for the rest of the request |
|
143 | - * |
|
144 | - * @return boolean |
|
145 | - */ |
|
146 | - public function delete() |
|
147 | - { |
|
148 | - return delete_option($this->option_name()); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Loads the specified job from the database |
|
154 | - * |
|
155 | - * @param string $job_id |
|
156 | - * @return JobParameters |
|
157 | - * @throws BatchRequestException |
|
158 | - */ |
|
159 | - public static function load($job_id) |
|
160 | - { |
|
161 | - $job_parameter_vars = get_option(JobParameters::wp_option_prefix . $job_id); |
|
162 | - if ( |
|
163 | - ! is_array($job_parameter_vars) || |
|
164 | - ! isset($job_parameter_vars['_classname']) || |
|
165 | - ! isset($job_parameter_vars['_request_data']) |
|
166 | - ) { |
|
167 | - throw new BatchRequestException( |
|
168 | - sprintf( |
|
169 | - esc_html__( |
|
170 | - 'Could not retrieve job %1$s from the Wordpress options table, and so the job could not continue. The wordpress option was %2$s', |
|
171 | - 'event_espresso' |
|
172 | - ), |
|
173 | - $job_id, |
|
174 | - get_option(JobParameters::wp_option_prefix . $job_id) |
|
175 | - ) |
|
176 | - ); |
|
177 | - } |
|
178 | - $job_parameters = new JobParameters( |
|
179 | - $job_id, |
|
180 | - $job_parameter_vars['_classname'], |
|
181 | - $job_parameter_vars['_request_data'] |
|
182 | - ); |
|
183 | - foreach ($job_parameter_vars as $key => $value) { |
|
184 | - $job_parameters->{$key} = $value; |
|
185 | - } |
|
186 | - return $job_parameters; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * Gets the job's unique string |
|
192 | - * |
|
193 | - * @return string |
|
194 | - */ |
|
195 | - public function job_id() |
|
196 | - { |
|
197 | - return $this->_job_id; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Gets the classname that should run this job |
|
203 | - * |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - public function classname() |
|
207 | - { |
|
208 | - return $this->_classname; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * Gets the original array of request data for this job |
|
214 | - * |
|
215 | - * @return array |
|
216 | - */ |
|
217 | - public function request_data() |
|
218 | - { |
|
219 | - return $this->_request_data; |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * Gets a single item from the request data |
|
225 | - * |
|
226 | - * @param string $key |
|
227 | - * @param string|array $default |
|
228 | - * @return string|array |
|
229 | - */ |
|
230 | - public function request_datum($key, $default = '') |
|
231 | - { |
|
232 | - if (isset($this->_request_data[ $key ])) { |
|
233 | - return $this->_request_data[ $key ]; |
|
234 | - } else { |
|
235 | - return $default; |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * Gets a single item from the extra data |
|
242 | - * |
|
243 | - * @param string $key |
|
244 | - * @param string|array $default |
|
245 | - * @return string|array |
|
246 | - */ |
|
247 | - public function extra_datum($key, $default = '') |
|
248 | - { |
|
249 | - if (isset($this->_extra_data[ $key ])) { |
|
250 | - return $this->_extra_data[ $key ]; |
|
251 | - } else { |
|
252 | - return $default; |
|
253 | - } |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * Adds an extra piece of extra data that we're going to want later during the job |
|
259 | - * |
|
260 | - * @param string $key |
|
261 | - * @param string|int|array|null $value almost any extra data you want to store |
|
262 | - */ |
|
263 | - public function add_extra_data($key, $value) |
|
264 | - { |
|
265 | - $this->_extra_data[ $key ] = $value; |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * Array of any extra data we want to store |
|
271 | - * |
|
272 | - * @return array |
|
273 | - */ |
|
274 | - public function extra_data() |
|
275 | - { |
|
276 | - return $this->_extra_data; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Returns the job size, in whatever units you want |
|
282 | - * |
|
283 | - * @return int |
|
284 | - */ |
|
285 | - public function job_size() |
|
286 | - { |
|
287 | - return $this->_job_size; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * Sets the job size. You decide what units to use |
|
293 | - * |
|
294 | - * @param int $size |
|
295 | - */ |
|
296 | - public function set_job_size($size) |
|
297 | - { |
|
298 | - $this->_job_size = $size; |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * The number of "units" processed, in the same units as the "job size" |
|
304 | - * |
|
305 | - * @return int |
|
306 | - */ |
|
307 | - public function units_processed() |
|
308 | - { |
|
309 | - return $this->_units_processed; |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Marks more units as processed |
|
315 | - * |
|
316 | - * @param int $newly_processed |
|
317 | - * @return int updated units processed |
|
318 | - */ |
|
319 | - public function mark_processed($newly_processed) |
|
320 | - { |
|
321 | - $this->_units_processed += $newly_processed; |
|
322 | - return $this->_units_processed; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * Sets the total count of units processed. You might prefer to use mark_processed |
|
328 | - * |
|
329 | - * @param int $total_units_processed |
|
330 | - */ |
|
331 | - public function set_units_processed($total_units_processed) |
|
332 | - { |
|
333 | - $this->_units_processed = $total_units_processed; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * Sets the job's ID |
|
339 | - * |
|
340 | - * @param string $job_id |
|
341 | - */ |
|
342 | - public function set_job_id($job_id) |
|
343 | - { |
|
344 | - $this->_job_id = $job_id; |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * sets the classname |
|
350 | - * |
|
351 | - * @param string $classname |
|
352 | - */ |
|
353 | - public function set_classname($classname) |
|
354 | - { |
|
355 | - $this->_classname = $classname; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * Sets the request data |
|
361 | - * |
|
362 | - * @param array $request_data |
|
363 | - */ |
|
364 | - public function set_request_data($request_data) |
|
365 | - { |
|
366 | - $this->_request_data = $request_data; |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * Sets the array of extra data we want to store on this request |
|
372 | - * |
|
373 | - * @param array $extra_data |
|
374 | - */ |
|
375 | - public function set_extra_data($extra_data) |
|
376 | - { |
|
377 | - $this->_extra_data = $extra_data; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * Gets the name of the wordpress option that should store these job parameters |
|
383 | - * |
|
384 | - * @return string |
|
385 | - */ |
|
386 | - public function option_name() |
|
387 | - { |
|
388 | - return JobParameters::wp_option_prefix . $this->job_id(); |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * Gets the job\s current status. One of JobParameters::valid_stati(); |
|
394 | - * |
|
395 | - * @return string |
|
396 | - */ |
|
397 | - public function status() |
|
398 | - { |
|
399 | - return $this->_status; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * @param string $status on eof JobParameters::valid_stati() |
|
405 | - */ |
|
406 | - public function set_status($status) |
|
407 | - { |
|
408 | - $this->_status = $status; |
|
409 | - } |
|
17 | + // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
18 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
19 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
20 | + /** |
|
21 | + * status indicating the job should continue |
|
22 | + */ |
|
23 | + const status_continue = 'continue'; |
|
24 | + |
|
25 | + /** |
|
26 | + * status indicated the job has been completed successfully and should be cleaned up next |
|
27 | + */ |
|
28 | + const status_complete = 'complete'; |
|
29 | + |
|
30 | + /** |
|
31 | + * status indicating there was an error and the job should be cleaned up |
|
32 | + */ |
|
33 | + const status_error = 'error'; |
|
34 | + |
|
35 | + /** |
|
36 | + * status indicating the job has been cleaned up, and so this is probably the last |
|
37 | + * time you'll see this job |
|
38 | + */ |
|
39 | + const status_cleaned_up = 'cleaned_up'; |
|
40 | + |
|
41 | + const wp_option_prefix = 'ee_job_parameters_'; |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * String uniquely identifying the job |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + protected $_job_id; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $_classname; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + protected $_request_data; |
|
60 | + |
|
61 | + /** |
|
62 | + * Array of any extra data we want to remember about this request, that |
|
63 | + * wasn't necessarily past in with the request data |
|
64 | + * |
|
65 | + * @var array |
|
66 | + */ |
|
67 | + protected $_extra_data; |
|
68 | + |
|
69 | + /** |
|
70 | + * Estimate of how many units HAVE been processed |
|
71 | + * |
|
72 | + * @var int |
|
73 | + */ |
|
74 | + protected $_units_processed = 0; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var string |
|
78 | + */ |
|
79 | + protected $_status; |
|
80 | + |
|
81 | + /** |
|
82 | + * The size of the total job in whatever units you want. |
|
83 | + * If you can't provide an estimate leave as 0. |
|
84 | + * Once _units_processed equals _job_size, we should be done |
|
85 | + * |
|
86 | + * @var int |
|
87 | + */ |
|
88 | + protected $_job_size = 0; |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @param string $job_id |
|
93 | + * @param string $classname |
|
94 | + * @param array $request_data |
|
95 | + * @param array $extra_data |
|
96 | + */ |
|
97 | + public function __construct($job_id, $classname, $request_data, $extra_data = array()) |
|
98 | + { |
|
99 | + $this->set_job_id($job_id); |
|
100 | + $this->set_classname($classname); |
|
101 | + $this->set_request_data($request_data); |
|
102 | + $this->set_extra_data($extra_data); |
|
103 | + $this->set_status(JobParameters::status_continue); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Returns the array of strings of valid stati |
|
109 | + * |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public static function valid_stati() |
|
113 | + { |
|
114 | + return array( |
|
115 | + JobParameters::status_complete, |
|
116 | + JobParameters::status_continue, |
|
117 | + JobParameters::status_error, |
|
118 | + JobParameters::status_cleaned_up, |
|
119 | + ); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * Saves this option to the database (wordpress options table) |
|
125 | + * |
|
126 | + * @param boolean $first |
|
127 | + * @return boolean success |
|
128 | + */ |
|
129 | + public function save($first = false) |
|
130 | + { |
|
131 | + $object_vars = get_object_vars($this); |
|
132 | + if ($first) { |
|
133 | + return add_option($this->option_name(), $object_vars, null, 'no'); |
|
134 | + } else { |
|
135 | + return update_option($this->option_name(), $object_vars); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * Deletes the job from teh database, although this object is still usable |
|
142 | + * for the rest of the request |
|
143 | + * |
|
144 | + * @return boolean |
|
145 | + */ |
|
146 | + public function delete() |
|
147 | + { |
|
148 | + return delete_option($this->option_name()); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Loads the specified job from the database |
|
154 | + * |
|
155 | + * @param string $job_id |
|
156 | + * @return JobParameters |
|
157 | + * @throws BatchRequestException |
|
158 | + */ |
|
159 | + public static function load($job_id) |
|
160 | + { |
|
161 | + $job_parameter_vars = get_option(JobParameters::wp_option_prefix . $job_id); |
|
162 | + if ( |
|
163 | + ! is_array($job_parameter_vars) || |
|
164 | + ! isset($job_parameter_vars['_classname']) || |
|
165 | + ! isset($job_parameter_vars['_request_data']) |
|
166 | + ) { |
|
167 | + throw new BatchRequestException( |
|
168 | + sprintf( |
|
169 | + esc_html__( |
|
170 | + 'Could not retrieve job %1$s from the Wordpress options table, and so the job could not continue. The wordpress option was %2$s', |
|
171 | + 'event_espresso' |
|
172 | + ), |
|
173 | + $job_id, |
|
174 | + get_option(JobParameters::wp_option_prefix . $job_id) |
|
175 | + ) |
|
176 | + ); |
|
177 | + } |
|
178 | + $job_parameters = new JobParameters( |
|
179 | + $job_id, |
|
180 | + $job_parameter_vars['_classname'], |
|
181 | + $job_parameter_vars['_request_data'] |
|
182 | + ); |
|
183 | + foreach ($job_parameter_vars as $key => $value) { |
|
184 | + $job_parameters->{$key} = $value; |
|
185 | + } |
|
186 | + return $job_parameters; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * Gets the job's unique string |
|
192 | + * |
|
193 | + * @return string |
|
194 | + */ |
|
195 | + public function job_id() |
|
196 | + { |
|
197 | + return $this->_job_id; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Gets the classname that should run this job |
|
203 | + * |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + public function classname() |
|
207 | + { |
|
208 | + return $this->_classname; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * Gets the original array of request data for this job |
|
214 | + * |
|
215 | + * @return array |
|
216 | + */ |
|
217 | + public function request_data() |
|
218 | + { |
|
219 | + return $this->_request_data; |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * Gets a single item from the request data |
|
225 | + * |
|
226 | + * @param string $key |
|
227 | + * @param string|array $default |
|
228 | + * @return string|array |
|
229 | + */ |
|
230 | + public function request_datum($key, $default = '') |
|
231 | + { |
|
232 | + if (isset($this->_request_data[ $key ])) { |
|
233 | + return $this->_request_data[ $key ]; |
|
234 | + } else { |
|
235 | + return $default; |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * Gets a single item from the extra data |
|
242 | + * |
|
243 | + * @param string $key |
|
244 | + * @param string|array $default |
|
245 | + * @return string|array |
|
246 | + */ |
|
247 | + public function extra_datum($key, $default = '') |
|
248 | + { |
|
249 | + if (isset($this->_extra_data[ $key ])) { |
|
250 | + return $this->_extra_data[ $key ]; |
|
251 | + } else { |
|
252 | + return $default; |
|
253 | + } |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * Adds an extra piece of extra data that we're going to want later during the job |
|
259 | + * |
|
260 | + * @param string $key |
|
261 | + * @param string|int|array|null $value almost any extra data you want to store |
|
262 | + */ |
|
263 | + public function add_extra_data($key, $value) |
|
264 | + { |
|
265 | + $this->_extra_data[ $key ] = $value; |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * Array of any extra data we want to store |
|
271 | + * |
|
272 | + * @return array |
|
273 | + */ |
|
274 | + public function extra_data() |
|
275 | + { |
|
276 | + return $this->_extra_data; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Returns the job size, in whatever units you want |
|
282 | + * |
|
283 | + * @return int |
|
284 | + */ |
|
285 | + public function job_size() |
|
286 | + { |
|
287 | + return $this->_job_size; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * Sets the job size. You decide what units to use |
|
293 | + * |
|
294 | + * @param int $size |
|
295 | + */ |
|
296 | + public function set_job_size($size) |
|
297 | + { |
|
298 | + $this->_job_size = $size; |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * The number of "units" processed, in the same units as the "job size" |
|
304 | + * |
|
305 | + * @return int |
|
306 | + */ |
|
307 | + public function units_processed() |
|
308 | + { |
|
309 | + return $this->_units_processed; |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Marks more units as processed |
|
315 | + * |
|
316 | + * @param int $newly_processed |
|
317 | + * @return int updated units processed |
|
318 | + */ |
|
319 | + public function mark_processed($newly_processed) |
|
320 | + { |
|
321 | + $this->_units_processed += $newly_processed; |
|
322 | + return $this->_units_processed; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * Sets the total count of units processed. You might prefer to use mark_processed |
|
328 | + * |
|
329 | + * @param int $total_units_processed |
|
330 | + */ |
|
331 | + public function set_units_processed($total_units_processed) |
|
332 | + { |
|
333 | + $this->_units_processed = $total_units_processed; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * Sets the job's ID |
|
339 | + * |
|
340 | + * @param string $job_id |
|
341 | + */ |
|
342 | + public function set_job_id($job_id) |
|
343 | + { |
|
344 | + $this->_job_id = $job_id; |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * sets the classname |
|
350 | + * |
|
351 | + * @param string $classname |
|
352 | + */ |
|
353 | + public function set_classname($classname) |
|
354 | + { |
|
355 | + $this->_classname = $classname; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * Sets the request data |
|
361 | + * |
|
362 | + * @param array $request_data |
|
363 | + */ |
|
364 | + public function set_request_data($request_data) |
|
365 | + { |
|
366 | + $this->_request_data = $request_data; |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * Sets the array of extra data we want to store on this request |
|
372 | + * |
|
373 | + * @param array $extra_data |
|
374 | + */ |
|
375 | + public function set_extra_data($extra_data) |
|
376 | + { |
|
377 | + $this->_extra_data = $extra_data; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * Gets the name of the wordpress option that should store these job parameters |
|
383 | + * |
|
384 | + * @return string |
|
385 | + */ |
|
386 | + public function option_name() |
|
387 | + { |
|
388 | + return JobParameters::wp_option_prefix . $this->job_id(); |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * Gets the job\s current status. One of JobParameters::valid_stati(); |
|
394 | + * |
|
395 | + * @return string |
|
396 | + */ |
|
397 | + public function status() |
|
398 | + { |
|
399 | + return $this->_status; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * @param string $status on eof JobParameters::valid_stati() |
|
405 | + */ |
|
406 | + public function set_status($status) |
|
407 | + { |
|
408 | + $this->_status = $status; |
|
409 | + } |
|
410 | 410 | } |
@@ -42,11 +42,11 @@ |
||
42 | 42 | 'Price' => new EE_Belongs_To_Relation() |
43 | 43 | ); |
44 | 44 | $this->_model_chain_to_wp_user = 'Ticket'; |
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
45 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
46 | 46 | // account for default tickets in the caps |
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
50 | 50 | // follow the caps of the ticket |
51 | 51 | $this->_caps_slug = 'tickets'; |
52 | 52 | parent::__construct($timezone); |
@@ -11,43 +11,43 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Ticket_Price extends EEM_Base |
13 | 13 | { |
14 | - // private instance of the EEM_Ticket_Price object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the EEM_Ticket_Price object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | - /** |
|
18 | - * private constructor to prevent direct creation |
|
19 | - * @Constructor |
|
20 | - * @access protected |
|
21 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - protected function __construct($timezone) |
|
25 | - { |
|
26 | - $this->singular_item = esc_html__('Ticket Price', 'event_espresso'); |
|
27 | - $this->plural_item = esc_html__('Ticket Prices', 'event_espresso'); |
|
17 | + /** |
|
18 | + * private constructor to prevent direct creation |
|
19 | + * @Constructor |
|
20 | + * @access protected |
|
21 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + protected function __construct($timezone) |
|
25 | + { |
|
26 | + $this->singular_item = esc_html__('Ticket Price', 'event_espresso'); |
|
27 | + $this->plural_item = esc_html__('Ticket Prices', 'event_espresso'); |
|
28 | 28 | |
29 | - $this->_tables = array( |
|
30 | - 'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID') |
|
31 | - ); |
|
32 | - $this->_fields = array( |
|
33 | - 'Ticket_Price' => array( |
|
34 | - 'TKP_ID' => new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'), |
|
35 | - 'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'), |
|
36 | - 'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'), |
|
37 | - ) |
|
38 | - ); |
|
39 | - $this->_model_relations = array( |
|
40 | - 'Ticket' => new EE_Belongs_To_Relation(), |
|
41 | - 'Price' => new EE_Belongs_To_Relation() |
|
42 | - ); |
|
43 | - $this->_model_chain_to_wp_user = 'Ticket'; |
|
44 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
45 | - // account for default tickets in the caps |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | - // follow the caps of the ticket |
|
50 | - $this->_caps_slug = 'tickets'; |
|
51 | - parent::__construct($timezone); |
|
52 | - } |
|
29 | + $this->_tables = array( |
|
30 | + 'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID') |
|
31 | + ); |
|
32 | + $this->_fields = array( |
|
33 | + 'Ticket_Price' => array( |
|
34 | + 'TKP_ID' => new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'), |
|
35 | + 'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'), |
|
36 | + 'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'), |
|
37 | + ) |
|
38 | + ); |
|
39 | + $this->_model_relations = array( |
|
40 | + 'Ticket' => new EE_Belongs_To_Relation(), |
|
41 | + 'Price' => new EE_Belongs_To_Relation() |
|
42 | + ); |
|
43 | + $this->_model_chain_to_wp_user = 'Ticket'; |
|
44 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
45 | + // account for default tickets in the caps |
|
46 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | + // follow the caps of the ticket |
|
50 | + $this->_caps_slug = 'tickets'; |
|
51 | + parent::__construct($timezone); |
|
52 | + } |
|
53 | 53 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | 'Payment_Method' => new EE_HABTM_Relation('Currency_Payment_Method'), |
35 | 35 | ); |
36 | 36 | // this model is generally available for reading |
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
37 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
38 | 38 | |
39 | 39 | parent::__construct($timezone); |
40 | 40 | } |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | public function get_all_active($query_params = array()) |
49 | 49 | { |
50 | 50 | $query_params[0]['CUR_active'] = true; |
51 | - if (! isset($query_params['order_by'])) { |
|
52 | - $query_params['order_by'] = array('CUR_code' => 'ASC','CUR_single' => 'ASC'); |
|
51 | + if ( ! isset($query_params['order_by'])) { |
|
52 | + $query_params['order_by'] = array('CUR_code' => 'ASC', 'CUR_single' => 'ASC'); |
|
53 | 53 | } |
54 | 54 | return $this->get_all($query_params); |
55 | 55 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | if ($currencies_supported == EE_Gateway::all_currencies_supported || empty($currencies_supported)) { |
72 | 72 | $currencies = $this->get_all_active(); |
73 | 73 | } else { |
74 | - $currencies = $this->get_all_active(array(array('CUR_code' => array('IN',$currencies_supported)))); |
|
74 | + $currencies = $this->get_all_active(array(array('CUR_code' => array('IN', $currencies_supported)))); |
|
75 | 75 | } |
76 | 76 | return $currencies; |
77 | 77 | } |
@@ -11,68 +11,68 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Currency extends EEM_Base |
13 | 13 | { |
14 | - // private instance of the Attendee object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the Attendee object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | - protected function __construct($timezone = null) |
|
18 | - { |
|
19 | - $this->singular_item = esc_html__('Currency', 'event_espresso'); |
|
20 | - $this->plural_item = esc_html__('Currencies', 'event_espresso'); |
|
21 | - $this->_tables = array( |
|
22 | - 'Currency' => new EE_Primary_Table('esp_currency', 'CUR_code') |
|
23 | - ); |
|
24 | - $this->_fields = array( |
|
25 | - 'Currency' => array( |
|
26 | - 'CUR_code' => new EE_Primary_Key_String_Field('CUR_code', esc_html__('Currency Code', 'event_espresso')), |
|
27 | - 'CUR_single' => new EE_Plain_Text_Field('CUR_single', esc_html__('Currency Name Singular', 'event_espresso'), false), |
|
28 | - 'CUR_plural' => new EE_Plain_Text_Field('CUR_plural', esc_html__('Currency Name Plural', 'event_espresso'), false), |
|
29 | - 'CUR_sign' => new EE_Plain_Text_Field('CUR_sign', esc_html__('Currency Sign', 'event_espresso'), false), |
|
30 | - 'CUR_dec_plc' => new EE_Integer_Field('CUR_dec_plc', esc_html__('Currency Decimal Places', 'event_espresso'), false, 2), |
|
31 | - 'CUR_active' => new EE_Boolean_Field('CUR_active', esc_html__('Active?', 'event_espresso'), false, true), |
|
32 | - )); |
|
33 | - $this->_model_relations = array( |
|
34 | - 'Payment_Method' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
35 | - ); |
|
36 | - // this model is generally available for reading |
|
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
17 | + protected function __construct($timezone = null) |
|
18 | + { |
|
19 | + $this->singular_item = esc_html__('Currency', 'event_espresso'); |
|
20 | + $this->plural_item = esc_html__('Currencies', 'event_espresso'); |
|
21 | + $this->_tables = array( |
|
22 | + 'Currency' => new EE_Primary_Table('esp_currency', 'CUR_code') |
|
23 | + ); |
|
24 | + $this->_fields = array( |
|
25 | + 'Currency' => array( |
|
26 | + 'CUR_code' => new EE_Primary_Key_String_Field('CUR_code', esc_html__('Currency Code', 'event_espresso')), |
|
27 | + 'CUR_single' => new EE_Plain_Text_Field('CUR_single', esc_html__('Currency Name Singular', 'event_espresso'), false), |
|
28 | + 'CUR_plural' => new EE_Plain_Text_Field('CUR_plural', esc_html__('Currency Name Plural', 'event_espresso'), false), |
|
29 | + 'CUR_sign' => new EE_Plain_Text_Field('CUR_sign', esc_html__('Currency Sign', 'event_espresso'), false), |
|
30 | + 'CUR_dec_plc' => new EE_Integer_Field('CUR_dec_plc', esc_html__('Currency Decimal Places', 'event_espresso'), false, 2), |
|
31 | + 'CUR_active' => new EE_Boolean_Field('CUR_active', esc_html__('Active?', 'event_espresso'), false, true), |
|
32 | + )); |
|
33 | + $this->_model_relations = array( |
|
34 | + 'Payment_Method' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
35 | + ); |
|
36 | + // this model is generally available for reading |
|
37 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
38 | 38 | |
39 | - parent::__construct($timezone); |
|
40 | - } |
|
39 | + parent::__construct($timezone); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Gets all thea ctive currencies, and orders them by their singular name, and then their code |
|
44 | - * (may be overridden) |
|
45 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
46 | - * @return EE_Currency[] |
|
47 | - */ |
|
48 | - public function get_all_active($query_params = array()) |
|
49 | - { |
|
50 | - $query_params[0]['CUR_active'] = true; |
|
51 | - if (! isset($query_params['order_by'])) { |
|
52 | - $query_params['order_by'] = array('CUR_code' => 'ASC','CUR_single' => 'ASC'); |
|
53 | - } |
|
54 | - return $this->get_all($query_params); |
|
55 | - } |
|
56 | - /** |
|
57 | - * Gets all the currencies which can be used by that payment method type |
|
58 | - * @param EE_PMT_Base $payment_method_type |
|
59 | - * @return EE_Currency[] |
|
60 | - */ |
|
61 | - public function get_all_currencies_usable_by($payment_method_type) |
|
62 | - { |
|
63 | - if ( |
|
64 | - $payment_method_type instanceof EE_PMT_Base && |
|
65 | - $payment_method_type->get_gateway() |
|
66 | - ) { |
|
67 | - $currencies_supported = $payment_method_type->get_gateway()->currencies_supported(); |
|
68 | - } else { |
|
69 | - $currencies_supported = EE_Gateway::all_currencies_supported; |
|
70 | - } |
|
71 | - if ($currencies_supported == EE_Gateway::all_currencies_supported || empty($currencies_supported)) { |
|
72 | - $currencies = $this->get_all_active(); |
|
73 | - } else { |
|
74 | - $currencies = $this->get_all_active(array(array('CUR_code' => array('IN',$currencies_supported)))); |
|
75 | - } |
|
76 | - return $currencies; |
|
77 | - } |
|
42 | + /** |
|
43 | + * Gets all thea ctive currencies, and orders them by their singular name, and then their code |
|
44 | + * (may be overridden) |
|
45 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
46 | + * @return EE_Currency[] |
|
47 | + */ |
|
48 | + public function get_all_active($query_params = array()) |
|
49 | + { |
|
50 | + $query_params[0]['CUR_active'] = true; |
|
51 | + if (! isset($query_params['order_by'])) { |
|
52 | + $query_params['order_by'] = array('CUR_code' => 'ASC','CUR_single' => 'ASC'); |
|
53 | + } |
|
54 | + return $this->get_all($query_params); |
|
55 | + } |
|
56 | + /** |
|
57 | + * Gets all the currencies which can be used by that payment method type |
|
58 | + * @param EE_PMT_Base $payment_method_type |
|
59 | + * @return EE_Currency[] |
|
60 | + */ |
|
61 | + public function get_all_currencies_usable_by($payment_method_type) |
|
62 | + { |
|
63 | + if ( |
|
64 | + $payment_method_type instanceof EE_PMT_Base && |
|
65 | + $payment_method_type->get_gateway() |
|
66 | + ) { |
|
67 | + $currencies_supported = $payment_method_type->get_gateway()->currencies_supported(); |
|
68 | + } else { |
|
69 | + $currencies_supported = EE_Gateway::all_currencies_supported; |
|
70 | + } |
|
71 | + if ($currencies_supported == EE_Gateway::all_currencies_supported || empty($currencies_supported)) { |
|
72 | + $currencies = $this->get_all_active(); |
|
73 | + } else { |
|
74 | + $currencies = $this->get_all_active(array(array('CUR_code' => array('IN',$currencies_supported)))); |
|
75 | + } |
|
76 | + return $currencies; |
|
77 | + } |
|
78 | 78 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | 'Payment_Method' => new EE_Belongs_To_Relation() |
35 | 35 | ); |
36 | 36 | // this model is generally available for reading |
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
37 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
38 | 38 | $this->_caps_slug = 'payment_methods'; |
39 | 39 | parent::__construct($timezone); |
40 | 40 | } |
@@ -11,31 +11,31 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Currency_Payment_Method extends EEM_Base |
13 | 13 | { |
14 | - // private instance of the Attendee object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the Attendee object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | 17 | |
18 | - protected function __construct($timezone = null) |
|
19 | - { |
|
20 | - $this->singular_item = esc_html__('Currency Usable by Payment Method', 'event_espresso'); |
|
21 | - $this->plural_item = esc_html__('Currencies Usable by Payment Methods', 'event_espresso'); |
|
22 | - $this->_tables = array( |
|
23 | - 'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID') |
|
24 | - ); |
|
25 | - $this->_fields = array( |
|
26 | - 'Currency_Payment_Method' => array( |
|
27 | - 'CPM_ID' => new EE_Primary_Key_Int_Field('CPM_ID', esc_html__('Currency to Payment Method LInk ID', 'event_espresso')), |
|
28 | - 'CUR_code' => new EE_Foreign_Key_String_Field('CUR_code', esc_html__('Currency Code', 'event_espresso'), false, '', 'Currency'), |
|
29 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__('Paymetn Method ID', 'event_espresso'), false, 0, 'Payment_Method') |
|
30 | - ) |
|
31 | - ); |
|
32 | - $this->_model_relations = array( |
|
33 | - 'Currency' => new EE_Belongs_To_Relation(), |
|
34 | - 'Payment_Method' => new EE_Belongs_To_Relation() |
|
35 | - ); |
|
36 | - // this model is generally available for reading |
|
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
38 | - $this->_caps_slug = 'payment_methods'; |
|
39 | - parent::__construct($timezone); |
|
40 | - } |
|
18 | + protected function __construct($timezone = null) |
|
19 | + { |
|
20 | + $this->singular_item = esc_html__('Currency Usable by Payment Method', 'event_espresso'); |
|
21 | + $this->plural_item = esc_html__('Currencies Usable by Payment Methods', 'event_espresso'); |
|
22 | + $this->_tables = array( |
|
23 | + 'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID') |
|
24 | + ); |
|
25 | + $this->_fields = array( |
|
26 | + 'Currency_Payment_Method' => array( |
|
27 | + 'CPM_ID' => new EE_Primary_Key_Int_Field('CPM_ID', esc_html__('Currency to Payment Method LInk ID', 'event_espresso')), |
|
28 | + 'CUR_code' => new EE_Foreign_Key_String_Field('CUR_code', esc_html__('Currency Code', 'event_espresso'), false, '', 'Currency'), |
|
29 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__('Paymetn Method ID', 'event_espresso'), false, 0, 'Payment_Method') |
|
30 | + ) |
|
31 | + ); |
|
32 | + $this->_model_relations = array( |
|
33 | + 'Currency' => new EE_Belongs_To_Relation(), |
|
34 | + 'Payment_Method' => new EE_Belongs_To_Relation() |
|
35 | + ); |
|
36 | + // this model is generally available for reading |
|
37 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
38 | + $this->_caps_slug = 'payment_methods'; |
|
39 | + parent::__construct($timezone); |
|
40 | + } |
|
41 | 41 | } |
@@ -9,153 +9,153 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_Model_Parser |
11 | 11 | { |
12 | - const table_alias_model_relation_chain_separator = '__'; |
|
13 | - const table_alias_model_relation_chain_prefix_end = '___'; |
|
14 | - /** |
|
15 | - * Adds a period onto the front and end of the string. This often helps in searching. |
|
16 | - * For example, if we want to find the model name "Event", it can be tricky when the following are possible |
|
17 | - * "","Event.EVT_ID","Event","Event_Venue.Venue.VNU_ID",etc. It's easier to look for ".Event." in |
|
18 | - * "..",".Event.EVT_ID.", ".Event.", and ".Event_Venue.Venue.VNU_ID", especially when the last example should NOT |
|
19 | - * be found because the "Event" model isn't mentioned- it's just a string that has a model name that coincidentally |
|
20 | - * has it as a substring |
|
21 | - * @param string $string_to_pad |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public static function pad_with_periods($string_to_pad) |
|
25 | - { |
|
26 | - return "." . $string_to_pad . "."; |
|
27 | - } |
|
28 | - /** |
|
29 | - * Basically undoes _pad_with_periods |
|
30 | - * @param string $string_to_trim |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public static function trim_periods($string_to_trim) |
|
34 | - { |
|
35 | - return trim($string_to_trim, '.'); |
|
36 | - } |
|
12 | + const table_alias_model_relation_chain_separator = '__'; |
|
13 | + const table_alias_model_relation_chain_prefix_end = '___'; |
|
14 | + /** |
|
15 | + * Adds a period onto the front and end of the string. This often helps in searching. |
|
16 | + * For example, if we want to find the model name "Event", it can be tricky when the following are possible |
|
17 | + * "","Event.EVT_ID","Event","Event_Venue.Venue.VNU_ID",etc. It's easier to look for ".Event." in |
|
18 | + * "..",".Event.EVT_ID.", ".Event.", and ".Event_Venue.Venue.VNU_ID", especially when the last example should NOT |
|
19 | + * be found because the "Event" model isn't mentioned- it's just a string that has a model name that coincidentally |
|
20 | + * has it as a substring |
|
21 | + * @param string $string_to_pad |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public static function pad_with_periods($string_to_pad) |
|
25 | + { |
|
26 | + return "." . $string_to_pad . "."; |
|
27 | + } |
|
28 | + /** |
|
29 | + * Basically undoes _pad_with_periods |
|
30 | + * @param string $string_to_trim |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public static function trim_periods($string_to_trim) |
|
34 | + { |
|
35 | + return trim($string_to_trim, '.'); |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Gets the calculated table's alias |
|
42 | - * @param string $model_relation_chain or query param |
|
43 | - * @param $this_model_name |
|
44 | - * @return string which can be added onto table aliases to make them unique |
|
45 | - */ |
|
46 | - public static function extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this_model_name) |
|
47 | - { |
|
48 | - // eg $model_relation_chain = 'Venue.Event_Venue.Event.Registration", and $this_model_name = 'Event' |
|
49 | - $model_relation_chain = self::pad_with_periods($model_relation_chain); |
|
50 | - $this_model_name = self::pad_with_periods($this_model_name); |
|
51 | - // eg '.Venue.Event_Venue.Event.Registration." and '.Event.' |
|
52 | - // remove this model name and everything afterwards |
|
53 | - $pos_of_model_name = strpos($model_relation_chain, $this_model_name); |
|
54 | - $model_relation_chain = substr($model_relation_chain, 0, $pos_of_model_name); |
|
55 | - // eg '.Venue.Event_Venue.' |
|
56 | - // trim periods |
|
57 | - $model_relation_chain = self::trim_periods($model_relation_chain); |
|
58 | - // eg 'Venue.Event_Venue' |
|
59 | - // replace periods with double-underscores |
|
60 | - $model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain); |
|
61 | - // eg 'Venue__Event_Venue' |
|
62 | - if ($model_relation_chain != '') { |
|
63 | - $model_relation_chain = $model_relation_chain . self::table_alias_model_relation_chain_prefix_end; |
|
64 | - } |
|
65 | - // eg 'Venue_Event_Venue___' |
|
66 | - return $model_relation_chain; |
|
67 | - } |
|
68 | - /** |
|
69 | - * Gets the table's alias (without prefix or anything) |
|
70 | - * @param string $table_alias_with_model_relation_chain_prefix which CAN have a table alias model relation chain prefix (or not) |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public static function remove_table_alias_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix) |
|
74 | - { |
|
75 | - // does this actually have a table alias model relation chain prefix? |
|
76 | - $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end); |
|
77 | - if ($pos !== false) { |
|
78 | - // yes |
|
79 | - // find that triple underscore and remove it and everything before it |
|
80 | - $table_alias = substr($table_alias_with_model_relation_chain_prefix, $pos + strlen(self::table_alias_model_relation_chain_prefix_end)); |
|
81 | - } else { |
|
82 | - $table_alias = $table_alias_with_model_relation_chain_prefix; |
|
83 | - } |
|
84 | - return $table_alias; |
|
85 | - } |
|
86 | - /** |
|
87 | - * Gets the table alias model relation chain prefix from the table alias already containing it |
|
88 | - * @param string $table_alias_with_model_relation_chain_prefix |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public static function get_prefix_from_table_alias_with_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix) |
|
92 | - { |
|
93 | - // does this actually have a table alias model relation chain prefix? |
|
94 | - $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end); |
|
95 | - if ($pos !== false) { |
|
96 | - // yes |
|
97 | - // find that triple underscore and remove it and everything before it |
|
98 | - $prefix = substr($table_alias_with_model_relation_chain_prefix, 0, $pos + strlen(self::table_alias_model_relation_chain_prefix_end)); |
|
99 | - } else { |
|
100 | - $prefix = ''; |
|
101 | - } |
|
102 | - return $prefix; |
|
103 | - } |
|
40 | + /** |
|
41 | + * Gets the calculated table's alias |
|
42 | + * @param string $model_relation_chain or query param |
|
43 | + * @param $this_model_name |
|
44 | + * @return string which can be added onto table aliases to make them unique |
|
45 | + */ |
|
46 | + public static function extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this_model_name) |
|
47 | + { |
|
48 | + // eg $model_relation_chain = 'Venue.Event_Venue.Event.Registration", and $this_model_name = 'Event' |
|
49 | + $model_relation_chain = self::pad_with_periods($model_relation_chain); |
|
50 | + $this_model_name = self::pad_with_periods($this_model_name); |
|
51 | + // eg '.Venue.Event_Venue.Event.Registration." and '.Event.' |
|
52 | + // remove this model name and everything afterwards |
|
53 | + $pos_of_model_name = strpos($model_relation_chain, $this_model_name); |
|
54 | + $model_relation_chain = substr($model_relation_chain, 0, $pos_of_model_name); |
|
55 | + // eg '.Venue.Event_Venue.' |
|
56 | + // trim periods |
|
57 | + $model_relation_chain = self::trim_periods($model_relation_chain); |
|
58 | + // eg 'Venue.Event_Venue' |
|
59 | + // replace periods with double-underscores |
|
60 | + $model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain); |
|
61 | + // eg 'Venue__Event_Venue' |
|
62 | + if ($model_relation_chain != '') { |
|
63 | + $model_relation_chain = $model_relation_chain . self::table_alias_model_relation_chain_prefix_end; |
|
64 | + } |
|
65 | + // eg 'Venue_Event_Venue___' |
|
66 | + return $model_relation_chain; |
|
67 | + } |
|
68 | + /** |
|
69 | + * Gets the table's alias (without prefix or anything) |
|
70 | + * @param string $table_alias_with_model_relation_chain_prefix which CAN have a table alias model relation chain prefix (or not) |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public static function remove_table_alias_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix) |
|
74 | + { |
|
75 | + // does this actually have a table alias model relation chain prefix? |
|
76 | + $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end); |
|
77 | + if ($pos !== false) { |
|
78 | + // yes |
|
79 | + // find that triple underscore and remove it and everything before it |
|
80 | + $table_alias = substr($table_alias_with_model_relation_chain_prefix, $pos + strlen(self::table_alias_model_relation_chain_prefix_end)); |
|
81 | + } else { |
|
82 | + $table_alias = $table_alias_with_model_relation_chain_prefix; |
|
83 | + } |
|
84 | + return $table_alias; |
|
85 | + } |
|
86 | + /** |
|
87 | + * Gets the table alias model relation chain prefix from the table alias already containing it |
|
88 | + * @param string $table_alias_with_model_relation_chain_prefix |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public static function get_prefix_from_table_alias_with_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix) |
|
92 | + { |
|
93 | + // does this actually have a table alias model relation chain prefix? |
|
94 | + $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end); |
|
95 | + if ($pos !== false) { |
|
96 | + // yes |
|
97 | + // find that triple underscore and remove it and everything before it |
|
98 | + $prefix = substr($table_alias_with_model_relation_chain_prefix, 0, $pos + strlen(self::table_alias_model_relation_chain_prefix_end)); |
|
99 | + } else { |
|
100 | + $prefix = ''; |
|
101 | + } |
|
102 | + return $prefix; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Gets the table alias model relation chain prefix (ie, what can be prepended onto |
|
107 | - * EE_Model_Field::get_qualified_column() to get the proper column name for that field |
|
108 | - * in a specific query) from teh query param (eg 'Registration.Event.EVT_ID'). |
|
109 | - * |
|
110 | - * @param string $model_name of the model on which the related query param was found to be belong |
|
111 | - * @param string $original_query_param |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public static function extract_table_alias_model_relation_chain_from_query_param($model_name, $original_query_param) |
|
115 | - { |
|
116 | - $relation_chain = self::extract_model_relation_chain($model_name, $original_query_param); |
|
117 | - $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($relation_chain, $model_name); |
|
118 | - return $table_alias_with_model_relation_chain_prefix; |
|
119 | - } |
|
120 | - /** |
|
121 | - * Gets the model relation chain to $model_name from the $original_query_param. |
|
122 | - * Eg, if $model_name were 'Payment', and $original_query_param were 'Registration.Transaction.Payment.PAY_ID', |
|
123 | - * this would return 'Registration.Transaction.Payment'. Also if the query param were 'Registration.Transaction.Payment' |
|
124 | - * and $model_name were 'Payment', it should return 'Registration.Transaction.Payment' |
|
125 | - * @param string $model_name |
|
126 | - * @param string $original_query_param |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public static function extract_model_relation_chain($model_name, $original_query_param) |
|
130 | - { |
|
131 | - // prefix and postfix both with a period, as this facilitates searching |
|
132 | - $model_name = EE_Model_Parser::pad_with_periods($model_name); |
|
133 | - $original_query_param = EE_Model_Parser::pad_with_periods($original_query_param); |
|
134 | - $pos_of_model_string = strpos($original_query_param, $model_name); |
|
135 | - // eg, if we're looking for the model relation chain from Event to Payment, the original query param is probably something like |
|
136 | - // "Registration.Transaction.Payment.PAY_ID", $pos_of_model_string points to the 'P' or Payment. We want the string |
|
137 | - // "Registration.Transaction.Payment" |
|
138 | - $model_relation_chain = substr($original_query_param, 0, $pos_of_model_string + strlen($model_name)); |
|
139 | - return EE_Model_Parser::trim_periods($model_relation_chain); |
|
140 | - } |
|
105 | + /** |
|
106 | + * Gets the table alias model relation chain prefix (ie, what can be prepended onto |
|
107 | + * EE_Model_Field::get_qualified_column() to get the proper column name for that field |
|
108 | + * in a specific query) from teh query param (eg 'Registration.Event.EVT_ID'). |
|
109 | + * |
|
110 | + * @param string $model_name of the model on which the related query param was found to be belong |
|
111 | + * @param string $original_query_param |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public static function extract_table_alias_model_relation_chain_from_query_param($model_name, $original_query_param) |
|
115 | + { |
|
116 | + $relation_chain = self::extract_model_relation_chain($model_name, $original_query_param); |
|
117 | + $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($relation_chain, $model_name); |
|
118 | + return $table_alias_with_model_relation_chain_prefix; |
|
119 | + } |
|
120 | + /** |
|
121 | + * Gets the model relation chain to $model_name from the $original_query_param. |
|
122 | + * Eg, if $model_name were 'Payment', and $original_query_param were 'Registration.Transaction.Payment.PAY_ID', |
|
123 | + * this would return 'Registration.Transaction.Payment'. Also if the query param were 'Registration.Transaction.Payment' |
|
124 | + * and $model_name were 'Payment', it should return 'Registration.Transaction.Payment' |
|
125 | + * @param string $model_name |
|
126 | + * @param string $original_query_param |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public static function extract_model_relation_chain($model_name, $original_query_param) |
|
130 | + { |
|
131 | + // prefix and postfix both with a period, as this facilitates searching |
|
132 | + $model_name = EE_Model_Parser::pad_with_periods($model_name); |
|
133 | + $original_query_param = EE_Model_Parser::pad_with_periods($original_query_param); |
|
134 | + $pos_of_model_string = strpos($original_query_param, $model_name); |
|
135 | + // eg, if we're looking for the model relation chain from Event to Payment, the original query param is probably something like |
|
136 | + // "Registration.Transaction.Payment.PAY_ID", $pos_of_model_string points to the 'P' or Payment. We want the string |
|
137 | + // "Registration.Transaction.Payment" |
|
138 | + $model_relation_chain = substr($original_query_param, 0, $pos_of_model_string + strlen($model_name)); |
|
139 | + return EE_Model_Parser::trim_periods($model_relation_chain); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Replaces the specified model in teh model relation chain with teh join model. |
|
144 | - * Eg EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain( |
|
145 | - * "Ticket", "Datetime_Ticket", "Datetime.Ticket" ) will return |
|
146 | - * "Datetime.Datetime_Ticket" which can be used to find the table alias model relation chain prefix |
|
147 | - * using EE_Model_Parser::extract_table_alias_model_relation_chain_prefix |
|
148 | - * @param string $model_name |
|
149 | - * @param string $join_model_name |
|
150 | - * @param string $model_relation_chain |
|
151 | - * @return string |
|
152 | - */ |
|
153 | - public static function replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_name, $model_relation_chain) |
|
154 | - { |
|
155 | - $model_name = EE_Model_Parser::pad_with_periods($model_name); |
|
156 | - $join_model_name = EE_Model_Parser::pad_with_periods($join_model_name); |
|
157 | - $model_relation_chain = EE_Model_Parser::pad_with_periods($model_relation_chain); |
|
158 | - $replaced_with_periods = str_replace($model_name, $join_model_name, $model_relation_chain); |
|
159 | - return EE_Model_Parser::trim_periods($replaced_with_periods); |
|
160 | - } |
|
142 | + /** |
|
143 | + * Replaces the specified model in teh model relation chain with teh join model. |
|
144 | + * Eg EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain( |
|
145 | + * "Ticket", "Datetime_Ticket", "Datetime.Ticket" ) will return |
|
146 | + * "Datetime.Datetime_Ticket" which can be used to find the table alias model relation chain prefix |
|
147 | + * using EE_Model_Parser::extract_table_alias_model_relation_chain_prefix |
|
148 | + * @param string $model_name |
|
149 | + * @param string $join_model_name |
|
150 | + * @param string $model_relation_chain |
|
151 | + * @return string |
|
152 | + */ |
|
153 | + public static function replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_name, $model_relation_chain) |
|
154 | + { |
|
155 | + $model_name = EE_Model_Parser::pad_with_periods($model_name); |
|
156 | + $join_model_name = EE_Model_Parser::pad_with_periods($join_model_name); |
|
157 | + $model_relation_chain = EE_Model_Parser::pad_with_periods($model_relation_chain); |
|
158 | + $replaced_with_periods = str_replace($model_name, $join_model_name, $model_relation_chain); |
|
159 | + return EE_Model_Parser::trim_periods($replaced_with_periods); |
|
160 | + } |
|
161 | 161 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public static function pad_with_periods($string_to_pad) |
25 | 25 | { |
26 | - return "." . $string_to_pad . "."; |
|
26 | + return ".".$string_to_pad."."; |
|
27 | 27 | } |
28 | 28 | /** |
29 | 29 | * Basically undoes _pad_with_periods |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain); |
61 | 61 | // eg 'Venue__Event_Venue' |
62 | 62 | if ($model_relation_chain != '') { |
63 | - $model_relation_chain = $model_relation_chain . self::table_alias_model_relation_chain_prefix_end; |
|
63 | + $model_relation_chain = $model_relation_chain.self::table_alias_model_relation_chain_prefix_end; |
|
64 | 64 | } |
65 | 65 | // eg 'Venue_Event_Venue___' |
66 | 66 | return $model_relation_chain; |