@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | */ |
18 | 18 | public function __construct($validation_error_message = null) |
19 | 19 | { |
20 | - if (! $validation_error_message) { |
|
20 | + if ( ! $validation_error_message) { |
|
21 | 21 | $validation_error_message = sprintf(esc_html__("Only numeric characters, commas, periods, and spaces, please!", "event_espresso")); |
22 | 22 | } |
23 | 23 | parent::__construct($validation_error_message); |
@@ -42,6 +42,6 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function get_jquery_validation_rule_array() |
44 | 44 | { |
45 | - return array('number' => true, 'messages' => array( 'number' => $this->get_validation_error_message() ) ); |
|
45 | + return array('number' => true, 'messages' => array('number' => $this->get_validation_error_message())); |
|
46 | 46 | } |
47 | 47 | } |
@@ -11,36 +11,36 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Float_Validation_Strategy extends EE_Validation_Strategy_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * @param null $validation_error_message |
|
16 | - */ |
|
17 | - public function __construct($validation_error_message = null) |
|
18 | - { |
|
19 | - if (! $validation_error_message) { |
|
20 | - $validation_error_message = sprintf(esc_html__("Only numeric characters, commas, periods, and spaces, please!", "event_espresso")); |
|
21 | - } |
|
22 | - parent::__construct($validation_error_message); |
|
23 | - } |
|
14 | + /** |
|
15 | + * @param null $validation_error_message |
|
16 | + */ |
|
17 | + public function __construct($validation_error_message = null) |
|
18 | + { |
|
19 | + if (! $validation_error_message) { |
|
20 | + $validation_error_message = sprintf(esc_html__("Only numeric characters, commas, periods, and spaces, please!", "event_espresso")); |
|
21 | + } |
|
22 | + parent::__construct($validation_error_message); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * |
|
29 | - * @param $normalized_value |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - public function validate($normalized_value) |
|
33 | - { |
|
34 | - // errors should have been detected by the normalization strategy |
|
35 | - } |
|
27 | + /** |
|
28 | + * |
|
29 | + * @param $normalized_value |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + public function validate($normalized_value) |
|
33 | + { |
|
34 | + // errors should have been detected by the normalization strategy |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @return array |
|
41 | - */ |
|
42 | - public function get_jquery_validation_rule_array() |
|
43 | - { |
|
44 | - return array('number' => true, 'messages' => array( 'number' => $this->get_validation_error_message() ) ); |
|
45 | - } |
|
39 | + /** |
|
40 | + * @return array |
|
41 | + */ |
|
42 | + public function get_jquery_validation_rule_array() |
|
43 | + { |
|
44 | + return array('number' => true, 'messages' => array( 'number' => $this->get_validation_error_message() ) ); |
|
45 | + } |
|
46 | 46 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function __construct($validation_error_message = null) |
21 | 21 | { |
22 | - if (! $validation_error_message) { |
|
22 | + if ( ! $validation_error_message) { |
|
23 | 23 | $allowedtags = $this->_get_allowed_tags(); |
24 | 24 | $validation_error_message = sprintf(esc_html__("Only simple HTML tags are allowed. Eg, %s", "event_espresso"), implode(",", array_keys($allowedtags))); |
25 | 25 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | { |
63 | 63 | $allowedtags = $this->_get_allowed_tags(); |
64 | 64 | parent::validate($normalized_value); |
65 | - $normalized_value_sans_tags = wp_kses("$normalized_value", $allowedtags); |
|
65 | + $normalized_value_sans_tags = wp_kses("$normalized_value", $allowedtags); |
|
66 | 66 | if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) { |
67 | 67 | throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags'); |
68 | 68 | } |
@@ -13,57 +13,57 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Simple_HTML_Validation_Strategy extends EE_Validation_Strategy_Base |
15 | 15 | { |
16 | - /** |
|
17 | - * @param null $validation_error_message |
|
18 | - */ |
|
19 | - public function __construct($validation_error_message = null) |
|
20 | - { |
|
21 | - if (! $validation_error_message) { |
|
22 | - $allowedtags = $this->_get_allowed_tags(); |
|
23 | - $validation_error_message = sprintf(esc_html__("Only simple HTML tags are allowed. Eg, %s", "event_espresso"), implode(",", array_keys($allowedtags))); |
|
24 | - } |
|
25 | - parent::__construct($validation_error_message); |
|
26 | - } |
|
16 | + /** |
|
17 | + * @param null $validation_error_message |
|
18 | + */ |
|
19 | + public function __construct($validation_error_message = null) |
|
20 | + { |
|
21 | + if (! $validation_error_message) { |
|
22 | + $allowedtags = $this->_get_allowed_tags(); |
|
23 | + $validation_error_message = sprintf(esc_html__("Only simple HTML tags are allowed. Eg, %s", "event_espresso"), implode(",", array_keys($allowedtags))); |
|
24 | + } |
|
25 | + parent::__construct($validation_error_message); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * get tags allowed |
|
32 | - */ |
|
33 | - protected function _get_allowed_tags() |
|
34 | - { |
|
35 | - return EEH_HTML::get_simple_tags(); |
|
36 | - } |
|
30 | + /** |
|
31 | + * get tags allowed |
|
32 | + */ |
|
33 | + protected function _get_allowed_tags() |
|
34 | + { |
|
35 | + return EEH_HTML::get_simple_tags(); |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * add_more_tags |
|
42 | - * |
|
43 | - * generates and returns a string that lists the top-level HTML tags that are allowable for this input |
|
44 | - * |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function get_list_of_allowed_tags() |
|
48 | - { |
|
49 | - $allowed_tags = $this->_get_allowed_tags(); |
|
50 | - ksort($allowed_tags); |
|
51 | - return implode(', ', array_keys($allowed_tags)); |
|
52 | - } |
|
40 | + /** |
|
41 | + * add_more_tags |
|
42 | + * |
|
43 | + * generates and returns a string that lists the top-level HTML tags that are allowable for this input |
|
44 | + * |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function get_list_of_allowed_tags() |
|
48 | + { |
|
49 | + $allowed_tags = $this->_get_allowed_tags(); |
|
50 | + ksort($allowed_tags); |
|
51 | + return implode(', ', array_keys($allowed_tags)); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * @param $normalized_value |
|
58 | - * @throws \EE_Validation_Error |
|
59 | - */ |
|
60 | - public function validate($normalized_value) |
|
61 | - { |
|
62 | - $allowedtags = $this->_get_allowed_tags(); |
|
63 | - parent::validate($normalized_value); |
|
64 | - $normalized_value_sans_tags = wp_kses("$normalized_value", $allowedtags); |
|
65 | - if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) { |
|
66 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags'); |
|
67 | - } |
|
68 | - } |
|
56 | + /** |
|
57 | + * @param $normalized_value |
|
58 | + * @throws \EE_Validation_Error |
|
59 | + */ |
|
60 | + public function validate($normalized_value) |
|
61 | + { |
|
62 | + $allowedtags = $this->_get_allowed_tags(); |
|
63 | + parent::validate($normalized_value); |
|
64 | + $normalized_value_sans_tags = wp_kses("$normalized_value", $allowedtags); |
|
65 | + if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) { |
|
66 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags'); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
34 | 34 | return (float) $value_to_normalize; |
35 | 35 | } |
36 | - if (! is_string($value_to_normalize)) { |
|
36 | + if ( ! is_string($value_to_normalize)) { |
|
37 | 37 | throw new EE_Validation_Error( |
38 | 38 | sprintf( |
39 | 39 | esc_html__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | } |
70 | 70 | // this really shouldn't ever happen because fields with a float normalization strategy |
71 | 71 | // should also have a float validation strategy, but in case it doesn't use the default |
72 | - if (! $validation_error_message) { |
|
72 | + if ( ! $validation_error_message) { |
|
73 | 73 | $default_validation_strategy = new EE_Float_Validation_Strategy(); |
74 | 74 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
75 | 75 | } |
@@ -10,84 +10,84 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Float_Normalization extends EE_Normalization_Strategy_Base |
12 | 12 | { |
13 | - /* |
|
13 | + /* |
|
14 | 14 | * regex pattern that matches for the following: |
15 | 15 | * * optional negative sign |
16 | 16 | * * one or more digits or decimals |
17 | 17 | */ |
18 | - const REGEX = '/^(-?)([\d.]+)$/'; |
|
18 | + const REGEX = '/^(-?)([\d.]+)$/'; |
|
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param string $value_to_normalize |
|
24 | - * @return float |
|
25 | - * @throws \EE_Validation_Error |
|
26 | - */ |
|
27 | - public function normalize($value_to_normalize) |
|
28 | - { |
|
29 | - if ($value_to_normalize === null) { |
|
30 | - return null; |
|
31 | - } |
|
32 | - if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
|
33 | - return (float) $value_to_normalize; |
|
34 | - } |
|
35 | - if (! is_string($value_to_normalize)) { |
|
36 | - throw new EE_Validation_Error( |
|
37 | - sprintf( |
|
38 | - esc_html__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
39 | - print_r($value_to_normalize, true), |
|
40 | - gettype($value_to_normalize) |
|
41 | - ) |
|
42 | - ); |
|
43 | - } |
|
44 | - $normalized_value = filter_var( |
|
45 | - $value_to_normalize, |
|
46 | - FILTER_SANITIZE_NUMBER_FLOAT, |
|
47 | - FILTER_FLAG_ALLOW_FRACTION |
|
48 | - ); |
|
49 | - if ($normalized_value === '') { |
|
50 | - return null; |
|
51 | - } |
|
52 | - if (preg_match(EE_Float_Normalization::REGEX, $normalized_value, $matches)) { |
|
53 | - if (count($matches) === 3) { |
|
54 | - // if first match is the negative sign, |
|
55 | - // then the number needs to be multiplied by -1 to remain negative |
|
56 | - return $matches[1] === '-' |
|
57 | - ? (float) $matches[2] * -1 |
|
58 | - : (float) $matches[2]; |
|
59 | - } |
|
60 | - } |
|
61 | - // find if this input has a float validation strategy |
|
62 | - // in which case, use its message |
|
63 | - $validation_error_message = null; |
|
64 | - foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
65 | - if ($validation_strategy instanceof EE_Float_Validation_Strategy) { |
|
66 | - $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
67 | - } |
|
68 | - } |
|
69 | - // this really shouldn't ever happen because fields with a float normalization strategy |
|
70 | - // should also have a float validation strategy, but in case it doesn't use the default |
|
71 | - if (! $validation_error_message) { |
|
72 | - $default_validation_strategy = new EE_Float_Validation_Strategy(); |
|
73 | - $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
74 | - } |
|
75 | - throw new EE_Validation_Error($validation_error_message, 'float_only'); |
|
76 | - } |
|
22 | + /** |
|
23 | + * @param string $value_to_normalize |
|
24 | + * @return float |
|
25 | + * @throws \EE_Validation_Error |
|
26 | + */ |
|
27 | + public function normalize($value_to_normalize) |
|
28 | + { |
|
29 | + if ($value_to_normalize === null) { |
|
30 | + return null; |
|
31 | + } |
|
32 | + if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
|
33 | + return (float) $value_to_normalize; |
|
34 | + } |
|
35 | + if (! is_string($value_to_normalize)) { |
|
36 | + throw new EE_Validation_Error( |
|
37 | + sprintf( |
|
38 | + esc_html__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
39 | + print_r($value_to_normalize, true), |
|
40 | + gettype($value_to_normalize) |
|
41 | + ) |
|
42 | + ); |
|
43 | + } |
|
44 | + $normalized_value = filter_var( |
|
45 | + $value_to_normalize, |
|
46 | + FILTER_SANITIZE_NUMBER_FLOAT, |
|
47 | + FILTER_FLAG_ALLOW_FRACTION |
|
48 | + ); |
|
49 | + if ($normalized_value === '') { |
|
50 | + return null; |
|
51 | + } |
|
52 | + if (preg_match(EE_Float_Normalization::REGEX, $normalized_value, $matches)) { |
|
53 | + if (count($matches) === 3) { |
|
54 | + // if first match is the negative sign, |
|
55 | + // then the number needs to be multiplied by -1 to remain negative |
|
56 | + return $matches[1] === '-' |
|
57 | + ? (float) $matches[2] * -1 |
|
58 | + : (float) $matches[2]; |
|
59 | + } |
|
60 | + } |
|
61 | + // find if this input has a float validation strategy |
|
62 | + // in which case, use its message |
|
63 | + $validation_error_message = null; |
|
64 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
65 | + if ($validation_strategy instanceof EE_Float_Validation_Strategy) { |
|
66 | + $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
67 | + } |
|
68 | + } |
|
69 | + // this really shouldn't ever happen because fields with a float normalization strategy |
|
70 | + // should also have a float validation strategy, but in case it doesn't use the default |
|
71 | + if (! $validation_error_message) { |
|
72 | + $default_validation_strategy = new EE_Float_Validation_Strategy(); |
|
73 | + $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
74 | + } |
|
75 | + throw new EE_Validation_Error($validation_error_message, 'float_only'); |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * Converts a float into a string |
|
82 | - * |
|
83 | - * @param float $normalized_value |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public function unnormalize($normalized_value) |
|
87 | - { |
|
88 | - if (empty($normalized_value)) { |
|
89 | - return '0.00'; |
|
90 | - } |
|
91 | - return "{$normalized_value}"; |
|
92 | - } |
|
80 | + /** |
|
81 | + * Converts a float into a string |
|
82 | + * |
|
83 | + * @param float $normalized_value |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public function unnormalize($normalized_value) |
|
87 | + { |
|
88 | + if (empty($normalized_value)) { |
|
89 | + return '0.00'; |
|
90 | + } |
|
91 | + return "{$normalized_value}"; |
|
92 | + } |
|
93 | 93 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | if (is_int($value_to_normalize) || is_float($value_to_normalize)) { |
34 | 34 | return (int) $value_to_normalize; |
35 | 35 | } |
36 | - if (! is_string($value_to_normalize)) { |
|
36 | + if ( ! is_string($value_to_normalize)) { |
|
37 | 37 | throw new EE_Validation_Error( |
38 | 38 | sprintf( |
39 | 39 | esc_html__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | } |
71 | 71 | // this really shouldn't ever happen because fields with a int normalization strategy |
72 | 72 | // should also have a int validation strategy, but in case it doesn't use the default |
73 | - if (! $validation_error_message) { |
|
73 | + if ( ! $validation_error_message) { |
|
74 | 74 | $default_validation_strategy = new EE_Int_Validation_Strategy(); |
75 | 75 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
76 | 76 | } |
@@ -10,88 +10,88 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Int_Normalization extends EE_Normalization_Strategy_Base |
12 | 12 | { |
13 | - /* |
|
13 | + /* |
|
14 | 14 | * regex pattern that matches for the following: |
15 | 15 | * * optional negative sign |
16 | 16 | * * one or more digits |
17 | 17 | */ |
18 | - const REGEX = '/^(-?)(\d+)(?:\.0+)?$/'; |
|
18 | + const REGEX = '/^(-?)(\d+)(?:\.0+)?$/'; |
|
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param string $value_to_normalize |
|
24 | - * @return int|mixed|string |
|
25 | - * @throws \EE_Validation_Error |
|
26 | - */ |
|
27 | - public function normalize($value_to_normalize) |
|
28 | - { |
|
29 | - if ($value_to_normalize === null) { |
|
30 | - return null; |
|
31 | - } |
|
32 | - if (is_int($value_to_normalize) || is_float($value_to_normalize)) { |
|
33 | - return (int) $value_to_normalize; |
|
34 | - } |
|
35 | - if (! is_string($value_to_normalize)) { |
|
36 | - throw new EE_Validation_Error( |
|
37 | - sprintf( |
|
38 | - esc_html__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
39 | - print_r($value_to_normalize, true), |
|
40 | - gettype($value_to_normalize) |
|
41 | - ) |
|
42 | - ); |
|
43 | - } |
|
44 | - $value_to_normalize = filter_var( |
|
45 | - $value_to_normalize, |
|
46 | - FILTER_SANITIZE_NUMBER_FLOAT, |
|
47 | - FILTER_FLAG_ALLOW_FRACTION |
|
48 | - ); |
|
49 | - if ($value_to_normalize === '') { |
|
50 | - return null; |
|
51 | - } |
|
52 | - $matches = array(); |
|
53 | - if (preg_match(EE_Int_Normalization::REGEX, $value_to_normalize, $matches)) { |
|
54 | - if (count($matches) === 3) { |
|
55 | - // if first match is the negative sign, |
|
56 | - // then the number needs to be multiplied by -1 to remain negative |
|
57 | - return $matches[1] === '-' |
|
58 | - ? (int) $matches[2] * -1 |
|
59 | - : (int) $matches[2]; |
|
60 | - } |
|
61 | - } |
|
62 | - // find if this input has a int validation strategy |
|
63 | - // in which case, use its message |
|
64 | - $validation_error_message = null; |
|
65 | - foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
66 | - if ($validation_strategy instanceof EE_Int_Validation_Strategy) { |
|
67 | - $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
68 | - } |
|
69 | - } |
|
70 | - // this really shouldn't ever happen because fields with a int normalization strategy |
|
71 | - // should also have a int validation strategy, but in case it doesn't use the default |
|
72 | - if (! $validation_error_message) { |
|
73 | - $default_validation_strategy = new EE_Int_Validation_Strategy(); |
|
74 | - $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
75 | - } |
|
76 | - throw new EE_Validation_Error($validation_error_message, 'numeric_only'); |
|
77 | - } |
|
22 | + /** |
|
23 | + * @param string $value_to_normalize |
|
24 | + * @return int|mixed|string |
|
25 | + * @throws \EE_Validation_Error |
|
26 | + */ |
|
27 | + public function normalize($value_to_normalize) |
|
28 | + { |
|
29 | + if ($value_to_normalize === null) { |
|
30 | + return null; |
|
31 | + } |
|
32 | + if (is_int($value_to_normalize) || is_float($value_to_normalize)) { |
|
33 | + return (int) $value_to_normalize; |
|
34 | + } |
|
35 | + if (! is_string($value_to_normalize)) { |
|
36 | + throw new EE_Validation_Error( |
|
37 | + sprintf( |
|
38 | + esc_html__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
39 | + print_r($value_to_normalize, true), |
|
40 | + gettype($value_to_normalize) |
|
41 | + ) |
|
42 | + ); |
|
43 | + } |
|
44 | + $value_to_normalize = filter_var( |
|
45 | + $value_to_normalize, |
|
46 | + FILTER_SANITIZE_NUMBER_FLOAT, |
|
47 | + FILTER_FLAG_ALLOW_FRACTION |
|
48 | + ); |
|
49 | + if ($value_to_normalize === '') { |
|
50 | + return null; |
|
51 | + } |
|
52 | + $matches = array(); |
|
53 | + if (preg_match(EE_Int_Normalization::REGEX, $value_to_normalize, $matches)) { |
|
54 | + if (count($matches) === 3) { |
|
55 | + // if first match is the negative sign, |
|
56 | + // then the number needs to be multiplied by -1 to remain negative |
|
57 | + return $matches[1] === '-' |
|
58 | + ? (int) $matches[2] * -1 |
|
59 | + : (int) $matches[2]; |
|
60 | + } |
|
61 | + } |
|
62 | + // find if this input has a int validation strategy |
|
63 | + // in which case, use its message |
|
64 | + $validation_error_message = null; |
|
65 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
66 | + if ($validation_strategy instanceof EE_Int_Validation_Strategy) { |
|
67 | + $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
68 | + } |
|
69 | + } |
|
70 | + // this really shouldn't ever happen because fields with a int normalization strategy |
|
71 | + // should also have a int validation strategy, but in case it doesn't use the default |
|
72 | + if (! $validation_error_message) { |
|
73 | + $default_validation_strategy = new EE_Int_Validation_Strategy(); |
|
74 | + $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
75 | + } |
|
76 | + throw new EE_Validation_Error($validation_error_message, 'numeric_only'); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * Converts the int into a string for use in teh html form |
|
83 | - * |
|
84 | - * @param int $normalized_value |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function unnormalize($normalized_value) |
|
88 | - { |
|
89 | - if ($normalized_value === null || $normalized_value === '') { |
|
90 | - return ''; |
|
91 | - } |
|
92 | - if (empty($normalized_value)) { |
|
93 | - return '0'; |
|
94 | - } |
|
95 | - return "$normalized_value"; |
|
96 | - } |
|
81 | + /** |
|
82 | + * Converts the int into a string for use in teh html form |
|
83 | + * |
|
84 | + * @param int $normalized_value |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function unnormalize($normalized_value) |
|
88 | + { |
|
89 | + if ($normalized_value === null || $normalized_value === '') { |
|
90 | + return ''; |
|
91 | + } |
|
92 | + if (empty($normalized_value)) { |
|
93 | + return '0'; |
|
94 | + } |
|
95 | + return "$normalized_value"; |
|
96 | + } |
|
97 | 97 | } |
@@ -14,17 +14,17 @@ |
||
14 | 14 | */ |
15 | 15 | class EE_Phone_Input extends EE_Text_Input |
16 | 16 | { |
17 | - /** |
|
18 | - * @param array $options |
|
19 | - */ |
|
20 | - public function __construct($options = array()) |
|
21 | - { |
|
22 | - $this->_add_validation_strategy( |
|
23 | - new EE_Text_Validation_Strategy( |
|
24 | - esc_html__('Please enter a valid phone number. Eg 123-456-7890 or 1234567890', 'event_espresso'), |
|
25 | - '~^(([\d]{10})|(^[\d]{3}-[\d]{3}-[\d]{4}))$~' |
|
26 | - ) |
|
27 | - ); |
|
28 | - parent::__construct($options); |
|
29 | - } |
|
17 | + /** |
|
18 | + * @param array $options |
|
19 | + */ |
|
20 | + public function __construct($options = array()) |
|
21 | + { |
|
22 | + $this->_add_validation_strategy( |
|
23 | + new EE_Text_Validation_Strategy( |
|
24 | + esc_html__('Please enter a valid phone number. Eg 123-456-7890 or 1234567890', 'event_espresso'), |
|
25 | + '~^(([\d]{10})|(^[\d]{3}-[\d]{3}-[\d]{4}))$~' |
|
26 | + ) |
|
27 | + ); |
|
28 | + parent::__construct($options); |
|
29 | + } |
|
30 | 30 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | ); |
75 | 75 | // make sure limit and caps are always set |
76 | 76 | $query_params = array_merge( |
77 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
77 | + array('limit' => 10, 'caps' => EEM_Base::caps_read_admin), |
|
78 | 78 | $query_params |
79 | 79 | ); |
80 | 80 | $this->_value_field_name = EEH_Array::is_set( |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | $values_for_options = (array) $value; |
156 | 156 | $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
157 | 157 | $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
158 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
159 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
158 | + $this->_extra_select_columns[] = $value_field->get_qualified_column().' AS '.$this->_value_field_name; |
|
159 | + $this->_extra_select_columns[] = $display_field->get_qualified_column().' AS '.$this->_display_field_name; |
|
160 | 160 | $display_values = $this->_get_model()->get_all_wpdb_results( |
161 | 161 | array( |
162 | 162 | array( |
163 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
163 | + $this->_value_field_name => array('IN', $values_for_options) |
|
164 | 164 | ) |
165 | 165 | ), |
166 | 166 | ARRAY_A, |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | if (is_array($select_options)) { |
171 | 171 | foreach ($display_values as $db_rows) { |
172 | 172 | $db_rows = (array) $db_rows; |
173 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
173 | + $select_options[$db_rows[$this->_value_field_name]] = apply_filters( |
|
174 | 174 | 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
175 | - $db_rows[ $this->_display_field_name ], |
|
175 | + $db_rows[$this->_display_field_name], |
|
176 | 176 | $db_rows |
177 | 177 | ); |
178 | 178 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | protected function _get_model() |
190 | 190 | { |
191 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
191 | + if ( ! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
192 | 192 | throw new EE_Error( |
193 | 193 | sprintf( |
194 | 194 | esc_html__( |
@@ -16,189 +16,189 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Select_Ajax_Model_Rest_Input extends EE_Form_Input_With_Options_Base |
18 | 18 | { |
19 | - /** |
|
20 | - * @var string $_model_name |
|
21 | - */ |
|
22 | - protected $_model_name; |
|
19 | + /** |
|
20 | + * @var string $_model_name |
|
21 | + */ |
|
22 | + protected $_model_name; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var string $_display_field_name |
|
26 | - */ |
|
27 | - protected $_display_field_name; |
|
24 | + /** |
|
25 | + * @var string $_display_field_name |
|
26 | + */ |
|
27 | + protected $_display_field_name; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var string $_value_field_name |
|
31 | - */ |
|
32 | - protected $_value_field_name; |
|
29 | + /** |
|
30 | + * @var string $_value_field_name |
|
31 | + */ |
|
32 | + protected $_value_field_name; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var array $_extra_select_columns |
|
36 | - */ |
|
37 | - protected $_extra_select_columns = array(); |
|
34 | + /** |
|
35 | + * @var array $_extra_select_columns |
|
36 | + */ |
|
37 | + protected $_extra_select_columns = array(); |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * @param array $input_settings { |
|
42 | - * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
43 | - * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
44 | - * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
45 | - * the string "where") |
|
46 | - * @type string $value_field_name the name of the model field on this model to |
|
47 | - * be used for the HTML select's option's values |
|
48 | - * @type string $display_field_name the name of the model field on this model |
|
49 | - * to be used for the HTML select's option's display text |
|
50 | - * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
51 | - * } |
|
52 | - * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
53 | - * } |
|
54 | - * @throws EE_Error |
|
55 | - * @throws InvalidArgumentException |
|
56 | - * @throws InvalidDataTypeException |
|
57 | - * @throws InvalidInterfaceException |
|
58 | - */ |
|
59 | - public function __construct($input_settings = array()) |
|
60 | - { |
|
61 | - // needed input settings: |
|
62 | - // select2_args |
|
63 | - $this->_model_name = EEH_Array::is_set( |
|
64 | - $input_settings, |
|
65 | - 'model_name', |
|
66 | - null |
|
67 | - ); |
|
68 | - $model = $this->_get_model(); |
|
69 | - $query_params = EEH_Array::is_set( |
|
70 | - $input_settings, |
|
71 | - 'query_params', |
|
72 | - array() |
|
73 | - ); |
|
74 | - // make sure limit and caps are always set |
|
75 | - $query_params = array_merge( |
|
76 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
77 | - $query_params |
|
78 | - ); |
|
79 | - $this->_value_field_name = EEH_Array::is_set( |
|
80 | - $input_settings, |
|
81 | - 'value_field_name', |
|
82 | - $model->primary_key_name() |
|
83 | - ); |
|
84 | - $this->_display_field_name = EEH_Array::is_set( |
|
85 | - $input_settings, |
|
86 | - 'display_field_name', |
|
87 | - $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
88 | - ); |
|
89 | - $this->_extra_select_columns = EEH_Array::is_set( |
|
90 | - $input_settings, |
|
91 | - 'extra_select_columns', |
|
92 | - array() |
|
93 | - ); |
|
94 | - $this->_add_validation_strategy( |
|
95 | - new EE_Model_Matching_Query_Validation_Strategy( |
|
96 | - '', |
|
97 | - $this->_model_name, |
|
98 | - $query_params, |
|
99 | - $this->_value_field_name |
|
100 | - ) |
|
101 | - ); |
|
102 | - // get resource endpoint |
|
103 | - $rest_controller = LoaderFactory::getLoader()->getNew( |
|
104 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
105 | - ); |
|
106 | - $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
107 | - $default_select2_args = array( |
|
108 | - 'ajax' => array( |
|
109 | - 'url' => $rest_controller->getVersionedLinkTo( |
|
110 | - EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
111 | - ), |
|
112 | - 'dataType' => 'json', |
|
113 | - 'delay' => '250', |
|
114 | - 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
115 | - 'data_interface_args' => array( |
|
116 | - 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
117 | - $query_params, |
|
118 | - $model |
|
119 | - ), |
|
120 | - 'display_field' => $this->_display_field_name, |
|
121 | - 'value_field' => $this->_value_field_name, |
|
122 | - 'nonce' => wp_create_nonce('wp_rest'), |
|
123 | - 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
124 | - ), |
|
125 | - ), |
|
126 | - 'cache' => true, |
|
127 | - 'width' => 'resolve' |
|
128 | - ); |
|
129 | - $select2_args = array_replace_recursive( |
|
130 | - $default_select2_args, |
|
131 | - (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
132 | - ); |
|
133 | - $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
134 | - parent::__construct(array(), $input_settings); |
|
135 | - } |
|
40 | + /** |
|
41 | + * @param array $input_settings { |
|
42 | + * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
43 | + * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
44 | + * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
45 | + * the string "where") |
|
46 | + * @type string $value_field_name the name of the model field on this model to |
|
47 | + * be used for the HTML select's option's values |
|
48 | + * @type string $display_field_name the name of the model field on this model |
|
49 | + * to be used for the HTML select's option's display text |
|
50 | + * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
51 | + * } |
|
52 | + * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
53 | + * } |
|
54 | + * @throws EE_Error |
|
55 | + * @throws InvalidArgumentException |
|
56 | + * @throws InvalidDataTypeException |
|
57 | + * @throws InvalidInterfaceException |
|
58 | + */ |
|
59 | + public function __construct($input_settings = array()) |
|
60 | + { |
|
61 | + // needed input settings: |
|
62 | + // select2_args |
|
63 | + $this->_model_name = EEH_Array::is_set( |
|
64 | + $input_settings, |
|
65 | + 'model_name', |
|
66 | + null |
|
67 | + ); |
|
68 | + $model = $this->_get_model(); |
|
69 | + $query_params = EEH_Array::is_set( |
|
70 | + $input_settings, |
|
71 | + 'query_params', |
|
72 | + array() |
|
73 | + ); |
|
74 | + // make sure limit and caps are always set |
|
75 | + $query_params = array_merge( |
|
76 | + array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
77 | + $query_params |
|
78 | + ); |
|
79 | + $this->_value_field_name = EEH_Array::is_set( |
|
80 | + $input_settings, |
|
81 | + 'value_field_name', |
|
82 | + $model->primary_key_name() |
|
83 | + ); |
|
84 | + $this->_display_field_name = EEH_Array::is_set( |
|
85 | + $input_settings, |
|
86 | + 'display_field_name', |
|
87 | + $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
88 | + ); |
|
89 | + $this->_extra_select_columns = EEH_Array::is_set( |
|
90 | + $input_settings, |
|
91 | + 'extra_select_columns', |
|
92 | + array() |
|
93 | + ); |
|
94 | + $this->_add_validation_strategy( |
|
95 | + new EE_Model_Matching_Query_Validation_Strategy( |
|
96 | + '', |
|
97 | + $this->_model_name, |
|
98 | + $query_params, |
|
99 | + $this->_value_field_name |
|
100 | + ) |
|
101 | + ); |
|
102 | + // get resource endpoint |
|
103 | + $rest_controller = LoaderFactory::getLoader()->getNew( |
|
104 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
105 | + ); |
|
106 | + $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
107 | + $default_select2_args = array( |
|
108 | + 'ajax' => array( |
|
109 | + 'url' => $rest_controller->getVersionedLinkTo( |
|
110 | + EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
111 | + ), |
|
112 | + 'dataType' => 'json', |
|
113 | + 'delay' => '250', |
|
114 | + 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
115 | + 'data_interface_args' => array( |
|
116 | + 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
117 | + $query_params, |
|
118 | + $model |
|
119 | + ), |
|
120 | + 'display_field' => $this->_display_field_name, |
|
121 | + 'value_field' => $this->_value_field_name, |
|
122 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
123 | + 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
124 | + ), |
|
125 | + ), |
|
126 | + 'cache' => true, |
|
127 | + 'width' => 'resolve' |
|
128 | + ); |
|
129 | + $select2_args = array_replace_recursive( |
|
130 | + $default_select2_args, |
|
131 | + (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
132 | + ); |
|
133 | + $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
134 | + parent::__construct(array(), $input_settings); |
|
135 | + } |
|
136 | 136 | |
137 | 137 | |
138 | 138 | |
139 | - /** |
|
140 | - * Before setting the raw value (usually because we're setting the default, |
|
141 | - * or we've received a form submission and this might be re-displayed to the user), |
|
142 | - * sets the options so that the current selections appear on initial display. |
|
143 | - * |
|
144 | - * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
145 | - * for validation, this input's options only affect DISPLAY and NOT validation, |
|
146 | - * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
147 | - * |
|
148 | - * @param mixed $value |
|
149 | - * @return void |
|
150 | - * @throws \EE_Error |
|
151 | - */ |
|
152 | - public function _set_raw_value($value) |
|
153 | - { |
|
154 | - $values_for_options = (array) $value; |
|
155 | - $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
156 | - $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
157 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
158 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
159 | - $display_values = $this->_get_model()->get_all_wpdb_results( |
|
160 | - array( |
|
161 | - array( |
|
162 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
163 | - ) |
|
164 | - ), |
|
165 | - ARRAY_A, |
|
166 | - implode(',', $this->_extra_select_columns) |
|
167 | - ); |
|
168 | - $select_options = array(); |
|
169 | - if (is_array($select_options)) { |
|
170 | - foreach ($display_values as $db_rows) { |
|
171 | - $db_rows = (array) $db_rows; |
|
172 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
173 | - 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
174 | - $db_rows[ $this->_display_field_name ], |
|
175 | - $db_rows |
|
176 | - ); |
|
177 | - } |
|
178 | - } |
|
179 | - $this->set_select_options($select_options); |
|
180 | - parent::_set_raw_value($value); |
|
181 | - } |
|
139 | + /** |
|
140 | + * Before setting the raw value (usually because we're setting the default, |
|
141 | + * or we've received a form submission and this might be re-displayed to the user), |
|
142 | + * sets the options so that the current selections appear on initial display. |
|
143 | + * |
|
144 | + * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
145 | + * for validation, this input's options only affect DISPLAY and NOT validation, |
|
146 | + * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
147 | + * |
|
148 | + * @param mixed $value |
|
149 | + * @return void |
|
150 | + * @throws \EE_Error |
|
151 | + */ |
|
152 | + public function _set_raw_value($value) |
|
153 | + { |
|
154 | + $values_for_options = (array) $value; |
|
155 | + $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
156 | + $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
157 | + $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
158 | + $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
159 | + $display_values = $this->_get_model()->get_all_wpdb_results( |
|
160 | + array( |
|
161 | + array( |
|
162 | + $this->_value_field_name => array( 'IN', $values_for_options ) |
|
163 | + ) |
|
164 | + ), |
|
165 | + ARRAY_A, |
|
166 | + implode(',', $this->_extra_select_columns) |
|
167 | + ); |
|
168 | + $select_options = array(); |
|
169 | + if (is_array($select_options)) { |
|
170 | + foreach ($display_values as $db_rows) { |
|
171 | + $db_rows = (array) $db_rows; |
|
172 | + $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
173 | + 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
174 | + $db_rows[ $this->_display_field_name ], |
|
175 | + $db_rows |
|
176 | + ); |
|
177 | + } |
|
178 | + } |
|
179 | + $this->set_select_options($select_options); |
|
180 | + parent::_set_raw_value($value); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
185 | - * @return EEM_Base |
|
186 | - * @throws EE_Error |
|
187 | - */ |
|
188 | - protected function _get_model() |
|
189 | - { |
|
190 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
191 | - throw new EE_Error( |
|
192 | - sprintf( |
|
193 | - esc_html__( |
|
194 | - '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
195 | - 'event_espresso' |
|
196 | - ), |
|
197 | - $this->_model_name |
|
198 | - ) |
|
199 | - ); |
|
200 | - } else { |
|
201 | - return EE_Registry::instance()->load_model($this->_model_name); |
|
202 | - } |
|
203 | - } |
|
183 | + /** |
|
184 | + * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
185 | + * @return EEM_Base |
|
186 | + * @throws EE_Error |
|
187 | + */ |
|
188 | + protected function _get_model() |
|
189 | + { |
|
190 | + if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
191 | + throw new EE_Error( |
|
192 | + sprintf( |
|
193 | + esc_html__( |
|
194 | + '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
195 | + 'event_espresso' |
|
196 | + ), |
|
197 | + $this->_model_name |
|
198 | + ) |
|
199 | + ); |
|
200 | + } else { |
|
201 | + return EE_Registry::instance()->load_model($this->_model_name); |
|
202 | + } |
|
203 | + } |
|
204 | 204 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | ), |
144 | 144 | ], |
145 | 145 | ]; |
146 | - $this->_model_relations = [ |
|
146 | + $this->_model_relations = [ |
|
147 | 147 | 'Registration' => new EE_Has_Many_Relation(), |
148 | 148 | 'Payment' => new EE_Has_Many_Relation(), |
149 | 149 | 'Status' => new EE_Belongs_To_Relation(), |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | ], |
212 | 212 | OBJECT, |
213 | 213 | [ |
214 | - 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
214 | + 'txnDate' => ['DATE('.$query_interval.')', '%s'], |
|
215 | 215 | 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
216 | 216 | ] |
217 | 217 | ); |
@@ -230,17 +230,17 @@ discard block |
||
230 | 230 | public function get_revenue_per_event_report($period = '-1 month') |
231 | 231 | { |
232 | 232 | global $wpdb; |
233 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
234 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
235 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
233 | + $transaction_table = $wpdb->prefix.'esp_transaction'; |
|
234 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
235 | + $registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
236 | 236 | $event_table = $wpdb->posts; |
237 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
237 | + $payment_table = $wpdb->prefix.'esp_payment'; |
|
238 | 238 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
239 | 239 | $approved_payment_status = EEM_Payment::status_id_approved; |
240 | 240 | $extra_event_on_join = ''; |
241 | 241 | // exclude events not authored by user if permissions in effect |
242 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
243 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
242 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
243 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | return $wpdb->get_results( |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
319 | 319 | { |
320 | 320 | EE_Error::doing_it_wrong( |
321 | - __CLASS__ . '::' . __FUNCTION__, |
|
321 | + __CLASS__.'::'.__FUNCTION__, |
|
322 | 322 | sprintf( |
323 | 323 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
324 | 324 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | $time_to_leave_alone |
391 | 391 | ); |
392 | 392 | // now that we have the ids to delete |
393 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
393 | + if ( ! empty($txn_ids) && is_array($txn_ids)) { |
|
394 | 394 | // first, make sure these TXN's are removed the "ee_locked_transactions" array |
395 | 395 | EEM_Transaction::unset_locked_transactions($txn_ids); |
396 | 396 | |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | // let's get deleting... |
404 | 404 | // We got the ids from the original query to get them FROM |
405 | 405 | // the db (which is sanitized) so no need to prepare them again. |
406 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
406 | + $query = $wpdb->prepare("DELETE FROM ".$this->table()." WHERE TXN_ID IN ( $format )", $txn_ids); |
|
407 | 407 | $deleted = $wpdb->query($query); |
408 | 408 | } |
409 | 409 | if ($deleted) { |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | $locked_transactions = get_option('ee_locked_transactions', []); |
428 | 428 | $update = false; |
429 | 429 | foreach ($transaction_IDs as $TXN_ID) { |
430 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
431 | - unset($locked_transactions[ $TXN_ID ]); |
|
430 | + if (isset($locked_transactions[$TXN_ID])) { |
|
431 | + unset($locked_transactions[$TXN_ID]); |
|
432 | 432 | $update = true; |
433 | 433 | } |
434 | 434 | } |
@@ -18,225 +18,225 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class EEM_Transaction extends EEM_Base |
20 | 20 | { |
21 | - protected static ?EEM_Transaction $_instance = null; |
|
22 | - |
|
23 | - /** |
|
24 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
25 | - * but payment is pending. This is the state for transactions where payment is promised |
|
26 | - * from an offline gateway. |
|
27 | - */ |
|
28 | - // const open_status_code = 'TPN'; |
|
29 | - |
|
30 | - /** |
|
31 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
32 | - * either due to a technical reason (server or computer crash during registration), |
|
33 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
34 | - */ |
|
35 | - const failed_status_code = 'TFL'; |
|
36 | - |
|
37 | - /** |
|
38 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
39 | - * either due to a technical reason (server or computer crash during registration), |
|
40 | - * or due to an abandoned cart after registrant chose not to complete the registration process |
|
41 | - * HOWEVER... |
|
42 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
43 | - * registrant |
|
44 | - */ |
|
45 | - const abandoned_status_code = 'TAB'; |
|
46 | - |
|
47 | - /** |
|
48 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
49 | - * meaning that monies are still owing: TXN_paid < TXN_total |
|
50 | - */ |
|
51 | - const incomplete_status_code = 'TIN'; |
|
52 | - |
|
53 | - /** |
|
54 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
55 | - * meaning that NO monies are owing: TXN_paid == TXN_total |
|
56 | - */ |
|
57 | - const complete_status_code = 'TCM'; |
|
58 | - |
|
59 | - /** |
|
60 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
61 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
62 | - */ |
|
63 | - const overpaid_status_code = 'TOP'; |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * private constructor to prevent direct creation |
|
68 | - * |
|
69 | - * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
70 | - * any incoming timezone data that gets saved). Note this just sends the timezone info |
|
71 | - * to the date time model field objects. Default is NULL (and will be assumed using |
|
72 | - * the set timezone in the 'timezone_string' wp option) |
|
73 | - * @throws EE_Error |
|
74 | - * @throws ReflectionException |
|
75 | - */ |
|
76 | - protected function __construct(?string $timezone = '') |
|
77 | - { |
|
78 | - $this->singular_item = esc_html__('Transaction', 'event_espresso'); |
|
79 | - $this->plural_item = esc_html__('Transactions', 'event_espresso'); |
|
80 | - |
|
81 | - $this->_tables = [ |
|
82 | - 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID'), |
|
83 | - ]; |
|
84 | - $this->_fields = [ |
|
85 | - 'TransactionTable' => [ |
|
86 | - 'TXN_ID' => new EE_Primary_Key_Int_Field( |
|
87 | - 'TXN_ID', esc_html__('Transaction ID', 'event_espresso') |
|
88 | - ), |
|
89 | - 'TXN_timestamp' => new EE_Datetime_Field( |
|
90 | - 'TXN_timestamp', |
|
91 | - esc_html__('date when transaction was created', 'event_espresso'), |
|
92 | - false, |
|
93 | - EE_Datetime_Field::now, |
|
94 | - $timezone |
|
95 | - ), |
|
96 | - 'TXN_total' => new EE_Money_Field( |
|
97 | - 'TXN_total', |
|
98 | - esc_html__('Total value of Transaction', 'event_espresso'), |
|
99 | - false, |
|
100 | - 0 |
|
101 | - ), |
|
102 | - 'TXN_paid' => new EE_Money_Field( |
|
103 | - 'TXN_paid', |
|
104 | - esc_html__('Amount paid towards transaction to date', 'event_espresso'), |
|
105 | - false, |
|
106 | - 0 |
|
107 | - ), |
|
108 | - 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
109 | - 'STS_ID', |
|
110 | - esc_html__('Status ID', 'event_espresso'), |
|
111 | - false, |
|
112 | - EEM_Transaction::failed_status_code, |
|
113 | - 'Status' |
|
114 | - ), |
|
115 | - 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
116 | - 'TXN_session_data', |
|
117 | - esc_html__('Serialized session data', 'event_espresso'), |
|
118 | - true, |
|
119 | - '' |
|
120 | - ), |
|
121 | - 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
122 | - 'TXN_hash_salt', |
|
123 | - esc_html__('Transaction Hash Salt', 'event_espresso'), |
|
124 | - true, |
|
125 | - '' |
|
126 | - ), |
|
127 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
128 | - 'PMD_ID', |
|
129 | - esc_html__("Last Used Payment Method", 'event_espresso'), |
|
130 | - true, |
|
131 | - null, |
|
132 | - 'Payment_Method' |
|
133 | - ), |
|
134 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
135 | - 'TXN_reg_steps', |
|
136 | - esc_html__('Registration Steps', 'event_espresso'), |
|
137 | - false, |
|
138 | - [] |
|
139 | - ), |
|
140 | - ], |
|
141 | - ]; |
|
142 | - $this->_model_relations = [ |
|
143 | - 'Registration' => new EE_Has_Many_Relation(), |
|
144 | - 'Payment' => new EE_Has_Many_Relation(), |
|
145 | - 'Status' => new EE_Belongs_To_Relation(), |
|
146 | - 'Line_Item' => new EE_Has_Many_Relation(false), |
|
147 | - // you can delete a transaction without needing to delete its line items |
|
148 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
149 | - 'Message' => new EE_Has_Many_Relation(), |
|
150 | - ]; |
|
151 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
152 | - parent::__construct($timezone); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * txn_status_array |
|
158 | - * get list of transaction statuses |
|
159 | - * |
|
160 | - * @access public |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public static function txn_status_array() |
|
164 | - { |
|
165 | - return apply_filters( |
|
166 | - 'FHEE__EEM_Transaction__txn_status_array', |
|
167 | - [ |
|
168 | - EEM_Transaction::overpaid_status_code, |
|
169 | - EEM_Transaction::complete_status_code, |
|
170 | - EEM_Transaction::incomplete_status_code, |
|
171 | - EEM_Transaction::abandoned_status_code, |
|
172 | - EEM_Transaction::failed_status_code, |
|
173 | - ] |
|
174 | - ); |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * get the revenue per day for the Transaction Admin page Reports Tab |
|
180 | - * |
|
181 | - * @access public |
|
182 | - * @param string $period |
|
183 | - * @return stdClass[] |
|
184 | - * @throws EE_Error |
|
185 | - * @throws EE_Error |
|
186 | - */ |
|
187 | - public function get_revenue_per_day_report($period = '-1 month') |
|
188 | - { |
|
189 | - $sql_date = $this->convert_datetime_for_query( |
|
190 | - 'TXN_timestamp', |
|
191 | - date('Y-m-d H:i:s', strtotime($period)), |
|
192 | - 'Y-m-d H:i:s', |
|
193 | - 'UTC' |
|
194 | - ); |
|
195 | - |
|
196 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
197 | - |
|
198 | - return $this->_get_all_wpdb_results( |
|
199 | - [ |
|
200 | - [ |
|
201 | - 'TXN_timestamp' => ['>=', $sql_date], |
|
202 | - ], |
|
203 | - 'group_by' => 'txnDate', |
|
204 | - 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
205 | - ], |
|
206 | - OBJECT, |
|
207 | - [ |
|
208 | - 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
209 | - 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
|
210 | - ] |
|
211 | - ); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * get the revenue per event for the Transaction Admin page Reports Tab |
|
217 | - * |
|
218 | - * @access public |
|
219 | - * @param string $period |
|
220 | - * @return EE_Transaction[] |
|
221 | - */ |
|
222 | - public function get_revenue_per_event_report($period = '-1 month') |
|
223 | - { |
|
224 | - global $wpdb; |
|
225 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
226 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
227 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
228 | - $event_table = $wpdb->posts; |
|
229 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
230 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
231 | - $approved_payment_status = EEM_Payment::status_id_approved; |
|
232 | - $extra_event_on_join = ''; |
|
233 | - // exclude events not authored by user if permissions in effect |
|
234 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
235 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
236 | - } |
|
237 | - |
|
238 | - return $wpdb->get_results( |
|
239 | - "SELECT |
|
21 | + protected static ?EEM_Transaction $_instance = null; |
|
22 | + |
|
23 | + /** |
|
24 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
25 | + * but payment is pending. This is the state for transactions where payment is promised |
|
26 | + * from an offline gateway. |
|
27 | + */ |
|
28 | + // const open_status_code = 'TPN'; |
|
29 | + |
|
30 | + /** |
|
31 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
32 | + * either due to a technical reason (server or computer crash during registration), |
|
33 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
34 | + */ |
|
35 | + const failed_status_code = 'TFL'; |
|
36 | + |
|
37 | + /** |
|
38 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
39 | + * either due to a technical reason (server or computer crash during registration), |
|
40 | + * or due to an abandoned cart after registrant chose not to complete the registration process |
|
41 | + * HOWEVER... |
|
42 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
43 | + * registrant |
|
44 | + */ |
|
45 | + const abandoned_status_code = 'TAB'; |
|
46 | + |
|
47 | + /** |
|
48 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
49 | + * meaning that monies are still owing: TXN_paid < TXN_total |
|
50 | + */ |
|
51 | + const incomplete_status_code = 'TIN'; |
|
52 | + |
|
53 | + /** |
|
54 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
55 | + * meaning that NO monies are owing: TXN_paid == TXN_total |
|
56 | + */ |
|
57 | + const complete_status_code = 'TCM'; |
|
58 | + |
|
59 | + /** |
|
60 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
61 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
62 | + */ |
|
63 | + const overpaid_status_code = 'TOP'; |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * private constructor to prevent direct creation |
|
68 | + * |
|
69 | + * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
70 | + * any incoming timezone data that gets saved). Note this just sends the timezone info |
|
71 | + * to the date time model field objects. Default is NULL (and will be assumed using |
|
72 | + * the set timezone in the 'timezone_string' wp option) |
|
73 | + * @throws EE_Error |
|
74 | + * @throws ReflectionException |
|
75 | + */ |
|
76 | + protected function __construct(?string $timezone = '') |
|
77 | + { |
|
78 | + $this->singular_item = esc_html__('Transaction', 'event_espresso'); |
|
79 | + $this->plural_item = esc_html__('Transactions', 'event_espresso'); |
|
80 | + |
|
81 | + $this->_tables = [ |
|
82 | + 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID'), |
|
83 | + ]; |
|
84 | + $this->_fields = [ |
|
85 | + 'TransactionTable' => [ |
|
86 | + 'TXN_ID' => new EE_Primary_Key_Int_Field( |
|
87 | + 'TXN_ID', esc_html__('Transaction ID', 'event_espresso') |
|
88 | + ), |
|
89 | + 'TXN_timestamp' => new EE_Datetime_Field( |
|
90 | + 'TXN_timestamp', |
|
91 | + esc_html__('date when transaction was created', 'event_espresso'), |
|
92 | + false, |
|
93 | + EE_Datetime_Field::now, |
|
94 | + $timezone |
|
95 | + ), |
|
96 | + 'TXN_total' => new EE_Money_Field( |
|
97 | + 'TXN_total', |
|
98 | + esc_html__('Total value of Transaction', 'event_espresso'), |
|
99 | + false, |
|
100 | + 0 |
|
101 | + ), |
|
102 | + 'TXN_paid' => new EE_Money_Field( |
|
103 | + 'TXN_paid', |
|
104 | + esc_html__('Amount paid towards transaction to date', 'event_espresso'), |
|
105 | + false, |
|
106 | + 0 |
|
107 | + ), |
|
108 | + 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
109 | + 'STS_ID', |
|
110 | + esc_html__('Status ID', 'event_espresso'), |
|
111 | + false, |
|
112 | + EEM_Transaction::failed_status_code, |
|
113 | + 'Status' |
|
114 | + ), |
|
115 | + 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
116 | + 'TXN_session_data', |
|
117 | + esc_html__('Serialized session data', 'event_espresso'), |
|
118 | + true, |
|
119 | + '' |
|
120 | + ), |
|
121 | + 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
122 | + 'TXN_hash_salt', |
|
123 | + esc_html__('Transaction Hash Salt', 'event_espresso'), |
|
124 | + true, |
|
125 | + '' |
|
126 | + ), |
|
127 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
128 | + 'PMD_ID', |
|
129 | + esc_html__("Last Used Payment Method", 'event_espresso'), |
|
130 | + true, |
|
131 | + null, |
|
132 | + 'Payment_Method' |
|
133 | + ), |
|
134 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
135 | + 'TXN_reg_steps', |
|
136 | + esc_html__('Registration Steps', 'event_espresso'), |
|
137 | + false, |
|
138 | + [] |
|
139 | + ), |
|
140 | + ], |
|
141 | + ]; |
|
142 | + $this->_model_relations = [ |
|
143 | + 'Registration' => new EE_Has_Many_Relation(), |
|
144 | + 'Payment' => new EE_Has_Many_Relation(), |
|
145 | + 'Status' => new EE_Belongs_To_Relation(), |
|
146 | + 'Line_Item' => new EE_Has_Many_Relation(false), |
|
147 | + // you can delete a transaction without needing to delete its line items |
|
148 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
149 | + 'Message' => new EE_Has_Many_Relation(), |
|
150 | + ]; |
|
151 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
152 | + parent::__construct($timezone); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * txn_status_array |
|
158 | + * get list of transaction statuses |
|
159 | + * |
|
160 | + * @access public |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public static function txn_status_array() |
|
164 | + { |
|
165 | + return apply_filters( |
|
166 | + 'FHEE__EEM_Transaction__txn_status_array', |
|
167 | + [ |
|
168 | + EEM_Transaction::overpaid_status_code, |
|
169 | + EEM_Transaction::complete_status_code, |
|
170 | + EEM_Transaction::incomplete_status_code, |
|
171 | + EEM_Transaction::abandoned_status_code, |
|
172 | + EEM_Transaction::failed_status_code, |
|
173 | + ] |
|
174 | + ); |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * get the revenue per day for the Transaction Admin page Reports Tab |
|
180 | + * |
|
181 | + * @access public |
|
182 | + * @param string $period |
|
183 | + * @return stdClass[] |
|
184 | + * @throws EE_Error |
|
185 | + * @throws EE_Error |
|
186 | + */ |
|
187 | + public function get_revenue_per_day_report($period = '-1 month') |
|
188 | + { |
|
189 | + $sql_date = $this->convert_datetime_for_query( |
|
190 | + 'TXN_timestamp', |
|
191 | + date('Y-m-d H:i:s', strtotime($period)), |
|
192 | + 'Y-m-d H:i:s', |
|
193 | + 'UTC' |
|
194 | + ); |
|
195 | + |
|
196 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
197 | + |
|
198 | + return $this->_get_all_wpdb_results( |
|
199 | + [ |
|
200 | + [ |
|
201 | + 'TXN_timestamp' => ['>=', $sql_date], |
|
202 | + ], |
|
203 | + 'group_by' => 'txnDate', |
|
204 | + 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
205 | + ], |
|
206 | + OBJECT, |
|
207 | + [ |
|
208 | + 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
209 | + 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
|
210 | + ] |
|
211 | + ); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * get the revenue per event for the Transaction Admin page Reports Tab |
|
217 | + * |
|
218 | + * @access public |
|
219 | + * @param string $period |
|
220 | + * @return EE_Transaction[] |
|
221 | + */ |
|
222 | + public function get_revenue_per_event_report($period = '-1 month') |
|
223 | + { |
|
224 | + global $wpdb; |
|
225 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
226 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
227 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
228 | + $event_table = $wpdb->posts; |
|
229 | + $payment_table = $wpdb->prefix . 'esp_payment'; |
|
230 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
231 | + $approved_payment_status = EEM_Payment::status_id_approved; |
|
232 | + $extra_event_on_join = ''; |
|
233 | + // exclude events not authored by user if permissions in effect |
|
234 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
235 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
236 | + } |
|
237 | + |
|
238 | + return $wpdb->get_results( |
|
239 | + "SELECT |
|
240 | 240 | Transaction_Event.event_name AS event_name, |
241 | 241 | SUM(Transaction_Event.paid) AS revenue |
242 | 242 | FROM |
@@ -264,232 +264,232 @@ discard block |
||
264 | 264 | $extra_event_on_join |
265 | 265 | ) AS Transaction_Event |
266 | 266 | GROUP BY event_name" |
267 | - ); |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
273 | - * request global variable. Either way, tries to find the current transaction (through |
|
274 | - * the registration pointed to by reg_url_link), if not returns null |
|
275 | - * |
|
276 | - * @param string $reg_url_link |
|
277 | - * @return EE_Transaction |
|
278 | - * @throws EE_Error |
|
279 | - */ |
|
280 | - public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
281 | - { |
|
282 | - if (empty($reg_url_link)) { |
|
283 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
284 | - $reg_url_link = $request->getRequestParam('e_reg_url_link'); |
|
285 | - } |
|
286 | - return $this->get_one( |
|
287 | - [ |
|
288 | - [ |
|
289 | - 'Registration.REG_url_link' => $reg_url_link, |
|
290 | - ], |
|
291 | - ] |
|
292 | - ); |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * Updates the provided EE_Transaction with all the applicable payments |
|
298 | - * (or fetch the EE_Transaction from its ID) |
|
299 | - * |
|
300 | - * @param EE_Transaction|int $transaction_obj_or_id |
|
301 | - * @param boolean $save_txn whether or not to save the transaction during this function call |
|
302 | - * @return array |
|
303 | - * @throws EE_Error |
|
304 | - * @throws ReflectionException |
|
305 | - * @deprecated |
|
306 | - */ |
|
307 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
308 | - { |
|
309 | - EE_Error::doing_it_wrong( |
|
310 | - __CLASS__ . '::' . __FUNCTION__, |
|
311 | - sprintf( |
|
312 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
313 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
314 | - ), |
|
315 | - '4.6.0' |
|
316 | - ); |
|
317 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
318 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
319 | - |
|
320 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
321 | - $this->ensure_is_obj($transaction_obj_or_id) |
|
322 | - ); |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
328 | - * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
329 | - * and so we only use wpdb directly and only do minimal joins. |
|
330 | - * Transactions are considered "junk" if they're failed for longer than a week. |
|
331 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
332 | - * it, it's probably not junk (regardless of what status it has). |
|
333 | - * The downside to this approach is that is addons are listening for object deletions |
|
334 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
335 | - * to catch these types of deletions. |
|
336 | - * |
|
337 | - * @return int |
|
338 | - * @throws EE_Error |
|
339 | - * @throws EE_Error |
|
340 | - * @global WPDB $wpdb |
|
341 | - */ |
|
342 | - public function delete_junk_transactions() |
|
343 | - { |
|
344 | - global $wpdb; |
|
345 | - $deleted = false; |
|
346 | - $time_to_leave_alone = (int) apply_filters( |
|
347 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
348 | - WEEK_IN_SECONDS |
|
349 | - ); |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
354 | - * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
355 | - * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
356 | - */ |
|
357 | - $ids_query = apply_filters( |
|
358 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
359 | - [ |
|
360 | - 0 => [ |
|
361 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
362 | - 'Payment.PAY_ID' => ['IS NULL'], |
|
363 | - 'TXN_timestamp' => ['<', time() - $time_to_leave_alone], |
|
364 | - ], |
|
365 | - 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
366 | - 'limit' => 1000, |
|
367 | - ], |
|
368 | - $time_to_leave_alone |
|
369 | - ); |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
374 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
375 | - */ |
|
376 | - $txn_ids = apply_filters( |
|
377 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
378 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
379 | - $time_to_leave_alone |
|
380 | - ); |
|
381 | - // now that we have the ids to delete |
|
382 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
383 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
384 | - EEM_Transaction::unset_locked_transactions($txn_ids); |
|
385 | - |
|
386 | - // Create IDs placeholder. |
|
387 | - $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
388 | - |
|
389 | - // Glue it together to use inside $wpdb->prepare. |
|
390 | - $format = implode(', ', $placeholders); |
|
391 | - |
|
392 | - // let's get deleting... |
|
393 | - // We got the ids from the original query to get them FROM |
|
394 | - // the db (which is sanitized) so no need to prepare them again. |
|
395 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
396 | - $deleted = $wpdb->query($query); |
|
397 | - } |
|
398 | - if ($deleted) { |
|
399 | - /** |
|
400 | - * Allows code to do something after the transactions have been deleted. |
|
401 | - */ |
|
402 | - do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
403 | - } |
|
404 | - |
|
405 | - return $deleted; |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * @param array $transaction_IDs |
|
411 | - * @return bool |
|
412 | - */ |
|
413 | - public static function unset_locked_transactions(array $transaction_IDs) |
|
414 | - { |
|
415 | - $locked_transactions = get_option('ee_locked_transactions', []); |
|
416 | - $update = false; |
|
417 | - foreach ($transaction_IDs as $TXN_ID) { |
|
418 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
419 | - unset($locked_transactions[ $TXN_ID ]); |
|
420 | - $update = true; |
|
421 | - } |
|
422 | - } |
|
423 | - if ($update) { |
|
424 | - update_option('ee_locked_transactions', $locked_transactions); |
|
425 | - } |
|
426 | - |
|
427 | - return $update; |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * returns an array of EE_Transaction objects whose timestamp is greater than |
|
433 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
434 | - * |
|
435 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
436 | - * @throws EE_Error |
|
437 | - * @throws InvalidArgumentException |
|
438 | - * @throws InvalidDataTypeException |
|
439 | - * @throws InvalidInterfaceException |
|
440 | - */ |
|
441 | - public function get_transactions_in_progress() |
|
442 | - { |
|
443 | - return $this->_get_transactions_in_progress(); |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * returns an array of EE_Transaction objects whose timestamp is less than |
|
449 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
450 | - * |
|
451 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
452 | - * @throws EE_Error |
|
453 | - * @throws InvalidArgumentException |
|
454 | - * @throws InvalidDataTypeException |
|
455 | - * @throws InvalidInterfaceException |
|
456 | - */ |
|
457 | - public function get_transactions_not_in_progress() |
|
458 | - { |
|
459 | - return $this->_get_transactions_in_progress('<='); |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * @param string $comparison |
|
465 | - * @return EE_Transaction[] |
|
466 | - * @throws EE_Error |
|
467 | - * @throws InvalidArgumentException |
|
468 | - * @throws InvalidDataTypeException |
|
469 | - * @throws InvalidInterfaceException |
|
470 | - */ |
|
471 | - private function _get_transactions_in_progress($comparison = '>=') |
|
472 | - { |
|
473 | - $comparison = $comparison === '>=' || $comparison === '<=' |
|
474 | - ? $comparison |
|
475 | - : '>='; |
|
476 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
477 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
478 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
479 | - ); |
|
480 | - return $this->get_all( |
|
481 | - [ |
|
482 | - [ |
|
483 | - 'TXN_timestamp' => [ |
|
484 | - $comparison, |
|
485 | - $session_lifespan->expiration(), |
|
486 | - ], |
|
487 | - 'STS_ID' => [ |
|
488 | - '!=', |
|
489 | - EEM_Transaction::complete_status_code, |
|
490 | - ], |
|
491 | - ], |
|
492 | - ] |
|
493 | - ); |
|
494 | - } |
|
267 | + ); |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
273 | + * request global variable. Either way, tries to find the current transaction (through |
|
274 | + * the registration pointed to by reg_url_link), if not returns null |
|
275 | + * |
|
276 | + * @param string $reg_url_link |
|
277 | + * @return EE_Transaction |
|
278 | + * @throws EE_Error |
|
279 | + */ |
|
280 | + public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
281 | + { |
|
282 | + if (empty($reg_url_link)) { |
|
283 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
284 | + $reg_url_link = $request->getRequestParam('e_reg_url_link'); |
|
285 | + } |
|
286 | + return $this->get_one( |
|
287 | + [ |
|
288 | + [ |
|
289 | + 'Registration.REG_url_link' => $reg_url_link, |
|
290 | + ], |
|
291 | + ] |
|
292 | + ); |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * Updates the provided EE_Transaction with all the applicable payments |
|
298 | + * (or fetch the EE_Transaction from its ID) |
|
299 | + * |
|
300 | + * @param EE_Transaction|int $transaction_obj_or_id |
|
301 | + * @param boolean $save_txn whether or not to save the transaction during this function call |
|
302 | + * @return array |
|
303 | + * @throws EE_Error |
|
304 | + * @throws ReflectionException |
|
305 | + * @deprecated |
|
306 | + */ |
|
307 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
308 | + { |
|
309 | + EE_Error::doing_it_wrong( |
|
310 | + __CLASS__ . '::' . __FUNCTION__, |
|
311 | + sprintf( |
|
312 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
313 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
314 | + ), |
|
315 | + '4.6.0' |
|
316 | + ); |
|
317 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
318 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
319 | + |
|
320 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
321 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
322 | + ); |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
328 | + * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
329 | + * and so we only use wpdb directly and only do minimal joins. |
|
330 | + * Transactions are considered "junk" if they're failed for longer than a week. |
|
331 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
332 | + * it, it's probably not junk (regardless of what status it has). |
|
333 | + * The downside to this approach is that is addons are listening for object deletions |
|
334 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
335 | + * to catch these types of deletions. |
|
336 | + * |
|
337 | + * @return int |
|
338 | + * @throws EE_Error |
|
339 | + * @throws EE_Error |
|
340 | + * @global WPDB $wpdb |
|
341 | + */ |
|
342 | + public function delete_junk_transactions() |
|
343 | + { |
|
344 | + global $wpdb; |
|
345 | + $deleted = false; |
|
346 | + $time_to_leave_alone = (int) apply_filters( |
|
347 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
348 | + WEEK_IN_SECONDS |
|
349 | + ); |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
354 | + * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
355 | + * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
356 | + */ |
|
357 | + $ids_query = apply_filters( |
|
358 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
359 | + [ |
|
360 | + 0 => [ |
|
361 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
362 | + 'Payment.PAY_ID' => ['IS NULL'], |
|
363 | + 'TXN_timestamp' => ['<', time() - $time_to_leave_alone], |
|
364 | + ], |
|
365 | + 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
366 | + 'limit' => 1000, |
|
367 | + ], |
|
368 | + $time_to_leave_alone |
|
369 | + ); |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
374 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
375 | + */ |
|
376 | + $txn_ids = apply_filters( |
|
377 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
378 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
379 | + $time_to_leave_alone |
|
380 | + ); |
|
381 | + // now that we have the ids to delete |
|
382 | + if (! empty($txn_ids) && is_array($txn_ids)) { |
|
383 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
384 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
385 | + |
|
386 | + // Create IDs placeholder. |
|
387 | + $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
388 | + |
|
389 | + // Glue it together to use inside $wpdb->prepare. |
|
390 | + $format = implode(', ', $placeholders); |
|
391 | + |
|
392 | + // let's get deleting... |
|
393 | + // We got the ids from the original query to get them FROM |
|
394 | + // the db (which is sanitized) so no need to prepare them again. |
|
395 | + $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
396 | + $deleted = $wpdb->query($query); |
|
397 | + } |
|
398 | + if ($deleted) { |
|
399 | + /** |
|
400 | + * Allows code to do something after the transactions have been deleted. |
|
401 | + */ |
|
402 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
403 | + } |
|
404 | + |
|
405 | + return $deleted; |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * @param array $transaction_IDs |
|
411 | + * @return bool |
|
412 | + */ |
|
413 | + public static function unset_locked_transactions(array $transaction_IDs) |
|
414 | + { |
|
415 | + $locked_transactions = get_option('ee_locked_transactions', []); |
|
416 | + $update = false; |
|
417 | + foreach ($transaction_IDs as $TXN_ID) { |
|
418 | + if (isset($locked_transactions[ $TXN_ID ])) { |
|
419 | + unset($locked_transactions[ $TXN_ID ]); |
|
420 | + $update = true; |
|
421 | + } |
|
422 | + } |
|
423 | + if ($update) { |
|
424 | + update_option('ee_locked_transactions', $locked_transactions); |
|
425 | + } |
|
426 | + |
|
427 | + return $update; |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * returns an array of EE_Transaction objects whose timestamp is greater than |
|
433 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
434 | + * |
|
435 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
436 | + * @throws EE_Error |
|
437 | + * @throws InvalidArgumentException |
|
438 | + * @throws InvalidDataTypeException |
|
439 | + * @throws InvalidInterfaceException |
|
440 | + */ |
|
441 | + public function get_transactions_in_progress() |
|
442 | + { |
|
443 | + return $this->_get_transactions_in_progress(); |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * returns an array of EE_Transaction objects whose timestamp is less than |
|
449 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
450 | + * |
|
451 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
452 | + * @throws EE_Error |
|
453 | + * @throws InvalidArgumentException |
|
454 | + * @throws InvalidDataTypeException |
|
455 | + * @throws InvalidInterfaceException |
|
456 | + */ |
|
457 | + public function get_transactions_not_in_progress() |
|
458 | + { |
|
459 | + return $this->_get_transactions_in_progress('<='); |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * @param string $comparison |
|
465 | + * @return EE_Transaction[] |
|
466 | + * @throws EE_Error |
|
467 | + * @throws InvalidArgumentException |
|
468 | + * @throws InvalidDataTypeException |
|
469 | + * @throws InvalidInterfaceException |
|
470 | + */ |
|
471 | + private function _get_transactions_in_progress($comparison = '>=') |
|
472 | + { |
|
473 | + $comparison = $comparison === '>=' || $comparison === '<=' |
|
474 | + ? $comparison |
|
475 | + : '>='; |
|
476 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
477 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
478 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
479 | + ); |
|
480 | + return $this->get_all( |
|
481 | + [ |
|
482 | + [ |
|
483 | + 'TXN_timestamp' => [ |
|
484 | + $comparison, |
|
485 | + $session_lifespan->expiration(), |
|
486 | + ], |
|
487 | + 'STS_ID' => [ |
|
488 | + '!=', |
|
489 | + EEM_Transaction::complete_status_code, |
|
490 | + ], |
|
491 | + ], |
|
492 | + ] |
|
493 | + ); |
|
494 | + } |
|
495 | 495 | } |
@@ -3,36 +3,36 @@ |
||
3 | 3 | class EE_Foreign_Key_Int_Field extends EE_Foreign_Key_Field_Base |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * @param string $table_column name fo column for field |
|
8 | - * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
9 | - * @param boolean $nullable |
|
10 | - * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
11 | - * dbe a string |
|
12 | - * @param string|string[] $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
13 | - * "EEM_" |
|
14 | - */ |
|
15 | - public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
16 | - { |
|
17 | - parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
18 | - $this->setSchemaType('integer'); |
|
19 | - } |
|
6 | + /** |
|
7 | + * @param string $table_column name fo column for field |
|
8 | + * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
9 | + * @param boolean $nullable |
|
10 | + * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
11 | + * dbe a string |
|
12 | + * @param string|string[] $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
13 | + * "EEM_" |
|
14 | + */ |
|
15 | + public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
16 | + { |
|
17 | + parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
18 | + $this->setSchemaType('integer'); |
|
19 | + } |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
24 | - * @return int |
|
25 | - */ |
|
26 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | - { |
|
28 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
29 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
30 | - } |
|
31 | - return absint($value_inputted_for_field_on_model_object); |
|
32 | - } |
|
22 | + /** |
|
23 | + * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
24 | + * @return int |
|
25 | + */ |
|
26 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | + { |
|
28 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
29 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
30 | + } |
|
31 | + return absint($value_inputted_for_field_on_model_object); |
|
32 | + } |
|
33 | 33 | |
34 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
35 | - { |
|
36 | - return intval($value_found_in_db_for_model_object); |
|
37 | - } |
|
34 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
35 | + { |
|
36 | + return intval($value_found_in_db_for_model_object); |
|
37 | + } |
|
38 | 38 | } |
@@ -13,39 +13,39 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_WP_User_Field extends EE_Foreign_Key_Int_Field |
15 | 15 | { |
16 | - /** |
|
17 | - * No need to provide a default or the model pointed to- the default is |
|
18 | - * always get_current_user_id() and the model pointed to is always WP_User |
|
19 | - * |
|
20 | - * @param string $table_column name fo column for field |
|
21 | - * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
22 | - * @param boolean $nullable |
|
23 | - */ |
|
24 | - public function __construct($table_column, $nicename, $nullable) |
|
25 | - { |
|
26 | - parent::__construct($table_column, $nicename, $nullable, null, 'WP_User'); |
|
27 | - } |
|
16 | + /** |
|
17 | + * No need to provide a default or the model pointed to- the default is |
|
18 | + * always get_current_user_id() and the model pointed to is always WP_User |
|
19 | + * |
|
20 | + * @param string $table_column name fo column for field |
|
21 | + * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
22 | + * @param boolean $nullable |
|
23 | + */ |
|
24 | + public function __construct($table_column, $nicename, $nullable) |
|
25 | + { |
|
26 | + parent::__construct($table_column, $nicename, $nullable, null, 'WP_User'); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Gets the default which is always the current user. This can't be set when initially |
|
31 | - * constructing the model field because that's done before $current_user is set |
|
32 | - * |
|
33 | - * @return mixed |
|
34 | - */ |
|
35 | - public function get_default_value() |
|
36 | - { |
|
37 | - if (did_action('init')) { |
|
38 | - return get_current_user_id(); |
|
39 | - } else { |
|
40 | - EE_Error::doing_it_wrong( |
|
41 | - 'EE_WP_User_Field::get_default_value', |
|
42 | - esc_html__( |
|
43 | - 'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - '4.6.20' |
|
47 | - ); |
|
48 | - return 1; |
|
49 | - } |
|
50 | - } |
|
29 | + /** |
|
30 | + * Gets the default which is always the current user. This can't be set when initially |
|
31 | + * constructing the model field because that's done before $current_user is set |
|
32 | + * |
|
33 | + * @return mixed |
|
34 | + */ |
|
35 | + public function get_default_value() |
|
36 | + { |
|
37 | + if (did_action('init')) { |
|
38 | + return get_current_user_id(); |
|
39 | + } else { |
|
40 | + EE_Error::doing_it_wrong( |
|
41 | + 'EE_WP_User_Field::get_default_value', |
|
42 | + esc_html__( |
|
43 | + 'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + '4.6.20' |
|
47 | + ); |
|
48 | + return 1; |
|
49 | + } |
|
50 | + } |
|
51 | 51 | } |