@@ -14,1261 +14,1261 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable |
16 | 16 | { |
17 | - /** |
|
18 | - * the input's name attribute |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $_html_name; |
|
23 | - |
|
24 | - /** |
|
25 | - * id for the html label tag |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $_html_label_id; |
|
30 | - |
|
31 | - /** |
|
32 | - * class for teh html label tag |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $_html_label_class; |
|
37 | - |
|
38 | - /** |
|
39 | - * style for teh html label tag |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - protected $_html_label_style; |
|
44 | - |
|
45 | - /** |
|
46 | - * text to be placed in the html label |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - protected $_html_label_text; |
|
51 | - |
|
52 | - /** |
|
53 | - * the full html label. If used, all other html_label_* properties are invalid |
|
54 | - * |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - protected $_html_label; |
|
58 | - |
|
59 | - /** |
|
60 | - * HTML to use for help text (normally placed below form input), in a span which normally |
|
61 | - * has a class of 'description' |
|
62 | - * |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - protected $_html_help_text; |
|
66 | - |
|
67 | - /** |
|
68 | - * CSS classes for displaying the help span |
|
69 | - * |
|
70 | - * @var string |
|
71 | - */ |
|
72 | - protected $_html_help_class = 'description'; |
|
73 | - |
|
74 | - /** |
|
75 | - * CSS to put in the style attribute on the help span |
|
76 | - * |
|
77 | - * @var string |
|
78 | - */ |
|
79 | - protected $_html_help_style; |
|
80 | - |
|
81 | - /** |
|
82 | - * Stores whether or not this input's response is required. |
|
83 | - * Because certain styling elements may also want to know that this |
|
84 | - * input is required etc. |
|
85 | - * |
|
86 | - * @var boolean |
|
87 | - */ |
|
88 | - protected $_required; |
|
89 | - |
|
90 | - /** |
|
91 | - * css class added to required inputs |
|
92 | - * |
|
93 | - * @var string |
|
94 | - */ |
|
95 | - protected $_required_css_class = 'ee-required'; |
|
96 | - |
|
97 | - /** |
|
98 | - * css styles applied to button type inputs |
|
99 | - * |
|
100 | - * @var string |
|
101 | - */ |
|
102 | - protected $_button_css_attributes; |
|
103 | - |
|
104 | - /** |
|
105 | - * The raw post data submitted for this |
|
106 | - * Generally unsafe for usage in client code |
|
107 | - * |
|
108 | - * @var mixed string or array |
|
109 | - */ |
|
110 | - protected $_raw_value; |
|
111 | - |
|
112 | - /** |
|
113 | - * Value normalized according to the input's normalization strategy. |
|
114 | - * The normalization strategy dictates whether this is a string, int, float, |
|
115 | - * boolean, or array of any of those. |
|
116 | - * |
|
117 | - * @var mixed |
|
118 | - */ |
|
119 | - protected $_normalized_value; |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * Normalized default value either initially set on the input, or provided by calling |
|
124 | - * set_default(). |
|
125 | - * @var mixed |
|
126 | - */ |
|
127 | - protected $_default; |
|
128 | - |
|
129 | - /** |
|
130 | - * Strategy used for displaying this field. |
|
131 | - * Child classes must use _get_display_strategy to access it. |
|
132 | - * |
|
133 | - * @var EE_Display_Strategy_Base |
|
134 | - */ |
|
135 | - private $_display_strategy; |
|
136 | - |
|
137 | - /** |
|
138 | - * Gets all the validation strategies used on this field |
|
139 | - * |
|
140 | - * @var EE_Validation_Strategy_Base[] |
|
141 | - */ |
|
142 | - private $_validation_strategies = array(); |
|
143 | - |
|
144 | - /** |
|
145 | - * The normalization strategy for this field |
|
146 | - * |
|
147 | - * @var EE_Normalization_Strategy_Base |
|
148 | - */ |
|
149 | - private $_normalization_strategy; |
|
150 | - |
|
151 | - /** |
|
152 | - * Strategy for removing sensitive data after we're done with the form input |
|
153 | - * |
|
154 | - * @var EE_Sensitive_Data_Removal_Base |
|
155 | - */ |
|
156 | - protected $_sensitive_data_removal_strategy; |
|
157 | - |
|
158 | - /** |
|
159 | - * Whether this input has been disabled or not. |
|
160 | - * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled. |
|
161 | - * (Client-side code that wants to dynamically disable it must also add this hidden input). |
|
162 | - * When the form is submitted, if the input is disabled in the PHP form section, then input is ignored. |
|
163 | - * If the input is missing from the request data but the hidden input indicating the input is disabled, then the input is again ignored. |
|
164 | - * |
|
165 | - * @var boolean |
|
166 | - */ |
|
167 | - protected $disabled = false; |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param array $input_args { |
|
173 | - * @type string $html_name the html name for the input |
|
174 | - * @type string $html_label_id the id attribute to give to the html label tag |
|
175 | - * @type string $html_label_class the class attribute to give to the html label tag |
|
176 | - * @type string $html_label_style the style attribute to give ot teh label tag |
|
177 | - * @type string $html_label_text the text to put in the label tag |
|
178 | - * @type string $html_label the full html label. If used, |
|
179 | - * all other html_label_* args are invalid |
|
180 | - * @type string $html_help_text text to put in help element |
|
181 | - * @type string $html_help_style style attribute to give to teh help element |
|
182 | - * @type string $html_help_class class attribute to give to the help element |
|
183 | - * @type string $default default value NORMALIZED (eg, if providing the default |
|
184 | - * for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0') |
|
185 | - * @type EE_Display_Strategy_Base $display strategy |
|
186 | - * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
187 | - * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
188 | - * @type boolean $ignore_input special argument which can be used to avoid adding any validation strategies, |
|
189 | - * and sets the normalization strategy to the Null normalization. This is good |
|
190 | - * when you want the input to be totally ignored server-side (like when using |
|
191 | - * React.js form inputs) |
|
192 | - * } |
|
193 | - */ |
|
194 | - public function __construct($input_args = array()) |
|
195 | - { |
|
196 | - $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
197 | - // the following properties must be cast as arrays |
|
198 | - if (isset($input_args['validation_strategies'])) { |
|
199 | - foreach ((array) $input_args['validation_strategies'] as $validation_strategy) { |
|
200 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) { |
|
201 | - $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy; |
|
202 | - } |
|
203 | - } |
|
204 | - unset($input_args['validation_strategies']); |
|
205 | - } |
|
206 | - if (isset($input_args['ignore_input'])) { |
|
207 | - $this->_validation_strategies = array(); |
|
208 | - } |
|
209 | - // loop thru incoming options |
|
210 | - foreach ($input_args as $key => $value) { |
|
211 | - // add underscore to $key to match property names |
|
212 | - $_key = '_' . $key; |
|
213 | - if (property_exists($this, $_key)) { |
|
214 | - $this->{$_key} = $value; |
|
215 | - } |
|
216 | - } |
|
217 | - // ensure that "required" is set correctly |
|
218 | - $this->set_required( |
|
219 | - $this->_required, |
|
220 | - isset($input_args['required_validation_error_message']) |
|
221 | - ? $input_args['required_validation_error_message'] |
|
222 | - : null |
|
223 | - ); |
|
224 | - // $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
225 | - $this->_display_strategy->_construct_finalize($this); |
|
226 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
227 | - $validation_strategy->_construct_finalize($this); |
|
228 | - } |
|
229 | - if (isset($input_args['ignore_input'])) { |
|
230 | - $this->_normalization_strategy = new EE_Null_Normalization(); |
|
231 | - } |
|
232 | - if (! $this->_normalization_strategy) { |
|
233 | - $this->_normalization_strategy = new EE_Text_Normalization(); |
|
234 | - } |
|
235 | - $this->_normalization_strategy->_construct_finalize($this); |
|
236 | - // at least we can use the normalization strategy to populate the default |
|
237 | - if (isset($input_args['default'])) { |
|
238 | - $this->set_default($input_args['default']); |
|
239 | - unset($input_args['default']); |
|
240 | - } |
|
241 | - if (! $this->_sensitive_data_removal_strategy) { |
|
242 | - $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
243 | - } |
|
244 | - $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
245 | - parent::__construct($input_args); |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * Sets the html_name to its default value, if none was specified in teh constructor. |
|
252 | - * Calculation involves using the name and the parent's html_name |
|
253 | - * |
|
254 | - * @throws EE_Error |
|
255 | - */ |
|
256 | - protected function _set_default_html_name_if_empty() |
|
257 | - { |
|
258 | - if (! $this->_html_name) { |
|
259 | - $this->_html_name = $this->name(); |
|
260 | - if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
261 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
262 | - } |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * @param $parent_form_section |
|
270 | - * @param $name |
|
271 | - * @throws EE_Error |
|
272 | - */ |
|
273 | - public function _construct_finalize($parent_form_section, $name) |
|
274 | - { |
|
275 | - parent::_construct_finalize($parent_form_section, $name); |
|
276 | - if ($this->_html_label === null && $this->_html_label_text === null) { |
|
277 | - $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
278 | - } |
|
279 | - do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
286 | - * |
|
287 | - * @return EE_Display_Strategy_Base |
|
288 | - * @throws EE_Error |
|
289 | - */ |
|
290 | - protected function _get_display_strategy() |
|
291 | - { |
|
292 | - $this->ensure_construct_finalized_called(); |
|
293 | - if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
294 | - throw new EE_Error( |
|
295 | - sprintf( |
|
296 | - esc_html__( |
|
297 | - "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
298 | - "event_espresso" |
|
299 | - ), |
|
300 | - $this->html_name(), |
|
301 | - $this->html_id() |
|
302 | - ) |
|
303 | - ); |
|
304 | - } else { |
|
305 | - return $this->_display_strategy; |
|
306 | - } |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * Sets the display strategy. |
|
313 | - * |
|
314 | - * @param EE_Display_Strategy_Base $strategy |
|
315 | - */ |
|
316 | - protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
317 | - { |
|
318 | - $this->_display_strategy = $strategy; |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * Sets the sanitization strategy |
|
325 | - * |
|
326 | - * @param EE_Normalization_Strategy_Base $strategy |
|
327 | - */ |
|
328 | - protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
329 | - { |
|
330 | - $this->_normalization_strategy = $strategy; |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * Gets sensitive_data_removal_strategy |
|
337 | - * |
|
338 | - * @return EE_Sensitive_Data_Removal_Base |
|
339 | - */ |
|
340 | - public function get_sensitive_data_removal_strategy() |
|
341 | - { |
|
342 | - return $this->_sensitive_data_removal_strategy; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Sets sensitive_data_removal_strategy |
|
349 | - * |
|
350 | - * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
351 | - * @return void |
|
352 | - */ |
|
353 | - public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
354 | - { |
|
355 | - $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * Gets the display strategy for this input |
|
362 | - * |
|
363 | - * @return EE_Display_Strategy_Base |
|
364 | - */ |
|
365 | - public function get_display_strategy() |
|
366 | - { |
|
367 | - return $this->_display_strategy; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Overwrites the display strategy |
|
374 | - * |
|
375 | - * @param EE_Display_Strategy_Base $display_strategy |
|
376 | - */ |
|
377 | - public function set_display_strategy($display_strategy) |
|
378 | - { |
|
379 | - $this->_display_strategy = $display_strategy; |
|
380 | - $this->_display_strategy->_construct_finalize($this); |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * Gets the normalization strategy set on this input |
|
387 | - * |
|
388 | - * @return EE_Normalization_Strategy_Base |
|
389 | - */ |
|
390 | - public function get_normalization_strategy() |
|
391 | - { |
|
392 | - return $this->_normalization_strategy; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * Overwrites the normalization strategy |
|
399 | - * |
|
400 | - * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
401 | - */ |
|
402 | - public function set_normalization_strategy($normalization_strategy) |
|
403 | - { |
|
404 | - $this->_normalization_strategy = $normalization_strategy; |
|
405 | - $this->_normalization_strategy->_construct_finalize($this); |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * Returns all teh validation strategies which apply to this field, numerically indexed |
|
412 | - * |
|
413 | - * @return EE_Validation_Strategy_Base[] |
|
414 | - */ |
|
415 | - public function get_validation_strategies() |
|
416 | - { |
|
417 | - return $this->_validation_strategies; |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
424 | - * |
|
425 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
426 | - * @return void |
|
427 | - */ |
|
428 | - protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
429 | - { |
|
430 | - $validation_strategy->_construct_finalize($this); |
|
431 | - $this->_validation_strategies[] = $validation_strategy; |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Adds a new validation strategy onto the form input |
|
438 | - * |
|
439 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
440 | - * @return void |
|
441 | - */ |
|
442 | - public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
443 | - { |
|
444 | - $this->_add_validation_strategy($validation_strategy); |
|
445 | - } |
|
446 | - |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * The classname of the validation strategy to remove |
|
451 | - * |
|
452 | - * @param string $validation_strategy_classname |
|
453 | - */ |
|
454 | - public function remove_validation_strategy($validation_strategy_classname) |
|
455 | - { |
|
456 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
457 | - if ( |
|
458 | - $validation_strategy instanceof $validation_strategy_classname |
|
459 | - || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
460 | - ) { |
|
461 | - unset($this->_validation_strategies[ $key ]); |
|
462 | - } |
|
463 | - } |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
470 | - * |
|
471 | - * @param array $validation_strategy_classnames |
|
472 | - * @return bool |
|
473 | - */ |
|
474 | - public function has_validation_strategy($validation_strategy_classnames) |
|
475 | - { |
|
476 | - $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
477 | - ? $validation_strategy_classnames |
|
478 | - : array($validation_strategy_classnames); |
|
479 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
480 | - if (in_array($key, $validation_strategy_classnames)) { |
|
481 | - return true; |
|
482 | - } |
|
483 | - } |
|
484 | - return false; |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * Gets the HTML |
|
491 | - * |
|
492 | - * @return string |
|
493 | - */ |
|
494 | - public function get_html() |
|
495 | - { |
|
496 | - return $this->_parent_section->get_html_for_input($this); |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * Gets the HTML for the input itself (no label or errors) according to the |
|
503 | - * input's display strategy |
|
504 | - * Makes sure the JS and CSS are enqueued for it |
|
505 | - * |
|
506 | - * @return string |
|
507 | - * @throws EE_Error |
|
508 | - */ |
|
509 | - public function get_html_for_input() |
|
510 | - { |
|
511 | - return $this->_form_html_filter |
|
512 | - ? $this->_form_html_filter->filterHtml( |
|
513 | - $this->_get_display_strategy()->display(), |
|
514 | - $this |
|
515 | - ) |
|
516 | - : $this->_get_display_strategy()->display(); |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - |
|
521 | - /** |
|
522 | - * @return string |
|
523 | - */ |
|
524 | - public function html_other_attributes() |
|
525 | - { |
|
526 | - EE_Error::doing_it_wrong( |
|
527 | - __METHOD__, |
|
528 | - sprintf( |
|
529 | - esc_html__( |
|
530 | - 'This method is no longer in use. You should replace it by %s', |
|
531 | - 'event_espresso' |
|
532 | - ), |
|
533 | - 'EE_Form_Section_Base::other_html_attributes()' |
|
534 | - ), |
|
535 | - '4.10.2.p' |
|
536 | - ); |
|
537 | - |
|
538 | - return $this->other_html_attributes(); |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * @param string $html_other_attributes |
|
545 | - */ |
|
546 | - public function set_html_other_attributes($html_other_attributes) |
|
547 | - { |
|
548 | - EE_Error::doing_it_wrong( |
|
549 | - __METHOD__, |
|
550 | - sprintf( |
|
551 | - esc_html__( |
|
552 | - 'This method is no longer in use. You should replace it by %s', |
|
553 | - 'event_espresso' |
|
554 | - ), |
|
555 | - 'EE_Form_Section_Base::set_other_html_attributes()' |
|
556 | - ), |
|
557 | - '4.10.2.p' |
|
558 | - ); |
|
559 | - |
|
560 | - $this->set_other_html_attributes($html_other_attributes); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * Gets the HTML for displaying the label for this form input |
|
567 | - * according to the form section's layout strategy |
|
568 | - * |
|
569 | - * @return string |
|
570 | - */ |
|
571 | - public function get_html_for_label() |
|
572 | - { |
|
573 | - return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * Gets the HTML for displaying the errors section for this form input |
|
580 | - * according to the form section's layout strategy |
|
581 | - * |
|
582 | - * @return string |
|
583 | - */ |
|
584 | - public function get_html_for_errors() |
|
585 | - { |
|
586 | - return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
587 | - } |
|
588 | - |
|
589 | - |
|
590 | - |
|
591 | - /** |
|
592 | - * Gets the HTML for displaying the help text for this form input |
|
593 | - * according to the form section's layout strategy |
|
594 | - * |
|
595 | - * @return string |
|
596 | - */ |
|
597 | - public function get_html_for_help() |
|
598 | - { |
|
599 | - return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
600 | - } |
|
601 | - |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
606 | - * and returns whether or not the form input's submitted value is value |
|
607 | - * |
|
608 | - * @return boolean |
|
609 | - */ |
|
610 | - protected function _validate() |
|
611 | - { |
|
612 | - if ($this->isDisabled()) { |
|
613 | - return true; |
|
614 | - } |
|
615 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
616 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
617 | - try { |
|
618 | - $validation_strategy->validate($this->normalized_value()); |
|
619 | - } catch (EE_Validation_Error $e) { |
|
620 | - $this->add_validation_error($e); |
|
621 | - } |
|
622 | - } |
|
623 | - } |
|
624 | - if ($this->get_validation_errors()) { |
|
625 | - return false; |
|
626 | - } else { |
|
627 | - return true; |
|
628 | - } |
|
629 | - } |
|
630 | - |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
635 | - * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
636 | - * |
|
637 | - * @param string $value |
|
638 | - * @return null|string |
|
639 | - */ |
|
640 | - protected function _sanitize($value) |
|
641 | - { |
|
642 | - return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
643 | - } |
|
644 | - |
|
645 | - |
|
646 | - |
|
647 | - /** |
|
648 | - * Picks out the form value that relates to this form input, |
|
649 | - * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
650 | - * Returns whether or not any validation errors occurred |
|
651 | - * |
|
652 | - * @param array $req_data |
|
653 | - * @return boolean whether or not there was an error |
|
654 | - * @throws EE_Error |
|
655 | - */ |
|
656 | - protected function _normalize($req_data) |
|
657 | - { |
|
658 | - // any existing validation errors don't apply so clear them |
|
659 | - $this->_validation_errors = array(); |
|
660 | - // if the input is disabled, ignore whatever input was sent in |
|
661 | - if ($this->isDisabled()) { |
|
662 | - $this->_set_raw_value(null); |
|
663 | - $this->_set_normalized_value($this->get_default()); |
|
664 | - return false; |
|
665 | - } |
|
666 | - try { |
|
667 | - $raw_input = $this->find_form_data_for_this_section($req_data); |
|
668 | - // super simple sanitization for now |
|
669 | - if (is_array($raw_input)) { |
|
670 | - $raw_value = array(); |
|
671 | - foreach ($raw_input as $key => $value) { |
|
672 | - $raw_value[ $key ] = $this->_sanitize($value); |
|
673 | - } |
|
674 | - $this->_set_raw_value($raw_value); |
|
675 | - } else { |
|
676 | - $this->_set_raw_value($this->_sanitize($raw_input)); |
|
677 | - } |
|
678 | - // we want to mostly leave the input alone in case we need to re-display it to the user |
|
679 | - $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
680 | - return false; |
|
681 | - } catch (EE_Validation_Error $e) { |
|
682 | - $this->add_validation_error($e); |
|
683 | - return true; |
|
684 | - } |
|
685 | - } |
|
686 | - |
|
687 | - |
|
688 | - /** |
|
689 | - * @return string |
|
690 | - * @throws EE_Error |
|
691 | - */ |
|
692 | - public function html_name() |
|
693 | - { |
|
694 | - $this->_set_default_html_name_if_empty(); |
|
695 | - return $this->_html_name; |
|
696 | - } |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * @return string |
|
701 | - * @throws EE_Error |
|
702 | - */ |
|
703 | - public function html_label_id() |
|
704 | - { |
|
705 | - return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl'; |
|
706 | - } |
|
707 | - |
|
708 | - |
|
709 | - |
|
710 | - /** |
|
711 | - * @return string |
|
712 | - */ |
|
713 | - public function html_label_class() |
|
714 | - { |
|
715 | - return $this->_html_label_class; |
|
716 | - } |
|
717 | - |
|
718 | - |
|
719 | - |
|
720 | - /** |
|
721 | - * @return string |
|
722 | - */ |
|
723 | - public function html_label_style() |
|
724 | - { |
|
725 | - return $this->_html_label_style; |
|
726 | - } |
|
727 | - |
|
728 | - |
|
729 | - |
|
730 | - /** |
|
731 | - * @return string |
|
732 | - */ |
|
733 | - public function html_label_text() |
|
734 | - { |
|
735 | - return $this->_html_label_text; |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * @return string |
|
742 | - */ |
|
743 | - public function html_help_text() |
|
744 | - { |
|
745 | - return $this->_html_help_text; |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - |
|
750 | - /** |
|
751 | - * @return string |
|
752 | - */ |
|
753 | - public function html_help_class() |
|
754 | - { |
|
755 | - return $this->_html_help_class; |
|
756 | - } |
|
757 | - |
|
758 | - |
|
759 | - |
|
760 | - /** |
|
761 | - * @return string |
|
762 | - */ |
|
763 | - public function html_help_style() |
|
764 | - { |
|
765 | - return $this->_html_style; |
|
766 | - } |
|
767 | - |
|
768 | - |
|
769 | - |
|
770 | - /** |
|
771 | - * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
772 | - * Please note that almost all client code should instead use the normalized_value; |
|
773 | - * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
774 | - * mostly by escaping quotes) |
|
775 | - * Note, we do not store the exact original value sent in the user's request because |
|
776 | - * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
777 | - * in which case, we would have stored the malicious content to our database. |
|
778 | - * |
|
779 | - * @return string |
|
780 | - */ |
|
781 | - public function raw_value() |
|
782 | - { |
|
783 | - return $this->_raw_value; |
|
784 | - } |
|
785 | - |
|
786 | - |
|
787 | - |
|
788 | - /** |
|
789 | - * Returns a string safe to usage in form inputs when displaying, because |
|
790 | - * it escapes all html entities |
|
791 | - * |
|
792 | - * @return string |
|
793 | - */ |
|
794 | - public function raw_value_in_form() |
|
795 | - { |
|
796 | - return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
797 | - } |
|
798 | - |
|
799 | - |
|
800 | - |
|
801 | - /** |
|
802 | - * returns the value after it's been sanitized, and then converted into it's proper type |
|
803 | - * in PHP. Eg, a string, an int, an array, |
|
804 | - * |
|
805 | - * @return mixed |
|
806 | - */ |
|
807 | - public function normalized_value() |
|
808 | - { |
|
809 | - return $this->_normalized_value; |
|
810 | - } |
|
811 | - |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * Returns the normalized value is a presentable way. By default this is just |
|
816 | - * the normalized value by itself, but it can be overridden for when that's not |
|
817 | - * the best thing to display |
|
818 | - * |
|
819 | - * @return string |
|
820 | - */ |
|
821 | - public function pretty_value() |
|
822 | - { |
|
823 | - return $this->_normalized_value; |
|
824 | - } |
|
825 | - |
|
826 | - |
|
827 | - |
|
828 | - /** |
|
829 | - * When generating the JS for the jquery validation rules like<br> |
|
830 | - * <code>$( "#myform" ).validate({ |
|
831 | - * rules: { |
|
832 | - * password: "required", |
|
833 | - * password_again: { |
|
834 | - * equalTo: "#password" |
|
835 | - * } |
|
836 | - * } |
|
837 | - * });</code> |
|
838 | - * if this field had the name 'password_again', it should return |
|
839 | - * <br><code>password_again: { |
|
840 | - * equalTo: "#password" |
|
841 | - * }</code> |
|
842 | - * |
|
843 | - * @return array |
|
844 | - */ |
|
845 | - public function get_jquery_validation_rules() |
|
846 | - { |
|
847 | - $jquery_validation_js = array(); |
|
848 | - $jquery_validation_rules = array(); |
|
849 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
850 | - $jquery_validation_rules = array_replace_recursive( |
|
851 | - $jquery_validation_rules, |
|
852 | - $validation_strategy->get_jquery_validation_rule_array() |
|
853 | - ); |
|
854 | - } |
|
855 | - if (! empty($jquery_validation_rules)) { |
|
856 | - foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
857 | - $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules; |
|
858 | - } |
|
859 | - } |
|
860 | - return $jquery_validation_js; |
|
861 | - } |
|
862 | - |
|
863 | - |
|
864 | - |
|
865 | - /** |
|
866 | - * Sets the input's default value for use in displaying in the form. Note: value should be |
|
867 | - * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
868 | - * |
|
869 | - * @param mixed $value |
|
870 | - * @return void |
|
871 | - */ |
|
872 | - public function set_default($value) |
|
873 | - { |
|
874 | - $this->_default = $value; |
|
875 | - $this->_set_normalized_value($value); |
|
876 | - $this->_set_raw_value($value); |
|
877 | - } |
|
878 | - |
|
879 | - |
|
880 | - |
|
881 | - /** |
|
882 | - * Sets the normalized value on this input |
|
883 | - * |
|
884 | - * @param mixed $value |
|
885 | - */ |
|
886 | - protected function _set_normalized_value($value) |
|
887 | - { |
|
888 | - $this->_normalized_value = $value; |
|
889 | - } |
|
890 | - |
|
891 | - |
|
892 | - |
|
893 | - /** |
|
894 | - * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
895 | - * |
|
896 | - * @param mixed $value |
|
897 | - */ |
|
898 | - protected function _set_raw_value($value) |
|
899 | - { |
|
900 | - $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
901 | - } |
|
902 | - |
|
903 | - |
|
904 | - |
|
905 | - /** |
|
906 | - * Sets the HTML label text after it has already been defined |
|
907 | - * |
|
908 | - * @param string $label |
|
909 | - * @return void |
|
910 | - */ |
|
911 | - public function set_html_label_text($label) |
|
912 | - { |
|
913 | - $this->_html_label_text = $label; |
|
914 | - } |
|
915 | - |
|
916 | - |
|
917 | - |
|
918 | - /** |
|
919 | - * Sets whether or not this field is required, and adjusts the validation strategy. |
|
920 | - * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
921 | - * please add it as a validation strategy using add_validation_strategy as normal |
|
922 | - * |
|
923 | - * @param boolean $required boolean |
|
924 | - * @param null $required_text |
|
925 | - */ |
|
926 | - public function set_required($required = true, $required_text = null) |
|
927 | - { |
|
928 | - $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
929 | - // whether $required is a string or a boolean, we want to add a required validation strategy |
|
930 | - if ($required) { |
|
931 | - $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
932 | - } else { |
|
933 | - $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
934 | - } |
|
935 | - $this->_required = $required; |
|
936 | - } |
|
937 | - |
|
938 | - |
|
939 | - |
|
940 | - /** |
|
941 | - * Returns whether or not this field is required |
|
942 | - * |
|
943 | - * @return boolean |
|
944 | - */ |
|
945 | - public function required() |
|
946 | - { |
|
947 | - return $this->_required; |
|
948 | - } |
|
949 | - |
|
950 | - |
|
951 | - |
|
952 | - /** |
|
953 | - * @param string $required_css_class |
|
954 | - */ |
|
955 | - public function set_required_css_class($required_css_class) |
|
956 | - { |
|
957 | - $this->_required_css_class = $required_css_class; |
|
958 | - } |
|
959 | - |
|
960 | - |
|
961 | - |
|
962 | - /** |
|
963 | - * @return string |
|
964 | - */ |
|
965 | - public function required_css_class() |
|
966 | - { |
|
967 | - return $this->_required_css_class; |
|
968 | - } |
|
969 | - |
|
970 | - |
|
971 | - |
|
972 | - /** |
|
973 | - * @param bool $add_required |
|
974 | - * @return string |
|
975 | - */ |
|
976 | - public function html_class($add_required = false) |
|
977 | - { |
|
978 | - return $add_required && $this->required() |
|
979 | - ? $this->required_css_class() . ' ' . $this->_html_class |
|
980 | - : $this->_html_class; |
|
981 | - } |
|
982 | - |
|
983 | - |
|
984 | - /** |
|
985 | - * Sets the help text, in case |
|
986 | - * |
|
987 | - * @param string $text |
|
988 | - */ |
|
989 | - public function set_html_help_text($text) |
|
990 | - { |
|
991 | - $this->_html_help_text = $text; |
|
992 | - } |
|
993 | - |
|
994 | - |
|
995 | - |
|
996 | - /** |
|
997 | - * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
998 | - * input. If there is any kind of sensitive data removal on this input, we clear |
|
999 | - * out the raw value completely |
|
1000 | - * |
|
1001 | - * @return void |
|
1002 | - */ |
|
1003 | - public function clean_sensitive_data() |
|
1004 | - { |
|
1005 | - // if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
1006 | - // if we need more logic than this we'll make a strategy for it |
|
1007 | - if ( |
|
1008 | - $this->_sensitive_data_removal_strategy |
|
1009 | - && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
1010 | - ) { |
|
1011 | - $this->_set_raw_value(null); |
|
1012 | - } |
|
1013 | - // and clean the normalized value according to the appropriate strategy |
|
1014 | - $this->_set_normalized_value( |
|
1015 | - $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
1016 | - $this->_normalized_value |
|
1017 | - ) |
|
1018 | - ); |
|
1019 | - } |
|
1020 | - |
|
1021 | - |
|
1022 | - |
|
1023 | - /** |
|
1024 | - * @param bool $primary |
|
1025 | - * @param string $button_size |
|
1026 | - * @param string $other_attributes |
|
1027 | - */ |
|
1028 | - public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
1029 | - { |
|
1030 | - $button_css_attributes = 'button'; |
|
1031 | - $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary'; |
|
1032 | - switch ($button_size) { |
|
1033 | - case 'xs': |
|
1034 | - case 'extra-small': |
|
1035 | - $button_css_attributes .= ' button-xs'; |
|
1036 | - break; |
|
1037 | - case 'sm': |
|
1038 | - case 'small': |
|
1039 | - $button_css_attributes .= ' button-sm'; |
|
1040 | - break; |
|
1041 | - case 'lg': |
|
1042 | - case 'large': |
|
1043 | - $button_css_attributes .= ' button-lg'; |
|
1044 | - break; |
|
1045 | - case 'block': |
|
1046 | - $button_css_attributes .= ' button-block'; |
|
1047 | - break; |
|
1048 | - case 'md': |
|
1049 | - case 'medium': |
|
1050 | - default: |
|
1051 | - $button_css_attributes .= ''; |
|
1052 | - } |
|
1053 | - $this->_button_css_attributes .= ! empty($other_attributes) |
|
1054 | - ? $button_css_attributes . ' ' . $other_attributes |
|
1055 | - : $button_css_attributes; |
|
1056 | - } |
|
1057 | - |
|
1058 | - |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * @return string |
|
1062 | - */ |
|
1063 | - public function button_css_attributes() |
|
1064 | - { |
|
1065 | - if (empty($this->_button_css_attributes)) { |
|
1066 | - $this->set_button_css_attributes(); |
|
1067 | - } |
|
1068 | - return $this->_button_css_attributes; |
|
1069 | - } |
|
1070 | - |
|
1071 | - |
|
1072 | - |
|
1073 | - /** |
|
1074 | - * find_form_data_for_this_section |
|
1075 | - * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
1076 | - * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
1077 | - * then it's value should be in request at request['my_form']['subform']['form_input_1']. |
|
1078 | - * (If that doesn't exist, we also check for this subsection's name |
|
1079 | - * at the TOP LEVEL of the request data. Eg request['form_input_1'].) |
|
1080 | - * This function finds its value in the form. |
|
1081 | - * |
|
1082 | - * @param array $req_data |
|
1083 | - * @return mixed whatever the raw value of this form section is in the request data |
|
1084 | - * @throws EE_Error |
|
1085 | - */ |
|
1086 | - public function find_form_data_for_this_section($req_data) |
|
1087 | - { |
|
1088 | - $name_parts = $this->getInputNameParts(); |
|
1089 | - // now get the value for the input |
|
1090 | - $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data); |
|
1091 | - // check if this thing's name is at the TOP level of the request data |
|
1092 | - if ($value === null && isset($req_data[ $this->name() ])) { |
|
1093 | - $value = $req_data[ $this->name() ]; |
|
1094 | - } |
|
1095 | - return $value; |
|
1096 | - } |
|
1097 | - |
|
1098 | - |
|
1099 | - /** |
|
1100 | - * If this input's name is something like "foo[bar][baz]" |
|
1101 | - * returns an array like `array('foo','bar',baz')` |
|
1102 | - * |
|
1103 | - * @return array |
|
1104 | - * @throws EE_Error |
|
1105 | - */ |
|
1106 | - protected function getInputNameParts() |
|
1107 | - { |
|
1108 | - // break up the html name by "[]" |
|
1109 | - if (strpos($this->html_name(), '[') !== false) { |
|
1110 | - $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
1111 | - } else { |
|
1112 | - $before_any_brackets = $this->html_name(); |
|
1113 | - } |
|
1114 | - // grab all of the segments |
|
1115 | - preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
1116 | - if (isset($matches[1]) && is_array($matches[1])) { |
|
1117 | - $name_parts = $matches[1]; |
|
1118 | - array_unshift($name_parts, $before_any_brackets); |
|
1119 | - } else { |
|
1120 | - $name_parts = array($before_any_brackets); |
|
1121 | - } |
|
1122 | - return $name_parts; |
|
1123 | - } |
|
1124 | - |
|
1125 | - |
|
1126 | - |
|
1127 | - /** |
|
1128 | - * @param array $html_name_parts |
|
1129 | - * @param array $req_data |
|
1130 | - * @return array | NULL |
|
1131 | - */ |
|
1132 | - public function findRequestForSectionUsingNameParts($html_name_parts, $req_data) |
|
1133 | - { |
|
1134 | - $first_part_to_consider = array_shift($html_name_parts); |
|
1135 | - if (isset($req_data[ $first_part_to_consider ])) { |
|
1136 | - if (empty($html_name_parts)) { |
|
1137 | - return $req_data[ $first_part_to_consider ]; |
|
1138 | - } else { |
|
1139 | - return $this->findRequestForSectionUsingNameParts( |
|
1140 | - $html_name_parts, |
|
1141 | - $req_data[ $first_part_to_consider ] |
|
1142 | - ); |
|
1143 | - } |
|
1144 | - } else { |
|
1145 | - return null; |
|
1146 | - } |
|
1147 | - } |
|
1148 | - |
|
1149 | - |
|
1150 | - |
|
1151 | - /** |
|
1152 | - * Checks if this form input's data is in the request data |
|
1153 | - * |
|
1154 | - * @param array $req_data |
|
1155 | - * @return boolean |
|
1156 | - * @throws EE_Error |
|
1157 | - */ |
|
1158 | - public function form_data_present_in($req_data = null) |
|
1159 | - { |
|
1160 | - if ($req_data === null) { |
|
1161 | - /** @var RequestInterface $request */ |
|
1162 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
1163 | - $req_data = $request->postParams(); |
|
1164 | - } |
|
1165 | - $checked_value = $this->find_form_data_for_this_section($req_data); |
|
1166 | - if ($checked_value !== null) { |
|
1167 | - return true; |
|
1168 | - } else { |
|
1169 | - return false; |
|
1170 | - } |
|
1171 | - } |
|
1172 | - |
|
1173 | - |
|
1174 | - |
|
1175 | - /** |
|
1176 | - * Overrides parent to add js data from validation and display strategies |
|
1177 | - * |
|
1178 | - * @param array $form_other_js_data |
|
1179 | - * @return array |
|
1180 | - */ |
|
1181 | - public function get_other_js_data($form_other_js_data = array()) |
|
1182 | - { |
|
1183 | - return $this->get_other_js_data_from_strategies($form_other_js_data); |
|
1184 | - } |
|
1185 | - |
|
1186 | - |
|
1187 | - |
|
1188 | - /** |
|
1189 | - * Gets other JS data for localization from this input's strategies, like |
|
1190 | - * the validation strategies and the display strategy |
|
1191 | - * |
|
1192 | - * @param array $form_other_js_data |
|
1193 | - * @return array |
|
1194 | - */ |
|
1195 | - public function get_other_js_data_from_strategies($form_other_js_data = array()) |
|
1196 | - { |
|
1197 | - $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
1198 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1199 | - $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
1200 | - } |
|
1201 | - return $form_other_js_data; |
|
1202 | - } |
|
1203 | - |
|
1204 | - |
|
1205 | - |
|
1206 | - /** |
|
1207 | - * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
1208 | - * |
|
1209 | - * @return void |
|
1210 | - */ |
|
1211 | - public function enqueue_js() |
|
1212 | - { |
|
1213 | - // ask our display strategy and validation strategies if they have js to enqueue |
|
1214 | - $this->enqueue_js_from_strategies(); |
|
1215 | - } |
|
1216 | - |
|
1217 | - |
|
1218 | - |
|
1219 | - /** |
|
1220 | - * Tells strategies when its ok to enqueue their js and css |
|
1221 | - * |
|
1222 | - * @return void |
|
1223 | - */ |
|
1224 | - public function enqueue_js_from_strategies() |
|
1225 | - { |
|
1226 | - $this->get_display_strategy()->enqueue_js(); |
|
1227 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1228 | - $validation_strategy->enqueue_js(); |
|
1229 | - } |
|
1230 | - } |
|
1231 | - |
|
1232 | - |
|
1233 | - |
|
1234 | - /** |
|
1235 | - * Gets the default value set on the input (not the current value, which may have been |
|
1236 | - * changed because of a form submission). If no default was set, this us null. |
|
1237 | - * @return mixed |
|
1238 | - */ |
|
1239 | - public function get_default() |
|
1240 | - { |
|
1241 | - return $this->_default; |
|
1242 | - } |
|
1243 | - |
|
1244 | - |
|
1245 | - |
|
1246 | - /** |
|
1247 | - * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"', |
|
1248 | - * and server-side if any input was received it will be ignored |
|
1249 | - */ |
|
1250 | - public function disable($disable = true) |
|
1251 | - { |
|
1252 | - $disabled_attribute = ' disabled="disabled"'; |
|
1253 | - $this->disabled = filter_var($disable, FILTER_VALIDATE_BOOLEAN); |
|
1254 | - if ($this->disabled) { |
|
1255 | - if (strpos($this->_other_html_attributes, $disabled_attribute) === false) { |
|
1256 | - $this->_other_html_attributes .= $disabled_attribute; |
|
1257 | - } |
|
1258 | - $this->_set_normalized_value($this->get_default()); |
|
1259 | - } else { |
|
1260 | - $this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes); |
|
1261 | - } |
|
1262 | - } |
|
1263 | - |
|
1264 | - |
|
1265 | - |
|
1266 | - /** |
|
1267 | - * Returns whether or not this input is currently disabled. |
|
1268 | - * @return bool |
|
1269 | - */ |
|
1270 | - public function isDisabled() |
|
1271 | - { |
|
1272 | - return $this->disabled; |
|
1273 | - } |
|
17 | + /** |
|
18 | + * the input's name attribute |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $_html_name; |
|
23 | + |
|
24 | + /** |
|
25 | + * id for the html label tag |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $_html_label_id; |
|
30 | + |
|
31 | + /** |
|
32 | + * class for teh html label tag |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $_html_label_class; |
|
37 | + |
|
38 | + /** |
|
39 | + * style for teh html label tag |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + protected $_html_label_style; |
|
44 | + |
|
45 | + /** |
|
46 | + * text to be placed in the html label |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + protected $_html_label_text; |
|
51 | + |
|
52 | + /** |
|
53 | + * the full html label. If used, all other html_label_* properties are invalid |
|
54 | + * |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + protected $_html_label; |
|
58 | + |
|
59 | + /** |
|
60 | + * HTML to use for help text (normally placed below form input), in a span which normally |
|
61 | + * has a class of 'description' |
|
62 | + * |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + protected $_html_help_text; |
|
66 | + |
|
67 | + /** |
|
68 | + * CSS classes for displaying the help span |
|
69 | + * |
|
70 | + * @var string |
|
71 | + */ |
|
72 | + protected $_html_help_class = 'description'; |
|
73 | + |
|
74 | + /** |
|
75 | + * CSS to put in the style attribute on the help span |
|
76 | + * |
|
77 | + * @var string |
|
78 | + */ |
|
79 | + protected $_html_help_style; |
|
80 | + |
|
81 | + /** |
|
82 | + * Stores whether or not this input's response is required. |
|
83 | + * Because certain styling elements may also want to know that this |
|
84 | + * input is required etc. |
|
85 | + * |
|
86 | + * @var boolean |
|
87 | + */ |
|
88 | + protected $_required; |
|
89 | + |
|
90 | + /** |
|
91 | + * css class added to required inputs |
|
92 | + * |
|
93 | + * @var string |
|
94 | + */ |
|
95 | + protected $_required_css_class = 'ee-required'; |
|
96 | + |
|
97 | + /** |
|
98 | + * css styles applied to button type inputs |
|
99 | + * |
|
100 | + * @var string |
|
101 | + */ |
|
102 | + protected $_button_css_attributes; |
|
103 | + |
|
104 | + /** |
|
105 | + * The raw post data submitted for this |
|
106 | + * Generally unsafe for usage in client code |
|
107 | + * |
|
108 | + * @var mixed string or array |
|
109 | + */ |
|
110 | + protected $_raw_value; |
|
111 | + |
|
112 | + /** |
|
113 | + * Value normalized according to the input's normalization strategy. |
|
114 | + * The normalization strategy dictates whether this is a string, int, float, |
|
115 | + * boolean, or array of any of those. |
|
116 | + * |
|
117 | + * @var mixed |
|
118 | + */ |
|
119 | + protected $_normalized_value; |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * Normalized default value either initially set on the input, or provided by calling |
|
124 | + * set_default(). |
|
125 | + * @var mixed |
|
126 | + */ |
|
127 | + protected $_default; |
|
128 | + |
|
129 | + /** |
|
130 | + * Strategy used for displaying this field. |
|
131 | + * Child classes must use _get_display_strategy to access it. |
|
132 | + * |
|
133 | + * @var EE_Display_Strategy_Base |
|
134 | + */ |
|
135 | + private $_display_strategy; |
|
136 | + |
|
137 | + /** |
|
138 | + * Gets all the validation strategies used on this field |
|
139 | + * |
|
140 | + * @var EE_Validation_Strategy_Base[] |
|
141 | + */ |
|
142 | + private $_validation_strategies = array(); |
|
143 | + |
|
144 | + /** |
|
145 | + * The normalization strategy for this field |
|
146 | + * |
|
147 | + * @var EE_Normalization_Strategy_Base |
|
148 | + */ |
|
149 | + private $_normalization_strategy; |
|
150 | + |
|
151 | + /** |
|
152 | + * Strategy for removing sensitive data after we're done with the form input |
|
153 | + * |
|
154 | + * @var EE_Sensitive_Data_Removal_Base |
|
155 | + */ |
|
156 | + protected $_sensitive_data_removal_strategy; |
|
157 | + |
|
158 | + /** |
|
159 | + * Whether this input has been disabled or not. |
|
160 | + * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled. |
|
161 | + * (Client-side code that wants to dynamically disable it must also add this hidden input). |
|
162 | + * When the form is submitted, if the input is disabled in the PHP form section, then input is ignored. |
|
163 | + * If the input is missing from the request data but the hidden input indicating the input is disabled, then the input is again ignored. |
|
164 | + * |
|
165 | + * @var boolean |
|
166 | + */ |
|
167 | + protected $disabled = false; |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param array $input_args { |
|
173 | + * @type string $html_name the html name for the input |
|
174 | + * @type string $html_label_id the id attribute to give to the html label tag |
|
175 | + * @type string $html_label_class the class attribute to give to the html label tag |
|
176 | + * @type string $html_label_style the style attribute to give ot teh label tag |
|
177 | + * @type string $html_label_text the text to put in the label tag |
|
178 | + * @type string $html_label the full html label. If used, |
|
179 | + * all other html_label_* args are invalid |
|
180 | + * @type string $html_help_text text to put in help element |
|
181 | + * @type string $html_help_style style attribute to give to teh help element |
|
182 | + * @type string $html_help_class class attribute to give to the help element |
|
183 | + * @type string $default default value NORMALIZED (eg, if providing the default |
|
184 | + * for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0') |
|
185 | + * @type EE_Display_Strategy_Base $display strategy |
|
186 | + * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
187 | + * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
188 | + * @type boolean $ignore_input special argument which can be used to avoid adding any validation strategies, |
|
189 | + * and sets the normalization strategy to the Null normalization. This is good |
|
190 | + * when you want the input to be totally ignored server-side (like when using |
|
191 | + * React.js form inputs) |
|
192 | + * } |
|
193 | + */ |
|
194 | + public function __construct($input_args = array()) |
|
195 | + { |
|
196 | + $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
197 | + // the following properties must be cast as arrays |
|
198 | + if (isset($input_args['validation_strategies'])) { |
|
199 | + foreach ((array) $input_args['validation_strategies'] as $validation_strategy) { |
|
200 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) { |
|
201 | + $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy; |
|
202 | + } |
|
203 | + } |
|
204 | + unset($input_args['validation_strategies']); |
|
205 | + } |
|
206 | + if (isset($input_args['ignore_input'])) { |
|
207 | + $this->_validation_strategies = array(); |
|
208 | + } |
|
209 | + // loop thru incoming options |
|
210 | + foreach ($input_args as $key => $value) { |
|
211 | + // add underscore to $key to match property names |
|
212 | + $_key = '_' . $key; |
|
213 | + if (property_exists($this, $_key)) { |
|
214 | + $this->{$_key} = $value; |
|
215 | + } |
|
216 | + } |
|
217 | + // ensure that "required" is set correctly |
|
218 | + $this->set_required( |
|
219 | + $this->_required, |
|
220 | + isset($input_args['required_validation_error_message']) |
|
221 | + ? $input_args['required_validation_error_message'] |
|
222 | + : null |
|
223 | + ); |
|
224 | + // $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
225 | + $this->_display_strategy->_construct_finalize($this); |
|
226 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
227 | + $validation_strategy->_construct_finalize($this); |
|
228 | + } |
|
229 | + if (isset($input_args['ignore_input'])) { |
|
230 | + $this->_normalization_strategy = new EE_Null_Normalization(); |
|
231 | + } |
|
232 | + if (! $this->_normalization_strategy) { |
|
233 | + $this->_normalization_strategy = new EE_Text_Normalization(); |
|
234 | + } |
|
235 | + $this->_normalization_strategy->_construct_finalize($this); |
|
236 | + // at least we can use the normalization strategy to populate the default |
|
237 | + if (isset($input_args['default'])) { |
|
238 | + $this->set_default($input_args['default']); |
|
239 | + unset($input_args['default']); |
|
240 | + } |
|
241 | + if (! $this->_sensitive_data_removal_strategy) { |
|
242 | + $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
243 | + } |
|
244 | + $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
245 | + parent::__construct($input_args); |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * Sets the html_name to its default value, if none was specified in teh constructor. |
|
252 | + * Calculation involves using the name and the parent's html_name |
|
253 | + * |
|
254 | + * @throws EE_Error |
|
255 | + */ |
|
256 | + protected function _set_default_html_name_if_empty() |
|
257 | + { |
|
258 | + if (! $this->_html_name) { |
|
259 | + $this->_html_name = $this->name(); |
|
260 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
261 | + $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
262 | + } |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * @param $parent_form_section |
|
270 | + * @param $name |
|
271 | + * @throws EE_Error |
|
272 | + */ |
|
273 | + public function _construct_finalize($parent_form_section, $name) |
|
274 | + { |
|
275 | + parent::_construct_finalize($parent_form_section, $name); |
|
276 | + if ($this->_html_label === null && $this->_html_label_text === null) { |
|
277 | + $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
278 | + } |
|
279 | + do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
286 | + * |
|
287 | + * @return EE_Display_Strategy_Base |
|
288 | + * @throws EE_Error |
|
289 | + */ |
|
290 | + protected function _get_display_strategy() |
|
291 | + { |
|
292 | + $this->ensure_construct_finalized_called(); |
|
293 | + if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
294 | + throw new EE_Error( |
|
295 | + sprintf( |
|
296 | + esc_html__( |
|
297 | + "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
298 | + "event_espresso" |
|
299 | + ), |
|
300 | + $this->html_name(), |
|
301 | + $this->html_id() |
|
302 | + ) |
|
303 | + ); |
|
304 | + } else { |
|
305 | + return $this->_display_strategy; |
|
306 | + } |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * Sets the display strategy. |
|
313 | + * |
|
314 | + * @param EE_Display_Strategy_Base $strategy |
|
315 | + */ |
|
316 | + protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
317 | + { |
|
318 | + $this->_display_strategy = $strategy; |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * Sets the sanitization strategy |
|
325 | + * |
|
326 | + * @param EE_Normalization_Strategy_Base $strategy |
|
327 | + */ |
|
328 | + protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
329 | + { |
|
330 | + $this->_normalization_strategy = $strategy; |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * Gets sensitive_data_removal_strategy |
|
337 | + * |
|
338 | + * @return EE_Sensitive_Data_Removal_Base |
|
339 | + */ |
|
340 | + public function get_sensitive_data_removal_strategy() |
|
341 | + { |
|
342 | + return $this->_sensitive_data_removal_strategy; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Sets sensitive_data_removal_strategy |
|
349 | + * |
|
350 | + * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
351 | + * @return void |
|
352 | + */ |
|
353 | + public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
354 | + { |
|
355 | + $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * Gets the display strategy for this input |
|
362 | + * |
|
363 | + * @return EE_Display_Strategy_Base |
|
364 | + */ |
|
365 | + public function get_display_strategy() |
|
366 | + { |
|
367 | + return $this->_display_strategy; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Overwrites the display strategy |
|
374 | + * |
|
375 | + * @param EE_Display_Strategy_Base $display_strategy |
|
376 | + */ |
|
377 | + public function set_display_strategy($display_strategy) |
|
378 | + { |
|
379 | + $this->_display_strategy = $display_strategy; |
|
380 | + $this->_display_strategy->_construct_finalize($this); |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * Gets the normalization strategy set on this input |
|
387 | + * |
|
388 | + * @return EE_Normalization_Strategy_Base |
|
389 | + */ |
|
390 | + public function get_normalization_strategy() |
|
391 | + { |
|
392 | + return $this->_normalization_strategy; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * Overwrites the normalization strategy |
|
399 | + * |
|
400 | + * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
401 | + */ |
|
402 | + public function set_normalization_strategy($normalization_strategy) |
|
403 | + { |
|
404 | + $this->_normalization_strategy = $normalization_strategy; |
|
405 | + $this->_normalization_strategy->_construct_finalize($this); |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * Returns all teh validation strategies which apply to this field, numerically indexed |
|
412 | + * |
|
413 | + * @return EE_Validation_Strategy_Base[] |
|
414 | + */ |
|
415 | + public function get_validation_strategies() |
|
416 | + { |
|
417 | + return $this->_validation_strategies; |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
424 | + * |
|
425 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
426 | + * @return void |
|
427 | + */ |
|
428 | + protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
429 | + { |
|
430 | + $validation_strategy->_construct_finalize($this); |
|
431 | + $this->_validation_strategies[] = $validation_strategy; |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Adds a new validation strategy onto the form input |
|
438 | + * |
|
439 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
440 | + * @return void |
|
441 | + */ |
|
442 | + public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
443 | + { |
|
444 | + $this->_add_validation_strategy($validation_strategy); |
|
445 | + } |
|
446 | + |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * The classname of the validation strategy to remove |
|
451 | + * |
|
452 | + * @param string $validation_strategy_classname |
|
453 | + */ |
|
454 | + public function remove_validation_strategy($validation_strategy_classname) |
|
455 | + { |
|
456 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
457 | + if ( |
|
458 | + $validation_strategy instanceof $validation_strategy_classname |
|
459 | + || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
460 | + ) { |
|
461 | + unset($this->_validation_strategies[ $key ]); |
|
462 | + } |
|
463 | + } |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
470 | + * |
|
471 | + * @param array $validation_strategy_classnames |
|
472 | + * @return bool |
|
473 | + */ |
|
474 | + public function has_validation_strategy($validation_strategy_classnames) |
|
475 | + { |
|
476 | + $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
477 | + ? $validation_strategy_classnames |
|
478 | + : array($validation_strategy_classnames); |
|
479 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
480 | + if (in_array($key, $validation_strategy_classnames)) { |
|
481 | + return true; |
|
482 | + } |
|
483 | + } |
|
484 | + return false; |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * Gets the HTML |
|
491 | + * |
|
492 | + * @return string |
|
493 | + */ |
|
494 | + public function get_html() |
|
495 | + { |
|
496 | + return $this->_parent_section->get_html_for_input($this); |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * Gets the HTML for the input itself (no label or errors) according to the |
|
503 | + * input's display strategy |
|
504 | + * Makes sure the JS and CSS are enqueued for it |
|
505 | + * |
|
506 | + * @return string |
|
507 | + * @throws EE_Error |
|
508 | + */ |
|
509 | + public function get_html_for_input() |
|
510 | + { |
|
511 | + return $this->_form_html_filter |
|
512 | + ? $this->_form_html_filter->filterHtml( |
|
513 | + $this->_get_display_strategy()->display(), |
|
514 | + $this |
|
515 | + ) |
|
516 | + : $this->_get_display_strategy()->display(); |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + |
|
521 | + /** |
|
522 | + * @return string |
|
523 | + */ |
|
524 | + public function html_other_attributes() |
|
525 | + { |
|
526 | + EE_Error::doing_it_wrong( |
|
527 | + __METHOD__, |
|
528 | + sprintf( |
|
529 | + esc_html__( |
|
530 | + 'This method is no longer in use. You should replace it by %s', |
|
531 | + 'event_espresso' |
|
532 | + ), |
|
533 | + 'EE_Form_Section_Base::other_html_attributes()' |
|
534 | + ), |
|
535 | + '4.10.2.p' |
|
536 | + ); |
|
537 | + |
|
538 | + return $this->other_html_attributes(); |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * @param string $html_other_attributes |
|
545 | + */ |
|
546 | + public function set_html_other_attributes($html_other_attributes) |
|
547 | + { |
|
548 | + EE_Error::doing_it_wrong( |
|
549 | + __METHOD__, |
|
550 | + sprintf( |
|
551 | + esc_html__( |
|
552 | + 'This method is no longer in use. You should replace it by %s', |
|
553 | + 'event_espresso' |
|
554 | + ), |
|
555 | + 'EE_Form_Section_Base::set_other_html_attributes()' |
|
556 | + ), |
|
557 | + '4.10.2.p' |
|
558 | + ); |
|
559 | + |
|
560 | + $this->set_other_html_attributes($html_other_attributes); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * Gets the HTML for displaying the label for this form input |
|
567 | + * according to the form section's layout strategy |
|
568 | + * |
|
569 | + * @return string |
|
570 | + */ |
|
571 | + public function get_html_for_label() |
|
572 | + { |
|
573 | + return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * Gets the HTML for displaying the errors section for this form input |
|
580 | + * according to the form section's layout strategy |
|
581 | + * |
|
582 | + * @return string |
|
583 | + */ |
|
584 | + public function get_html_for_errors() |
|
585 | + { |
|
586 | + return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
587 | + } |
|
588 | + |
|
589 | + |
|
590 | + |
|
591 | + /** |
|
592 | + * Gets the HTML for displaying the help text for this form input |
|
593 | + * according to the form section's layout strategy |
|
594 | + * |
|
595 | + * @return string |
|
596 | + */ |
|
597 | + public function get_html_for_help() |
|
598 | + { |
|
599 | + return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
600 | + } |
|
601 | + |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
606 | + * and returns whether or not the form input's submitted value is value |
|
607 | + * |
|
608 | + * @return boolean |
|
609 | + */ |
|
610 | + protected function _validate() |
|
611 | + { |
|
612 | + if ($this->isDisabled()) { |
|
613 | + return true; |
|
614 | + } |
|
615 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
616 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
617 | + try { |
|
618 | + $validation_strategy->validate($this->normalized_value()); |
|
619 | + } catch (EE_Validation_Error $e) { |
|
620 | + $this->add_validation_error($e); |
|
621 | + } |
|
622 | + } |
|
623 | + } |
|
624 | + if ($this->get_validation_errors()) { |
|
625 | + return false; |
|
626 | + } else { |
|
627 | + return true; |
|
628 | + } |
|
629 | + } |
|
630 | + |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
635 | + * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
636 | + * |
|
637 | + * @param string $value |
|
638 | + * @return null|string |
|
639 | + */ |
|
640 | + protected function _sanitize($value) |
|
641 | + { |
|
642 | + return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
643 | + } |
|
644 | + |
|
645 | + |
|
646 | + |
|
647 | + /** |
|
648 | + * Picks out the form value that relates to this form input, |
|
649 | + * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
650 | + * Returns whether or not any validation errors occurred |
|
651 | + * |
|
652 | + * @param array $req_data |
|
653 | + * @return boolean whether or not there was an error |
|
654 | + * @throws EE_Error |
|
655 | + */ |
|
656 | + protected function _normalize($req_data) |
|
657 | + { |
|
658 | + // any existing validation errors don't apply so clear them |
|
659 | + $this->_validation_errors = array(); |
|
660 | + // if the input is disabled, ignore whatever input was sent in |
|
661 | + if ($this->isDisabled()) { |
|
662 | + $this->_set_raw_value(null); |
|
663 | + $this->_set_normalized_value($this->get_default()); |
|
664 | + return false; |
|
665 | + } |
|
666 | + try { |
|
667 | + $raw_input = $this->find_form_data_for_this_section($req_data); |
|
668 | + // super simple sanitization for now |
|
669 | + if (is_array($raw_input)) { |
|
670 | + $raw_value = array(); |
|
671 | + foreach ($raw_input as $key => $value) { |
|
672 | + $raw_value[ $key ] = $this->_sanitize($value); |
|
673 | + } |
|
674 | + $this->_set_raw_value($raw_value); |
|
675 | + } else { |
|
676 | + $this->_set_raw_value($this->_sanitize($raw_input)); |
|
677 | + } |
|
678 | + // we want to mostly leave the input alone in case we need to re-display it to the user |
|
679 | + $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
680 | + return false; |
|
681 | + } catch (EE_Validation_Error $e) { |
|
682 | + $this->add_validation_error($e); |
|
683 | + return true; |
|
684 | + } |
|
685 | + } |
|
686 | + |
|
687 | + |
|
688 | + /** |
|
689 | + * @return string |
|
690 | + * @throws EE_Error |
|
691 | + */ |
|
692 | + public function html_name() |
|
693 | + { |
|
694 | + $this->_set_default_html_name_if_empty(); |
|
695 | + return $this->_html_name; |
|
696 | + } |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * @return string |
|
701 | + * @throws EE_Error |
|
702 | + */ |
|
703 | + public function html_label_id() |
|
704 | + { |
|
705 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl'; |
|
706 | + } |
|
707 | + |
|
708 | + |
|
709 | + |
|
710 | + /** |
|
711 | + * @return string |
|
712 | + */ |
|
713 | + public function html_label_class() |
|
714 | + { |
|
715 | + return $this->_html_label_class; |
|
716 | + } |
|
717 | + |
|
718 | + |
|
719 | + |
|
720 | + /** |
|
721 | + * @return string |
|
722 | + */ |
|
723 | + public function html_label_style() |
|
724 | + { |
|
725 | + return $this->_html_label_style; |
|
726 | + } |
|
727 | + |
|
728 | + |
|
729 | + |
|
730 | + /** |
|
731 | + * @return string |
|
732 | + */ |
|
733 | + public function html_label_text() |
|
734 | + { |
|
735 | + return $this->_html_label_text; |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * @return string |
|
742 | + */ |
|
743 | + public function html_help_text() |
|
744 | + { |
|
745 | + return $this->_html_help_text; |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + |
|
750 | + /** |
|
751 | + * @return string |
|
752 | + */ |
|
753 | + public function html_help_class() |
|
754 | + { |
|
755 | + return $this->_html_help_class; |
|
756 | + } |
|
757 | + |
|
758 | + |
|
759 | + |
|
760 | + /** |
|
761 | + * @return string |
|
762 | + */ |
|
763 | + public function html_help_style() |
|
764 | + { |
|
765 | + return $this->_html_style; |
|
766 | + } |
|
767 | + |
|
768 | + |
|
769 | + |
|
770 | + /** |
|
771 | + * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
772 | + * Please note that almost all client code should instead use the normalized_value; |
|
773 | + * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
774 | + * mostly by escaping quotes) |
|
775 | + * Note, we do not store the exact original value sent in the user's request because |
|
776 | + * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
777 | + * in which case, we would have stored the malicious content to our database. |
|
778 | + * |
|
779 | + * @return string |
|
780 | + */ |
|
781 | + public function raw_value() |
|
782 | + { |
|
783 | + return $this->_raw_value; |
|
784 | + } |
|
785 | + |
|
786 | + |
|
787 | + |
|
788 | + /** |
|
789 | + * Returns a string safe to usage in form inputs when displaying, because |
|
790 | + * it escapes all html entities |
|
791 | + * |
|
792 | + * @return string |
|
793 | + */ |
|
794 | + public function raw_value_in_form() |
|
795 | + { |
|
796 | + return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
797 | + } |
|
798 | + |
|
799 | + |
|
800 | + |
|
801 | + /** |
|
802 | + * returns the value after it's been sanitized, and then converted into it's proper type |
|
803 | + * in PHP. Eg, a string, an int, an array, |
|
804 | + * |
|
805 | + * @return mixed |
|
806 | + */ |
|
807 | + public function normalized_value() |
|
808 | + { |
|
809 | + return $this->_normalized_value; |
|
810 | + } |
|
811 | + |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * Returns the normalized value is a presentable way. By default this is just |
|
816 | + * the normalized value by itself, but it can be overridden for when that's not |
|
817 | + * the best thing to display |
|
818 | + * |
|
819 | + * @return string |
|
820 | + */ |
|
821 | + public function pretty_value() |
|
822 | + { |
|
823 | + return $this->_normalized_value; |
|
824 | + } |
|
825 | + |
|
826 | + |
|
827 | + |
|
828 | + /** |
|
829 | + * When generating the JS for the jquery validation rules like<br> |
|
830 | + * <code>$( "#myform" ).validate({ |
|
831 | + * rules: { |
|
832 | + * password: "required", |
|
833 | + * password_again: { |
|
834 | + * equalTo: "#password" |
|
835 | + * } |
|
836 | + * } |
|
837 | + * });</code> |
|
838 | + * if this field had the name 'password_again', it should return |
|
839 | + * <br><code>password_again: { |
|
840 | + * equalTo: "#password" |
|
841 | + * }</code> |
|
842 | + * |
|
843 | + * @return array |
|
844 | + */ |
|
845 | + public function get_jquery_validation_rules() |
|
846 | + { |
|
847 | + $jquery_validation_js = array(); |
|
848 | + $jquery_validation_rules = array(); |
|
849 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
850 | + $jquery_validation_rules = array_replace_recursive( |
|
851 | + $jquery_validation_rules, |
|
852 | + $validation_strategy->get_jquery_validation_rule_array() |
|
853 | + ); |
|
854 | + } |
|
855 | + if (! empty($jquery_validation_rules)) { |
|
856 | + foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
857 | + $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules; |
|
858 | + } |
|
859 | + } |
|
860 | + return $jquery_validation_js; |
|
861 | + } |
|
862 | + |
|
863 | + |
|
864 | + |
|
865 | + /** |
|
866 | + * Sets the input's default value for use in displaying in the form. Note: value should be |
|
867 | + * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
868 | + * |
|
869 | + * @param mixed $value |
|
870 | + * @return void |
|
871 | + */ |
|
872 | + public function set_default($value) |
|
873 | + { |
|
874 | + $this->_default = $value; |
|
875 | + $this->_set_normalized_value($value); |
|
876 | + $this->_set_raw_value($value); |
|
877 | + } |
|
878 | + |
|
879 | + |
|
880 | + |
|
881 | + /** |
|
882 | + * Sets the normalized value on this input |
|
883 | + * |
|
884 | + * @param mixed $value |
|
885 | + */ |
|
886 | + protected function _set_normalized_value($value) |
|
887 | + { |
|
888 | + $this->_normalized_value = $value; |
|
889 | + } |
|
890 | + |
|
891 | + |
|
892 | + |
|
893 | + /** |
|
894 | + * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
895 | + * |
|
896 | + * @param mixed $value |
|
897 | + */ |
|
898 | + protected function _set_raw_value($value) |
|
899 | + { |
|
900 | + $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
901 | + } |
|
902 | + |
|
903 | + |
|
904 | + |
|
905 | + /** |
|
906 | + * Sets the HTML label text after it has already been defined |
|
907 | + * |
|
908 | + * @param string $label |
|
909 | + * @return void |
|
910 | + */ |
|
911 | + public function set_html_label_text($label) |
|
912 | + { |
|
913 | + $this->_html_label_text = $label; |
|
914 | + } |
|
915 | + |
|
916 | + |
|
917 | + |
|
918 | + /** |
|
919 | + * Sets whether or not this field is required, and adjusts the validation strategy. |
|
920 | + * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
921 | + * please add it as a validation strategy using add_validation_strategy as normal |
|
922 | + * |
|
923 | + * @param boolean $required boolean |
|
924 | + * @param null $required_text |
|
925 | + */ |
|
926 | + public function set_required($required = true, $required_text = null) |
|
927 | + { |
|
928 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
929 | + // whether $required is a string or a boolean, we want to add a required validation strategy |
|
930 | + if ($required) { |
|
931 | + $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
932 | + } else { |
|
933 | + $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
934 | + } |
|
935 | + $this->_required = $required; |
|
936 | + } |
|
937 | + |
|
938 | + |
|
939 | + |
|
940 | + /** |
|
941 | + * Returns whether or not this field is required |
|
942 | + * |
|
943 | + * @return boolean |
|
944 | + */ |
|
945 | + public function required() |
|
946 | + { |
|
947 | + return $this->_required; |
|
948 | + } |
|
949 | + |
|
950 | + |
|
951 | + |
|
952 | + /** |
|
953 | + * @param string $required_css_class |
|
954 | + */ |
|
955 | + public function set_required_css_class($required_css_class) |
|
956 | + { |
|
957 | + $this->_required_css_class = $required_css_class; |
|
958 | + } |
|
959 | + |
|
960 | + |
|
961 | + |
|
962 | + /** |
|
963 | + * @return string |
|
964 | + */ |
|
965 | + public function required_css_class() |
|
966 | + { |
|
967 | + return $this->_required_css_class; |
|
968 | + } |
|
969 | + |
|
970 | + |
|
971 | + |
|
972 | + /** |
|
973 | + * @param bool $add_required |
|
974 | + * @return string |
|
975 | + */ |
|
976 | + public function html_class($add_required = false) |
|
977 | + { |
|
978 | + return $add_required && $this->required() |
|
979 | + ? $this->required_css_class() . ' ' . $this->_html_class |
|
980 | + : $this->_html_class; |
|
981 | + } |
|
982 | + |
|
983 | + |
|
984 | + /** |
|
985 | + * Sets the help text, in case |
|
986 | + * |
|
987 | + * @param string $text |
|
988 | + */ |
|
989 | + public function set_html_help_text($text) |
|
990 | + { |
|
991 | + $this->_html_help_text = $text; |
|
992 | + } |
|
993 | + |
|
994 | + |
|
995 | + |
|
996 | + /** |
|
997 | + * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
998 | + * input. If there is any kind of sensitive data removal on this input, we clear |
|
999 | + * out the raw value completely |
|
1000 | + * |
|
1001 | + * @return void |
|
1002 | + */ |
|
1003 | + public function clean_sensitive_data() |
|
1004 | + { |
|
1005 | + // if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
1006 | + // if we need more logic than this we'll make a strategy for it |
|
1007 | + if ( |
|
1008 | + $this->_sensitive_data_removal_strategy |
|
1009 | + && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
1010 | + ) { |
|
1011 | + $this->_set_raw_value(null); |
|
1012 | + } |
|
1013 | + // and clean the normalized value according to the appropriate strategy |
|
1014 | + $this->_set_normalized_value( |
|
1015 | + $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
1016 | + $this->_normalized_value |
|
1017 | + ) |
|
1018 | + ); |
|
1019 | + } |
|
1020 | + |
|
1021 | + |
|
1022 | + |
|
1023 | + /** |
|
1024 | + * @param bool $primary |
|
1025 | + * @param string $button_size |
|
1026 | + * @param string $other_attributes |
|
1027 | + */ |
|
1028 | + public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
1029 | + { |
|
1030 | + $button_css_attributes = 'button'; |
|
1031 | + $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary'; |
|
1032 | + switch ($button_size) { |
|
1033 | + case 'xs': |
|
1034 | + case 'extra-small': |
|
1035 | + $button_css_attributes .= ' button-xs'; |
|
1036 | + break; |
|
1037 | + case 'sm': |
|
1038 | + case 'small': |
|
1039 | + $button_css_attributes .= ' button-sm'; |
|
1040 | + break; |
|
1041 | + case 'lg': |
|
1042 | + case 'large': |
|
1043 | + $button_css_attributes .= ' button-lg'; |
|
1044 | + break; |
|
1045 | + case 'block': |
|
1046 | + $button_css_attributes .= ' button-block'; |
|
1047 | + break; |
|
1048 | + case 'md': |
|
1049 | + case 'medium': |
|
1050 | + default: |
|
1051 | + $button_css_attributes .= ''; |
|
1052 | + } |
|
1053 | + $this->_button_css_attributes .= ! empty($other_attributes) |
|
1054 | + ? $button_css_attributes . ' ' . $other_attributes |
|
1055 | + : $button_css_attributes; |
|
1056 | + } |
|
1057 | + |
|
1058 | + |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * @return string |
|
1062 | + */ |
|
1063 | + public function button_css_attributes() |
|
1064 | + { |
|
1065 | + if (empty($this->_button_css_attributes)) { |
|
1066 | + $this->set_button_css_attributes(); |
|
1067 | + } |
|
1068 | + return $this->_button_css_attributes; |
|
1069 | + } |
|
1070 | + |
|
1071 | + |
|
1072 | + |
|
1073 | + /** |
|
1074 | + * find_form_data_for_this_section |
|
1075 | + * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
1076 | + * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
1077 | + * then it's value should be in request at request['my_form']['subform']['form_input_1']. |
|
1078 | + * (If that doesn't exist, we also check for this subsection's name |
|
1079 | + * at the TOP LEVEL of the request data. Eg request['form_input_1'].) |
|
1080 | + * This function finds its value in the form. |
|
1081 | + * |
|
1082 | + * @param array $req_data |
|
1083 | + * @return mixed whatever the raw value of this form section is in the request data |
|
1084 | + * @throws EE_Error |
|
1085 | + */ |
|
1086 | + public function find_form_data_for_this_section($req_data) |
|
1087 | + { |
|
1088 | + $name_parts = $this->getInputNameParts(); |
|
1089 | + // now get the value for the input |
|
1090 | + $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data); |
|
1091 | + // check if this thing's name is at the TOP level of the request data |
|
1092 | + if ($value === null && isset($req_data[ $this->name() ])) { |
|
1093 | + $value = $req_data[ $this->name() ]; |
|
1094 | + } |
|
1095 | + return $value; |
|
1096 | + } |
|
1097 | + |
|
1098 | + |
|
1099 | + /** |
|
1100 | + * If this input's name is something like "foo[bar][baz]" |
|
1101 | + * returns an array like `array('foo','bar',baz')` |
|
1102 | + * |
|
1103 | + * @return array |
|
1104 | + * @throws EE_Error |
|
1105 | + */ |
|
1106 | + protected function getInputNameParts() |
|
1107 | + { |
|
1108 | + // break up the html name by "[]" |
|
1109 | + if (strpos($this->html_name(), '[') !== false) { |
|
1110 | + $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
1111 | + } else { |
|
1112 | + $before_any_brackets = $this->html_name(); |
|
1113 | + } |
|
1114 | + // grab all of the segments |
|
1115 | + preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
1116 | + if (isset($matches[1]) && is_array($matches[1])) { |
|
1117 | + $name_parts = $matches[1]; |
|
1118 | + array_unshift($name_parts, $before_any_brackets); |
|
1119 | + } else { |
|
1120 | + $name_parts = array($before_any_brackets); |
|
1121 | + } |
|
1122 | + return $name_parts; |
|
1123 | + } |
|
1124 | + |
|
1125 | + |
|
1126 | + |
|
1127 | + /** |
|
1128 | + * @param array $html_name_parts |
|
1129 | + * @param array $req_data |
|
1130 | + * @return array | NULL |
|
1131 | + */ |
|
1132 | + public function findRequestForSectionUsingNameParts($html_name_parts, $req_data) |
|
1133 | + { |
|
1134 | + $first_part_to_consider = array_shift($html_name_parts); |
|
1135 | + if (isset($req_data[ $first_part_to_consider ])) { |
|
1136 | + if (empty($html_name_parts)) { |
|
1137 | + return $req_data[ $first_part_to_consider ]; |
|
1138 | + } else { |
|
1139 | + return $this->findRequestForSectionUsingNameParts( |
|
1140 | + $html_name_parts, |
|
1141 | + $req_data[ $first_part_to_consider ] |
|
1142 | + ); |
|
1143 | + } |
|
1144 | + } else { |
|
1145 | + return null; |
|
1146 | + } |
|
1147 | + } |
|
1148 | + |
|
1149 | + |
|
1150 | + |
|
1151 | + /** |
|
1152 | + * Checks if this form input's data is in the request data |
|
1153 | + * |
|
1154 | + * @param array $req_data |
|
1155 | + * @return boolean |
|
1156 | + * @throws EE_Error |
|
1157 | + */ |
|
1158 | + public function form_data_present_in($req_data = null) |
|
1159 | + { |
|
1160 | + if ($req_data === null) { |
|
1161 | + /** @var RequestInterface $request */ |
|
1162 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
1163 | + $req_data = $request->postParams(); |
|
1164 | + } |
|
1165 | + $checked_value = $this->find_form_data_for_this_section($req_data); |
|
1166 | + if ($checked_value !== null) { |
|
1167 | + return true; |
|
1168 | + } else { |
|
1169 | + return false; |
|
1170 | + } |
|
1171 | + } |
|
1172 | + |
|
1173 | + |
|
1174 | + |
|
1175 | + /** |
|
1176 | + * Overrides parent to add js data from validation and display strategies |
|
1177 | + * |
|
1178 | + * @param array $form_other_js_data |
|
1179 | + * @return array |
|
1180 | + */ |
|
1181 | + public function get_other_js_data($form_other_js_data = array()) |
|
1182 | + { |
|
1183 | + return $this->get_other_js_data_from_strategies($form_other_js_data); |
|
1184 | + } |
|
1185 | + |
|
1186 | + |
|
1187 | + |
|
1188 | + /** |
|
1189 | + * Gets other JS data for localization from this input's strategies, like |
|
1190 | + * the validation strategies and the display strategy |
|
1191 | + * |
|
1192 | + * @param array $form_other_js_data |
|
1193 | + * @return array |
|
1194 | + */ |
|
1195 | + public function get_other_js_data_from_strategies($form_other_js_data = array()) |
|
1196 | + { |
|
1197 | + $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
1198 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1199 | + $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
1200 | + } |
|
1201 | + return $form_other_js_data; |
|
1202 | + } |
|
1203 | + |
|
1204 | + |
|
1205 | + |
|
1206 | + /** |
|
1207 | + * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
1208 | + * |
|
1209 | + * @return void |
|
1210 | + */ |
|
1211 | + public function enqueue_js() |
|
1212 | + { |
|
1213 | + // ask our display strategy and validation strategies if they have js to enqueue |
|
1214 | + $this->enqueue_js_from_strategies(); |
|
1215 | + } |
|
1216 | + |
|
1217 | + |
|
1218 | + |
|
1219 | + /** |
|
1220 | + * Tells strategies when its ok to enqueue their js and css |
|
1221 | + * |
|
1222 | + * @return void |
|
1223 | + */ |
|
1224 | + public function enqueue_js_from_strategies() |
|
1225 | + { |
|
1226 | + $this->get_display_strategy()->enqueue_js(); |
|
1227 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1228 | + $validation_strategy->enqueue_js(); |
|
1229 | + } |
|
1230 | + } |
|
1231 | + |
|
1232 | + |
|
1233 | + |
|
1234 | + /** |
|
1235 | + * Gets the default value set on the input (not the current value, which may have been |
|
1236 | + * changed because of a form submission). If no default was set, this us null. |
|
1237 | + * @return mixed |
|
1238 | + */ |
|
1239 | + public function get_default() |
|
1240 | + { |
|
1241 | + return $this->_default; |
|
1242 | + } |
|
1243 | + |
|
1244 | + |
|
1245 | + |
|
1246 | + /** |
|
1247 | + * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"', |
|
1248 | + * and server-side if any input was received it will be ignored |
|
1249 | + */ |
|
1250 | + public function disable($disable = true) |
|
1251 | + { |
|
1252 | + $disabled_attribute = ' disabled="disabled"'; |
|
1253 | + $this->disabled = filter_var($disable, FILTER_VALIDATE_BOOLEAN); |
|
1254 | + if ($this->disabled) { |
|
1255 | + if (strpos($this->_other_html_attributes, $disabled_attribute) === false) { |
|
1256 | + $this->_other_html_attributes .= $disabled_attribute; |
|
1257 | + } |
|
1258 | + $this->_set_normalized_value($this->get_default()); |
|
1259 | + } else { |
|
1260 | + $this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes); |
|
1261 | + } |
|
1262 | + } |
|
1263 | + |
|
1264 | + |
|
1265 | + |
|
1266 | + /** |
|
1267 | + * Returns whether or not this input is currently disabled. |
|
1268 | + * @return bool |
|
1269 | + */ |
|
1270 | + public function isDisabled() |
|
1271 | + { |
|
1272 | + return $this->disabled; |
|
1273 | + } |
|
1274 | 1274 | } |
@@ -42,519 +42,519 @@ discard block |
||
42 | 42 | */ |
43 | 43 | class ClassLoader |
44 | 44 | { |
45 | - /** @var ?string */ |
|
46 | - private $vendorDir; |
|
47 | - |
|
48 | - // PSR-4 |
|
49 | - /** |
|
50 | - * @var array[] |
|
51 | - * @psalm-var array<string, array<string, int>> |
|
52 | - */ |
|
53 | - private $prefixLengthsPsr4 = array(); |
|
54 | - /** |
|
55 | - * @var array[] |
|
56 | - * @psalm-var array<string, array<int, string>> |
|
57 | - */ |
|
58 | - private $prefixDirsPsr4 = array(); |
|
59 | - /** |
|
60 | - * @var array[] |
|
61 | - * @psalm-var array<string, string> |
|
62 | - */ |
|
63 | - private $fallbackDirsPsr4 = array(); |
|
64 | - |
|
65 | - // PSR-0 |
|
66 | - /** |
|
67 | - * @var array[] |
|
68 | - * @psalm-var array<string, array<string, string[]>> |
|
69 | - */ |
|
70 | - private $prefixesPsr0 = array(); |
|
71 | - /** |
|
72 | - * @var array[] |
|
73 | - * @psalm-var array<string, string> |
|
74 | - */ |
|
75 | - private $fallbackDirsPsr0 = array(); |
|
76 | - |
|
77 | - /** @var bool */ |
|
78 | - private $useIncludePath = false; |
|
79 | - |
|
80 | - /** |
|
81 | - * @var string[] |
|
82 | - * @psalm-var array<string, string> |
|
83 | - */ |
|
84 | - private $classMap = array(); |
|
85 | - |
|
86 | - /** @var bool */ |
|
87 | - private $classMapAuthoritative = false; |
|
88 | - |
|
89 | - /** |
|
90 | - * @var bool[] |
|
91 | - * @psalm-var array<string, bool> |
|
92 | - */ |
|
93 | - private $missingClasses = array(); |
|
94 | - |
|
95 | - /** @var ?string */ |
|
96 | - private $apcuPrefix; |
|
97 | - |
|
98 | - /** |
|
99 | - * @var self[] |
|
100 | - */ |
|
101 | - private static $registeredLoaders = array(); |
|
102 | - |
|
103 | - /** |
|
104 | - * @param ?string $vendorDir |
|
105 | - */ |
|
106 | - public function __construct($vendorDir = null) |
|
107 | - { |
|
108 | - $this->vendorDir = $vendorDir; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @return string[] |
|
113 | - */ |
|
114 | - public function getPrefixes() |
|
115 | - { |
|
116 | - if (!empty($this->prefixesPsr0)) { |
|
117 | - return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); |
|
118 | - } |
|
119 | - |
|
120 | - return array(); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @return array[] |
|
125 | - * @psalm-return array<string, array<int, string>> |
|
126 | - */ |
|
127 | - public function getPrefixesPsr4() |
|
128 | - { |
|
129 | - return $this->prefixDirsPsr4; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @return array[] |
|
134 | - * @psalm-return array<string, string> |
|
135 | - */ |
|
136 | - public function getFallbackDirs() |
|
137 | - { |
|
138 | - return $this->fallbackDirsPsr0; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @return array[] |
|
143 | - * @psalm-return array<string, string> |
|
144 | - */ |
|
145 | - public function getFallbackDirsPsr4() |
|
146 | - { |
|
147 | - return $this->fallbackDirsPsr4; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return string[] Array of classname => path |
|
152 | - * @psalm-return array<string, string> |
|
153 | - */ |
|
154 | - public function getClassMap() |
|
155 | - { |
|
156 | - return $this->classMap; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @param string[] $classMap Class to filename map |
|
161 | - * @psalm-param array<string, string> $classMap |
|
162 | - * |
|
163 | - * @return void |
|
164 | - */ |
|
165 | - public function addClassMap(array $classMap) |
|
166 | - { |
|
167 | - if ($this->classMap) { |
|
168 | - $this->classMap = array_merge($this->classMap, $classMap); |
|
169 | - } else { |
|
170 | - $this->classMap = $classMap; |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Registers a set of PSR-0 directories for a given prefix, either |
|
176 | - * appending or prepending to the ones previously set for this prefix. |
|
177 | - * |
|
178 | - * @param string $prefix The prefix |
|
179 | - * @param string[]|string $paths The PSR-0 root directories |
|
180 | - * @param bool $prepend Whether to prepend the directories |
|
181 | - * |
|
182 | - * @return void |
|
183 | - */ |
|
184 | - public function add($prefix, $paths, $prepend = false) |
|
185 | - { |
|
186 | - if (!$prefix) { |
|
187 | - if ($prepend) { |
|
188 | - $this->fallbackDirsPsr0 = array_merge( |
|
189 | - (array) $paths, |
|
190 | - $this->fallbackDirsPsr0 |
|
191 | - ); |
|
192 | - } else { |
|
193 | - $this->fallbackDirsPsr0 = array_merge( |
|
194 | - $this->fallbackDirsPsr0, |
|
195 | - (array) $paths |
|
196 | - ); |
|
197 | - } |
|
198 | - |
|
199 | - return; |
|
200 | - } |
|
201 | - |
|
202 | - $first = $prefix[0]; |
|
203 | - if (!isset($this->prefixesPsr0[$first][$prefix])) { |
|
204 | - $this->prefixesPsr0[$first][$prefix] = (array) $paths; |
|
205 | - |
|
206 | - return; |
|
207 | - } |
|
208 | - if ($prepend) { |
|
209 | - $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
210 | - (array) $paths, |
|
211 | - $this->prefixesPsr0[$first][$prefix] |
|
212 | - ); |
|
213 | - } else { |
|
214 | - $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
215 | - $this->prefixesPsr0[$first][$prefix], |
|
216 | - (array) $paths |
|
217 | - ); |
|
218 | - } |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Registers a set of PSR-4 directories for a given namespace, either |
|
223 | - * appending or prepending to the ones previously set for this namespace. |
|
224 | - * |
|
225 | - * @param string $prefix The prefix/namespace, with trailing '\\' |
|
226 | - * @param string[]|string $paths The PSR-4 base directories |
|
227 | - * @param bool $prepend Whether to prepend the directories |
|
228 | - * |
|
229 | - * @throws \InvalidArgumentException |
|
230 | - * |
|
231 | - * @return void |
|
232 | - */ |
|
233 | - public function addPsr4($prefix, $paths, $prepend = false) |
|
234 | - { |
|
235 | - if (!$prefix) { |
|
236 | - // Register directories for the root namespace. |
|
237 | - if ($prepend) { |
|
238 | - $this->fallbackDirsPsr4 = array_merge( |
|
239 | - (array) $paths, |
|
240 | - $this->fallbackDirsPsr4 |
|
241 | - ); |
|
242 | - } else { |
|
243 | - $this->fallbackDirsPsr4 = array_merge( |
|
244 | - $this->fallbackDirsPsr4, |
|
245 | - (array) $paths |
|
246 | - ); |
|
247 | - } |
|
248 | - } elseif (!isset($this->prefixDirsPsr4[$prefix])) { |
|
249 | - // Register directories for a new namespace. |
|
250 | - $length = strlen($prefix); |
|
251 | - if ('\\' !== $prefix[$length - 1]) { |
|
252 | - throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); |
|
253 | - } |
|
254 | - $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
255 | - $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
256 | - } elseif ($prepend) { |
|
257 | - // Prepend directories for an already registered namespace. |
|
258 | - $this->prefixDirsPsr4[$prefix] = array_merge( |
|
259 | - (array) $paths, |
|
260 | - $this->prefixDirsPsr4[$prefix] |
|
261 | - ); |
|
262 | - } else { |
|
263 | - // Append directories for an already registered namespace. |
|
264 | - $this->prefixDirsPsr4[$prefix] = array_merge( |
|
265 | - $this->prefixDirsPsr4[$prefix], |
|
266 | - (array) $paths |
|
267 | - ); |
|
268 | - } |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Registers a set of PSR-0 directories for a given prefix, |
|
273 | - * replacing any others previously set for this prefix. |
|
274 | - * |
|
275 | - * @param string $prefix The prefix |
|
276 | - * @param string[]|string $paths The PSR-0 base directories |
|
277 | - * |
|
278 | - * @return void |
|
279 | - */ |
|
280 | - public function set($prefix, $paths) |
|
281 | - { |
|
282 | - if (!$prefix) { |
|
283 | - $this->fallbackDirsPsr0 = (array) $paths; |
|
284 | - } else { |
|
285 | - $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Registers a set of PSR-4 directories for a given namespace, |
|
291 | - * replacing any others previously set for this namespace. |
|
292 | - * |
|
293 | - * @param string $prefix The prefix/namespace, with trailing '\\' |
|
294 | - * @param string[]|string $paths The PSR-4 base directories |
|
295 | - * |
|
296 | - * @throws \InvalidArgumentException |
|
297 | - * |
|
298 | - * @return void |
|
299 | - */ |
|
300 | - public function setPsr4($prefix, $paths) |
|
301 | - { |
|
302 | - if (!$prefix) { |
|
303 | - $this->fallbackDirsPsr4 = (array) $paths; |
|
304 | - } else { |
|
305 | - $length = strlen($prefix); |
|
306 | - if ('\\' !== $prefix[$length - 1]) { |
|
307 | - throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); |
|
308 | - } |
|
309 | - $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
310 | - $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Turns on searching the include path for class files. |
|
316 | - * |
|
317 | - * @param bool $useIncludePath |
|
318 | - * |
|
319 | - * @return void |
|
320 | - */ |
|
321 | - public function setUseIncludePath($useIncludePath) |
|
322 | - { |
|
323 | - $this->useIncludePath = $useIncludePath; |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Can be used to check if the autoloader uses the include path to check |
|
328 | - * for classes. |
|
329 | - * |
|
330 | - * @return bool |
|
331 | - */ |
|
332 | - public function getUseIncludePath() |
|
333 | - { |
|
334 | - return $this->useIncludePath; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Turns off searching the prefix and fallback directories for classes |
|
339 | - * that have not been registered with the class map. |
|
340 | - * |
|
341 | - * @param bool $classMapAuthoritative |
|
342 | - * |
|
343 | - * @return void |
|
344 | - */ |
|
345 | - public function setClassMapAuthoritative($classMapAuthoritative) |
|
346 | - { |
|
347 | - $this->classMapAuthoritative = $classMapAuthoritative; |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * Should class lookup fail if not found in the current class map? |
|
352 | - * |
|
353 | - * @return bool |
|
354 | - */ |
|
355 | - public function isClassMapAuthoritative() |
|
356 | - { |
|
357 | - return $this->classMapAuthoritative; |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * APCu prefix to use to cache found/not-found classes, if the extension is enabled. |
|
362 | - * |
|
363 | - * @param string|null $apcuPrefix |
|
364 | - * |
|
365 | - * @return void |
|
366 | - */ |
|
367 | - public function setApcuPrefix($apcuPrefix) |
|
368 | - { |
|
369 | - $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * The APCu prefix in use, or null if APCu caching is not enabled. |
|
374 | - * |
|
375 | - * @return string|null |
|
376 | - */ |
|
377 | - public function getApcuPrefix() |
|
378 | - { |
|
379 | - return $this->apcuPrefix; |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Registers this instance as an autoloader. |
|
384 | - * |
|
385 | - * @param bool $prepend Whether to prepend the autoloader or not |
|
386 | - * |
|
387 | - * @return void |
|
388 | - */ |
|
389 | - public function register($prepend = false) |
|
390 | - { |
|
391 | - spl_autoload_register(array($this, 'loadClass'), true, $prepend); |
|
392 | - |
|
393 | - if (null === $this->vendorDir) { |
|
394 | - return; |
|
395 | - } |
|
396 | - |
|
397 | - if ($prepend) { |
|
398 | - self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders; |
|
399 | - } else { |
|
400 | - unset(self::$registeredLoaders[$this->vendorDir]); |
|
401 | - self::$registeredLoaders[$this->vendorDir] = $this; |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Unregisters this instance as an autoloader. |
|
407 | - * |
|
408 | - * @return void |
|
409 | - */ |
|
410 | - public function unregister() |
|
411 | - { |
|
412 | - spl_autoload_unregister(array($this, 'loadClass')); |
|
413 | - |
|
414 | - if (null !== $this->vendorDir) { |
|
415 | - unset(self::$registeredLoaders[$this->vendorDir]); |
|
416 | - } |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Loads the given class or interface. |
|
421 | - * |
|
422 | - * @param string $class The name of the class |
|
423 | - * @return true|null True if loaded, null otherwise |
|
424 | - */ |
|
425 | - public function loadClass($class) |
|
426 | - { |
|
427 | - if ($file = $this->findFile($class)) { |
|
428 | - includeFile($file); |
|
429 | - |
|
430 | - return true; |
|
431 | - } |
|
432 | - |
|
433 | - return null; |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Finds the path to the file where the class is defined. |
|
438 | - * |
|
439 | - * @param string $class The name of the class |
|
440 | - * |
|
441 | - * @return string|false The path if found, false otherwise |
|
442 | - */ |
|
443 | - public function findFile($class) |
|
444 | - { |
|
445 | - // class map lookup |
|
446 | - if (isset($this->classMap[$class])) { |
|
447 | - return $this->classMap[$class]; |
|
448 | - } |
|
449 | - if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { |
|
450 | - return false; |
|
451 | - } |
|
452 | - if (null !== $this->apcuPrefix) { |
|
453 | - $file = apcu_fetch($this->apcuPrefix.$class, $hit); |
|
454 | - if ($hit) { |
|
455 | - return $file; |
|
456 | - } |
|
457 | - } |
|
458 | - |
|
459 | - $file = $this->findFileWithExtension($class, '.php'); |
|
460 | - |
|
461 | - // Search for Hack files if we are running on HHVM |
|
462 | - if (false === $file && defined('HHVM_VERSION')) { |
|
463 | - $file = $this->findFileWithExtension($class, '.hh'); |
|
464 | - } |
|
465 | - |
|
466 | - if (null !== $this->apcuPrefix) { |
|
467 | - apcu_add($this->apcuPrefix.$class, $file); |
|
468 | - } |
|
469 | - |
|
470 | - if (false === $file) { |
|
471 | - // Remember that this class does not exist. |
|
472 | - $this->missingClasses[$class] = true; |
|
473 | - } |
|
474 | - |
|
475 | - return $file; |
|
476 | - } |
|
477 | - |
|
478 | - /** |
|
479 | - * Returns the currently registered loaders indexed by their corresponding vendor directories. |
|
480 | - * |
|
481 | - * @return self[] |
|
482 | - */ |
|
483 | - public static function getRegisteredLoaders() |
|
484 | - { |
|
485 | - return self::$registeredLoaders; |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * @param string $class |
|
490 | - * @param string $ext |
|
491 | - * @return string|false |
|
492 | - */ |
|
493 | - private function findFileWithExtension($class, $ext) |
|
494 | - { |
|
495 | - // PSR-4 lookup |
|
496 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
497 | - |
|
498 | - $first = $class[0]; |
|
499 | - if (isset($this->prefixLengthsPsr4[$first])) { |
|
500 | - $subPath = $class; |
|
501 | - while (false !== $lastPos = strrpos($subPath, '\\')) { |
|
502 | - $subPath = substr($subPath, 0, $lastPos); |
|
503 | - $search = $subPath . '\\'; |
|
504 | - if (isset($this->prefixDirsPsr4[$search])) { |
|
505 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
506 | - foreach ($this->prefixDirsPsr4[$search] as $dir) { |
|
507 | - if (file_exists($file = $dir . $pathEnd)) { |
|
508 | - return $file; |
|
509 | - } |
|
510 | - } |
|
511 | - } |
|
512 | - } |
|
513 | - } |
|
514 | - |
|
515 | - // PSR-4 fallback dirs |
|
516 | - foreach ($this->fallbackDirsPsr4 as $dir) { |
|
517 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
518 | - return $file; |
|
519 | - } |
|
520 | - } |
|
521 | - |
|
522 | - // PSR-0 lookup |
|
523 | - if (false !== $pos = strrpos($class, '\\')) { |
|
524 | - // namespaced class name |
|
525 | - $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) |
|
526 | - . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
|
527 | - } else { |
|
528 | - // PEAR-like class name |
|
529 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
530 | - } |
|
531 | - |
|
532 | - if (isset($this->prefixesPsr0[$first])) { |
|
533 | - foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
|
534 | - if (0 === strpos($class, $prefix)) { |
|
535 | - foreach ($dirs as $dir) { |
|
536 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
537 | - return $file; |
|
538 | - } |
|
539 | - } |
|
540 | - } |
|
541 | - } |
|
542 | - } |
|
543 | - |
|
544 | - // PSR-0 fallback dirs |
|
545 | - foreach ($this->fallbackDirsPsr0 as $dir) { |
|
546 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
547 | - return $file; |
|
548 | - } |
|
549 | - } |
|
550 | - |
|
551 | - // PSR-0 include paths. |
|
552 | - if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { |
|
553 | - return $file; |
|
554 | - } |
|
555 | - |
|
556 | - return false; |
|
557 | - } |
|
45 | + /** @var ?string */ |
|
46 | + private $vendorDir; |
|
47 | + |
|
48 | + // PSR-4 |
|
49 | + /** |
|
50 | + * @var array[] |
|
51 | + * @psalm-var array<string, array<string, int>> |
|
52 | + */ |
|
53 | + private $prefixLengthsPsr4 = array(); |
|
54 | + /** |
|
55 | + * @var array[] |
|
56 | + * @psalm-var array<string, array<int, string>> |
|
57 | + */ |
|
58 | + private $prefixDirsPsr4 = array(); |
|
59 | + /** |
|
60 | + * @var array[] |
|
61 | + * @psalm-var array<string, string> |
|
62 | + */ |
|
63 | + private $fallbackDirsPsr4 = array(); |
|
64 | + |
|
65 | + // PSR-0 |
|
66 | + /** |
|
67 | + * @var array[] |
|
68 | + * @psalm-var array<string, array<string, string[]>> |
|
69 | + */ |
|
70 | + private $prefixesPsr0 = array(); |
|
71 | + /** |
|
72 | + * @var array[] |
|
73 | + * @psalm-var array<string, string> |
|
74 | + */ |
|
75 | + private $fallbackDirsPsr0 = array(); |
|
76 | + |
|
77 | + /** @var bool */ |
|
78 | + private $useIncludePath = false; |
|
79 | + |
|
80 | + /** |
|
81 | + * @var string[] |
|
82 | + * @psalm-var array<string, string> |
|
83 | + */ |
|
84 | + private $classMap = array(); |
|
85 | + |
|
86 | + /** @var bool */ |
|
87 | + private $classMapAuthoritative = false; |
|
88 | + |
|
89 | + /** |
|
90 | + * @var bool[] |
|
91 | + * @psalm-var array<string, bool> |
|
92 | + */ |
|
93 | + private $missingClasses = array(); |
|
94 | + |
|
95 | + /** @var ?string */ |
|
96 | + private $apcuPrefix; |
|
97 | + |
|
98 | + /** |
|
99 | + * @var self[] |
|
100 | + */ |
|
101 | + private static $registeredLoaders = array(); |
|
102 | + |
|
103 | + /** |
|
104 | + * @param ?string $vendorDir |
|
105 | + */ |
|
106 | + public function __construct($vendorDir = null) |
|
107 | + { |
|
108 | + $this->vendorDir = $vendorDir; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @return string[] |
|
113 | + */ |
|
114 | + public function getPrefixes() |
|
115 | + { |
|
116 | + if (!empty($this->prefixesPsr0)) { |
|
117 | + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); |
|
118 | + } |
|
119 | + |
|
120 | + return array(); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @return array[] |
|
125 | + * @psalm-return array<string, array<int, string>> |
|
126 | + */ |
|
127 | + public function getPrefixesPsr4() |
|
128 | + { |
|
129 | + return $this->prefixDirsPsr4; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @return array[] |
|
134 | + * @psalm-return array<string, string> |
|
135 | + */ |
|
136 | + public function getFallbackDirs() |
|
137 | + { |
|
138 | + return $this->fallbackDirsPsr0; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @return array[] |
|
143 | + * @psalm-return array<string, string> |
|
144 | + */ |
|
145 | + public function getFallbackDirsPsr4() |
|
146 | + { |
|
147 | + return $this->fallbackDirsPsr4; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return string[] Array of classname => path |
|
152 | + * @psalm-return array<string, string> |
|
153 | + */ |
|
154 | + public function getClassMap() |
|
155 | + { |
|
156 | + return $this->classMap; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @param string[] $classMap Class to filename map |
|
161 | + * @psalm-param array<string, string> $classMap |
|
162 | + * |
|
163 | + * @return void |
|
164 | + */ |
|
165 | + public function addClassMap(array $classMap) |
|
166 | + { |
|
167 | + if ($this->classMap) { |
|
168 | + $this->classMap = array_merge($this->classMap, $classMap); |
|
169 | + } else { |
|
170 | + $this->classMap = $classMap; |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Registers a set of PSR-0 directories for a given prefix, either |
|
176 | + * appending or prepending to the ones previously set for this prefix. |
|
177 | + * |
|
178 | + * @param string $prefix The prefix |
|
179 | + * @param string[]|string $paths The PSR-0 root directories |
|
180 | + * @param bool $prepend Whether to prepend the directories |
|
181 | + * |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + public function add($prefix, $paths, $prepend = false) |
|
185 | + { |
|
186 | + if (!$prefix) { |
|
187 | + if ($prepend) { |
|
188 | + $this->fallbackDirsPsr0 = array_merge( |
|
189 | + (array) $paths, |
|
190 | + $this->fallbackDirsPsr0 |
|
191 | + ); |
|
192 | + } else { |
|
193 | + $this->fallbackDirsPsr0 = array_merge( |
|
194 | + $this->fallbackDirsPsr0, |
|
195 | + (array) $paths |
|
196 | + ); |
|
197 | + } |
|
198 | + |
|
199 | + return; |
|
200 | + } |
|
201 | + |
|
202 | + $first = $prefix[0]; |
|
203 | + if (!isset($this->prefixesPsr0[$first][$prefix])) { |
|
204 | + $this->prefixesPsr0[$first][$prefix] = (array) $paths; |
|
205 | + |
|
206 | + return; |
|
207 | + } |
|
208 | + if ($prepend) { |
|
209 | + $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
210 | + (array) $paths, |
|
211 | + $this->prefixesPsr0[$first][$prefix] |
|
212 | + ); |
|
213 | + } else { |
|
214 | + $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
215 | + $this->prefixesPsr0[$first][$prefix], |
|
216 | + (array) $paths |
|
217 | + ); |
|
218 | + } |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Registers a set of PSR-4 directories for a given namespace, either |
|
223 | + * appending or prepending to the ones previously set for this namespace. |
|
224 | + * |
|
225 | + * @param string $prefix The prefix/namespace, with trailing '\\' |
|
226 | + * @param string[]|string $paths The PSR-4 base directories |
|
227 | + * @param bool $prepend Whether to prepend the directories |
|
228 | + * |
|
229 | + * @throws \InvalidArgumentException |
|
230 | + * |
|
231 | + * @return void |
|
232 | + */ |
|
233 | + public function addPsr4($prefix, $paths, $prepend = false) |
|
234 | + { |
|
235 | + if (!$prefix) { |
|
236 | + // Register directories for the root namespace. |
|
237 | + if ($prepend) { |
|
238 | + $this->fallbackDirsPsr4 = array_merge( |
|
239 | + (array) $paths, |
|
240 | + $this->fallbackDirsPsr4 |
|
241 | + ); |
|
242 | + } else { |
|
243 | + $this->fallbackDirsPsr4 = array_merge( |
|
244 | + $this->fallbackDirsPsr4, |
|
245 | + (array) $paths |
|
246 | + ); |
|
247 | + } |
|
248 | + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { |
|
249 | + // Register directories for a new namespace. |
|
250 | + $length = strlen($prefix); |
|
251 | + if ('\\' !== $prefix[$length - 1]) { |
|
252 | + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); |
|
253 | + } |
|
254 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
255 | + $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
256 | + } elseif ($prepend) { |
|
257 | + // Prepend directories for an already registered namespace. |
|
258 | + $this->prefixDirsPsr4[$prefix] = array_merge( |
|
259 | + (array) $paths, |
|
260 | + $this->prefixDirsPsr4[$prefix] |
|
261 | + ); |
|
262 | + } else { |
|
263 | + // Append directories for an already registered namespace. |
|
264 | + $this->prefixDirsPsr4[$prefix] = array_merge( |
|
265 | + $this->prefixDirsPsr4[$prefix], |
|
266 | + (array) $paths |
|
267 | + ); |
|
268 | + } |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Registers a set of PSR-0 directories for a given prefix, |
|
273 | + * replacing any others previously set for this prefix. |
|
274 | + * |
|
275 | + * @param string $prefix The prefix |
|
276 | + * @param string[]|string $paths The PSR-0 base directories |
|
277 | + * |
|
278 | + * @return void |
|
279 | + */ |
|
280 | + public function set($prefix, $paths) |
|
281 | + { |
|
282 | + if (!$prefix) { |
|
283 | + $this->fallbackDirsPsr0 = (array) $paths; |
|
284 | + } else { |
|
285 | + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Registers a set of PSR-4 directories for a given namespace, |
|
291 | + * replacing any others previously set for this namespace. |
|
292 | + * |
|
293 | + * @param string $prefix The prefix/namespace, with trailing '\\' |
|
294 | + * @param string[]|string $paths The PSR-4 base directories |
|
295 | + * |
|
296 | + * @throws \InvalidArgumentException |
|
297 | + * |
|
298 | + * @return void |
|
299 | + */ |
|
300 | + public function setPsr4($prefix, $paths) |
|
301 | + { |
|
302 | + if (!$prefix) { |
|
303 | + $this->fallbackDirsPsr4 = (array) $paths; |
|
304 | + } else { |
|
305 | + $length = strlen($prefix); |
|
306 | + if ('\\' !== $prefix[$length - 1]) { |
|
307 | + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); |
|
308 | + } |
|
309 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
310 | + $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Turns on searching the include path for class files. |
|
316 | + * |
|
317 | + * @param bool $useIncludePath |
|
318 | + * |
|
319 | + * @return void |
|
320 | + */ |
|
321 | + public function setUseIncludePath($useIncludePath) |
|
322 | + { |
|
323 | + $this->useIncludePath = $useIncludePath; |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Can be used to check if the autoloader uses the include path to check |
|
328 | + * for classes. |
|
329 | + * |
|
330 | + * @return bool |
|
331 | + */ |
|
332 | + public function getUseIncludePath() |
|
333 | + { |
|
334 | + return $this->useIncludePath; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Turns off searching the prefix and fallback directories for classes |
|
339 | + * that have not been registered with the class map. |
|
340 | + * |
|
341 | + * @param bool $classMapAuthoritative |
|
342 | + * |
|
343 | + * @return void |
|
344 | + */ |
|
345 | + public function setClassMapAuthoritative($classMapAuthoritative) |
|
346 | + { |
|
347 | + $this->classMapAuthoritative = $classMapAuthoritative; |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * Should class lookup fail if not found in the current class map? |
|
352 | + * |
|
353 | + * @return bool |
|
354 | + */ |
|
355 | + public function isClassMapAuthoritative() |
|
356 | + { |
|
357 | + return $this->classMapAuthoritative; |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. |
|
362 | + * |
|
363 | + * @param string|null $apcuPrefix |
|
364 | + * |
|
365 | + * @return void |
|
366 | + */ |
|
367 | + public function setApcuPrefix($apcuPrefix) |
|
368 | + { |
|
369 | + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * The APCu prefix in use, or null if APCu caching is not enabled. |
|
374 | + * |
|
375 | + * @return string|null |
|
376 | + */ |
|
377 | + public function getApcuPrefix() |
|
378 | + { |
|
379 | + return $this->apcuPrefix; |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Registers this instance as an autoloader. |
|
384 | + * |
|
385 | + * @param bool $prepend Whether to prepend the autoloader or not |
|
386 | + * |
|
387 | + * @return void |
|
388 | + */ |
|
389 | + public function register($prepend = false) |
|
390 | + { |
|
391 | + spl_autoload_register(array($this, 'loadClass'), true, $prepend); |
|
392 | + |
|
393 | + if (null === $this->vendorDir) { |
|
394 | + return; |
|
395 | + } |
|
396 | + |
|
397 | + if ($prepend) { |
|
398 | + self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders; |
|
399 | + } else { |
|
400 | + unset(self::$registeredLoaders[$this->vendorDir]); |
|
401 | + self::$registeredLoaders[$this->vendorDir] = $this; |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Unregisters this instance as an autoloader. |
|
407 | + * |
|
408 | + * @return void |
|
409 | + */ |
|
410 | + public function unregister() |
|
411 | + { |
|
412 | + spl_autoload_unregister(array($this, 'loadClass')); |
|
413 | + |
|
414 | + if (null !== $this->vendorDir) { |
|
415 | + unset(self::$registeredLoaders[$this->vendorDir]); |
|
416 | + } |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Loads the given class or interface. |
|
421 | + * |
|
422 | + * @param string $class The name of the class |
|
423 | + * @return true|null True if loaded, null otherwise |
|
424 | + */ |
|
425 | + public function loadClass($class) |
|
426 | + { |
|
427 | + if ($file = $this->findFile($class)) { |
|
428 | + includeFile($file); |
|
429 | + |
|
430 | + return true; |
|
431 | + } |
|
432 | + |
|
433 | + return null; |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * Finds the path to the file where the class is defined. |
|
438 | + * |
|
439 | + * @param string $class The name of the class |
|
440 | + * |
|
441 | + * @return string|false The path if found, false otherwise |
|
442 | + */ |
|
443 | + public function findFile($class) |
|
444 | + { |
|
445 | + // class map lookup |
|
446 | + if (isset($this->classMap[$class])) { |
|
447 | + return $this->classMap[$class]; |
|
448 | + } |
|
449 | + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { |
|
450 | + return false; |
|
451 | + } |
|
452 | + if (null !== $this->apcuPrefix) { |
|
453 | + $file = apcu_fetch($this->apcuPrefix.$class, $hit); |
|
454 | + if ($hit) { |
|
455 | + return $file; |
|
456 | + } |
|
457 | + } |
|
458 | + |
|
459 | + $file = $this->findFileWithExtension($class, '.php'); |
|
460 | + |
|
461 | + // Search for Hack files if we are running on HHVM |
|
462 | + if (false === $file && defined('HHVM_VERSION')) { |
|
463 | + $file = $this->findFileWithExtension($class, '.hh'); |
|
464 | + } |
|
465 | + |
|
466 | + if (null !== $this->apcuPrefix) { |
|
467 | + apcu_add($this->apcuPrefix.$class, $file); |
|
468 | + } |
|
469 | + |
|
470 | + if (false === $file) { |
|
471 | + // Remember that this class does not exist. |
|
472 | + $this->missingClasses[$class] = true; |
|
473 | + } |
|
474 | + |
|
475 | + return $file; |
|
476 | + } |
|
477 | + |
|
478 | + /** |
|
479 | + * Returns the currently registered loaders indexed by their corresponding vendor directories. |
|
480 | + * |
|
481 | + * @return self[] |
|
482 | + */ |
|
483 | + public static function getRegisteredLoaders() |
|
484 | + { |
|
485 | + return self::$registeredLoaders; |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * @param string $class |
|
490 | + * @param string $ext |
|
491 | + * @return string|false |
|
492 | + */ |
|
493 | + private function findFileWithExtension($class, $ext) |
|
494 | + { |
|
495 | + // PSR-4 lookup |
|
496 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
497 | + |
|
498 | + $first = $class[0]; |
|
499 | + if (isset($this->prefixLengthsPsr4[$first])) { |
|
500 | + $subPath = $class; |
|
501 | + while (false !== $lastPos = strrpos($subPath, '\\')) { |
|
502 | + $subPath = substr($subPath, 0, $lastPos); |
|
503 | + $search = $subPath . '\\'; |
|
504 | + if (isset($this->prefixDirsPsr4[$search])) { |
|
505 | + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
506 | + foreach ($this->prefixDirsPsr4[$search] as $dir) { |
|
507 | + if (file_exists($file = $dir . $pathEnd)) { |
|
508 | + return $file; |
|
509 | + } |
|
510 | + } |
|
511 | + } |
|
512 | + } |
|
513 | + } |
|
514 | + |
|
515 | + // PSR-4 fallback dirs |
|
516 | + foreach ($this->fallbackDirsPsr4 as $dir) { |
|
517 | + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
518 | + return $file; |
|
519 | + } |
|
520 | + } |
|
521 | + |
|
522 | + // PSR-0 lookup |
|
523 | + if (false !== $pos = strrpos($class, '\\')) { |
|
524 | + // namespaced class name |
|
525 | + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) |
|
526 | + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
|
527 | + } else { |
|
528 | + // PEAR-like class name |
|
529 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
530 | + } |
|
531 | + |
|
532 | + if (isset($this->prefixesPsr0[$first])) { |
|
533 | + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
|
534 | + if (0 === strpos($class, $prefix)) { |
|
535 | + foreach ($dirs as $dir) { |
|
536 | + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
537 | + return $file; |
|
538 | + } |
|
539 | + } |
|
540 | + } |
|
541 | + } |
|
542 | + } |
|
543 | + |
|
544 | + // PSR-0 fallback dirs |
|
545 | + foreach ($this->fallbackDirsPsr0 as $dir) { |
|
546 | + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
547 | + return $file; |
|
548 | + } |
|
549 | + } |
|
550 | + |
|
551 | + // PSR-0 include paths. |
|
552 | + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { |
|
553 | + return $file; |
|
554 | + } |
|
555 | + |
|
556 | + return false; |
|
557 | + } |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | /** |
@@ -568,5 +568,5 @@ discard block |
||
568 | 568 | */ |
569 | 569 | function includeFile($file) |
570 | 570 | { |
571 | - include $file; |
|
571 | + include $file; |
|
572 | 572 | } |
@@ -26,327 +26,327 @@ |
||
26 | 26 | */ |
27 | 27 | class InstalledVersions |
28 | 28 | { |
29 | - /** |
|
30 | - * @var mixed[]|null |
|
31 | - * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null |
|
32 | - */ |
|
33 | - private static $installed; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var bool|null |
|
37 | - */ |
|
38 | - private static $canGetVendors; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var array[] |
|
42 | - * @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}> |
|
43 | - */ |
|
44 | - private static $installedByVendor = array(); |
|
45 | - |
|
46 | - /** |
|
47 | - * Returns a list of all package names which are present, either by being installed, replaced or provided |
|
48 | - * |
|
49 | - * @return string[] |
|
50 | - * @psalm-return list<string> |
|
51 | - */ |
|
52 | - public static function getInstalledPackages() |
|
53 | - { |
|
54 | - $packages = array(); |
|
55 | - foreach (self::getInstalled() as $installed) { |
|
56 | - $packages[] = array_keys($installed['versions']); |
|
57 | - } |
|
58 | - |
|
59 | - if (1 === \count($packages)) { |
|
60 | - return $packages[0]; |
|
61 | - } |
|
62 | - |
|
63 | - return array_keys(array_flip(\call_user_func_array('array_merge', $packages))); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Returns a list of all package names with a specific type e.g. 'library' |
|
68 | - * |
|
69 | - * @param string $type |
|
70 | - * @return string[] |
|
71 | - * @psalm-return list<string> |
|
72 | - */ |
|
73 | - public static function getInstalledPackagesByType($type) |
|
74 | - { |
|
75 | - $packagesByType = array(); |
|
76 | - |
|
77 | - foreach (self::getInstalled() as $installed) { |
|
78 | - foreach ($installed['versions'] as $name => $package) { |
|
79 | - if (isset($package['type']) && $package['type'] === $type) { |
|
80 | - $packagesByType[] = $name; |
|
81 | - } |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - return $packagesByType; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Checks whether the given package is installed |
|
90 | - * |
|
91 | - * This also returns true if the package name is provided or replaced by another package |
|
92 | - * |
|
93 | - * @param string $packageName |
|
94 | - * @param bool $includeDevRequirements |
|
95 | - * @return bool |
|
96 | - */ |
|
97 | - public static function isInstalled($packageName, $includeDevRequirements = true) |
|
98 | - { |
|
99 | - foreach (self::getInstalled() as $installed) { |
|
100 | - if (isset($installed['versions'][$packageName])) { |
|
101 | - return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - return false; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Checks whether the given package satisfies a version constraint |
|
110 | - * |
|
111 | - * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call: |
|
112 | - * |
|
113 | - * Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3') |
|
114 | - * |
|
115 | - * @param VersionParser $parser Install composer/semver to have access to this class and functionality |
|
116 | - * @param string $packageName |
|
117 | - * @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package |
|
118 | - * @return bool |
|
119 | - */ |
|
120 | - public static function satisfies(VersionParser $parser, $packageName, $constraint) |
|
121 | - { |
|
122 | - $constraint = $parser->parseConstraints($constraint); |
|
123 | - $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); |
|
124 | - |
|
125 | - return $provided->matches($constraint); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Returns a version constraint representing all the range(s) which are installed for a given package |
|
130 | - * |
|
131 | - * It is easier to use this via isInstalled() with the $constraint argument if you need to check |
|
132 | - * whether a given version of a package is installed, and not just whether it exists |
|
133 | - * |
|
134 | - * @param string $packageName |
|
135 | - * @return string Version constraint usable with composer/semver |
|
136 | - */ |
|
137 | - public static function getVersionRanges($packageName) |
|
138 | - { |
|
139 | - foreach (self::getInstalled() as $installed) { |
|
140 | - if (!isset($installed['versions'][$packageName])) { |
|
141 | - continue; |
|
142 | - } |
|
143 | - |
|
144 | - $ranges = array(); |
|
145 | - if (isset($installed['versions'][$packageName]['pretty_version'])) { |
|
146 | - $ranges[] = $installed['versions'][$packageName]['pretty_version']; |
|
147 | - } |
|
148 | - if (array_key_exists('aliases', $installed['versions'][$packageName])) { |
|
149 | - $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']); |
|
150 | - } |
|
151 | - if (array_key_exists('replaced', $installed['versions'][$packageName])) { |
|
152 | - $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']); |
|
153 | - } |
|
154 | - if (array_key_exists('provided', $installed['versions'][$packageName])) { |
|
155 | - $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']); |
|
156 | - } |
|
157 | - |
|
158 | - return implode(' || ', $ranges); |
|
159 | - } |
|
160 | - |
|
161 | - throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @param string $packageName |
|
166 | - * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present |
|
167 | - */ |
|
168 | - public static function getVersion($packageName) |
|
169 | - { |
|
170 | - foreach (self::getInstalled() as $installed) { |
|
171 | - if (!isset($installed['versions'][$packageName])) { |
|
172 | - continue; |
|
173 | - } |
|
174 | - |
|
175 | - if (!isset($installed['versions'][$packageName]['version'])) { |
|
176 | - return null; |
|
177 | - } |
|
178 | - |
|
179 | - return $installed['versions'][$packageName]['version']; |
|
180 | - } |
|
181 | - |
|
182 | - throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @param string $packageName |
|
187 | - * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present |
|
188 | - */ |
|
189 | - public static function getPrettyVersion($packageName) |
|
190 | - { |
|
191 | - foreach (self::getInstalled() as $installed) { |
|
192 | - if (!isset($installed['versions'][$packageName])) { |
|
193 | - continue; |
|
194 | - } |
|
195 | - |
|
196 | - if (!isset($installed['versions'][$packageName]['pretty_version'])) { |
|
197 | - return null; |
|
198 | - } |
|
199 | - |
|
200 | - return $installed['versions'][$packageName]['pretty_version']; |
|
201 | - } |
|
202 | - |
|
203 | - throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @param string $packageName |
|
208 | - * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference |
|
209 | - */ |
|
210 | - public static function getReference($packageName) |
|
211 | - { |
|
212 | - foreach (self::getInstalled() as $installed) { |
|
213 | - if (!isset($installed['versions'][$packageName])) { |
|
214 | - continue; |
|
215 | - } |
|
216 | - |
|
217 | - if (!isset($installed['versions'][$packageName]['reference'])) { |
|
218 | - return null; |
|
219 | - } |
|
220 | - |
|
221 | - return $installed['versions'][$packageName]['reference']; |
|
222 | - } |
|
223 | - |
|
224 | - throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @param string $packageName |
|
229 | - * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path. |
|
230 | - */ |
|
231 | - public static function getInstallPath($packageName) |
|
232 | - { |
|
233 | - foreach (self::getInstalled() as $installed) { |
|
234 | - if (!isset($installed['versions'][$packageName])) { |
|
235 | - continue; |
|
236 | - } |
|
237 | - |
|
238 | - return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null; |
|
239 | - } |
|
240 | - |
|
241 | - throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * @return array |
|
246 | - * @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool} |
|
247 | - */ |
|
248 | - public static function getRootPackage() |
|
249 | - { |
|
250 | - $installed = self::getInstalled(); |
|
251 | - |
|
252 | - return $installed[0]['root']; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Returns the raw installed.php data for custom implementations |
|
257 | - * |
|
258 | - * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect. |
|
259 | - * @return array[] |
|
260 | - * @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} |
|
261 | - */ |
|
262 | - public static function getRawData() |
|
263 | - { |
|
264 | - @trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED); |
|
265 | - |
|
266 | - if (null === self::$installed) { |
|
267 | - // only require the installed.php file if this file is loaded from its dumped location, |
|
268 | - // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 |
|
269 | - if (substr(__DIR__, -8, 1) !== 'C') { |
|
270 | - self::$installed = include __DIR__ . '/installed.php'; |
|
271 | - } else { |
|
272 | - self::$installed = array(); |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - return self::$installed; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Returns the raw data of all installed.php which are currently loaded for custom implementations |
|
281 | - * |
|
282 | - * @return array[] |
|
283 | - * @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}> |
|
284 | - */ |
|
285 | - public static function getAllRawData() |
|
286 | - { |
|
287 | - return self::getInstalled(); |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Lets you reload the static array from another file |
|
292 | - * |
|
293 | - * This is only useful for complex integrations in which a project needs to use |
|
294 | - * this class but then also needs to execute another project's autoloader in process, |
|
295 | - * and wants to ensure both projects have access to their version of installed.php. |
|
296 | - * |
|
297 | - * A typical case would be PHPUnit, where it would need to make sure it reads all |
|
298 | - * the data it needs from this class, then call reload() with |
|
299 | - * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure |
|
300 | - * the project in which it runs can then also use this class safely, without |
|
301 | - * interference between PHPUnit's dependencies and the project's dependencies. |
|
302 | - * |
|
303 | - * @param array[] $data A vendor/composer/installed.php data set |
|
304 | - * @return void |
|
305 | - * |
|
306 | - * @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data |
|
307 | - */ |
|
308 | - public static function reload($data) |
|
309 | - { |
|
310 | - self::$installed = $data; |
|
311 | - self::$installedByVendor = array(); |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * @return array[] |
|
316 | - * @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}> |
|
317 | - */ |
|
318 | - private static function getInstalled() |
|
319 | - { |
|
320 | - if (null === self::$canGetVendors) { |
|
321 | - self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders'); |
|
322 | - } |
|
323 | - |
|
324 | - $installed = array(); |
|
325 | - |
|
326 | - if (self::$canGetVendors) { |
|
327 | - foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { |
|
328 | - if (isset(self::$installedByVendor[$vendorDir])) { |
|
329 | - $installed[] = self::$installedByVendor[$vendorDir]; |
|
330 | - } elseif (is_file($vendorDir.'/composer/installed.php')) { |
|
331 | - $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php'; |
|
332 | - if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { |
|
333 | - self::$installed = $installed[count($installed) - 1]; |
|
334 | - } |
|
335 | - } |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - if (null === self::$installed) { |
|
340 | - // only require the installed.php file if this file is loaded from its dumped location, |
|
341 | - // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 |
|
342 | - if (substr(__DIR__, -8, 1) !== 'C') { |
|
343 | - self::$installed = require __DIR__ . '/installed.php'; |
|
344 | - } else { |
|
345 | - self::$installed = array(); |
|
346 | - } |
|
347 | - } |
|
348 | - $installed[] = self::$installed; |
|
349 | - |
|
350 | - return $installed; |
|
351 | - } |
|
29 | + /** |
|
30 | + * @var mixed[]|null |
|
31 | + * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null |
|
32 | + */ |
|
33 | + private static $installed; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var bool|null |
|
37 | + */ |
|
38 | + private static $canGetVendors; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var array[] |
|
42 | + * @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}> |
|
43 | + */ |
|
44 | + private static $installedByVendor = array(); |
|
45 | + |
|
46 | + /** |
|
47 | + * Returns a list of all package names which are present, either by being installed, replaced or provided |
|
48 | + * |
|
49 | + * @return string[] |
|
50 | + * @psalm-return list<string> |
|
51 | + */ |
|
52 | + public static function getInstalledPackages() |
|
53 | + { |
|
54 | + $packages = array(); |
|
55 | + foreach (self::getInstalled() as $installed) { |
|
56 | + $packages[] = array_keys($installed['versions']); |
|
57 | + } |
|
58 | + |
|
59 | + if (1 === \count($packages)) { |
|
60 | + return $packages[0]; |
|
61 | + } |
|
62 | + |
|
63 | + return array_keys(array_flip(\call_user_func_array('array_merge', $packages))); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Returns a list of all package names with a specific type e.g. 'library' |
|
68 | + * |
|
69 | + * @param string $type |
|
70 | + * @return string[] |
|
71 | + * @psalm-return list<string> |
|
72 | + */ |
|
73 | + public static function getInstalledPackagesByType($type) |
|
74 | + { |
|
75 | + $packagesByType = array(); |
|
76 | + |
|
77 | + foreach (self::getInstalled() as $installed) { |
|
78 | + foreach ($installed['versions'] as $name => $package) { |
|
79 | + if (isset($package['type']) && $package['type'] === $type) { |
|
80 | + $packagesByType[] = $name; |
|
81 | + } |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + return $packagesByType; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Checks whether the given package is installed |
|
90 | + * |
|
91 | + * This also returns true if the package name is provided or replaced by another package |
|
92 | + * |
|
93 | + * @param string $packageName |
|
94 | + * @param bool $includeDevRequirements |
|
95 | + * @return bool |
|
96 | + */ |
|
97 | + public static function isInstalled($packageName, $includeDevRequirements = true) |
|
98 | + { |
|
99 | + foreach (self::getInstalled() as $installed) { |
|
100 | + if (isset($installed['versions'][$packageName])) { |
|
101 | + return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + return false; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Checks whether the given package satisfies a version constraint |
|
110 | + * |
|
111 | + * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call: |
|
112 | + * |
|
113 | + * Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3') |
|
114 | + * |
|
115 | + * @param VersionParser $parser Install composer/semver to have access to this class and functionality |
|
116 | + * @param string $packageName |
|
117 | + * @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package |
|
118 | + * @return bool |
|
119 | + */ |
|
120 | + public static function satisfies(VersionParser $parser, $packageName, $constraint) |
|
121 | + { |
|
122 | + $constraint = $parser->parseConstraints($constraint); |
|
123 | + $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); |
|
124 | + |
|
125 | + return $provided->matches($constraint); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Returns a version constraint representing all the range(s) which are installed for a given package |
|
130 | + * |
|
131 | + * It is easier to use this via isInstalled() with the $constraint argument if you need to check |
|
132 | + * whether a given version of a package is installed, and not just whether it exists |
|
133 | + * |
|
134 | + * @param string $packageName |
|
135 | + * @return string Version constraint usable with composer/semver |
|
136 | + */ |
|
137 | + public static function getVersionRanges($packageName) |
|
138 | + { |
|
139 | + foreach (self::getInstalled() as $installed) { |
|
140 | + if (!isset($installed['versions'][$packageName])) { |
|
141 | + continue; |
|
142 | + } |
|
143 | + |
|
144 | + $ranges = array(); |
|
145 | + if (isset($installed['versions'][$packageName]['pretty_version'])) { |
|
146 | + $ranges[] = $installed['versions'][$packageName]['pretty_version']; |
|
147 | + } |
|
148 | + if (array_key_exists('aliases', $installed['versions'][$packageName])) { |
|
149 | + $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']); |
|
150 | + } |
|
151 | + if (array_key_exists('replaced', $installed['versions'][$packageName])) { |
|
152 | + $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']); |
|
153 | + } |
|
154 | + if (array_key_exists('provided', $installed['versions'][$packageName])) { |
|
155 | + $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']); |
|
156 | + } |
|
157 | + |
|
158 | + return implode(' || ', $ranges); |
|
159 | + } |
|
160 | + |
|
161 | + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @param string $packageName |
|
166 | + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present |
|
167 | + */ |
|
168 | + public static function getVersion($packageName) |
|
169 | + { |
|
170 | + foreach (self::getInstalled() as $installed) { |
|
171 | + if (!isset($installed['versions'][$packageName])) { |
|
172 | + continue; |
|
173 | + } |
|
174 | + |
|
175 | + if (!isset($installed['versions'][$packageName]['version'])) { |
|
176 | + return null; |
|
177 | + } |
|
178 | + |
|
179 | + return $installed['versions'][$packageName]['version']; |
|
180 | + } |
|
181 | + |
|
182 | + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @param string $packageName |
|
187 | + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present |
|
188 | + */ |
|
189 | + public static function getPrettyVersion($packageName) |
|
190 | + { |
|
191 | + foreach (self::getInstalled() as $installed) { |
|
192 | + if (!isset($installed['versions'][$packageName])) { |
|
193 | + continue; |
|
194 | + } |
|
195 | + |
|
196 | + if (!isset($installed['versions'][$packageName]['pretty_version'])) { |
|
197 | + return null; |
|
198 | + } |
|
199 | + |
|
200 | + return $installed['versions'][$packageName]['pretty_version']; |
|
201 | + } |
|
202 | + |
|
203 | + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @param string $packageName |
|
208 | + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference |
|
209 | + */ |
|
210 | + public static function getReference($packageName) |
|
211 | + { |
|
212 | + foreach (self::getInstalled() as $installed) { |
|
213 | + if (!isset($installed['versions'][$packageName])) { |
|
214 | + continue; |
|
215 | + } |
|
216 | + |
|
217 | + if (!isset($installed['versions'][$packageName]['reference'])) { |
|
218 | + return null; |
|
219 | + } |
|
220 | + |
|
221 | + return $installed['versions'][$packageName]['reference']; |
|
222 | + } |
|
223 | + |
|
224 | + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @param string $packageName |
|
229 | + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path. |
|
230 | + */ |
|
231 | + public static function getInstallPath($packageName) |
|
232 | + { |
|
233 | + foreach (self::getInstalled() as $installed) { |
|
234 | + if (!isset($installed['versions'][$packageName])) { |
|
235 | + continue; |
|
236 | + } |
|
237 | + |
|
238 | + return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null; |
|
239 | + } |
|
240 | + |
|
241 | + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * @return array |
|
246 | + * @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool} |
|
247 | + */ |
|
248 | + public static function getRootPackage() |
|
249 | + { |
|
250 | + $installed = self::getInstalled(); |
|
251 | + |
|
252 | + return $installed[0]['root']; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Returns the raw installed.php data for custom implementations |
|
257 | + * |
|
258 | + * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect. |
|
259 | + * @return array[] |
|
260 | + * @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} |
|
261 | + */ |
|
262 | + public static function getRawData() |
|
263 | + { |
|
264 | + @trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED); |
|
265 | + |
|
266 | + if (null === self::$installed) { |
|
267 | + // only require the installed.php file if this file is loaded from its dumped location, |
|
268 | + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 |
|
269 | + if (substr(__DIR__, -8, 1) !== 'C') { |
|
270 | + self::$installed = include __DIR__ . '/installed.php'; |
|
271 | + } else { |
|
272 | + self::$installed = array(); |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + return self::$installed; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Returns the raw data of all installed.php which are currently loaded for custom implementations |
|
281 | + * |
|
282 | + * @return array[] |
|
283 | + * @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}> |
|
284 | + */ |
|
285 | + public static function getAllRawData() |
|
286 | + { |
|
287 | + return self::getInstalled(); |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Lets you reload the static array from another file |
|
292 | + * |
|
293 | + * This is only useful for complex integrations in which a project needs to use |
|
294 | + * this class but then also needs to execute another project's autoloader in process, |
|
295 | + * and wants to ensure both projects have access to their version of installed.php. |
|
296 | + * |
|
297 | + * A typical case would be PHPUnit, where it would need to make sure it reads all |
|
298 | + * the data it needs from this class, then call reload() with |
|
299 | + * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure |
|
300 | + * the project in which it runs can then also use this class safely, without |
|
301 | + * interference between PHPUnit's dependencies and the project's dependencies. |
|
302 | + * |
|
303 | + * @param array[] $data A vendor/composer/installed.php data set |
|
304 | + * @return void |
|
305 | + * |
|
306 | + * @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data |
|
307 | + */ |
|
308 | + public static function reload($data) |
|
309 | + { |
|
310 | + self::$installed = $data; |
|
311 | + self::$installedByVendor = array(); |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * @return array[] |
|
316 | + * @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}> |
|
317 | + */ |
|
318 | + private static function getInstalled() |
|
319 | + { |
|
320 | + if (null === self::$canGetVendors) { |
|
321 | + self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders'); |
|
322 | + } |
|
323 | + |
|
324 | + $installed = array(); |
|
325 | + |
|
326 | + if (self::$canGetVendors) { |
|
327 | + foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { |
|
328 | + if (isset(self::$installedByVendor[$vendorDir])) { |
|
329 | + $installed[] = self::$installedByVendor[$vendorDir]; |
|
330 | + } elseif (is_file($vendorDir.'/composer/installed.php')) { |
|
331 | + $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php'; |
|
332 | + if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { |
|
333 | + self::$installed = $installed[count($installed) - 1]; |
|
334 | + } |
|
335 | + } |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + if (null === self::$installed) { |
|
340 | + // only require the installed.php file if this file is loaded from its dumped location, |
|
341 | + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 |
|
342 | + if (substr(__DIR__, -8, 1) !== 'C') { |
|
343 | + self::$installed = require __DIR__ . '/installed.php'; |
|
344 | + } else { |
|
345 | + self::$installed = array(); |
|
346 | + } |
|
347 | + } |
|
348 | + $installed[] = self::$installed; |
|
349 | + |
|
350 | + return $installed; |
|
351 | + } |
|
352 | 352 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | EEH_HTML::h4( |
48 | 48 | '<span class="dashicons dashicons-info"></span>' |
49 | 49 | . esc_html__('Did you know...', 'event_espresso') |
50 | - ) . |
|
50 | + ). |
|
51 | 51 | EEH_HTML::p( |
52 | 52 | esc_html__( |
53 | 53 | 'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.', |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | type="hidden" |
109 | 109 | value="<?php echo esc_attr($question->get('QST_order')); ?>" |
110 | 110 | /> |
111 | - <?php if (! empty($QST_system)) { ?> |
|
111 | + <?php if ( ! empty($QST_system)) { ?> |
|
112 | 112 | <input id='QST_admin_label' |
113 | 113 | name="QST_admin_label" |
114 | 114 | type="hidden" |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | <?php } ?> |
118 | 118 | <br /> |
119 | 119 | <p class="description"> |
120 | - <?php if (! empty($QST_system)) { ?> |
|
120 | + <?php if ( ! empty($QST_system)) { ?> |
|
121 | 121 | <span class="description" style="color:#D54E21;"> |
122 | 122 | <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso') ?> |
123 | 123 | </span> |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | <br /> |
155 | 155 | <p class="description"> |
156 | 156 | <?php |
157 | - if (! empty($QST_system)) { ?> |
|
157 | + if ( ! empty($QST_system)) { ?> |
|
158 | 158 | <span class="description" style="color:#D54E21;"> |
159 | 159 | <?php esc_html_e( |
160 | 160 | 'System question! This field cannot be changed.', |
@@ -186,15 +186,15 @@ discard block |
||
186 | 186 | |
187 | 187 | // Only display Confirm email for |
188 | 188 | if (empty($QST_system) || $QST_system !== EEM_Attendee::system_question_email_confirm) { |
189 | - unset($question_types[ EEM_Question::QST_type_email_confirm ]); |
|
189 | + unset($question_types[EEM_Question::QST_type_email_confirm]); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | echo wp_kses( |
193 | 193 | EEH_Form_Fields::select_input( |
194 | - 'QST_type' . $id, |
|
194 | + 'QST_type'.$id, |
|
195 | 195 | $question_types, |
196 | 196 | $question->type(), |
197 | - 'id="QST_type' . $id . '"' . $disabled_attr |
|
197 | + 'id="QST_type'.$id.'"'.$disabled_attr |
|
198 | 198 | ), |
199 | 199 | AllowedTags::getWithFormTags() |
200 | 200 | ); |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | <input id="QST_max" |
238 | 238 | class="ee-input-width--small" |
239 | 239 | <?php if ($max_max !== EE_INF) :?> |
240 | - max="<?php echo esc_attr($max_max);?>" |
|
240 | + max="<?php echo esc_attr($max_max); ?>" |
|
241 | 241 | <?php endif; ?> |
242 | 242 | min="1" |
243 | 243 | name="QST_max" |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | <?php |
323 | 323 | $count = 0; |
324 | 324 | $question_options = $question->options(); |
325 | - if (! empty($question_options)) { |
|
325 | + if ( ! empty($question_options)) { |
|
326 | 326 | foreach ($question_options as $option_id => $option) { |
327 | 327 | $disabled_attr = $has_answers || $option->get('QSO_system') |
328 | 328 | ? 'disabled' |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | /> |
357 | 357 | </td> |
358 | 358 | <td> |
359 | - <?php if (! $option->system()) { ?> |
|
359 | + <?php if ( ! $option->system()) { ?> |
|
360 | 360 | <span class="dashicons clickable dashicons-post-trash ee-icon-size-18 remove-option remove-item"> |
361 | 361 | </span> |
362 | 362 | <?php } ?> |
@@ -478,10 +478,10 @@ discard block |
||
478 | 478 | ]; |
479 | 479 | echo wp_kses( |
480 | 480 | EEH_Form_Fields::select_input( |
481 | - 'QST_required' . $id, |
|
481 | + 'QST_required'.$id, |
|
482 | 482 | $requiredOptions, |
483 | 483 | $question->required(), |
484 | - 'id="QST_required' . $id . '"' . $disabled_attr |
|
484 | + 'id="QST_required'.$id.'"'.$disabled_attr |
|
485 | 485 | ), |
486 | 486 | AllowedTags::getWithFormTags() |
487 | 487 | ); |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | ) ?> |
505 | 505 | </span> |
506 | 506 | </p> |
507 | - <?php if (! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?> |
|
507 | + <?php if ( ! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?> |
|
508 | 508 | <input type="hidden" id="QST_required" name="QST_required" value="1" /> |
509 | 509 | <p> |
510 | 510 | <span class="description" style="color:#D54E21;"> |
@@ -40,417 +40,417 @@ |
||
40 | 40 | */ |
41 | 41 | class OrganizationSettings extends FormHandler |
42 | 42 | { |
43 | - /** |
|
44 | - * @var EE_Organization_Config |
|
45 | - */ |
|
46 | - protected $organization_config; |
|
43 | + /** |
|
44 | + * @var EE_Organization_Config |
|
45 | + */ |
|
46 | + protected $organization_config; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @var EE_Core_Config |
|
50 | - */ |
|
51 | - protected $core_config; |
|
48 | + /** |
|
49 | + * @var EE_Core_Config |
|
50 | + */ |
|
51 | + protected $core_config; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @var EE_Network_Core_Config |
|
55 | - */ |
|
56 | - protected $network_core_config; |
|
53 | + /** |
|
54 | + * @var EE_Network_Core_Config |
|
55 | + */ |
|
56 | + protected $network_core_config; |
|
57 | 57 | |
58 | - /** |
|
59 | - * @var CountrySubRegionDao |
|
60 | - */ |
|
61 | - protected $countrySubRegionDao; |
|
58 | + /** |
|
59 | + * @var CountrySubRegionDao |
|
60 | + */ |
|
61 | + protected $countrySubRegionDao; |
|
62 | 62 | |
63 | - /** |
|
64 | - * Form constructor. |
|
65 | - * |
|
66 | - * @param EE_Registry $registry |
|
67 | - * @param EE_Organization_Config $organization_config |
|
68 | - * @param EE_Core_Config $core_config |
|
69 | - * @param EE_Network_Core_Config $network_core_config |
|
70 | - * @param CountrySubRegionDao $countrySubRegionDao |
|
71 | - * @throws InvalidArgumentException |
|
72 | - * @throws InvalidDataTypeException |
|
73 | - * @throws DomainException |
|
74 | - */ |
|
75 | - public function __construct( |
|
76 | - EE_Registry $registry, |
|
77 | - EE_Organization_Config $organization_config, |
|
78 | - EE_Core_Config $core_config, |
|
79 | - EE_Network_Core_Config $network_core_config, |
|
80 | - CountrySubRegionDao $countrySubRegionDao |
|
81 | - ) { |
|
82 | - $this->organization_config = $organization_config; |
|
83 | - $this->core_config = $core_config; |
|
84 | - $this->network_core_config = $network_core_config; |
|
85 | - $this->countrySubRegionDao = $countrySubRegionDao; |
|
86 | - parent::__construct( |
|
87 | - esc_html__('Your Organization Settings', 'event_espresso'), |
|
88 | - esc_html__('Your Organization Settings', 'event_espresso'), |
|
89 | - 'organization_settings', |
|
90 | - '', |
|
91 | - FormHandler::DO_NOT_SETUP_FORM, |
|
92 | - $registry |
|
93 | - ); |
|
94 | - } |
|
63 | + /** |
|
64 | + * Form constructor. |
|
65 | + * |
|
66 | + * @param EE_Registry $registry |
|
67 | + * @param EE_Organization_Config $organization_config |
|
68 | + * @param EE_Core_Config $core_config |
|
69 | + * @param EE_Network_Core_Config $network_core_config |
|
70 | + * @param CountrySubRegionDao $countrySubRegionDao |
|
71 | + * @throws InvalidArgumentException |
|
72 | + * @throws InvalidDataTypeException |
|
73 | + * @throws DomainException |
|
74 | + */ |
|
75 | + public function __construct( |
|
76 | + EE_Registry $registry, |
|
77 | + EE_Organization_Config $organization_config, |
|
78 | + EE_Core_Config $core_config, |
|
79 | + EE_Network_Core_Config $network_core_config, |
|
80 | + CountrySubRegionDao $countrySubRegionDao |
|
81 | + ) { |
|
82 | + $this->organization_config = $organization_config; |
|
83 | + $this->core_config = $core_config; |
|
84 | + $this->network_core_config = $network_core_config; |
|
85 | + $this->countrySubRegionDao = $countrySubRegionDao; |
|
86 | + parent::__construct( |
|
87 | + esc_html__('Your Organization Settings', 'event_espresso'), |
|
88 | + esc_html__('Your Organization Settings', 'event_espresso'), |
|
89 | + 'organization_settings', |
|
90 | + '', |
|
91 | + FormHandler::DO_NOT_SETUP_FORM, |
|
92 | + $registry |
|
93 | + ); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * creates and returns the actual form |
|
99 | - * |
|
100 | - * @return EE_Form_Section_Proper |
|
101 | - * @throws EE_Error |
|
102 | - * @throws InvalidArgumentException |
|
103 | - * @throws InvalidDataTypeException |
|
104 | - * @throws InvalidInterfaceException |
|
105 | - * @throws ReflectionException |
|
106 | - */ |
|
107 | - public function generate(): EE_Form_Section_Proper |
|
108 | - { |
|
109 | - $has_sub_regions = EEM_State::instance()->count( |
|
110 | - array(array('Country.CNT_ISO' => $this->organization_config->CNT_ISO)) |
|
111 | - ); |
|
112 | - return apply_filters( |
|
113 | - 'FHEE__EventEspresso_admin_pages_general_settings_OrganizationSettings__generate__form', |
|
114 | - new EE_Form_Section_Proper( |
|
115 | - array( |
|
116 | - 'name' => 'organization_settings', |
|
117 | - 'html_id' => 'organization_settings', |
|
118 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
119 | - 'subsections' => array( |
|
120 | - 'contact_information_hdr' => new EE_Form_Section_HTML( |
|
121 | - EEH_HTML::h2( |
|
122 | - esc_html__('Contact Information', 'event_espresso') |
|
123 | - . ' ' |
|
124 | - . EEH_HTML::span(EEH_Template::get_help_tab_link('contact_info_info')), |
|
125 | - '', |
|
126 | - 'contact-information-hdr' |
|
127 | - ) |
|
128 | - ), |
|
129 | - 'organization_name' => new EE_Text_Input( |
|
130 | - array( |
|
131 | - 'html_name' => 'organization_name', |
|
132 | - 'html_label_text' => esc_html__('Organization Name', 'event_espresso'), |
|
133 | - 'html_help_text' => esc_html__( |
|
134 | - 'Displayed on all emails and invoices.', |
|
135 | - 'event_espresso' |
|
136 | - ), |
|
137 | - 'default' => $this->organization_config->get_pretty('name'), |
|
138 | - 'required' => false, |
|
139 | - ) |
|
140 | - ), |
|
141 | - 'organization_address_1' => new EE_Text_Input( |
|
142 | - array( |
|
143 | - 'html_name' => 'organization_address_1', |
|
144 | - 'html_label_text' => esc_html__('Street Address', 'event_espresso'), |
|
145 | - 'default' => $this->organization_config->get_pretty('address_1'), |
|
146 | - 'required' => false, |
|
147 | - ) |
|
148 | - ), |
|
149 | - 'organization_address_2' => new EE_Text_Input( |
|
150 | - array( |
|
151 | - 'html_name' => 'organization_address_2', |
|
152 | - 'html_label_text' => esc_html__('Street Address 2', 'event_espresso'), |
|
153 | - 'default' => $this->organization_config->get_pretty('address_2'), |
|
154 | - 'required' => false, |
|
155 | - ) |
|
156 | - ), |
|
157 | - 'organization_city' => new EE_Text_Input( |
|
158 | - array( |
|
159 | - 'html_name' => 'organization_city', |
|
160 | - 'html_label_text' => esc_html__('City', 'event_espresso'), |
|
161 | - 'default' => $this->organization_config->get_pretty('city'), |
|
162 | - 'required' => false, |
|
163 | - ) |
|
164 | - ), |
|
165 | - 'organization_country' => new EE_Country_Select_Input( |
|
166 | - null, |
|
167 | - array( |
|
168 | - EE_Country_Select_Input::OPTION_GET_KEY => EE_Country_Select_Input::OPTION_GET_ALL, |
|
169 | - 'html_name' => 'organization_country', |
|
170 | - 'html_label_text' => esc_html__('Country', 'event_espresso'), |
|
171 | - 'default' => $this->organization_config->CNT_ISO, |
|
172 | - 'required' => false, |
|
173 | - 'html_help_text' => sprintf( |
|
174 | - esc_html__( |
|
175 | - '%1$sThe Country set here will have the effect of setting the currency used for all ticket prices.%2$s', |
|
176 | - 'event_espresso' |
|
177 | - ), |
|
178 | - '<span class="reminder-spn">', |
|
179 | - '</span>' |
|
180 | - ), |
|
181 | - ) |
|
182 | - ), |
|
183 | - 'organization_state' => new EE_State_Select_Input( |
|
184 | - null, |
|
185 | - array( |
|
186 | - 'html_name' => 'organization_state', |
|
187 | - 'html_label_text' => esc_html__('State/Province', 'event_espresso'), |
|
188 | - 'default' => $this->organization_config->STA_ID, |
|
189 | - 'required' => false, |
|
190 | - 'html_help_text' => empty($this->organization_config->STA_ID) || ! $has_sub_regions |
|
191 | - ? sprintf( |
|
192 | - esc_html__( |
|
193 | - 'If the States/Provinces for the selected Country do not appear in this list, then click "Save".%3$sIf data exists, then the list will be populated when the page reloads and you will be able to make a selection at that time.%3$s%1$sMake sure you click "Save" again after selecting a State/Province that has just been loaded in order to keep that selection.%2$s', |
|
194 | - 'event_espresso' |
|
195 | - ), |
|
196 | - '<span class="reminder-spn">', |
|
197 | - '</span>', |
|
198 | - '<br />' |
|
199 | - ) |
|
200 | - : '', |
|
201 | - ) |
|
202 | - ), |
|
203 | - 'organization_zip' => new EE_Text_Input( |
|
204 | - array( |
|
205 | - 'html_name' => 'organization_zip', |
|
206 | - 'html_label_text' => esc_html__('Zip/Postal Code', 'event_espresso'), |
|
207 | - 'default' => $this->organization_config->get_pretty('zip'), |
|
208 | - 'required' => false, |
|
209 | - ) |
|
210 | - ), |
|
211 | - 'organization_email' => new EE_Text_Input( |
|
212 | - array( |
|
213 | - 'html_name' => 'organization_email', |
|
214 | - 'html_label_text' => esc_html__('Primary Contact Email', 'event_espresso'), |
|
215 | - 'html_help_text' => sprintf( |
|
216 | - esc_html__( |
|
217 | - 'This is where notifications go to when you use the %1$s and %2$s shortcodes in the message templates.', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - '<code>[CO_FORMATTED_EMAIL]</code>', |
|
221 | - '<code>[CO_EMAIL]</code>' |
|
222 | - ), |
|
223 | - 'default' => $this->organization_config->get_pretty('email'), |
|
224 | - 'required' => false, |
|
225 | - ) |
|
226 | - ), |
|
227 | - 'organization_phone' => new EE_Text_Input( |
|
228 | - array( |
|
229 | - 'html_name' => 'organization_phone', |
|
230 | - 'html_label_text' => esc_html__('Phone Number', 'event_espresso'), |
|
231 | - 'html_help_text' => esc_html__( |
|
232 | - 'The phone number for your organization.', |
|
233 | - 'event_espresso' |
|
234 | - ), |
|
235 | - 'default' => $this->organization_config->get_pretty('phone'), |
|
236 | - 'required' => false, |
|
237 | - ) |
|
238 | - ), |
|
239 | - 'organization_vat' => new EE_Text_Input( |
|
240 | - array( |
|
241 | - 'html_name' => 'organization_vat', |
|
242 | - 'html_label_text' => esc_html__('VAT/Tax Number', 'event_espresso'), |
|
243 | - 'html_help_text' => esc_html__( |
|
244 | - 'The VAT/Tax Number may be displayed on invoices and receipts.', |
|
245 | - 'event_espresso' |
|
246 | - ), |
|
247 | - 'default' => $this->organization_config->get_pretty('vat'), |
|
248 | - 'required' => false, |
|
249 | - ) |
|
250 | - ), |
|
251 | - 'company_logo_hdr' => new EE_Form_Section_HTML( |
|
252 | - EEH_HTML::h2( |
|
253 | - esc_html__('Company Logo', 'event_espresso') |
|
254 | - . ' ' |
|
255 | - . EEH_HTML::span(EEH_Template::get_help_tab_link('organization_logo_info')), |
|
256 | - '', |
|
257 | - 'company-logo-hdr' |
|
258 | - ) |
|
259 | - ), |
|
260 | - 'organization_logo_url' => new EE_Admin_File_Uploader_Input( |
|
261 | - array( |
|
262 | - 'html_name' => 'organization_logo_url', |
|
263 | - 'html_label_text' => esc_html__('Upload New Logo', 'event_espresso'), |
|
264 | - 'html_help_text' => esc_html__( |
|
265 | - 'Your logo will be used on custom invoices, tickets, certificates, and payment templates.', |
|
266 | - 'event_espresso' |
|
267 | - ), |
|
268 | - 'default' => $this->organization_config->get_pretty('logo_url'), |
|
269 | - 'required' => false, |
|
270 | - ) |
|
271 | - ), |
|
272 | - 'social_links_hdr' => new EE_Form_Section_HTML( |
|
273 | - EEH_HTML::h2( |
|
274 | - esc_html__('Social Links', 'event_espresso') |
|
275 | - . ' ' |
|
276 | - . EEH_HTML::span(EEH_Template::get_help_tab_link('social_links_info')) |
|
277 | - . EEH_HTML::br() |
|
278 | - . EEH_HTML::p( |
|
279 | - esc_html__( |
|
280 | - 'Enter any links to social accounts for your organization here', |
|
281 | - 'event_espresso' |
|
282 | - ), |
|
283 | - '', |
|
284 | - 'description' |
|
285 | - ), |
|
286 | - '', |
|
287 | - 'social-links-hdr' |
|
288 | - ) |
|
289 | - ), |
|
290 | - 'organization_facebook' => new EE_Text_Input( |
|
291 | - array( |
|
292 | - 'html_name' => 'organization_facebook', |
|
293 | - 'html_label_text' => esc_html__('Facebook', 'event_espresso'), |
|
294 | - 'other_html_attributes' => ' placeholder="facebook.com/profile.name"', |
|
295 | - 'default' => $this->organization_config->get_pretty('facebook'), |
|
296 | - 'required' => false, |
|
297 | - ) |
|
298 | - ), |
|
299 | - 'organization_twitter' => new EE_Text_Input( |
|
300 | - array( |
|
301 | - 'html_name' => 'organization_twitter', |
|
302 | - 'html_label_text' => esc_html__('Twitter', 'event_espresso'), |
|
303 | - 'other_html_attributes' => ' placeholder="twitter.com/twitterhandle"', |
|
304 | - 'default' => $this->organization_config->get_pretty('twitter'), |
|
305 | - 'required' => false, |
|
306 | - ) |
|
307 | - ), |
|
308 | - 'organization_linkedin' => new EE_Text_Input( |
|
309 | - array( |
|
310 | - 'html_name' => 'organization_linkedin', |
|
311 | - 'html_label_text' => esc_html__('LinkedIn', 'event_espresso'), |
|
312 | - 'other_html_attributes' => ' placeholder="linkedin.com/in/profilename"', |
|
313 | - 'default' => $this->organization_config->get_pretty('linkedin'), |
|
314 | - 'required' => false, |
|
315 | - ) |
|
316 | - ), |
|
317 | - 'organization_pinterest' => new EE_Text_Input( |
|
318 | - array( |
|
319 | - 'html_name' => 'organization_pinterest', |
|
320 | - 'html_label_text' => esc_html__('Pinterest', 'event_espresso'), |
|
321 | - 'other_html_attributes' => ' placeholder="pinterest.com/profilename"', |
|
322 | - 'default' => $this->organization_config->get_pretty('pinterest'), |
|
323 | - 'required' => false, |
|
324 | - ) |
|
325 | - ), |
|
326 | - 'organization_instagram' => new EE_Text_Input( |
|
327 | - array( |
|
328 | - 'html_name' => 'organization_instagram', |
|
329 | - 'html_label_text' => esc_html__('Instagram', 'event_espresso'), |
|
330 | - 'other_html_attributes' => ' placeholder="instagram.com/handle"', |
|
331 | - 'default' => $this->organization_config->get_pretty('instagram'), |
|
332 | - 'required' => false, |
|
333 | - ) |
|
334 | - ), |
|
335 | - ), |
|
336 | - ) |
|
337 | - ), |
|
338 | - $this, |
|
339 | - $has_sub_regions |
|
340 | - ); |
|
341 | - } |
|
97 | + /** |
|
98 | + * creates and returns the actual form |
|
99 | + * |
|
100 | + * @return EE_Form_Section_Proper |
|
101 | + * @throws EE_Error |
|
102 | + * @throws InvalidArgumentException |
|
103 | + * @throws InvalidDataTypeException |
|
104 | + * @throws InvalidInterfaceException |
|
105 | + * @throws ReflectionException |
|
106 | + */ |
|
107 | + public function generate(): EE_Form_Section_Proper |
|
108 | + { |
|
109 | + $has_sub_regions = EEM_State::instance()->count( |
|
110 | + array(array('Country.CNT_ISO' => $this->organization_config->CNT_ISO)) |
|
111 | + ); |
|
112 | + return apply_filters( |
|
113 | + 'FHEE__EventEspresso_admin_pages_general_settings_OrganizationSettings__generate__form', |
|
114 | + new EE_Form_Section_Proper( |
|
115 | + array( |
|
116 | + 'name' => 'organization_settings', |
|
117 | + 'html_id' => 'organization_settings', |
|
118 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
119 | + 'subsections' => array( |
|
120 | + 'contact_information_hdr' => new EE_Form_Section_HTML( |
|
121 | + EEH_HTML::h2( |
|
122 | + esc_html__('Contact Information', 'event_espresso') |
|
123 | + . ' ' |
|
124 | + . EEH_HTML::span(EEH_Template::get_help_tab_link('contact_info_info')), |
|
125 | + '', |
|
126 | + 'contact-information-hdr' |
|
127 | + ) |
|
128 | + ), |
|
129 | + 'organization_name' => new EE_Text_Input( |
|
130 | + array( |
|
131 | + 'html_name' => 'organization_name', |
|
132 | + 'html_label_text' => esc_html__('Organization Name', 'event_espresso'), |
|
133 | + 'html_help_text' => esc_html__( |
|
134 | + 'Displayed on all emails and invoices.', |
|
135 | + 'event_espresso' |
|
136 | + ), |
|
137 | + 'default' => $this->organization_config->get_pretty('name'), |
|
138 | + 'required' => false, |
|
139 | + ) |
|
140 | + ), |
|
141 | + 'organization_address_1' => new EE_Text_Input( |
|
142 | + array( |
|
143 | + 'html_name' => 'organization_address_1', |
|
144 | + 'html_label_text' => esc_html__('Street Address', 'event_espresso'), |
|
145 | + 'default' => $this->organization_config->get_pretty('address_1'), |
|
146 | + 'required' => false, |
|
147 | + ) |
|
148 | + ), |
|
149 | + 'organization_address_2' => new EE_Text_Input( |
|
150 | + array( |
|
151 | + 'html_name' => 'organization_address_2', |
|
152 | + 'html_label_text' => esc_html__('Street Address 2', 'event_espresso'), |
|
153 | + 'default' => $this->organization_config->get_pretty('address_2'), |
|
154 | + 'required' => false, |
|
155 | + ) |
|
156 | + ), |
|
157 | + 'organization_city' => new EE_Text_Input( |
|
158 | + array( |
|
159 | + 'html_name' => 'organization_city', |
|
160 | + 'html_label_text' => esc_html__('City', 'event_espresso'), |
|
161 | + 'default' => $this->organization_config->get_pretty('city'), |
|
162 | + 'required' => false, |
|
163 | + ) |
|
164 | + ), |
|
165 | + 'organization_country' => new EE_Country_Select_Input( |
|
166 | + null, |
|
167 | + array( |
|
168 | + EE_Country_Select_Input::OPTION_GET_KEY => EE_Country_Select_Input::OPTION_GET_ALL, |
|
169 | + 'html_name' => 'organization_country', |
|
170 | + 'html_label_text' => esc_html__('Country', 'event_espresso'), |
|
171 | + 'default' => $this->organization_config->CNT_ISO, |
|
172 | + 'required' => false, |
|
173 | + 'html_help_text' => sprintf( |
|
174 | + esc_html__( |
|
175 | + '%1$sThe Country set here will have the effect of setting the currency used for all ticket prices.%2$s', |
|
176 | + 'event_espresso' |
|
177 | + ), |
|
178 | + '<span class="reminder-spn">', |
|
179 | + '</span>' |
|
180 | + ), |
|
181 | + ) |
|
182 | + ), |
|
183 | + 'organization_state' => new EE_State_Select_Input( |
|
184 | + null, |
|
185 | + array( |
|
186 | + 'html_name' => 'organization_state', |
|
187 | + 'html_label_text' => esc_html__('State/Province', 'event_espresso'), |
|
188 | + 'default' => $this->organization_config->STA_ID, |
|
189 | + 'required' => false, |
|
190 | + 'html_help_text' => empty($this->organization_config->STA_ID) || ! $has_sub_regions |
|
191 | + ? sprintf( |
|
192 | + esc_html__( |
|
193 | + 'If the States/Provinces for the selected Country do not appear in this list, then click "Save".%3$sIf data exists, then the list will be populated when the page reloads and you will be able to make a selection at that time.%3$s%1$sMake sure you click "Save" again after selecting a State/Province that has just been loaded in order to keep that selection.%2$s', |
|
194 | + 'event_espresso' |
|
195 | + ), |
|
196 | + '<span class="reminder-spn">', |
|
197 | + '</span>', |
|
198 | + '<br />' |
|
199 | + ) |
|
200 | + : '', |
|
201 | + ) |
|
202 | + ), |
|
203 | + 'organization_zip' => new EE_Text_Input( |
|
204 | + array( |
|
205 | + 'html_name' => 'organization_zip', |
|
206 | + 'html_label_text' => esc_html__('Zip/Postal Code', 'event_espresso'), |
|
207 | + 'default' => $this->organization_config->get_pretty('zip'), |
|
208 | + 'required' => false, |
|
209 | + ) |
|
210 | + ), |
|
211 | + 'organization_email' => new EE_Text_Input( |
|
212 | + array( |
|
213 | + 'html_name' => 'organization_email', |
|
214 | + 'html_label_text' => esc_html__('Primary Contact Email', 'event_espresso'), |
|
215 | + 'html_help_text' => sprintf( |
|
216 | + esc_html__( |
|
217 | + 'This is where notifications go to when you use the %1$s and %2$s shortcodes in the message templates.', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + '<code>[CO_FORMATTED_EMAIL]</code>', |
|
221 | + '<code>[CO_EMAIL]</code>' |
|
222 | + ), |
|
223 | + 'default' => $this->organization_config->get_pretty('email'), |
|
224 | + 'required' => false, |
|
225 | + ) |
|
226 | + ), |
|
227 | + 'organization_phone' => new EE_Text_Input( |
|
228 | + array( |
|
229 | + 'html_name' => 'organization_phone', |
|
230 | + 'html_label_text' => esc_html__('Phone Number', 'event_espresso'), |
|
231 | + 'html_help_text' => esc_html__( |
|
232 | + 'The phone number for your organization.', |
|
233 | + 'event_espresso' |
|
234 | + ), |
|
235 | + 'default' => $this->organization_config->get_pretty('phone'), |
|
236 | + 'required' => false, |
|
237 | + ) |
|
238 | + ), |
|
239 | + 'organization_vat' => new EE_Text_Input( |
|
240 | + array( |
|
241 | + 'html_name' => 'organization_vat', |
|
242 | + 'html_label_text' => esc_html__('VAT/Tax Number', 'event_espresso'), |
|
243 | + 'html_help_text' => esc_html__( |
|
244 | + 'The VAT/Tax Number may be displayed on invoices and receipts.', |
|
245 | + 'event_espresso' |
|
246 | + ), |
|
247 | + 'default' => $this->organization_config->get_pretty('vat'), |
|
248 | + 'required' => false, |
|
249 | + ) |
|
250 | + ), |
|
251 | + 'company_logo_hdr' => new EE_Form_Section_HTML( |
|
252 | + EEH_HTML::h2( |
|
253 | + esc_html__('Company Logo', 'event_espresso') |
|
254 | + . ' ' |
|
255 | + . EEH_HTML::span(EEH_Template::get_help_tab_link('organization_logo_info')), |
|
256 | + '', |
|
257 | + 'company-logo-hdr' |
|
258 | + ) |
|
259 | + ), |
|
260 | + 'organization_logo_url' => new EE_Admin_File_Uploader_Input( |
|
261 | + array( |
|
262 | + 'html_name' => 'organization_logo_url', |
|
263 | + 'html_label_text' => esc_html__('Upload New Logo', 'event_espresso'), |
|
264 | + 'html_help_text' => esc_html__( |
|
265 | + 'Your logo will be used on custom invoices, tickets, certificates, and payment templates.', |
|
266 | + 'event_espresso' |
|
267 | + ), |
|
268 | + 'default' => $this->organization_config->get_pretty('logo_url'), |
|
269 | + 'required' => false, |
|
270 | + ) |
|
271 | + ), |
|
272 | + 'social_links_hdr' => new EE_Form_Section_HTML( |
|
273 | + EEH_HTML::h2( |
|
274 | + esc_html__('Social Links', 'event_espresso') |
|
275 | + . ' ' |
|
276 | + . EEH_HTML::span(EEH_Template::get_help_tab_link('social_links_info')) |
|
277 | + . EEH_HTML::br() |
|
278 | + . EEH_HTML::p( |
|
279 | + esc_html__( |
|
280 | + 'Enter any links to social accounts for your organization here', |
|
281 | + 'event_espresso' |
|
282 | + ), |
|
283 | + '', |
|
284 | + 'description' |
|
285 | + ), |
|
286 | + '', |
|
287 | + 'social-links-hdr' |
|
288 | + ) |
|
289 | + ), |
|
290 | + 'organization_facebook' => new EE_Text_Input( |
|
291 | + array( |
|
292 | + 'html_name' => 'organization_facebook', |
|
293 | + 'html_label_text' => esc_html__('Facebook', 'event_espresso'), |
|
294 | + 'other_html_attributes' => ' placeholder="facebook.com/profile.name"', |
|
295 | + 'default' => $this->organization_config->get_pretty('facebook'), |
|
296 | + 'required' => false, |
|
297 | + ) |
|
298 | + ), |
|
299 | + 'organization_twitter' => new EE_Text_Input( |
|
300 | + array( |
|
301 | + 'html_name' => 'organization_twitter', |
|
302 | + 'html_label_text' => esc_html__('Twitter', 'event_espresso'), |
|
303 | + 'other_html_attributes' => ' placeholder="twitter.com/twitterhandle"', |
|
304 | + 'default' => $this->organization_config->get_pretty('twitter'), |
|
305 | + 'required' => false, |
|
306 | + ) |
|
307 | + ), |
|
308 | + 'organization_linkedin' => new EE_Text_Input( |
|
309 | + array( |
|
310 | + 'html_name' => 'organization_linkedin', |
|
311 | + 'html_label_text' => esc_html__('LinkedIn', 'event_espresso'), |
|
312 | + 'other_html_attributes' => ' placeholder="linkedin.com/in/profilename"', |
|
313 | + 'default' => $this->organization_config->get_pretty('linkedin'), |
|
314 | + 'required' => false, |
|
315 | + ) |
|
316 | + ), |
|
317 | + 'organization_pinterest' => new EE_Text_Input( |
|
318 | + array( |
|
319 | + 'html_name' => 'organization_pinterest', |
|
320 | + 'html_label_text' => esc_html__('Pinterest', 'event_espresso'), |
|
321 | + 'other_html_attributes' => ' placeholder="pinterest.com/profilename"', |
|
322 | + 'default' => $this->organization_config->get_pretty('pinterest'), |
|
323 | + 'required' => false, |
|
324 | + ) |
|
325 | + ), |
|
326 | + 'organization_instagram' => new EE_Text_Input( |
|
327 | + array( |
|
328 | + 'html_name' => 'organization_instagram', |
|
329 | + 'html_label_text' => esc_html__('Instagram', 'event_espresso'), |
|
330 | + 'other_html_attributes' => ' placeholder="instagram.com/handle"', |
|
331 | + 'default' => $this->organization_config->get_pretty('instagram'), |
|
332 | + 'required' => false, |
|
333 | + ) |
|
334 | + ), |
|
335 | + ), |
|
336 | + ) |
|
337 | + ), |
|
338 | + $this, |
|
339 | + $has_sub_regions |
|
340 | + ); |
|
341 | + } |
|
342 | 342 | |
343 | 343 | |
344 | - /** |
|
345 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
346 | - * returns a string of HTML that can be directly echoed in a template |
|
347 | - * |
|
348 | - * @return string |
|
349 | - * @throws EE_Error |
|
350 | - * @throws InvalidArgumentException |
|
351 | - * @throws InvalidDataTypeException |
|
352 | - * @throws InvalidInterfaceException |
|
353 | - * @throws LogicException |
|
354 | - */ |
|
355 | - public function display() |
|
356 | - { |
|
357 | - $this->form()->enqueue_js(); |
|
358 | - return parent::display(); |
|
359 | - } |
|
344 | + /** |
|
345 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
346 | + * returns a string of HTML that can be directly echoed in a template |
|
347 | + * |
|
348 | + * @return string |
|
349 | + * @throws EE_Error |
|
350 | + * @throws InvalidArgumentException |
|
351 | + * @throws InvalidDataTypeException |
|
352 | + * @throws InvalidInterfaceException |
|
353 | + * @throws LogicException |
|
354 | + */ |
|
355 | + public function display() |
|
356 | + { |
|
357 | + $this->form()->enqueue_js(); |
|
358 | + return parent::display(); |
|
359 | + } |
|
360 | 360 | |
361 | 361 | |
362 | - /** |
|
363 | - * handles processing the form submission |
|
364 | - * returns true or false depending on whether the form was processed successfully or not |
|
365 | - * |
|
366 | - * @param array $form_data |
|
367 | - * @return bool |
|
368 | - * @throws InvalidFormSubmissionException |
|
369 | - * @throws EE_Error |
|
370 | - * @throws LogicException |
|
371 | - * @throws InvalidArgumentException |
|
372 | - * @throws InvalidDataTypeException |
|
373 | - * @throws ReflectionException |
|
374 | - */ |
|
375 | - public function process($form_data = array()): bool |
|
376 | - { |
|
377 | - // process form |
|
378 | - $valid_data = (array) parent::process($form_data); |
|
379 | - if (empty($valid_data)) { |
|
380 | - return false; |
|
381 | - } |
|
362 | + /** |
|
363 | + * handles processing the form submission |
|
364 | + * returns true or false depending on whether the form was processed successfully or not |
|
365 | + * |
|
366 | + * @param array $form_data |
|
367 | + * @return bool |
|
368 | + * @throws InvalidFormSubmissionException |
|
369 | + * @throws EE_Error |
|
370 | + * @throws LogicException |
|
371 | + * @throws InvalidArgumentException |
|
372 | + * @throws InvalidDataTypeException |
|
373 | + * @throws ReflectionException |
|
374 | + */ |
|
375 | + public function process($form_data = array()): bool |
|
376 | + { |
|
377 | + // process form |
|
378 | + $valid_data = (array) parent::process($form_data); |
|
379 | + if (empty($valid_data)) { |
|
380 | + return false; |
|
381 | + } |
|
382 | 382 | |
383 | - if (is_main_site()) { |
|
384 | - $this->network_core_config->site_license_key = isset($form_data['ee_site_license_key']) |
|
385 | - ? sanitize_text_field($form_data['ee_site_license_key']) |
|
386 | - : $this->network_core_config->site_license_key; |
|
387 | - } |
|
388 | - $this->organization_config->name = isset($form_data['organization_name']) |
|
389 | - ? sanitize_text_field($form_data['organization_name']) |
|
390 | - : $this->organization_config->name; |
|
391 | - $this->organization_config->address_1 = isset($form_data['organization_address_1']) |
|
392 | - ? sanitize_text_field($form_data['organization_address_1']) |
|
393 | - : $this->organization_config->address_1; |
|
394 | - $this->organization_config->address_2 = isset($form_data['organization_address_2']) |
|
395 | - ? sanitize_text_field($form_data['organization_address_2']) |
|
396 | - : $this->organization_config->address_2; |
|
397 | - $this->organization_config->city = isset($form_data['organization_city']) |
|
398 | - ? sanitize_text_field($form_data['organization_city']) |
|
399 | - : $this->organization_config->city; |
|
400 | - $this->organization_config->STA_ID = isset($form_data['organization_state']) |
|
401 | - ? absint($form_data['organization_state']) |
|
402 | - : $this->organization_config->STA_ID; |
|
403 | - $this->organization_config->CNT_ISO = isset($form_data['organization_country']) |
|
404 | - ? sanitize_text_field($form_data['organization_country']) |
|
405 | - : $this->organization_config->CNT_ISO; |
|
406 | - $this->organization_config->zip = isset($form_data['organization_zip']) |
|
407 | - ? sanitize_text_field($form_data['organization_zip']) |
|
408 | - : $this->organization_config->zip; |
|
409 | - $this->organization_config->email = isset($form_data['organization_email']) |
|
410 | - ? sanitize_email($form_data['organization_email']) |
|
411 | - : $this->organization_config->email; |
|
412 | - $this->organization_config->vat = isset($form_data['organization_vat']) |
|
413 | - ? sanitize_text_field($form_data['organization_vat']) |
|
414 | - : $this->organization_config->vat; |
|
415 | - $this->organization_config->phone = isset($form_data['organization_phone']) |
|
416 | - ? sanitize_text_field($form_data['organization_phone']) |
|
417 | - : $this->organization_config->phone; |
|
418 | - $this->organization_config->logo_url = isset($form_data['organization_logo_url']) |
|
419 | - ? esc_url_raw($form_data['organization_logo_url']) |
|
420 | - : $this->organization_config->logo_url; |
|
421 | - $this->organization_config->facebook = isset($form_data['organization_facebook']) |
|
422 | - ? esc_url_raw($form_data['organization_facebook']) |
|
423 | - : $this->organization_config->facebook; |
|
424 | - $this->organization_config->twitter = isset($form_data['organization_twitter']) |
|
425 | - ? esc_url_raw($form_data['organization_twitter']) |
|
426 | - : $this->organization_config->twitter; |
|
427 | - $this->organization_config->linkedin = isset($form_data['organization_linkedin']) |
|
428 | - ? esc_url_raw($form_data['organization_linkedin']) |
|
429 | - : $this->organization_config->linkedin; |
|
430 | - $this->organization_config->pinterest = isset($form_data['organization_pinterest']) |
|
431 | - ? esc_url_raw($form_data['organization_pinterest']) |
|
432 | - : $this->organization_config->pinterest; |
|
433 | - $this->organization_config->google = isset($form_data['organization_google']) |
|
434 | - ? esc_url_raw($form_data['organization_google']) |
|
435 | - : $this->organization_config->google; |
|
436 | - $this->organization_config->instagram = isset($form_data['organization_instagram']) |
|
437 | - ? esc_url_raw($form_data['organization_instagram']) |
|
438 | - : $this->organization_config->instagram; |
|
439 | - $this->core_config->ee_ueip_optin = isset($form_data[ EE_Core_Config::OPTION_NAME_UXIP ][0]) |
|
440 | - ? filter_var($form_data[ EE_Core_Config::OPTION_NAME_UXIP ][0], FILTER_VALIDATE_BOOLEAN) |
|
441 | - : false; |
|
442 | - $this->core_config->ee_ueip_has_notified = true; |
|
383 | + if (is_main_site()) { |
|
384 | + $this->network_core_config->site_license_key = isset($form_data['ee_site_license_key']) |
|
385 | + ? sanitize_text_field($form_data['ee_site_license_key']) |
|
386 | + : $this->network_core_config->site_license_key; |
|
387 | + } |
|
388 | + $this->organization_config->name = isset($form_data['organization_name']) |
|
389 | + ? sanitize_text_field($form_data['organization_name']) |
|
390 | + : $this->organization_config->name; |
|
391 | + $this->organization_config->address_1 = isset($form_data['organization_address_1']) |
|
392 | + ? sanitize_text_field($form_data['organization_address_1']) |
|
393 | + : $this->organization_config->address_1; |
|
394 | + $this->organization_config->address_2 = isset($form_data['organization_address_2']) |
|
395 | + ? sanitize_text_field($form_data['organization_address_2']) |
|
396 | + : $this->organization_config->address_2; |
|
397 | + $this->organization_config->city = isset($form_data['organization_city']) |
|
398 | + ? sanitize_text_field($form_data['organization_city']) |
|
399 | + : $this->organization_config->city; |
|
400 | + $this->organization_config->STA_ID = isset($form_data['organization_state']) |
|
401 | + ? absint($form_data['organization_state']) |
|
402 | + : $this->organization_config->STA_ID; |
|
403 | + $this->organization_config->CNT_ISO = isset($form_data['organization_country']) |
|
404 | + ? sanitize_text_field($form_data['organization_country']) |
|
405 | + : $this->organization_config->CNT_ISO; |
|
406 | + $this->organization_config->zip = isset($form_data['organization_zip']) |
|
407 | + ? sanitize_text_field($form_data['organization_zip']) |
|
408 | + : $this->organization_config->zip; |
|
409 | + $this->organization_config->email = isset($form_data['organization_email']) |
|
410 | + ? sanitize_email($form_data['organization_email']) |
|
411 | + : $this->organization_config->email; |
|
412 | + $this->organization_config->vat = isset($form_data['organization_vat']) |
|
413 | + ? sanitize_text_field($form_data['organization_vat']) |
|
414 | + : $this->organization_config->vat; |
|
415 | + $this->organization_config->phone = isset($form_data['organization_phone']) |
|
416 | + ? sanitize_text_field($form_data['organization_phone']) |
|
417 | + : $this->organization_config->phone; |
|
418 | + $this->organization_config->logo_url = isset($form_data['organization_logo_url']) |
|
419 | + ? esc_url_raw($form_data['organization_logo_url']) |
|
420 | + : $this->organization_config->logo_url; |
|
421 | + $this->organization_config->facebook = isset($form_data['organization_facebook']) |
|
422 | + ? esc_url_raw($form_data['organization_facebook']) |
|
423 | + : $this->organization_config->facebook; |
|
424 | + $this->organization_config->twitter = isset($form_data['organization_twitter']) |
|
425 | + ? esc_url_raw($form_data['organization_twitter']) |
|
426 | + : $this->organization_config->twitter; |
|
427 | + $this->organization_config->linkedin = isset($form_data['organization_linkedin']) |
|
428 | + ? esc_url_raw($form_data['organization_linkedin']) |
|
429 | + : $this->organization_config->linkedin; |
|
430 | + $this->organization_config->pinterest = isset($form_data['organization_pinterest']) |
|
431 | + ? esc_url_raw($form_data['organization_pinterest']) |
|
432 | + : $this->organization_config->pinterest; |
|
433 | + $this->organization_config->google = isset($form_data['organization_google']) |
|
434 | + ? esc_url_raw($form_data['organization_google']) |
|
435 | + : $this->organization_config->google; |
|
436 | + $this->organization_config->instagram = isset($form_data['organization_instagram']) |
|
437 | + ? esc_url_raw($form_data['organization_instagram']) |
|
438 | + : $this->organization_config->instagram; |
|
439 | + $this->core_config->ee_ueip_optin = isset($form_data[ EE_Core_Config::OPTION_NAME_UXIP ][0]) |
|
440 | + ? filter_var($form_data[ EE_Core_Config::OPTION_NAME_UXIP ][0], FILTER_VALIDATE_BOOLEAN) |
|
441 | + : false; |
|
442 | + $this->core_config->ee_ueip_has_notified = true; |
|
443 | 443 | |
444 | - $this->registry->CFG->currency = new EE_Currency_Config( |
|
445 | - $this->organization_config->CNT_ISO |
|
446 | - ); |
|
447 | - /** @var EE_Country $country */ |
|
448 | - $country = EEM_Country::instance()->get_one_by_ID($this->organization_config->CNT_ISO); |
|
449 | - if ($country instanceof EE_Country) { |
|
450 | - $country->set('CNT_active', 1); |
|
451 | - $country->save(); |
|
452 | - $this->countrySubRegionDao->saveCountrySubRegions($country); |
|
453 | - } |
|
454 | - return true; |
|
455 | - } |
|
444 | + $this->registry->CFG->currency = new EE_Currency_Config( |
|
445 | + $this->organization_config->CNT_ISO |
|
446 | + ); |
|
447 | + /** @var EE_Country $country */ |
|
448 | + $country = EEM_Country::instance()->get_one_by_ID($this->organization_config->CNT_ISO); |
|
449 | + if ($country instanceof EE_Country) { |
|
450 | + $country->set('CNT_active', 1); |
|
451 | + $country->save(); |
|
452 | + $this->countrySubRegionDao->saveCountrySubRegions($country); |
|
453 | + } |
|
454 | + return true; |
|
455 | + } |
|
456 | 456 | } |
@@ -23,356 +23,356 @@ |
||
23 | 23 | */ |
24 | 24 | class EE_Brewing_Regular extends EE_BASE implements InterminableInterface |
25 | 25 | { |
26 | - /** |
|
27 | - * @var EE_Dependency_Map |
|
28 | - */ |
|
29 | - protected $dependency_map; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var LoaderInterface |
|
33 | - */ |
|
34 | - protected $loader; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var TableAnalysis |
|
38 | - */ |
|
39 | - protected $_table_analysis; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * EE_Brewing_Regular constructor. |
|
44 | - * |
|
45 | - * @param EE_Dependency_Map $dependency_map |
|
46 | - * @param LoaderInterface $loader |
|
47 | - * @param TableAnalysis $table_analysis |
|
48 | - */ |
|
49 | - public function __construct( |
|
50 | - EE_Dependency_Map $dependency_map, |
|
51 | - LoaderInterface $loader, |
|
52 | - TableAnalysis $table_analysis |
|
53 | - ) { |
|
54 | - $this->dependency_map = $dependency_map; |
|
55 | - $this->loader = $loader; |
|
56 | - $this->_table_analysis = $table_analysis; |
|
57 | - if (defined('EE_CAFF_PATH')) { |
|
58 | - // defined some new constants related to caffeinated folder |
|
59 | - define('EE_CAF_URL', EE_PLUGIN_DIR_URL . 'caffeinated/'); |
|
60 | - define('EE_CAF_CORE', EE_CAFF_PATH . 'core/'); |
|
61 | - define('EE_CAF_LIBRARIES', EE_CAF_CORE . 'libraries/'); |
|
62 | - define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH . 'payment_methods/'); |
|
63 | - } |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @throws EE_Error |
|
69 | - */ |
|
70 | - public function caffeinated() |
|
71 | - { |
|
72 | - $this->setInitializationHooks(); |
|
73 | - $this->setApiRegistrationHooks(); |
|
74 | - $this->setSwitchHooks(); |
|
75 | - $this->setDefaultFilterHooks(); |
|
76 | - // caffeinated constructed |
|
77 | - do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - public function initializePUE() |
|
82 | - { |
|
83 | - $this->dependency_map->registerDependencies( |
|
84 | - PueLicensingManager::class, |
|
85 | - [ |
|
86 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
87 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
88 | - ] |
|
89 | - ); |
|
90 | - /** @var PueLicensingManager $pue_manager */ |
|
91 | - $pue_manager = $this->loader->getShared(PueLicensingManager::class); |
|
92 | - $pue_manager->registerDependencies(); |
|
93 | - $pue_manager->registerHooks(); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * Various hooks used for extending features via registration of modules or extensions. |
|
99 | - * |
|
100 | - * @throws EE_Error |
|
101 | - */ |
|
102 | - private function setApiRegistrationHooks() |
|
103 | - { |
|
104 | - add_filter( |
|
105 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
106 | - [$this, 'caffeinated_modules_to_register'] |
|
107 | - ); |
|
108 | - add_filter('FHEE__EE_Registry__load_helper__helper_paths', [$this, 'caf_helper_paths'], 10); |
|
109 | - add_filter( |
|
110 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
111 | - function () { |
|
112 | - EE_Register_Payment_Method::register( |
|
113 | - 'caffeinated_payment_methods', |
|
114 | - [ |
|
115 | - 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR), |
|
116 | - ] |
|
117 | - ); |
|
118 | - } |
|
119 | - ); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * Various hooks used for modifying initialization or activation processes. |
|
125 | - */ |
|
126 | - private function setInitializationHooks() |
|
127 | - { |
|
128 | - // activation |
|
129 | - add_action('AHEE__EEH_Activation__initialize_db_content', [$this, 'initialize_caf_db_content']); |
|
130 | - // load caff init |
|
131 | - add_action('AHEE__EE_System__set_hooks_for_core', [$this, 'caffeinated_init']); |
|
132 | - // load caff scripts |
|
133 | - add_action('wp_enqueue_scripts', [$this, 'enqueue_caffeinated_scripts'], 10); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * Various hooks used for switch (on/off) type filters. |
|
139 | - */ |
|
140 | - private function setSwitchHooks() |
|
141 | - { |
|
142 | - // remove the "powered by" credit link from receipts and invoices |
|
143 | - add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
144 | - // seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
145 | - add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * Various filters for affecting default configuration values in the caffeinated |
|
151 | - * context. |
|
152 | - */ |
|
153 | - private function setDefaultFilterHooks() |
|
154 | - { |
|
155 | - add_filter( |
|
156 | - 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
157 | - '__return_true' |
|
158 | - ); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
164 | - * |
|
165 | - * @param array $paths original helper paths array |
|
166 | - * @return array new array of paths |
|
167 | - */ |
|
168 | - public function caf_helper_paths(array $paths): array |
|
169 | - { |
|
170 | - $paths[] = EE_CAF_CORE . 'helpers/'; |
|
171 | - return $paths; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
177 | - * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
178 | - * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
179 | - * This action should only be called when EE 4.x.0.P is initially activated. |
|
180 | - * Right now the only CAF content are these global prices. If there's more in the future, then |
|
181 | - * we should probably create a caf file to contain it all instead just a function like this. |
|
182 | - * Right now, we ASSUME the only price types in the system are default ones |
|
183 | - * |
|
184 | - * @global wpdb $wpdb |
|
185 | - */ |
|
186 | - public function initialize_caf_db_content() |
|
187 | - { |
|
188 | - global $wpdb; |
|
189 | - // use same method of getting creator id as the version introducing the change |
|
190 | - $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
191 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
192 | - $price_table = $wpdb->prefix . "esp_price"; |
|
193 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
194 | - $SQL = |
|
195 | - 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types |
|
196 | - $tax_price_type_count = $wpdb->get_var($SQL); |
|
197 | - if ($tax_price_type_count <= 1) { |
|
198 | - $wpdb->insert( |
|
199 | - $price_type_table, |
|
200 | - [ |
|
201 | - 'PRT_name' => esc_html__("Regional Tax", "event_espresso"), |
|
202 | - 'PBT_ID' => 4, |
|
203 | - 'PRT_is_percent' => true, |
|
204 | - 'PRT_order' => 60, |
|
205 | - 'PRT_deleted' => false, |
|
206 | - 'PRT_wp_user' => $default_creator_id, |
|
207 | - ], |
|
208 | - [ |
|
209 | - '%s',// PRT_name |
|
210 | - '%d',// PBT_id |
|
211 | - '%d',// PRT_is_percent |
|
212 | - '%d',// PRT_order |
|
213 | - '%d',// PRT_deleted |
|
214 | - '%d', // PRT_wp_user |
|
215 | - ] |
|
216 | - ); |
|
217 | - // federal tax |
|
218 | - $result = $wpdb->insert( |
|
219 | - $price_type_table, |
|
220 | - [ |
|
221 | - 'PRT_name' => esc_html__("Federal Tax", "event_espresso"), |
|
222 | - 'PBT_ID' => 4, |
|
223 | - 'PRT_is_percent' => true, |
|
224 | - 'PRT_order' => 70, |
|
225 | - 'PRT_deleted' => false, |
|
226 | - 'PRT_wp_user' => $default_creator_id, |
|
227 | - ], |
|
228 | - [ |
|
229 | - '%s',// PRT_name |
|
230 | - '%d',// PBT_id |
|
231 | - '%d',// PRT_is_percent |
|
232 | - '%d',// PRT_order |
|
233 | - '%d',// PRT_deleted |
|
234 | - '%d' // PRT_wp_user |
|
235 | - ] |
|
236 | - ); |
|
237 | - if ($result) { |
|
238 | - $wpdb->insert( |
|
239 | - $price_table, |
|
240 | - [ |
|
241 | - 'PRT_ID' => $wpdb->insert_id, |
|
242 | - 'PRC_amount' => 15.00, |
|
243 | - 'PRC_name' => esc_html__("Sales Tax", "event_espresso"), |
|
244 | - 'PRC_desc' => '', |
|
245 | - 'PRC_is_default' => true, |
|
246 | - 'PRC_overrides' => null, |
|
247 | - 'PRC_deleted' => false, |
|
248 | - 'PRC_order' => 50, |
|
249 | - 'PRC_parent' => null, |
|
250 | - 'PRC_wp_user' => $default_creator_id, |
|
251 | - ], |
|
252 | - [ |
|
253 | - '%d',// PRT_id |
|
254 | - '%f',// PRC_amount |
|
255 | - '%s',// PRC_name |
|
256 | - '%s',// PRC_desc |
|
257 | - '%d',// PRC_is_default |
|
258 | - '%d',// PRC_overrides |
|
259 | - '%d',// PRC_deleted |
|
260 | - '%d',// PRC_order |
|
261 | - '%d',// PRC_parent |
|
262 | - '%d' // PRC_wp_user |
|
263 | - ] |
|
264 | - ); |
|
265 | - } |
|
266 | - } |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * caffeinated_modules_to_register |
|
273 | - * |
|
274 | - * @access public |
|
275 | - * @param array $modules_to_register |
|
276 | - * @return array |
|
277 | - */ |
|
278 | - public function caffeinated_modules_to_register(array $modules_to_register = []): array |
|
279 | - { |
|
280 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
281 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules/*', GLOB_ONLYDIR); |
|
282 | - if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
283 | - $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
284 | - } |
|
285 | - } |
|
286 | - return $modules_to_register; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * @throws EE_Error |
|
292 | - * @throws InvalidArgumentException |
|
293 | - * @throws ReflectionException |
|
294 | - * @throws InvalidDataTypeException |
|
295 | - * @throws InvalidInterfaceException |
|
296 | - */ |
|
297 | - public function caffeinated_init() |
|
298 | - { |
|
299 | - // Custom Post Type hooks |
|
300 | - add_filter( |
|
301 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
302 | - [$this, 'filter_taxonomies'] |
|
303 | - ); |
|
304 | - add_filter( |
|
305 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
306 | - [$this, 'filter_cpts'] |
|
307 | - ); |
|
308 | - add_filter( |
|
309 | - 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', |
|
310 | - [$this, 'nav_metabox_items'] |
|
311 | - ); |
|
312 | - EE_Registry::instance()->load_file( |
|
313 | - EE_CAFF_PATH, |
|
314 | - 'EE_Caf_Messages', |
|
315 | - 'class', |
|
316 | - [], |
|
317 | - false |
|
318 | - ); |
|
319 | - // caffeinated_init__complete hook |
|
320 | - do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - public function enqueue_caffeinated_scripts() |
|
325 | - { |
|
326 | - // sound of crickets... |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * callbacks below here |
|
332 | - * |
|
333 | - * @param array $taxonomy_array |
|
334 | - * @return array |
|
335 | - */ |
|
336 | - public function filter_taxonomies(array $taxonomy_array): array |
|
337 | - { |
|
338 | - $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
339 | - return $taxonomy_array; |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * @param array $cpt_array |
|
345 | - * @return array |
|
346 | - */ |
|
347 | - public function filter_cpts(array $cpt_array): array |
|
348 | - { |
|
349 | - $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
350 | - return $cpt_array; |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * @param array $menu_items |
|
356 | - * @return array |
|
357 | - */ |
|
358 | - public function nav_metabox_items(array $menu_items): array |
|
359 | - { |
|
360 | - $menu_items[] = [ |
|
361 | - 'title' => esc_html__('Venue List', 'event_espresso'), |
|
362 | - 'url' => get_post_type_archive_link('espresso_venues'), |
|
363 | - 'description' => esc_html__('Archive page for all venues.', 'event_espresso'), |
|
364 | - ]; |
|
365 | - return $menu_items; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * Gets the injected table analyzer, or throws an exception |
|
371 | - * |
|
372 | - * @return TableAnalysis |
|
373 | - */ |
|
374 | - protected function _get_table_analysis(): TableAnalysis |
|
375 | - { |
|
376 | - return $this->_table_analysis; |
|
377 | - } |
|
26 | + /** |
|
27 | + * @var EE_Dependency_Map |
|
28 | + */ |
|
29 | + protected $dependency_map; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var LoaderInterface |
|
33 | + */ |
|
34 | + protected $loader; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var TableAnalysis |
|
38 | + */ |
|
39 | + protected $_table_analysis; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * EE_Brewing_Regular constructor. |
|
44 | + * |
|
45 | + * @param EE_Dependency_Map $dependency_map |
|
46 | + * @param LoaderInterface $loader |
|
47 | + * @param TableAnalysis $table_analysis |
|
48 | + */ |
|
49 | + public function __construct( |
|
50 | + EE_Dependency_Map $dependency_map, |
|
51 | + LoaderInterface $loader, |
|
52 | + TableAnalysis $table_analysis |
|
53 | + ) { |
|
54 | + $this->dependency_map = $dependency_map; |
|
55 | + $this->loader = $loader; |
|
56 | + $this->_table_analysis = $table_analysis; |
|
57 | + if (defined('EE_CAFF_PATH')) { |
|
58 | + // defined some new constants related to caffeinated folder |
|
59 | + define('EE_CAF_URL', EE_PLUGIN_DIR_URL . 'caffeinated/'); |
|
60 | + define('EE_CAF_CORE', EE_CAFF_PATH . 'core/'); |
|
61 | + define('EE_CAF_LIBRARIES', EE_CAF_CORE . 'libraries/'); |
|
62 | + define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH . 'payment_methods/'); |
|
63 | + } |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @throws EE_Error |
|
69 | + */ |
|
70 | + public function caffeinated() |
|
71 | + { |
|
72 | + $this->setInitializationHooks(); |
|
73 | + $this->setApiRegistrationHooks(); |
|
74 | + $this->setSwitchHooks(); |
|
75 | + $this->setDefaultFilterHooks(); |
|
76 | + // caffeinated constructed |
|
77 | + do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + public function initializePUE() |
|
82 | + { |
|
83 | + $this->dependency_map->registerDependencies( |
|
84 | + PueLicensingManager::class, |
|
85 | + [ |
|
86 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
87 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
88 | + ] |
|
89 | + ); |
|
90 | + /** @var PueLicensingManager $pue_manager */ |
|
91 | + $pue_manager = $this->loader->getShared(PueLicensingManager::class); |
|
92 | + $pue_manager->registerDependencies(); |
|
93 | + $pue_manager->registerHooks(); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * Various hooks used for extending features via registration of modules or extensions. |
|
99 | + * |
|
100 | + * @throws EE_Error |
|
101 | + */ |
|
102 | + private function setApiRegistrationHooks() |
|
103 | + { |
|
104 | + add_filter( |
|
105 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
106 | + [$this, 'caffeinated_modules_to_register'] |
|
107 | + ); |
|
108 | + add_filter('FHEE__EE_Registry__load_helper__helper_paths', [$this, 'caf_helper_paths'], 10); |
|
109 | + add_filter( |
|
110 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
111 | + function () { |
|
112 | + EE_Register_Payment_Method::register( |
|
113 | + 'caffeinated_payment_methods', |
|
114 | + [ |
|
115 | + 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR), |
|
116 | + ] |
|
117 | + ); |
|
118 | + } |
|
119 | + ); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * Various hooks used for modifying initialization or activation processes. |
|
125 | + */ |
|
126 | + private function setInitializationHooks() |
|
127 | + { |
|
128 | + // activation |
|
129 | + add_action('AHEE__EEH_Activation__initialize_db_content', [$this, 'initialize_caf_db_content']); |
|
130 | + // load caff init |
|
131 | + add_action('AHEE__EE_System__set_hooks_for_core', [$this, 'caffeinated_init']); |
|
132 | + // load caff scripts |
|
133 | + add_action('wp_enqueue_scripts', [$this, 'enqueue_caffeinated_scripts'], 10); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * Various hooks used for switch (on/off) type filters. |
|
139 | + */ |
|
140 | + private function setSwitchHooks() |
|
141 | + { |
|
142 | + // remove the "powered by" credit link from receipts and invoices |
|
143 | + add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
144 | + // seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
145 | + add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * Various filters for affecting default configuration values in the caffeinated |
|
151 | + * context. |
|
152 | + */ |
|
153 | + private function setDefaultFilterHooks() |
|
154 | + { |
|
155 | + add_filter( |
|
156 | + 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
157 | + '__return_true' |
|
158 | + ); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
164 | + * |
|
165 | + * @param array $paths original helper paths array |
|
166 | + * @return array new array of paths |
|
167 | + */ |
|
168 | + public function caf_helper_paths(array $paths): array |
|
169 | + { |
|
170 | + $paths[] = EE_CAF_CORE . 'helpers/'; |
|
171 | + return $paths; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
177 | + * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
178 | + * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
179 | + * This action should only be called when EE 4.x.0.P is initially activated. |
|
180 | + * Right now the only CAF content are these global prices. If there's more in the future, then |
|
181 | + * we should probably create a caf file to contain it all instead just a function like this. |
|
182 | + * Right now, we ASSUME the only price types in the system are default ones |
|
183 | + * |
|
184 | + * @global wpdb $wpdb |
|
185 | + */ |
|
186 | + public function initialize_caf_db_content() |
|
187 | + { |
|
188 | + global $wpdb; |
|
189 | + // use same method of getting creator id as the version introducing the change |
|
190 | + $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
191 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
192 | + $price_table = $wpdb->prefix . "esp_price"; |
|
193 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
194 | + $SQL = |
|
195 | + 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types |
|
196 | + $tax_price_type_count = $wpdb->get_var($SQL); |
|
197 | + if ($tax_price_type_count <= 1) { |
|
198 | + $wpdb->insert( |
|
199 | + $price_type_table, |
|
200 | + [ |
|
201 | + 'PRT_name' => esc_html__("Regional Tax", "event_espresso"), |
|
202 | + 'PBT_ID' => 4, |
|
203 | + 'PRT_is_percent' => true, |
|
204 | + 'PRT_order' => 60, |
|
205 | + 'PRT_deleted' => false, |
|
206 | + 'PRT_wp_user' => $default_creator_id, |
|
207 | + ], |
|
208 | + [ |
|
209 | + '%s',// PRT_name |
|
210 | + '%d',// PBT_id |
|
211 | + '%d',// PRT_is_percent |
|
212 | + '%d',// PRT_order |
|
213 | + '%d',// PRT_deleted |
|
214 | + '%d', // PRT_wp_user |
|
215 | + ] |
|
216 | + ); |
|
217 | + // federal tax |
|
218 | + $result = $wpdb->insert( |
|
219 | + $price_type_table, |
|
220 | + [ |
|
221 | + 'PRT_name' => esc_html__("Federal Tax", "event_espresso"), |
|
222 | + 'PBT_ID' => 4, |
|
223 | + 'PRT_is_percent' => true, |
|
224 | + 'PRT_order' => 70, |
|
225 | + 'PRT_deleted' => false, |
|
226 | + 'PRT_wp_user' => $default_creator_id, |
|
227 | + ], |
|
228 | + [ |
|
229 | + '%s',// PRT_name |
|
230 | + '%d',// PBT_id |
|
231 | + '%d',// PRT_is_percent |
|
232 | + '%d',// PRT_order |
|
233 | + '%d',// PRT_deleted |
|
234 | + '%d' // PRT_wp_user |
|
235 | + ] |
|
236 | + ); |
|
237 | + if ($result) { |
|
238 | + $wpdb->insert( |
|
239 | + $price_table, |
|
240 | + [ |
|
241 | + 'PRT_ID' => $wpdb->insert_id, |
|
242 | + 'PRC_amount' => 15.00, |
|
243 | + 'PRC_name' => esc_html__("Sales Tax", "event_espresso"), |
|
244 | + 'PRC_desc' => '', |
|
245 | + 'PRC_is_default' => true, |
|
246 | + 'PRC_overrides' => null, |
|
247 | + 'PRC_deleted' => false, |
|
248 | + 'PRC_order' => 50, |
|
249 | + 'PRC_parent' => null, |
|
250 | + 'PRC_wp_user' => $default_creator_id, |
|
251 | + ], |
|
252 | + [ |
|
253 | + '%d',// PRT_id |
|
254 | + '%f',// PRC_amount |
|
255 | + '%s',// PRC_name |
|
256 | + '%s',// PRC_desc |
|
257 | + '%d',// PRC_is_default |
|
258 | + '%d',// PRC_overrides |
|
259 | + '%d',// PRC_deleted |
|
260 | + '%d',// PRC_order |
|
261 | + '%d',// PRC_parent |
|
262 | + '%d' // PRC_wp_user |
|
263 | + ] |
|
264 | + ); |
|
265 | + } |
|
266 | + } |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * caffeinated_modules_to_register |
|
273 | + * |
|
274 | + * @access public |
|
275 | + * @param array $modules_to_register |
|
276 | + * @return array |
|
277 | + */ |
|
278 | + public function caffeinated_modules_to_register(array $modules_to_register = []): array |
|
279 | + { |
|
280 | + if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
281 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules/*', GLOB_ONLYDIR); |
|
282 | + if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
283 | + $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
284 | + } |
|
285 | + } |
|
286 | + return $modules_to_register; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * @throws EE_Error |
|
292 | + * @throws InvalidArgumentException |
|
293 | + * @throws ReflectionException |
|
294 | + * @throws InvalidDataTypeException |
|
295 | + * @throws InvalidInterfaceException |
|
296 | + */ |
|
297 | + public function caffeinated_init() |
|
298 | + { |
|
299 | + // Custom Post Type hooks |
|
300 | + add_filter( |
|
301 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
302 | + [$this, 'filter_taxonomies'] |
|
303 | + ); |
|
304 | + add_filter( |
|
305 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
306 | + [$this, 'filter_cpts'] |
|
307 | + ); |
|
308 | + add_filter( |
|
309 | + 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', |
|
310 | + [$this, 'nav_metabox_items'] |
|
311 | + ); |
|
312 | + EE_Registry::instance()->load_file( |
|
313 | + EE_CAFF_PATH, |
|
314 | + 'EE_Caf_Messages', |
|
315 | + 'class', |
|
316 | + [], |
|
317 | + false |
|
318 | + ); |
|
319 | + // caffeinated_init__complete hook |
|
320 | + do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + public function enqueue_caffeinated_scripts() |
|
325 | + { |
|
326 | + // sound of crickets... |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * callbacks below here |
|
332 | + * |
|
333 | + * @param array $taxonomy_array |
|
334 | + * @return array |
|
335 | + */ |
|
336 | + public function filter_taxonomies(array $taxonomy_array): array |
|
337 | + { |
|
338 | + $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
339 | + return $taxonomy_array; |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * @param array $cpt_array |
|
345 | + * @return array |
|
346 | + */ |
|
347 | + public function filter_cpts(array $cpt_array): array |
|
348 | + { |
|
349 | + $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
350 | + return $cpt_array; |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * @param array $menu_items |
|
356 | + * @return array |
|
357 | + */ |
|
358 | + public function nav_metabox_items(array $menu_items): array |
|
359 | + { |
|
360 | + $menu_items[] = [ |
|
361 | + 'title' => esc_html__('Venue List', 'event_espresso'), |
|
362 | + 'url' => get_post_type_archive_link('espresso_venues'), |
|
363 | + 'description' => esc_html__('Archive page for all venues.', 'event_espresso'), |
|
364 | + ]; |
|
365 | + return $menu_items; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * Gets the injected table analyzer, or throws an exception |
|
371 | + * |
|
372 | + * @return TableAnalysis |
|
373 | + */ |
|
374 | + protected function _get_table_analysis(): TableAnalysis |
|
375 | + { |
|
376 | + return $this->_table_analysis; |
|
377 | + } |
|
378 | 378 | } |
@@ -14,2207 +14,2207 @@ |
||
14 | 14 | */ |
15 | 15 | class espresso_events_Pricing_Hooks extends EE_Admin_Hooks |
16 | 16 | { |
17 | - /** |
|
18 | - * This property is just used to hold the status of whether an event is currently being |
|
19 | - * created (true) or edited (false) |
|
20 | - * |
|
21 | - * @access protected |
|
22 | - * @var bool |
|
23 | - */ |
|
24 | - protected $_is_creating_event; |
|
17 | + /** |
|
18 | + * This property is just used to hold the status of whether an event is currently being |
|
19 | + * created (true) or edited (false) |
|
20 | + * |
|
21 | + * @access protected |
|
22 | + * @var bool |
|
23 | + */ |
|
24 | + protected $_is_creating_event; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Used to contain the format strings for date and time that will be used for php date and |
|
28 | - * time. |
|
29 | - * Is set in the _set_hooks_properties() method. |
|
30 | - * |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected $_date_format_strings; |
|
26 | + /** |
|
27 | + * Used to contain the format strings for date and time that will be used for php date and |
|
28 | + * time. |
|
29 | + * Is set in the _set_hooks_properties() method. |
|
30 | + * |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected $_date_format_strings; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var string $_date_time_format |
|
37 | - */ |
|
38 | - protected $_date_time_format; |
|
35 | + /** |
|
36 | + * @var string $_date_time_format |
|
37 | + */ |
|
38 | + protected $_date_time_format; |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @throws InvalidArgumentException |
|
43 | - * @throws InvalidInterfaceException |
|
44 | - * @throws InvalidDataTypeException |
|
45 | - */ |
|
46 | - protected function _set_hooks_properties() |
|
47 | - { |
|
48 | - $this->_name = 'pricing'; |
|
49 | - // capability check |
|
50 | - if ( |
|
51 | - ! EE_Registry::instance()->CAP->current_user_can( |
|
52 | - 'ee_read_default_prices', |
|
53 | - 'advanced_ticket_datetime_metabox' |
|
54 | - ) |
|
55 | - ) { |
|
56 | - return; |
|
57 | - } |
|
58 | - $this->_setup_metaboxes(); |
|
59 | - $this->_set_date_time_formats(); |
|
60 | - $this->_validate_format_strings(); |
|
61 | - $this->_set_scripts_styles(); |
|
62 | - // commented out temporarily until logic is implemented in callback |
|
63 | - // add_action( |
|
64 | - // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
65 | - // array($this, 'autosave_handling') |
|
66 | - // ); |
|
67 | - add_filter( |
|
68 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
69 | - array($this, 'caf_updates') |
|
70 | - ); |
|
71 | - } |
|
41 | + /** |
|
42 | + * @throws InvalidArgumentException |
|
43 | + * @throws InvalidInterfaceException |
|
44 | + * @throws InvalidDataTypeException |
|
45 | + */ |
|
46 | + protected function _set_hooks_properties() |
|
47 | + { |
|
48 | + $this->_name = 'pricing'; |
|
49 | + // capability check |
|
50 | + if ( |
|
51 | + ! EE_Registry::instance()->CAP->current_user_can( |
|
52 | + 'ee_read_default_prices', |
|
53 | + 'advanced_ticket_datetime_metabox' |
|
54 | + ) |
|
55 | + ) { |
|
56 | + return; |
|
57 | + } |
|
58 | + $this->_setup_metaboxes(); |
|
59 | + $this->_set_date_time_formats(); |
|
60 | + $this->_validate_format_strings(); |
|
61 | + $this->_set_scripts_styles(); |
|
62 | + // commented out temporarily until logic is implemented in callback |
|
63 | + // add_action( |
|
64 | + // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
65 | + // array($this, 'autosave_handling') |
|
66 | + // ); |
|
67 | + add_filter( |
|
68 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
69 | + array($this, 'caf_updates') |
|
70 | + ); |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * @return void |
|
76 | - */ |
|
77 | - protected function _setup_metaboxes() |
|
78 | - { |
|
79 | - // if we were going to add our own metaboxes we'd use the below. |
|
80 | - $this->_metaboxes = array( |
|
81 | - 0 => array( |
|
82 | - 'page_route' => array('edit', 'create_new'), |
|
83 | - 'func' => 'pricing_metabox', |
|
84 | - 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
85 | - 'priority' => 'high', |
|
86 | - 'context' => 'normal', |
|
87 | - ), |
|
88 | - ); |
|
89 | - $this->_remove_metaboxes = array( |
|
90 | - 0 => array( |
|
91 | - 'page_route' => array('edit', 'create_new'), |
|
92 | - 'id' => 'espresso_event_editor_tickets', |
|
93 | - 'context' => 'normal', |
|
94 | - ), |
|
95 | - ); |
|
96 | - } |
|
74 | + /** |
|
75 | + * @return void |
|
76 | + */ |
|
77 | + protected function _setup_metaboxes() |
|
78 | + { |
|
79 | + // if we were going to add our own metaboxes we'd use the below. |
|
80 | + $this->_metaboxes = array( |
|
81 | + 0 => array( |
|
82 | + 'page_route' => array('edit', 'create_new'), |
|
83 | + 'func' => 'pricing_metabox', |
|
84 | + 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
85 | + 'priority' => 'high', |
|
86 | + 'context' => 'normal', |
|
87 | + ), |
|
88 | + ); |
|
89 | + $this->_remove_metaboxes = array( |
|
90 | + 0 => array( |
|
91 | + 'page_route' => array('edit', 'create_new'), |
|
92 | + 'id' => 'espresso_event_editor_tickets', |
|
93 | + 'context' => 'normal', |
|
94 | + ), |
|
95 | + ); |
|
96 | + } |
|
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * @return void |
|
101 | - */ |
|
102 | - protected function _set_date_time_formats() |
|
103 | - { |
|
104 | - /** |
|
105 | - * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
106 | - * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
107 | - * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
108 | - * |
|
109 | - * @since 4.6.7 |
|
110 | - * @var array Expected an array returned with 'date' and 'time' keys. |
|
111 | - */ |
|
112 | - $this->_date_format_strings = apply_filters( |
|
113 | - 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
114 | - array( |
|
115 | - 'date' => 'Y-m-d', |
|
116 | - 'time' => 'h:i a', |
|
117 | - ) |
|
118 | - ); |
|
119 | - // validate |
|
120 | - $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
121 | - ? $this->_date_format_strings['date'] |
|
122 | - : null; |
|
123 | - $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
124 | - ? $this->_date_format_strings['time'] |
|
125 | - : null; |
|
126 | - $this->_date_time_format = $this->_date_format_strings['date'] |
|
127 | - . ' ' |
|
128 | - . $this->_date_format_strings['time']; |
|
129 | - } |
|
99 | + /** |
|
100 | + * @return void |
|
101 | + */ |
|
102 | + protected function _set_date_time_formats() |
|
103 | + { |
|
104 | + /** |
|
105 | + * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
106 | + * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
107 | + * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
108 | + * |
|
109 | + * @since 4.6.7 |
|
110 | + * @var array Expected an array returned with 'date' and 'time' keys. |
|
111 | + */ |
|
112 | + $this->_date_format_strings = apply_filters( |
|
113 | + 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
114 | + array( |
|
115 | + 'date' => 'Y-m-d', |
|
116 | + 'time' => 'h:i a', |
|
117 | + ) |
|
118 | + ); |
|
119 | + // validate |
|
120 | + $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
121 | + ? $this->_date_format_strings['date'] |
|
122 | + : null; |
|
123 | + $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
124 | + ? $this->_date_format_strings['time'] |
|
125 | + : null; |
|
126 | + $this->_date_time_format = $this->_date_format_strings['date'] |
|
127 | + . ' ' |
|
128 | + . $this->_date_format_strings['time']; |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - protected function _validate_format_strings() |
|
136 | - { |
|
137 | - // validate format strings |
|
138 | - $format_validation = EEH_DTT_Helper::validate_format_string( |
|
139 | - $this->_date_time_format |
|
140 | - ); |
|
141 | - if (is_array($format_validation)) { |
|
142 | - $msg = '<p>'; |
|
143 | - $msg .= sprintf( |
|
144 | - esc_html__( |
|
145 | - 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
146 | - 'event_espresso' |
|
147 | - ), |
|
148 | - $this->_date_time_format |
|
149 | - ); |
|
150 | - $msg .= '</p><ul>'; |
|
151 | - foreach ($format_validation as $error) { |
|
152 | - $msg .= '<li>' . $error . '</li>'; |
|
153 | - } |
|
154 | - $msg .= '</ul><p>'; |
|
155 | - $msg .= sprintf( |
|
156 | - esc_html__( |
|
157 | - '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
158 | - 'event_espresso' |
|
159 | - ), |
|
160 | - '<span style="color:#D54E21;">', |
|
161 | - '</span>' |
|
162 | - ); |
|
163 | - $msg .= '</p>'; |
|
164 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
165 | - $this->_date_format_strings = array( |
|
166 | - 'date' => 'Y-m-d', |
|
167 | - 'time' => 'h:i a', |
|
168 | - ); |
|
169 | - } |
|
170 | - } |
|
132 | + /** |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + protected function _validate_format_strings() |
|
136 | + { |
|
137 | + // validate format strings |
|
138 | + $format_validation = EEH_DTT_Helper::validate_format_string( |
|
139 | + $this->_date_time_format |
|
140 | + ); |
|
141 | + if (is_array($format_validation)) { |
|
142 | + $msg = '<p>'; |
|
143 | + $msg .= sprintf( |
|
144 | + esc_html__( |
|
145 | + 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
146 | + 'event_espresso' |
|
147 | + ), |
|
148 | + $this->_date_time_format |
|
149 | + ); |
|
150 | + $msg .= '</p><ul>'; |
|
151 | + foreach ($format_validation as $error) { |
|
152 | + $msg .= '<li>' . $error . '</li>'; |
|
153 | + } |
|
154 | + $msg .= '</ul><p>'; |
|
155 | + $msg .= sprintf( |
|
156 | + esc_html__( |
|
157 | + '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
158 | + 'event_espresso' |
|
159 | + ), |
|
160 | + '<span style="color:#D54E21;">', |
|
161 | + '</span>' |
|
162 | + ); |
|
163 | + $msg .= '</p>'; |
|
164 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
165 | + $this->_date_format_strings = array( |
|
166 | + 'date' => 'Y-m-d', |
|
167 | + 'time' => 'h:i a', |
|
168 | + ); |
|
169 | + } |
|
170 | + } |
|
171 | 171 | |
172 | 172 | |
173 | - /** |
|
174 | - * @return void |
|
175 | - */ |
|
176 | - protected function _set_scripts_styles() |
|
177 | - { |
|
178 | - $this->_scripts_styles = array( |
|
179 | - 'registers' => array( |
|
180 | - 'ee-tickets-datetimes-css' => array( |
|
181 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
182 | - 'type' => 'css', |
|
183 | - ), |
|
184 | - 'ee-dtt-ticket-metabox' => array( |
|
185 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
186 | - 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
187 | - ), |
|
188 | - ), |
|
189 | - 'deregisters' => array( |
|
190 | - 'event-editor-css' => array('type' => 'css'), |
|
191 | - 'event-datetime-metabox' => array('type' => 'js'), |
|
192 | - ), |
|
193 | - 'enqueues' => array( |
|
194 | - 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
195 | - 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
196 | - ), |
|
197 | - 'localize' => array( |
|
198 | - 'ee-dtt-ticket-metabox' => array( |
|
199 | - 'DTT_TRASH_BLOCK' => array( |
|
200 | - 'main_warning' => esc_html__( |
|
201 | - 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
202 | - 'event_espresso' |
|
203 | - ), |
|
204 | - 'after_warning' => esc_html__( |
|
205 | - 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
206 | - 'event_espresso' |
|
207 | - ), |
|
208 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
209 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
210 | - 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
211 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
212 | - 'single_warning_from_tkt' => esc_html__( |
|
213 | - 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
214 | - 'event_espresso' |
|
215 | - ), |
|
216 | - 'single_warning_from_dtt' => esc_html__( |
|
217 | - 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
221 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
222 | - ), |
|
223 | - 'DTT_ERROR_MSG' => array( |
|
224 | - 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
225 | - 'dismiss_button' => '<div class="save-cancel-button-container">' |
|
226 | - . '<button class="button-secondary ee-modal-cancel">' |
|
227 | - . esc_html__('Dismiss', 'event_espresso') |
|
228 | - . '</button></div>', |
|
229 | - ), |
|
230 | - 'DTT_OVERSELL_WARNING' => array( |
|
231 | - 'datetime_ticket' => esc_html__( |
|
232 | - 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
233 | - 'event_espresso' |
|
234 | - ), |
|
235 | - 'ticket_datetime' => esc_html__( |
|
236 | - 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
237 | - 'event_espresso' |
|
238 | - ), |
|
239 | - ), |
|
240 | - 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
241 | - $this->_date_format_strings['date'], |
|
242 | - $this->_date_format_strings['time'] |
|
243 | - ), |
|
244 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
245 | - ), |
|
246 | - ), |
|
247 | - ); |
|
248 | - } |
|
173 | + /** |
|
174 | + * @return void |
|
175 | + */ |
|
176 | + protected function _set_scripts_styles() |
|
177 | + { |
|
178 | + $this->_scripts_styles = array( |
|
179 | + 'registers' => array( |
|
180 | + 'ee-tickets-datetimes-css' => array( |
|
181 | + 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
182 | + 'type' => 'css', |
|
183 | + ), |
|
184 | + 'ee-dtt-ticket-metabox' => array( |
|
185 | + 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
186 | + 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
187 | + ), |
|
188 | + ), |
|
189 | + 'deregisters' => array( |
|
190 | + 'event-editor-css' => array('type' => 'css'), |
|
191 | + 'event-datetime-metabox' => array('type' => 'js'), |
|
192 | + ), |
|
193 | + 'enqueues' => array( |
|
194 | + 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
195 | + 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
196 | + ), |
|
197 | + 'localize' => array( |
|
198 | + 'ee-dtt-ticket-metabox' => array( |
|
199 | + 'DTT_TRASH_BLOCK' => array( |
|
200 | + 'main_warning' => esc_html__( |
|
201 | + 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
202 | + 'event_espresso' |
|
203 | + ), |
|
204 | + 'after_warning' => esc_html__( |
|
205 | + 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
206 | + 'event_espresso' |
|
207 | + ), |
|
208 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
209 | + . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
210 | + 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
211 | + . esc_html__('Close', 'event_espresso') . '</button>', |
|
212 | + 'single_warning_from_tkt' => esc_html__( |
|
213 | + 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
214 | + 'event_espresso' |
|
215 | + ), |
|
216 | + 'single_warning_from_dtt' => esc_html__( |
|
217 | + 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
221 | + . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
222 | + ), |
|
223 | + 'DTT_ERROR_MSG' => array( |
|
224 | + 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
225 | + 'dismiss_button' => '<div class="save-cancel-button-container">' |
|
226 | + . '<button class="button-secondary ee-modal-cancel">' |
|
227 | + . esc_html__('Dismiss', 'event_espresso') |
|
228 | + . '</button></div>', |
|
229 | + ), |
|
230 | + 'DTT_OVERSELL_WARNING' => array( |
|
231 | + 'datetime_ticket' => esc_html__( |
|
232 | + 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
233 | + 'event_espresso' |
|
234 | + ), |
|
235 | + 'ticket_datetime' => esc_html__( |
|
236 | + 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
237 | + 'event_espresso' |
|
238 | + ), |
|
239 | + ), |
|
240 | + 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
241 | + $this->_date_format_strings['date'], |
|
242 | + $this->_date_format_strings['time'] |
|
243 | + ), |
|
244 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
245 | + ), |
|
246 | + ), |
|
247 | + ); |
|
248 | + } |
|
249 | 249 | |
250 | 250 | |
251 | - /** |
|
252 | - * @param array $update_callbacks |
|
253 | - * @return array |
|
254 | - */ |
|
255 | - public function caf_updates(array $update_callbacks) |
|
256 | - { |
|
257 | - foreach ($update_callbacks as $key => $callback) { |
|
258 | - if ($callback[1] === '_default_tickets_update') { |
|
259 | - unset($update_callbacks[ $key ]); |
|
260 | - } |
|
261 | - } |
|
262 | - $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
263 | - return $update_callbacks; |
|
264 | - } |
|
251 | + /** |
|
252 | + * @param array $update_callbacks |
|
253 | + * @return array |
|
254 | + */ |
|
255 | + public function caf_updates(array $update_callbacks) |
|
256 | + { |
|
257 | + foreach ($update_callbacks as $key => $callback) { |
|
258 | + if ($callback[1] === '_default_tickets_update') { |
|
259 | + unset($update_callbacks[ $key ]); |
|
260 | + } |
|
261 | + } |
|
262 | + $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
263 | + return $update_callbacks; |
|
264 | + } |
|
265 | 265 | |
266 | 266 | |
267 | - /** |
|
268 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
269 | - * |
|
270 | - * @param EE_Event $event The Event object we're attaching data to |
|
271 | - * @param array $data The request data from the form |
|
272 | - * @throws ReflectionException |
|
273 | - * @throws Exception |
|
274 | - * @throws InvalidInterfaceException |
|
275 | - * @throws InvalidDataTypeException |
|
276 | - * @throws EE_Error |
|
277 | - * @throws InvalidArgumentException |
|
278 | - */ |
|
279 | - public function datetime_and_tickets_caf_update($event, $data) |
|
280 | - { |
|
281 | - // first we need to start with datetimes cause they are the "root" items attached to events. |
|
282 | - $saved_datetimes = $this->_update_datetimes($event, $data); |
|
283 | - // next tackle the tickets (and prices?) |
|
284 | - $this->_update_tickets($event, $saved_datetimes, $data); |
|
285 | - } |
|
267 | + /** |
|
268 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
269 | + * |
|
270 | + * @param EE_Event $event The Event object we're attaching data to |
|
271 | + * @param array $data The request data from the form |
|
272 | + * @throws ReflectionException |
|
273 | + * @throws Exception |
|
274 | + * @throws InvalidInterfaceException |
|
275 | + * @throws InvalidDataTypeException |
|
276 | + * @throws EE_Error |
|
277 | + * @throws InvalidArgumentException |
|
278 | + */ |
|
279 | + public function datetime_and_tickets_caf_update($event, $data) |
|
280 | + { |
|
281 | + // first we need to start with datetimes cause they are the "root" items attached to events. |
|
282 | + $saved_datetimes = $this->_update_datetimes($event, $data); |
|
283 | + // next tackle the tickets (and prices?) |
|
284 | + $this->_update_tickets($event, $saved_datetimes, $data); |
|
285 | + } |
|
286 | 286 | |
287 | 287 | |
288 | - /** |
|
289 | - * update event_datetimes |
|
290 | - * |
|
291 | - * @param EE_Event $event Event being updated |
|
292 | - * @param array $data the request data from the form |
|
293 | - * @return EE_Datetime[] |
|
294 | - * @throws Exception |
|
295 | - * @throws ReflectionException |
|
296 | - * @throws InvalidInterfaceException |
|
297 | - * @throws InvalidDataTypeException |
|
298 | - * @throws InvalidArgumentException |
|
299 | - * @throws EE_Error |
|
300 | - */ |
|
301 | - protected function _update_datetimes($event, $data) |
|
302 | - { |
|
303 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
304 | - $saved_dtt_ids = array(); |
|
305 | - $saved_dtt_objs = array(); |
|
306 | - if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) { |
|
307 | - throw new InvalidArgumentException( |
|
308 | - esc_html__( |
|
309 | - 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
310 | - 'event_espresso' |
|
311 | - ) |
|
312 | - ); |
|
313 | - } |
|
314 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
315 | - // trim all values to ensure any excess whitespace is removed. |
|
316 | - $datetime_data = array_map( |
|
317 | - function ($datetime_data) { |
|
318 | - return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
319 | - }, |
|
320 | - $datetime_data |
|
321 | - ); |
|
322 | - $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
323 | - && ! empty($datetime_data['DTT_EVT_end']) |
|
324 | - ? $datetime_data['DTT_EVT_end'] |
|
325 | - : $datetime_data['DTT_EVT_start']; |
|
326 | - $datetime_values = array( |
|
327 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
328 | - ? $datetime_data['DTT_ID'] |
|
329 | - : null, |
|
330 | - 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
331 | - ? $datetime_data['DTT_name'] |
|
332 | - : '', |
|
333 | - 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
334 | - ? $datetime_data['DTT_description'] |
|
335 | - : '', |
|
336 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
337 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
338 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
339 | - ? EE_INF |
|
340 | - : $datetime_data['DTT_reg_limit'], |
|
341 | - 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
342 | - ? $row |
|
343 | - : $datetime_data['DTT_order'], |
|
344 | - ); |
|
345 | - // if we have an id then let's get existing object first and then set the new values. |
|
346 | - // Otherwise we instantiate a new object for save. |
|
347 | - if (! empty($datetime_data['DTT_ID'])) { |
|
348 | - $datetime = EE_Registry::instance() |
|
349 | - ->load_model('Datetime', array($timezone)) |
|
350 | - ->get_one_by_ID($datetime_data['DTT_ID']); |
|
351 | - // set date and time format according to what is set in this class. |
|
352 | - $datetime->set_date_format($this->_date_format_strings['date']); |
|
353 | - $datetime->set_time_format($this->_date_format_strings['time']); |
|
354 | - foreach ($datetime_values as $field => $value) { |
|
355 | - $datetime->set($field, $value); |
|
356 | - } |
|
357 | - // make sure the $dtt_id here is saved just in case |
|
358 | - // after the add_relation_to() the autosave replaces it. |
|
359 | - // We need to do this so we dont' TRASH the parent DTT. |
|
360 | - // (save the ID for both key and value to avoid duplications) |
|
361 | - $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
362 | - } else { |
|
363 | - $datetime = EE_Registry::instance()->load_class( |
|
364 | - 'Datetime', |
|
365 | - array( |
|
366 | - $datetime_values, |
|
367 | - $timezone, |
|
368 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
369 | - ), |
|
370 | - false, |
|
371 | - false |
|
372 | - ); |
|
373 | - foreach ($datetime_values as $field => $value) { |
|
374 | - $datetime->set($field, $value); |
|
375 | - } |
|
376 | - } |
|
377 | - $datetime->save(); |
|
378 | - do_action( |
|
379 | - 'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save', |
|
380 | - $datetime, |
|
381 | - $row, |
|
382 | - $datetime_data, |
|
383 | - $data |
|
384 | - ); |
|
385 | - $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
386 | - // before going any further make sure our dates are setup correctly |
|
387 | - // so that the end date is always equal or greater than the start date. |
|
388 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
389 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
390 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
391 | - $datetime->save(); |
|
392 | - } |
|
393 | - // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
394 | - // because it is possible there was a new one created for the autosave. |
|
395 | - // (save the ID for both key and value to avoid duplications) |
|
396 | - $DTT_ID = $datetime->ID(); |
|
397 | - $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
398 | - $saved_dtt_objs[ $row ] = $datetime; |
|
399 | - // @todo if ANY of these updates fail then we want the appropriate global error message. |
|
400 | - } |
|
401 | - $event->save(); |
|
402 | - // now we need to REMOVE any datetimes that got deleted. |
|
403 | - // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
404 | - // So its safe to permanently delete at this point. |
|
405 | - $old_datetimes = explode(',', $data['datetime_IDs']); |
|
406 | - $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
407 | - if (is_array($old_datetimes)) { |
|
408 | - $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
409 | - foreach ($datetimes_to_delete as $id) { |
|
410 | - $id = absint($id); |
|
411 | - if (empty($id)) { |
|
412 | - continue; |
|
413 | - } |
|
414 | - /** @var EE_Datetime $dtt_to_remove */ |
|
415 | - $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
416 | - // remove tkt relationships. |
|
417 | - $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
418 | - foreach ($related_tickets as $tkt) { |
|
419 | - $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
420 | - } |
|
421 | - $event->_remove_relation_to($id, 'Datetime'); |
|
422 | - $dtt_to_remove->refresh_cache_of_related_objects(); |
|
423 | - $dtt_to_remove->delete_or_restore(); |
|
424 | - } |
|
425 | - } |
|
426 | - return $saved_dtt_objs; |
|
427 | - } |
|
288 | + /** |
|
289 | + * update event_datetimes |
|
290 | + * |
|
291 | + * @param EE_Event $event Event being updated |
|
292 | + * @param array $data the request data from the form |
|
293 | + * @return EE_Datetime[] |
|
294 | + * @throws Exception |
|
295 | + * @throws ReflectionException |
|
296 | + * @throws InvalidInterfaceException |
|
297 | + * @throws InvalidDataTypeException |
|
298 | + * @throws InvalidArgumentException |
|
299 | + * @throws EE_Error |
|
300 | + */ |
|
301 | + protected function _update_datetimes($event, $data) |
|
302 | + { |
|
303 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
304 | + $saved_dtt_ids = array(); |
|
305 | + $saved_dtt_objs = array(); |
|
306 | + if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) { |
|
307 | + throw new InvalidArgumentException( |
|
308 | + esc_html__( |
|
309 | + 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
310 | + 'event_espresso' |
|
311 | + ) |
|
312 | + ); |
|
313 | + } |
|
314 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
315 | + // trim all values to ensure any excess whitespace is removed. |
|
316 | + $datetime_data = array_map( |
|
317 | + function ($datetime_data) { |
|
318 | + return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
319 | + }, |
|
320 | + $datetime_data |
|
321 | + ); |
|
322 | + $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
323 | + && ! empty($datetime_data['DTT_EVT_end']) |
|
324 | + ? $datetime_data['DTT_EVT_end'] |
|
325 | + : $datetime_data['DTT_EVT_start']; |
|
326 | + $datetime_values = array( |
|
327 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
328 | + ? $datetime_data['DTT_ID'] |
|
329 | + : null, |
|
330 | + 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
331 | + ? $datetime_data['DTT_name'] |
|
332 | + : '', |
|
333 | + 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
334 | + ? $datetime_data['DTT_description'] |
|
335 | + : '', |
|
336 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
337 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
338 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
339 | + ? EE_INF |
|
340 | + : $datetime_data['DTT_reg_limit'], |
|
341 | + 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
342 | + ? $row |
|
343 | + : $datetime_data['DTT_order'], |
|
344 | + ); |
|
345 | + // if we have an id then let's get existing object first and then set the new values. |
|
346 | + // Otherwise we instantiate a new object for save. |
|
347 | + if (! empty($datetime_data['DTT_ID'])) { |
|
348 | + $datetime = EE_Registry::instance() |
|
349 | + ->load_model('Datetime', array($timezone)) |
|
350 | + ->get_one_by_ID($datetime_data['DTT_ID']); |
|
351 | + // set date and time format according to what is set in this class. |
|
352 | + $datetime->set_date_format($this->_date_format_strings['date']); |
|
353 | + $datetime->set_time_format($this->_date_format_strings['time']); |
|
354 | + foreach ($datetime_values as $field => $value) { |
|
355 | + $datetime->set($field, $value); |
|
356 | + } |
|
357 | + // make sure the $dtt_id here is saved just in case |
|
358 | + // after the add_relation_to() the autosave replaces it. |
|
359 | + // We need to do this so we dont' TRASH the parent DTT. |
|
360 | + // (save the ID for both key and value to avoid duplications) |
|
361 | + $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
362 | + } else { |
|
363 | + $datetime = EE_Registry::instance()->load_class( |
|
364 | + 'Datetime', |
|
365 | + array( |
|
366 | + $datetime_values, |
|
367 | + $timezone, |
|
368 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
369 | + ), |
|
370 | + false, |
|
371 | + false |
|
372 | + ); |
|
373 | + foreach ($datetime_values as $field => $value) { |
|
374 | + $datetime->set($field, $value); |
|
375 | + } |
|
376 | + } |
|
377 | + $datetime->save(); |
|
378 | + do_action( |
|
379 | + 'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save', |
|
380 | + $datetime, |
|
381 | + $row, |
|
382 | + $datetime_data, |
|
383 | + $data |
|
384 | + ); |
|
385 | + $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
386 | + // before going any further make sure our dates are setup correctly |
|
387 | + // so that the end date is always equal or greater than the start date. |
|
388 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
389 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
390 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
391 | + $datetime->save(); |
|
392 | + } |
|
393 | + // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
394 | + // because it is possible there was a new one created for the autosave. |
|
395 | + // (save the ID for both key and value to avoid duplications) |
|
396 | + $DTT_ID = $datetime->ID(); |
|
397 | + $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
398 | + $saved_dtt_objs[ $row ] = $datetime; |
|
399 | + // @todo if ANY of these updates fail then we want the appropriate global error message. |
|
400 | + } |
|
401 | + $event->save(); |
|
402 | + // now we need to REMOVE any datetimes that got deleted. |
|
403 | + // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
404 | + // So its safe to permanently delete at this point. |
|
405 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
406 | + $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
407 | + if (is_array($old_datetimes)) { |
|
408 | + $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
409 | + foreach ($datetimes_to_delete as $id) { |
|
410 | + $id = absint($id); |
|
411 | + if (empty($id)) { |
|
412 | + continue; |
|
413 | + } |
|
414 | + /** @var EE_Datetime $dtt_to_remove */ |
|
415 | + $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
416 | + // remove tkt relationships. |
|
417 | + $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
418 | + foreach ($related_tickets as $tkt) { |
|
419 | + $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
420 | + } |
|
421 | + $event->_remove_relation_to($id, 'Datetime'); |
|
422 | + $dtt_to_remove->refresh_cache_of_related_objects(); |
|
423 | + $dtt_to_remove->delete_or_restore(); |
|
424 | + } |
|
425 | + } |
|
426 | + return $saved_dtt_objs; |
|
427 | + } |
|
428 | 428 | |
429 | 429 | |
430 | - /** |
|
431 | - * update tickets |
|
432 | - * |
|
433 | - * @param EE_Event $event Event object being updated |
|
434 | - * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
435 | - * @param array $data incoming request data |
|
436 | - * @return EE_Ticket[] |
|
437 | - * @throws Exception |
|
438 | - * @throws ReflectionException |
|
439 | - * @throws InvalidInterfaceException |
|
440 | - * @throws InvalidDataTypeException |
|
441 | - * @throws InvalidArgumentException |
|
442 | - * @throws EE_Error |
|
443 | - */ |
|
444 | - protected function _update_tickets($event, $saved_datetimes, $data) |
|
445 | - { |
|
446 | - $new_tkt = null; |
|
447 | - // stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
448 | - $data = stripslashes_deep($data); |
|
449 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
450 | - $saved_tickets = array(); |
|
451 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
452 | - if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
453 | - throw new InvalidArgumentException( |
|
454 | - esc_html__( |
|
455 | - 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
456 | - 'event_espresso' |
|
457 | - ) |
|
458 | - ); |
|
459 | - } |
|
460 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
461 | - $update_prices = $create_new_TKT = false; |
|
462 | - // figure out what datetimes were added to the ticket |
|
463 | - // and what datetimes were removed from the ticket in the session. |
|
464 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
465 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
466 | - $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
467 | - $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
468 | - // trim inputs to ensure any excess whitespace is removed. |
|
469 | - $tkt = array_map( |
|
470 | - function ($ticket_data) { |
|
471 | - return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
472 | - }, |
|
473 | - $tkt |
|
474 | - ); |
|
475 | - // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
476 | - // because we're doing calculations prior to using the models. |
|
477 | - // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
478 | - $ticket_price = isset($tkt['TKT_price']) |
|
479 | - ? round((float) $tkt['TKT_price'], 3) |
|
480 | - : 0; |
|
481 | - // note incoming base price needs converted from localized value. |
|
482 | - $base_price = isset($tkt['TKT_base_price']) |
|
483 | - ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
484 | - : 0; |
|
485 | - // if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
486 | - $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
487 | - ? $base_price |
|
488 | - : $ticket_price; |
|
489 | - $base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0; |
|
490 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
491 | - ? $data['edit_prices'][ $row ] |
|
492 | - : array(); |
|
493 | - $now = null; |
|
494 | - if (empty($tkt['TKT_start_date'])) { |
|
495 | - // lets' use now in the set timezone. |
|
496 | - $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
497 | - $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
498 | - } |
|
499 | - if (empty($tkt['TKT_end_date'])) { |
|
500 | - /** |
|
501 | - * set the TKT_end_date to the first datetime attached to the ticket. |
|
502 | - */ |
|
503 | - $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
504 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
505 | - } |
|
506 | - $TKT_values = array( |
|
507 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
508 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
509 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
510 | - 'TKT_description' => ! empty($tkt['TKT_description']) |
|
511 | - && $tkt['TKT_description'] !== esc_html__( |
|
512 | - 'You can modify this description', |
|
513 | - 'event_espresso' |
|
514 | - ) |
|
515 | - ? $tkt['TKT_description'] |
|
516 | - : '', |
|
517 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
518 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
519 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
520 | - ? EE_INF |
|
521 | - : $tkt['TKT_qty'], |
|
522 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
523 | - ? EE_INF |
|
524 | - : $tkt['TKT_uses'], |
|
525 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
526 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
527 | - 'TKT_row' => $row, |
|
528 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
529 | - 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
530 | - 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
531 | - 'TKT_price' => $ticket_price, |
|
532 | - ); |
|
533 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
534 | - // which means in turn that the prices will become new prices as well. |
|
535 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
536 | - $TKT_values['TKT_ID'] = 0; |
|
537 | - $TKT_values['TKT_is_default'] = 0; |
|
538 | - $update_prices = true; |
|
539 | - } |
|
540 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
541 | - // we actually do our saves ahead of doing any add_relations to |
|
542 | - // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
543 | - // but DID have it's items modified. |
|
544 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
545 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
546 | - if (absint($TKT_values['TKT_ID'])) { |
|
547 | - $ticket = EE_Registry::instance() |
|
548 | - ->load_model('Ticket', array($timezone)) |
|
549 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
550 | - if ($ticket instanceof EE_Ticket) { |
|
551 | - $ticket = $this->_update_ticket_datetimes( |
|
552 | - $ticket, |
|
553 | - $saved_datetimes, |
|
554 | - $datetimes_added, |
|
555 | - $datetimes_removed |
|
556 | - ); |
|
557 | - // are there any registrations using this ticket ? |
|
558 | - $tickets_sold = $ticket->count_related( |
|
559 | - 'Registration', |
|
560 | - array( |
|
561 | - array( |
|
562 | - 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
563 | - ), |
|
564 | - ) |
|
565 | - ); |
|
566 | - // set ticket formats |
|
567 | - $ticket->set_date_format($this->_date_format_strings['date']); |
|
568 | - $ticket->set_time_format($this->_date_format_strings['time']); |
|
569 | - // let's just check the total price for the existing ticket |
|
570 | - // and determine if it matches the new total price. |
|
571 | - // if they are different then we create a new ticket (if tickets sold) |
|
572 | - // if they aren't different then we go ahead and modify existing ticket. |
|
573 | - $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
574 | - // set new values |
|
575 | - foreach ($TKT_values as $field => $value) { |
|
576 | - if ($field === 'TKT_qty') { |
|
577 | - $ticket->set_qty($value); |
|
578 | - } else { |
|
579 | - $ticket->set($field, $value); |
|
580 | - } |
|
581 | - } |
|
582 | - // if $create_new_TKT is false then we can safely update the existing ticket. |
|
583 | - // Otherwise we have to create a new ticket. |
|
584 | - if ($create_new_TKT) { |
|
585 | - $new_tkt = $this->_duplicate_ticket( |
|
586 | - $ticket, |
|
587 | - $price_rows, |
|
588 | - $ticket_price, |
|
589 | - $base_price, |
|
590 | - $base_price_id |
|
591 | - ); |
|
592 | - } |
|
593 | - } |
|
594 | - } else { |
|
595 | - // no TKT_id so a new TKT |
|
596 | - $ticket = EE_Ticket::new_instance( |
|
597 | - $TKT_values, |
|
598 | - $timezone, |
|
599 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
600 | - ); |
|
601 | - if ($ticket instanceof EE_Ticket) { |
|
602 | - // make sure ticket has an ID of setting relations won't work |
|
603 | - $ticket->save(); |
|
604 | - $ticket = $this->_update_ticket_datetimes( |
|
605 | - $ticket, |
|
606 | - $saved_datetimes, |
|
607 | - $datetimes_added, |
|
608 | - $datetimes_removed |
|
609 | - ); |
|
610 | - $update_prices = true; |
|
611 | - } |
|
612 | - } |
|
613 | - // make sure any current values have been saved. |
|
614 | - // $ticket->save(); |
|
615 | - // before going any further make sure our dates are setup correctly |
|
616 | - // so that the end date is always equal or greater than the start date. |
|
617 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
618 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
619 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
620 | - } |
|
621 | - // let's make sure the base price is handled |
|
622 | - $ticket = ! $create_new_TKT |
|
623 | - ? $this->_add_prices_to_ticket( |
|
624 | - array(), |
|
625 | - $ticket, |
|
626 | - $update_prices, |
|
627 | - $base_price, |
|
628 | - $base_price_id |
|
629 | - ) |
|
630 | - : $ticket; |
|
631 | - // add/update price_modifiers |
|
632 | - $ticket = ! $create_new_TKT |
|
633 | - ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) |
|
634 | - : $ticket; |
|
635 | - // need to make sue that the TKT_price is accurate after saving the prices. |
|
636 | - $ticket->ensure_TKT_Price_correct(); |
|
637 | - // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
638 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
639 | - $update_prices = true; |
|
640 | - $new_default = clone $ticket; |
|
641 | - $new_default->set('TKT_ID', 0); |
|
642 | - $new_default->set('TKT_is_default', 1); |
|
643 | - $new_default->set('TKT_row', 1); |
|
644 | - $new_default->set('TKT_price', $ticket_price); |
|
645 | - // remove any dtt relations cause we DON'T want dtt relations attached |
|
646 | - // (note this is just removing the cached relations in the object) |
|
647 | - $new_default->_remove_relations('Datetime'); |
|
648 | - // @todo we need to add the current attached prices as new prices to the new default ticket. |
|
649 | - $new_default = $this->_add_prices_to_ticket( |
|
650 | - $price_rows, |
|
651 | - $new_default, |
|
652 | - $update_prices |
|
653 | - ); |
|
654 | - // don't forget the base price! |
|
655 | - $new_default = $this->_add_prices_to_ticket( |
|
656 | - array(), |
|
657 | - $new_default, |
|
658 | - $update_prices, |
|
659 | - $base_price, |
|
660 | - $base_price_id |
|
661 | - ); |
|
662 | - $new_default->save(); |
|
663 | - do_action( |
|
664 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
665 | - $new_default, |
|
666 | - $row, |
|
667 | - $ticket, |
|
668 | - $data |
|
669 | - ); |
|
670 | - } |
|
671 | - // DO ALL dtt relationships for both current tickets and any archived tickets |
|
672 | - // for the given dtt that are related to the current ticket. |
|
673 | - // TODO... not sure exactly how we're going to do this considering we don't know |
|
674 | - // what current ticket the archived tickets are related to |
|
675 | - // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
676 | - // let's assign any tickets that have been setup to the saved_tickets tracker |
|
677 | - // save existing TKT |
|
678 | - $ticket->save(); |
|
679 | - if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
680 | - // save new TKT |
|
681 | - $new_tkt->save(); |
|
682 | - // add new ticket to array |
|
683 | - $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
684 | - do_action( |
|
685 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
686 | - $new_tkt, |
|
687 | - $row, |
|
688 | - $tkt, |
|
689 | - $data |
|
690 | - ); |
|
691 | - } else { |
|
692 | - // add tkt to saved tkts |
|
693 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
694 | - do_action( |
|
695 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
696 | - $ticket, |
|
697 | - $row, |
|
698 | - $tkt, |
|
699 | - $data |
|
700 | - ); |
|
701 | - } |
|
702 | - } |
|
703 | - // now we need to handle tickets actually "deleted permanently". |
|
704 | - // There are cases where we'd want this to happen |
|
705 | - // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
706 | - // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
707 | - // No sense in keeping all the related data in the db! |
|
708 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
709 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
710 | - foreach ($tickets_removed as $id) { |
|
711 | - $id = absint($id); |
|
712 | - // get the ticket for this id |
|
713 | - $tkt_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
|
714 | - // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
715 | - if ($tkt_to_remove->get('TKT_is_default')) { |
|
716 | - continue; |
|
717 | - } |
|
718 | - // if this tkt has any registrations attached so then we just ARCHIVE |
|
719 | - // because we don't actually permanently delete these tickets. |
|
720 | - if ($tkt_to_remove->count_related('Registration') > 0) { |
|
721 | - $tkt_to_remove->delete(); |
|
722 | - continue; |
|
723 | - } |
|
724 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
725 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
726 | - $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
727 | - foreach ($datetimes as $datetime) { |
|
728 | - $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
729 | - } |
|
730 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
731 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
732 | - $tkt_to_remove->delete_related('Price'); |
|
733 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
734 | - // finally let's delete this ticket |
|
735 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
736 | - $tkt_to_remove->delete_or_restore(); |
|
737 | - } |
|
738 | - return $saved_tickets; |
|
739 | - } |
|
430 | + /** |
|
431 | + * update tickets |
|
432 | + * |
|
433 | + * @param EE_Event $event Event object being updated |
|
434 | + * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
435 | + * @param array $data incoming request data |
|
436 | + * @return EE_Ticket[] |
|
437 | + * @throws Exception |
|
438 | + * @throws ReflectionException |
|
439 | + * @throws InvalidInterfaceException |
|
440 | + * @throws InvalidDataTypeException |
|
441 | + * @throws InvalidArgumentException |
|
442 | + * @throws EE_Error |
|
443 | + */ |
|
444 | + protected function _update_tickets($event, $saved_datetimes, $data) |
|
445 | + { |
|
446 | + $new_tkt = null; |
|
447 | + // stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
448 | + $data = stripslashes_deep($data); |
|
449 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
450 | + $saved_tickets = array(); |
|
451 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
452 | + if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
453 | + throw new InvalidArgumentException( |
|
454 | + esc_html__( |
|
455 | + 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
456 | + 'event_espresso' |
|
457 | + ) |
|
458 | + ); |
|
459 | + } |
|
460 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
461 | + $update_prices = $create_new_TKT = false; |
|
462 | + // figure out what datetimes were added to the ticket |
|
463 | + // and what datetimes were removed from the ticket in the session. |
|
464 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
465 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
466 | + $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
467 | + $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
468 | + // trim inputs to ensure any excess whitespace is removed. |
|
469 | + $tkt = array_map( |
|
470 | + function ($ticket_data) { |
|
471 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
472 | + }, |
|
473 | + $tkt |
|
474 | + ); |
|
475 | + // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
476 | + // because we're doing calculations prior to using the models. |
|
477 | + // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
478 | + $ticket_price = isset($tkt['TKT_price']) |
|
479 | + ? round((float) $tkt['TKT_price'], 3) |
|
480 | + : 0; |
|
481 | + // note incoming base price needs converted from localized value. |
|
482 | + $base_price = isset($tkt['TKT_base_price']) |
|
483 | + ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
484 | + : 0; |
|
485 | + // if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
486 | + $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
487 | + ? $base_price |
|
488 | + : $ticket_price; |
|
489 | + $base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0; |
|
490 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
491 | + ? $data['edit_prices'][ $row ] |
|
492 | + : array(); |
|
493 | + $now = null; |
|
494 | + if (empty($tkt['TKT_start_date'])) { |
|
495 | + // lets' use now in the set timezone. |
|
496 | + $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
497 | + $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
498 | + } |
|
499 | + if (empty($tkt['TKT_end_date'])) { |
|
500 | + /** |
|
501 | + * set the TKT_end_date to the first datetime attached to the ticket. |
|
502 | + */ |
|
503 | + $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
504 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
505 | + } |
|
506 | + $TKT_values = array( |
|
507 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
508 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
509 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
510 | + 'TKT_description' => ! empty($tkt['TKT_description']) |
|
511 | + && $tkt['TKT_description'] !== esc_html__( |
|
512 | + 'You can modify this description', |
|
513 | + 'event_espresso' |
|
514 | + ) |
|
515 | + ? $tkt['TKT_description'] |
|
516 | + : '', |
|
517 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
518 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
519 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
520 | + ? EE_INF |
|
521 | + : $tkt['TKT_qty'], |
|
522 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
523 | + ? EE_INF |
|
524 | + : $tkt['TKT_uses'], |
|
525 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
526 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
527 | + 'TKT_row' => $row, |
|
528 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
529 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
530 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
531 | + 'TKT_price' => $ticket_price, |
|
532 | + ); |
|
533 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
534 | + // which means in turn that the prices will become new prices as well. |
|
535 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
536 | + $TKT_values['TKT_ID'] = 0; |
|
537 | + $TKT_values['TKT_is_default'] = 0; |
|
538 | + $update_prices = true; |
|
539 | + } |
|
540 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
541 | + // we actually do our saves ahead of doing any add_relations to |
|
542 | + // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
543 | + // but DID have it's items modified. |
|
544 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
545 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
546 | + if (absint($TKT_values['TKT_ID'])) { |
|
547 | + $ticket = EE_Registry::instance() |
|
548 | + ->load_model('Ticket', array($timezone)) |
|
549 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
550 | + if ($ticket instanceof EE_Ticket) { |
|
551 | + $ticket = $this->_update_ticket_datetimes( |
|
552 | + $ticket, |
|
553 | + $saved_datetimes, |
|
554 | + $datetimes_added, |
|
555 | + $datetimes_removed |
|
556 | + ); |
|
557 | + // are there any registrations using this ticket ? |
|
558 | + $tickets_sold = $ticket->count_related( |
|
559 | + 'Registration', |
|
560 | + array( |
|
561 | + array( |
|
562 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
563 | + ), |
|
564 | + ) |
|
565 | + ); |
|
566 | + // set ticket formats |
|
567 | + $ticket->set_date_format($this->_date_format_strings['date']); |
|
568 | + $ticket->set_time_format($this->_date_format_strings['time']); |
|
569 | + // let's just check the total price for the existing ticket |
|
570 | + // and determine if it matches the new total price. |
|
571 | + // if they are different then we create a new ticket (if tickets sold) |
|
572 | + // if they aren't different then we go ahead and modify existing ticket. |
|
573 | + $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
574 | + // set new values |
|
575 | + foreach ($TKT_values as $field => $value) { |
|
576 | + if ($field === 'TKT_qty') { |
|
577 | + $ticket->set_qty($value); |
|
578 | + } else { |
|
579 | + $ticket->set($field, $value); |
|
580 | + } |
|
581 | + } |
|
582 | + // if $create_new_TKT is false then we can safely update the existing ticket. |
|
583 | + // Otherwise we have to create a new ticket. |
|
584 | + if ($create_new_TKT) { |
|
585 | + $new_tkt = $this->_duplicate_ticket( |
|
586 | + $ticket, |
|
587 | + $price_rows, |
|
588 | + $ticket_price, |
|
589 | + $base_price, |
|
590 | + $base_price_id |
|
591 | + ); |
|
592 | + } |
|
593 | + } |
|
594 | + } else { |
|
595 | + // no TKT_id so a new TKT |
|
596 | + $ticket = EE_Ticket::new_instance( |
|
597 | + $TKT_values, |
|
598 | + $timezone, |
|
599 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
600 | + ); |
|
601 | + if ($ticket instanceof EE_Ticket) { |
|
602 | + // make sure ticket has an ID of setting relations won't work |
|
603 | + $ticket->save(); |
|
604 | + $ticket = $this->_update_ticket_datetimes( |
|
605 | + $ticket, |
|
606 | + $saved_datetimes, |
|
607 | + $datetimes_added, |
|
608 | + $datetimes_removed |
|
609 | + ); |
|
610 | + $update_prices = true; |
|
611 | + } |
|
612 | + } |
|
613 | + // make sure any current values have been saved. |
|
614 | + // $ticket->save(); |
|
615 | + // before going any further make sure our dates are setup correctly |
|
616 | + // so that the end date is always equal or greater than the start date. |
|
617 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
618 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
619 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
620 | + } |
|
621 | + // let's make sure the base price is handled |
|
622 | + $ticket = ! $create_new_TKT |
|
623 | + ? $this->_add_prices_to_ticket( |
|
624 | + array(), |
|
625 | + $ticket, |
|
626 | + $update_prices, |
|
627 | + $base_price, |
|
628 | + $base_price_id |
|
629 | + ) |
|
630 | + : $ticket; |
|
631 | + // add/update price_modifiers |
|
632 | + $ticket = ! $create_new_TKT |
|
633 | + ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) |
|
634 | + : $ticket; |
|
635 | + // need to make sue that the TKT_price is accurate after saving the prices. |
|
636 | + $ticket->ensure_TKT_Price_correct(); |
|
637 | + // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
638 | + if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
639 | + $update_prices = true; |
|
640 | + $new_default = clone $ticket; |
|
641 | + $new_default->set('TKT_ID', 0); |
|
642 | + $new_default->set('TKT_is_default', 1); |
|
643 | + $new_default->set('TKT_row', 1); |
|
644 | + $new_default->set('TKT_price', $ticket_price); |
|
645 | + // remove any dtt relations cause we DON'T want dtt relations attached |
|
646 | + // (note this is just removing the cached relations in the object) |
|
647 | + $new_default->_remove_relations('Datetime'); |
|
648 | + // @todo we need to add the current attached prices as new prices to the new default ticket. |
|
649 | + $new_default = $this->_add_prices_to_ticket( |
|
650 | + $price_rows, |
|
651 | + $new_default, |
|
652 | + $update_prices |
|
653 | + ); |
|
654 | + // don't forget the base price! |
|
655 | + $new_default = $this->_add_prices_to_ticket( |
|
656 | + array(), |
|
657 | + $new_default, |
|
658 | + $update_prices, |
|
659 | + $base_price, |
|
660 | + $base_price_id |
|
661 | + ); |
|
662 | + $new_default->save(); |
|
663 | + do_action( |
|
664 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
665 | + $new_default, |
|
666 | + $row, |
|
667 | + $ticket, |
|
668 | + $data |
|
669 | + ); |
|
670 | + } |
|
671 | + // DO ALL dtt relationships for both current tickets and any archived tickets |
|
672 | + // for the given dtt that are related to the current ticket. |
|
673 | + // TODO... not sure exactly how we're going to do this considering we don't know |
|
674 | + // what current ticket the archived tickets are related to |
|
675 | + // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
676 | + // let's assign any tickets that have been setup to the saved_tickets tracker |
|
677 | + // save existing TKT |
|
678 | + $ticket->save(); |
|
679 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
680 | + // save new TKT |
|
681 | + $new_tkt->save(); |
|
682 | + // add new ticket to array |
|
683 | + $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
684 | + do_action( |
|
685 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
686 | + $new_tkt, |
|
687 | + $row, |
|
688 | + $tkt, |
|
689 | + $data |
|
690 | + ); |
|
691 | + } else { |
|
692 | + // add tkt to saved tkts |
|
693 | + $saved_tickets[ $ticket->ID() ] = $ticket; |
|
694 | + do_action( |
|
695 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
696 | + $ticket, |
|
697 | + $row, |
|
698 | + $tkt, |
|
699 | + $data |
|
700 | + ); |
|
701 | + } |
|
702 | + } |
|
703 | + // now we need to handle tickets actually "deleted permanently". |
|
704 | + // There are cases where we'd want this to happen |
|
705 | + // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
706 | + // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
707 | + // No sense in keeping all the related data in the db! |
|
708 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
709 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
710 | + foreach ($tickets_removed as $id) { |
|
711 | + $id = absint($id); |
|
712 | + // get the ticket for this id |
|
713 | + $tkt_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
|
714 | + // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
715 | + if ($tkt_to_remove->get('TKT_is_default')) { |
|
716 | + continue; |
|
717 | + } |
|
718 | + // if this tkt has any registrations attached so then we just ARCHIVE |
|
719 | + // because we don't actually permanently delete these tickets. |
|
720 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
721 | + $tkt_to_remove->delete(); |
|
722 | + continue; |
|
723 | + } |
|
724 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
725 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
726 | + $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
727 | + foreach ($datetimes as $datetime) { |
|
728 | + $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
729 | + } |
|
730 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
731 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
732 | + $tkt_to_remove->delete_related('Price'); |
|
733 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
734 | + // finally let's delete this ticket |
|
735 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
736 | + $tkt_to_remove->delete_or_restore(); |
|
737 | + } |
|
738 | + return $saved_tickets; |
|
739 | + } |
|
740 | 740 | |
741 | 741 | |
742 | - /** |
|
743 | - * @access protected |
|
744 | - * @param EE_Ticket $ticket |
|
745 | - * @param \EE_Datetime[] $saved_datetimes |
|
746 | - * @param \EE_Datetime[] $added_datetimes |
|
747 | - * @param \EE_Datetime[] $removed_datetimes |
|
748 | - * @return EE_Ticket |
|
749 | - * @throws EE_Error |
|
750 | - */ |
|
751 | - protected function _update_ticket_datetimes( |
|
752 | - EE_Ticket $ticket, |
|
753 | - $saved_datetimes = array(), |
|
754 | - $added_datetimes = array(), |
|
755 | - $removed_datetimes = array() |
|
756 | - ) { |
|
757 | - // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
758 | - // and removing the ticket from datetimes it got removed from. |
|
759 | - // first let's add datetimes |
|
760 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
761 | - foreach ($added_datetimes as $row_id) { |
|
762 | - $row_id = (int) $row_id; |
|
763 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
764 | - $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
765 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
766 | - // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
767 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
768 | - $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false); |
|
769 | - } |
|
770 | - } |
|
771 | - } |
|
772 | - } |
|
773 | - // then remove datetimes |
|
774 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
775 | - foreach ($removed_datetimes as $row_id) { |
|
776 | - $row_id = (int) $row_id; |
|
777 | - // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
778 | - // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
779 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
780 | - $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
781 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
782 | - // If so, then we need to remove it's sold from the DTT_sold. |
|
783 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
784 | - $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold()); |
|
785 | - } |
|
786 | - } |
|
787 | - } |
|
788 | - } |
|
789 | - // cap ticket qty by datetime reg limits |
|
790 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
791 | - return $ticket; |
|
792 | - } |
|
742 | + /** |
|
743 | + * @access protected |
|
744 | + * @param EE_Ticket $ticket |
|
745 | + * @param \EE_Datetime[] $saved_datetimes |
|
746 | + * @param \EE_Datetime[] $added_datetimes |
|
747 | + * @param \EE_Datetime[] $removed_datetimes |
|
748 | + * @return EE_Ticket |
|
749 | + * @throws EE_Error |
|
750 | + */ |
|
751 | + protected function _update_ticket_datetimes( |
|
752 | + EE_Ticket $ticket, |
|
753 | + $saved_datetimes = array(), |
|
754 | + $added_datetimes = array(), |
|
755 | + $removed_datetimes = array() |
|
756 | + ) { |
|
757 | + // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
758 | + // and removing the ticket from datetimes it got removed from. |
|
759 | + // first let's add datetimes |
|
760 | + if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
761 | + foreach ($added_datetimes as $row_id) { |
|
762 | + $row_id = (int) $row_id; |
|
763 | + if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
764 | + $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
765 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
766 | + // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
767 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
768 | + $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false); |
|
769 | + } |
|
770 | + } |
|
771 | + } |
|
772 | + } |
|
773 | + // then remove datetimes |
|
774 | + if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
775 | + foreach ($removed_datetimes as $row_id) { |
|
776 | + $row_id = (int) $row_id; |
|
777 | + // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
778 | + // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
779 | + if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
780 | + $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
781 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
782 | + // If so, then we need to remove it's sold from the DTT_sold. |
|
783 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
784 | + $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold()); |
|
785 | + } |
|
786 | + } |
|
787 | + } |
|
788 | + } |
|
789 | + // cap ticket qty by datetime reg limits |
|
790 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
791 | + return $ticket; |
|
792 | + } |
|
793 | 793 | |
794 | 794 | |
795 | - /** |
|
796 | - * @access protected |
|
797 | - * @param EE_Ticket $ticket |
|
798 | - * @param array $price_rows |
|
799 | - * @param int $ticket_price |
|
800 | - * @param int $base_price |
|
801 | - * @param int $base_price_id |
|
802 | - * @return EE_Ticket |
|
803 | - * @throws ReflectionException |
|
804 | - * @throws InvalidArgumentException |
|
805 | - * @throws InvalidInterfaceException |
|
806 | - * @throws InvalidDataTypeException |
|
807 | - * @throws EE_Error |
|
808 | - */ |
|
809 | - protected function _duplicate_ticket( |
|
810 | - EE_Ticket $ticket, |
|
811 | - $price_rows = array(), |
|
812 | - $ticket_price = 0, |
|
813 | - $base_price = 0, |
|
814 | - $base_price_id = 0 |
|
815 | - ) { |
|
816 | - // create new ticket that's a copy of the existing |
|
817 | - // except a new id of course (and not archived) |
|
818 | - // AND has the new TKT_price associated with it. |
|
819 | - $new_ticket = clone $ticket; |
|
820 | - $new_ticket->set('TKT_ID', 0); |
|
821 | - $new_ticket->set_deleted(0); |
|
822 | - $new_ticket->set_price($ticket_price); |
|
823 | - $new_ticket->set_sold(0); |
|
824 | - // let's get a new ID for this ticket |
|
825 | - $new_ticket->save(); |
|
826 | - // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
827 | - $datetimes_on_existing = $ticket->datetimes(); |
|
828 | - $new_ticket = $this->_update_ticket_datetimes( |
|
829 | - $new_ticket, |
|
830 | - $datetimes_on_existing, |
|
831 | - array_keys($datetimes_on_existing) |
|
832 | - ); |
|
833 | - // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
834 | - // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
835 | - // available. |
|
836 | - if ($ticket->sold() > 0) { |
|
837 | - $new_qty = $ticket->qty() - $ticket->sold(); |
|
838 | - $new_ticket->set_qty($new_qty); |
|
839 | - } |
|
840 | - // now we update the prices just for this ticket |
|
841 | - $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
842 | - // and we update the base price |
|
843 | - $new_ticket = $this->_add_prices_to_ticket( |
|
844 | - array(), |
|
845 | - $new_ticket, |
|
846 | - true, |
|
847 | - $base_price, |
|
848 | - $base_price_id |
|
849 | - ); |
|
850 | - return $new_ticket; |
|
851 | - } |
|
795 | + /** |
|
796 | + * @access protected |
|
797 | + * @param EE_Ticket $ticket |
|
798 | + * @param array $price_rows |
|
799 | + * @param int $ticket_price |
|
800 | + * @param int $base_price |
|
801 | + * @param int $base_price_id |
|
802 | + * @return EE_Ticket |
|
803 | + * @throws ReflectionException |
|
804 | + * @throws InvalidArgumentException |
|
805 | + * @throws InvalidInterfaceException |
|
806 | + * @throws InvalidDataTypeException |
|
807 | + * @throws EE_Error |
|
808 | + */ |
|
809 | + protected function _duplicate_ticket( |
|
810 | + EE_Ticket $ticket, |
|
811 | + $price_rows = array(), |
|
812 | + $ticket_price = 0, |
|
813 | + $base_price = 0, |
|
814 | + $base_price_id = 0 |
|
815 | + ) { |
|
816 | + // create new ticket that's a copy of the existing |
|
817 | + // except a new id of course (and not archived) |
|
818 | + // AND has the new TKT_price associated with it. |
|
819 | + $new_ticket = clone $ticket; |
|
820 | + $new_ticket->set('TKT_ID', 0); |
|
821 | + $new_ticket->set_deleted(0); |
|
822 | + $new_ticket->set_price($ticket_price); |
|
823 | + $new_ticket->set_sold(0); |
|
824 | + // let's get a new ID for this ticket |
|
825 | + $new_ticket->save(); |
|
826 | + // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
827 | + $datetimes_on_existing = $ticket->datetimes(); |
|
828 | + $new_ticket = $this->_update_ticket_datetimes( |
|
829 | + $new_ticket, |
|
830 | + $datetimes_on_existing, |
|
831 | + array_keys($datetimes_on_existing) |
|
832 | + ); |
|
833 | + // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
834 | + // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
835 | + // available. |
|
836 | + if ($ticket->sold() > 0) { |
|
837 | + $new_qty = $ticket->qty() - $ticket->sold(); |
|
838 | + $new_ticket->set_qty($new_qty); |
|
839 | + } |
|
840 | + // now we update the prices just for this ticket |
|
841 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
842 | + // and we update the base price |
|
843 | + $new_ticket = $this->_add_prices_to_ticket( |
|
844 | + array(), |
|
845 | + $new_ticket, |
|
846 | + true, |
|
847 | + $base_price, |
|
848 | + $base_price_id |
|
849 | + ); |
|
850 | + return $new_ticket; |
|
851 | + } |
|
852 | 852 | |
853 | 853 | |
854 | - /** |
|
855 | - * This attaches a list of given prices to a ticket. |
|
856 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
857 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
858 | - * price info and prices are automatically "archived" via the ticket. |
|
859 | - * |
|
860 | - * @access private |
|
861 | - * @param array $prices Array of prices from the form. |
|
862 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
863 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
864 | - * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
865 | - * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
866 | - * @return EE_Ticket |
|
867 | - * @throws ReflectionException |
|
868 | - * @throws InvalidArgumentException |
|
869 | - * @throws InvalidInterfaceException |
|
870 | - * @throws InvalidDataTypeException |
|
871 | - * @throws EE_Error |
|
872 | - */ |
|
873 | - protected function _add_prices_to_ticket( |
|
874 | - array $prices, |
|
875 | - EE_Ticket $ticket, |
|
876 | - $new_prices = false, |
|
877 | - $base_price = false, |
|
878 | - $base_price_id = false |
|
879 | - ) { |
|
880 | - // let's just get any current prices that may exist on the given ticket |
|
881 | - // so we can remove any prices that got trashed in this session. |
|
882 | - $current_prices_on_ticket = $base_price !== false |
|
883 | - ? $ticket->base_price(true) |
|
884 | - : $ticket->price_modifiers(); |
|
885 | - $updated_prices = array(); |
|
886 | - // if $base_price ! FALSE then updating a base price. |
|
887 | - if ($base_price !== false) { |
|
888 | - $prices[1] = array( |
|
889 | - 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
890 | - 'PRT_ID' => 1, |
|
891 | - 'PRC_amount' => $base_price, |
|
892 | - 'PRC_name' => $ticket->get('TKT_name'), |
|
893 | - 'PRC_desc' => $ticket->get('TKT_description'), |
|
894 | - ); |
|
895 | - } |
|
896 | - // possibly need to save tkt |
|
897 | - if (! $ticket->ID()) { |
|
898 | - $ticket->save(); |
|
899 | - } |
|
900 | - foreach ($prices as $row => $prc) { |
|
901 | - $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
902 | - if (empty($prt_id)) { |
|
903 | - continue; |
|
904 | - } //prices MUST have a price type id. |
|
905 | - $PRC_values = array( |
|
906 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
907 | - 'PRT_ID' => $prt_id, |
|
908 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
909 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
910 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
911 | - 'PRC_is_default' => false, |
|
912 | - // make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
913 | - 'PRC_order' => $row, |
|
914 | - ); |
|
915 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
916 | - $PRC_values['PRC_ID'] = 0; |
|
917 | - $price = EE_Registry::instance()->load_class( |
|
918 | - 'Price', |
|
919 | - array($PRC_values), |
|
920 | - false, |
|
921 | - false |
|
922 | - ); |
|
923 | - } else { |
|
924 | - $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
925 | - // update this price with new values |
|
926 | - foreach ($PRC_values as $field => $value) { |
|
927 | - $price->set($field, $value); |
|
928 | - } |
|
929 | - } |
|
930 | - $price->save(); |
|
931 | - $updated_prices[ $price->ID() ] = $price; |
|
932 | - $ticket->_add_relation_to($price, 'Price'); |
|
933 | - } |
|
934 | - // now let's remove any prices that got removed from the ticket |
|
935 | - if (! empty($current_prices_on_ticket)) { |
|
936 | - $current = array_keys($current_prices_on_ticket); |
|
937 | - $updated = array_keys($updated_prices); |
|
938 | - $prices_to_remove = array_diff($current, $updated); |
|
939 | - if (! empty($prices_to_remove)) { |
|
940 | - foreach ($prices_to_remove as $prc_id) { |
|
941 | - $p = $current_prices_on_ticket[ $prc_id ]; |
|
942 | - $ticket->_remove_relation_to($p, 'Price'); |
|
943 | - // delete permanently the price |
|
944 | - $p->delete_or_restore(); |
|
945 | - } |
|
946 | - } |
|
947 | - } |
|
948 | - return $ticket; |
|
949 | - } |
|
854 | + /** |
|
855 | + * This attaches a list of given prices to a ticket. |
|
856 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
857 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
858 | + * price info and prices are automatically "archived" via the ticket. |
|
859 | + * |
|
860 | + * @access private |
|
861 | + * @param array $prices Array of prices from the form. |
|
862 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
863 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
864 | + * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
865 | + * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
866 | + * @return EE_Ticket |
|
867 | + * @throws ReflectionException |
|
868 | + * @throws InvalidArgumentException |
|
869 | + * @throws InvalidInterfaceException |
|
870 | + * @throws InvalidDataTypeException |
|
871 | + * @throws EE_Error |
|
872 | + */ |
|
873 | + protected function _add_prices_to_ticket( |
|
874 | + array $prices, |
|
875 | + EE_Ticket $ticket, |
|
876 | + $new_prices = false, |
|
877 | + $base_price = false, |
|
878 | + $base_price_id = false |
|
879 | + ) { |
|
880 | + // let's just get any current prices that may exist on the given ticket |
|
881 | + // so we can remove any prices that got trashed in this session. |
|
882 | + $current_prices_on_ticket = $base_price !== false |
|
883 | + ? $ticket->base_price(true) |
|
884 | + : $ticket->price_modifiers(); |
|
885 | + $updated_prices = array(); |
|
886 | + // if $base_price ! FALSE then updating a base price. |
|
887 | + if ($base_price !== false) { |
|
888 | + $prices[1] = array( |
|
889 | + 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
890 | + 'PRT_ID' => 1, |
|
891 | + 'PRC_amount' => $base_price, |
|
892 | + 'PRC_name' => $ticket->get('TKT_name'), |
|
893 | + 'PRC_desc' => $ticket->get('TKT_description'), |
|
894 | + ); |
|
895 | + } |
|
896 | + // possibly need to save tkt |
|
897 | + if (! $ticket->ID()) { |
|
898 | + $ticket->save(); |
|
899 | + } |
|
900 | + foreach ($prices as $row => $prc) { |
|
901 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
902 | + if (empty($prt_id)) { |
|
903 | + continue; |
|
904 | + } //prices MUST have a price type id. |
|
905 | + $PRC_values = array( |
|
906 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
907 | + 'PRT_ID' => $prt_id, |
|
908 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
909 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
910 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
911 | + 'PRC_is_default' => false, |
|
912 | + // make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
913 | + 'PRC_order' => $row, |
|
914 | + ); |
|
915 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
916 | + $PRC_values['PRC_ID'] = 0; |
|
917 | + $price = EE_Registry::instance()->load_class( |
|
918 | + 'Price', |
|
919 | + array($PRC_values), |
|
920 | + false, |
|
921 | + false |
|
922 | + ); |
|
923 | + } else { |
|
924 | + $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
925 | + // update this price with new values |
|
926 | + foreach ($PRC_values as $field => $value) { |
|
927 | + $price->set($field, $value); |
|
928 | + } |
|
929 | + } |
|
930 | + $price->save(); |
|
931 | + $updated_prices[ $price->ID() ] = $price; |
|
932 | + $ticket->_add_relation_to($price, 'Price'); |
|
933 | + } |
|
934 | + // now let's remove any prices that got removed from the ticket |
|
935 | + if (! empty($current_prices_on_ticket)) { |
|
936 | + $current = array_keys($current_prices_on_ticket); |
|
937 | + $updated = array_keys($updated_prices); |
|
938 | + $prices_to_remove = array_diff($current, $updated); |
|
939 | + if (! empty($prices_to_remove)) { |
|
940 | + foreach ($prices_to_remove as $prc_id) { |
|
941 | + $p = $current_prices_on_ticket[ $prc_id ]; |
|
942 | + $ticket->_remove_relation_to($p, 'Price'); |
|
943 | + // delete permanently the price |
|
944 | + $p->delete_or_restore(); |
|
945 | + } |
|
946 | + } |
|
947 | + } |
|
948 | + return $ticket; |
|
949 | + } |
|
950 | 950 | |
951 | 951 | |
952 | - /** |
|
953 | - * @param Events_Admin_Page $event_admin_obj |
|
954 | - * @return Events_Admin_Page |
|
955 | - */ |
|
956 | - public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
957 | - { |
|
958 | - return $event_admin_obj; |
|
959 | - // doing nothing for the moment. |
|
960 | - // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
961 | - // (use the set_template_args() method) |
|
962 | - /** |
|
963 | - * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
964 | - * 1. TKT_is_default_selector (visible) |
|
965 | - * 2. TKT_is_default (hidden) |
|
966 | - * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
967 | - * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
968 | - * this ticket to be saved as a default. |
|
969 | - * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
970 | - * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
971 | - * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
972 | - * the TKT HAS been saved as a default.. |
|
973 | - * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
974 | - * On Autosave: |
|
975 | - * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
976 | - * then set the TKT_is_default to false. |
|
977 | - * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
978 | - * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
979 | - * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
980 | - */ |
|
981 | - } |
|
952 | + /** |
|
953 | + * @param Events_Admin_Page $event_admin_obj |
|
954 | + * @return Events_Admin_Page |
|
955 | + */ |
|
956 | + public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
957 | + { |
|
958 | + return $event_admin_obj; |
|
959 | + // doing nothing for the moment. |
|
960 | + // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
961 | + // (use the set_template_args() method) |
|
962 | + /** |
|
963 | + * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
964 | + * 1. TKT_is_default_selector (visible) |
|
965 | + * 2. TKT_is_default (hidden) |
|
966 | + * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
967 | + * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
968 | + * this ticket to be saved as a default. |
|
969 | + * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
970 | + * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
971 | + * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
972 | + * the TKT HAS been saved as a default.. |
|
973 | + * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
974 | + * On Autosave: |
|
975 | + * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
976 | + * then set the TKT_is_default to false. |
|
977 | + * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
978 | + * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
979 | + * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
980 | + */ |
|
981 | + } |
|
982 | 982 | |
983 | 983 | |
984 | - /** |
|
985 | - * @throws ReflectionException |
|
986 | - * @throws InvalidArgumentException |
|
987 | - * @throws InvalidInterfaceException |
|
988 | - * @throws InvalidDataTypeException |
|
989 | - * @throws DomainException |
|
990 | - * @throws EE_Error |
|
991 | - */ |
|
992 | - public function pricing_metabox() |
|
993 | - { |
|
994 | - $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
995 | - $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
996 | - // set is_creating_event property. |
|
997 | - $EVT_ID = $event->ID(); |
|
998 | - $this->_is_creating_event = empty($this->_req_data['post']); |
|
999 | - // default main template args |
|
1000 | - $main_template_args = array( |
|
1001 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
1002 | - 'event_editor_event_datetimes_help_tab', |
|
1003 | - $this->_adminpage_obj->page_slug, |
|
1004 | - $this->_adminpage_obj->get_req_action(), |
|
1005 | - false, |
|
1006 | - false |
|
1007 | - ), |
|
1008 | - // todo need to add a filter to the template for the help text |
|
1009 | - // in the Events_Admin_Page core file so we can add further help |
|
1010 | - 'existing_datetime_ids' => '', |
|
1011 | - 'total_dtt_rows' => 1, |
|
1012 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
1013 | - 'add_new_dtt_info', |
|
1014 | - $this->_adminpage_obj->page_slug, |
|
1015 | - $this->_adminpage_obj->get_req_action(), |
|
1016 | - false, |
|
1017 | - false |
|
1018 | - ), |
|
1019 | - // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1020 | - 'datetime_rows' => '', |
|
1021 | - 'show_tickets_container' => '', |
|
1022 | - // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
1023 | - 'ticket_rows' => '', |
|
1024 | - 'existing_ticket_ids' => '', |
|
1025 | - 'total_ticket_rows' => 1, |
|
1026 | - 'ticket_js_structure' => '', |
|
1027 | - 'ee_collapsible_status' => ' ee-collapsible-open' |
|
1028 | - // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
1029 | - ); |
|
1030 | - $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
1031 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1032 | - /** |
|
1033 | - * 1. Start with retrieving Datetimes |
|
1034 | - * 2. For each datetime get related tickets |
|
1035 | - * 3. For each ticket get related prices |
|
1036 | - */ |
|
1037 | - /** @var EEM_Datetime $datetime_model */ |
|
1038 | - $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
1039 | - $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
1040 | - $main_template_args['total_dtt_rows'] = count($datetimes); |
|
1041 | - /** |
|
1042 | - * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
1043 | - * for why we are counting $datetime_row and then setting that on the Datetime object |
|
1044 | - */ |
|
1045 | - $datetime_row = 1; |
|
1046 | - foreach ($datetimes as $datetime) { |
|
1047 | - $DTT_ID = $datetime->get('DTT_ID'); |
|
1048 | - $datetime->set('DTT_order', $datetime_row); |
|
1049 | - $existing_datetime_ids[] = $DTT_ID; |
|
1050 | - // tickets attached |
|
1051 | - $related_tickets = $datetime->ID() > 0 |
|
1052 | - ? $datetime->get_many_related( |
|
1053 | - 'Ticket', |
|
1054 | - array( |
|
1055 | - array( |
|
1056 | - 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
1057 | - ), |
|
1058 | - 'default_where_conditions' => 'none', |
|
1059 | - 'order_by' => array('TKT_order' => 'ASC'), |
|
1060 | - ) |
|
1061 | - ) |
|
1062 | - : array(); |
|
1063 | - // if there are no related tickets this is likely a new event OR autodraft |
|
1064 | - // event so we need to generate the default tickets because datetimes |
|
1065 | - // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1066 | - // datetime on the event. |
|
1067 | - if (empty($related_tickets) && count($datetimes) < 2) { |
|
1068 | - /** @var EEM_Ticket $ticket_model */ |
|
1069 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1070 | - $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1071 | - // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1072 | - // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1073 | - $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1074 | - $main_default_ticket = reset($related_tickets); |
|
1075 | - if ($main_default_ticket instanceof EE_Ticket) { |
|
1076 | - foreach ($default_prices as $default_price) { |
|
1077 | - if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1078 | - continue; |
|
1079 | - } |
|
1080 | - $main_default_ticket->cache('Price', $default_price); |
|
1081 | - } |
|
1082 | - } |
|
1083 | - } |
|
1084 | - // we can't actually setup rows in this loop yet cause we don't know all |
|
1085 | - // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1086 | - // So we're going to temporarily cache some of that information. |
|
1087 | - // loop through and setup the ticket rows and make sure the order is set. |
|
1088 | - foreach ($related_tickets as $ticket) { |
|
1089 | - $TKT_ID = $ticket->get('TKT_ID'); |
|
1090 | - $ticket_row = $ticket->get('TKT_row'); |
|
1091 | - // we only want unique tickets in our final display!! |
|
1092 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1093 | - $existing_ticket_ids[] = $TKT_ID; |
|
1094 | - $all_tickets[] = $ticket; |
|
1095 | - } |
|
1096 | - // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1097 | - $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
1098 | - // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1099 | - if ( |
|
1100 | - ! isset($ticket_datetimes[ $TKT_ID ]) |
|
1101 | - || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
1102 | - ) { |
|
1103 | - $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
1104 | - } |
|
1105 | - } |
|
1106 | - $datetime_row++; |
|
1107 | - } |
|
1108 | - $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1109 | - $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1110 | - $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1111 | - // sort $all_tickets by order |
|
1112 | - usort( |
|
1113 | - $all_tickets, |
|
1114 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
1115 | - $a_order = (int) $a->get('TKT_order'); |
|
1116 | - $b_order = (int) $b->get('TKT_order'); |
|
1117 | - if ($a_order === $b_order) { |
|
1118 | - return 0; |
|
1119 | - } |
|
1120 | - return ($a_order < $b_order) ? -1 : 1; |
|
1121 | - } |
|
1122 | - ); |
|
1123 | - // k NOW we have all the data we need for setting up the dtt rows |
|
1124 | - // and ticket rows so we start our dtt loop again. |
|
1125 | - $datetime_row = 1; |
|
1126 | - foreach ($datetimes as $datetime) { |
|
1127 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1128 | - $datetime_row, |
|
1129 | - $datetime, |
|
1130 | - $datetime_tickets, |
|
1131 | - $all_tickets, |
|
1132 | - false, |
|
1133 | - $datetimes |
|
1134 | - ); |
|
1135 | - $datetime_row++; |
|
1136 | - } |
|
1137 | - // then loop through all tickets for the ticket rows. |
|
1138 | - $ticket_row = 1; |
|
1139 | - foreach ($all_tickets as $ticket) { |
|
1140 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1141 | - $ticket_row, |
|
1142 | - $ticket, |
|
1143 | - $ticket_datetimes, |
|
1144 | - $datetimes, |
|
1145 | - false, |
|
1146 | - $all_tickets |
|
1147 | - ); |
|
1148 | - $ticket_row++; |
|
1149 | - } |
|
1150 | - $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1151 | - EEH_Template::display_template( |
|
1152 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1153 | - $main_template_args |
|
1154 | - ); |
|
1155 | - } |
|
984 | + /** |
|
985 | + * @throws ReflectionException |
|
986 | + * @throws InvalidArgumentException |
|
987 | + * @throws InvalidInterfaceException |
|
988 | + * @throws InvalidDataTypeException |
|
989 | + * @throws DomainException |
|
990 | + * @throws EE_Error |
|
991 | + */ |
|
992 | + public function pricing_metabox() |
|
993 | + { |
|
994 | + $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
995 | + $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
996 | + // set is_creating_event property. |
|
997 | + $EVT_ID = $event->ID(); |
|
998 | + $this->_is_creating_event = empty($this->_req_data['post']); |
|
999 | + // default main template args |
|
1000 | + $main_template_args = array( |
|
1001 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
1002 | + 'event_editor_event_datetimes_help_tab', |
|
1003 | + $this->_adminpage_obj->page_slug, |
|
1004 | + $this->_adminpage_obj->get_req_action(), |
|
1005 | + false, |
|
1006 | + false |
|
1007 | + ), |
|
1008 | + // todo need to add a filter to the template for the help text |
|
1009 | + // in the Events_Admin_Page core file so we can add further help |
|
1010 | + 'existing_datetime_ids' => '', |
|
1011 | + 'total_dtt_rows' => 1, |
|
1012 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
1013 | + 'add_new_dtt_info', |
|
1014 | + $this->_adminpage_obj->page_slug, |
|
1015 | + $this->_adminpage_obj->get_req_action(), |
|
1016 | + false, |
|
1017 | + false |
|
1018 | + ), |
|
1019 | + // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1020 | + 'datetime_rows' => '', |
|
1021 | + 'show_tickets_container' => '', |
|
1022 | + // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
1023 | + 'ticket_rows' => '', |
|
1024 | + 'existing_ticket_ids' => '', |
|
1025 | + 'total_ticket_rows' => 1, |
|
1026 | + 'ticket_js_structure' => '', |
|
1027 | + 'ee_collapsible_status' => ' ee-collapsible-open' |
|
1028 | + // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
1029 | + ); |
|
1030 | + $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
1031 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1032 | + /** |
|
1033 | + * 1. Start with retrieving Datetimes |
|
1034 | + * 2. For each datetime get related tickets |
|
1035 | + * 3. For each ticket get related prices |
|
1036 | + */ |
|
1037 | + /** @var EEM_Datetime $datetime_model */ |
|
1038 | + $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
1039 | + $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
1040 | + $main_template_args['total_dtt_rows'] = count($datetimes); |
|
1041 | + /** |
|
1042 | + * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
1043 | + * for why we are counting $datetime_row and then setting that on the Datetime object |
|
1044 | + */ |
|
1045 | + $datetime_row = 1; |
|
1046 | + foreach ($datetimes as $datetime) { |
|
1047 | + $DTT_ID = $datetime->get('DTT_ID'); |
|
1048 | + $datetime->set('DTT_order', $datetime_row); |
|
1049 | + $existing_datetime_ids[] = $DTT_ID; |
|
1050 | + // tickets attached |
|
1051 | + $related_tickets = $datetime->ID() > 0 |
|
1052 | + ? $datetime->get_many_related( |
|
1053 | + 'Ticket', |
|
1054 | + array( |
|
1055 | + array( |
|
1056 | + 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
1057 | + ), |
|
1058 | + 'default_where_conditions' => 'none', |
|
1059 | + 'order_by' => array('TKT_order' => 'ASC'), |
|
1060 | + ) |
|
1061 | + ) |
|
1062 | + : array(); |
|
1063 | + // if there are no related tickets this is likely a new event OR autodraft |
|
1064 | + // event so we need to generate the default tickets because datetimes |
|
1065 | + // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1066 | + // datetime on the event. |
|
1067 | + if (empty($related_tickets) && count($datetimes) < 2) { |
|
1068 | + /** @var EEM_Ticket $ticket_model */ |
|
1069 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1070 | + $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1071 | + // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1072 | + // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1073 | + $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1074 | + $main_default_ticket = reset($related_tickets); |
|
1075 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
1076 | + foreach ($default_prices as $default_price) { |
|
1077 | + if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1078 | + continue; |
|
1079 | + } |
|
1080 | + $main_default_ticket->cache('Price', $default_price); |
|
1081 | + } |
|
1082 | + } |
|
1083 | + } |
|
1084 | + // we can't actually setup rows in this loop yet cause we don't know all |
|
1085 | + // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1086 | + // So we're going to temporarily cache some of that information. |
|
1087 | + // loop through and setup the ticket rows and make sure the order is set. |
|
1088 | + foreach ($related_tickets as $ticket) { |
|
1089 | + $TKT_ID = $ticket->get('TKT_ID'); |
|
1090 | + $ticket_row = $ticket->get('TKT_row'); |
|
1091 | + // we only want unique tickets in our final display!! |
|
1092 | + if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1093 | + $existing_ticket_ids[] = $TKT_ID; |
|
1094 | + $all_tickets[] = $ticket; |
|
1095 | + } |
|
1096 | + // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1097 | + $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
1098 | + // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1099 | + if ( |
|
1100 | + ! isset($ticket_datetimes[ $TKT_ID ]) |
|
1101 | + || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
1102 | + ) { |
|
1103 | + $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
1104 | + } |
|
1105 | + } |
|
1106 | + $datetime_row++; |
|
1107 | + } |
|
1108 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1109 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1110 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1111 | + // sort $all_tickets by order |
|
1112 | + usort( |
|
1113 | + $all_tickets, |
|
1114 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
1115 | + $a_order = (int) $a->get('TKT_order'); |
|
1116 | + $b_order = (int) $b->get('TKT_order'); |
|
1117 | + if ($a_order === $b_order) { |
|
1118 | + return 0; |
|
1119 | + } |
|
1120 | + return ($a_order < $b_order) ? -1 : 1; |
|
1121 | + } |
|
1122 | + ); |
|
1123 | + // k NOW we have all the data we need for setting up the dtt rows |
|
1124 | + // and ticket rows so we start our dtt loop again. |
|
1125 | + $datetime_row = 1; |
|
1126 | + foreach ($datetimes as $datetime) { |
|
1127 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1128 | + $datetime_row, |
|
1129 | + $datetime, |
|
1130 | + $datetime_tickets, |
|
1131 | + $all_tickets, |
|
1132 | + false, |
|
1133 | + $datetimes |
|
1134 | + ); |
|
1135 | + $datetime_row++; |
|
1136 | + } |
|
1137 | + // then loop through all tickets for the ticket rows. |
|
1138 | + $ticket_row = 1; |
|
1139 | + foreach ($all_tickets as $ticket) { |
|
1140 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1141 | + $ticket_row, |
|
1142 | + $ticket, |
|
1143 | + $ticket_datetimes, |
|
1144 | + $datetimes, |
|
1145 | + false, |
|
1146 | + $all_tickets |
|
1147 | + ); |
|
1148 | + $ticket_row++; |
|
1149 | + } |
|
1150 | + $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1151 | + EEH_Template::display_template( |
|
1152 | + PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1153 | + $main_template_args |
|
1154 | + ); |
|
1155 | + } |
|
1156 | 1156 | |
1157 | 1157 | |
1158 | - /** |
|
1159 | - * @param int $datetime_row |
|
1160 | - * @param EE_Datetime $datetime |
|
1161 | - * @param array $datetime_tickets |
|
1162 | - * @param array $all_tickets |
|
1163 | - * @param bool $default |
|
1164 | - * @param array $all_datetimes |
|
1165 | - * @return mixed |
|
1166 | - * @throws DomainException |
|
1167 | - * @throws EE_Error |
|
1168 | - */ |
|
1169 | - protected function _get_datetime_row( |
|
1170 | - $datetime_row, |
|
1171 | - EE_Datetime $datetime, |
|
1172 | - $datetime_tickets = array(), |
|
1173 | - $all_tickets = array(), |
|
1174 | - $default = false, |
|
1175 | - $all_datetimes = array() |
|
1176 | - ) { |
|
1177 | - $dtt_display_template_args = array( |
|
1178 | - 'dtt_edit_row' => $this->_get_dtt_edit_row( |
|
1179 | - $datetime_row, |
|
1180 | - $datetime, |
|
1181 | - $default, |
|
1182 | - $all_datetimes |
|
1183 | - ), |
|
1184 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1185 | - $datetime_row, |
|
1186 | - $datetime, |
|
1187 | - $datetime_tickets, |
|
1188 | - $all_tickets, |
|
1189 | - $default |
|
1190 | - ), |
|
1191 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1192 | - ); |
|
1193 | - return EEH_Template::display_template( |
|
1194 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1195 | - $dtt_display_template_args, |
|
1196 | - true |
|
1197 | - ); |
|
1198 | - } |
|
1158 | + /** |
|
1159 | + * @param int $datetime_row |
|
1160 | + * @param EE_Datetime $datetime |
|
1161 | + * @param array $datetime_tickets |
|
1162 | + * @param array $all_tickets |
|
1163 | + * @param bool $default |
|
1164 | + * @param array $all_datetimes |
|
1165 | + * @return mixed |
|
1166 | + * @throws DomainException |
|
1167 | + * @throws EE_Error |
|
1168 | + */ |
|
1169 | + protected function _get_datetime_row( |
|
1170 | + $datetime_row, |
|
1171 | + EE_Datetime $datetime, |
|
1172 | + $datetime_tickets = array(), |
|
1173 | + $all_tickets = array(), |
|
1174 | + $default = false, |
|
1175 | + $all_datetimes = array() |
|
1176 | + ) { |
|
1177 | + $dtt_display_template_args = array( |
|
1178 | + 'dtt_edit_row' => $this->_get_dtt_edit_row( |
|
1179 | + $datetime_row, |
|
1180 | + $datetime, |
|
1181 | + $default, |
|
1182 | + $all_datetimes |
|
1183 | + ), |
|
1184 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1185 | + $datetime_row, |
|
1186 | + $datetime, |
|
1187 | + $datetime_tickets, |
|
1188 | + $all_tickets, |
|
1189 | + $default |
|
1190 | + ), |
|
1191 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1192 | + ); |
|
1193 | + return EEH_Template::display_template( |
|
1194 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1195 | + $dtt_display_template_args, |
|
1196 | + true |
|
1197 | + ); |
|
1198 | + } |
|
1199 | 1199 | |
1200 | 1200 | |
1201 | - /** |
|
1202 | - * This method is used to generate a dtt fields edit row. |
|
1203 | - * The same row is used to generate a row with valid DTT objects |
|
1204 | - * and the default row that is used as the skeleton by the js. |
|
1205 | - * |
|
1206 | - * @param int $datetime_row The row number for the row being generated. |
|
1207 | - * @param EE_Datetime $datetime |
|
1208 | - * @param bool $default Whether a default row is being generated or not. |
|
1209 | - * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1210 | - * @return string |
|
1211 | - * @throws DomainException |
|
1212 | - * @throws EE_Error |
|
1213 | - */ |
|
1214 | - protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1215 | - { |
|
1216 | - // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1217 | - $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1218 | - $template_args = array( |
|
1219 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1220 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1221 | - 'edit_dtt_expanded' => '', |
|
1222 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1223 | - 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
1224 | - 'DTT_description' => $default ? '' : $datetime->get_raw('DTT_description'), |
|
1225 | - 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1226 | - 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1227 | - 'DTT_reg_limit' => $default |
|
1228 | - ? '' |
|
1229 | - : $datetime->get_pretty( |
|
1230 | - 'DTT_reg_limit', |
|
1231 | - 'input' |
|
1232 | - ), |
|
1233 | - 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1234 | - 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1235 | - 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1236 | - 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1237 | - ? '' |
|
1238 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1239 | - 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1240 | - ? 'ee-lock-icon' |
|
1241 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1242 | - 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1243 | - ? '' |
|
1244 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
1245 | - array( |
|
1246 | - 'event_id' => $datetime->event()->ID(), |
|
1247 | - 'datetime_id' => $datetime->ID(), |
|
1248 | - 'use_filters' => true |
|
1249 | - ), |
|
1250 | - REG_ADMIN_URL |
|
1251 | - ), |
|
1252 | - ); |
|
1253 | - $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1254 | - ? 'display:none' |
|
1255 | - : ''; |
|
1256 | - // allow filtering of template args at this point. |
|
1257 | - $template_args = apply_filters( |
|
1258 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1259 | - $template_args, |
|
1260 | - $datetime_row, |
|
1261 | - $datetime, |
|
1262 | - $default, |
|
1263 | - $all_datetimes, |
|
1264 | - $this->_is_creating_event |
|
1265 | - ); |
|
1266 | - return EEH_Template::display_template( |
|
1267 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1268 | - $template_args, |
|
1269 | - true |
|
1270 | - ); |
|
1271 | - } |
|
1201 | + /** |
|
1202 | + * This method is used to generate a dtt fields edit row. |
|
1203 | + * The same row is used to generate a row with valid DTT objects |
|
1204 | + * and the default row that is used as the skeleton by the js. |
|
1205 | + * |
|
1206 | + * @param int $datetime_row The row number for the row being generated. |
|
1207 | + * @param EE_Datetime $datetime |
|
1208 | + * @param bool $default Whether a default row is being generated or not. |
|
1209 | + * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1210 | + * @return string |
|
1211 | + * @throws DomainException |
|
1212 | + * @throws EE_Error |
|
1213 | + */ |
|
1214 | + protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1215 | + { |
|
1216 | + // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1217 | + $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1218 | + $template_args = array( |
|
1219 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1220 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1221 | + 'edit_dtt_expanded' => '', |
|
1222 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1223 | + 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
1224 | + 'DTT_description' => $default ? '' : $datetime->get_raw('DTT_description'), |
|
1225 | + 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1226 | + 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1227 | + 'DTT_reg_limit' => $default |
|
1228 | + ? '' |
|
1229 | + : $datetime->get_pretty( |
|
1230 | + 'DTT_reg_limit', |
|
1231 | + 'input' |
|
1232 | + ), |
|
1233 | + 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1234 | + 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1235 | + 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1236 | + 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1237 | + ? '' |
|
1238 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1239 | + 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1240 | + ? 'ee-lock-icon' |
|
1241 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1242 | + 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1243 | + ? '' |
|
1244 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
1245 | + array( |
|
1246 | + 'event_id' => $datetime->event()->ID(), |
|
1247 | + 'datetime_id' => $datetime->ID(), |
|
1248 | + 'use_filters' => true |
|
1249 | + ), |
|
1250 | + REG_ADMIN_URL |
|
1251 | + ), |
|
1252 | + ); |
|
1253 | + $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1254 | + ? 'display:none' |
|
1255 | + : ''; |
|
1256 | + // allow filtering of template args at this point. |
|
1257 | + $template_args = apply_filters( |
|
1258 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1259 | + $template_args, |
|
1260 | + $datetime_row, |
|
1261 | + $datetime, |
|
1262 | + $default, |
|
1263 | + $all_datetimes, |
|
1264 | + $this->_is_creating_event |
|
1265 | + ); |
|
1266 | + return EEH_Template::display_template( |
|
1267 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1268 | + $template_args, |
|
1269 | + true |
|
1270 | + ); |
|
1271 | + } |
|
1272 | 1272 | |
1273 | 1273 | |
1274 | - /** |
|
1275 | - * @param int $datetime_row |
|
1276 | - * @param EE_Datetime $datetime |
|
1277 | - * @param array $datetime_tickets |
|
1278 | - * @param array $all_tickets |
|
1279 | - * @param bool $default |
|
1280 | - * @return mixed |
|
1281 | - * @throws DomainException |
|
1282 | - * @throws EE_Error |
|
1283 | - */ |
|
1284 | - protected function _get_dtt_attached_tickets_row( |
|
1285 | - $datetime_row, |
|
1286 | - $datetime, |
|
1287 | - $datetime_tickets = array(), |
|
1288 | - $all_tickets = array(), |
|
1289 | - $default = false |
|
1290 | - ) { |
|
1291 | - $template_args = array( |
|
1292 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1293 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1294 | - 'DTT_description' => $default ? '' : $datetime->get_raw('DTT_description'), |
|
1295 | - 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1296 | - 'show_tickets_row' => 'display:none;', |
|
1297 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1298 | - 'add_new_ticket_via_datetime', |
|
1299 | - $this->_adminpage_obj->page_slug, |
|
1300 | - $this->_adminpage_obj->get_req_action(), |
|
1301 | - false, |
|
1302 | - false |
|
1303 | - ), |
|
1304 | - // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1305 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1306 | - ); |
|
1307 | - // need to setup the list items (but only if this isn't a default skeleton setup) |
|
1308 | - if (! $default) { |
|
1309 | - $ticket_row = 1; |
|
1310 | - foreach ($all_tickets as $ticket) { |
|
1311 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1312 | - $datetime_row, |
|
1313 | - $ticket_row, |
|
1314 | - $datetime, |
|
1315 | - $ticket, |
|
1316 | - $datetime_tickets, |
|
1317 | - $default |
|
1318 | - ); |
|
1319 | - $ticket_row++; |
|
1320 | - } |
|
1321 | - } |
|
1322 | - // filter template args at this point |
|
1323 | - $template_args = apply_filters( |
|
1324 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1325 | - $template_args, |
|
1326 | - $datetime_row, |
|
1327 | - $datetime, |
|
1328 | - $datetime_tickets, |
|
1329 | - $all_tickets, |
|
1330 | - $default, |
|
1331 | - $this->_is_creating_event |
|
1332 | - ); |
|
1333 | - return EEH_Template::display_template( |
|
1334 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1335 | - $template_args, |
|
1336 | - true |
|
1337 | - ); |
|
1338 | - } |
|
1274 | + /** |
|
1275 | + * @param int $datetime_row |
|
1276 | + * @param EE_Datetime $datetime |
|
1277 | + * @param array $datetime_tickets |
|
1278 | + * @param array $all_tickets |
|
1279 | + * @param bool $default |
|
1280 | + * @return mixed |
|
1281 | + * @throws DomainException |
|
1282 | + * @throws EE_Error |
|
1283 | + */ |
|
1284 | + protected function _get_dtt_attached_tickets_row( |
|
1285 | + $datetime_row, |
|
1286 | + $datetime, |
|
1287 | + $datetime_tickets = array(), |
|
1288 | + $all_tickets = array(), |
|
1289 | + $default = false |
|
1290 | + ) { |
|
1291 | + $template_args = array( |
|
1292 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1293 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1294 | + 'DTT_description' => $default ? '' : $datetime->get_raw('DTT_description'), |
|
1295 | + 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1296 | + 'show_tickets_row' => 'display:none;', |
|
1297 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1298 | + 'add_new_ticket_via_datetime', |
|
1299 | + $this->_adminpage_obj->page_slug, |
|
1300 | + $this->_adminpage_obj->get_req_action(), |
|
1301 | + false, |
|
1302 | + false |
|
1303 | + ), |
|
1304 | + // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1305 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1306 | + ); |
|
1307 | + // need to setup the list items (but only if this isn't a default skeleton setup) |
|
1308 | + if (! $default) { |
|
1309 | + $ticket_row = 1; |
|
1310 | + foreach ($all_tickets as $ticket) { |
|
1311 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1312 | + $datetime_row, |
|
1313 | + $ticket_row, |
|
1314 | + $datetime, |
|
1315 | + $ticket, |
|
1316 | + $datetime_tickets, |
|
1317 | + $default |
|
1318 | + ); |
|
1319 | + $ticket_row++; |
|
1320 | + } |
|
1321 | + } |
|
1322 | + // filter template args at this point |
|
1323 | + $template_args = apply_filters( |
|
1324 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1325 | + $template_args, |
|
1326 | + $datetime_row, |
|
1327 | + $datetime, |
|
1328 | + $datetime_tickets, |
|
1329 | + $all_tickets, |
|
1330 | + $default, |
|
1331 | + $this->_is_creating_event |
|
1332 | + ); |
|
1333 | + return EEH_Template::display_template( |
|
1334 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1335 | + $template_args, |
|
1336 | + true |
|
1337 | + ); |
|
1338 | + } |
|
1339 | 1339 | |
1340 | 1340 | |
1341 | - /** |
|
1342 | - * @param int $datetime_row |
|
1343 | - * @param int $ticket_row |
|
1344 | - * @param EE_Datetime $datetime |
|
1345 | - * @param EE_Ticket $ticket |
|
1346 | - * @param array $datetime_tickets |
|
1347 | - * @param bool $default |
|
1348 | - * @return mixed |
|
1349 | - * @throws DomainException |
|
1350 | - * @throws EE_Error |
|
1351 | - */ |
|
1352 | - protected function _get_datetime_tickets_list_item( |
|
1353 | - $datetime_row, |
|
1354 | - $ticket_row, |
|
1355 | - $datetime, |
|
1356 | - $ticket, |
|
1357 | - $datetime_tickets = array(), |
|
1358 | - $default = false |
|
1359 | - ) { |
|
1360 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
1361 | - ? $datetime_tickets[ $datetime->ID() ] |
|
1362 | - : array(); |
|
1363 | - $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1364 | - $no_ticket = $default && empty($ticket); |
|
1365 | - $template_args = array( |
|
1366 | - 'dtt_row' => $default |
|
1367 | - ? 'DTTNUM' |
|
1368 | - : $datetime_row, |
|
1369 | - 'tkt_row' => $no_ticket |
|
1370 | - ? 'TICKETNUM' |
|
1371 | - : $ticket_row, |
|
1372 | - 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1373 | - ? ' checked' |
|
1374 | - : '', |
|
1375 | - 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1376 | - ? ' ticket-selected' |
|
1377 | - : '', |
|
1378 | - 'TKT_name' => $no_ticket |
|
1379 | - ? 'TKTNAME' |
|
1380 | - : $ticket->get('TKT_name'), |
|
1381 | - 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1382 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1383 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
1384 | - ); |
|
1385 | - // filter template args |
|
1386 | - $template_args = apply_filters( |
|
1387 | - 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1388 | - $template_args, |
|
1389 | - $datetime_row, |
|
1390 | - $ticket_row, |
|
1391 | - $datetime, |
|
1392 | - $ticket, |
|
1393 | - $datetime_tickets, |
|
1394 | - $default, |
|
1395 | - $this->_is_creating_event |
|
1396 | - ); |
|
1397 | - return EEH_Template::display_template( |
|
1398 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1399 | - $template_args, |
|
1400 | - true |
|
1401 | - ); |
|
1402 | - } |
|
1341 | + /** |
|
1342 | + * @param int $datetime_row |
|
1343 | + * @param int $ticket_row |
|
1344 | + * @param EE_Datetime $datetime |
|
1345 | + * @param EE_Ticket $ticket |
|
1346 | + * @param array $datetime_tickets |
|
1347 | + * @param bool $default |
|
1348 | + * @return mixed |
|
1349 | + * @throws DomainException |
|
1350 | + * @throws EE_Error |
|
1351 | + */ |
|
1352 | + protected function _get_datetime_tickets_list_item( |
|
1353 | + $datetime_row, |
|
1354 | + $ticket_row, |
|
1355 | + $datetime, |
|
1356 | + $ticket, |
|
1357 | + $datetime_tickets = array(), |
|
1358 | + $default = false |
|
1359 | + ) { |
|
1360 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
1361 | + ? $datetime_tickets[ $datetime->ID() ] |
|
1362 | + : array(); |
|
1363 | + $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1364 | + $no_ticket = $default && empty($ticket); |
|
1365 | + $template_args = array( |
|
1366 | + 'dtt_row' => $default |
|
1367 | + ? 'DTTNUM' |
|
1368 | + : $datetime_row, |
|
1369 | + 'tkt_row' => $no_ticket |
|
1370 | + ? 'TICKETNUM' |
|
1371 | + : $ticket_row, |
|
1372 | + 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1373 | + ? ' checked' |
|
1374 | + : '', |
|
1375 | + 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1376 | + ? ' ticket-selected' |
|
1377 | + : '', |
|
1378 | + 'TKT_name' => $no_ticket |
|
1379 | + ? 'TKTNAME' |
|
1380 | + : $ticket->get('TKT_name'), |
|
1381 | + 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1382 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1383 | + : ' tkt-status-' . $ticket->ticket_status(), |
|
1384 | + ); |
|
1385 | + // filter template args |
|
1386 | + $template_args = apply_filters( |
|
1387 | + 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1388 | + $template_args, |
|
1389 | + $datetime_row, |
|
1390 | + $ticket_row, |
|
1391 | + $datetime, |
|
1392 | + $ticket, |
|
1393 | + $datetime_tickets, |
|
1394 | + $default, |
|
1395 | + $this->_is_creating_event |
|
1396 | + ); |
|
1397 | + return EEH_Template::display_template( |
|
1398 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1399 | + $template_args, |
|
1400 | + true |
|
1401 | + ); |
|
1402 | + } |
|
1403 | 1403 | |
1404 | 1404 | |
1405 | - /** |
|
1406 | - * This generates the ticket row for tickets. |
|
1407 | - * This same method is used to generate both the actual rows and the js skeleton row |
|
1408 | - * (when default === true) |
|
1409 | - * |
|
1410 | - * @param int $ticket_row Represents the row number being generated. |
|
1411 | - * @param $ticket |
|
1412 | - * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1413 | - * or empty for default |
|
1414 | - * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1415 | - * @param bool $default Whether default row being generated or not. |
|
1416 | - * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1417 | - * (or empty in the case of defaults) |
|
1418 | - * @return mixed |
|
1419 | - * @throws InvalidArgumentException |
|
1420 | - * @throws InvalidInterfaceException |
|
1421 | - * @throws InvalidDataTypeException |
|
1422 | - * @throws DomainException |
|
1423 | - * @throws EE_Error |
|
1424 | - * @throws ReflectionException |
|
1425 | - */ |
|
1426 | - protected function _get_ticket_row( |
|
1427 | - $ticket_row, |
|
1428 | - $ticket, |
|
1429 | - $ticket_datetimes, |
|
1430 | - $all_datetimes, |
|
1431 | - $default = false, |
|
1432 | - $all_tickets = array() |
|
1433 | - ) { |
|
1434 | - // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1435 | - $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1436 | - $prices = ! empty($ticket) && ! $default |
|
1437 | - ? $ticket->get_many_related( |
|
1438 | - 'Price', |
|
1439 | - array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')) |
|
1440 | - ) |
|
1441 | - : array(); |
|
1442 | - // if there is only one price (which would be the base price) |
|
1443 | - // or NO prices and this ticket is a default ticket, |
|
1444 | - // let's just make sure there are no cached default prices on the object. |
|
1445 | - // This is done by not including any query_params. |
|
1446 | - if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1447 | - $prices = $ticket->prices(); |
|
1448 | - } |
|
1449 | - // check if we're dealing with a default ticket in which case |
|
1450 | - // we don't want any starting_ticket_datetime_row values set |
|
1451 | - // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1452 | - // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1453 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
1454 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
1455 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
1456 | - : array(); |
|
1457 | - $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1458 | - $base_price = $default ? null : $ticket->base_price(); |
|
1459 | - $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1460 | - // breaking out complicated condition for ticket_status |
|
1461 | - if ($default) { |
|
1462 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1463 | - } else { |
|
1464 | - $ticket_status_class = $ticket->is_default() |
|
1465 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1466 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
1467 | - } |
|
1468 | - // breaking out complicated condition for TKT_taxable |
|
1469 | - if ($default) { |
|
1470 | - $TKT_taxable = ''; |
|
1471 | - } else { |
|
1472 | - $TKT_taxable = $ticket->taxable() |
|
1473 | - ? 'checked' |
|
1474 | - : ''; |
|
1475 | - } |
|
1476 | - if ($default) { |
|
1477 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1478 | - } elseif ($ticket->is_default()) { |
|
1479 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1480 | - } else { |
|
1481 | - $TKT_status = $ticket->ticket_status(true); |
|
1482 | - } |
|
1483 | - if ($default) { |
|
1484 | - $TKT_min = ''; |
|
1485 | - } else { |
|
1486 | - $TKT_min = $ticket->min(); |
|
1487 | - if ($TKT_min === -1 || $TKT_min === 0) { |
|
1488 | - $TKT_min = ''; |
|
1489 | - } |
|
1490 | - } |
|
1491 | - $template_args = array( |
|
1492 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1493 | - 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1494 | - // on initial page load this will always be the correct order. |
|
1495 | - 'tkt_status_class' => $ticket_status_class, |
|
1496 | - 'display_edit_tkt_row' => 'display:none;', |
|
1497 | - 'edit_tkt_expanded' => '', |
|
1498 | - 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1499 | - 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
1500 | - 'TKT_start_date' => $default |
|
1501 | - ? '' |
|
1502 | - : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
1503 | - 'TKT_end_date' => $default |
|
1504 | - ? '' |
|
1505 | - : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
1506 | - 'TKT_status' => $TKT_status, |
|
1507 | - 'TKT_price' => $default |
|
1508 | - ? '' |
|
1509 | - : EEH_Template::format_currency( |
|
1510 | - $ticket->get_ticket_total_with_taxes(), |
|
1511 | - false, |
|
1512 | - false |
|
1513 | - ), |
|
1514 | - 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1515 | - 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1516 | - 'TKT_qty' => $default |
|
1517 | - ? '' |
|
1518 | - : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1519 | - 'TKT_qty_for_input' => $default |
|
1520 | - ? '' |
|
1521 | - : $ticket->get_pretty('TKT_qty', 'input'), |
|
1522 | - 'TKT_uses' => $default |
|
1523 | - ? '' |
|
1524 | - : $ticket->get_pretty('TKT_uses', 'input'), |
|
1525 | - 'TKT_min' => $TKT_min, |
|
1526 | - 'TKT_max' => $default |
|
1527 | - ? '' |
|
1528 | - : $ticket->get_pretty('TKT_max', 'input'), |
|
1529 | - 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1530 | - 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1531 | - 'TKT_registrations' => $default |
|
1532 | - ? 0 |
|
1533 | - : $ticket->count_registrations( |
|
1534 | - array( |
|
1535 | - array( |
|
1536 | - 'STS_ID' => array( |
|
1537 | - '!=', |
|
1538 | - EEM_Registration::status_id_incomplete, |
|
1539 | - ), |
|
1540 | - ), |
|
1541 | - ) |
|
1542 | - ), |
|
1543 | - 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
1544 | - 'TKT_description' => $default ? '' : $ticket->get_raw('TKT_description'), |
|
1545 | - 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
1546 | - 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1547 | - 'TKT_is_default_selector' => '', |
|
1548 | - 'ticket_price_rows' => '', |
|
1549 | - 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1550 | - ? '' |
|
1551 | - : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1552 | - 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1553 | - 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1554 | - ? '' |
|
1555 | - : 'display:none;', |
|
1556 | - 'show_price_mod_button' => count($prices) > 1 |
|
1557 | - || ($default && $count_price_mods > 0) |
|
1558 | - || (! $default && $ticket->deleted()) |
|
1559 | - ? 'display:none;' |
|
1560 | - : '', |
|
1561 | - 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1562 | - 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1563 | - 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1564 | - 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1565 | - 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1566 | - 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1567 | - 'TKT_taxable' => $TKT_taxable, |
|
1568 | - 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
1569 | - ? '' |
|
1570 | - : 'display:none;', |
|
1571 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1572 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1573 | - $ticket_subtotal, |
|
1574 | - false, |
|
1575 | - false |
|
1576 | - ), |
|
1577 | - 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1578 | - 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1579 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
1580 | - 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1581 | - ? ' ticket-archived' |
|
1582 | - : '', |
|
1583 | - 'trash_icon' => $ticket instanceof EE_Ticket |
|
1584 | - && $ticket->deleted() |
|
1585 | - && ! $ticket->is_permanently_deleteable() |
|
1586 | - ? 'ee-lock-icon ' |
|
1587 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1588 | - 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1589 | - ? '' |
|
1590 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1591 | - ); |
|
1592 | - $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1593 | - ? 'display:none' |
|
1594 | - : ''; |
|
1595 | - // handle rows that should NOT be empty |
|
1596 | - if (empty($template_args['TKT_start_date'])) { |
|
1597 | - // if empty then the start date will be now. |
|
1598 | - $template_args['TKT_start_date'] = date( |
|
1599 | - $this->_date_time_format, |
|
1600 | - current_time('timestamp') |
|
1601 | - ); |
|
1602 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1603 | - } |
|
1604 | - if (empty($template_args['TKT_end_date'])) { |
|
1605 | - // get the earliest datetime (if present); |
|
1606 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1607 | - ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1608 | - 'Datetime', |
|
1609 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1610 | - ) |
|
1611 | - : null; |
|
1612 | - if (! empty($earliest_dtt)) { |
|
1613 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1614 | - 'DTT_EVT_start', |
|
1615 | - $this->_date_time_format |
|
1616 | - ); |
|
1617 | - } else { |
|
1618 | - // default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1619 | - $template_args['TKT_end_date'] = date( |
|
1620 | - $this->_date_time_format, |
|
1621 | - mktime( |
|
1622 | - 24, |
|
1623 | - 0, |
|
1624 | - 0, |
|
1625 | - date('m'), |
|
1626 | - date('d') + 29, |
|
1627 | - date('Y') |
|
1628 | - ) |
|
1629 | - ); |
|
1630 | - } |
|
1631 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1632 | - } |
|
1633 | - // generate ticket_datetime items |
|
1634 | - if (! $default) { |
|
1635 | - $datetime_row = 1; |
|
1636 | - foreach ($all_datetimes as $datetime) { |
|
1637 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1638 | - $datetime_row, |
|
1639 | - $ticket_row, |
|
1640 | - $datetime, |
|
1641 | - $ticket, |
|
1642 | - $ticket_datetimes, |
|
1643 | - $default |
|
1644 | - ); |
|
1645 | - $datetime_row++; |
|
1646 | - } |
|
1647 | - } |
|
1648 | - $price_row = 1; |
|
1649 | - foreach ($prices as $price) { |
|
1650 | - if (! $price instanceof EE_Price) { |
|
1651 | - continue; |
|
1652 | - } |
|
1653 | - if ($price->is_base_price()) { |
|
1654 | - $price_row++; |
|
1655 | - continue; |
|
1656 | - } |
|
1657 | - $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1658 | - $show_create = ! (count($prices) > 1 && count($prices) !== $price_row); |
|
1659 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1660 | - $ticket_row, |
|
1661 | - $price_row, |
|
1662 | - $price, |
|
1663 | - $default, |
|
1664 | - $ticket, |
|
1665 | - $show_trash, |
|
1666 | - $show_create |
|
1667 | - ); |
|
1668 | - $price_row++; |
|
1669 | - } |
|
1670 | - // filter $template_args |
|
1671 | - $template_args = apply_filters( |
|
1672 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1673 | - $template_args, |
|
1674 | - $ticket_row, |
|
1675 | - $ticket, |
|
1676 | - $ticket_datetimes, |
|
1677 | - $all_datetimes, |
|
1678 | - $default, |
|
1679 | - $all_tickets, |
|
1680 | - $this->_is_creating_event |
|
1681 | - ); |
|
1682 | - return EEH_Template::display_template( |
|
1683 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1684 | - $template_args, |
|
1685 | - true |
|
1686 | - ); |
|
1687 | - } |
|
1405 | + /** |
|
1406 | + * This generates the ticket row for tickets. |
|
1407 | + * This same method is used to generate both the actual rows and the js skeleton row |
|
1408 | + * (when default === true) |
|
1409 | + * |
|
1410 | + * @param int $ticket_row Represents the row number being generated. |
|
1411 | + * @param $ticket |
|
1412 | + * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1413 | + * or empty for default |
|
1414 | + * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1415 | + * @param bool $default Whether default row being generated or not. |
|
1416 | + * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1417 | + * (or empty in the case of defaults) |
|
1418 | + * @return mixed |
|
1419 | + * @throws InvalidArgumentException |
|
1420 | + * @throws InvalidInterfaceException |
|
1421 | + * @throws InvalidDataTypeException |
|
1422 | + * @throws DomainException |
|
1423 | + * @throws EE_Error |
|
1424 | + * @throws ReflectionException |
|
1425 | + */ |
|
1426 | + protected function _get_ticket_row( |
|
1427 | + $ticket_row, |
|
1428 | + $ticket, |
|
1429 | + $ticket_datetimes, |
|
1430 | + $all_datetimes, |
|
1431 | + $default = false, |
|
1432 | + $all_tickets = array() |
|
1433 | + ) { |
|
1434 | + // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1435 | + $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1436 | + $prices = ! empty($ticket) && ! $default |
|
1437 | + ? $ticket->get_many_related( |
|
1438 | + 'Price', |
|
1439 | + array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')) |
|
1440 | + ) |
|
1441 | + : array(); |
|
1442 | + // if there is only one price (which would be the base price) |
|
1443 | + // or NO prices and this ticket is a default ticket, |
|
1444 | + // let's just make sure there are no cached default prices on the object. |
|
1445 | + // This is done by not including any query_params. |
|
1446 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1447 | + $prices = $ticket->prices(); |
|
1448 | + } |
|
1449 | + // check if we're dealing with a default ticket in which case |
|
1450 | + // we don't want any starting_ticket_datetime_row values set |
|
1451 | + // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1452 | + // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1453 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
1454 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
1455 | + ? $ticket_datetimes[ $ticket->ID() ] |
|
1456 | + : array(); |
|
1457 | + $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1458 | + $base_price = $default ? null : $ticket->base_price(); |
|
1459 | + $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1460 | + // breaking out complicated condition for ticket_status |
|
1461 | + if ($default) { |
|
1462 | + $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1463 | + } else { |
|
1464 | + $ticket_status_class = $ticket->is_default() |
|
1465 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1466 | + : ' tkt-status-' . $ticket->ticket_status(); |
|
1467 | + } |
|
1468 | + // breaking out complicated condition for TKT_taxable |
|
1469 | + if ($default) { |
|
1470 | + $TKT_taxable = ''; |
|
1471 | + } else { |
|
1472 | + $TKT_taxable = $ticket->taxable() |
|
1473 | + ? 'checked' |
|
1474 | + : ''; |
|
1475 | + } |
|
1476 | + if ($default) { |
|
1477 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1478 | + } elseif ($ticket->is_default()) { |
|
1479 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1480 | + } else { |
|
1481 | + $TKT_status = $ticket->ticket_status(true); |
|
1482 | + } |
|
1483 | + if ($default) { |
|
1484 | + $TKT_min = ''; |
|
1485 | + } else { |
|
1486 | + $TKT_min = $ticket->min(); |
|
1487 | + if ($TKT_min === -1 || $TKT_min === 0) { |
|
1488 | + $TKT_min = ''; |
|
1489 | + } |
|
1490 | + } |
|
1491 | + $template_args = array( |
|
1492 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1493 | + 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1494 | + // on initial page load this will always be the correct order. |
|
1495 | + 'tkt_status_class' => $ticket_status_class, |
|
1496 | + 'display_edit_tkt_row' => 'display:none;', |
|
1497 | + 'edit_tkt_expanded' => '', |
|
1498 | + 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1499 | + 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
1500 | + 'TKT_start_date' => $default |
|
1501 | + ? '' |
|
1502 | + : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
1503 | + 'TKT_end_date' => $default |
|
1504 | + ? '' |
|
1505 | + : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
1506 | + 'TKT_status' => $TKT_status, |
|
1507 | + 'TKT_price' => $default |
|
1508 | + ? '' |
|
1509 | + : EEH_Template::format_currency( |
|
1510 | + $ticket->get_ticket_total_with_taxes(), |
|
1511 | + false, |
|
1512 | + false |
|
1513 | + ), |
|
1514 | + 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1515 | + 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1516 | + 'TKT_qty' => $default |
|
1517 | + ? '' |
|
1518 | + : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1519 | + 'TKT_qty_for_input' => $default |
|
1520 | + ? '' |
|
1521 | + : $ticket->get_pretty('TKT_qty', 'input'), |
|
1522 | + 'TKT_uses' => $default |
|
1523 | + ? '' |
|
1524 | + : $ticket->get_pretty('TKT_uses', 'input'), |
|
1525 | + 'TKT_min' => $TKT_min, |
|
1526 | + 'TKT_max' => $default |
|
1527 | + ? '' |
|
1528 | + : $ticket->get_pretty('TKT_max', 'input'), |
|
1529 | + 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1530 | + 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1531 | + 'TKT_registrations' => $default |
|
1532 | + ? 0 |
|
1533 | + : $ticket->count_registrations( |
|
1534 | + array( |
|
1535 | + array( |
|
1536 | + 'STS_ID' => array( |
|
1537 | + '!=', |
|
1538 | + EEM_Registration::status_id_incomplete, |
|
1539 | + ), |
|
1540 | + ), |
|
1541 | + ) |
|
1542 | + ), |
|
1543 | + 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
1544 | + 'TKT_description' => $default ? '' : $ticket->get_raw('TKT_description'), |
|
1545 | + 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
1546 | + 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1547 | + 'TKT_is_default_selector' => '', |
|
1548 | + 'ticket_price_rows' => '', |
|
1549 | + 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1550 | + ? '' |
|
1551 | + : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1552 | + 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1553 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1554 | + ? '' |
|
1555 | + : 'display:none;', |
|
1556 | + 'show_price_mod_button' => count($prices) > 1 |
|
1557 | + || ($default && $count_price_mods > 0) |
|
1558 | + || (! $default && $ticket->deleted()) |
|
1559 | + ? 'display:none;' |
|
1560 | + : '', |
|
1561 | + 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1562 | + 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1563 | + 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1564 | + 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1565 | + 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1566 | + 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1567 | + 'TKT_taxable' => $TKT_taxable, |
|
1568 | + 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
1569 | + ? '' |
|
1570 | + : 'display:none;', |
|
1571 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1572 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1573 | + $ticket_subtotal, |
|
1574 | + false, |
|
1575 | + false |
|
1576 | + ), |
|
1577 | + 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1578 | + 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1579 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
1580 | + 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1581 | + ? ' ticket-archived' |
|
1582 | + : '', |
|
1583 | + 'trash_icon' => $ticket instanceof EE_Ticket |
|
1584 | + && $ticket->deleted() |
|
1585 | + && ! $ticket->is_permanently_deleteable() |
|
1586 | + ? 'ee-lock-icon ' |
|
1587 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1588 | + 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1589 | + ? '' |
|
1590 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1591 | + ); |
|
1592 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1593 | + ? 'display:none' |
|
1594 | + : ''; |
|
1595 | + // handle rows that should NOT be empty |
|
1596 | + if (empty($template_args['TKT_start_date'])) { |
|
1597 | + // if empty then the start date will be now. |
|
1598 | + $template_args['TKT_start_date'] = date( |
|
1599 | + $this->_date_time_format, |
|
1600 | + current_time('timestamp') |
|
1601 | + ); |
|
1602 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1603 | + } |
|
1604 | + if (empty($template_args['TKT_end_date'])) { |
|
1605 | + // get the earliest datetime (if present); |
|
1606 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1607 | + ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1608 | + 'Datetime', |
|
1609 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1610 | + ) |
|
1611 | + : null; |
|
1612 | + if (! empty($earliest_dtt)) { |
|
1613 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1614 | + 'DTT_EVT_start', |
|
1615 | + $this->_date_time_format |
|
1616 | + ); |
|
1617 | + } else { |
|
1618 | + // default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1619 | + $template_args['TKT_end_date'] = date( |
|
1620 | + $this->_date_time_format, |
|
1621 | + mktime( |
|
1622 | + 24, |
|
1623 | + 0, |
|
1624 | + 0, |
|
1625 | + date('m'), |
|
1626 | + date('d') + 29, |
|
1627 | + date('Y') |
|
1628 | + ) |
|
1629 | + ); |
|
1630 | + } |
|
1631 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1632 | + } |
|
1633 | + // generate ticket_datetime items |
|
1634 | + if (! $default) { |
|
1635 | + $datetime_row = 1; |
|
1636 | + foreach ($all_datetimes as $datetime) { |
|
1637 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1638 | + $datetime_row, |
|
1639 | + $ticket_row, |
|
1640 | + $datetime, |
|
1641 | + $ticket, |
|
1642 | + $ticket_datetimes, |
|
1643 | + $default |
|
1644 | + ); |
|
1645 | + $datetime_row++; |
|
1646 | + } |
|
1647 | + } |
|
1648 | + $price_row = 1; |
|
1649 | + foreach ($prices as $price) { |
|
1650 | + if (! $price instanceof EE_Price) { |
|
1651 | + continue; |
|
1652 | + } |
|
1653 | + if ($price->is_base_price()) { |
|
1654 | + $price_row++; |
|
1655 | + continue; |
|
1656 | + } |
|
1657 | + $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1658 | + $show_create = ! (count($prices) > 1 && count($prices) !== $price_row); |
|
1659 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1660 | + $ticket_row, |
|
1661 | + $price_row, |
|
1662 | + $price, |
|
1663 | + $default, |
|
1664 | + $ticket, |
|
1665 | + $show_trash, |
|
1666 | + $show_create |
|
1667 | + ); |
|
1668 | + $price_row++; |
|
1669 | + } |
|
1670 | + // filter $template_args |
|
1671 | + $template_args = apply_filters( |
|
1672 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1673 | + $template_args, |
|
1674 | + $ticket_row, |
|
1675 | + $ticket, |
|
1676 | + $ticket_datetimes, |
|
1677 | + $all_datetimes, |
|
1678 | + $default, |
|
1679 | + $all_tickets, |
|
1680 | + $this->_is_creating_event |
|
1681 | + ); |
|
1682 | + return EEH_Template::display_template( |
|
1683 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1684 | + $template_args, |
|
1685 | + true |
|
1686 | + ); |
|
1687 | + } |
|
1688 | 1688 | |
1689 | 1689 | |
1690 | - /** |
|
1691 | - * @param int $ticket_row |
|
1692 | - * @param EE_Ticket|null $ticket |
|
1693 | - * @return string |
|
1694 | - * @throws DomainException |
|
1695 | - * @throws EE_Error |
|
1696 | - */ |
|
1697 | - protected function _get_tax_rows($ticket_row, $ticket) |
|
1698 | - { |
|
1699 | - $tax_rows = ''; |
|
1700 | - /** @var EE_Price[] $taxes */ |
|
1701 | - $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1702 | - foreach ($taxes as $tax) { |
|
1703 | - $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1704 | - $template_args = array( |
|
1705 | - 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1706 | - ? '' |
|
1707 | - : 'display:none;', |
|
1708 | - 'tax_id' => $tax->ID(), |
|
1709 | - 'tkt_row' => $ticket_row, |
|
1710 | - 'tax_label' => $tax->get('PRC_name'), |
|
1711 | - 'tax_added' => $tax_added, |
|
1712 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1713 | - 'tax_amount' => $tax->get('PRC_amount'), |
|
1714 | - ); |
|
1715 | - $template_args = apply_filters( |
|
1716 | - 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1717 | - $template_args, |
|
1718 | - $ticket_row, |
|
1719 | - $ticket, |
|
1720 | - $this->_is_creating_event |
|
1721 | - ); |
|
1722 | - $tax_rows .= EEH_Template::display_template( |
|
1723 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1724 | - $template_args, |
|
1725 | - true |
|
1726 | - ); |
|
1727 | - } |
|
1728 | - return $tax_rows; |
|
1729 | - } |
|
1690 | + /** |
|
1691 | + * @param int $ticket_row |
|
1692 | + * @param EE_Ticket|null $ticket |
|
1693 | + * @return string |
|
1694 | + * @throws DomainException |
|
1695 | + * @throws EE_Error |
|
1696 | + */ |
|
1697 | + protected function _get_tax_rows($ticket_row, $ticket) |
|
1698 | + { |
|
1699 | + $tax_rows = ''; |
|
1700 | + /** @var EE_Price[] $taxes */ |
|
1701 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1702 | + foreach ($taxes as $tax) { |
|
1703 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1704 | + $template_args = array( |
|
1705 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1706 | + ? '' |
|
1707 | + : 'display:none;', |
|
1708 | + 'tax_id' => $tax->ID(), |
|
1709 | + 'tkt_row' => $ticket_row, |
|
1710 | + 'tax_label' => $tax->get('PRC_name'), |
|
1711 | + 'tax_added' => $tax_added, |
|
1712 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1713 | + 'tax_amount' => $tax->get('PRC_amount'), |
|
1714 | + ); |
|
1715 | + $template_args = apply_filters( |
|
1716 | + 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1717 | + $template_args, |
|
1718 | + $ticket_row, |
|
1719 | + $ticket, |
|
1720 | + $this->_is_creating_event |
|
1721 | + ); |
|
1722 | + $tax_rows .= EEH_Template::display_template( |
|
1723 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1724 | + $template_args, |
|
1725 | + true |
|
1726 | + ); |
|
1727 | + } |
|
1728 | + return $tax_rows; |
|
1729 | + } |
|
1730 | 1730 | |
1731 | 1731 | |
1732 | - /** |
|
1733 | - * @param EE_Price $tax |
|
1734 | - * @param EE_Ticket|null $ticket |
|
1735 | - * @return float|int |
|
1736 | - * @throws EE_Error |
|
1737 | - */ |
|
1738 | - protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1739 | - { |
|
1740 | - $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1741 | - return $subtotal * $tax->get('PRC_amount') / 100; |
|
1742 | - } |
|
1732 | + /** |
|
1733 | + * @param EE_Price $tax |
|
1734 | + * @param EE_Ticket|null $ticket |
|
1735 | + * @return float|int |
|
1736 | + * @throws EE_Error |
|
1737 | + */ |
|
1738 | + protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1739 | + { |
|
1740 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1741 | + return $subtotal * $tax->get('PRC_amount') / 100; |
|
1742 | + } |
|
1743 | 1743 | |
1744 | 1744 | |
1745 | - /** |
|
1746 | - * @param int $ticket_row |
|
1747 | - * @param int $price_row |
|
1748 | - * @param EE_Price|null $price |
|
1749 | - * @param bool $default |
|
1750 | - * @param EE_Ticket|null $ticket |
|
1751 | - * @param bool $show_trash |
|
1752 | - * @param bool $show_create |
|
1753 | - * @return mixed |
|
1754 | - * @throws InvalidArgumentException |
|
1755 | - * @throws InvalidInterfaceException |
|
1756 | - * @throws InvalidDataTypeException |
|
1757 | - * @throws DomainException |
|
1758 | - * @throws EE_Error |
|
1759 | - * @throws ReflectionException |
|
1760 | - */ |
|
1761 | - protected function _get_ticket_price_row( |
|
1762 | - $ticket_row, |
|
1763 | - $price_row, |
|
1764 | - $price, |
|
1765 | - $default, |
|
1766 | - $ticket, |
|
1767 | - $show_trash = true, |
|
1768 | - $show_create = true |
|
1769 | - ) { |
|
1770 | - $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
1771 | - $template_args = array( |
|
1772 | - 'tkt_row' => $default && empty($ticket) |
|
1773 | - ? 'TICKETNUM' |
|
1774 | - : $ticket_row, |
|
1775 | - 'PRC_order' => $default && empty($price) |
|
1776 | - ? 'PRICENUM' |
|
1777 | - : $price_row, |
|
1778 | - 'edit_prices_name' => $default && empty($price) |
|
1779 | - ? 'PRICENAMEATTR' |
|
1780 | - : 'edit_prices', |
|
1781 | - 'price_type_selector' => $default && empty($price) |
|
1782 | - ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1783 | - : $this->_get_price_type_selector( |
|
1784 | - $ticket_row, |
|
1785 | - $price_row, |
|
1786 | - $price, |
|
1787 | - $default, |
|
1788 | - $send_disabled |
|
1789 | - ), |
|
1790 | - 'PRC_ID' => $default && empty($price) |
|
1791 | - ? 0 |
|
1792 | - : $price->ID(), |
|
1793 | - 'PRC_is_default' => $default && empty($price) |
|
1794 | - ? 0 |
|
1795 | - : $price->get('PRC_is_default'), |
|
1796 | - 'PRC_name' => $default && empty($price) |
|
1797 | - ? '' |
|
1798 | - : $price->get('PRC_name'), |
|
1799 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1800 | - 'show_plus_or_minus' => $default && empty($price) |
|
1801 | - ? '' |
|
1802 | - : 'display:none;', |
|
1803 | - 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1804 | - ? 'display:none;' |
|
1805 | - : '', |
|
1806 | - 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1807 | - ? 'display:none;' |
|
1808 | - : '', |
|
1809 | - 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1810 | - ? 'display:none' |
|
1811 | - : '', |
|
1812 | - 'PRC_amount' => $default && empty($price) |
|
1813 | - ? 0 |
|
1814 | - : $price->get_pretty('PRC_amount', 'localized_float'), |
|
1815 | - 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1816 | - ? 'display:none;' |
|
1817 | - : '', |
|
1818 | - 'show_trash_icon' => $show_trash |
|
1819 | - ? '' |
|
1820 | - : ' style="display:none;"', |
|
1821 | - 'show_create_button' => $show_create |
|
1822 | - ? '' |
|
1823 | - : ' style="display:none;"', |
|
1824 | - 'PRC_desc' => $default && empty($price) |
|
1825 | - ? '' |
|
1826 | - : $price->get('PRC_desc'), |
|
1827 | - 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
1828 | - ); |
|
1829 | - $template_args = apply_filters( |
|
1830 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1831 | - $template_args, |
|
1832 | - $ticket_row, |
|
1833 | - $price_row, |
|
1834 | - $price, |
|
1835 | - $default, |
|
1836 | - $ticket, |
|
1837 | - $show_trash, |
|
1838 | - $show_create, |
|
1839 | - $this->_is_creating_event |
|
1840 | - ); |
|
1841 | - return EEH_Template::display_template( |
|
1842 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1843 | - $template_args, |
|
1844 | - true |
|
1845 | - ); |
|
1846 | - } |
|
1745 | + /** |
|
1746 | + * @param int $ticket_row |
|
1747 | + * @param int $price_row |
|
1748 | + * @param EE_Price|null $price |
|
1749 | + * @param bool $default |
|
1750 | + * @param EE_Ticket|null $ticket |
|
1751 | + * @param bool $show_trash |
|
1752 | + * @param bool $show_create |
|
1753 | + * @return mixed |
|
1754 | + * @throws InvalidArgumentException |
|
1755 | + * @throws InvalidInterfaceException |
|
1756 | + * @throws InvalidDataTypeException |
|
1757 | + * @throws DomainException |
|
1758 | + * @throws EE_Error |
|
1759 | + * @throws ReflectionException |
|
1760 | + */ |
|
1761 | + protected function _get_ticket_price_row( |
|
1762 | + $ticket_row, |
|
1763 | + $price_row, |
|
1764 | + $price, |
|
1765 | + $default, |
|
1766 | + $ticket, |
|
1767 | + $show_trash = true, |
|
1768 | + $show_create = true |
|
1769 | + ) { |
|
1770 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
1771 | + $template_args = array( |
|
1772 | + 'tkt_row' => $default && empty($ticket) |
|
1773 | + ? 'TICKETNUM' |
|
1774 | + : $ticket_row, |
|
1775 | + 'PRC_order' => $default && empty($price) |
|
1776 | + ? 'PRICENUM' |
|
1777 | + : $price_row, |
|
1778 | + 'edit_prices_name' => $default && empty($price) |
|
1779 | + ? 'PRICENAMEATTR' |
|
1780 | + : 'edit_prices', |
|
1781 | + 'price_type_selector' => $default && empty($price) |
|
1782 | + ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1783 | + : $this->_get_price_type_selector( |
|
1784 | + $ticket_row, |
|
1785 | + $price_row, |
|
1786 | + $price, |
|
1787 | + $default, |
|
1788 | + $send_disabled |
|
1789 | + ), |
|
1790 | + 'PRC_ID' => $default && empty($price) |
|
1791 | + ? 0 |
|
1792 | + : $price->ID(), |
|
1793 | + 'PRC_is_default' => $default && empty($price) |
|
1794 | + ? 0 |
|
1795 | + : $price->get('PRC_is_default'), |
|
1796 | + 'PRC_name' => $default && empty($price) |
|
1797 | + ? '' |
|
1798 | + : $price->get('PRC_name'), |
|
1799 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1800 | + 'show_plus_or_minus' => $default && empty($price) |
|
1801 | + ? '' |
|
1802 | + : 'display:none;', |
|
1803 | + 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1804 | + ? 'display:none;' |
|
1805 | + : '', |
|
1806 | + 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1807 | + ? 'display:none;' |
|
1808 | + : '', |
|
1809 | + 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1810 | + ? 'display:none' |
|
1811 | + : '', |
|
1812 | + 'PRC_amount' => $default && empty($price) |
|
1813 | + ? 0 |
|
1814 | + : $price->get_pretty('PRC_amount', 'localized_float'), |
|
1815 | + 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1816 | + ? 'display:none;' |
|
1817 | + : '', |
|
1818 | + 'show_trash_icon' => $show_trash |
|
1819 | + ? '' |
|
1820 | + : ' style="display:none;"', |
|
1821 | + 'show_create_button' => $show_create |
|
1822 | + ? '' |
|
1823 | + : ' style="display:none;"', |
|
1824 | + 'PRC_desc' => $default && empty($price) |
|
1825 | + ? '' |
|
1826 | + : $price->get('PRC_desc'), |
|
1827 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
1828 | + ); |
|
1829 | + $template_args = apply_filters( |
|
1830 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1831 | + $template_args, |
|
1832 | + $ticket_row, |
|
1833 | + $price_row, |
|
1834 | + $price, |
|
1835 | + $default, |
|
1836 | + $ticket, |
|
1837 | + $show_trash, |
|
1838 | + $show_create, |
|
1839 | + $this->_is_creating_event |
|
1840 | + ); |
|
1841 | + return EEH_Template::display_template( |
|
1842 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1843 | + $template_args, |
|
1844 | + true |
|
1845 | + ); |
|
1846 | + } |
|
1847 | 1847 | |
1848 | 1848 | |
1849 | - /** |
|
1850 | - * @param int $ticket_row |
|
1851 | - * @param int $price_row |
|
1852 | - * @param EE_Price $price |
|
1853 | - * @param bool $default |
|
1854 | - * @param bool $disabled |
|
1855 | - * @return mixed |
|
1856 | - * @throws ReflectionException |
|
1857 | - * @throws InvalidArgumentException |
|
1858 | - * @throws InvalidInterfaceException |
|
1859 | - * @throws InvalidDataTypeException |
|
1860 | - * @throws DomainException |
|
1861 | - * @throws EE_Error |
|
1862 | - */ |
|
1863 | - protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1864 | - { |
|
1865 | - if ($price->is_base_price()) { |
|
1866 | - return $this->_get_base_price_template( |
|
1867 | - $ticket_row, |
|
1868 | - $price_row, |
|
1869 | - $price, |
|
1870 | - $default |
|
1871 | - ); |
|
1872 | - } |
|
1873 | - return $this->_get_price_modifier_template( |
|
1874 | - $ticket_row, |
|
1875 | - $price_row, |
|
1876 | - $price, |
|
1877 | - $default, |
|
1878 | - $disabled |
|
1879 | - ); |
|
1880 | - } |
|
1849 | + /** |
|
1850 | + * @param int $ticket_row |
|
1851 | + * @param int $price_row |
|
1852 | + * @param EE_Price $price |
|
1853 | + * @param bool $default |
|
1854 | + * @param bool $disabled |
|
1855 | + * @return mixed |
|
1856 | + * @throws ReflectionException |
|
1857 | + * @throws InvalidArgumentException |
|
1858 | + * @throws InvalidInterfaceException |
|
1859 | + * @throws InvalidDataTypeException |
|
1860 | + * @throws DomainException |
|
1861 | + * @throws EE_Error |
|
1862 | + */ |
|
1863 | + protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1864 | + { |
|
1865 | + if ($price->is_base_price()) { |
|
1866 | + return $this->_get_base_price_template( |
|
1867 | + $ticket_row, |
|
1868 | + $price_row, |
|
1869 | + $price, |
|
1870 | + $default |
|
1871 | + ); |
|
1872 | + } |
|
1873 | + return $this->_get_price_modifier_template( |
|
1874 | + $ticket_row, |
|
1875 | + $price_row, |
|
1876 | + $price, |
|
1877 | + $default, |
|
1878 | + $disabled |
|
1879 | + ); |
|
1880 | + } |
|
1881 | 1881 | |
1882 | 1882 | |
1883 | - /** |
|
1884 | - * @param int $ticket_row |
|
1885 | - * @param int $price_row |
|
1886 | - * @param EE_Price $price |
|
1887 | - * @param bool $default |
|
1888 | - * @return mixed |
|
1889 | - * @throws DomainException |
|
1890 | - * @throws EE_Error |
|
1891 | - */ |
|
1892 | - protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1893 | - { |
|
1894 | - $template_args = array( |
|
1895 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1896 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1897 | - 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1898 | - 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1899 | - 'price_selected_operator' => '+', |
|
1900 | - 'price_selected_is_percent' => 0, |
|
1901 | - ); |
|
1902 | - $template_args = apply_filters( |
|
1903 | - 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1904 | - $template_args, |
|
1905 | - $ticket_row, |
|
1906 | - $price_row, |
|
1907 | - $price, |
|
1908 | - $default, |
|
1909 | - $this->_is_creating_event |
|
1910 | - ); |
|
1911 | - return EEH_Template::display_template( |
|
1912 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1913 | - $template_args, |
|
1914 | - true |
|
1915 | - ); |
|
1916 | - } |
|
1883 | + /** |
|
1884 | + * @param int $ticket_row |
|
1885 | + * @param int $price_row |
|
1886 | + * @param EE_Price $price |
|
1887 | + * @param bool $default |
|
1888 | + * @return mixed |
|
1889 | + * @throws DomainException |
|
1890 | + * @throws EE_Error |
|
1891 | + */ |
|
1892 | + protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1893 | + { |
|
1894 | + $template_args = array( |
|
1895 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1896 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1897 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1898 | + 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1899 | + 'price_selected_operator' => '+', |
|
1900 | + 'price_selected_is_percent' => 0, |
|
1901 | + ); |
|
1902 | + $template_args = apply_filters( |
|
1903 | + 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1904 | + $template_args, |
|
1905 | + $ticket_row, |
|
1906 | + $price_row, |
|
1907 | + $price, |
|
1908 | + $default, |
|
1909 | + $this->_is_creating_event |
|
1910 | + ); |
|
1911 | + return EEH_Template::display_template( |
|
1912 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1913 | + $template_args, |
|
1914 | + true |
|
1915 | + ); |
|
1916 | + } |
|
1917 | 1917 | |
1918 | 1918 | |
1919 | - /** |
|
1920 | - * @param int $ticket_row |
|
1921 | - * @param int $price_row |
|
1922 | - * @param EE_Price $price |
|
1923 | - * @param bool $default |
|
1924 | - * @param bool $disabled |
|
1925 | - * @return mixed |
|
1926 | - * @throws ReflectionException |
|
1927 | - * @throws InvalidArgumentException |
|
1928 | - * @throws InvalidInterfaceException |
|
1929 | - * @throws InvalidDataTypeException |
|
1930 | - * @throws DomainException |
|
1931 | - * @throws EE_Error |
|
1932 | - */ |
|
1933 | - protected function _get_price_modifier_template( |
|
1934 | - $ticket_row, |
|
1935 | - $price_row, |
|
1936 | - $price, |
|
1937 | - $default, |
|
1938 | - $disabled = false |
|
1939 | - ) { |
|
1940 | - $select_name = $default && ! $price instanceof EE_Price |
|
1941 | - ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1942 | - : 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]'; |
|
1943 | - /** @var EEM_Price_Type $price_type_model */ |
|
1944 | - $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1945 | - $price_types = $price_type_model->get_all(array( |
|
1946 | - array( |
|
1947 | - 'OR' => array( |
|
1948 | - 'PBT_ID' => '2', |
|
1949 | - 'PBT_ID*' => '3', |
|
1950 | - ), |
|
1951 | - ), |
|
1952 | - )); |
|
1953 | - $all_price_types = $default && ! $price instanceof EE_Price |
|
1954 | - ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
1955 | - : array(); |
|
1956 | - $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1957 | - $price_option_spans = ''; |
|
1958 | - // setup price types for selector |
|
1959 | - foreach ($price_types as $price_type) { |
|
1960 | - if (! $price_type instanceof EE_Price_Type) { |
|
1961 | - continue; |
|
1962 | - } |
|
1963 | - $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name'); |
|
1964 | - // while we're in the loop let's setup the option spans used by js |
|
1965 | - $span_args = array( |
|
1966 | - 'PRT_ID' => $price_type->ID(), |
|
1967 | - 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1968 | - 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1969 | - ); |
|
1970 | - $price_option_spans .= EEH_Template::display_template( |
|
1971 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1972 | - $span_args, |
|
1973 | - true |
|
1974 | - ); |
|
1975 | - } |
|
1976 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
1977 | - : $select_name; |
|
1978 | - $select_input = new EE_Select_Input( |
|
1979 | - $all_price_types, |
|
1980 | - array( |
|
1981 | - 'default' => $selected_price_type_id, |
|
1982 | - 'html_name' => $select_name, |
|
1983 | - 'html_class' => 'edit-price-PRT_ID', |
|
1984 | - 'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1985 | - ) |
|
1986 | - ); |
|
1987 | - $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1988 | - $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1989 | - $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1990 | - $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1991 | - $template_args = array( |
|
1992 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1993 | - 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1994 | - 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1995 | - 'main_name' => $select_name, |
|
1996 | - 'selected_price_type_id' => $selected_price_type_id, |
|
1997 | - 'price_option_spans' => $price_option_spans, |
|
1998 | - 'price_selected_operator' => $price_selected_operator, |
|
1999 | - 'price_selected_is_percent' => $price_selected_is_percent, |
|
2000 | - 'disabled' => $disabled, |
|
2001 | - ); |
|
2002 | - $template_args = apply_filters( |
|
2003 | - 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
2004 | - $template_args, |
|
2005 | - $ticket_row, |
|
2006 | - $price_row, |
|
2007 | - $price, |
|
2008 | - $default, |
|
2009 | - $disabled, |
|
2010 | - $this->_is_creating_event |
|
2011 | - ); |
|
2012 | - return EEH_Template::display_template( |
|
2013 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
2014 | - $template_args, |
|
2015 | - true |
|
2016 | - ); |
|
2017 | - } |
|
1919 | + /** |
|
1920 | + * @param int $ticket_row |
|
1921 | + * @param int $price_row |
|
1922 | + * @param EE_Price $price |
|
1923 | + * @param bool $default |
|
1924 | + * @param bool $disabled |
|
1925 | + * @return mixed |
|
1926 | + * @throws ReflectionException |
|
1927 | + * @throws InvalidArgumentException |
|
1928 | + * @throws InvalidInterfaceException |
|
1929 | + * @throws InvalidDataTypeException |
|
1930 | + * @throws DomainException |
|
1931 | + * @throws EE_Error |
|
1932 | + */ |
|
1933 | + protected function _get_price_modifier_template( |
|
1934 | + $ticket_row, |
|
1935 | + $price_row, |
|
1936 | + $price, |
|
1937 | + $default, |
|
1938 | + $disabled = false |
|
1939 | + ) { |
|
1940 | + $select_name = $default && ! $price instanceof EE_Price |
|
1941 | + ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1942 | + : 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]'; |
|
1943 | + /** @var EEM_Price_Type $price_type_model */ |
|
1944 | + $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1945 | + $price_types = $price_type_model->get_all(array( |
|
1946 | + array( |
|
1947 | + 'OR' => array( |
|
1948 | + 'PBT_ID' => '2', |
|
1949 | + 'PBT_ID*' => '3', |
|
1950 | + ), |
|
1951 | + ), |
|
1952 | + )); |
|
1953 | + $all_price_types = $default && ! $price instanceof EE_Price |
|
1954 | + ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
1955 | + : array(); |
|
1956 | + $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1957 | + $price_option_spans = ''; |
|
1958 | + // setup price types for selector |
|
1959 | + foreach ($price_types as $price_type) { |
|
1960 | + if (! $price_type instanceof EE_Price_Type) { |
|
1961 | + continue; |
|
1962 | + } |
|
1963 | + $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name'); |
|
1964 | + // while we're in the loop let's setup the option spans used by js |
|
1965 | + $span_args = array( |
|
1966 | + 'PRT_ID' => $price_type->ID(), |
|
1967 | + 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1968 | + 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1969 | + ); |
|
1970 | + $price_option_spans .= EEH_Template::display_template( |
|
1971 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1972 | + $span_args, |
|
1973 | + true |
|
1974 | + ); |
|
1975 | + } |
|
1976 | + $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
1977 | + : $select_name; |
|
1978 | + $select_input = new EE_Select_Input( |
|
1979 | + $all_price_types, |
|
1980 | + array( |
|
1981 | + 'default' => $selected_price_type_id, |
|
1982 | + 'html_name' => $select_name, |
|
1983 | + 'html_class' => 'edit-price-PRT_ID', |
|
1984 | + 'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1985 | + ) |
|
1986 | + ); |
|
1987 | + $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1988 | + $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1989 | + $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1990 | + $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1991 | + $template_args = array( |
|
1992 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1993 | + 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1994 | + 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1995 | + 'main_name' => $select_name, |
|
1996 | + 'selected_price_type_id' => $selected_price_type_id, |
|
1997 | + 'price_option_spans' => $price_option_spans, |
|
1998 | + 'price_selected_operator' => $price_selected_operator, |
|
1999 | + 'price_selected_is_percent' => $price_selected_is_percent, |
|
2000 | + 'disabled' => $disabled, |
|
2001 | + ); |
|
2002 | + $template_args = apply_filters( |
|
2003 | + 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
2004 | + $template_args, |
|
2005 | + $ticket_row, |
|
2006 | + $price_row, |
|
2007 | + $price, |
|
2008 | + $default, |
|
2009 | + $disabled, |
|
2010 | + $this->_is_creating_event |
|
2011 | + ); |
|
2012 | + return EEH_Template::display_template( |
|
2013 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
2014 | + $template_args, |
|
2015 | + true |
|
2016 | + ); |
|
2017 | + } |
|
2018 | 2018 | |
2019 | 2019 | |
2020 | - /** |
|
2021 | - * @param int $datetime_row |
|
2022 | - * @param int $ticket_row |
|
2023 | - * @param EE_Datetime|null $datetime |
|
2024 | - * @param EE_Ticket|null $ticket |
|
2025 | - * @param array $ticket_datetimes |
|
2026 | - * @param bool $default |
|
2027 | - * @return mixed |
|
2028 | - * @throws DomainException |
|
2029 | - * @throws EE_Error |
|
2030 | - */ |
|
2031 | - protected function _get_ticket_datetime_list_item( |
|
2032 | - $datetime_row, |
|
2033 | - $ticket_row, |
|
2034 | - $datetime, |
|
2035 | - $ticket, |
|
2036 | - $ticket_datetimes = array(), |
|
2037 | - $default = false |
|
2038 | - ) { |
|
2039 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
2040 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
2041 | - : array(); |
|
2042 | - $template_args = array( |
|
2043 | - 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
2044 | - ? 'DTTNUM' |
|
2045 | - : $datetime_row, |
|
2046 | - 'tkt_row' => $default |
|
2047 | - ? 'TICKETNUM' |
|
2048 | - : $ticket_row, |
|
2049 | - 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
2050 | - ? ' ticket-selected' |
|
2051 | - : '', |
|
2052 | - 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
2053 | - ? ' checked' |
|
2054 | - : '', |
|
2055 | - 'DTT_name' => $default && empty($datetime) |
|
2056 | - ? 'DTTNAME' |
|
2057 | - : $datetime->get_dtt_display_name(true), |
|
2058 | - 'tkt_status_class' => '', |
|
2059 | - ); |
|
2060 | - $template_args = apply_filters( |
|
2061 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
2062 | - $template_args, |
|
2063 | - $datetime_row, |
|
2064 | - $ticket_row, |
|
2065 | - $datetime, |
|
2066 | - $ticket, |
|
2067 | - $ticket_datetimes, |
|
2068 | - $default, |
|
2069 | - $this->_is_creating_event |
|
2070 | - ); |
|
2071 | - return EEH_Template::display_template( |
|
2072 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
2073 | - $template_args, |
|
2074 | - true |
|
2075 | - ); |
|
2076 | - } |
|
2020 | + /** |
|
2021 | + * @param int $datetime_row |
|
2022 | + * @param int $ticket_row |
|
2023 | + * @param EE_Datetime|null $datetime |
|
2024 | + * @param EE_Ticket|null $ticket |
|
2025 | + * @param array $ticket_datetimes |
|
2026 | + * @param bool $default |
|
2027 | + * @return mixed |
|
2028 | + * @throws DomainException |
|
2029 | + * @throws EE_Error |
|
2030 | + */ |
|
2031 | + protected function _get_ticket_datetime_list_item( |
|
2032 | + $datetime_row, |
|
2033 | + $ticket_row, |
|
2034 | + $datetime, |
|
2035 | + $ticket, |
|
2036 | + $ticket_datetimes = array(), |
|
2037 | + $default = false |
|
2038 | + ) { |
|
2039 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
2040 | + ? $ticket_datetimes[ $ticket->ID() ] |
|
2041 | + : array(); |
|
2042 | + $template_args = array( |
|
2043 | + 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
2044 | + ? 'DTTNUM' |
|
2045 | + : $datetime_row, |
|
2046 | + 'tkt_row' => $default |
|
2047 | + ? 'TICKETNUM' |
|
2048 | + : $ticket_row, |
|
2049 | + 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
2050 | + ? ' ticket-selected' |
|
2051 | + : '', |
|
2052 | + 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
2053 | + ? ' checked' |
|
2054 | + : '', |
|
2055 | + 'DTT_name' => $default && empty($datetime) |
|
2056 | + ? 'DTTNAME' |
|
2057 | + : $datetime->get_dtt_display_name(true), |
|
2058 | + 'tkt_status_class' => '', |
|
2059 | + ); |
|
2060 | + $template_args = apply_filters( |
|
2061 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
2062 | + $template_args, |
|
2063 | + $datetime_row, |
|
2064 | + $ticket_row, |
|
2065 | + $datetime, |
|
2066 | + $ticket, |
|
2067 | + $ticket_datetimes, |
|
2068 | + $default, |
|
2069 | + $this->_is_creating_event |
|
2070 | + ); |
|
2071 | + return EEH_Template::display_template( |
|
2072 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
2073 | + $template_args, |
|
2074 | + true |
|
2075 | + ); |
|
2076 | + } |
|
2077 | 2077 | |
2078 | 2078 | |
2079 | - /** |
|
2080 | - * @param array $all_datetimes |
|
2081 | - * @param array $all_tickets |
|
2082 | - * @return mixed |
|
2083 | - * @throws ReflectionException |
|
2084 | - * @throws InvalidArgumentException |
|
2085 | - * @throws InvalidInterfaceException |
|
2086 | - * @throws InvalidDataTypeException |
|
2087 | - * @throws DomainException |
|
2088 | - * @throws EE_Error |
|
2089 | - */ |
|
2090 | - protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
2091 | - { |
|
2092 | - $template_args = array( |
|
2093 | - 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
2094 | - 'DTTNUM', |
|
2095 | - null, |
|
2096 | - true, |
|
2097 | - $all_datetimes |
|
2098 | - ), |
|
2099 | - 'default_ticket_row' => $this->_get_ticket_row( |
|
2100 | - 'TICKETNUM', |
|
2101 | - null, |
|
2102 | - array(), |
|
2103 | - array(), |
|
2104 | - true |
|
2105 | - ), |
|
2106 | - 'default_price_row' => $this->_get_ticket_price_row( |
|
2107 | - 'TICKETNUM', |
|
2108 | - 'PRICENUM', |
|
2109 | - null, |
|
2110 | - true, |
|
2111 | - null |
|
2112 | - ), |
|
2113 | - 'default_price_rows' => '', |
|
2114 | - 'default_base_price_amount' => 0, |
|
2115 | - 'default_base_price_name' => '', |
|
2116 | - 'default_base_price_description' => '', |
|
2117 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2118 | - 'TICKETNUM', |
|
2119 | - 'PRICENUM', |
|
2120 | - null, |
|
2121 | - true |
|
2122 | - ), |
|
2123 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2124 | - 'DTTNUM', |
|
2125 | - null, |
|
2126 | - array(), |
|
2127 | - array(), |
|
2128 | - true |
|
2129 | - ), |
|
2130 | - 'existing_available_datetime_tickets_list' => '', |
|
2131 | - 'existing_available_ticket_datetimes_list' => '', |
|
2132 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2133 | - 'DTTNUM', |
|
2134 | - 'TICKETNUM', |
|
2135 | - null, |
|
2136 | - null, |
|
2137 | - array(), |
|
2138 | - true |
|
2139 | - ), |
|
2140 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2141 | - 'DTTNUM', |
|
2142 | - 'TICKETNUM', |
|
2143 | - null, |
|
2144 | - null, |
|
2145 | - array(), |
|
2146 | - true |
|
2147 | - ), |
|
2148 | - ); |
|
2149 | - $ticket_row = 1; |
|
2150 | - foreach ($all_tickets as $ticket) { |
|
2151 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2152 | - 'DTTNUM', |
|
2153 | - $ticket_row, |
|
2154 | - null, |
|
2155 | - $ticket, |
|
2156 | - array(), |
|
2157 | - true |
|
2158 | - ); |
|
2159 | - $ticket_row++; |
|
2160 | - } |
|
2161 | - $datetime_row = 1; |
|
2162 | - foreach ($all_datetimes as $datetime) { |
|
2163 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2164 | - $datetime_row, |
|
2165 | - 'TICKETNUM', |
|
2166 | - $datetime, |
|
2167 | - null, |
|
2168 | - array(), |
|
2169 | - true |
|
2170 | - ); |
|
2171 | - $datetime_row++; |
|
2172 | - } |
|
2173 | - /** @var EEM_Price $price_model */ |
|
2174 | - $price_model = EE_Registry::instance()->load_model('Price'); |
|
2175 | - $default_prices = $price_model->get_all_default_prices(); |
|
2176 | - $price_row = 1; |
|
2177 | - foreach ($default_prices as $price) { |
|
2178 | - if (! $price instanceof EE_Price) { |
|
2179 | - continue; |
|
2180 | - } |
|
2181 | - if ($price->is_base_price()) { |
|
2182 | - $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2183 | - 'PRC_amount', |
|
2184 | - 'localized_float' |
|
2185 | - ); |
|
2186 | - $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2187 | - $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2188 | - $price_row++; |
|
2189 | - continue; |
|
2190 | - } |
|
2191 | - $show_trash = ! ((count($default_prices) > 1 && $price_row === 1) |
|
2192 | - || count($default_prices) === 1); |
|
2193 | - $show_create = ! (count($default_prices) > 1 |
|
2194 | - && count($default_prices) |
|
2195 | - !== $price_row); |
|
2196 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2197 | - 'TICKETNUM', |
|
2198 | - $price_row, |
|
2199 | - $price, |
|
2200 | - true, |
|
2201 | - null, |
|
2202 | - $show_trash, |
|
2203 | - $show_create |
|
2204 | - ); |
|
2205 | - $price_row++; |
|
2206 | - } |
|
2207 | - $template_args = apply_filters( |
|
2208 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2209 | - $template_args, |
|
2210 | - $all_datetimes, |
|
2211 | - $all_tickets, |
|
2212 | - $this->_is_creating_event |
|
2213 | - ); |
|
2214 | - return EEH_Template::display_template( |
|
2215 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2216 | - $template_args, |
|
2217 | - true |
|
2218 | - ); |
|
2219 | - } |
|
2079 | + /** |
|
2080 | + * @param array $all_datetimes |
|
2081 | + * @param array $all_tickets |
|
2082 | + * @return mixed |
|
2083 | + * @throws ReflectionException |
|
2084 | + * @throws InvalidArgumentException |
|
2085 | + * @throws InvalidInterfaceException |
|
2086 | + * @throws InvalidDataTypeException |
|
2087 | + * @throws DomainException |
|
2088 | + * @throws EE_Error |
|
2089 | + */ |
|
2090 | + protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
2091 | + { |
|
2092 | + $template_args = array( |
|
2093 | + 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
2094 | + 'DTTNUM', |
|
2095 | + null, |
|
2096 | + true, |
|
2097 | + $all_datetimes |
|
2098 | + ), |
|
2099 | + 'default_ticket_row' => $this->_get_ticket_row( |
|
2100 | + 'TICKETNUM', |
|
2101 | + null, |
|
2102 | + array(), |
|
2103 | + array(), |
|
2104 | + true |
|
2105 | + ), |
|
2106 | + 'default_price_row' => $this->_get_ticket_price_row( |
|
2107 | + 'TICKETNUM', |
|
2108 | + 'PRICENUM', |
|
2109 | + null, |
|
2110 | + true, |
|
2111 | + null |
|
2112 | + ), |
|
2113 | + 'default_price_rows' => '', |
|
2114 | + 'default_base_price_amount' => 0, |
|
2115 | + 'default_base_price_name' => '', |
|
2116 | + 'default_base_price_description' => '', |
|
2117 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2118 | + 'TICKETNUM', |
|
2119 | + 'PRICENUM', |
|
2120 | + null, |
|
2121 | + true |
|
2122 | + ), |
|
2123 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2124 | + 'DTTNUM', |
|
2125 | + null, |
|
2126 | + array(), |
|
2127 | + array(), |
|
2128 | + true |
|
2129 | + ), |
|
2130 | + 'existing_available_datetime_tickets_list' => '', |
|
2131 | + 'existing_available_ticket_datetimes_list' => '', |
|
2132 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2133 | + 'DTTNUM', |
|
2134 | + 'TICKETNUM', |
|
2135 | + null, |
|
2136 | + null, |
|
2137 | + array(), |
|
2138 | + true |
|
2139 | + ), |
|
2140 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2141 | + 'DTTNUM', |
|
2142 | + 'TICKETNUM', |
|
2143 | + null, |
|
2144 | + null, |
|
2145 | + array(), |
|
2146 | + true |
|
2147 | + ), |
|
2148 | + ); |
|
2149 | + $ticket_row = 1; |
|
2150 | + foreach ($all_tickets as $ticket) { |
|
2151 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2152 | + 'DTTNUM', |
|
2153 | + $ticket_row, |
|
2154 | + null, |
|
2155 | + $ticket, |
|
2156 | + array(), |
|
2157 | + true |
|
2158 | + ); |
|
2159 | + $ticket_row++; |
|
2160 | + } |
|
2161 | + $datetime_row = 1; |
|
2162 | + foreach ($all_datetimes as $datetime) { |
|
2163 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2164 | + $datetime_row, |
|
2165 | + 'TICKETNUM', |
|
2166 | + $datetime, |
|
2167 | + null, |
|
2168 | + array(), |
|
2169 | + true |
|
2170 | + ); |
|
2171 | + $datetime_row++; |
|
2172 | + } |
|
2173 | + /** @var EEM_Price $price_model */ |
|
2174 | + $price_model = EE_Registry::instance()->load_model('Price'); |
|
2175 | + $default_prices = $price_model->get_all_default_prices(); |
|
2176 | + $price_row = 1; |
|
2177 | + foreach ($default_prices as $price) { |
|
2178 | + if (! $price instanceof EE_Price) { |
|
2179 | + continue; |
|
2180 | + } |
|
2181 | + if ($price->is_base_price()) { |
|
2182 | + $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2183 | + 'PRC_amount', |
|
2184 | + 'localized_float' |
|
2185 | + ); |
|
2186 | + $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2187 | + $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2188 | + $price_row++; |
|
2189 | + continue; |
|
2190 | + } |
|
2191 | + $show_trash = ! ((count($default_prices) > 1 && $price_row === 1) |
|
2192 | + || count($default_prices) === 1); |
|
2193 | + $show_create = ! (count($default_prices) > 1 |
|
2194 | + && count($default_prices) |
|
2195 | + !== $price_row); |
|
2196 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2197 | + 'TICKETNUM', |
|
2198 | + $price_row, |
|
2199 | + $price, |
|
2200 | + true, |
|
2201 | + null, |
|
2202 | + $show_trash, |
|
2203 | + $show_create |
|
2204 | + ); |
|
2205 | + $price_row++; |
|
2206 | + } |
|
2207 | + $template_args = apply_filters( |
|
2208 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2209 | + $template_args, |
|
2210 | + $all_datetimes, |
|
2211 | + $all_tickets, |
|
2212 | + $this->_is_creating_event |
|
2213 | + ); |
|
2214 | + return EEH_Template::display_template( |
|
2215 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2216 | + $template_args, |
|
2217 | + true |
|
2218 | + ); |
|
2219 | + } |
|
2220 | 2220 | } |
@@ -16,129 +16,129 @@ |
||
16 | 16 | |
17 | 17 | class UserExperienceForm |
18 | 18 | { |
19 | - /** |
|
20 | - * @var EE_Core_Config |
|
21 | - */ |
|
22 | - protected $core_config; |
|
19 | + /** |
|
20 | + * @var EE_Core_Config |
|
21 | + */ |
|
22 | + protected $core_config; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var EE_Network_Core_Config |
|
26 | - */ |
|
27 | - protected $network_core_config; |
|
24 | + /** |
|
25 | + * @var EE_Network_Core_Config |
|
26 | + */ |
|
27 | + protected $network_core_config; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * @param EE_Core_Config $core_config |
|
32 | - * @param EE_Network_Core_Config $network_core_config |
|
33 | - */ |
|
34 | - public function __construct(EE_Core_Config $core_config, EE_Network_Core_Config $network_core_config) |
|
35 | - { |
|
36 | - $this->core_config = $core_config; |
|
37 | - $this->network_core_config = $network_core_config; |
|
38 | - } |
|
30 | + /** |
|
31 | + * @param EE_Core_Config $core_config |
|
32 | + * @param EE_Network_Core_Config $network_core_config |
|
33 | + */ |
|
34 | + public function __construct(EE_Core_Config $core_config, EE_Network_Core_Config $network_core_config) |
|
35 | + { |
|
36 | + $this->core_config = $core_config; |
|
37 | + $this->network_core_config = $network_core_config; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @throws EE_Error |
|
43 | - */ |
|
44 | - public function uxipFormSections(EE_Form_Section_Proper $org_settings_form): EE_Form_Section_Proper |
|
45 | - { |
|
46 | - if (is_main_site()) { |
|
47 | - $org_settings_form->add_subsections( |
|
48 | - [ |
|
49 | - 'site_license_key_hdr' => new EE_Form_Section_HTML( |
|
50 | - EEH_HTML::h2( |
|
51 | - esc_html__('Your Event Espresso License Key', 'event_espresso') |
|
52 | - . ' ' |
|
53 | - . EEH_HTML::span( |
|
54 | - EEH_Template::get_help_tab_link('site_license_key_info') |
|
55 | - ), |
|
56 | - '', |
|
57 | - 'site-license-key-hdr' |
|
58 | - ) |
|
59 | - ), |
|
60 | - 'site_license_key' => new EE_Text_Input( |
|
61 | - [ |
|
62 | - 'html_name' => 'ee_site_license_key', |
|
63 | - 'html_id' => 'site_license_key', |
|
64 | - 'html_label_text' => esc_html__('Support License Key', 'event_espresso'), |
|
65 | - /** phpcs:disable WordPress.WP.I18n.UnorderedPlaceholdersText */ |
|
66 | - 'html_help_text' => sprintf( |
|
67 | - esc_html__( |
|
68 | - 'Adding a valid Support License Key will enable automatic update notifications and backend updates for Event Espresso Core and any installed add-ons. If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', |
|
69 | - 'event_espresso' |
|
70 | - ), |
|
71 | - '<strong>', |
|
72 | - '</strong>' |
|
73 | - ), |
|
74 | - /** phpcs:enable */ |
|
75 | - 'default' => $this->network_core_config->site_license_key ?? '', |
|
76 | - 'required' => false, |
|
77 | - 'form_html_filter' => new VsprintfFilter( |
|
78 | - '%2$s %1$s', |
|
79 | - [$this->getValidationIndicator()] |
|
80 | - ) |
|
81 | - ] |
|
82 | - ) |
|
83 | - ] |
|
84 | - ); |
|
85 | - $org_settings_form->add_subsections( |
|
86 | - [ |
|
87 | - 'uxip_optin_hdr' => new EE_Form_Section_HTML(Stats::optinText(false)), |
|
88 | - 'ueip_optin' => new EE_Checkbox_Multi_Input( |
|
89 | - [ |
|
90 | - true => esc_html__('Yes! I want to help improve Event Espresso!', 'event_espresso') |
|
91 | - ], |
|
92 | - [ |
|
93 | - 'html_name' => EE_Core_Config::OPTION_NAME_UXIP, |
|
94 | - 'html_label_text' => esc_html__( |
|
95 | - 'UXIP Opt In?', |
|
96 | - 'event_espresso' |
|
97 | - ), |
|
98 | - 'default' => isset($this->core_config->ee_ueip_optin) |
|
99 | - ? filter_var($this->core_config->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN) |
|
100 | - : false, |
|
101 | - 'required' => false, |
|
102 | - ] |
|
103 | - ), |
|
104 | - ], |
|
105 | - 'organization_instagram', |
|
106 | - false |
|
107 | - ); |
|
108 | - } |
|
109 | - return $org_settings_form; |
|
110 | - } |
|
41 | + /** |
|
42 | + * @throws EE_Error |
|
43 | + */ |
|
44 | + public function uxipFormSections(EE_Form_Section_Proper $org_settings_form): EE_Form_Section_Proper |
|
45 | + { |
|
46 | + if (is_main_site()) { |
|
47 | + $org_settings_form->add_subsections( |
|
48 | + [ |
|
49 | + 'site_license_key_hdr' => new EE_Form_Section_HTML( |
|
50 | + EEH_HTML::h2( |
|
51 | + esc_html__('Your Event Espresso License Key', 'event_espresso') |
|
52 | + . ' ' |
|
53 | + . EEH_HTML::span( |
|
54 | + EEH_Template::get_help_tab_link('site_license_key_info') |
|
55 | + ), |
|
56 | + '', |
|
57 | + 'site-license-key-hdr' |
|
58 | + ) |
|
59 | + ), |
|
60 | + 'site_license_key' => new EE_Text_Input( |
|
61 | + [ |
|
62 | + 'html_name' => 'ee_site_license_key', |
|
63 | + 'html_id' => 'site_license_key', |
|
64 | + 'html_label_text' => esc_html__('Support License Key', 'event_espresso'), |
|
65 | + /** phpcs:disable WordPress.WP.I18n.UnorderedPlaceholdersText */ |
|
66 | + 'html_help_text' => sprintf( |
|
67 | + esc_html__( |
|
68 | + 'Adding a valid Support License Key will enable automatic update notifications and backend updates for Event Espresso Core and any installed add-ons. If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', |
|
69 | + 'event_espresso' |
|
70 | + ), |
|
71 | + '<strong>', |
|
72 | + '</strong>' |
|
73 | + ), |
|
74 | + /** phpcs:enable */ |
|
75 | + 'default' => $this->network_core_config->site_license_key ?? '', |
|
76 | + 'required' => false, |
|
77 | + 'form_html_filter' => new VsprintfFilter( |
|
78 | + '%2$s %1$s', |
|
79 | + [$this->getValidationIndicator()] |
|
80 | + ) |
|
81 | + ] |
|
82 | + ) |
|
83 | + ] |
|
84 | + ); |
|
85 | + $org_settings_form->add_subsections( |
|
86 | + [ |
|
87 | + 'uxip_optin_hdr' => new EE_Form_Section_HTML(Stats::optinText(false)), |
|
88 | + 'ueip_optin' => new EE_Checkbox_Multi_Input( |
|
89 | + [ |
|
90 | + true => esc_html__('Yes! I want to help improve Event Espresso!', 'event_espresso') |
|
91 | + ], |
|
92 | + [ |
|
93 | + 'html_name' => EE_Core_Config::OPTION_NAME_UXIP, |
|
94 | + 'html_label_text' => esc_html__( |
|
95 | + 'UXIP Opt In?', |
|
96 | + 'event_espresso' |
|
97 | + ), |
|
98 | + 'default' => isset($this->core_config->ee_ueip_optin) |
|
99 | + ? filter_var($this->core_config->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN) |
|
100 | + : false, |
|
101 | + 'required' => false, |
|
102 | + ] |
|
103 | + ), |
|
104 | + ], |
|
105 | + 'organization_instagram', |
|
106 | + false |
|
107 | + ); |
|
108 | + } |
|
109 | + return $org_settings_form; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | |
113 | 113 | |
114 | - /** |
|
115 | - * Return whether the site license key has been verified or not. |
|
116 | - * |
|
117 | - * @return bool |
|
118 | - */ |
|
119 | - private function licenseKeyVerified(): bool |
|
120 | - { |
|
121 | - if (empty($this->network_core_config->site_license_key)) { |
|
122 | - return false; |
|
123 | - } |
|
124 | - $verify_fail = get_option( |
|
125 | - 'puvererr_' . basename(EE_PLUGIN_BASENAME), |
|
126 | - false |
|
127 | - ); |
|
128 | - return $verify_fail === false |
|
129 | - || ( |
|
130 | - ! empty($this->network_core_config->site_license_key) |
|
131 | - && $verify_fail === false |
|
132 | - ); |
|
133 | - } |
|
114 | + /** |
|
115 | + * Return whether the site license key has been verified or not. |
|
116 | + * |
|
117 | + * @return bool |
|
118 | + */ |
|
119 | + private function licenseKeyVerified(): bool |
|
120 | + { |
|
121 | + if (empty($this->network_core_config->site_license_key)) { |
|
122 | + return false; |
|
123 | + } |
|
124 | + $verify_fail = get_option( |
|
125 | + 'puvererr_' . basename(EE_PLUGIN_BASENAME), |
|
126 | + false |
|
127 | + ); |
|
128 | + return $verify_fail === false |
|
129 | + || ( |
|
130 | + ! empty($this->network_core_config->site_license_key) |
|
131 | + && $verify_fail === false |
|
132 | + ); |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | - /** |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - private function getValidationIndicator(): string |
|
140 | - { |
|
141 | - $verified_class = $this->licenseKeyVerified() ? 'ee-icon-color-ee-green' : 'ee-icon-color-ee-red'; |
|
142 | - return '<span class="dashicons dashicons-admin-network ' . $verified_class . ' ee-icon-size-20"></span>'; |
|
143 | - } |
|
136 | + /** |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + private function getValidationIndicator(): string |
|
140 | + { |
|
141 | + $verified_class = $this->licenseKeyVerified() ? 'ee-icon-color-ee-green' : 'ee-icon-color-ee-red'; |
|
142 | + return '<span class="dashicons dashicons-admin-network ' . $verified_class . ' ee-icon-size-20"></span>'; |
|
143 | + } |
|
144 | 144 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | return false; |
123 | 123 | } |
124 | 124 | $verify_fail = get_option( |
125 | - 'puvererr_' . basename(EE_PLUGIN_BASENAME), |
|
125 | + 'puvererr_'.basename(EE_PLUGIN_BASENAME), |
|
126 | 126 | false |
127 | 127 | ); |
128 | 128 | return $verify_fail === false |
@@ -139,6 +139,6 @@ discard block |
||
139 | 139 | private function getValidationIndicator(): string |
140 | 140 | { |
141 | 141 | $verified_class = $this->licenseKeyVerified() ? 'ee-icon-color-ee-green' : 'ee-icon-color-ee-red'; |
142 | - return '<span class="dashicons dashicons-admin-network ' . $verified_class . ' ee-icon-size-20"></span>'; |
|
142 | + return '<span class="dashicons dashicons-admin-network '.$verified_class.' ee-icon-size-20"></span>'; |
|
143 | 143 | } |
144 | 144 | } |
@@ -15,288 +15,288 @@ |
||
15 | 15 | |
16 | 16 | class StatsGatherer |
17 | 17 | { |
18 | - public const COUNT_ALL_EVENTS = 'event'; |
|
18 | + public const COUNT_ALL_EVENTS = 'event'; |
|
19 | 19 | |
20 | - public const COUNT_ACTIVE_EVENTS = 'active_event'; |
|
20 | + public const COUNT_ACTIVE_EVENTS = 'active_event'; |
|
21 | 21 | |
22 | - public const COUNT_DATETIMES = 'datetime'; |
|
22 | + public const COUNT_DATETIMES = 'datetime'; |
|
23 | 23 | |
24 | - public const COUNT_TICKETS = 'ticket'; |
|
24 | + public const COUNT_TICKETS = 'ticket'; |
|
25 | 25 | |
26 | - public const COUNT_DATETIMES_SOLD = 'datetime_sold'; |
|
26 | + public const COUNT_DATETIMES_SOLD = 'datetime_sold'; |
|
27 | 27 | |
28 | - public const COUNT_TICKETS_FREE = 'free_ticket'; |
|
28 | + public const COUNT_TICKETS_FREE = 'free_ticket'; |
|
29 | 29 | |
30 | - public const COUNT_TICKETS_PAID = 'paid_ticket'; |
|
30 | + public const COUNT_TICKETS_PAID = 'paid_ticket'; |
|
31 | 31 | |
32 | - public const COUNT_TICKETS_SOLD = 'ticket_sold'; |
|
32 | + public const COUNT_TICKETS_SOLD = 'ticket_sold'; |
|
33 | 33 | |
34 | - public const COUNT_REGISTRATIONS_APPROVED = 'registrations_approved'; |
|
34 | + public const COUNT_REGISTRATIONS_APPROVED = 'registrations_approved'; |
|
35 | 35 | |
36 | - public const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved'; |
|
36 | + public const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved'; |
|
37 | 37 | |
38 | - public const COUNT_REGISTRATIONS_PENDING = 'registrations_pending'; |
|
38 | + public const COUNT_REGISTRATIONS_PENDING = 'registrations_pending'; |
|
39 | 39 | |
40 | - public const COUNT_REGISTRATIONS_INCOMPLETE = 'registrations_incomplete'; |
|
40 | + public const COUNT_REGISTRATIONS_INCOMPLETE = 'registrations_incomplete'; |
|
41 | 41 | |
42 | - public const COUNT_REGISTRATIONS_ALL = 'registrations_all'; |
|
42 | + public const COUNT_REGISTRATIONS_ALL = 'registrations_all'; |
|
43 | 43 | |
44 | - public const COUNT_REGISTRATIONS_CANCELLED = 'registrations_cancelled'; |
|
44 | + public const COUNT_REGISTRATIONS_CANCELLED = 'registrations_cancelled'; |
|
45 | 45 | |
46 | - public const COUNT_REGISTRATIONS_DECLINED = 'registrations_declined'; |
|
46 | + public const COUNT_REGISTRATIONS_DECLINED = 'registrations_declined'; |
|
47 | 47 | |
48 | - public const SUM_TRANSACTIONS_COMPLETE_TOTAL = 'transactions_complete_total_sum'; |
|
48 | + public const SUM_TRANSACTIONS_COMPLETE_TOTAL = 'transactions_complete_total_sum'; |
|
49 | 49 | |
50 | - public const SUM_TRANSACTIONS_ALL_PAID = 'transactions_all_paid'; |
|
50 | + public const SUM_TRANSACTIONS_ALL_PAID = 'transactions_all_paid'; |
|
51 | 51 | |
52 | - public const INFO_SITE_CURRENCY = 'site_currency'; |
|
52 | + public const INFO_SITE_CURRENCY = 'site_currency'; |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * @var EEM_Payment_Method |
|
57 | - */ |
|
58 | - private $payment_method_model; |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @var EEM_Event |
|
63 | - */ |
|
64 | - private $event_model; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var EEM_Datetime |
|
68 | - */ |
|
69 | - private $datetime_model; |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @var EEM_Ticket |
|
74 | - */ |
|
75 | - private $ticket_model; |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @var EEM_Registration |
|
80 | - */ |
|
81 | - private $registration_model; |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * @var EEM_Transaction |
|
86 | - */ |
|
87 | - private $transaction_model; |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @var EE_Config |
|
92 | - */ |
|
93 | - private $config; |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * StatsGatherer constructor. |
|
98 | - * |
|
99 | - * @param EEM_Payment_Method $payment_method_model |
|
100 | - * @param EEM_Event $event_model |
|
101 | - * @param EEM_Datetime $datetime_model |
|
102 | - * @param EEM_Ticket $ticket_model |
|
103 | - * @param EEM_Registration $registration_model |
|
104 | - * @param EEM_Transaction $transaction_model |
|
105 | - * @param EE_Config $config |
|
106 | - */ |
|
107 | - public function __construct( |
|
108 | - EEM_Payment_Method $payment_method_model, |
|
109 | - EEM_Event $event_model, |
|
110 | - EEM_Datetime $datetime_model, |
|
111 | - EEM_Ticket $ticket_model, |
|
112 | - EEM_Registration $registration_model, |
|
113 | - EEM_Transaction $transaction_model, |
|
114 | - EE_Config $config |
|
115 | - ) { |
|
116 | - $this->payment_method_model = $payment_method_model; |
|
117 | - $this->event_model = $event_model; |
|
118 | - $this->datetime_model = $datetime_model; |
|
119 | - $this->ticket_model = $ticket_model; |
|
120 | - $this->registration_model = $registration_model; |
|
121 | - $this->transaction_model = $transaction_model; |
|
122 | - $this->config = $config; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Return the stats array for PUE UXIP stats. |
|
128 | - * |
|
129 | - * @return array |
|
130 | - */ |
|
131 | - public function stats(): array |
|
132 | - { |
|
133 | - global $wp_version; |
|
134 | - $stats = $this->paymentMethodStats(); |
|
135 | - // a-ok so let's setup our stats. |
|
136 | - $stats = array_merge( |
|
137 | - $stats, |
|
138 | - [ |
|
139 | - 'is_multisite' => is_multisite() && is_main_site(), |
|
140 | - 'active_theme' => $this->getActiveThemeStat(), |
|
141 | - 'ee4_all_events_count' => $this->getCountFor(self::COUNT_ALL_EVENTS), |
|
142 | - 'ee4_active_events_count' => $this->getCountFor(self::COUNT_ACTIVE_EVENTS), |
|
143 | - 'all_dtts_count' => $this->getCountFor(self::COUNT_DATETIMES), |
|
144 | - 'dtt_sold' => $this->getCountFor(self::COUNT_DATETIMES_SOLD), |
|
145 | - 'all_tkt_count' => $this->getCountFor(self::COUNT_TICKETS), |
|
146 | - 'free_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_FREE), |
|
147 | - 'paid_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_PAID), |
|
148 | - 'tkt_sold' => $this->getCountFor(self::COUNT_TICKETS_SOLD), |
|
149 | - 'approve_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED), |
|
150 | - 'pending_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING), |
|
151 | - 'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED), |
|
152 | - 'incomplete_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE), |
|
153 | - 'cancelled_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED), |
|
154 | - 'declined_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED), |
|
155 | - 'all_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL), |
|
156 | - 'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL), |
|
157 | - 'all_transaction_paid_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID), |
|
158 | - self::INFO_SITE_CURRENCY => $this->config->currency instanceof EE_Currency_Config |
|
159 | - ? $this->config->currency->code |
|
160 | - : 'unknown', |
|
161 | - 'phpversion' => implode( |
|
162 | - '.', |
|
163 | - [PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION] |
|
164 | - ), |
|
165 | - 'wpversion' => $wp_version, |
|
166 | - 'active_addons' => $this->getActiveAddons(), |
|
167 | - ] |
|
168 | - ); |
|
169 | - // remove any values that equal null. This ensures any stats that weren't retrieved successfully are excluded. |
|
170 | - return array_filter($stats, function ($value) { |
|
171 | - return $value !== null; |
|
172 | - }); |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @param string $which enum (@see constants prefixed with COUNT) |
|
178 | - * @return int|null |
|
179 | - */ |
|
180 | - private function getCountFor(string $which): ?int |
|
181 | - { |
|
182 | - try { |
|
183 | - switch ($which) { |
|
184 | - case self::COUNT_ALL_EVENTS: |
|
185 | - $count = $this->event_model->count(); |
|
186 | - break; |
|
187 | - case self::COUNT_TICKETS: |
|
188 | - $count = $this->ticket_model->count(); |
|
189 | - break; |
|
190 | - case self::COUNT_DATETIMES: |
|
191 | - $count = $this->datetime_model->count(); |
|
192 | - break; |
|
193 | - case self::COUNT_ACTIVE_EVENTS: |
|
194 | - $count = $this->event_model->get_active_events([], true); |
|
195 | - break; |
|
196 | - case self::COUNT_DATETIMES_SOLD: |
|
197 | - $count = $this->datetime_model->sum([], 'DTT_sold'); |
|
198 | - break; |
|
199 | - case self::COUNT_TICKETS_FREE: |
|
200 | - $count = $this->ticket_model->count([['TKT_price' => 0]]); |
|
201 | - break; |
|
202 | - case self::COUNT_TICKETS_PAID: |
|
203 | - $count = $this->ticket_model->count([['TKT_price' => ['>', 0]]]); |
|
204 | - break; |
|
205 | - case self::COUNT_TICKETS_SOLD: |
|
206 | - $count = $this->ticket_model->sum([], 'TKT_sold'); |
|
207 | - break; |
|
208 | - case self::COUNT_REGISTRATIONS_ALL: |
|
209 | - $count = $this->registration_model->count(); |
|
210 | - break; |
|
211 | - case self::COUNT_REGISTRATIONS_CANCELLED: |
|
212 | - $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_cancelled]]); |
|
213 | - break; |
|
214 | - case self::COUNT_REGISTRATIONS_INCOMPLETE: |
|
215 | - $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_incomplete]]); |
|
216 | - break; |
|
217 | - case self::COUNT_REGISTRATIONS_NOT_APPROVED: |
|
218 | - $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_not_approved]]); |
|
219 | - break; |
|
220 | - case self::COUNT_REGISTRATIONS_DECLINED: |
|
221 | - $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_declined]]); |
|
222 | - break; |
|
223 | - case self::COUNT_REGISTRATIONS_PENDING: |
|
224 | - $count = $this->registration_model->count( |
|
225 | - [['STS_ID' => EEM_Registration::status_id_pending_payment]] |
|
226 | - ); |
|
227 | - break; |
|
228 | - case self::COUNT_REGISTRATIONS_APPROVED: |
|
229 | - $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_approved]]); |
|
230 | - break; |
|
231 | - case self::SUM_TRANSACTIONS_COMPLETE_TOTAL: |
|
232 | - $count = $this->transaction_model->sum( |
|
233 | - [['STS_ID' => EEM_Transaction::complete_status_code]], |
|
234 | - 'TXN_total' |
|
235 | - ); |
|
236 | - break; |
|
237 | - case self::SUM_TRANSACTIONS_ALL_PAID: |
|
238 | - $count = $this->transaction_model->sum([], 'TXN_paid'); |
|
239 | - break; |
|
240 | - default: |
|
241 | - $count = null; |
|
242 | - break; |
|
243 | - } |
|
244 | - } catch (Exception $e) { |
|
245 | - $count = null; |
|
246 | - } |
|
247 | - return $count; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * Return the active theme. |
|
253 | - * |
|
254 | - * @return false|string |
|
255 | - */ |
|
256 | - private function getActiveThemeStat() |
|
257 | - { |
|
258 | - $theme = wp_get_theme(); |
|
259 | - return $theme->get('Name'); |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * @return array |
|
265 | - */ |
|
266 | - private function paymentMethodStats(): array |
|
267 | - { |
|
268 | - $payment_method_stats = []; |
|
269 | - try { |
|
270 | - $active_payment_methods = $this->payment_method_model->get_all_active( |
|
271 | - null, |
|
272 | - ['group_by' => 'PMD_type'] |
|
273 | - ); |
|
274 | - if ($active_payment_methods) { |
|
275 | - foreach ($active_payment_methods as $payment_method) { |
|
276 | - $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1; |
|
277 | - } |
|
278 | - } |
|
279 | - } catch (Exception $e) { |
|
280 | - // do nothing just prevents fatals. |
|
281 | - } |
|
282 | - return $payment_method_stats; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Return a list of active EE add-ons and their versions. |
|
288 | - * |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - private function getActiveAddons(): string |
|
292 | - { |
|
293 | - $activeAddons = []; |
|
294 | - $addOns = EE_Registry::instance()->addons; |
|
295 | - if (! empty($addOns)) { |
|
296 | - foreach ($addOns as $addon) { |
|
297 | - $activeAddons[] = $addon->name() . '@' . $addon->version(); |
|
298 | - } |
|
299 | - } |
|
300 | - return implode(',', $activeAddons); |
|
301 | - } |
|
55 | + /** |
|
56 | + * @var EEM_Payment_Method |
|
57 | + */ |
|
58 | + private $payment_method_model; |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @var EEM_Event |
|
63 | + */ |
|
64 | + private $event_model; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var EEM_Datetime |
|
68 | + */ |
|
69 | + private $datetime_model; |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @var EEM_Ticket |
|
74 | + */ |
|
75 | + private $ticket_model; |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @var EEM_Registration |
|
80 | + */ |
|
81 | + private $registration_model; |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * @var EEM_Transaction |
|
86 | + */ |
|
87 | + private $transaction_model; |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @var EE_Config |
|
92 | + */ |
|
93 | + private $config; |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * StatsGatherer constructor. |
|
98 | + * |
|
99 | + * @param EEM_Payment_Method $payment_method_model |
|
100 | + * @param EEM_Event $event_model |
|
101 | + * @param EEM_Datetime $datetime_model |
|
102 | + * @param EEM_Ticket $ticket_model |
|
103 | + * @param EEM_Registration $registration_model |
|
104 | + * @param EEM_Transaction $transaction_model |
|
105 | + * @param EE_Config $config |
|
106 | + */ |
|
107 | + public function __construct( |
|
108 | + EEM_Payment_Method $payment_method_model, |
|
109 | + EEM_Event $event_model, |
|
110 | + EEM_Datetime $datetime_model, |
|
111 | + EEM_Ticket $ticket_model, |
|
112 | + EEM_Registration $registration_model, |
|
113 | + EEM_Transaction $transaction_model, |
|
114 | + EE_Config $config |
|
115 | + ) { |
|
116 | + $this->payment_method_model = $payment_method_model; |
|
117 | + $this->event_model = $event_model; |
|
118 | + $this->datetime_model = $datetime_model; |
|
119 | + $this->ticket_model = $ticket_model; |
|
120 | + $this->registration_model = $registration_model; |
|
121 | + $this->transaction_model = $transaction_model; |
|
122 | + $this->config = $config; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Return the stats array for PUE UXIP stats. |
|
128 | + * |
|
129 | + * @return array |
|
130 | + */ |
|
131 | + public function stats(): array |
|
132 | + { |
|
133 | + global $wp_version; |
|
134 | + $stats = $this->paymentMethodStats(); |
|
135 | + // a-ok so let's setup our stats. |
|
136 | + $stats = array_merge( |
|
137 | + $stats, |
|
138 | + [ |
|
139 | + 'is_multisite' => is_multisite() && is_main_site(), |
|
140 | + 'active_theme' => $this->getActiveThemeStat(), |
|
141 | + 'ee4_all_events_count' => $this->getCountFor(self::COUNT_ALL_EVENTS), |
|
142 | + 'ee4_active_events_count' => $this->getCountFor(self::COUNT_ACTIVE_EVENTS), |
|
143 | + 'all_dtts_count' => $this->getCountFor(self::COUNT_DATETIMES), |
|
144 | + 'dtt_sold' => $this->getCountFor(self::COUNT_DATETIMES_SOLD), |
|
145 | + 'all_tkt_count' => $this->getCountFor(self::COUNT_TICKETS), |
|
146 | + 'free_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_FREE), |
|
147 | + 'paid_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_PAID), |
|
148 | + 'tkt_sold' => $this->getCountFor(self::COUNT_TICKETS_SOLD), |
|
149 | + 'approve_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED), |
|
150 | + 'pending_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING), |
|
151 | + 'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED), |
|
152 | + 'incomplete_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE), |
|
153 | + 'cancelled_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED), |
|
154 | + 'declined_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED), |
|
155 | + 'all_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL), |
|
156 | + 'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL), |
|
157 | + 'all_transaction_paid_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID), |
|
158 | + self::INFO_SITE_CURRENCY => $this->config->currency instanceof EE_Currency_Config |
|
159 | + ? $this->config->currency->code |
|
160 | + : 'unknown', |
|
161 | + 'phpversion' => implode( |
|
162 | + '.', |
|
163 | + [PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION] |
|
164 | + ), |
|
165 | + 'wpversion' => $wp_version, |
|
166 | + 'active_addons' => $this->getActiveAddons(), |
|
167 | + ] |
|
168 | + ); |
|
169 | + // remove any values that equal null. This ensures any stats that weren't retrieved successfully are excluded. |
|
170 | + return array_filter($stats, function ($value) { |
|
171 | + return $value !== null; |
|
172 | + }); |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @param string $which enum (@see constants prefixed with COUNT) |
|
178 | + * @return int|null |
|
179 | + */ |
|
180 | + private function getCountFor(string $which): ?int |
|
181 | + { |
|
182 | + try { |
|
183 | + switch ($which) { |
|
184 | + case self::COUNT_ALL_EVENTS: |
|
185 | + $count = $this->event_model->count(); |
|
186 | + break; |
|
187 | + case self::COUNT_TICKETS: |
|
188 | + $count = $this->ticket_model->count(); |
|
189 | + break; |
|
190 | + case self::COUNT_DATETIMES: |
|
191 | + $count = $this->datetime_model->count(); |
|
192 | + break; |
|
193 | + case self::COUNT_ACTIVE_EVENTS: |
|
194 | + $count = $this->event_model->get_active_events([], true); |
|
195 | + break; |
|
196 | + case self::COUNT_DATETIMES_SOLD: |
|
197 | + $count = $this->datetime_model->sum([], 'DTT_sold'); |
|
198 | + break; |
|
199 | + case self::COUNT_TICKETS_FREE: |
|
200 | + $count = $this->ticket_model->count([['TKT_price' => 0]]); |
|
201 | + break; |
|
202 | + case self::COUNT_TICKETS_PAID: |
|
203 | + $count = $this->ticket_model->count([['TKT_price' => ['>', 0]]]); |
|
204 | + break; |
|
205 | + case self::COUNT_TICKETS_SOLD: |
|
206 | + $count = $this->ticket_model->sum([], 'TKT_sold'); |
|
207 | + break; |
|
208 | + case self::COUNT_REGISTRATIONS_ALL: |
|
209 | + $count = $this->registration_model->count(); |
|
210 | + break; |
|
211 | + case self::COUNT_REGISTRATIONS_CANCELLED: |
|
212 | + $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_cancelled]]); |
|
213 | + break; |
|
214 | + case self::COUNT_REGISTRATIONS_INCOMPLETE: |
|
215 | + $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_incomplete]]); |
|
216 | + break; |
|
217 | + case self::COUNT_REGISTRATIONS_NOT_APPROVED: |
|
218 | + $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_not_approved]]); |
|
219 | + break; |
|
220 | + case self::COUNT_REGISTRATIONS_DECLINED: |
|
221 | + $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_declined]]); |
|
222 | + break; |
|
223 | + case self::COUNT_REGISTRATIONS_PENDING: |
|
224 | + $count = $this->registration_model->count( |
|
225 | + [['STS_ID' => EEM_Registration::status_id_pending_payment]] |
|
226 | + ); |
|
227 | + break; |
|
228 | + case self::COUNT_REGISTRATIONS_APPROVED: |
|
229 | + $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_approved]]); |
|
230 | + break; |
|
231 | + case self::SUM_TRANSACTIONS_COMPLETE_TOTAL: |
|
232 | + $count = $this->transaction_model->sum( |
|
233 | + [['STS_ID' => EEM_Transaction::complete_status_code]], |
|
234 | + 'TXN_total' |
|
235 | + ); |
|
236 | + break; |
|
237 | + case self::SUM_TRANSACTIONS_ALL_PAID: |
|
238 | + $count = $this->transaction_model->sum([], 'TXN_paid'); |
|
239 | + break; |
|
240 | + default: |
|
241 | + $count = null; |
|
242 | + break; |
|
243 | + } |
|
244 | + } catch (Exception $e) { |
|
245 | + $count = null; |
|
246 | + } |
|
247 | + return $count; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * Return the active theme. |
|
253 | + * |
|
254 | + * @return false|string |
|
255 | + */ |
|
256 | + private function getActiveThemeStat() |
|
257 | + { |
|
258 | + $theme = wp_get_theme(); |
|
259 | + return $theme->get('Name'); |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * @return array |
|
265 | + */ |
|
266 | + private function paymentMethodStats(): array |
|
267 | + { |
|
268 | + $payment_method_stats = []; |
|
269 | + try { |
|
270 | + $active_payment_methods = $this->payment_method_model->get_all_active( |
|
271 | + null, |
|
272 | + ['group_by' => 'PMD_type'] |
|
273 | + ); |
|
274 | + if ($active_payment_methods) { |
|
275 | + foreach ($active_payment_methods as $payment_method) { |
|
276 | + $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1; |
|
277 | + } |
|
278 | + } |
|
279 | + } catch (Exception $e) { |
|
280 | + // do nothing just prevents fatals. |
|
281 | + } |
|
282 | + return $payment_method_stats; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Return a list of active EE add-ons and their versions. |
|
288 | + * |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + private function getActiveAddons(): string |
|
292 | + { |
|
293 | + $activeAddons = []; |
|
294 | + $addOns = EE_Registry::instance()->addons; |
|
295 | + if (! empty($addOns)) { |
|
296 | + foreach ($addOns as $addon) { |
|
297 | + $activeAddons[] = $addon->name() . '@' . $addon->version(); |
|
298 | + } |
|
299 | + } |
|
300 | + return implode(',', $activeAddons); |
|
301 | + } |
|
302 | 302 | } |