@@ -445,11 +445,11 @@ discard block |
||
445 | 445 | */ |
446 | 446 | public function type_obj() |
447 | 447 | { |
448 | - if (! $this->_type_obj) { |
|
448 | + if ( ! $this->_type_obj) { |
|
449 | 449 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
450 | 450 | if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
451 | 451 | $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
452 | - if (! class_exists($class_name)) { |
|
452 | + if ( ! class_exists($class_name)) { |
|
453 | 453 | throw new EE_Error( |
454 | 454 | sprintf( |
455 | 455 | esc_html__( |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | ), |
459 | 459 | $class_name, |
460 | 460 | '<br />', |
461 | - '<a href="' . admin_url('plugins.php') . '">', |
|
461 | + '<a href="'.admin_url('plugins.php').'">', |
|
462 | 462 | '</a>' |
463 | 463 | ) |
464 | 464 | ); |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | foreach ($fields as $key => $value) { |
500 | 500 | if (strpos($key, 'PMD_') === 0) { |
501 | 501 | $key_sans_model_prefix = str_replace('PMD_', '', $key); |
502 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
502 | + $combined_settings_array [$key_sans_model_prefix] = $value; |
|
503 | 503 | } |
504 | 504 | } |
505 | 505 | $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
@@ -522,14 +522,14 @@ discard block |
||
522 | 522 | <div id="' |
523 | 523 | . $this->slug() |
524 | 524 | . '-payment-option-dv" class="' |
525 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
525 | + . $payment_occurs.'-payment-gateway reg-page-payment-option-dv'.$css_class.'"> |
|
526 | 526 | <a id="payment-gateway-button-' . $this->slug() |
527 | 527 | . '" class="reg-page-payment-option-lnk" rel="' |
528 | - . $this->slug() . '" href="' . $url . '" > |
|
529 | - <img src="' . $this->button_url() . '" alt="' . sprintf( |
|
528 | + . $this->slug().'" href="'.$url.'" > |
|
529 | + <img src="' . $this->button_url().'" alt="'.sprintf( |
|
530 | 530 | esc_attr__('Pay using %s', 'event_espresso'), |
531 | 531 | $this->get_pretty('PMD_name', 'form_input') |
532 | - ) . '" /> |
|
532 | + ).'" /> |
|
533 | 533 | </a> |
534 | 534 | </div> |
535 | 535 | '; |
@@ -13,582 +13,582 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Payment_Method extends EE_Base_Class |
15 | 15 | { |
16 | - /** |
|
17 | - * Payment Method type object, which has all the info about this type of payment method, |
|
18 | - * including functions for processing payments, to get settings forms, etc. |
|
19 | - * |
|
20 | - * @var EE_PMT_Base |
|
21 | - */ |
|
22 | - protected $_type_obj; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * @param array $props_n_values |
|
27 | - * @return EE_Payment_Method |
|
28 | - * @throws \EE_Error |
|
29 | - */ |
|
30 | - public static function new_instance($props_n_values = array()) |
|
31 | - { |
|
32 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
33 | - return $has_object ? $has_object : new self($props_n_values, false); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @param array $props_n_values |
|
39 | - * @return EE_Payment_Method |
|
40 | - * @throws \EE_Error |
|
41 | - */ |
|
42 | - public static function new_instance_from_db($props_n_values = array()) |
|
43 | - { |
|
44 | - return new self($props_n_values, true); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
51 | - * Otherwise returns a normal EE_Payment_Method |
|
52 | - * |
|
53 | - * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
54 | - * the classname minus 'EEPM_') |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - // private static function _payment_method_type($props_n_values) |
|
58 | - // { |
|
59 | - // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
60 | - // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
61 | - // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
62 | - // return 'EEPM_' . $type_string; |
|
63 | - // } else { |
|
64 | - // return __CLASS__; |
|
65 | - // } |
|
66 | - // } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
71 | - * |
|
72 | - * @return boolean |
|
73 | - */ |
|
74 | - public function active() |
|
75 | - { |
|
76 | - return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
82 | - * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
83 | - * |
|
84 | - * @throws \EE_Error |
|
85 | - */ |
|
86 | - public function set_active() |
|
87 | - { |
|
88 | - $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
89 | - if ( |
|
90 | - $this->type_obj() && |
|
91 | - $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
92 | - ) { |
|
93 | - $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
94 | - } |
|
95 | - $this->set_scope($default_scopes); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
101 | - */ |
|
102 | - public function deactivate() |
|
103 | - { |
|
104 | - $this->set_scope(array()); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Gets button_url |
|
110 | - * |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function button_url() |
|
114 | - { |
|
115 | - return $this->get('PMD_button_url'); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Sets button_url |
|
121 | - * |
|
122 | - * @param string $button_url |
|
123 | - */ |
|
124 | - public function set_button_url($button_url) |
|
125 | - { |
|
126 | - $this->set('PMD_button_url', $button_url); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Gets debug_mode |
|
132 | - * |
|
133 | - * @return boolean |
|
134 | - */ |
|
135 | - public function debug_mode() |
|
136 | - { |
|
137 | - return (bool) $this->get('PMD_debug_mode'); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Sets debug_mode |
|
143 | - * |
|
144 | - * @param boolean $debug_mode |
|
145 | - */ |
|
146 | - public function set_debug_mode($debug_mode) |
|
147 | - { |
|
148 | - $this->set('PMD_debug_mode', $debug_mode); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Gets description |
|
154 | - * |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function description() |
|
158 | - { |
|
159 | - return $this->get('PMD_desc'); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Sets description |
|
165 | - * |
|
166 | - * @param string $description |
|
167 | - */ |
|
168 | - public function set_description($description) |
|
169 | - { |
|
170 | - $this->set('PMD_desc', $description); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Gets name |
|
176 | - * |
|
177 | - * @return string |
|
178 | - */ |
|
179 | - public function name() |
|
180 | - { |
|
181 | - return $this->get('PMD_name'); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Sets name |
|
187 | - * |
|
188 | - * @param string $name |
|
189 | - */ |
|
190 | - public function set_name($name) |
|
191 | - { |
|
192 | - $this->set('PMD_name', $name); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * Gets open_by_default |
|
198 | - * |
|
199 | - * @return boolean |
|
200 | - */ |
|
201 | - public function open_by_default() |
|
202 | - { |
|
203 | - return $this->get('PMD_open_by_default'); |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * Sets open_by_default |
|
209 | - * |
|
210 | - * @param boolean $open_by_default |
|
211 | - */ |
|
212 | - public function set_open_by_default($open_by_default) |
|
213 | - { |
|
214 | - $this->set('PMD_open_by_default', $open_by_default); |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * Gets order |
|
220 | - * |
|
221 | - * @return int |
|
222 | - */ |
|
223 | - public function order() |
|
224 | - { |
|
225 | - return $this->get('PMD_order'); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * Sets order |
|
231 | - * |
|
232 | - * @param int $order |
|
233 | - */ |
|
234 | - public function set_order($order) |
|
235 | - { |
|
236 | - $this->set('PMD_order', $order); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * Gets slug |
|
242 | - * |
|
243 | - * @return string |
|
244 | - */ |
|
245 | - public function slug() |
|
246 | - { |
|
247 | - return $this->get('PMD_slug'); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * Sets slug |
|
253 | - * |
|
254 | - * @param string $slug |
|
255 | - */ |
|
256 | - public function set_slug($slug) |
|
257 | - { |
|
258 | - $this->set('PMD_slug', $slug); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * Gets type |
|
264 | - * |
|
265 | - * @return string |
|
266 | - */ |
|
267 | - public function type() |
|
268 | - { |
|
269 | - return $this->get('PMD_type'); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Sets type |
|
275 | - * |
|
276 | - * @param string $type |
|
277 | - */ |
|
278 | - public function set_type($type) |
|
279 | - { |
|
280 | - $this->set('PMD_type', $type); |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * Gets wp_user |
|
286 | - * |
|
287 | - * @return int |
|
288 | - */ |
|
289 | - public function wp_user() |
|
290 | - { |
|
291 | - return $this->get('PMD_wp_user'); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * Sets wp_user |
|
297 | - * |
|
298 | - * @param int $wp_user_id |
|
299 | - */ |
|
300 | - public function set_wp_user($wp_user_id) |
|
301 | - { |
|
302 | - $this->set('PMD_wp_user', $wp_user_id); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
307 | - * |
|
308 | - * @param string $field_name |
|
309 | - * @param mixed $field_value |
|
310 | - * @param boolean $use_default |
|
311 | - */ |
|
312 | - public function set($field_name, $field_value, $use_default = false) |
|
313 | - { |
|
314 | - if ($field_name === 'PMD_type') { |
|
315 | - // the type has probably changed, so forget about its old type object |
|
316 | - $this->_type_obj = null; |
|
317 | - } |
|
318 | - parent::set($field_name, $field_value, $use_default); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Gets admin_name |
|
324 | - * |
|
325 | - * @return string |
|
326 | - */ |
|
327 | - public function admin_name() |
|
328 | - { |
|
329 | - return $this->get('PMD_admin_name'); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * Sets admin_name |
|
335 | - * |
|
336 | - * @param string $admin_name |
|
337 | - */ |
|
338 | - public function set_admin_name($admin_name) |
|
339 | - { |
|
340 | - $this->set('PMD_admin_name', $admin_name); |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * Gets admin_desc |
|
346 | - * |
|
347 | - * @return string |
|
348 | - */ |
|
349 | - public function admin_desc() |
|
350 | - { |
|
351 | - return $this->get('PMD_admin_desc'); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Sets admin_desc |
|
357 | - * |
|
358 | - * @param string $admin_desc |
|
359 | - */ |
|
360 | - public function set_admin_desc($admin_desc) |
|
361 | - { |
|
362 | - $this->set('PMD_admin_desc', $admin_desc); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * Gets scope |
|
368 | - * |
|
369 | - * @return array |
|
370 | - */ |
|
371 | - public function scope() |
|
372 | - { |
|
373 | - return $this->get('PMD_scope'); |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Sets scope |
|
379 | - * |
|
380 | - * @param array $scope |
|
381 | - */ |
|
382 | - public function set_scope($scope) |
|
383 | - { |
|
384 | - $this->set('PMD_scope', $scope); |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * Gets the payment method type for this payment method instance |
|
390 | - * |
|
391 | - * @return EE_PMT_Base |
|
392 | - * @throws EE_Error |
|
393 | - */ |
|
394 | - public function type_obj() |
|
395 | - { |
|
396 | - if (! $this->_type_obj) { |
|
397 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
398 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
399 | - $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
400 | - if (! class_exists($class_name)) { |
|
401 | - throw new EE_Error( |
|
402 | - sprintf( |
|
403 | - esc_html__( |
|
404 | - 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
405 | - 'event_espresso' |
|
406 | - ), |
|
407 | - $class_name, |
|
408 | - '<br />', |
|
409 | - '<a href="' . admin_url('plugins.php') . '">', |
|
410 | - '</a>' |
|
411 | - ) |
|
412 | - ); |
|
413 | - } |
|
414 | - $r = new ReflectionClass($class_name); |
|
415 | - $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
416 | - } else { |
|
417 | - throw new EE_Error( |
|
418 | - sprintf( |
|
419 | - esc_html__( |
|
420 | - 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
421 | - 'event_espresso' |
|
422 | - ), |
|
423 | - $this->type(), |
|
424 | - implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
425 | - ) |
|
426 | - ); |
|
427 | - } |
|
428 | - } |
|
429 | - return $this->_type_obj; |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
435 | - * and the extra meta. Mostly used for passing off ot gateways. * |
|
436 | - * |
|
437 | - * @return array |
|
438 | - */ |
|
439 | - public function settings_array() |
|
440 | - { |
|
441 | - $fields = $this->model_field_array(); |
|
442 | - $extra_meta = $this->all_extra_meta_array(); |
|
443 | - // remove the model's prefix from the fields |
|
444 | - $combined_settings_array = array(); |
|
445 | - foreach ($fields as $key => $value) { |
|
446 | - if (strpos($key, 'PMD_') === 0) { |
|
447 | - $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
448 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
449 | - } |
|
450 | - } |
|
451 | - $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
452 | - return $combined_settings_array; |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * Gets the HTML for displaying the payment method on a page. |
|
458 | - * |
|
459 | - * @param string $url |
|
460 | - * @param string $css_class |
|
461 | - * @return string of HTML for displaying the button |
|
462 | - * @throws \EE_Error |
|
463 | - */ |
|
464 | - public function button_html($url = '', $css_class = '') |
|
465 | - { |
|
466 | - $payment_occurs = $this->type_obj()->payment_occurs(); |
|
467 | - return ' |
|
16 | + /** |
|
17 | + * Payment Method type object, which has all the info about this type of payment method, |
|
18 | + * including functions for processing payments, to get settings forms, etc. |
|
19 | + * |
|
20 | + * @var EE_PMT_Base |
|
21 | + */ |
|
22 | + protected $_type_obj; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * @param array $props_n_values |
|
27 | + * @return EE_Payment_Method |
|
28 | + * @throws \EE_Error |
|
29 | + */ |
|
30 | + public static function new_instance($props_n_values = array()) |
|
31 | + { |
|
32 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
33 | + return $has_object ? $has_object : new self($props_n_values, false); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @param array $props_n_values |
|
39 | + * @return EE_Payment_Method |
|
40 | + * @throws \EE_Error |
|
41 | + */ |
|
42 | + public static function new_instance_from_db($props_n_values = array()) |
|
43 | + { |
|
44 | + return new self($props_n_values, true); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
51 | + * Otherwise returns a normal EE_Payment_Method |
|
52 | + * |
|
53 | + * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
54 | + * the classname minus 'EEPM_') |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + // private static function _payment_method_type($props_n_values) |
|
58 | + // { |
|
59 | + // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
60 | + // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
61 | + // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
62 | + // return 'EEPM_' . $type_string; |
|
63 | + // } else { |
|
64 | + // return __CLASS__; |
|
65 | + // } |
|
66 | + // } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
71 | + * |
|
72 | + * @return boolean |
|
73 | + */ |
|
74 | + public function active() |
|
75 | + { |
|
76 | + return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
82 | + * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
83 | + * |
|
84 | + * @throws \EE_Error |
|
85 | + */ |
|
86 | + public function set_active() |
|
87 | + { |
|
88 | + $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
89 | + if ( |
|
90 | + $this->type_obj() && |
|
91 | + $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
92 | + ) { |
|
93 | + $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
94 | + } |
|
95 | + $this->set_scope($default_scopes); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
101 | + */ |
|
102 | + public function deactivate() |
|
103 | + { |
|
104 | + $this->set_scope(array()); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Gets button_url |
|
110 | + * |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function button_url() |
|
114 | + { |
|
115 | + return $this->get('PMD_button_url'); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Sets button_url |
|
121 | + * |
|
122 | + * @param string $button_url |
|
123 | + */ |
|
124 | + public function set_button_url($button_url) |
|
125 | + { |
|
126 | + $this->set('PMD_button_url', $button_url); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Gets debug_mode |
|
132 | + * |
|
133 | + * @return boolean |
|
134 | + */ |
|
135 | + public function debug_mode() |
|
136 | + { |
|
137 | + return (bool) $this->get('PMD_debug_mode'); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Sets debug_mode |
|
143 | + * |
|
144 | + * @param boolean $debug_mode |
|
145 | + */ |
|
146 | + public function set_debug_mode($debug_mode) |
|
147 | + { |
|
148 | + $this->set('PMD_debug_mode', $debug_mode); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Gets description |
|
154 | + * |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function description() |
|
158 | + { |
|
159 | + return $this->get('PMD_desc'); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Sets description |
|
165 | + * |
|
166 | + * @param string $description |
|
167 | + */ |
|
168 | + public function set_description($description) |
|
169 | + { |
|
170 | + $this->set('PMD_desc', $description); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Gets name |
|
176 | + * |
|
177 | + * @return string |
|
178 | + */ |
|
179 | + public function name() |
|
180 | + { |
|
181 | + return $this->get('PMD_name'); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Sets name |
|
187 | + * |
|
188 | + * @param string $name |
|
189 | + */ |
|
190 | + public function set_name($name) |
|
191 | + { |
|
192 | + $this->set('PMD_name', $name); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * Gets open_by_default |
|
198 | + * |
|
199 | + * @return boolean |
|
200 | + */ |
|
201 | + public function open_by_default() |
|
202 | + { |
|
203 | + return $this->get('PMD_open_by_default'); |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * Sets open_by_default |
|
209 | + * |
|
210 | + * @param boolean $open_by_default |
|
211 | + */ |
|
212 | + public function set_open_by_default($open_by_default) |
|
213 | + { |
|
214 | + $this->set('PMD_open_by_default', $open_by_default); |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * Gets order |
|
220 | + * |
|
221 | + * @return int |
|
222 | + */ |
|
223 | + public function order() |
|
224 | + { |
|
225 | + return $this->get('PMD_order'); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * Sets order |
|
231 | + * |
|
232 | + * @param int $order |
|
233 | + */ |
|
234 | + public function set_order($order) |
|
235 | + { |
|
236 | + $this->set('PMD_order', $order); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * Gets slug |
|
242 | + * |
|
243 | + * @return string |
|
244 | + */ |
|
245 | + public function slug() |
|
246 | + { |
|
247 | + return $this->get('PMD_slug'); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * Sets slug |
|
253 | + * |
|
254 | + * @param string $slug |
|
255 | + */ |
|
256 | + public function set_slug($slug) |
|
257 | + { |
|
258 | + $this->set('PMD_slug', $slug); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * Gets type |
|
264 | + * |
|
265 | + * @return string |
|
266 | + */ |
|
267 | + public function type() |
|
268 | + { |
|
269 | + return $this->get('PMD_type'); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Sets type |
|
275 | + * |
|
276 | + * @param string $type |
|
277 | + */ |
|
278 | + public function set_type($type) |
|
279 | + { |
|
280 | + $this->set('PMD_type', $type); |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * Gets wp_user |
|
286 | + * |
|
287 | + * @return int |
|
288 | + */ |
|
289 | + public function wp_user() |
|
290 | + { |
|
291 | + return $this->get('PMD_wp_user'); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * Sets wp_user |
|
297 | + * |
|
298 | + * @param int $wp_user_id |
|
299 | + */ |
|
300 | + public function set_wp_user($wp_user_id) |
|
301 | + { |
|
302 | + $this->set('PMD_wp_user', $wp_user_id); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
307 | + * |
|
308 | + * @param string $field_name |
|
309 | + * @param mixed $field_value |
|
310 | + * @param boolean $use_default |
|
311 | + */ |
|
312 | + public function set($field_name, $field_value, $use_default = false) |
|
313 | + { |
|
314 | + if ($field_name === 'PMD_type') { |
|
315 | + // the type has probably changed, so forget about its old type object |
|
316 | + $this->_type_obj = null; |
|
317 | + } |
|
318 | + parent::set($field_name, $field_value, $use_default); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Gets admin_name |
|
324 | + * |
|
325 | + * @return string |
|
326 | + */ |
|
327 | + public function admin_name() |
|
328 | + { |
|
329 | + return $this->get('PMD_admin_name'); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * Sets admin_name |
|
335 | + * |
|
336 | + * @param string $admin_name |
|
337 | + */ |
|
338 | + public function set_admin_name($admin_name) |
|
339 | + { |
|
340 | + $this->set('PMD_admin_name', $admin_name); |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * Gets admin_desc |
|
346 | + * |
|
347 | + * @return string |
|
348 | + */ |
|
349 | + public function admin_desc() |
|
350 | + { |
|
351 | + return $this->get('PMD_admin_desc'); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Sets admin_desc |
|
357 | + * |
|
358 | + * @param string $admin_desc |
|
359 | + */ |
|
360 | + public function set_admin_desc($admin_desc) |
|
361 | + { |
|
362 | + $this->set('PMD_admin_desc', $admin_desc); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * Gets scope |
|
368 | + * |
|
369 | + * @return array |
|
370 | + */ |
|
371 | + public function scope() |
|
372 | + { |
|
373 | + return $this->get('PMD_scope'); |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Sets scope |
|
379 | + * |
|
380 | + * @param array $scope |
|
381 | + */ |
|
382 | + public function set_scope($scope) |
|
383 | + { |
|
384 | + $this->set('PMD_scope', $scope); |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * Gets the payment method type for this payment method instance |
|
390 | + * |
|
391 | + * @return EE_PMT_Base |
|
392 | + * @throws EE_Error |
|
393 | + */ |
|
394 | + public function type_obj() |
|
395 | + { |
|
396 | + if (! $this->_type_obj) { |
|
397 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
398 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
399 | + $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
400 | + if (! class_exists($class_name)) { |
|
401 | + throw new EE_Error( |
|
402 | + sprintf( |
|
403 | + esc_html__( |
|
404 | + 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
405 | + 'event_espresso' |
|
406 | + ), |
|
407 | + $class_name, |
|
408 | + '<br />', |
|
409 | + '<a href="' . admin_url('plugins.php') . '">', |
|
410 | + '</a>' |
|
411 | + ) |
|
412 | + ); |
|
413 | + } |
|
414 | + $r = new ReflectionClass($class_name); |
|
415 | + $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
416 | + } else { |
|
417 | + throw new EE_Error( |
|
418 | + sprintf( |
|
419 | + esc_html__( |
|
420 | + 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
421 | + 'event_espresso' |
|
422 | + ), |
|
423 | + $this->type(), |
|
424 | + implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
425 | + ) |
|
426 | + ); |
|
427 | + } |
|
428 | + } |
|
429 | + return $this->_type_obj; |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
435 | + * and the extra meta. Mostly used for passing off ot gateways. * |
|
436 | + * |
|
437 | + * @return array |
|
438 | + */ |
|
439 | + public function settings_array() |
|
440 | + { |
|
441 | + $fields = $this->model_field_array(); |
|
442 | + $extra_meta = $this->all_extra_meta_array(); |
|
443 | + // remove the model's prefix from the fields |
|
444 | + $combined_settings_array = array(); |
|
445 | + foreach ($fields as $key => $value) { |
|
446 | + if (strpos($key, 'PMD_') === 0) { |
|
447 | + $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
448 | + $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
449 | + } |
|
450 | + } |
|
451 | + $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
452 | + return $combined_settings_array; |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * Gets the HTML for displaying the payment method on a page. |
|
458 | + * |
|
459 | + * @param string $url |
|
460 | + * @param string $css_class |
|
461 | + * @return string of HTML for displaying the button |
|
462 | + * @throws \EE_Error |
|
463 | + */ |
|
464 | + public function button_html($url = '', $css_class = '') |
|
465 | + { |
|
466 | + $payment_occurs = $this->type_obj()->payment_occurs(); |
|
467 | + return ' |
|
468 | 468 | <div id="' |
469 | - . $this->slug() |
|
470 | - . '-payment-option-dv" class="' |
|
471 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
469 | + . $this->slug() |
|
470 | + . '-payment-option-dv" class="' |
|
471 | + . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
472 | 472 | <a id="payment-gateway-button-' . $this->slug() |
473 | - . '" class="reg-page-payment-option-lnk" rel="' |
|
474 | - . $this->slug() . '" href="' . $url . '" > |
|
473 | + . '" class="reg-page-payment-option-lnk" rel="' |
|
474 | + . $this->slug() . '" href="' . $url . '" > |
|
475 | 475 | <img src="' . $this->button_url() . '" alt="' . sprintf( |
476 | - esc_attr__('Pay using %s', 'event_espresso'), |
|
477 | - $this->get_pretty('PMD_name', 'form_input') |
|
478 | - ) . '" /> |
|
476 | + esc_attr__('Pay using %s', 'event_espresso'), |
|
477 | + $this->get_pretty('PMD_name', 'form_input') |
|
478 | + ) . '" /> |
|
479 | 479 | </a> |
480 | 480 | </div> |
481 | 481 | '; |
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * Gets all the currencies which are an option for this payment method |
|
487 | - * (as defined by the gateway and the currently active currencies) |
|
488 | - * |
|
489 | - * @return EE_Currency[] |
|
490 | - * @throws \EE_Error |
|
491 | - */ |
|
492 | - public function get_all_usable_currencies() |
|
493 | - { |
|
494 | - return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * Reports whether or not this payment method can be used for this payment method |
|
500 | - * |
|
501 | - * @param string $currency_code currency ID (code) |
|
502 | - * @return boolean |
|
503 | - * @throws \EE_Error |
|
504 | - */ |
|
505 | - public function usable_for_currency($currency_code) |
|
506 | - { |
|
507 | - foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
508 | - if ($currency_obj->ID() === $currency_code) { |
|
509 | - return true; |
|
510 | - } |
|
511 | - } |
|
512 | - return false; |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - /** |
|
517 | - * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
518 | - * |
|
519 | - * @return bool |
|
520 | - * @throws \EE_Error |
|
521 | - */ |
|
522 | - public function is_on_site() |
|
523 | - { |
|
524 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
530 | - * |
|
531 | - * @return bool |
|
532 | - * @throws \EE_Error |
|
533 | - */ |
|
534 | - public function is_off_site() |
|
535 | - { |
|
536 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * Returns TRUE if this payment method does not utilize a gateway |
|
542 | - * |
|
543 | - * @return bool |
|
544 | - * @throws \EE_Error |
|
545 | - */ |
|
546 | - public function is_off_line() |
|
547 | - { |
|
548 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
549 | - } |
|
550 | - |
|
551 | - /** |
|
552 | - * Overrides default __sleep so the object type is NOT cached. |
|
553 | - * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
554 | - * to load the required classes, and don't need them at the time of unserialization |
|
555 | - * |
|
556 | - * @return array |
|
557 | - */ |
|
558 | - public function __sleep() |
|
559 | - { |
|
560 | - $properties = get_object_vars($this); |
|
561 | - unset($properties['_type_obj']); |
|
562 | - return array_keys($properties); |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * Overrides parent to add some logging for when payment methods get deactivated |
|
568 | - * |
|
569 | - * @param array $set_cols_n_values |
|
570 | - * @return int @see EE_Base_Class::save() |
|
571 | - * @throws \EE_Error |
|
572 | - */ |
|
573 | - public function save($set_cols_n_values = array()) |
|
574 | - { |
|
575 | - $results = parent::save($set_cols_n_values); |
|
576 | - if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
577 | - /** @var CurrentPage $current_page */ |
|
578 | - $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
579 | - EE_Log::instance()->log( |
|
580 | - __FILE__, |
|
581 | - __FUNCTION__, |
|
582 | - sprintf( |
|
583 | - esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
584 | - $this->name(), |
|
585 | - serialize($this->get_original('PMD_scope')), |
|
586 | - serialize($this->get('PMD_scope')), |
|
587 | - $current_page->getPermalink() |
|
588 | - ), |
|
589 | - 'payment_method_change' |
|
590 | - ); |
|
591 | - } |
|
592 | - return $results; |
|
593 | - } |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * Gets all the currencies which are an option for this payment method |
|
487 | + * (as defined by the gateway and the currently active currencies) |
|
488 | + * |
|
489 | + * @return EE_Currency[] |
|
490 | + * @throws \EE_Error |
|
491 | + */ |
|
492 | + public function get_all_usable_currencies() |
|
493 | + { |
|
494 | + return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * Reports whether or not this payment method can be used for this payment method |
|
500 | + * |
|
501 | + * @param string $currency_code currency ID (code) |
|
502 | + * @return boolean |
|
503 | + * @throws \EE_Error |
|
504 | + */ |
|
505 | + public function usable_for_currency($currency_code) |
|
506 | + { |
|
507 | + foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
508 | + if ($currency_obj->ID() === $currency_code) { |
|
509 | + return true; |
|
510 | + } |
|
511 | + } |
|
512 | + return false; |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
518 | + * |
|
519 | + * @return bool |
|
520 | + * @throws \EE_Error |
|
521 | + */ |
|
522 | + public function is_on_site() |
|
523 | + { |
|
524 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
530 | + * |
|
531 | + * @return bool |
|
532 | + * @throws \EE_Error |
|
533 | + */ |
|
534 | + public function is_off_site() |
|
535 | + { |
|
536 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * Returns TRUE if this payment method does not utilize a gateway |
|
542 | + * |
|
543 | + * @return bool |
|
544 | + * @throws \EE_Error |
|
545 | + */ |
|
546 | + public function is_off_line() |
|
547 | + { |
|
548 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
549 | + } |
|
550 | + |
|
551 | + /** |
|
552 | + * Overrides default __sleep so the object type is NOT cached. |
|
553 | + * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
554 | + * to load the required classes, and don't need them at the time of unserialization |
|
555 | + * |
|
556 | + * @return array |
|
557 | + */ |
|
558 | + public function __sleep() |
|
559 | + { |
|
560 | + $properties = get_object_vars($this); |
|
561 | + unset($properties['_type_obj']); |
|
562 | + return array_keys($properties); |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * Overrides parent to add some logging for when payment methods get deactivated |
|
568 | + * |
|
569 | + * @param array $set_cols_n_values |
|
570 | + * @return int @see EE_Base_Class::save() |
|
571 | + * @throws \EE_Error |
|
572 | + */ |
|
573 | + public function save($set_cols_n_values = array()) |
|
574 | + { |
|
575 | + $results = parent::save($set_cols_n_values); |
|
576 | + if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
577 | + /** @var CurrentPage $current_page */ |
|
578 | + $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
579 | + EE_Log::instance()->log( |
|
580 | + __FILE__, |
|
581 | + __FUNCTION__, |
|
582 | + sprintf( |
|
583 | + esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
584 | + $this->name(), |
|
585 | + serialize($this->get_original('PMD_scope')), |
|
586 | + serialize($this->get('PMD_scope')), |
|
587 | + $current_page->getPermalink() |
|
588 | + ), |
|
589 | + 'payment_method_change' |
|
590 | + ); |
|
591 | + } |
|
592 | + return $results; |
|
593 | + } |
|
594 | 594 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | */ |
23 | 23 | public function __construct() |
24 | 24 | { |
25 | - $this->setName($this->namespace . 'TicketVisibilityEnum'); |
|
25 | + $this->setName($this->namespace.'TicketVisibilityEnum'); |
|
26 | 26 | $this->setDescription(esc_html__('Where the ticket can be viewed throughout the UI', 'event_espresso')); |
27 | 27 | parent::__construct(); |
28 | 28 | } |
@@ -17,24 +17,24 @@ |
||
17 | 17 | */ |
18 | 18 | class TicketVisibilityEnum extends EnumBase |
19 | 19 | { |
20 | - /** |
|
21 | - * TicketVisibilityEnum constructor. |
|
22 | - */ |
|
23 | - public function __construct() |
|
24 | - { |
|
25 | - $this->setName($this->namespace . 'TicketVisibilityEnum'); |
|
26 | - $this->setDescription(esc_html__('Where the ticket can be viewed throughout the UI', 'event_espresso')); |
|
27 | - parent::__construct(); |
|
28 | - } |
|
20 | + /** |
|
21 | + * TicketVisibilityEnum constructor. |
|
22 | + */ |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + $this->setName($this->namespace . 'TicketVisibilityEnum'); |
|
26 | + $this->setDescription(esc_html__('Where the ticket can be viewed throughout the UI', 'event_espresso')); |
|
27 | + parent::__construct(); |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * @return array |
|
33 | - * @throws EE_Error |
|
34 | - * @throws ReflectionException |
|
35 | - */ |
|
36 | - protected function getValues(): array |
|
37 | - { |
|
38 | - return EEM_Ticket::instance()->getTicketVisibilityValues(); |
|
39 | - } |
|
31 | + /** |
|
32 | + * @return array |
|
33 | + * @throws EE_Error |
|
34 | + * @throws ReflectionException |
|
35 | + */ |
|
36 | + protected function getValues(): array |
|
37 | + { |
|
38 | + return EEM_Ticket::instance()->getTicketVisibilityValues(); |
|
39 | + } |
|
40 | 40 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | { |
36 | 36 | $args = []; |
37 | 37 | |
38 | - if (! empty($input['datetimes'])) { |
|
38 | + if ( ! empty($input['datetimes'])) { |
|
39 | 39 | $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
40 | 40 | } |
41 | 41 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $args['TKT_description'] = wp_kses_post($input['description']); |
44 | 44 | } |
45 | 45 | |
46 | - if (! empty($input['endDate'])) { |
|
46 | + if ( ! empty($input['endDate'])) { |
|
47 | 47 | $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
48 | 48 | } |
49 | 49 | |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | $args['TKT_order'] = (int) $input['order']; |
80 | 80 | } |
81 | 81 | |
82 | - if (! empty($input['parent'])) { |
|
82 | + if ( ! empty($input['parent'])) { |
|
83 | 83 | $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
84 | - $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
84 | + $args['TKT_parent'] = ( ! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | // price can be 0 |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $args['TKT_sold'] = (int) $input['sold']; |
115 | 115 | } |
116 | 116 | |
117 | - if (! empty($input['startDate'])) { |
|
117 | + if ( ! empty($input['startDate'])) { |
|
118 | 118 | $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
119 | 119 | } |
120 | 120 | |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | $args['TKT_uses'] = (int) $input['uses']; |
123 | 123 | } |
124 | 124 | |
125 | - if (! empty($input['wpUser'])) { |
|
125 | + if ( ! empty($input['wpUser'])) { |
|
126 | 126 | $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
127 | - $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
127 | + $args['TKT_wp_user'] = ( ! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | if (array_key_exists('visibility', $input)) { |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | // @todo replace loop with single query |
160 | 160 | foreach ($datetimes as $ID) { |
161 | 161 | $parts = Relay::fromGlobalId($ID); |
162 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
162 | + if ( ! empty($parts['id']) && absint($parts['id'])) { |
|
163 | 163 | $entity->_add_relation_to( |
164 | 164 | $parts['id'], |
165 | 165 | $relationName |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | // @todo replace loop with single query |
190 | 190 | foreach ($prices as $ID) { |
191 | 191 | $parts = Relay::fromGlobalId($ID); |
192 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
192 | + if ( ! empty($parts['id']) && absint($parts['id'])) { |
|
193 | 193 | $entity->_add_relation_to( |
194 | 194 | $parts['id'], |
195 | 195 | $relationName |
@@ -22,195 +22,195 @@ |
||
22 | 22 | */ |
23 | 23 | class TicketMutation |
24 | 24 | { |
25 | - /** |
|
26 | - * Maps the GraphQL input to a format that the model functions can use |
|
27 | - * |
|
28 | - * @param array $input Data coming from the GraphQL mutation query input |
|
29 | - * @return array |
|
30 | - * @throws Exception |
|
31 | - */ |
|
32 | - public static function prepareFields(array $input): array |
|
33 | - { |
|
34 | - $args = []; |
|
35 | - |
|
36 | - if (! empty($input['datetimes'])) { |
|
37 | - $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
|
38 | - } |
|
39 | - |
|
40 | - if (isset($input['description'])) { |
|
41 | - $args['TKT_description'] = wp_kses_post($input['description']); |
|
42 | - } |
|
43 | - |
|
44 | - if (! empty($input['endDate'])) { |
|
45 | - $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
46 | - } |
|
47 | - |
|
48 | - if (array_key_exists('isDefault', $input)) { |
|
49 | - $args['TKT_is_default'] = (bool) $input['isDefault']; |
|
50 | - } |
|
51 | - |
|
52 | - if (array_key_exists('isRequired', $input)) { |
|
53 | - $args['TKT_required'] = (bool) $input['isRequired']; |
|
54 | - } |
|
55 | - |
|
56 | - if (array_key_exists('isTaxable', $input)) { |
|
57 | - $args['TKT_taxable'] = (bool) $input['isTaxable']; |
|
58 | - } |
|
59 | - |
|
60 | - if (array_key_exists('isTrashed', $input)) { |
|
61 | - $args['TKT_deleted'] = (bool) $input['isTrashed']; |
|
62 | - } |
|
63 | - |
|
64 | - if (array_key_exists('max', $input)) { |
|
65 | - $args['TKT_max'] = (int) $input['max']; |
|
66 | - } |
|
67 | - |
|
68 | - if (array_key_exists('min', $input)) { |
|
69 | - $args['TKT_min'] = (int) $input['min']; |
|
70 | - } |
|
71 | - |
|
72 | - if (isset($input['name'])) { |
|
73 | - $args['TKT_name'] = sanitize_text_field($input['name']); |
|
74 | - } |
|
75 | - |
|
76 | - if (array_key_exists('order', $input)) { |
|
77 | - $args['TKT_order'] = (int) $input['order']; |
|
78 | - } |
|
79 | - |
|
80 | - if (! empty($input['parent'])) { |
|
81 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
82 | - $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
83 | - } |
|
84 | - |
|
85 | - // price can be 0 |
|
86 | - if (array_key_exists('price', $input)) { |
|
87 | - $args['TKT_price'] = (float) $input['price']; |
|
88 | - } |
|
89 | - |
|
90 | - // prices can be an empty array when all prices are deleted |
|
91 | - if (array_key_exists('prices', $input) && is_array($input['prices'])) { |
|
92 | - $args['prices'] = array_map('sanitize_text_field', $input['prices']); |
|
93 | - } |
|
94 | - |
|
95 | - if (array_key_exists('quantity', $input)) { |
|
96 | - $args['TKT_qty'] = (int) $input['quantity']; |
|
97 | - } |
|
98 | - |
|
99 | - if (array_key_exists('reserved', $input)) { |
|
100 | - $args['TKT_reserved'] = (int) $input['reserved']; |
|
101 | - } |
|
102 | - |
|
103 | - if (array_key_exists('reverseCalculate', $input)) { |
|
104 | - $args['TKT_reverse_calculate'] = (bool) $input['reverseCalculate']; |
|
105 | - } |
|
106 | - |
|
107 | - if (array_key_exists('row', $input)) { |
|
108 | - $args['TKT_row'] = (int) $input['row']; |
|
109 | - } |
|
110 | - |
|
111 | - if (array_key_exists('sold', $input)) { |
|
112 | - $args['TKT_sold'] = (int) $input['sold']; |
|
113 | - } |
|
114 | - |
|
115 | - if (! empty($input['startDate'])) { |
|
116 | - $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
117 | - } |
|
118 | - |
|
119 | - if (array_key_exists('uses', $input)) { |
|
120 | - $args['TKT_uses'] = (int) $input['uses']; |
|
121 | - } |
|
122 | - |
|
123 | - if (! empty($input['wpUser'])) { |
|
124 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
125 | - $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
126 | - } |
|
127 | - |
|
128 | - if (array_key_exists('visibility', $input)) { |
|
129 | - $args['TKT_visibility'] = (int) $input['visibility']; |
|
130 | - } |
|
131 | - |
|
132 | - return apply_filters( |
|
133 | - 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__ticket_args', |
|
134 | - $args, |
|
135 | - $input |
|
136 | - ); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * Sets the related datetimes for the given ticket. |
|
142 | - * |
|
143 | - * @param EE_Ticket $entity The Ticket instance. |
|
144 | - * @param array $datetimes Array of datetime IDs to relate. |
|
145 | - * @throws EE_Error |
|
146 | - * @throws InvalidArgumentException |
|
147 | - * @throws InvalidDataTypeException |
|
148 | - * @throws InvalidInterfaceException |
|
149 | - * @throws ReflectionException |
|
150 | - */ |
|
151 | - public static function setRelatedDatetimes(EE_Ticket $entity, array $datetimes) |
|
152 | - { |
|
153 | - $relationName = 'Datetime'; |
|
154 | - // Remove all the existing related datetimes |
|
155 | - |
|
156 | - $entity->_remove_relations($relationName); |
|
157 | - // @todo replace loop with single query |
|
158 | - foreach ($datetimes as $ID) { |
|
159 | - $parts = Relay::fromGlobalId($ID); |
|
160 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
161 | - $entity->_add_relation_to( |
|
162 | - $parts['id'], |
|
163 | - $relationName |
|
164 | - ); |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * Sets the related prices for the given ticket. |
|
172 | - * |
|
173 | - * @param EE_Ticket $entity The Ticket instance. |
|
174 | - * @param array $prices Array of entity IDs to relate. |
|
175 | - * @throws EE_Error |
|
176 | - * @throws InvalidArgumentException |
|
177 | - * @throws InvalidDataTypeException |
|
178 | - * @throws InvalidInterfaceException |
|
179 | - * @throws ReflectionException |
|
180 | - */ |
|
181 | - public static function setRelatedPrices(EE_Ticket $entity, array $prices) |
|
182 | - { |
|
183 | - $relationName = 'Price'; |
|
184 | - // Remove all the existing related entities |
|
185 | - $entity->_remove_relations($relationName); |
|
186 | - |
|
187 | - // @todo replace loop with single query |
|
188 | - foreach ($prices as $ID) { |
|
189 | - $parts = Relay::fromGlobalId($ID); |
|
190 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
191 | - $entity->_add_relation_to( |
|
192 | - $parts['id'], |
|
193 | - $relationName |
|
194 | - ); |
|
195 | - } |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @param EE_Ticket $ticket_entity |
|
202 | - * @throws EE_Error |
|
203 | - * @throws InvalidArgumentException |
|
204 | - * @throws InvalidDataTypeException |
|
205 | - * @throws InvalidInterfaceException |
|
206 | - * @throws ReflectionException |
|
207 | - */ |
|
208 | - public static function addDefaultPrices(EE_Ticket $ticket_entity) |
|
209 | - { |
|
210 | - /** @var DefaultPrices $default_prices */ |
|
211 | - $default_prices = LoaderFactory::getLoader()->getShared( |
|
212 | - 'EventEspresso\core\domain\services\admin\entities\DefaultPrices' |
|
213 | - ); |
|
214 | - $default_prices->create($ticket_entity); |
|
215 | - } |
|
25 | + /** |
|
26 | + * Maps the GraphQL input to a format that the model functions can use |
|
27 | + * |
|
28 | + * @param array $input Data coming from the GraphQL mutation query input |
|
29 | + * @return array |
|
30 | + * @throws Exception |
|
31 | + */ |
|
32 | + public static function prepareFields(array $input): array |
|
33 | + { |
|
34 | + $args = []; |
|
35 | + |
|
36 | + if (! empty($input['datetimes'])) { |
|
37 | + $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
|
38 | + } |
|
39 | + |
|
40 | + if (isset($input['description'])) { |
|
41 | + $args['TKT_description'] = wp_kses_post($input['description']); |
|
42 | + } |
|
43 | + |
|
44 | + if (! empty($input['endDate'])) { |
|
45 | + $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
46 | + } |
|
47 | + |
|
48 | + if (array_key_exists('isDefault', $input)) { |
|
49 | + $args['TKT_is_default'] = (bool) $input['isDefault']; |
|
50 | + } |
|
51 | + |
|
52 | + if (array_key_exists('isRequired', $input)) { |
|
53 | + $args['TKT_required'] = (bool) $input['isRequired']; |
|
54 | + } |
|
55 | + |
|
56 | + if (array_key_exists('isTaxable', $input)) { |
|
57 | + $args['TKT_taxable'] = (bool) $input['isTaxable']; |
|
58 | + } |
|
59 | + |
|
60 | + if (array_key_exists('isTrashed', $input)) { |
|
61 | + $args['TKT_deleted'] = (bool) $input['isTrashed']; |
|
62 | + } |
|
63 | + |
|
64 | + if (array_key_exists('max', $input)) { |
|
65 | + $args['TKT_max'] = (int) $input['max']; |
|
66 | + } |
|
67 | + |
|
68 | + if (array_key_exists('min', $input)) { |
|
69 | + $args['TKT_min'] = (int) $input['min']; |
|
70 | + } |
|
71 | + |
|
72 | + if (isset($input['name'])) { |
|
73 | + $args['TKT_name'] = sanitize_text_field($input['name']); |
|
74 | + } |
|
75 | + |
|
76 | + if (array_key_exists('order', $input)) { |
|
77 | + $args['TKT_order'] = (int) $input['order']; |
|
78 | + } |
|
79 | + |
|
80 | + if (! empty($input['parent'])) { |
|
81 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
82 | + $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
83 | + } |
|
84 | + |
|
85 | + // price can be 0 |
|
86 | + if (array_key_exists('price', $input)) { |
|
87 | + $args['TKT_price'] = (float) $input['price']; |
|
88 | + } |
|
89 | + |
|
90 | + // prices can be an empty array when all prices are deleted |
|
91 | + if (array_key_exists('prices', $input) && is_array($input['prices'])) { |
|
92 | + $args['prices'] = array_map('sanitize_text_field', $input['prices']); |
|
93 | + } |
|
94 | + |
|
95 | + if (array_key_exists('quantity', $input)) { |
|
96 | + $args['TKT_qty'] = (int) $input['quantity']; |
|
97 | + } |
|
98 | + |
|
99 | + if (array_key_exists('reserved', $input)) { |
|
100 | + $args['TKT_reserved'] = (int) $input['reserved']; |
|
101 | + } |
|
102 | + |
|
103 | + if (array_key_exists('reverseCalculate', $input)) { |
|
104 | + $args['TKT_reverse_calculate'] = (bool) $input['reverseCalculate']; |
|
105 | + } |
|
106 | + |
|
107 | + if (array_key_exists('row', $input)) { |
|
108 | + $args['TKT_row'] = (int) $input['row']; |
|
109 | + } |
|
110 | + |
|
111 | + if (array_key_exists('sold', $input)) { |
|
112 | + $args['TKT_sold'] = (int) $input['sold']; |
|
113 | + } |
|
114 | + |
|
115 | + if (! empty($input['startDate'])) { |
|
116 | + $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
117 | + } |
|
118 | + |
|
119 | + if (array_key_exists('uses', $input)) { |
|
120 | + $args['TKT_uses'] = (int) $input['uses']; |
|
121 | + } |
|
122 | + |
|
123 | + if (! empty($input['wpUser'])) { |
|
124 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
125 | + $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
126 | + } |
|
127 | + |
|
128 | + if (array_key_exists('visibility', $input)) { |
|
129 | + $args['TKT_visibility'] = (int) $input['visibility']; |
|
130 | + } |
|
131 | + |
|
132 | + return apply_filters( |
|
133 | + 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__ticket_args', |
|
134 | + $args, |
|
135 | + $input |
|
136 | + ); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * Sets the related datetimes for the given ticket. |
|
142 | + * |
|
143 | + * @param EE_Ticket $entity The Ticket instance. |
|
144 | + * @param array $datetimes Array of datetime IDs to relate. |
|
145 | + * @throws EE_Error |
|
146 | + * @throws InvalidArgumentException |
|
147 | + * @throws InvalidDataTypeException |
|
148 | + * @throws InvalidInterfaceException |
|
149 | + * @throws ReflectionException |
|
150 | + */ |
|
151 | + public static function setRelatedDatetimes(EE_Ticket $entity, array $datetimes) |
|
152 | + { |
|
153 | + $relationName = 'Datetime'; |
|
154 | + // Remove all the existing related datetimes |
|
155 | + |
|
156 | + $entity->_remove_relations($relationName); |
|
157 | + // @todo replace loop with single query |
|
158 | + foreach ($datetimes as $ID) { |
|
159 | + $parts = Relay::fromGlobalId($ID); |
|
160 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
161 | + $entity->_add_relation_to( |
|
162 | + $parts['id'], |
|
163 | + $relationName |
|
164 | + ); |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * Sets the related prices for the given ticket. |
|
172 | + * |
|
173 | + * @param EE_Ticket $entity The Ticket instance. |
|
174 | + * @param array $prices Array of entity IDs to relate. |
|
175 | + * @throws EE_Error |
|
176 | + * @throws InvalidArgumentException |
|
177 | + * @throws InvalidDataTypeException |
|
178 | + * @throws InvalidInterfaceException |
|
179 | + * @throws ReflectionException |
|
180 | + */ |
|
181 | + public static function setRelatedPrices(EE_Ticket $entity, array $prices) |
|
182 | + { |
|
183 | + $relationName = 'Price'; |
|
184 | + // Remove all the existing related entities |
|
185 | + $entity->_remove_relations($relationName); |
|
186 | + |
|
187 | + // @todo replace loop with single query |
|
188 | + foreach ($prices as $ID) { |
|
189 | + $parts = Relay::fromGlobalId($ID); |
|
190 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
191 | + $entity->_add_relation_to( |
|
192 | + $parts['id'], |
|
193 | + $relationName |
|
194 | + ); |
|
195 | + } |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @param EE_Ticket $ticket_entity |
|
202 | + * @throws EE_Error |
|
203 | + * @throws InvalidArgumentException |
|
204 | + * @throws InvalidDataTypeException |
|
205 | + * @throws InvalidInterfaceException |
|
206 | + * @throws ReflectionException |
|
207 | + */ |
|
208 | + public static function addDefaultPrices(EE_Ticket $ticket_entity) |
|
209 | + { |
|
210 | + /** @var DefaultPrices $default_prices */ |
|
211 | + $default_prices = LoaderFactory::getLoader()->getShared( |
|
212 | + 'EventEspresso\core\domain\services\admin\entities\DefaultPrices' |
|
213 | + ); |
|
214 | + $default_prices->create($ticket_entity); |
|
215 | + } |
|
216 | 216 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
76 | 76 | ]; |
77 | 77 | $this->parseTicketVisibilityOptions(); |
78 | - $this->_fields = [ |
|
78 | + $this->_fields = [ |
|
79 | 79 | 'Ticket' => [ |
80 | 80 | 'TKT_ID' => new EE_Primary_Key_Int_Field( |
81 | 81 | 'TKT_ID', |
@@ -249,25 +249,25 @@ discard block |
||
249 | 249 | ]; |
250 | 250 | // this model is generally available for reading |
251 | 251 | $path_to_event = 'Datetime.Event'; |
252 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public( |
|
252 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public( |
|
253 | 253 | 'TKT_is_default', |
254 | 254 | $path_to_event |
255 | 255 | ); |
256 | 256 | // account for default tickets in the caps |
257 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] |
|
257 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] |
|
258 | 258 | = new EE_Restriction_Generator_Default_Protected( |
259 | 259 | 'TKT_is_default', |
260 | 260 | $path_to_event |
261 | 261 | ); |
262 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected( |
|
262 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected( |
|
263 | 263 | 'TKT_is_default', |
264 | 264 | $path_to_event |
265 | 265 | ); |
266 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected( |
|
266 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected( |
|
267 | 267 | 'TKT_is_default', |
268 | 268 | $path_to_event |
269 | 269 | ); |
270 | - $this->model_chain_to_password = $path_to_event; |
|
270 | + $this->model_chain_to_password = $path_to_event; |
|
271 | 271 | parent::__construct($timezone); |
272 | 272 | } |
273 | 273 | |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | $ticket_visibility = []; |
441 | 441 | foreach ($this->ticket_visibility as $visibility) { |
442 | 442 | if (isset($visibility['value'], $visibility['label'])) { |
443 | - $ticket_visibility[ $visibility['value'] ] = $visibility['label']; |
|
443 | + $ticket_visibility[$visibility['value']] = $visibility['label']; |
|
444 | 444 | } |
445 | 445 | } |
446 | 446 | return $ticket_visibility; |
@@ -9,482 +9,482 @@ |
||
9 | 9 | */ |
10 | 10 | class EEM_Ticket extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * the following constants define where tickets can be viewed throughout the UI |
|
14 | - * |
|
15 | - * TICKET_VISIBILITY_NONE - will not be displayed anywhere |
|
16 | - * TICKET_VISIBILITY_PUBLIC - displayed basically anywhere |
|
17 | - * TICKET_VISIBILITY_MEMBERS_ONLY - displayed to any logged in user |
|
18 | - * TICKET_VISIBILITY_ADMINS_ONLY - displayed to any logged in user that is an admin |
|
19 | - * TICKET_VISIBILITY_ADMIN_UI_ONLY - only displayed in the admin, never publicly |
|
20 | - */ |
|
21 | - public const TICKET_VISIBILITY_NONE_KEY = 'NONE'; |
|
22 | - |
|
23 | - public const TICKET_VISIBILITY_NONE_VALUE = 0; |
|
24 | - |
|
25 | - public const TICKET_VISIBILITY_PUBLIC_KEY = 'PUBLIC'; |
|
26 | - |
|
27 | - public const TICKET_VISIBILITY_PUBLIC_VALUE = 100; |
|
28 | - |
|
29 | - public const TICKET_VISIBILITY_MEMBERS_ONLY_KEY = 'MEMBERS_ONLY'; |
|
30 | - |
|
31 | - public const TICKET_VISIBILITY_MEMBERS_ONLY_VALUE = 200; |
|
32 | - |
|
33 | - public const TICKET_VISIBILITY_ADMINS_ONLY_KEY = 'ADMINS_ONLY'; |
|
34 | - |
|
35 | - public const TICKET_VISIBILITY_ADMINS_ONLY_VALUE = 300; |
|
36 | - |
|
37 | - public const TICKET_VISIBILITY_ADMIN_UI_ONLY_KEY = 'ADMIN_UI_ONLY'; |
|
38 | - |
|
39 | - public const TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE = 400; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * defines where tickets can be viewed throughout the UI |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - private $ticket_visibility; |
|
48 | - |
|
49 | - /** |
|
50 | - * private instance of the EEM_Ticket object |
|
51 | - * |
|
52 | - * @var EEM_Ticket $_instance |
|
53 | - */ |
|
54 | - protected static $_instance; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * private constructor to prevent direct creation |
|
59 | - * |
|
60 | - * @Constructor |
|
61 | - * @access private |
|
62 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
63 | - * (and any incoming timezone data that gets saved). |
|
64 | - * Note this just sends the timezone info to the date time model field objects. |
|
65 | - * Default is NULL |
|
66 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
67 | - * @throws EE_Error |
|
68 | - */ |
|
69 | - protected function __construct($timezone) |
|
70 | - { |
|
71 | - $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
72 | - $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
73 | - $this->_tables = [ |
|
74 | - 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
75 | - ]; |
|
76 | - $this->parseTicketVisibilityOptions(); |
|
77 | - $this->_fields = [ |
|
78 | - 'Ticket' => [ |
|
79 | - 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
80 | - 'TKT_ID', |
|
81 | - esc_html__('Ticket ID', 'event_espresso') |
|
82 | - ), |
|
83 | - 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
84 | - 'TTM_ID', |
|
85 | - esc_html__('Ticket Template ID', 'event_espresso'), |
|
86 | - false, |
|
87 | - 0, |
|
88 | - 'Ticket_Template' |
|
89 | - ), |
|
90 | - 'TKT_name' => new EE_Plain_Text_Field( |
|
91 | - 'TKT_name', |
|
92 | - esc_html__('Ticket Name', 'event_espresso'), |
|
93 | - false, |
|
94 | - '' |
|
95 | - ), |
|
96 | - 'TKT_description' => new EE_Post_Content_Field( |
|
97 | - 'TKT_description', |
|
98 | - esc_html__('Description of Ticket', 'event_espresso'), |
|
99 | - false, |
|
100 | - '' |
|
101 | - ), |
|
102 | - 'TKT_start_date' => new EE_Datetime_Field( |
|
103 | - 'TKT_start_date', |
|
104 | - esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
105 | - false, |
|
106 | - EE_Datetime_Field::now, |
|
107 | - $timezone |
|
108 | - ), |
|
109 | - 'TKT_end_date' => new EE_Datetime_Field( |
|
110 | - 'TKT_end_date', |
|
111 | - esc_html__('End time/date of Ticket', 'event_espresso'), |
|
112 | - false, |
|
113 | - EE_Datetime_Field::now, |
|
114 | - $timezone |
|
115 | - ), |
|
116 | - 'TKT_min' => new EE_Integer_Field( |
|
117 | - 'TKT_min', |
|
118 | - esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
119 | - false, |
|
120 | - 0 |
|
121 | - ), |
|
122 | - 'TKT_max' => new EE_Infinite_Integer_Field( |
|
123 | - 'TKT_max', |
|
124 | - esc_html__( |
|
125 | - 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
126 | - 'event_espresso' |
|
127 | - ), |
|
128 | - false, |
|
129 | - EE_INF |
|
130 | - ), |
|
131 | - 'TKT_price' => new EE_Money_Field( |
|
132 | - 'TKT_price', |
|
133 | - esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
134 | - false, |
|
135 | - 0 |
|
136 | - ), |
|
137 | - 'TKT_sold' => new EE_Integer_Field( |
|
138 | - 'TKT_sold', |
|
139 | - esc_html__('Number of this ticket sold', 'event_espresso'), |
|
140 | - false, |
|
141 | - 0 |
|
142 | - ), |
|
143 | - 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
144 | - 'TKT_qty', |
|
145 | - esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
146 | - false, |
|
147 | - EE_INF |
|
148 | - ), |
|
149 | - 'TKT_reserved' => new EE_Integer_Field( |
|
150 | - 'TKT_reserved', |
|
151 | - esc_html__( |
|
152 | - 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
153 | - 'event_espresso' |
|
154 | - ), |
|
155 | - false, |
|
156 | - 0 |
|
157 | - ), |
|
158 | - 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
159 | - 'TKT_uses', |
|
160 | - esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
161 | - false, |
|
162 | - EE_INF |
|
163 | - ), |
|
164 | - 'TKT_required' => new EE_Boolean_Field( |
|
165 | - 'TKT_required', |
|
166 | - esc_html__( |
|
167 | - 'Flag indicating whether this ticket must be purchased with a transaction', |
|
168 | - 'event_espresso' |
|
169 | - ), |
|
170 | - false, |
|
171 | - false |
|
172 | - ), |
|
173 | - 'TKT_taxable' => new EE_Boolean_Field( |
|
174 | - 'TKT_taxable', |
|
175 | - esc_html__( |
|
176 | - 'Flag indicating whether there is tax applied on this ticket', |
|
177 | - 'event_espresso' |
|
178 | - ), |
|
179 | - false, |
|
180 | - false |
|
181 | - ), |
|
182 | - 'TKT_is_default' => new EE_Boolean_Field( |
|
183 | - 'TKT_is_default', |
|
184 | - esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
185 | - false, |
|
186 | - false |
|
187 | - ), |
|
188 | - 'TKT_order' => new EE_Integer_Field( |
|
189 | - 'TKT_order', |
|
190 | - esc_html__( |
|
191 | - 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
192 | - 'event_espresso' |
|
193 | - ), |
|
194 | - false, |
|
195 | - 0 |
|
196 | - ), |
|
197 | - 'TKT_row' => new EE_Integer_Field( |
|
198 | - 'TKT_row', |
|
199 | - esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
200 | - false, |
|
201 | - 0 |
|
202 | - ), |
|
203 | - 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
204 | - 'TKT_deleted', |
|
205 | - esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
206 | - false, |
|
207 | - false |
|
208 | - ), |
|
209 | - 'TKT_wp_user' => new EE_WP_User_Field( |
|
210 | - 'TKT_wp_user', |
|
211 | - esc_html__('Ticket Creator ID', 'event_espresso'), |
|
212 | - false |
|
213 | - ), |
|
214 | - 'TKT_parent' => new EE_Integer_Field( |
|
215 | - 'TKT_parent', |
|
216 | - esc_html__( |
|
217 | - 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - true, |
|
221 | - 0 |
|
222 | - ), |
|
223 | - 'TKT_reverse_calculate' => new EE_Boolean_Field( |
|
224 | - 'TKT_reverse_calculate', |
|
225 | - esc_html__( |
|
226 | - 'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.', |
|
227 | - 'event_espresso' |
|
228 | - ), |
|
229 | - false, |
|
230 | - false |
|
231 | - ), |
|
232 | - 'TKT_visibility' => new EE_Enum_Integer_Field( |
|
233 | - 'TKT_visibility', |
|
234 | - esc_html__('Defines where the ticket can be viewed throughout the UI.', 'event_espresso'), |
|
235 | - false, |
|
236 | - EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE, |
|
237 | - $this->getTicketVisibilityEnumOptions() |
|
238 | - ), |
|
239 | - ], |
|
240 | - ]; |
|
241 | - $this->_model_relations = [ |
|
242 | - 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
243 | - 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
244 | - 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
245 | - 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
246 | - 'Registration' => new EE_Has_Many_Relation(), |
|
247 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
248 | - ]; |
|
249 | - // this model is generally available for reading |
|
250 | - $path_to_event = 'Datetime.Event'; |
|
251 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public( |
|
252 | - 'TKT_is_default', |
|
253 | - $path_to_event |
|
254 | - ); |
|
255 | - // account for default tickets in the caps |
|
256 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] |
|
257 | - = new EE_Restriction_Generator_Default_Protected( |
|
258 | - 'TKT_is_default', |
|
259 | - $path_to_event |
|
260 | - ); |
|
261 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected( |
|
262 | - 'TKT_is_default', |
|
263 | - $path_to_event |
|
264 | - ); |
|
265 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected( |
|
266 | - 'TKT_is_default', |
|
267 | - $path_to_event |
|
268 | - ); |
|
269 | - $this->model_chain_to_password = $path_to_event; |
|
270 | - parent::__construct($timezone); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * This returns all tickets that are defaults from the db |
|
276 | - * |
|
277 | - * @return EE_Ticket[] |
|
278 | - * @throws EE_Error |
|
279 | - * @throws ReflectionException |
|
280 | - */ |
|
281 | - public function get_all_default_tickets(): array |
|
282 | - { |
|
283 | - /** @type EE_Ticket[] $tickets */ |
|
284 | - $tickets = $this->get_all( |
|
285 | - [ |
|
286 | - [ |
|
287 | - 'TKT_is_default' => 1, |
|
288 | - 'TKT_visibility' => ['>', EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE], |
|
289 | - ], |
|
290 | - 'order_by' => ['TKT_ID' => 'ASC'], |
|
291 | - ] |
|
292 | - ); |
|
293 | - // we need to set the start date and end date to today's date and the start of the default dtt |
|
294 | - return $this->_set_default_dates($tickets); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * sets up relevant start and end date for EE_Ticket (s) |
|
300 | - * |
|
301 | - * @param EE_Ticket[] $tickets |
|
302 | - * @return EE_Ticket[] |
|
303 | - * @throws EE_Error |
|
304 | - * @throws ReflectionException |
|
305 | - */ |
|
306 | - private function _set_default_dates(array $tickets): array |
|
307 | - { |
|
308 | - foreach ($tickets as $ticket) { |
|
309 | - $ticket->set( |
|
310 | - 'TKT_start_date', |
|
311 | - (int) $this->current_time_for_query('TKT_start_date', true) |
|
312 | - ); |
|
313 | - $ticket->set( |
|
314 | - 'TKT_end_date', |
|
315 | - (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
316 | - ); |
|
317 | - $ticket->set_end_time( |
|
318 | - $this->convert_datetime_for_query( |
|
319 | - 'TKT_end_date', |
|
320 | - '11:59 pm', |
|
321 | - 'g:i a', |
|
322 | - $this->_timezone |
|
323 | - ) |
|
324 | - ); |
|
325 | - } |
|
326 | - return $tickets; |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * Gets the total number of tickets available at a particular datetime (does |
|
332 | - * NOT take int account the datetime's spaces available) |
|
333 | - * |
|
334 | - * @param int $DTT_ID |
|
335 | - * @param array $query_params |
|
336 | - * @return int |
|
337 | - * @throws EE_Error |
|
338 | - * @throws ReflectionException |
|
339 | - */ |
|
340 | - public function sum_tickets_currently_available_at_datetime(int $DTT_ID, array $query_params = []): int |
|
341 | - { |
|
342 | - $query_params += [['TKT_visibility' => ['>', EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE]]]; |
|
343 | - return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
349 | - * |
|
350 | - * @param EE_Ticket[] $tickets |
|
351 | - * @return void |
|
352 | - * @throws EE_Error |
|
353 | - * @throws ReflectionException |
|
354 | - */ |
|
355 | - public function update_tickets_sold(array $tickets) |
|
356 | - { |
|
357 | - foreach ($tickets as $ticket) { |
|
358 | - $ticket->update_tickets_sold(); |
|
359 | - } |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
365 | - * |
|
366 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
367 | - * @throws EE_Error |
|
368 | - */ |
|
369 | - public function get_tickets_with_reservations() |
|
370 | - { |
|
371 | - return $this->get_all( |
|
372 | - [ |
|
373 | - [ |
|
374 | - 'TKT_reserved' => ['>', 0], |
|
375 | - 'TKT_visibility' => ['>', EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE], |
|
376 | - ], |
|
377 | - ] |
|
378 | - ); |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
384 | - * |
|
385 | - * @param array $ticket_IDs |
|
386 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
387 | - * @throws EE_Error |
|
388 | - */ |
|
389 | - public function get_tickets_with_IDs(array $ticket_IDs) |
|
390 | - { |
|
391 | - return $this->get_all( |
|
392 | - [ |
|
393 | - [ |
|
394 | - 'TKT_ID' => ['IN', $ticket_IDs], |
|
395 | - ], |
|
396 | - ] |
|
397 | - ); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * @return void |
|
403 | - */ |
|
404 | - private function parseTicketVisibilityOptions() |
|
405 | - { |
|
406 | - $this->ticket_visibility = (array) apply_filters( |
|
407 | - 'FHEE__EEM_Ticket__construct__ticket_visibility', |
|
408 | - [ |
|
409 | - EEM_Ticket::TICKET_VISIBILITY_PUBLIC_KEY => [ |
|
410 | - 'label' => esc_html__('Public', 'event_espresso'), |
|
411 | - 'value' => EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE, |
|
412 | - ], |
|
413 | - EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_KEY => [ |
|
414 | - 'label' => esc_html__('Members only', 'event_espresso'), |
|
415 | - 'value' => EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE, |
|
416 | - ], |
|
417 | - EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_KEY => [ |
|
418 | - 'label' => esc_html__('Admins only', 'event_espresso'), |
|
419 | - 'value' => EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE, |
|
420 | - ], |
|
421 | - EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_KEY => [ |
|
422 | - 'label' => esc_html__('Admin UI only', 'event_espresso'), |
|
423 | - 'value' => EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE, |
|
424 | - ], |
|
425 | - EEM_Ticket::TICKET_VISIBILITY_NONE_KEY => [ |
|
426 | - 'label' => esc_html__('None', 'event_espresso'), |
|
427 | - 'value' => EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE, |
|
428 | - ], |
|
429 | - ] |
|
430 | - ); |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * @return array |
|
436 | - */ |
|
437 | - public function getTicketVisibilityEnumOptions(): array |
|
438 | - { |
|
439 | - $ticket_visibility = []; |
|
440 | - foreach ($this->ticket_visibility as $visibility) { |
|
441 | - if (isset($visibility['value'], $visibility['label'])) { |
|
442 | - $ticket_visibility[ $visibility['value'] ] = $visibility['label']; |
|
443 | - } |
|
444 | - } |
|
445 | - return $ticket_visibility; |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * @return array |
|
451 | - */ |
|
452 | - public function getTicketVisibilityValues(): array |
|
453 | - { |
|
454 | - // copy ticket_visibility array |
|
455 | - $ticket_visibility_options = $this->ticket_visibility; |
|
456 | - foreach ($ticket_visibility_options as $ticket_visibility_option) { |
|
457 | - // remove labels because we only want the values |
|
458 | - unset($ticket_visibility_option['label']); |
|
459 | - } |
|
460 | - return $ticket_visibility_options; |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * @return array |
|
466 | - */ |
|
467 | - public function getTicketVisibilityLabels(): array |
|
468 | - { |
|
469 | - $ticket_visibility_options = []; |
|
470 | - foreach ($this->ticket_visibility as $key => $ticket_visibility_option) { |
|
471 | - if (isset($ticket_visibility_option['label'])) { |
|
472 | - // change because we only want the labels tied to the keys |
|
473 | - $ticket_visibility_options[] = [ |
|
474 | - 'value' => $key, |
|
475 | - 'label' => $ticket_visibility_option['label'] |
|
476 | - ]; |
|
477 | - } |
|
478 | - } |
|
479 | - return $ticket_visibility_options; |
|
480 | - } |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * @return array |
|
485 | - */ |
|
486 | - public function ticketVisibilityOptions(): array |
|
487 | - { |
|
488 | - return $this->ticket_visibility; |
|
489 | - } |
|
12 | + /** |
|
13 | + * the following constants define where tickets can be viewed throughout the UI |
|
14 | + * |
|
15 | + * TICKET_VISIBILITY_NONE - will not be displayed anywhere |
|
16 | + * TICKET_VISIBILITY_PUBLIC - displayed basically anywhere |
|
17 | + * TICKET_VISIBILITY_MEMBERS_ONLY - displayed to any logged in user |
|
18 | + * TICKET_VISIBILITY_ADMINS_ONLY - displayed to any logged in user that is an admin |
|
19 | + * TICKET_VISIBILITY_ADMIN_UI_ONLY - only displayed in the admin, never publicly |
|
20 | + */ |
|
21 | + public const TICKET_VISIBILITY_NONE_KEY = 'NONE'; |
|
22 | + |
|
23 | + public const TICKET_VISIBILITY_NONE_VALUE = 0; |
|
24 | + |
|
25 | + public const TICKET_VISIBILITY_PUBLIC_KEY = 'PUBLIC'; |
|
26 | + |
|
27 | + public const TICKET_VISIBILITY_PUBLIC_VALUE = 100; |
|
28 | + |
|
29 | + public const TICKET_VISIBILITY_MEMBERS_ONLY_KEY = 'MEMBERS_ONLY'; |
|
30 | + |
|
31 | + public const TICKET_VISIBILITY_MEMBERS_ONLY_VALUE = 200; |
|
32 | + |
|
33 | + public const TICKET_VISIBILITY_ADMINS_ONLY_KEY = 'ADMINS_ONLY'; |
|
34 | + |
|
35 | + public const TICKET_VISIBILITY_ADMINS_ONLY_VALUE = 300; |
|
36 | + |
|
37 | + public const TICKET_VISIBILITY_ADMIN_UI_ONLY_KEY = 'ADMIN_UI_ONLY'; |
|
38 | + |
|
39 | + public const TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE = 400; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * defines where tickets can be viewed throughout the UI |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + private $ticket_visibility; |
|
48 | + |
|
49 | + /** |
|
50 | + * private instance of the EEM_Ticket object |
|
51 | + * |
|
52 | + * @var EEM_Ticket $_instance |
|
53 | + */ |
|
54 | + protected static $_instance; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * private constructor to prevent direct creation |
|
59 | + * |
|
60 | + * @Constructor |
|
61 | + * @access private |
|
62 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
63 | + * (and any incoming timezone data that gets saved). |
|
64 | + * Note this just sends the timezone info to the date time model field objects. |
|
65 | + * Default is NULL |
|
66 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
67 | + * @throws EE_Error |
|
68 | + */ |
|
69 | + protected function __construct($timezone) |
|
70 | + { |
|
71 | + $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
72 | + $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
73 | + $this->_tables = [ |
|
74 | + 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
75 | + ]; |
|
76 | + $this->parseTicketVisibilityOptions(); |
|
77 | + $this->_fields = [ |
|
78 | + 'Ticket' => [ |
|
79 | + 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
80 | + 'TKT_ID', |
|
81 | + esc_html__('Ticket ID', 'event_espresso') |
|
82 | + ), |
|
83 | + 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
84 | + 'TTM_ID', |
|
85 | + esc_html__('Ticket Template ID', 'event_espresso'), |
|
86 | + false, |
|
87 | + 0, |
|
88 | + 'Ticket_Template' |
|
89 | + ), |
|
90 | + 'TKT_name' => new EE_Plain_Text_Field( |
|
91 | + 'TKT_name', |
|
92 | + esc_html__('Ticket Name', 'event_espresso'), |
|
93 | + false, |
|
94 | + '' |
|
95 | + ), |
|
96 | + 'TKT_description' => new EE_Post_Content_Field( |
|
97 | + 'TKT_description', |
|
98 | + esc_html__('Description of Ticket', 'event_espresso'), |
|
99 | + false, |
|
100 | + '' |
|
101 | + ), |
|
102 | + 'TKT_start_date' => new EE_Datetime_Field( |
|
103 | + 'TKT_start_date', |
|
104 | + esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
105 | + false, |
|
106 | + EE_Datetime_Field::now, |
|
107 | + $timezone |
|
108 | + ), |
|
109 | + 'TKT_end_date' => new EE_Datetime_Field( |
|
110 | + 'TKT_end_date', |
|
111 | + esc_html__('End time/date of Ticket', 'event_espresso'), |
|
112 | + false, |
|
113 | + EE_Datetime_Field::now, |
|
114 | + $timezone |
|
115 | + ), |
|
116 | + 'TKT_min' => new EE_Integer_Field( |
|
117 | + 'TKT_min', |
|
118 | + esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
119 | + false, |
|
120 | + 0 |
|
121 | + ), |
|
122 | + 'TKT_max' => new EE_Infinite_Integer_Field( |
|
123 | + 'TKT_max', |
|
124 | + esc_html__( |
|
125 | + 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
126 | + 'event_espresso' |
|
127 | + ), |
|
128 | + false, |
|
129 | + EE_INF |
|
130 | + ), |
|
131 | + 'TKT_price' => new EE_Money_Field( |
|
132 | + 'TKT_price', |
|
133 | + esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
134 | + false, |
|
135 | + 0 |
|
136 | + ), |
|
137 | + 'TKT_sold' => new EE_Integer_Field( |
|
138 | + 'TKT_sold', |
|
139 | + esc_html__('Number of this ticket sold', 'event_espresso'), |
|
140 | + false, |
|
141 | + 0 |
|
142 | + ), |
|
143 | + 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
144 | + 'TKT_qty', |
|
145 | + esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
146 | + false, |
|
147 | + EE_INF |
|
148 | + ), |
|
149 | + 'TKT_reserved' => new EE_Integer_Field( |
|
150 | + 'TKT_reserved', |
|
151 | + esc_html__( |
|
152 | + 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
153 | + 'event_espresso' |
|
154 | + ), |
|
155 | + false, |
|
156 | + 0 |
|
157 | + ), |
|
158 | + 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
159 | + 'TKT_uses', |
|
160 | + esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
161 | + false, |
|
162 | + EE_INF |
|
163 | + ), |
|
164 | + 'TKT_required' => new EE_Boolean_Field( |
|
165 | + 'TKT_required', |
|
166 | + esc_html__( |
|
167 | + 'Flag indicating whether this ticket must be purchased with a transaction', |
|
168 | + 'event_espresso' |
|
169 | + ), |
|
170 | + false, |
|
171 | + false |
|
172 | + ), |
|
173 | + 'TKT_taxable' => new EE_Boolean_Field( |
|
174 | + 'TKT_taxable', |
|
175 | + esc_html__( |
|
176 | + 'Flag indicating whether there is tax applied on this ticket', |
|
177 | + 'event_espresso' |
|
178 | + ), |
|
179 | + false, |
|
180 | + false |
|
181 | + ), |
|
182 | + 'TKT_is_default' => new EE_Boolean_Field( |
|
183 | + 'TKT_is_default', |
|
184 | + esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
185 | + false, |
|
186 | + false |
|
187 | + ), |
|
188 | + 'TKT_order' => new EE_Integer_Field( |
|
189 | + 'TKT_order', |
|
190 | + esc_html__( |
|
191 | + 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
192 | + 'event_espresso' |
|
193 | + ), |
|
194 | + false, |
|
195 | + 0 |
|
196 | + ), |
|
197 | + 'TKT_row' => new EE_Integer_Field( |
|
198 | + 'TKT_row', |
|
199 | + esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
200 | + false, |
|
201 | + 0 |
|
202 | + ), |
|
203 | + 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
204 | + 'TKT_deleted', |
|
205 | + esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
206 | + false, |
|
207 | + false |
|
208 | + ), |
|
209 | + 'TKT_wp_user' => new EE_WP_User_Field( |
|
210 | + 'TKT_wp_user', |
|
211 | + esc_html__('Ticket Creator ID', 'event_espresso'), |
|
212 | + false |
|
213 | + ), |
|
214 | + 'TKT_parent' => new EE_Integer_Field( |
|
215 | + 'TKT_parent', |
|
216 | + esc_html__( |
|
217 | + 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + true, |
|
221 | + 0 |
|
222 | + ), |
|
223 | + 'TKT_reverse_calculate' => new EE_Boolean_Field( |
|
224 | + 'TKT_reverse_calculate', |
|
225 | + esc_html__( |
|
226 | + 'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.', |
|
227 | + 'event_espresso' |
|
228 | + ), |
|
229 | + false, |
|
230 | + false |
|
231 | + ), |
|
232 | + 'TKT_visibility' => new EE_Enum_Integer_Field( |
|
233 | + 'TKT_visibility', |
|
234 | + esc_html__('Defines where the ticket can be viewed throughout the UI.', 'event_espresso'), |
|
235 | + false, |
|
236 | + EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE, |
|
237 | + $this->getTicketVisibilityEnumOptions() |
|
238 | + ), |
|
239 | + ], |
|
240 | + ]; |
|
241 | + $this->_model_relations = [ |
|
242 | + 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
243 | + 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
244 | + 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
245 | + 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
246 | + 'Registration' => new EE_Has_Many_Relation(), |
|
247 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
248 | + ]; |
|
249 | + // this model is generally available for reading |
|
250 | + $path_to_event = 'Datetime.Event'; |
|
251 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public( |
|
252 | + 'TKT_is_default', |
|
253 | + $path_to_event |
|
254 | + ); |
|
255 | + // account for default tickets in the caps |
|
256 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] |
|
257 | + = new EE_Restriction_Generator_Default_Protected( |
|
258 | + 'TKT_is_default', |
|
259 | + $path_to_event |
|
260 | + ); |
|
261 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected( |
|
262 | + 'TKT_is_default', |
|
263 | + $path_to_event |
|
264 | + ); |
|
265 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected( |
|
266 | + 'TKT_is_default', |
|
267 | + $path_to_event |
|
268 | + ); |
|
269 | + $this->model_chain_to_password = $path_to_event; |
|
270 | + parent::__construct($timezone); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * This returns all tickets that are defaults from the db |
|
276 | + * |
|
277 | + * @return EE_Ticket[] |
|
278 | + * @throws EE_Error |
|
279 | + * @throws ReflectionException |
|
280 | + */ |
|
281 | + public function get_all_default_tickets(): array |
|
282 | + { |
|
283 | + /** @type EE_Ticket[] $tickets */ |
|
284 | + $tickets = $this->get_all( |
|
285 | + [ |
|
286 | + [ |
|
287 | + 'TKT_is_default' => 1, |
|
288 | + 'TKT_visibility' => ['>', EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE], |
|
289 | + ], |
|
290 | + 'order_by' => ['TKT_ID' => 'ASC'], |
|
291 | + ] |
|
292 | + ); |
|
293 | + // we need to set the start date and end date to today's date and the start of the default dtt |
|
294 | + return $this->_set_default_dates($tickets); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * sets up relevant start and end date for EE_Ticket (s) |
|
300 | + * |
|
301 | + * @param EE_Ticket[] $tickets |
|
302 | + * @return EE_Ticket[] |
|
303 | + * @throws EE_Error |
|
304 | + * @throws ReflectionException |
|
305 | + */ |
|
306 | + private function _set_default_dates(array $tickets): array |
|
307 | + { |
|
308 | + foreach ($tickets as $ticket) { |
|
309 | + $ticket->set( |
|
310 | + 'TKT_start_date', |
|
311 | + (int) $this->current_time_for_query('TKT_start_date', true) |
|
312 | + ); |
|
313 | + $ticket->set( |
|
314 | + 'TKT_end_date', |
|
315 | + (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
316 | + ); |
|
317 | + $ticket->set_end_time( |
|
318 | + $this->convert_datetime_for_query( |
|
319 | + 'TKT_end_date', |
|
320 | + '11:59 pm', |
|
321 | + 'g:i a', |
|
322 | + $this->_timezone |
|
323 | + ) |
|
324 | + ); |
|
325 | + } |
|
326 | + return $tickets; |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * Gets the total number of tickets available at a particular datetime (does |
|
332 | + * NOT take int account the datetime's spaces available) |
|
333 | + * |
|
334 | + * @param int $DTT_ID |
|
335 | + * @param array $query_params |
|
336 | + * @return int |
|
337 | + * @throws EE_Error |
|
338 | + * @throws ReflectionException |
|
339 | + */ |
|
340 | + public function sum_tickets_currently_available_at_datetime(int $DTT_ID, array $query_params = []): int |
|
341 | + { |
|
342 | + $query_params += [['TKT_visibility' => ['>', EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE]]]; |
|
343 | + return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
349 | + * |
|
350 | + * @param EE_Ticket[] $tickets |
|
351 | + * @return void |
|
352 | + * @throws EE_Error |
|
353 | + * @throws ReflectionException |
|
354 | + */ |
|
355 | + public function update_tickets_sold(array $tickets) |
|
356 | + { |
|
357 | + foreach ($tickets as $ticket) { |
|
358 | + $ticket->update_tickets_sold(); |
|
359 | + } |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
365 | + * |
|
366 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
367 | + * @throws EE_Error |
|
368 | + */ |
|
369 | + public function get_tickets_with_reservations() |
|
370 | + { |
|
371 | + return $this->get_all( |
|
372 | + [ |
|
373 | + [ |
|
374 | + 'TKT_reserved' => ['>', 0], |
|
375 | + 'TKT_visibility' => ['>', EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE], |
|
376 | + ], |
|
377 | + ] |
|
378 | + ); |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
384 | + * |
|
385 | + * @param array $ticket_IDs |
|
386 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
387 | + * @throws EE_Error |
|
388 | + */ |
|
389 | + public function get_tickets_with_IDs(array $ticket_IDs) |
|
390 | + { |
|
391 | + return $this->get_all( |
|
392 | + [ |
|
393 | + [ |
|
394 | + 'TKT_ID' => ['IN', $ticket_IDs], |
|
395 | + ], |
|
396 | + ] |
|
397 | + ); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * @return void |
|
403 | + */ |
|
404 | + private function parseTicketVisibilityOptions() |
|
405 | + { |
|
406 | + $this->ticket_visibility = (array) apply_filters( |
|
407 | + 'FHEE__EEM_Ticket__construct__ticket_visibility', |
|
408 | + [ |
|
409 | + EEM_Ticket::TICKET_VISIBILITY_PUBLIC_KEY => [ |
|
410 | + 'label' => esc_html__('Public', 'event_espresso'), |
|
411 | + 'value' => EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE, |
|
412 | + ], |
|
413 | + EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_KEY => [ |
|
414 | + 'label' => esc_html__('Members only', 'event_espresso'), |
|
415 | + 'value' => EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE, |
|
416 | + ], |
|
417 | + EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_KEY => [ |
|
418 | + 'label' => esc_html__('Admins only', 'event_espresso'), |
|
419 | + 'value' => EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE, |
|
420 | + ], |
|
421 | + EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_KEY => [ |
|
422 | + 'label' => esc_html__('Admin UI only', 'event_espresso'), |
|
423 | + 'value' => EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE, |
|
424 | + ], |
|
425 | + EEM_Ticket::TICKET_VISIBILITY_NONE_KEY => [ |
|
426 | + 'label' => esc_html__('None', 'event_espresso'), |
|
427 | + 'value' => EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE, |
|
428 | + ], |
|
429 | + ] |
|
430 | + ); |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * @return array |
|
436 | + */ |
|
437 | + public function getTicketVisibilityEnumOptions(): array |
|
438 | + { |
|
439 | + $ticket_visibility = []; |
|
440 | + foreach ($this->ticket_visibility as $visibility) { |
|
441 | + if (isset($visibility['value'], $visibility['label'])) { |
|
442 | + $ticket_visibility[ $visibility['value'] ] = $visibility['label']; |
|
443 | + } |
|
444 | + } |
|
445 | + return $ticket_visibility; |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * @return array |
|
451 | + */ |
|
452 | + public function getTicketVisibilityValues(): array |
|
453 | + { |
|
454 | + // copy ticket_visibility array |
|
455 | + $ticket_visibility_options = $this->ticket_visibility; |
|
456 | + foreach ($ticket_visibility_options as $ticket_visibility_option) { |
|
457 | + // remove labels because we only want the values |
|
458 | + unset($ticket_visibility_option['label']); |
|
459 | + } |
|
460 | + return $ticket_visibility_options; |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * @return array |
|
466 | + */ |
|
467 | + public function getTicketVisibilityLabels(): array |
|
468 | + { |
|
469 | + $ticket_visibility_options = []; |
|
470 | + foreach ($this->ticket_visibility as $key => $ticket_visibility_option) { |
|
471 | + if (isset($ticket_visibility_option['label'])) { |
|
472 | + // change because we only want the labels tied to the keys |
|
473 | + $ticket_visibility_options[] = [ |
|
474 | + 'value' => $key, |
|
475 | + 'label' => $ticket_visibility_option['label'] |
|
476 | + ]; |
|
477 | + } |
|
478 | + } |
|
479 | + return $ticket_visibility_options; |
|
480 | + } |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * @return array |
|
485 | + */ |
|
486 | + public function ticketVisibilityOptions(): array |
|
487 | + { |
|
488 | + return $this->ticket_visibility; |
|
489 | + } |
|
490 | 490 | } |
@@ -50,7 +50,7 @@ |
||
50 | 50 | |
51 | 51 | public function setCurrentUser(): void |
52 | 52 | { |
53 | - if (! $this->current_user instanceof WP_User) { |
|
53 | + if ( ! $this->current_user instanceof WP_User) { |
|
54 | 54 | $this->current_user = wp_get_current_user(); |
55 | 55 | $event_manager_roles = array_keys($this->event_managers->roles()); |
56 | 56 | $current_user_roles = $this->current_user->roles; |
@@ -13,78 +13,78 @@ |
||
13 | 13 | */ |
14 | 14 | class CurrentUser |
15 | 15 | { |
16 | - /** |
|
17 | - * @var WP_User |
|
18 | - */ |
|
19 | - private $current_user; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var boolean |
|
23 | - */ |
|
24 | - private $is_event_manager = false; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var boolean |
|
28 | - */ |
|
29 | - private $is_logged_in = false; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EventManagers |
|
34 | - */ |
|
35 | - private $event_managers; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * CurrentUser constructor. |
|
40 | - * |
|
41 | - * @param EventManagers $event_managers |
|
42 | - */ |
|
43 | - public function __construct(EventManagers $event_managers) |
|
44 | - { |
|
45 | - $this->event_managers = $event_managers; |
|
46 | - $this->setCurrentUser(); |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - public function setCurrentUser(): void |
|
51 | - { |
|
52 | - if (! $this->current_user instanceof WP_User) { |
|
53 | - $this->current_user = wp_get_current_user(); |
|
54 | - $event_manager_roles = array_keys($this->event_managers->roles()); |
|
55 | - $current_user_roles = $this->current_user->roles; |
|
56 | - $this->is_event_manager = ! empty(array_intersect($event_manager_roles, $current_user_roles)); |
|
57 | - $this->is_logged_in = $this->current_user->exists(); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return WP_User |
|
64 | - */ |
|
65 | - public function currentUser(): ?WP_User |
|
66 | - { |
|
67 | - $this->setCurrentUser(); |
|
68 | - return $this->current_user; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @return bool |
|
74 | - */ |
|
75 | - public function isEventManager(): bool |
|
76 | - { |
|
77 | - $this->setCurrentUser(); |
|
78 | - return $this->is_event_manager; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function isLoggedIn(): bool |
|
86 | - { |
|
87 | - $this->setCurrentUser(); |
|
88 | - return $this->is_logged_in; |
|
89 | - } |
|
16 | + /** |
|
17 | + * @var WP_User |
|
18 | + */ |
|
19 | + private $current_user; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var boolean |
|
23 | + */ |
|
24 | + private $is_event_manager = false; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var boolean |
|
28 | + */ |
|
29 | + private $is_logged_in = false; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EventManagers |
|
34 | + */ |
|
35 | + private $event_managers; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * CurrentUser constructor. |
|
40 | + * |
|
41 | + * @param EventManagers $event_managers |
|
42 | + */ |
|
43 | + public function __construct(EventManagers $event_managers) |
|
44 | + { |
|
45 | + $this->event_managers = $event_managers; |
|
46 | + $this->setCurrentUser(); |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + public function setCurrentUser(): void |
|
51 | + { |
|
52 | + if (! $this->current_user instanceof WP_User) { |
|
53 | + $this->current_user = wp_get_current_user(); |
|
54 | + $event_manager_roles = array_keys($this->event_managers->roles()); |
|
55 | + $current_user_roles = $this->current_user->roles; |
|
56 | + $this->is_event_manager = ! empty(array_intersect($event_manager_roles, $current_user_roles)); |
|
57 | + $this->is_logged_in = $this->current_user->exists(); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return WP_User |
|
64 | + */ |
|
65 | + public function currentUser(): ?WP_User |
|
66 | + { |
|
67 | + $this->setCurrentUser(); |
|
68 | + return $this->current_user; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @return bool |
|
74 | + */ |
|
75 | + public function isEventManager(): bool |
|
76 | + { |
|
77 | + $this->setCurrentUser(); |
|
78 | + return $this->is_event_manager; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function isLoggedIn(): bool |
|
86 | + { |
|
87 | + $this->setCurrentUser(); |
|
88 | + return $this->is_logged_in; |
|
89 | + } |
|
90 | 90 | } |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | if ($role instanceof WP_Role) { |
72 | 72 | foreach ($this->capabilities as $capability) { |
73 | 73 | // we're using the role name as the array index to prevent duplicates |
74 | - if (! isset($event_manager_roles[ $role->name ]) && $role->has_cap($capability)) { |
|
75 | - $event_manager_roles[ $role->name ] = $role; |
|
74 | + if ( ! isset($event_manager_roles[$role->name]) && $role->has_cap($capability)) { |
|
75 | + $event_manager_roles[$role->name] = $role; |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $this->user_list = []; |
90 | 90 | } |
91 | 91 | // begin to build our query |
92 | - $SQL = "SELECT u1.ID, u1.display_name FROM $wpdb->users AS u1 " |
|
92 | + $SQL = "SELECT u1.ID, u1.display_name FROM $wpdb->users AS u1 " |
|
93 | 93 | . "INNER JOIN $wpdb->usermeta AS u2 ON u1.ID = u2.user_id " |
94 | 94 | . "AND u2.meta_key='{$wpdb->prefix}capabilities' " |
95 | 95 | . 'WHERE'; |
@@ -97,18 +97,18 @@ discard block |
||
97 | 97 | foreach ($this->roles as $role) { |
98 | 98 | // for each role, add a WHERE clause |
99 | 99 | if ($role instanceof WP_Role) { |
100 | - $SQL .= $operator . ' u2.meta_value LIKE \'%"' . $role->name . '"%\' '; |
|
100 | + $SQL .= $operator.' u2.meta_value LIKE \'%"'.$role->name.'"%\' '; |
|
101 | 101 | // subsequent clauses will use OR so that any role is accepted |
102 | 102 | $operator = 'OR'; |
103 | 103 | } |
104 | 104 | } |
105 | 105 | foreach ($this->capabilities as $capability) { |
106 | 106 | // for each capability, add a WHERE clause |
107 | - $SQL .= $operator . ' u2.meta_value LIKE \'%"' . $capability . '";b:1;%\' '; |
|
107 | + $SQL .= $operator.' u2.meta_value LIKE \'%"'.$capability.'";b:1;%\' '; |
|
108 | 108 | // subsequent clauses will use OR so that any role is accepted |
109 | 109 | $operator = 'OR'; |
110 | 110 | } |
111 | - $SQL .= 'ORDER BY user_id ASC'; |
|
111 | + $SQL .= 'ORDER BY user_id ASC'; |
|
112 | 112 | $users = $wpdb->get_results($SQL); |
113 | 113 | |
114 | 114 | $this->user_list = ! empty($users) ? $users : []; |
@@ -15,135 +15,135 @@ |
||
15 | 15 | */ |
16 | 16 | class EventManagers |
17 | 17 | { |
18 | - /** |
|
19 | - * @var string[] |
|
20 | - */ |
|
21 | - private $capabilities = []; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var WP_Role[] |
|
25 | - */ |
|
26 | - private $roles = []; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - private $user_list = []; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var WP_Role[] |
|
35 | - */ |
|
36 | - private $wp_roles; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * EventManagerRoles constructor. |
|
41 | - */ |
|
42 | - public function __construct() |
|
43 | - { |
|
44 | - global $wp_roles; |
|
45 | - // first let's grab ALL of the WP_Role objects |
|
46 | - $this->wp_roles = $wp_roles->role_objects; |
|
47 | - $this->setCapabilities(); |
|
48 | - $this->buildRolesArray(); |
|
49 | - $this->buildUserList(); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - private function setCapabilities(): void |
|
54 | - { |
|
55 | - // filter a list of capabilities we want to use to define an event manager |
|
56 | - $capabilities = (array) apply_filters( |
|
57 | - 'FHEE__EventEspresso_core_domain_services_capabilities_EventManagers__setCapabilities', |
|
58 | - ['ee_edit_events', 'ee_edit_event'], |
|
59 | - $this->wp_roles |
|
60 | - ); |
|
61 | - $this->capabilities = array_map('sanitize_text_field', $capabilities); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - private function buildRolesArray(): void |
|
66 | - { |
|
67 | - // we'll use this array to capture all of the WP_Role objects that have any of the caps we are targeting |
|
68 | - $event_manager_roles = []; |
|
69 | - foreach ($this->wp_roles as $role) { |
|
70 | - if ($role instanceof WP_Role) { |
|
71 | - foreach ($this->capabilities as $capability) { |
|
72 | - // we're using the role name as the array index to prevent duplicates |
|
73 | - if (! isset($event_manager_roles[ $role->name ]) && $role->has_cap($capability)) { |
|
74 | - $event_manager_roles[ $role->name ] = $role; |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
78 | - } |
|
79 | - $this->roles = $event_manager_roles; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - private function buildUserList(): void |
|
84 | - { |
|
85 | - global $wpdb; |
|
86 | - // no roles ?!!? then nothing to query for |
|
87 | - if (empty($this->roles)) { |
|
88 | - $this->user_list = []; |
|
89 | - } |
|
90 | - // begin to build our query |
|
91 | - $SQL = "SELECT u1.ID, u1.display_name FROM $wpdb->users AS u1 " |
|
92 | - . "INNER JOIN $wpdb->usermeta AS u2 ON u1.ID = u2.user_id " |
|
93 | - . "AND u2.meta_key='{$wpdb->prefix}capabilities' " |
|
94 | - . 'WHERE'; |
|
95 | - $operator = ''; |
|
96 | - foreach ($this->roles as $role) { |
|
97 | - // for each role, add a WHERE clause |
|
98 | - if ($role instanceof WP_Role) { |
|
99 | - $SQL .= $operator . ' u2.meta_value LIKE \'%"' . $role->name . '"%\' '; |
|
100 | - // subsequent clauses will use OR so that any role is accepted |
|
101 | - $operator = 'OR'; |
|
102 | - } |
|
103 | - } |
|
104 | - foreach ($this->capabilities as $capability) { |
|
105 | - // for each capability, add a WHERE clause |
|
106 | - $SQL .= $operator . ' u2.meta_value LIKE \'%"' . $capability . '";b:1;%\' '; |
|
107 | - // subsequent clauses will use OR so that any role is accepted |
|
108 | - $operator = 'OR'; |
|
109 | - } |
|
110 | - $SQL .= 'ORDER BY user_id ASC'; |
|
111 | - $users = $wpdb->get_results($SQL); |
|
112 | - |
|
113 | - $this->user_list = ! empty($users) ? $users : []; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - public function capabilities(): array |
|
121 | - { |
|
122 | - return $this->capabilities; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns a list of WP_Role objects that have "event manager" capabilities |
|
128 | - * The list of "event manager" capabilities is filtered but defaults to: |
|
129 | - * - 'ee_edit_events' |
|
130 | - * - 'ee_edit_event' |
|
131 | - * |
|
132 | - * @return WP_Role[] |
|
133 | - */ |
|
134 | - public function roles(): array |
|
135 | - { |
|
136 | - return $this->roles; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * Returns a list of users that have any of the Event Manager roles |
|
142 | - * |
|
143 | - * @return stdClass[] |
|
144 | - */ |
|
145 | - public function userList(): array |
|
146 | - { |
|
147 | - return $this->user_list; |
|
148 | - } |
|
18 | + /** |
|
19 | + * @var string[] |
|
20 | + */ |
|
21 | + private $capabilities = []; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var WP_Role[] |
|
25 | + */ |
|
26 | + private $roles = []; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + private $user_list = []; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var WP_Role[] |
|
35 | + */ |
|
36 | + private $wp_roles; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * EventManagerRoles constructor. |
|
41 | + */ |
|
42 | + public function __construct() |
|
43 | + { |
|
44 | + global $wp_roles; |
|
45 | + // first let's grab ALL of the WP_Role objects |
|
46 | + $this->wp_roles = $wp_roles->role_objects; |
|
47 | + $this->setCapabilities(); |
|
48 | + $this->buildRolesArray(); |
|
49 | + $this->buildUserList(); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + private function setCapabilities(): void |
|
54 | + { |
|
55 | + // filter a list of capabilities we want to use to define an event manager |
|
56 | + $capabilities = (array) apply_filters( |
|
57 | + 'FHEE__EventEspresso_core_domain_services_capabilities_EventManagers__setCapabilities', |
|
58 | + ['ee_edit_events', 'ee_edit_event'], |
|
59 | + $this->wp_roles |
|
60 | + ); |
|
61 | + $this->capabilities = array_map('sanitize_text_field', $capabilities); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + private function buildRolesArray(): void |
|
66 | + { |
|
67 | + // we'll use this array to capture all of the WP_Role objects that have any of the caps we are targeting |
|
68 | + $event_manager_roles = []; |
|
69 | + foreach ($this->wp_roles as $role) { |
|
70 | + if ($role instanceof WP_Role) { |
|
71 | + foreach ($this->capabilities as $capability) { |
|
72 | + // we're using the role name as the array index to prevent duplicates |
|
73 | + if (! isset($event_manager_roles[ $role->name ]) && $role->has_cap($capability)) { |
|
74 | + $event_manager_roles[ $role->name ] = $role; |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | + } |
|
79 | + $this->roles = $event_manager_roles; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + private function buildUserList(): void |
|
84 | + { |
|
85 | + global $wpdb; |
|
86 | + // no roles ?!!? then nothing to query for |
|
87 | + if (empty($this->roles)) { |
|
88 | + $this->user_list = []; |
|
89 | + } |
|
90 | + // begin to build our query |
|
91 | + $SQL = "SELECT u1.ID, u1.display_name FROM $wpdb->users AS u1 " |
|
92 | + . "INNER JOIN $wpdb->usermeta AS u2 ON u1.ID = u2.user_id " |
|
93 | + . "AND u2.meta_key='{$wpdb->prefix}capabilities' " |
|
94 | + . 'WHERE'; |
|
95 | + $operator = ''; |
|
96 | + foreach ($this->roles as $role) { |
|
97 | + // for each role, add a WHERE clause |
|
98 | + if ($role instanceof WP_Role) { |
|
99 | + $SQL .= $operator . ' u2.meta_value LIKE \'%"' . $role->name . '"%\' '; |
|
100 | + // subsequent clauses will use OR so that any role is accepted |
|
101 | + $operator = 'OR'; |
|
102 | + } |
|
103 | + } |
|
104 | + foreach ($this->capabilities as $capability) { |
|
105 | + // for each capability, add a WHERE clause |
|
106 | + $SQL .= $operator . ' u2.meta_value LIKE \'%"' . $capability . '";b:1;%\' '; |
|
107 | + // subsequent clauses will use OR so that any role is accepted |
|
108 | + $operator = 'OR'; |
|
109 | + } |
|
110 | + $SQL .= 'ORDER BY user_id ASC'; |
|
111 | + $users = $wpdb->get_results($SQL); |
|
112 | + |
|
113 | + $this->user_list = ! empty($users) ? $users : []; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + public function capabilities(): array |
|
121 | + { |
|
122 | + return $this->capabilities; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Returns a list of WP_Role objects that have "event manager" capabilities |
|
128 | + * The list of "event manager" capabilities is filtered but defaults to: |
|
129 | + * - 'ee_edit_events' |
|
130 | + * - 'ee_edit_event' |
|
131 | + * |
|
132 | + * @return WP_Role[] |
|
133 | + */ |
|
134 | + public function roles(): array |
|
135 | + { |
|
136 | + return $this->roles; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * Returns a list of users that have any of the Event Manager roles |
|
142 | + * |
|
143 | + * @return stdClass[] |
|
144 | + */ |
|
145 | + public function userList(): array |
|
146 | + { |
|
147 | + return $this->user_list; |
|
148 | + } |
|
149 | 149 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | self::priority_low => esc_html__('low', 'event_espresso'), |
127 | 127 | ); |
128 | 128 | |
129 | - $this->_fields = array( |
|
129 | + $this->_fields = array( |
|
130 | 130 | 'Message' => array( |
131 | 131 | 'MSG_ID' => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')), |
132 | 132 | 'MSG_token' => new EE_Plain_Text_Field( |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | ); |
437 | 437 | break; |
438 | 438 | default: |
439 | - $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value; |
|
439 | + $query_params[0]['AND**filter_by']['OR**filter_by_'.$request_key][$model_name.'.'.$request_key] = $request_value; |
|
440 | 440 | break; |
441 | 441 | } |
442 | 442 | } |
@@ -499,8 +499,8 @@ discard block |
||
499 | 499 | if ($label_parts) { |
500 | 500 | // prepend to the last element of $label_parts an "and". |
501 | 501 | if (count($label_parts) > 1) { |
502 | - $label_parts_index_to_prepend = count($label_parts) - 1; |
|
503 | - $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ]; |
|
502 | + $label_parts_index_to_prepend = count($label_parts) - 1; |
|
503 | + $label_parts[$label_parts_index_to_prepend] = 'and'.$label_parts[$label_parts_index_to_prepend]; |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | $pretty_label .= sprintf( |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES; |
561 | 561 | } |
562 | 562 | |
563 | - if (! is_null($set_debug)) { |
|
563 | + if ( ! is_null($set_debug)) { |
|
564 | 564 | $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN); |
565 | 565 | } |
566 | 566 | |
@@ -627,13 +627,13 @@ discard block |
||
627 | 627 | ) |
628 | 628 | ); |
629 | 629 | |
630 | - if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
630 | + if ( ! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
631 | 631 | global $wpdb; |
632 | 632 | $number_deleted = $wpdb->query(' |
633 | 633 | DELETE |
634 | - FROM ' . $this->table() . ' |
|
634 | + FROM ' . $this->table().' |
|
635 | 635 | WHERE |
636 | - MSG_ID IN (' . implode(",", $message_ids_to_delete) . ') |
|
636 | + MSG_ID IN (' . implode(",", $message_ids_to_delete).') |
|
637 | 637 | '); |
638 | 638 | } |
639 | 639 |
@@ -12,649 +12,649 @@ |
||
12 | 12 | */ |
13 | 13 | class EEM_Message extends EEM_Base implements EEI_Query_Filter |
14 | 14 | { |
15 | - // private instance of the Message object |
|
16 | - protected static $_instance = null; |
|
17 | - |
|
18 | - |
|
19 | - /** |
|
20 | - * This priority indicates a message should be generated and sent ASAP |
|
21 | - * |
|
22 | - * @type int |
|
23 | - */ |
|
24 | - const priority_high = 10; |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * This priority indicates a message should be generated ASAP and queued for sending. |
|
29 | - * |
|
30 | - * @type |
|
31 | - */ |
|
32 | - const priority_medium = 20; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * This priority indicates a message should be queued for generating. |
|
37 | - * |
|
38 | - * @type int |
|
39 | - */ |
|
40 | - const priority_low = 30; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * indicates this message was sent at the time modified |
|
45 | - */ |
|
46 | - const status_sent = 'MSN'; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * indicates this message is waiting to be sent |
|
51 | - */ |
|
52 | - const status_idle = 'MID'; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * indicates an attempt was a made to send this message |
|
57 | - * at the scheduled time, but it failed at the time modified. This differs from MDO status in that it will ALWAYS |
|
58 | - * appear to the end user. |
|
59 | - */ |
|
60 | - const status_failed = 'MFL'; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * indicates the message has been flagged for resending (at the time modified). |
|
65 | - */ |
|
66 | - const status_resend = 'MRS'; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * indicates the message has been flagged for generation but has not been generated yet. Messages always start as |
|
71 | - * this status when added to the queue. |
|
72 | - */ |
|
73 | - const status_incomplete = 'MIC'; |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Indicates everything was generated fine for the message, however, the messenger was unable to send. |
|
78 | - * This status means that its possible to retry sending the message. |
|
79 | - */ |
|
80 | - const status_retry = 'MRT'; |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * This is used for more informational messages that may not indicate anything is broken but still cannot be |
|
85 | - * generated or sent correctly. An example of a message that would get flagged this way would be when a not |
|
86 | - * approved message was queued for generation, but at time of generation, the attached registration(s) are |
|
87 | - * approved. So the message queued for generation is no longer valid. Messages for this status will only persist |
|
88 | - * in the db and be viewable in the message activity list table when the messages system is in debug mode. |
|
89 | - * |
|
90 | - * @see EEM_Message::debug() |
|
91 | - */ |
|
92 | - const status_debug_only = 'MDO'; |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * This status is given to messages it is processed by the messenger send method. |
|
97 | - * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually |
|
98 | - * indicative of a PHP timeout or memory limit issue. |
|
99 | - */ |
|
100 | - const status_messenger_executing = 'MEX'; |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Private constructor to prevent direct creation. |
|
105 | - * |
|
106 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
107 | - * any incoming timezone data that gets saved). Note this just sends the timezone info to |
|
108 | - * the date time model field objects. Default is null (and will be assumed using the set |
|
109 | - * timezone in the 'timezone_string' wp option) |
|
110 | - * @throws EE_Error |
|
111 | - * @throws EE_Error |
|
112 | - * @throws EE_Error |
|
113 | - */ |
|
114 | - protected function __construct($timezone = null) |
|
115 | - { |
|
116 | - $this->singular_item = esc_html__('Message', 'event_espresso'); |
|
117 | - $this->plural_item = esc_html__('Messages', 'event_espresso'); |
|
118 | - |
|
119 | - $this->_tables = array( |
|
120 | - 'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'), |
|
121 | - ); |
|
122 | - |
|
123 | - $allowed_priority = array( |
|
124 | - self::priority_high => esc_html__('high', 'event_espresso'), |
|
125 | - self::priority_medium => esc_html__('medium', 'event_espresso'), |
|
126 | - self::priority_low => esc_html__('low', 'event_espresso'), |
|
127 | - ); |
|
128 | - |
|
129 | - $this->_fields = array( |
|
130 | - 'Message' => array( |
|
131 | - 'MSG_ID' => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')), |
|
132 | - 'MSG_token' => new EE_Plain_Text_Field( |
|
133 | - 'MSG_token', |
|
134 | - esc_html__( |
|
135 | - 'Unique Token used to represent this row in publicly viewable contexts (eg. a url).', |
|
136 | - 'event_espresso' |
|
137 | - ), |
|
138 | - false, |
|
139 | - EEH_URL::generate_unique_token() |
|
140 | - ), |
|
141 | - 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
142 | - 'GRP_ID', |
|
143 | - esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'), |
|
144 | - true, |
|
145 | - 0, |
|
146 | - 'Message_Template_Group' |
|
147 | - ), |
|
148 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
149 | - 'TXN_ID', |
|
150 | - esc_html__( |
|
151 | - 'Foreign key to the related EE_Transaction. This is required to give context for regenerating the specific message', |
|
152 | - 'event_espresso' |
|
153 | - ), |
|
154 | - true, |
|
155 | - 0, |
|
156 | - 'Transaction' |
|
157 | - ), |
|
158 | - 'MSG_messenger' => new EE_Plain_Text_Field( |
|
159 | - 'MSG_messenger', |
|
160 | - esc_html__( |
|
161 | - 'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.', |
|
162 | - 'event_espresso' |
|
163 | - ), |
|
164 | - false, |
|
165 | - 'email' |
|
166 | - ), |
|
167 | - 'MSG_message_type' => new EE_Plain_Text_Field( |
|
168 | - 'MSG_message_type', |
|
169 | - esc_html__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'), |
|
170 | - false, |
|
171 | - 'receipt' |
|
172 | - ), |
|
173 | - 'MSG_context' => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false), |
|
174 | - 'MSG_recipient_ID' => new EE_Foreign_Key_Int_Field( |
|
175 | - 'MSG_recipient_ID', |
|
176 | - esc_html__('Recipient ID', 'event_espresso'), |
|
177 | - true, |
|
178 | - null, |
|
179 | - array('Registration', 'Attendee', 'WP_User') |
|
180 | - ), |
|
181 | - 'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field( |
|
182 | - 'MSG_recipient_type', |
|
183 | - esc_html__('Recipient Type', 'event_espresso'), |
|
184 | - true, |
|
185 | - null, |
|
186 | - array('Registration', 'Attendee', 'WP_User') |
|
187 | - ), |
|
188 | - 'MSG_content' => new EE_Maybe_Serialized_Text_Field( |
|
189 | - 'MSG_content', |
|
190 | - esc_html__('Content', 'event_espresso'), |
|
191 | - true, |
|
192 | - '' |
|
193 | - ), |
|
194 | - 'MSG_to' => new EE_Maybe_Serialized_Text_Field( |
|
195 | - 'MSG_to', |
|
196 | - esc_html__('Address To', 'event_espresso'), |
|
197 | - true |
|
198 | - ), |
|
199 | - 'MSG_from' => new EE_Maybe_Serialized_Text_Field( |
|
200 | - 'MSG_from', |
|
201 | - esc_html__('Address From', 'event_espresso'), |
|
202 | - true |
|
203 | - ), |
|
204 | - 'MSG_subject' => new EE_Maybe_Serialized_Text_Field( |
|
205 | - 'MSG_subject', |
|
206 | - esc_html__('Subject', 'event_espresso'), |
|
207 | - true, |
|
208 | - '' |
|
209 | - ), |
|
210 | - 'MSG_priority' => new EE_Enum_Integer_Field( |
|
211 | - 'MSG_priority', |
|
212 | - esc_html__('Priority', 'event_espresso'), |
|
213 | - false, |
|
214 | - self::priority_low, |
|
215 | - $allowed_priority |
|
216 | - ), |
|
217 | - 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
218 | - 'STS_ID', |
|
219 | - esc_html__('Status', 'event_espresso'), |
|
220 | - false, |
|
221 | - self::status_incomplete, |
|
222 | - 'Status' |
|
223 | - ), |
|
224 | - 'MSG_created' => new EE_Datetime_Field( |
|
225 | - 'MSG_created', |
|
226 | - esc_html__('Created', 'event_espresso'), |
|
227 | - false, |
|
228 | - EE_Datetime_Field::now |
|
229 | - ), |
|
230 | - 'MSG_modified' => new EE_Datetime_Field( |
|
231 | - 'MSG_modified', |
|
232 | - esc_html__('Modified', 'event_espresso'), |
|
233 | - true, |
|
234 | - EE_Datetime_Field::now |
|
235 | - ), |
|
236 | - ), |
|
237 | - ); |
|
238 | - $this->_model_relations = array( |
|
239 | - 'Attendee' => new EE_Belongs_To_Any_Relation(), |
|
240 | - 'Registration' => new EE_Belongs_To_Any_Relation(), |
|
241 | - 'WP_User' => new EE_Belongs_To_Any_Relation(), |
|
242 | - 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
243 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
244 | - ); |
|
245 | - parent::__construct($timezone); |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * @return EE_Message |
|
251 | - * @throws EE_Error |
|
252 | - */ |
|
253 | - public function create_default_object() |
|
254 | - { |
|
255 | - /** @type EE_Message $message */ |
|
256 | - $message = parent::create_default_object(); |
|
257 | - if ($message instanceof EE_Message) { |
|
258 | - return EE_Message_Factory::set_messenger_and_message_type($message); |
|
259 | - } |
|
260 | - return null; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @param mixed $cols_n_values |
|
266 | - * @return EE_Message |
|
267 | - * @throws EE_Error |
|
268 | - * @throws EE_Error |
|
269 | - */ |
|
270 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
271 | - { |
|
272 | - /** @type EE_Message $message */ |
|
273 | - $message = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
274 | - if ($message instanceof EE_Message) { |
|
275 | - return EE_Message_Factory::set_messenger_and_message_type($message); |
|
276 | - } |
|
277 | - return null; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Returns whether or not a message of that type was sent for a given attendee. |
|
283 | - * |
|
284 | - * @param EE_Attendee|int $attendee |
|
285 | - * @param string $message_type the message type slug |
|
286 | - * @return boolean |
|
287 | - * @throws EE_Error |
|
288 | - * @throws EE_Error |
|
289 | - * @throws EE_Error |
|
290 | - */ |
|
291 | - public function message_sent_for_attendee($attendee, $message_type) |
|
292 | - { |
|
293 | - $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee); |
|
294 | - return $this->exists(array( |
|
295 | - array( |
|
296 | - 'Attendee.ATT_ID' => $attendee_ID, |
|
297 | - 'MSG_message_type' => $message_type, |
|
298 | - 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
299 | - ), |
|
300 | - )); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Returns whether or not a message of that type was sent for a given registration |
|
306 | - * |
|
307 | - * @param EE_Registration|int $registration |
|
308 | - * @param string $message_type the message type slug |
|
309 | - * @return boolean |
|
310 | - * @throws EE_Error |
|
311 | - * @throws EE_Error |
|
312 | - * @throws EE_Error |
|
313 | - */ |
|
314 | - public function message_sent_for_registration($registration, $message_type) |
|
315 | - { |
|
316 | - $registrationID = EEM_Registration::instance()->ensure_is_ID($registration); |
|
317 | - return $this->exists(array( |
|
318 | - array( |
|
319 | - 'Registration.REG_ID' => $registrationID, |
|
320 | - 'MSG_message_type' => $message_type, |
|
321 | - 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
322 | - ), |
|
323 | - )); |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * This retrieves an EE_Message object from the db matching the given token string. |
|
329 | - * |
|
330 | - * @param string $token |
|
331 | - * @return EE_Message |
|
332 | - * @throws EE_Error |
|
333 | - */ |
|
334 | - public function get_one_by_token($token) |
|
335 | - { |
|
336 | - return $this->get_one(array( |
|
337 | - array( |
|
338 | - 'MSG_token' => $token, |
|
339 | - ), |
|
340 | - )); |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * Returns stati that indicate the message HAS been sent |
|
346 | - * |
|
347 | - * @return array of strings for possible stati |
|
348 | - */ |
|
349 | - public function stati_indicating_sent() |
|
350 | - { |
|
351 | - return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent)); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Returns stati that indicate the message is waiting to be sent. |
|
357 | - * |
|
358 | - * @return array of strings for possible stati. |
|
359 | - */ |
|
360 | - public function stati_indicating_to_send() |
|
361 | - { |
|
362 | - return apply_filters( |
|
363 | - 'FHEE__EEM_Message__stati_indicating_to_send', |
|
364 | - array(self::status_idle, self::status_resend) |
|
365 | - ); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * Returns stati that indicate the message has failed sending |
|
371 | - * |
|
372 | - * @return array array of strings for possible stati. |
|
373 | - */ |
|
374 | - public function stati_indicating_failed_sending() |
|
375 | - { |
|
376 | - $failed_stati = array( |
|
377 | - self::status_failed, |
|
378 | - self::status_retry, |
|
379 | - self::status_messenger_executing, |
|
380 | - ); |
|
381 | - // if WP_DEBUG is set, then let's include debug_only fails |
|
382 | - if (WP_DEBUG) { |
|
383 | - $failed_stati[] = self::status_debug_only; |
|
384 | - } |
|
385 | - return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Returns filterable array of all EEM_Message statuses. |
|
391 | - * |
|
392 | - * @return array |
|
393 | - */ |
|
394 | - public function all_statuses() |
|
395 | - { |
|
396 | - return apply_filters( |
|
397 | - 'FHEE__EEM_Message__all_statuses', |
|
398 | - array( |
|
399 | - EEM_Message::status_sent, |
|
400 | - EEM_Message::status_incomplete, |
|
401 | - EEM_Message::status_idle, |
|
402 | - EEM_Message::status_resend, |
|
403 | - EEM_Message::status_retry, |
|
404 | - EEM_Message::status_failed, |
|
405 | - EEM_Message::status_messenger_executing, |
|
406 | - EEM_Message::status_debug_only, |
|
407 | - ) |
|
408 | - ); |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Detects any specific query variables in the request and uses those to setup appropriate |
|
413 | - * filter for any queries. |
|
414 | - * |
|
415 | - * @return array |
|
416 | - */ |
|
417 | - public function filter_by_query_params() |
|
418 | - { |
|
419 | - /** @var RequestInterface $request */ |
|
420 | - $request = EEM_Base::$loader->getShared(RequestInterface::class); |
|
421 | - // expected possible query_vars, the key in this array matches an expected key in the request, |
|
422 | - // the value, matches the corresponding EEM_Base child reference. |
|
423 | - $expected_vars = $this->_expected_vars_for_query_inject(); |
|
424 | - $query_params[0] = array(); |
|
425 | - foreach ($expected_vars as $request_key => $model_name) { |
|
426 | - $request_value = $request->getRequestParam($request_key); |
|
427 | - if ($request_value) { |
|
428 | - // special case |
|
429 | - switch ($request_key) { |
|
430 | - case '_REG_ID': |
|
431 | - $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array( |
|
432 | - 'Transaction.Registration.REG_ID' => $request_value, |
|
433 | - ); |
|
434 | - break; |
|
435 | - case 'EVT_ID': |
|
436 | - $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array( |
|
437 | - 'Transaction.Registration.EVT_ID' => $request_value, |
|
438 | - ); |
|
439 | - break; |
|
440 | - default: |
|
441 | - $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value; |
|
442 | - break; |
|
443 | - } |
|
444 | - } |
|
445 | - } |
|
446 | - return $query_params; |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * @return string |
|
452 | - * @throws EE_Error |
|
453 | - * @throws ReflectionException |
|
454 | - */ |
|
455 | - public function get_pretty_label_for_results() |
|
456 | - { |
|
457 | - /** @var RequestInterface $request */ |
|
458 | - $request = EEM_Base::$loader->getShared(RequestInterface::class); |
|
459 | - $expected_vars = $this->_expected_vars_for_query_inject(); |
|
460 | - $pretty_label = ''; |
|
461 | - $label_parts = array(); |
|
462 | - foreach ($expected_vars as $request_key => $model_name) { |
|
463 | - $model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}"; |
|
464 | - $model = EEM_Base::$loader->getShared($model_name); |
|
465 | - $model_field_value = $request->getRequestParam($request_key); |
|
466 | - if ($model instanceof EEM_Base && $model_field_value !== '') { |
|
467 | - switch ($request_key) { |
|
468 | - case '_REG_ID': |
|
469 | - $label_parts[] = sprintf( |
|
470 | - esc_html__('Registration with the ID: %s', 'event_espresso'), |
|
471 | - $model_field_value |
|
472 | - ); |
|
473 | - break; |
|
474 | - case 'ATT_ID': |
|
475 | - /** @var EE_Attendee $attendee */ |
|
476 | - $attendee = $model->get_one_by_ID($model_field_value); |
|
477 | - $label_parts[] = $attendee instanceof EE_Attendee |
|
478 | - ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name()) |
|
479 | - : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value); |
|
480 | - break; |
|
481 | - case 'ID': |
|
482 | - /** @var EE_WP_User $wpUser */ |
|
483 | - $wpUser = $model->get_one_by_ID($model_field_value); |
|
484 | - $label_parts[] = $wpUser instanceof EE_WP_User |
|
485 | - ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name()) |
|
486 | - : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value); |
|
487 | - break; |
|
488 | - case 'TXN_ID': |
|
489 | - $label_parts[] = sprintf( |
|
490 | - esc_html__('Transaction with the ID: %s', 'event_espresso'), |
|
491 | - $model_field_value |
|
492 | - ); |
|
493 | - break; |
|
494 | - case 'EVT_ID': |
|
495 | - /** @var EE_Event $Event */ |
|
496 | - $Event = $model->get_one_by_ID($model_field_value); |
|
497 | - $label_parts[] = $Event instanceof EE_Event |
|
498 | - ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name()) |
|
499 | - : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value); |
|
500 | - break; |
|
501 | - } |
|
502 | - } |
|
503 | - } |
|
504 | - |
|
505 | - if ($label_parts) { |
|
506 | - // prepend to the last element of $label_parts an "and". |
|
507 | - if (count($label_parts) > 1) { |
|
508 | - $label_parts_index_to_prepend = count($label_parts) - 1; |
|
509 | - $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ]; |
|
510 | - } |
|
511 | - |
|
512 | - $pretty_label .= sprintf( |
|
513 | - esc_html_x( |
|
514 | - 'Showing messages for %s', |
|
515 | - 'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.', |
|
516 | - 'event_espresso' |
|
517 | - ), |
|
518 | - implode(', ', $label_parts) |
|
519 | - ); |
|
520 | - } |
|
521 | - return $pretty_label; |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * This returns the array of expected variables for the EEI_Query_Filter methods being implemented |
|
527 | - * The array is in the format: |
|
528 | - * array( |
|
529 | - * {$field_name} => {$model_name} |
|
530 | - * ); |
|
531 | - * |
|
532 | - * @since 4.9.0 |
|
533 | - * @return array |
|
534 | - */ |
|
535 | - protected function _expected_vars_for_query_inject() |
|
536 | - { |
|
537 | - return array( |
|
538 | - '_REG_ID' => 'Registration', |
|
539 | - 'ATT_ID' => 'Attendee', |
|
540 | - 'ID' => 'WP_User', |
|
541 | - 'TXN_ID' => 'Transaction', |
|
542 | - 'EVT_ID' => 'Event', |
|
543 | - ); |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * This returns whether EEM_Message is in debug mode or not. |
|
549 | - * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when |
|
550 | - * generating/sending messages. Debug mode can be set by either: |
|
551 | - * 1. Sending in a value for the $set_debug argument |
|
552 | - * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php |
|
553 | - * 3. Overriding the above via the provided filter. |
|
554 | - * |
|
555 | - * @param bool|null $set_debug If provided, then the debug mode will be set internally until reset via the |
|
556 | - * provided boolean. When no argument is provided (default null) then the debug |
|
557 | - * mode will be returned. |
|
558 | - * @return bool true means Messages is in debug mode. false means messages system is not in debug mode. |
|
559 | - */ |
|
560 | - public static function debug($set_debug = null) |
|
561 | - { |
|
562 | - static $is_debugging = null; |
|
563 | - |
|
564 | - // initialize (use constant if set). |
|
565 | - if (is_null($set_debug) && is_null($is_debugging)) { |
|
566 | - $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES; |
|
567 | - } |
|
568 | - |
|
569 | - if (! is_null($set_debug)) { |
|
570 | - $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN); |
|
571 | - } |
|
572 | - |
|
573 | - // return filtered value |
|
574 | - return apply_filters('FHEE__EEM_Message__debug', $is_debugging); |
|
575 | - } |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * Deletes old messages meeting certain criteria for removal from the database. |
|
580 | - * By default, this will delete messages that: |
|
581 | - * - are older than the value of the delete_threshold in months. |
|
582 | - * - have a STS_ID other than EEM_Message::status_idle |
|
583 | - * |
|
584 | - * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in |
|
585 | - * months. |
|
586 | - * @return bool|false|int Either the number of records affected or false if there was an error (you can call |
|
587 | - * $wpdb->last_error to find out what the error was. |
|
588 | - * @throws EE_Error |
|
589 | - * @throws EE_Error |
|
590 | - * @throws EE_Error |
|
591 | - */ |
|
592 | - public function delete_old_messages($delete_threshold = 6) |
|
593 | - { |
|
594 | - $number_deleted = 0; |
|
595 | - /** |
|
596 | - * Allows code to change the boundary for what messages are kept. |
|
597 | - * Uses the value of the `delete_threshold` variable by default. |
|
598 | - * |
|
599 | - * @param int $seconds seconds that will be subtracted from the timestamp for now. |
|
600 | - * @return int |
|
601 | - */ |
|
602 | - $time_to_leave_alone = absint( |
|
603 | - apply_filters( |
|
604 | - 'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone', |
|
605 | - ((int) $delete_threshold) * MONTH_IN_SECONDS |
|
606 | - ) |
|
607 | - ); |
|
608 | - |
|
609 | - |
|
610 | - /** |
|
611 | - * Allows code to change what message stati are ignored when deleting. |
|
612 | - * Defaults to only ignore EEM_Message::status_idle messages. |
|
613 | - * |
|
614 | - * @param string $message_stati_to_keep An array of message statuses that will be ignored when deleting. |
|
615 | - */ |
|
616 | - $message_stati_to_keep = (array) apply_filters( |
|
617 | - 'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep', |
|
618 | - array( |
|
619 | - EEM_Message::status_idle |
|
620 | - ) |
|
621 | - ); |
|
622 | - |
|
623 | - // first get all the ids of messages being deleted |
|
624 | - $message_ids_to_delete = EEM_Message::instance()->get_col( |
|
625 | - array( |
|
626 | - 0 => array( |
|
627 | - 'STS_ID' => array('NOT_IN', $message_stati_to_keep), |
|
628 | - 'MSG_modified' => array('<', time() - $time_to_leave_alone) |
|
629 | - ), |
|
630 | - 'limit' => apply_filters( |
|
631 | - 'EEM_Message__delete_old_messages__limit', |
|
632 | - 2000, |
|
633 | - $delete_threshold |
|
634 | - ) |
|
635 | - ) |
|
636 | - ); |
|
637 | - |
|
638 | - if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
639 | - global $wpdb; |
|
640 | - $number_deleted = $wpdb->query(' |
|
15 | + // private instance of the Message object |
|
16 | + protected static $_instance = null; |
|
17 | + |
|
18 | + |
|
19 | + /** |
|
20 | + * This priority indicates a message should be generated and sent ASAP |
|
21 | + * |
|
22 | + * @type int |
|
23 | + */ |
|
24 | + const priority_high = 10; |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * This priority indicates a message should be generated ASAP and queued for sending. |
|
29 | + * |
|
30 | + * @type |
|
31 | + */ |
|
32 | + const priority_medium = 20; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * This priority indicates a message should be queued for generating. |
|
37 | + * |
|
38 | + * @type int |
|
39 | + */ |
|
40 | + const priority_low = 30; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * indicates this message was sent at the time modified |
|
45 | + */ |
|
46 | + const status_sent = 'MSN'; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * indicates this message is waiting to be sent |
|
51 | + */ |
|
52 | + const status_idle = 'MID'; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * indicates an attempt was a made to send this message |
|
57 | + * at the scheduled time, but it failed at the time modified. This differs from MDO status in that it will ALWAYS |
|
58 | + * appear to the end user. |
|
59 | + */ |
|
60 | + const status_failed = 'MFL'; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * indicates the message has been flagged for resending (at the time modified). |
|
65 | + */ |
|
66 | + const status_resend = 'MRS'; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * indicates the message has been flagged for generation but has not been generated yet. Messages always start as |
|
71 | + * this status when added to the queue. |
|
72 | + */ |
|
73 | + const status_incomplete = 'MIC'; |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Indicates everything was generated fine for the message, however, the messenger was unable to send. |
|
78 | + * This status means that its possible to retry sending the message. |
|
79 | + */ |
|
80 | + const status_retry = 'MRT'; |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * This is used for more informational messages that may not indicate anything is broken but still cannot be |
|
85 | + * generated or sent correctly. An example of a message that would get flagged this way would be when a not |
|
86 | + * approved message was queued for generation, but at time of generation, the attached registration(s) are |
|
87 | + * approved. So the message queued for generation is no longer valid. Messages for this status will only persist |
|
88 | + * in the db and be viewable in the message activity list table when the messages system is in debug mode. |
|
89 | + * |
|
90 | + * @see EEM_Message::debug() |
|
91 | + */ |
|
92 | + const status_debug_only = 'MDO'; |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * This status is given to messages it is processed by the messenger send method. |
|
97 | + * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually |
|
98 | + * indicative of a PHP timeout or memory limit issue. |
|
99 | + */ |
|
100 | + const status_messenger_executing = 'MEX'; |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Private constructor to prevent direct creation. |
|
105 | + * |
|
106 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
107 | + * any incoming timezone data that gets saved). Note this just sends the timezone info to |
|
108 | + * the date time model field objects. Default is null (and will be assumed using the set |
|
109 | + * timezone in the 'timezone_string' wp option) |
|
110 | + * @throws EE_Error |
|
111 | + * @throws EE_Error |
|
112 | + * @throws EE_Error |
|
113 | + */ |
|
114 | + protected function __construct($timezone = null) |
|
115 | + { |
|
116 | + $this->singular_item = esc_html__('Message', 'event_espresso'); |
|
117 | + $this->plural_item = esc_html__('Messages', 'event_espresso'); |
|
118 | + |
|
119 | + $this->_tables = array( |
|
120 | + 'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'), |
|
121 | + ); |
|
122 | + |
|
123 | + $allowed_priority = array( |
|
124 | + self::priority_high => esc_html__('high', 'event_espresso'), |
|
125 | + self::priority_medium => esc_html__('medium', 'event_espresso'), |
|
126 | + self::priority_low => esc_html__('low', 'event_espresso'), |
|
127 | + ); |
|
128 | + |
|
129 | + $this->_fields = array( |
|
130 | + 'Message' => array( |
|
131 | + 'MSG_ID' => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')), |
|
132 | + 'MSG_token' => new EE_Plain_Text_Field( |
|
133 | + 'MSG_token', |
|
134 | + esc_html__( |
|
135 | + 'Unique Token used to represent this row in publicly viewable contexts (eg. a url).', |
|
136 | + 'event_espresso' |
|
137 | + ), |
|
138 | + false, |
|
139 | + EEH_URL::generate_unique_token() |
|
140 | + ), |
|
141 | + 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
142 | + 'GRP_ID', |
|
143 | + esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'), |
|
144 | + true, |
|
145 | + 0, |
|
146 | + 'Message_Template_Group' |
|
147 | + ), |
|
148 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
149 | + 'TXN_ID', |
|
150 | + esc_html__( |
|
151 | + 'Foreign key to the related EE_Transaction. This is required to give context for regenerating the specific message', |
|
152 | + 'event_espresso' |
|
153 | + ), |
|
154 | + true, |
|
155 | + 0, |
|
156 | + 'Transaction' |
|
157 | + ), |
|
158 | + 'MSG_messenger' => new EE_Plain_Text_Field( |
|
159 | + 'MSG_messenger', |
|
160 | + esc_html__( |
|
161 | + 'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.', |
|
162 | + 'event_espresso' |
|
163 | + ), |
|
164 | + false, |
|
165 | + 'email' |
|
166 | + ), |
|
167 | + 'MSG_message_type' => new EE_Plain_Text_Field( |
|
168 | + 'MSG_message_type', |
|
169 | + esc_html__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'), |
|
170 | + false, |
|
171 | + 'receipt' |
|
172 | + ), |
|
173 | + 'MSG_context' => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false), |
|
174 | + 'MSG_recipient_ID' => new EE_Foreign_Key_Int_Field( |
|
175 | + 'MSG_recipient_ID', |
|
176 | + esc_html__('Recipient ID', 'event_espresso'), |
|
177 | + true, |
|
178 | + null, |
|
179 | + array('Registration', 'Attendee', 'WP_User') |
|
180 | + ), |
|
181 | + 'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field( |
|
182 | + 'MSG_recipient_type', |
|
183 | + esc_html__('Recipient Type', 'event_espresso'), |
|
184 | + true, |
|
185 | + null, |
|
186 | + array('Registration', 'Attendee', 'WP_User') |
|
187 | + ), |
|
188 | + 'MSG_content' => new EE_Maybe_Serialized_Text_Field( |
|
189 | + 'MSG_content', |
|
190 | + esc_html__('Content', 'event_espresso'), |
|
191 | + true, |
|
192 | + '' |
|
193 | + ), |
|
194 | + 'MSG_to' => new EE_Maybe_Serialized_Text_Field( |
|
195 | + 'MSG_to', |
|
196 | + esc_html__('Address To', 'event_espresso'), |
|
197 | + true |
|
198 | + ), |
|
199 | + 'MSG_from' => new EE_Maybe_Serialized_Text_Field( |
|
200 | + 'MSG_from', |
|
201 | + esc_html__('Address From', 'event_espresso'), |
|
202 | + true |
|
203 | + ), |
|
204 | + 'MSG_subject' => new EE_Maybe_Serialized_Text_Field( |
|
205 | + 'MSG_subject', |
|
206 | + esc_html__('Subject', 'event_espresso'), |
|
207 | + true, |
|
208 | + '' |
|
209 | + ), |
|
210 | + 'MSG_priority' => new EE_Enum_Integer_Field( |
|
211 | + 'MSG_priority', |
|
212 | + esc_html__('Priority', 'event_espresso'), |
|
213 | + false, |
|
214 | + self::priority_low, |
|
215 | + $allowed_priority |
|
216 | + ), |
|
217 | + 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
218 | + 'STS_ID', |
|
219 | + esc_html__('Status', 'event_espresso'), |
|
220 | + false, |
|
221 | + self::status_incomplete, |
|
222 | + 'Status' |
|
223 | + ), |
|
224 | + 'MSG_created' => new EE_Datetime_Field( |
|
225 | + 'MSG_created', |
|
226 | + esc_html__('Created', 'event_espresso'), |
|
227 | + false, |
|
228 | + EE_Datetime_Field::now |
|
229 | + ), |
|
230 | + 'MSG_modified' => new EE_Datetime_Field( |
|
231 | + 'MSG_modified', |
|
232 | + esc_html__('Modified', 'event_espresso'), |
|
233 | + true, |
|
234 | + EE_Datetime_Field::now |
|
235 | + ), |
|
236 | + ), |
|
237 | + ); |
|
238 | + $this->_model_relations = array( |
|
239 | + 'Attendee' => new EE_Belongs_To_Any_Relation(), |
|
240 | + 'Registration' => new EE_Belongs_To_Any_Relation(), |
|
241 | + 'WP_User' => new EE_Belongs_To_Any_Relation(), |
|
242 | + 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
243 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
244 | + ); |
|
245 | + parent::__construct($timezone); |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * @return EE_Message |
|
251 | + * @throws EE_Error |
|
252 | + */ |
|
253 | + public function create_default_object() |
|
254 | + { |
|
255 | + /** @type EE_Message $message */ |
|
256 | + $message = parent::create_default_object(); |
|
257 | + if ($message instanceof EE_Message) { |
|
258 | + return EE_Message_Factory::set_messenger_and_message_type($message); |
|
259 | + } |
|
260 | + return null; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @param mixed $cols_n_values |
|
266 | + * @return EE_Message |
|
267 | + * @throws EE_Error |
|
268 | + * @throws EE_Error |
|
269 | + */ |
|
270 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
271 | + { |
|
272 | + /** @type EE_Message $message */ |
|
273 | + $message = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
274 | + if ($message instanceof EE_Message) { |
|
275 | + return EE_Message_Factory::set_messenger_and_message_type($message); |
|
276 | + } |
|
277 | + return null; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Returns whether or not a message of that type was sent for a given attendee. |
|
283 | + * |
|
284 | + * @param EE_Attendee|int $attendee |
|
285 | + * @param string $message_type the message type slug |
|
286 | + * @return boolean |
|
287 | + * @throws EE_Error |
|
288 | + * @throws EE_Error |
|
289 | + * @throws EE_Error |
|
290 | + */ |
|
291 | + public function message_sent_for_attendee($attendee, $message_type) |
|
292 | + { |
|
293 | + $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee); |
|
294 | + return $this->exists(array( |
|
295 | + array( |
|
296 | + 'Attendee.ATT_ID' => $attendee_ID, |
|
297 | + 'MSG_message_type' => $message_type, |
|
298 | + 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
299 | + ), |
|
300 | + )); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Returns whether or not a message of that type was sent for a given registration |
|
306 | + * |
|
307 | + * @param EE_Registration|int $registration |
|
308 | + * @param string $message_type the message type slug |
|
309 | + * @return boolean |
|
310 | + * @throws EE_Error |
|
311 | + * @throws EE_Error |
|
312 | + * @throws EE_Error |
|
313 | + */ |
|
314 | + public function message_sent_for_registration($registration, $message_type) |
|
315 | + { |
|
316 | + $registrationID = EEM_Registration::instance()->ensure_is_ID($registration); |
|
317 | + return $this->exists(array( |
|
318 | + array( |
|
319 | + 'Registration.REG_ID' => $registrationID, |
|
320 | + 'MSG_message_type' => $message_type, |
|
321 | + 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
322 | + ), |
|
323 | + )); |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * This retrieves an EE_Message object from the db matching the given token string. |
|
329 | + * |
|
330 | + * @param string $token |
|
331 | + * @return EE_Message |
|
332 | + * @throws EE_Error |
|
333 | + */ |
|
334 | + public function get_one_by_token($token) |
|
335 | + { |
|
336 | + return $this->get_one(array( |
|
337 | + array( |
|
338 | + 'MSG_token' => $token, |
|
339 | + ), |
|
340 | + )); |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * Returns stati that indicate the message HAS been sent |
|
346 | + * |
|
347 | + * @return array of strings for possible stati |
|
348 | + */ |
|
349 | + public function stati_indicating_sent() |
|
350 | + { |
|
351 | + return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent)); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Returns stati that indicate the message is waiting to be sent. |
|
357 | + * |
|
358 | + * @return array of strings for possible stati. |
|
359 | + */ |
|
360 | + public function stati_indicating_to_send() |
|
361 | + { |
|
362 | + return apply_filters( |
|
363 | + 'FHEE__EEM_Message__stati_indicating_to_send', |
|
364 | + array(self::status_idle, self::status_resend) |
|
365 | + ); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * Returns stati that indicate the message has failed sending |
|
371 | + * |
|
372 | + * @return array array of strings for possible stati. |
|
373 | + */ |
|
374 | + public function stati_indicating_failed_sending() |
|
375 | + { |
|
376 | + $failed_stati = array( |
|
377 | + self::status_failed, |
|
378 | + self::status_retry, |
|
379 | + self::status_messenger_executing, |
|
380 | + ); |
|
381 | + // if WP_DEBUG is set, then let's include debug_only fails |
|
382 | + if (WP_DEBUG) { |
|
383 | + $failed_stati[] = self::status_debug_only; |
|
384 | + } |
|
385 | + return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Returns filterable array of all EEM_Message statuses. |
|
391 | + * |
|
392 | + * @return array |
|
393 | + */ |
|
394 | + public function all_statuses() |
|
395 | + { |
|
396 | + return apply_filters( |
|
397 | + 'FHEE__EEM_Message__all_statuses', |
|
398 | + array( |
|
399 | + EEM_Message::status_sent, |
|
400 | + EEM_Message::status_incomplete, |
|
401 | + EEM_Message::status_idle, |
|
402 | + EEM_Message::status_resend, |
|
403 | + EEM_Message::status_retry, |
|
404 | + EEM_Message::status_failed, |
|
405 | + EEM_Message::status_messenger_executing, |
|
406 | + EEM_Message::status_debug_only, |
|
407 | + ) |
|
408 | + ); |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * Detects any specific query variables in the request and uses those to setup appropriate |
|
413 | + * filter for any queries. |
|
414 | + * |
|
415 | + * @return array |
|
416 | + */ |
|
417 | + public function filter_by_query_params() |
|
418 | + { |
|
419 | + /** @var RequestInterface $request */ |
|
420 | + $request = EEM_Base::$loader->getShared(RequestInterface::class); |
|
421 | + // expected possible query_vars, the key in this array matches an expected key in the request, |
|
422 | + // the value, matches the corresponding EEM_Base child reference. |
|
423 | + $expected_vars = $this->_expected_vars_for_query_inject(); |
|
424 | + $query_params[0] = array(); |
|
425 | + foreach ($expected_vars as $request_key => $model_name) { |
|
426 | + $request_value = $request->getRequestParam($request_key); |
|
427 | + if ($request_value) { |
|
428 | + // special case |
|
429 | + switch ($request_key) { |
|
430 | + case '_REG_ID': |
|
431 | + $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array( |
|
432 | + 'Transaction.Registration.REG_ID' => $request_value, |
|
433 | + ); |
|
434 | + break; |
|
435 | + case 'EVT_ID': |
|
436 | + $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array( |
|
437 | + 'Transaction.Registration.EVT_ID' => $request_value, |
|
438 | + ); |
|
439 | + break; |
|
440 | + default: |
|
441 | + $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value; |
|
442 | + break; |
|
443 | + } |
|
444 | + } |
|
445 | + } |
|
446 | + return $query_params; |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * @return string |
|
452 | + * @throws EE_Error |
|
453 | + * @throws ReflectionException |
|
454 | + */ |
|
455 | + public function get_pretty_label_for_results() |
|
456 | + { |
|
457 | + /** @var RequestInterface $request */ |
|
458 | + $request = EEM_Base::$loader->getShared(RequestInterface::class); |
|
459 | + $expected_vars = $this->_expected_vars_for_query_inject(); |
|
460 | + $pretty_label = ''; |
|
461 | + $label_parts = array(); |
|
462 | + foreach ($expected_vars as $request_key => $model_name) { |
|
463 | + $model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}"; |
|
464 | + $model = EEM_Base::$loader->getShared($model_name); |
|
465 | + $model_field_value = $request->getRequestParam($request_key); |
|
466 | + if ($model instanceof EEM_Base && $model_field_value !== '') { |
|
467 | + switch ($request_key) { |
|
468 | + case '_REG_ID': |
|
469 | + $label_parts[] = sprintf( |
|
470 | + esc_html__('Registration with the ID: %s', 'event_espresso'), |
|
471 | + $model_field_value |
|
472 | + ); |
|
473 | + break; |
|
474 | + case 'ATT_ID': |
|
475 | + /** @var EE_Attendee $attendee */ |
|
476 | + $attendee = $model->get_one_by_ID($model_field_value); |
|
477 | + $label_parts[] = $attendee instanceof EE_Attendee |
|
478 | + ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name()) |
|
479 | + : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value); |
|
480 | + break; |
|
481 | + case 'ID': |
|
482 | + /** @var EE_WP_User $wpUser */ |
|
483 | + $wpUser = $model->get_one_by_ID($model_field_value); |
|
484 | + $label_parts[] = $wpUser instanceof EE_WP_User |
|
485 | + ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name()) |
|
486 | + : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value); |
|
487 | + break; |
|
488 | + case 'TXN_ID': |
|
489 | + $label_parts[] = sprintf( |
|
490 | + esc_html__('Transaction with the ID: %s', 'event_espresso'), |
|
491 | + $model_field_value |
|
492 | + ); |
|
493 | + break; |
|
494 | + case 'EVT_ID': |
|
495 | + /** @var EE_Event $Event */ |
|
496 | + $Event = $model->get_one_by_ID($model_field_value); |
|
497 | + $label_parts[] = $Event instanceof EE_Event |
|
498 | + ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name()) |
|
499 | + : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value); |
|
500 | + break; |
|
501 | + } |
|
502 | + } |
|
503 | + } |
|
504 | + |
|
505 | + if ($label_parts) { |
|
506 | + // prepend to the last element of $label_parts an "and". |
|
507 | + if (count($label_parts) > 1) { |
|
508 | + $label_parts_index_to_prepend = count($label_parts) - 1; |
|
509 | + $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ]; |
|
510 | + } |
|
511 | + |
|
512 | + $pretty_label .= sprintf( |
|
513 | + esc_html_x( |
|
514 | + 'Showing messages for %s', |
|
515 | + 'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.', |
|
516 | + 'event_espresso' |
|
517 | + ), |
|
518 | + implode(', ', $label_parts) |
|
519 | + ); |
|
520 | + } |
|
521 | + return $pretty_label; |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * This returns the array of expected variables for the EEI_Query_Filter methods being implemented |
|
527 | + * The array is in the format: |
|
528 | + * array( |
|
529 | + * {$field_name} => {$model_name} |
|
530 | + * ); |
|
531 | + * |
|
532 | + * @since 4.9.0 |
|
533 | + * @return array |
|
534 | + */ |
|
535 | + protected function _expected_vars_for_query_inject() |
|
536 | + { |
|
537 | + return array( |
|
538 | + '_REG_ID' => 'Registration', |
|
539 | + 'ATT_ID' => 'Attendee', |
|
540 | + 'ID' => 'WP_User', |
|
541 | + 'TXN_ID' => 'Transaction', |
|
542 | + 'EVT_ID' => 'Event', |
|
543 | + ); |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * This returns whether EEM_Message is in debug mode or not. |
|
549 | + * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when |
|
550 | + * generating/sending messages. Debug mode can be set by either: |
|
551 | + * 1. Sending in a value for the $set_debug argument |
|
552 | + * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php |
|
553 | + * 3. Overriding the above via the provided filter. |
|
554 | + * |
|
555 | + * @param bool|null $set_debug If provided, then the debug mode will be set internally until reset via the |
|
556 | + * provided boolean. When no argument is provided (default null) then the debug |
|
557 | + * mode will be returned. |
|
558 | + * @return bool true means Messages is in debug mode. false means messages system is not in debug mode. |
|
559 | + */ |
|
560 | + public static function debug($set_debug = null) |
|
561 | + { |
|
562 | + static $is_debugging = null; |
|
563 | + |
|
564 | + // initialize (use constant if set). |
|
565 | + if (is_null($set_debug) && is_null($is_debugging)) { |
|
566 | + $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES; |
|
567 | + } |
|
568 | + |
|
569 | + if (! is_null($set_debug)) { |
|
570 | + $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN); |
|
571 | + } |
|
572 | + |
|
573 | + // return filtered value |
|
574 | + return apply_filters('FHEE__EEM_Message__debug', $is_debugging); |
|
575 | + } |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * Deletes old messages meeting certain criteria for removal from the database. |
|
580 | + * By default, this will delete messages that: |
|
581 | + * - are older than the value of the delete_threshold in months. |
|
582 | + * - have a STS_ID other than EEM_Message::status_idle |
|
583 | + * |
|
584 | + * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in |
|
585 | + * months. |
|
586 | + * @return bool|false|int Either the number of records affected or false if there was an error (you can call |
|
587 | + * $wpdb->last_error to find out what the error was. |
|
588 | + * @throws EE_Error |
|
589 | + * @throws EE_Error |
|
590 | + * @throws EE_Error |
|
591 | + */ |
|
592 | + public function delete_old_messages($delete_threshold = 6) |
|
593 | + { |
|
594 | + $number_deleted = 0; |
|
595 | + /** |
|
596 | + * Allows code to change the boundary for what messages are kept. |
|
597 | + * Uses the value of the `delete_threshold` variable by default. |
|
598 | + * |
|
599 | + * @param int $seconds seconds that will be subtracted from the timestamp for now. |
|
600 | + * @return int |
|
601 | + */ |
|
602 | + $time_to_leave_alone = absint( |
|
603 | + apply_filters( |
|
604 | + 'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone', |
|
605 | + ((int) $delete_threshold) * MONTH_IN_SECONDS |
|
606 | + ) |
|
607 | + ); |
|
608 | + |
|
609 | + |
|
610 | + /** |
|
611 | + * Allows code to change what message stati are ignored when deleting. |
|
612 | + * Defaults to only ignore EEM_Message::status_idle messages. |
|
613 | + * |
|
614 | + * @param string $message_stati_to_keep An array of message statuses that will be ignored when deleting. |
|
615 | + */ |
|
616 | + $message_stati_to_keep = (array) apply_filters( |
|
617 | + 'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep', |
|
618 | + array( |
|
619 | + EEM_Message::status_idle |
|
620 | + ) |
|
621 | + ); |
|
622 | + |
|
623 | + // first get all the ids of messages being deleted |
|
624 | + $message_ids_to_delete = EEM_Message::instance()->get_col( |
|
625 | + array( |
|
626 | + 0 => array( |
|
627 | + 'STS_ID' => array('NOT_IN', $message_stati_to_keep), |
|
628 | + 'MSG_modified' => array('<', time() - $time_to_leave_alone) |
|
629 | + ), |
|
630 | + 'limit' => apply_filters( |
|
631 | + 'EEM_Message__delete_old_messages__limit', |
|
632 | + 2000, |
|
633 | + $delete_threshold |
|
634 | + ) |
|
635 | + ) |
|
636 | + ); |
|
637 | + |
|
638 | + if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
639 | + global $wpdb; |
|
640 | + $number_deleted = $wpdb->query(' |
|
641 | 641 | DELETE |
642 | 642 | FROM ' . $this->table() . ' |
643 | 643 | WHERE |
644 | 644 | MSG_ID IN (' . implode(",", $message_ids_to_delete) . ') |
645 | 645 | '); |
646 | - } |
|
647 | - |
|
648 | - /** |
|
649 | - * This will get called if the number of records deleted 0 or greater. So a successful deletion is one where |
|
650 | - * there were no errors. An unsuccessful deletion is where there were errors. Keep that in mind for the actions |
|
651 | - * below. |
|
652 | - */ |
|
653 | - if ($number_deleted !== false) { |
|
654 | - do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted); |
|
655 | - } else { |
|
656 | - do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted); |
|
657 | - } |
|
658 | - return $number_deleted; |
|
659 | - } |
|
646 | + } |
|
647 | + |
|
648 | + /** |
|
649 | + * This will get called if the number of records deleted 0 or greater. So a successful deletion is one where |
|
650 | + * there were no errors. An unsuccessful deletion is where there were errors. Keep that in mind for the actions |
|
651 | + * below. |
|
652 | + */ |
|
653 | + if ($number_deleted !== false) { |
|
654 | + do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted); |
|
655 | + } else { |
|
656 | + do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted); |
|
657 | + } |
|
658 | + return $number_deleted; |
|
659 | + } |
|
660 | 660 | } |
@@ -79,10 +79,10 @@ |
||
79 | 79 | $model_names = []; |
80 | 80 | if (is_array($this->_model_name_pointed_to)) { |
81 | 81 | foreach ($this->_model_name_pointed_to as $model_name) { |
82 | - $model_names[] = "EE_" . $model_name; |
|
82 | + $model_names[] = "EE_".$model_name; |
|
83 | 83 | } |
84 | 84 | } else { |
85 | - $model_names = ["EE_" . $this->_model_name_pointed_to]; |
|
85 | + $model_names = ["EE_".$this->_model_name_pointed_to]; |
|
86 | 86 | } |
87 | 87 | return $model_names; |
88 | 88 | } |
@@ -8,94 +8,94 @@ |
||
8 | 8 | */ |
9 | 9 | abstract class EE_Field_With_Model_Name extends EE_Model_Field_Base |
10 | 10 | { |
11 | - /** |
|
12 | - * Usually the name of a single model. However, as in the case for custom post types, |
|
13 | - * it can actually be an array of models |
|
14 | - * |
|
15 | - * @var string[] |
|
16 | - */ |
|
17 | - protected $_model_name_pointed_to; |
|
11 | + /** |
|
12 | + * Usually the name of a single model. However, as in the case for custom post types, |
|
13 | + * it can actually be an array of models |
|
14 | + * |
|
15 | + * @var string[] |
|
16 | + */ |
|
17 | + protected $_model_name_pointed_to; |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * @param string $table_column name of column for field |
|
22 | - * @param string $nicename should be internationalized with __('blah','event_espresso') |
|
23 | - * @param boolean $nullable |
|
24 | - * @param int|string $default_value data type should match field type |
|
25 | - * @param string|string[] $model_name eg 'Event','Answer','Term', etc. |
|
26 | - * Basically its the model class's name without the "EEM_" |
|
27 | - */ |
|
28 | - public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
29 | - { |
|
30 | - $this->_model_name_pointed_to = (array) $model_name; |
|
31 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
32 | - } |
|
20 | + /** |
|
21 | + * @param string $table_column name of column for field |
|
22 | + * @param string $nicename should be internationalized with __('blah','event_espresso') |
|
23 | + * @param boolean $nullable |
|
24 | + * @param int|string $default_value data type should match field type |
|
25 | + * @param string|string[] $model_name eg 'Event','Answer','Term', etc. |
|
26 | + * Basically its the model class's name without the "EEM_" |
|
27 | + */ |
|
28 | + public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
29 | + { |
|
30 | + $this->_model_name_pointed_to = (array) $model_name; |
|
31 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * Returns the name of the model(s) pointed to |
|
37 | - * |
|
38 | - * @return string[] string or array of strings |
|
39 | - * @deprecated since version 4.6.7 |
|
40 | - */ |
|
41 | - public function get_model_name_pointed_to(): array |
|
42 | - { |
|
43 | - EE_Error::doing_it_wrong( |
|
44 | - 'get_model_name_pointed_to', |
|
45 | - esc_html__( |
|
46 | - 'This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array', |
|
47 | - 'event_espresso' |
|
48 | - ), |
|
49 | - '4.6.7' |
|
50 | - ); |
|
51 | - return $this->_model_name_pointed_to; |
|
52 | - } |
|
35 | + /** |
|
36 | + * Returns the name of the model(s) pointed to |
|
37 | + * |
|
38 | + * @return string[] string or array of strings |
|
39 | + * @deprecated since version 4.6.7 |
|
40 | + */ |
|
41 | + public function get_model_name_pointed_to(): array |
|
42 | + { |
|
43 | + EE_Error::doing_it_wrong( |
|
44 | + 'get_model_name_pointed_to', |
|
45 | + esc_html__( |
|
46 | + 'This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array', |
|
47 | + 'event_espresso' |
|
48 | + ), |
|
49 | + '4.6.7' |
|
50 | + ); |
|
51 | + return $this->_model_name_pointed_to; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Gets the model names pointed to by this field, always as an array |
|
57 | - * (even if there's only one) |
|
58 | - * |
|
59 | - * @return string[] of model names pointed to by this field |
|
60 | - */ |
|
61 | - public function get_model_names_pointed_to(): array |
|
62 | - { |
|
63 | - return is_array($this->_model_name_pointed_to) |
|
64 | - ? $this->_model_name_pointed_to |
|
65 | - : [$this->_model_name_pointed_to]; |
|
66 | - } |
|
55 | + /** |
|
56 | + * Gets the model names pointed to by this field, always as an array |
|
57 | + * (even if there's only one) |
|
58 | + * |
|
59 | + * @return string[] of model names pointed to by this field |
|
60 | + */ |
|
61 | + public function get_model_names_pointed_to(): array |
|
62 | + { |
|
63 | + return is_array($this->_model_name_pointed_to) |
|
64 | + ? $this->_model_name_pointed_to |
|
65 | + : [$this->_model_name_pointed_to]; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | - /** |
|
70 | - * Returns the model's classname (eg EE_Event instead of just Event) |
|
71 | - * |
|
72 | - * @return string[] |
|
73 | - */ |
|
74 | - public function get_model_class_names_pointed_to(): array |
|
75 | - { |
|
76 | - $model_names = []; |
|
77 | - if (is_array($this->_model_name_pointed_to)) { |
|
78 | - foreach ($this->_model_name_pointed_to as $model_name) { |
|
79 | - $model_names[] = "EE_" . $model_name; |
|
80 | - } |
|
81 | - } else { |
|
82 | - $model_names = ["EE_" . $this->_model_name_pointed_to]; |
|
83 | - } |
|
84 | - return $model_names; |
|
85 | - } |
|
69 | + /** |
|
70 | + * Returns the model's classname (eg EE_Event instead of just Event) |
|
71 | + * |
|
72 | + * @return string[] |
|
73 | + */ |
|
74 | + public function get_model_class_names_pointed_to(): array |
|
75 | + { |
|
76 | + $model_names = []; |
|
77 | + if (is_array($this->_model_name_pointed_to)) { |
|
78 | + foreach ($this->_model_name_pointed_to as $model_name) { |
|
79 | + $model_names[] = "EE_" . $model_name; |
|
80 | + } |
|
81 | + } else { |
|
82 | + $model_names = ["EE_" . $this->_model_name_pointed_to]; |
|
83 | + } |
|
84 | + return $model_names; |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * @param int|EE_Base_Class $model_obj |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function is_model_obj_of_type_pointed_to($model_obj): bool |
|
93 | - { |
|
94 | - foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) { |
|
95 | - if ($model_obj instanceof $model_obj_classname) { |
|
96 | - return true; |
|
97 | - } |
|
98 | - } |
|
99 | - return false; |
|
100 | - } |
|
88 | + /** |
|
89 | + * @param int|EE_Base_Class $model_obj |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function is_model_obj_of_type_pointed_to($model_obj): bool |
|
93 | + { |
|
94 | + foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) { |
|
95 | + if ($model_obj instanceof $model_obj_classname) { |
|
96 | + return true; |
|
97 | + } |
|
98 | + } |
|
99 | + return false; |
|
100 | + } |
|
101 | 101 | } |
@@ -5,12 +5,12 @@ |
||
5 | 5 | */ |
6 | 6 | class EE_WP_Post_Type_Field extends EE_DB_Only_Text_Field |
7 | 7 | { |
8 | - /** |
|
9 | - * @param string $post_type the exact string to be used for the post type |
|
10 | - * of all these post type model objects/rows |
|
11 | - */ |
|
12 | - public function __construct($post_type) |
|
13 | - { |
|
14 | - parent::__construct('post_type', esc_html__("Post Type", 'event_espresso'), false, $post_type); |
|
15 | - } |
|
8 | + /** |
|
9 | + * @param string $post_type the exact string to be used for the post type |
|
10 | + * of all these post type model objects/rows |
|
11 | + */ |
|
12 | + public function __construct($post_type) |
|
13 | + { |
|
14 | + parent::__construct('post_type', esc_html__("Post Type", 'event_espresso'), false, $post_type); |
|
15 | + } |
|
16 | 16 | } |