@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | { |
90 | 90 | // if there are no standard caps for this model, then for now |
91 | 91 | // all we know if they need the default cap to access this |
92 | - if (! $this->model()->cap_slug()) { |
|
92 | + if ( ! $this->model()->cap_slug()) { |
|
93 | 93 | return [ |
94 | 94 | self::get_default_restrictions_cap( |
95 | 95 | ) => new EE_Return_None_Where_Conditions(), |
@@ -110,26 +110,26 @@ discard block |
||
110 | 110 | // they can't access others' non-default items |
111 | 111 | EE_Restriction_Generator_Base::get_cap_name( |
112 | 112 | $event_model, |
113 | - $this->action_for_event() . '_others' |
|
113 | + $this->action_for_event().'_others' |
|
114 | 114 | ) => new EE_Default_Where_Conditions( |
115 | 115 | [ |
116 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
116 | + $this->_path_to_event_model.'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
117 | 117 | ] |
118 | 118 | ), |
119 | 119 | // if they have basic and others, but not private, |
120 | 120 | // they can't access others' private non-default items |
121 | 121 | EE_Restriction_Generator_Base::get_cap_name( |
122 | 122 | $event_model, |
123 | - $this->action_for_event() . '_private' |
|
123 | + $this->action_for_event().'_private' |
|
124 | 124 | ) => new EE_Default_Where_Conditions( |
125 | 125 | [ |
126 | - 'OR*no_' . |
|
126 | + 'OR*no_'. |
|
127 | 127 | EE_Restriction_Generator_Base::get_cap_name( |
128 | 128 | $event_model, |
129 | - $this->action_for_event() . '_private' |
|
129 | + $this->action_for_event().'_private' |
|
130 | 130 | ) => $this->addPublishedPostConditions( |
131 | 131 | [ |
132 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
132 | + $this->_path_to_event_model.'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
133 | 133 | ], |
134 | 134 | false, |
135 | 135 | $this->_path_to_event_model |
@@ -13,128 +13,128 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Restriction_Generator_Event_Related_Protected extends EE_Restriction_Generator_Base |
15 | 15 | { |
16 | - /** |
|
17 | - * Path to the event model from the model this restriction generator will |
|
18 | - * be applied to; including the event model itself. Eg |
|
19 | - * "Ticket.Datetime.Event" |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $_path_to_event_model = null; |
|
16 | + /** |
|
17 | + * Path to the event model from the model this restriction generator will |
|
18 | + * be applied to; including the event model itself. Eg |
|
19 | + * "Ticket.Datetime.Event" |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $_path_to_event_model = null; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Capability context on event model when creating restrictions. |
|
27 | - * Eg, although we may want capability restrictions relating to deleting |
|
28 | - * datetimes, they don't need to be able to DELETE EVENTS, they just need |
|
29 | - * to be able to EDIT EVENTS in order to DELETE DATETIMES. |
|
30 | - * |
|
31 | - * @var string one of EEM_Base::valid_cap_contexts() |
|
32 | - */ |
|
33 | - protected $_cap_context_on_event_model = null; |
|
25 | + /** |
|
26 | + * Capability context on event model when creating restrictions. |
|
27 | + * Eg, although we may want capability restrictions relating to deleting |
|
28 | + * datetimes, they don't need to be able to DELETE EVENTS, they just need |
|
29 | + * to be able to EDIT EVENTS in order to DELETE DATETIMES. |
|
30 | + * |
|
31 | + * @var string one of EEM_Base::valid_cap_contexts() |
|
32 | + */ |
|
33 | + protected $_cap_context_on_event_model = null; |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * @param string $path_to_event_model |
|
38 | - * @param string $cap_context_on_event_model capability context on event |
|
39 | - * model when creating |
|
40 | - * restrictions. Eg, although we |
|
41 | - * may want capability |
|
42 | - * restrictions relating to |
|
43 | - * deleting datetimes, they don't |
|
44 | - * need to be able to DELETE |
|
45 | - * EVENTS, they just need to be |
|
46 | - * able to EDIT EVENTS in order |
|
47 | - * to DELETE DATETIMES. If none |
|
48 | - * if provided, assumed to be the |
|
49 | - * same as on the primary model. |
|
50 | - */ |
|
51 | - public function __construct( |
|
52 | - string $path_to_event_model, |
|
53 | - string $cap_context_on_event_model = '' |
|
54 | - ) { |
|
55 | - if (substr($path_to_event_model, -1, 1) != '.') { |
|
56 | - $path_to_event_model .= '.'; |
|
57 | - } |
|
58 | - $this->_path_to_event_model = $path_to_event_model; |
|
59 | - $this->_cap_context_on_event_model = $cap_context_on_event_model; |
|
60 | - } |
|
36 | + /** |
|
37 | + * @param string $path_to_event_model |
|
38 | + * @param string $cap_context_on_event_model capability context on event |
|
39 | + * model when creating |
|
40 | + * restrictions. Eg, although we |
|
41 | + * may want capability |
|
42 | + * restrictions relating to |
|
43 | + * deleting datetimes, they don't |
|
44 | + * need to be able to DELETE |
|
45 | + * EVENTS, they just need to be |
|
46 | + * able to EDIT EVENTS in order |
|
47 | + * to DELETE DATETIMES. If none |
|
48 | + * if provided, assumed to be the |
|
49 | + * same as on the primary model. |
|
50 | + */ |
|
51 | + public function __construct( |
|
52 | + string $path_to_event_model, |
|
53 | + string $cap_context_on_event_model = '' |
|
54 | + ) { |
|
55 | + if (substr($path_to_event_model, -1, 1) != '.') { |
|
56 | + $path_to_event_model .= '.'; |
|
57 | + } |
|
58 | + $this->_path_to_event_model = $path_to_event_model; |
|
59 | + $this->_cap_context_on_event_model = $cap_context_on_event_model; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * Returns `$this->_cap_context_on_event_model`, the relevant action |
|
65 | - * ("read", |
|
66 | - * "read_admin", "edit" or "delete") for the EVENT related to this model. |
|
67 | - * |
|
68 | - * @return string one of EEM_Base::valid_cap_contexts() |
|
69 | - * @throws EE_Error |
|
70 | - * @see EE_Restriction_Generator_Event_Related_Protected::__construct() |
|
71 | - */ |
|
72 | - protected function action_for_event(): ?string |
|
73 | - { |
|
74 | - if ($this->_cap_context_on_event_model) { |
|
75 | - return $this->_cap_context_on_event_model; |
|
76 | - } else { |
|
77 | - return $this->action(); |
|
78 | - } |
|
79 | - } |
|
63 | + /** |
|
64 | + * Returns `$this->_cap_context_on_event_model`, the relevant action |
|
65 | + * ("read", |
|
66 | + * "read_admin", "edit" or "delete") for the EVENT related to this model. |
|
67 | + * |
|
68 | + * @return string one of EEM_Base::valid_cap_contexts() |
|
69 | + * @throws EE_Error |
|
70 | + * @see EE_Restriction_Generator_Event_Related_Protected::__construct() |
|
71 | + */ |
|
72 | + protected function action_for_event(): ?string |
|
73 | + { |
|
74 | + if ($this->_cap_context_on_event_model) { |
|
75 | + return $this->_cap_context_on_event_model; |
|
76 | + } else { |
|
77 | + return $this->action(); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | - /** |
|
83 | - * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
84 | - * @throws EE_Error |
|
85 | - * @throws EE_Error |
|
86 | - */ |
|
87 | - protected function _generate_restrictions(): array |
|
88 | - { |
|
89 | - // if there are no standard caps for this model, then for now |
|
90 | - // all we know if they need the default cap to access this |
|
91 | - if (! $this->model()->cap_slug()) { |
|
92 | - return [ |
|
93 | - self::get_default_restrictions_cap( |
|
94 | - ) => new EE_Return_None_Where_Conditions(), |
|
95 | - ]; |
|
96 | - } |
|
82 | + /** |
|
83 | + * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
84 | + * @throws EE_Error |
|
85 | + * @throws EE_Error |
|
86 | + */ |
|
87 | + protected function _generate_restrictions(): array |
|
88 | + { |
|
89 | + // if there are no standard caps for this model, then for now |
|
90 | + // all we know if they need the default cap to access this |
|
91 | + if (! $this->model()->cap_slug()) { |
|
92 | + return [ |
|
93 | + self::get_default_restrictions_cap( |
|
94 | + ) => new EE_Return_None_Where_Conditions(), |
|
95 | + ]; |
|
96 | + } |
|
97 | 97 | |
98 | - $event_model = EEM_Event::instance(); |
|
99 | - return [ |
|
100 | - // first: basically access to non-defaults is essentially |
|
101 | - // controlled by which events are accessible |
|
102 | - // if they don't have the basic event cap, |
|
103 | - // they can't access ANY non-default items |
|
104 | - EE_Restriction_Generator_Base::get_cap_name( |
|
105 | - $event_model, |
|
106 | - $this->action_for_event() |
|
107 | - ) => new EE_Return_None_Where_Conditions(), |
|
108 | - // if they don't have the others event cap, |
|
109 | - // they can't access others' non-default items |
|
110 | - EE_Restriction_Generator_Base::get_cap_name( |
|
111 | - $event_model, |
|
112 | - $this->action_for_event() . '_others' |
|
113 | - ) => new EE_Default_Where_Conditions( |
|
114 | - [ |
|
115 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
116 | - ] |
|
117 | - ), |
|
118 | - // if they have basic and others, but not private, |
|
119 | - // they can't access others' private non-default items |
|
120 | - EE_Restriction_Generator_Base::get_cap_name( |
|
121 | - $event_model, |
|
122 | - $this->action_for_event() . '_private' |
|
123 | - ) => new EE_Default_Where_Conditions( |
|
124 | - [ |
|
125 | - 'OR*no_' . |
|
126 | - EE_Restriction_Generator_Base::get_cap_name( |
|
127 | - $event_model, |
|
128 | - $this->action_for_event() . '_private' |
|
129 | - ) => $this->addPublishedPostConditions( |
|
130 | - [ |
|
131 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
132 | - ], |
|
133 | - false, |
|
134 | - $this->_path_to_event_model |
|
135 | - ) |
|
136 | - ] |
|
137 | - ), |
|
138 | - ]; |
|
139 | - } |
|
98 | + $event_model = EEM_Event::instance(); |
|
99 | + return [ |
|
100 | + // first: basically access to non-defaults is essentially |
|
101 | + // controlled by which events are accessible |
|
102 | + // if they don't have the basic event cap, |
|
103 | + // they can't access ANY non-default items |
|
104 | + EE_Restriction_Generator_Base::get_cap_name( |
|
105 | + $event_model, |
|
106 | + $this->action_for_event() |
|
107 | + ) => new EE_Return_None_Where_Conditions(), |
|
108 | + // if they don't have the others event cap, |
|
109 | + // they can't access others' non-default items |
|
110 | + EE_Restriction_Generator_Base::get_cap_name( |
|
111 | + $event_model, |
|
112 | + $this->action_for_event() . '_others' |
|
113 | + ) => new EE_Default_Where_Conditions( |
|
114 | + [ |
|
115 | + $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
116 | + ] |
|
117 | + ), |
|
118 | + // if they have basic and others, but not private, |
|
119 | + // they can't access others' private non-default items |
|
120 | + EE_Restriction_Generator_Base::get_cap_name( |
|
121 | + $event_model, |
|
122 | + $this->action_for_event() . '_private' |
|
123 | + ) => new EE_Default_Where_Conditions( |
|
124 | + [ |
|
125 | + 'OR*no_' . |
|
126 | + EE_Restriction_Generator_Base::get_cap_name( |
|
127 | + $event_model, |
|
128 | + $this->action_for_event() . '_private' |
|
129 | + ) => $this->addPublishedPostConditions( |
|
130 | + [ |
|
131 | + $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
132 | + ], |
|
133 | + false, |
|
134 | + $this->_path_to_event_model |
|
135 | + ) |
|
136 | + ] |
|
137 | + ), |
|
138 | + ]; |
|
139 | + } |
|
140 | 140 | } |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | */ |
297 | 297 | public function timestamp($dt_frmt = '', $tm_frmt = '') |
298 | 298 | { |
299 | - return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
299 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt.' '.$tm_frmt)); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | : ''; |
482 | 482 | break; |
483 | 483 | } |
484 | - return $icon . $status[ $this->STS_ID() ]; |
|
484 | + return $icon.$status[$this->STS_ID()]; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | public function redirect_form($inside_form_html = null) |
628 | 628 | { |
629 | 629 | $redirect_url = $this->redirect_url(); |
630 | - if (! empty($redirect_url)) { |
|
630 | + if ( ! empty($redirect_url)) { |
|
631 | 631 | // what ? no inner form content? |
632 | 632 | if ($inside_form_html === null) { |
633 | 633 | $inside_form_html = EEH_HTML::p( |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | $get_params = null; |
658 | 658 | parse_str($querystring, $get_params); |
659 | 659 | $inside_form_html .= $this->_args_as_inputs($get_params); |
660 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
660 | + $redirect_url = str_replace('?'.$querystring, '', $redirect_url); |
|
661 | 661 | } |
662 | 662 | $form = EEH_HTML::nl(1) |
663 | 663 | . '<form method="' |
@@ -665,9 +665,9 @@ discard block |
||
665 | 665 | . '" name="gateway_form" action="' |
666 | 666 | . $redirect_url |
667 | 667 | . '">'; |
668 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
668 | + $form .= EEH_HTML::nl(1).$this->redirect_args_as_inputs(); |
|
669 | 669 | $form .= $inside_form_html; |
670 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
670 | + $form .= EEH_HTML::nl(-1).'</form>'.EEH_HTML::nl(-1); |
|
671 | 671 | return $form; |
672 | 672 | } else { |
673 | 673 | return null; |
@@ -725,8 +725,8 @@ discard block |
||
725 | 725 | return $html; |
726 | 726 | } |
727 | 727 | return EEH_HTML::nl() |
728 | - . '<input type="hidden" name="' . $name . '"' |
|
729 | - . ' value="' . esc_attr($value) . '"/>'; |
|
728 | + . '<input type="hidden" name="'.$name.'"' |
|
729 | + . ' value="'.esc_attr($value).'"/>'; |
|
730 | 730 | } |
731 | 731 | |
732 | 732 |
@@ -11,874 +11,874 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Payment extends EE_Base_Class implements EEI_Payment |
13 | 13 | { |
14 | - /** |
|
15 | - * @param array $props_n_values incoming values |
|
16 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
17 | - * used.) |
|
18 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
19 | - * date_format and the second value is the time format |
|
20 | - * @return EE_Payment |
|
21 | - * @throws EE_Error|ReflectionException |
|
22 | - */ |
|
23 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
24 | - { |
|
25 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
26 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
27 | - } |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @param array $props_n_values incoming values from the database |
|
32 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
33 | - * the website will be used. |
|
34 | - * @return EE_Payment |
|
35 | - * @throws EE_Error |
|
36 | - */ |
|
37 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
38 | - { |
|
39 | - return new self($props_n_values, true, $timezone); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Set Transaction ID |
|
45 | - * |
|
46 | - * @access public |
|
47 | - * @param int $TXN_ID |
|
48 | - * @throws EE_Error |
|
49 | - */ |
|
50 | - public function set_transaction_id($TXN_ID = 0) |
|
51 | - { |
|
52 | - $this->set('TXN_ID', $TXN_ID); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Gets the transaction related to this payment |
|
58 | - * |
|
59 | - * @return EE_Transaction |
|
60 | - * @throws EE_Error |
|
61 | - */ |
|
62 | - public function transaction() |
|
63 | - { |
|
64 | - return $this->get_first_related('Transaction'); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Set Status |
|
70 | - * |
|
71 | - * @access public |
|
72 | - * @param string $STS_ID |
|
73 | - * @throws EE_Error |
|
74 | - */ |
|
75 | - public function set_status($STS_ID = '') |
|
76 | - { |
|
77 | - $this->set('STS_ID', $STS_ID); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Set Payment Timestamp |
|
83 | - * |
|
84 | - * @access public |
|
85 | - * @param int $timestamp |
|
86 | - * @throws EE_Error |
|
87 | - */ |
|
88 | - public function set_timestamp($timestamp = 0) |
|
89 | - { |
|
90 | - $this->set('PAY_timestamp', $timestamp); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Set Payment Method |
|
96 | - * |
|
97 | - * @access public |
|
98 | - * @param string $PAY_source |
|
99 | - * @throws EE_Error |
|
100 | - */ |
|
101 | - public function set_source($PAY_source = '') |
|
102 | - { |
|
103 | - $this->set('PAY_source', $PAY_source); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Set Payment Amount |
|
109 | - * |
|
110 | - * @access public |
|
111 | - * @param float $amount |
|
112 | - * @throws EE_Error |
|
113 | - */ |
|
114 | - public function set_amount($amount = 0.00) |
|
115 | - { |
|
116 | - $this->set('PAY_amount', (float) $amount); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Set Payment Gateway Response |
|
122 | - * |
|
123 | - * @access public |
|
124 | - * @param string $gateway_response |
|
125 | - * @throws EE_Error |
|
126 | - */ |
|
127 | - public function set_gateway_response($gateway_response = '') |
|
128 | - { |
|
129 | - $this->set('PAY_gateway_response', $gateway_response); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
135 | - * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
136 | - * used on it |
|
137 | - * |
|
138 | - * @return string |
|
139 | - * @throws EE_Error |
|
140 | - * @deprecated |
|
141 | - */ |
|
142 | - public function gateway() |
|
143 | - { |
|
144 | - EE_Error::doing_it_wrong( |
|
145 | - 'EE_Payment::gateway', |
|
146 | - esc_html__( |
|
147 | - 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
148 | - 'event_espresso' |
|
149 | - ), |
|
150 | - '4.6.0' |
|
151 | - ); |
|
152 | - return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * Set Gateway Transaction ID |
|
158 | - * |
|
159 | - * @access public |
|
160 | - * @param string $txn_id_chq_nmbr |
|
161 | - * @throws EE_Error |
|
162 | - */ |
|
163 | - public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
164 | - { |
|
165 | - $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * Set Purchase Order Number |
|
171 | - * |
|
172 | - * @access public |
|
173 | - * @param string $po_number |
|
174 | - * @throws EE_Error |
|
175 | - */ |
|
176 | - public function set_po_number($po_number = '') |
|
177 | - { |
|
178 | - $this->set('PAY_po_number', $po_number); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Set Extra Accounting Field |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * @param string $extra_accntng |
|
187 | - * @throws EE_Error |
|
188 | - */ |
|
189 | - public function set_extra_accntng($extra_accntng = '') |
|
190 | - { |
|
191 | - $this->set('PAY_extra_accntng', $extra_accntng); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * Set Payment made via admin flag |
|
197 | - * |
|
198 | - * @access public |
|
199 | - * @param bool $via_admin |
|
200 | - * @throws EE_Error |
|
201 | - */ |
|
202 | - public function set_payment_made_via_admin($via_admin = false) |
|
203 | - { |
|
204 | - if ($via_admin) { |
|
205 | - $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
206 | - } else { |
|
207 | - $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * Set Payment Details |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @param string|array $details |
|
217 | - * @throws EE_Error |
|
218 | - */ |
|
219 | - public function set_details($details = '') |
|
220 | - { |
|
221 | - if (is_array($details)) { |
|
222 | - array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
223 | - } else { |
|
224 | - $details = wp_strip_all_tags($details); |
|
225 | - } |
|
226 | - $this->set('PAY_details', $details); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * Sets redirect_url |
|
232 | - * |
|
233 | - * @param string $redirect_url |
|
234 | - * @throws EE_Error |
|
235 | - */ |
|
236 | - public function set_redirect_url($redirect_url) |
|
237 | - { |
|
238 | - $this->set('PAY_redirect_url', $redirect_url); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * Sets redirect_args |
|
244 | - * |
|
245 | - * @param array $redirect_args |
|
246 | - * @throws EE_Error |
|
247 | - */ |
|
248 | - public function set_redirect_args($redirect_args) |
|
249 | - { |
|
250 | - $this->set('PAY_redirect_args', $redirect_args); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * get Payment Transaction ID |
|
256 | - * |
|
257 | - * @access public |
|
258 | - * @throws EE_Error |
|
259 | - */ |
|
260 | - public function TXN_ID() |
|
261 | - { |
|
262 | - return $this->get('TXN_ID'); |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * get Payment Status |
|
268 | - * |
|
269 | - * @access public |
|
270 | - * @throws EE_Error |
|
271 | - */ |
|
272 | - public function status() |
|
273 | - { |
|
274 | - return $this->get('STS_ID'); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * get Payment Status |
|
280 | - * |
|
281 | - * @access public |
|
282 | - * @throws EE_Error |
|
283 | - */ |
|
284 | - public function STS_ID() |
|
285 | - { |
|
286 | - return $this->get('STS_ID'); |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * get Payment Timestamp |
|
292 | - * |
|
293 | - * @access public |
|
294 | - * @param string $dt_frmt |
|
295 | - * @param string $tm_frmt |
|
296 | - * @return string |
|
297 | - * @throws EE_Error |
|
298 | - */ |
|
299 | - public function timestamp($dt_frmt = '', $tm_frmt = '') |
|
300 | - { |
|
301 | - return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * get Payment Source |
|
307 | - * |
|
308 | - * @access public |
|
309 | - * @throws EE_Error |
|
310 | - */ |
|
311 | - public function source() |
|
312 | - { |
|
313 | - return $this->get('PAY_source'); |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * get Payment Amount |
|
319 | - * |
|
320 | - * @access public |
|
321 | - * @return float |
|
322 | - * @throws EE_Error |
|
323 | - */ |
|
324 | - public function amount() |
|
325 | - { |
|
326 | - return (float) $this->get('PAY_amount'); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * @return mixed |
|
332 | - * @throws EE_Error |
|
333 | - */ |
|
334 | - public function amount_no_code() |
|
335 | - { |
|
336 | - return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * get Payment Gateway Response |
|
342 | - * |
|
343 | - * @access public |
|
344 | - * @throws EE_Error |
|
345 | - */ |
|
346 | - public function gateway_response() |
|
347 | - { |
|
348 | - return $this->get('PAY_gateway_response'); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * get Payment Gateway Transaction ID |
|
354 | - * |
|
355 | - * @access public |
|
356 | - * @throws EE_Error |
|
357 | - */ |
|
358 | - public function txn_id_chq_nmbr() |
|
359 | - { |
|
360 | - return $this->get('PAY_txn_id_chq_nmbr'); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * get Purchase Order Number |
|
366 | - * |
|
367 | - * @access public |
|
368 | - * @throws EE_Error |
|
369 | - */ |
|
370 | - public function po_number() |
|
371 | - { |
|
372 | - return $this->get('PAY_po_number'); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * get Extra Accounting Field |
|
378 | - * |
|
379 | - * @access public |
|
380 | - * @throws EE_Error |
|
381 | - */ |
|
382 | - public function extra_accntng() |
|
383 | - { |
|
384 | - return $this->get('PAY_extra_accntng'); |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * get Payment made via admin source |
|
390 | - * |
|
391 | - * @access public |
|
392 | - * @throws EE_Error |
|
393 | - */ |
|
394 | - public function payment_made_via_admin() |
|
395 | - { |
|
396 | - return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
397 | - } |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * get Payment Details |
|
402 | - * |
|
403 | - * @access public |
|
404 | - * @throws EE_Error |
|
405 | - */ |
|
406 | - public function details() |
|
407 | - { |
|
408 | - return $this->get('PAY_details'); |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * Gets redirect_url |
|
414 | - * |
|
415 | - * @return string |
|
416 | - * @throws EE_Error |
|
417 | - */ |
|
418 | - public function redirect_url() |
|
419 | - { |
|
420 | - return $this->get('PAY_redirect_url'); |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * Gets redirect_args |
|
426 | - * |
|
427 | - * @return array |
|
428 | - * @throws EE_Error |
|
429 | - */ |
|
430 | - public function redirect_args() |
|
431 | - { |
|
432 | - return $this->get('PAY_redirect_args'); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * echoes $this->pretty_status() |
|
438 | - * |
|
439 | - * @param bool $show_icons |
|
440 | - * @return void |
|
441 | - * @throws EE_Error |
|
442 | - */ |
|
443 | - public function e_pretty_status($show_icons = false) |
|
444 | - { |
|
445 | - echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags()); |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * returns a pretty version of the status, good for displaying to users |
|
451 | - * |
|
452 | - * @param bool $show_icons |
|
453 | - * @return string |
|
454 | - * @throws EE_Error |
|
455 | - */ |
|
456 | - public function pretty_status($show_icons = false) |
|
457 | - { |
|
458 | - $status = EEM_Status::instance()->localized_status( |
|
459 | - array($this->STS_ID() => esc_html__('unknown', 'event_espresso')), |
|
460 | - false, |
|
461 | - 'sentence' |
|
462 | - ); |
|
463 | - $icon = ''; |
|
464 | - switch ($this->STS_ID()) { |
|
465 | - case EEM_Payment::status_id_approved: |
|
466 | - $icon = $show_icons |
|
467 | - ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
468 | - : ''; |
|
469 | - break; |
|
470 | - case EEM_Payment::status_id_pending: |
|
471 | - $icon = $show_icons |
|
472 | - ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
473 | - : ''; |
|
474 | - break; |
|
475 | - case EEM_Payment::status_id_cancelled: |
|
476 | - $icon = $show_icons |
|
477 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
478 | - : ''; |
|
479 | - break; |
|
480 | - case EEM_Payment::status_id_declined: |
|
481 | - $icon = $show_icons |
|
482 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
483 | - : ''; |
|
484 | - break; |
|
485 | - } |
|
486 | - return $icon . $status[ $this->STS_ID() ]; |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * For determining the status of the payment |
|
492 | - * |
|
493 | - * @return boolean whether the payment is approved or not |
|
494 | - * @throws EE_Error |
|
495 | - */ |
|
496 | - public function is_approved() |
|
497 | - { |
|
498 | - return $this->status_is(EEM_Payment::status_id_approved); |
|
499 | - } |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * Generally determines if the status of this payment equals |
|
504 | - * the $STS_ID string |
|
505 | - * |
|
506 | - * @param string $STS_ID an ID from the esp_status table/ |
|
507 | - * one of the status_id_* on the EEM_Payment model |
|
508 | - * @return boolean whether the status of this payment equals the status id |
|
509 | - * @throws EE_Error |
|
510 | - */ |
|
511 | - protected function status_is($STS_ID) |
|
512 | - { |
|
513 | - return $STS_ID === $this->STS_ID() ? true : false; |
|
514 | - } |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * For determining the status of the payment |
|
519 | - * |
|
520 | - * @return boolean whether the payment is pending or not |
|
521 | - * @throws EE_Error |
|
522 | - */ |
|
523 | - public function is_pending() |
|
524 | - { |
|
525 | - return $this->status_is(EEM_Payment::status_id_pending); |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * For determining the status of the payment |
|
531 | - * |
|
532 | - * @return boolean |
|
533 | - * @throws EE_Error |
|
534 | - */ |
|
535 | - public function is_cancelled() |
|
536 | - { |
|
537 | - return $this->status_is(EEM_Payment::status_id_cancelled); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * For determining the status of the payment |
|
543 | - * |
|
544 | - * @return boolean |
|
545 | - * @throws EE_Error |
|
546 | - */ |
|
547 | - public function is_declined() |
|
548 | - { |
|
549 | - return $this->status_is(EEM_Payment::status_id_declined); |
|
550 | - } |
|
551 | - |
|
552 | - |
|
553 | - /** |
|
554 | - * For determining the status of the payment |
|
555 | - * |
|
556 | - * @return boolean |
|
557 | - * @throws EE_Error |
|
558 | - */ |
|
559 | - public function is_failed() |
|
560 | - { |
|
561 | - return $this->status_is(EEM_Payment::status_id_failed); |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
567 | - * |
|
568 | - * @return boolean |
|
569 | - * @throws EE_Error |
|
570 | - */ |
|
571 | - public function is_a_refund() |
|
572 | - { |
|
573 | - return $this->amount() < 0 ? true : false; |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * Get the status object of this object |
|
579 | - * |
|
580 | - * @return EE_Status |
|
581 | - * @throws EE_Error |
|
582 | - */ |
|
583 | - public function status_obj() |
|
584 | - { |
|
585 | - return $this->get_first_related('Status'); |
|
586 | - } |
|
587 | - |
|
588 | - |
|
589 | - /** |
|
590 | - * Gets all the extra meta info on this payment |
|
591 | - * |
|
592 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
593 | - * @return EE_Extra_Meta |
|
594 | - * @throws EE_Error |
|
595 | - */ |
|
596 | - public function extra_meta($query_params = array()) |
|
597 | - { |
|
598 | - return $this->get_many_related('Extra_Meta', $query_params); |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * Gets the last-used payment method on this transaction |
|
604 | - * (we COULD just use the last-made payment, but some payment methods, namely |
|
605 | - * offline ones, dont' create payments) |
|
606 | - * |
|
607 | - * @return EE_Payment_Method |
|
608 | - * @throws EE_Error |
|
609 | - */ |
|
610 | - public function payment_method() |
|
611 | - { |
|
612 | - return $this->get_first_related('Payment_Method'); |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * Gets the HTML for redirecting the user to an offsite gateway |
|
618 | - * You can pass it special content to put inside the form, or use |
|
619 | - * the default inner content (or possibly generate this all yourself using |
|
620 | - * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
621 | - * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
622 | - * (and any querystring variables in the redirect_url are converted into html inputs |
|
623 | - * so browsers submit them properly) |
|
624 | - * |
|
625 | - * @param string $inside_form_html |
|
626 | - * @return string html |
|
627 | - * @throws EE_Error |
|
628 | - */ |
|
629 | - public function redirect_form($inside_form_html = null) |
|
630 | - { |
|
631 | - $redirect_url = $this->redirect_url(); |
|
632 | - if (! empty($redirect_url)) { |
|
633 | - // what ? no inner form content? |
|
634 | - if ($inside_form_html === null) { |
|
635 | - $inside_form_html = EEH_HTML::p( |
|
636 | - sprintf( |
|
637 | - esc_html__( |
|
638 | - 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
639 | - 'event_espresso' |
|
640 | - ), |
|
641 | - EEH_HTML::br(2), |
|
642 | - '<input type="submit" value="', |
|
643 | - '">' |
|
644 | - ), |
|
645 | - '', |
|
646 | - '', |
|
647 | - 'text-align:center;' |
|
648 | - ); |
|
649 | - } |
|
650 | - $method = apply_filters( |
|
651 | - 'FHEE__EE_Payment__redirect_form__method', |
|
652 | - $this->redirect_args() ? 'POST' : 'GET', |
|
653 | - $this |
|
654 | - ); |
|
655 | - // if it's a GET request, we need to remove all the GET params in the querystring |
|
656 | - // and put them into the form instead |
|
657 | - if ($method === 'GET') { |
|
658 | - $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
659 | - $get_params = null; |
|
660 | - parse_str($querystring, $get_params); |
|
661 | - $inside_form_html .= $this->_args_as_inputs($get_params); |
|
662 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
663 | - } |
|
664 | - $form = EEH_HTML::nl(1) |
|
665 | - . '<form method="' |
|
666 | - . $method |
|
667 | - . '" name="gateway_form" action="' |
|
668 | - . $redirect_url |
|
669 | - . '">'; |
|
670 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
671 | - $form .= $inside_form_html; |
|
672 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
673 | - return $form; |
|
674 | - } else { |
|
675 | - return null; |
|
676 | - } |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * Changes all the name-value pairs of the redirect args into html inputs |
|
682 | - * and returns the html as a string |
|
683 | - * |
|
684 | - * @return string |
|
685 | - * @throws EE_Error |
|
686 | - */ |
|
687 | - public function redirect_args_as_inputs() |
|
688 | - { |
|
689 | - return $this->_args_as_inputs($this->redirect_args()); |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * Converts a 2d array of key-value pairs into html hidden inputs |
|
695 | - * and returns the string of html |
|
696 | - * |
|
697 | - * @param array $args key-value pairs |
|
698 | - * @return string |
|
699 | - */ |
|
700 | - protected function _args_as_inputs($args) |
|
701 | - { |
|
702 | - $html = ''; |
|
703 | - if ($args !== null && is_array($args)) { |
|
704 | - foreach ($args as $name => $value) { |
|
705 | - $html .= $this->generateInput($name, $value); |
|
706 | - } |
|
707 | - } |
|
708 | - return $html; |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * Converts either a single name and value or array of values into html hidden inputs |
|
713 | - * and returns the string of html |
|
714 | - * |
|
715 | - * @param string $name |
|
716 | - * @param string|array $value |
|
717 | - * @return string |
|
718 | - */ |
|
719 | - private function generateInput($name, $value) |
|
720 | - { |
|
721 | - if (is_array($value)) { |
|
722 | - $html = ''; |
|
723 | - $name = "{$name}[]"; |
|
724 | - foreach ($value as $array_value) { |
|
725 | - $html .= $this->generateInput($name, $array_value); |
|
726 | - } |
|
727 | - return $html; |
|
728 | - } |
|
729 | - return EEH_HTML::nl() |
|
730 | - . '<input type="hidden" name="' . $name . '"' |
|
731 | - . ' value="' . esc_attr($value) . '"/>'; |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - /** |
|
736 | - * Returns the currency of the payment. |
|
737 | - * (At the time of writing, this will always be the currency in the configuration; |
|
738 | - * however in the future it is anticipated that this will be stored on the payment |
|
739 | - * object itself) |
|
740 | - * |
|
741 | - * @return string for the currency code |
|
742 | - */ |
|
743 | - public function currency_code() |
|
744 | - { |
|
745 | - return EE_Config::instance()->currency->code; |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * apply wp_strip_all_tags to all elements within an array |
|
751 | - * |
|
752 | - * @access private |
|
753 | - * @param mixed $item |
|
754 | - */ |
|
755 | - private function _strip_all_tags_within_array(&$item) |
|
756 | - { |
|
757 | - if (is_object($item)) { |
|
758 | - $item = (array) $item; |
|
759 | - } |
|
760 | - if (is_array($item)) { |
|
761 | - array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
762 | - } else { |
|
763 | - $item = wp_strip_all_tags((string) $item); |
|
764 | - } |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * Returns TRUE is this payment was set to approved during this request (or |
|
770 | - * is approved and was created during this request). False otherwise. |
|
771 | - * |
|
772 | - * @return boolean |
|
773 | - * @throws EE_Error |
|
774 | - */ |
|
775 | - public function just_approved() |
|
776 | - { |
|
777 | - $original_status = EEH_Array::is_set( |
|
778 | - $this->_props_n_values_provided_in_constructor, |
|
779 | - 'STS_ID', |
|
780 | - $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
781 | - ); |
|
782 | - $current_status = $this->status(); |
|
783 | - if ( |
|
784 | - $original_status !== EEM_Payment::status_id_approved |
|
785 | - && $current_status === EEM_Payment::status_id_approved |
|
786 | - ) { |
|
787 | - return true; |
|
788 | - } else { |
|
789 | - return false; |
|
790 | - } |
|
791 | - } |
|
792 | - |
|
793 | - |
|
794 | - /** |
|
795 | - * Overrides parents' get_pretty() function just for legacy reasons |
|
796 | - * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
797 | - * |
|
798 | - * @param string $field_name |
|
799 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
800 | - * (in cases where the same property may be used for different outputs |
|
801 | - * - i.e. datetime, money etc.) |
|
802 | - * @return mixed |
|
803 | - * @throws EE_Error |
|
804 | - */ |
|
805 | - public function get_pretty($field_name, $extra_cache_ref = null) |
|
806 | - { |
|
807 | - if ($field_name === 'PAY_gateway') { |
|
808 | - return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
809 | - } |
|
810 | - return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
811 | - } |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * Gets details regarding which registrations this payment was applied to |
|
816 | - * |
|
817 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
818 | - * @return EE_Registration_Payment[] |
|
819 | - * @throws EE_Error |
|
820 | - */ |
|
821 | - public function registration_payments($query_params = array()) |
|
822 | - { |
|
823 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
824 | - } |
|
825 | - |
|
826 | - |
|
827 | - /** |
|
828 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
829 | - * |
|
830 | - * @return EE_Event|null |
|
831 | - */ |
|
832 | - public function get_first_event() |
|
833 | - { |
|
834 | - $transaction = $this->transaction(); |
|
835 | - if ($transaction instanceof EE_Transaction) { |
|
836 | - $primary_registrant = $transaction->primary_registration(); |
|
837 | - if ($primary_registrant instanceof EE_Registration) { |
|
838 | - return $primary_registrant->event_obj(); |
|
839 | - } |
|
840 | - } |
|
841 | - return null; |
|
842 | - } |
|
843 | - |
|
844 | - |
|
845 | - /** |
|
846 | - * Gets the name of the first event for which is being paid |
|
847 | - * |
|
848 | - * @return string |
|
849 | - */ |
|
850 | - public function get_first_event_name() |
|
851 | - { |
|
852 | - $event = $this->get_first_event(); |
|
853 | - return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso'); |
|
854 | - } |
|
855 | - |
|
856 | - |
|
857 | - /** |
|
858 | - * Returns the payment's transaction's primary registration |
|
859 | - * |
|
860 | - * @return EE_Registration|null |
|
861 | - */ |
|
862 | - public function get_primary_registration() |
|
863 | - { |
|
864 | - if ($this->transaction() instanceof EE_Transaction) { |
|
865 | - return $this->transaction()->primary_registration(); |
|
866 | - } |
|
867 | - return null; |
|
868 | - } |
|
869 | - |
|
870 | - |
|
871 | - /** |
|
872 | - * Gets the payment's transaction's primary registration's attendee, or null |
|
873 | - * |
|
874 | - * @return EE_Attendee|null |
|
875 | - */ |
|
876 | - public function get_primary_attendee() |
|
877 | - { |
|
878 | - $primary_reg = $this->get_primary_registration(); |
|
879 | - if ($primary_reg instanceof EE_Registration) { |
|
880 | - return $primary_reg->attendee(); |
|
881 | - } |
|
882 | - return null; |
|
883 | - } |
|
14 | + /** |
|
15 | + * @param array $props_n_values incoming values |
|
16 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
17 | + * used.) |
|
18 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
19 | + * date_format and the second value is the time format |
|
20 | + * @return EE_Payment |
|
21 | + * @throws EE_Error|ReflectionException |
|
22 | + */ |
|
23 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
24 | + { |
|
25 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
26 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
27 | + } |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @param array $props_n_values incoming values from the database |
|
32 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
33 | + * the website will be used. |
|
34 | + * @return EE_Payment |
|
35 | + * @throws EE_Error |
|
36 | + */ |
|
37 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
38 | + { |
|
39 | + return new self($props_n_values, true, $timezone); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Set Transaction ID |
|
45 | + * |
|
46 | + * @access public |
|
47 | + * @param int $TXN_ID |
|
48 | + * @throws EE_Error |
|
49 | + */ |
|
50 | + public function set_transaction_id($TXN_ID = 0) |
|
51 | + { |
|
52 | + $this->set('TXN_ID', $TXN_ID); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Gets the transaction related to this payment |
|
58 | + * |
|
59 | + * @return EE_Transaction |
|
60 | + * @throws EE_Error |
|
61 | + */ |
|
62 | + public function transaction() |
|
63 | + { |
|
64 | + return $this->get_first_related('Transaction'); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Set Status |
|
70 | + * |
|
71 | + * @access public |
|
72 | + * @param string $STS_ID |
|
73 | + * @throws EE_Error |
|
74 | + */ |
|
75 | + public function set_status($STS_ID = '') |
|
76 | + { |
|
77 | + $this->set('STS_ID', $STS_ID); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Set Payment Timestamp |
|
83 | + * |
|
84 | + * @access public |
|
85 | + * @param int $timestamp |
|
86 | + * @throws EE_Error |
|
87 | + */ |
|
88 | + public function set_timestamp($timestamp = 0) |
|
89 | + { |
|
90 | + $this->set('PAY_timestamp', $timestamp); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Set Payment Method |
|
96 | + * |
|
97 | + * @access public |
|
98 | + * @param string $PAY_source |
|
99 | + * @throws EE_Error |
|
100 | + */ |
|
101 | + public function set_source($PAY_source = '') |
|
102 | + { |
|
103 | + $this->set('PAY_source', $PAY_source); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Set Payment Amount |
|
109 | + * |
|
110 | + * @access public |
|
111 | + * @param float $amount |
|
112 | + * @throws EE_Error |
|
113 | + */ |
|
114 | + public function set_amount($amount = 0.00) |
|
115 | + { |
|
116 | + $this->set('PAY_amount', (float) $amount); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Set Payment Gateway Response |
|
122 | + * |
|
123 | + * @access public |
|
124 | + * @param string $gateway_response |
|
125 | + * @throws EE_Error |
|
126 | + */ |
|
127 | + public function set_gateway_response($gateway_response = '') |
|
128 | + { |
|
129 | + $this->set('PAY_gateway_response', $gateway_response); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
135 | + * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
136 | + * used on it |
|
137 | + * |
|
138 | + * @return string |
|
139 | + * @throws EE_Error |
|
140 | + * @deprecated |
|
141 | + */ |
|
142 | + public function gateway() |
|
143 | + { |
|
144 | + EE_Error::doing_it_wrong( |
|
145 | + 'EE_Payment::gateway', |
|
146 | + esc_html__( |
|
147 | + 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
148 | + 'event_espresso' |
|
149 | + ), |
|
150 | + '4.6.0' |
|
151 | + ); |
|
152 | + return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * Set Gateway Transaction ID |
|
158 | + * |
|
159 | + * @access public |
|
160 | + * @param string $txn_id_chq_nmbr |
|
161 | + * @throws EE_Error |
|
162 | + */ |
|
163 | + public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
164 | + { |
|
165 | + $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * Set Purchase Order Number |
|
171 | + * |
|
172 | + * @access public |
|
173 | + * @param string $po_number |
|
174 | + * @throws EE_Error |
|
175 | + */ |
|
176 | + public function set_po_number($po_number = '') |
|
177 | + { |
|
178 | + $this->set('PAY_po_number', $po_number); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Set Extra Accounting Field |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * @param string $extra_accntng |
|
187 | + * @throws EE_Error |
|
188 | + */ |
|
189 | + public function set_extra_accntng($extra_accntng = '') |
|
190 | + { |
|
191 | + $this->set('PAY_extra_accntng', $extra_accntng); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * Set Payment made via admin flag |
|
197 | + * |
|
198 | + * @access public |
|
199 | + * @param bool $via_admin |
|
200 | + * @throws EE_Error |
|
201 | + */ |
|
202 | + public function set_payment_made_via_admin($via_admin = false) |
|
203 | + { |
|
204 | + if ($via_admin) { |
|
205 | + $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
206 | + } else { |
|
207 | + $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * Set Payment Details |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @param string|array $details |
|
217 | + * @throws EE_Error |
|
218 | + */ |
|
219 | + public function set_details($details = '') |
|
220 | + { |
|
221 | + if (is_array($details)) { |
|
222 | + array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
223 | + } else { |
|
224 | + $details = wp_strip_all_tags($details); |
|
225 | + } |
|
226 | + $this->set('PAY_details', $details); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * Sets redirect_url |
|
232 | + * |
|
233 | + * @param string $redirect_url |
|
234 | + * @throws EE_Error |
|
235 | + */ |
|
236 | + public function set_redirect_url($redirect_url) |
|
237 | + { |
|
238 | + $this->set('PAY_redirect_url', $redirect_url); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * Sets redirect_args |
|
244 | + * |
|
245 | + * @param array $redirect_args |
|
246 | + * @throws EE_Error |
|
247 | + */ |
|
248 | + public function set_redirect_args($redirect_args) |
|
249 | + { |
|
250 | + $this->set('PAY_redirect_args', $redirect_args); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * get Payment Transaction ID |
|
256 | + * |
|
257 | + * @access public |
|
258 | + * @throws EE_Error |
|
259 | + */ |
|
260 | + public function TXN_ID() |
|
261 | + { |
|
262 | + return $this->get('TXN_ID'); |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * get Payment Status |
|
268 | + * |
|
269 | + * @access public |
|
270 | + * @throws EE_Error |
|
271 | + */ |
|
272 | + public function status() |
|
273 | + { |
|
274 | + return $this->get('STS_ID'); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * get Payment Status |
|
280 | + * |
|
281 | + * @access public |
|
282 | + * @throws EE_Error |
|
283 | + */ |
|
284 | + public function STS_ID() |
|
285 | + { |
|
286 | + return $this->get('STS_ID'); |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * get Payment Timestamp |
|
292 | + * |
|
293 | + * @access public |
|
294 | + * @param string $dt_frmt |
|
295 | + * @param string $tm_frmt |
|
296 | + * @return string |
|
297 | + * @throws EE_Error |
|
298 | + */ |
|
299 | + public function timestamp($dt_frmt = '', $tm_frmt = '') |
|
300 | + { |
|
301 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * get Payment Source |
|
307 | + * |
|
308 | + * @access public |
|
309 | + * @throws EE_Error |
|
310 | + */ |
|
311 | + public function source() |
|
312 | + { |
|
313 | + return $this->get('PAY_source'); |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * get Payment Amount |
|
319 | + * |
|
320 | + * @access public |
|
321 | + * @return float |
|
322 | + * @throws EE_Error |
|
323 | + */ |
|
324 | + public function amount() |
|
325 | + { |
|
326 | + return (float) $this->get('PAY_amount'); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * @return mixed |
|
332 | + * @throws EE_Error |
|
333 | + */ |
|
334 | + public function amount_no_code() |
|
335 | + { |
|
336 | + return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * get Payment Gateway Response |
|
342 | + * |
|
343 | + * @access public |
|
344 | + * @throws EE_Error |
|
345 | + */ |
|
346 | + public function gateway_response() |
|
347 | + { |
|
348 | + return $this->get('PAY_gateway_response'); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * get Payment Gateway Transaction ID |
|
354 | + * |
|
355 | + * @access public |
|
356 | + * @throws EE_Error |
|
357 | + */ |
|
358 | + public function txn_id_chq_nmbr() |
|
359 | + { |
|
360 | + return $this->get('PAY_txn_id_chq_nmbr'); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * get Purchase Order Number |
|
366 | + * |
|
367 | + * @access public |
|
368 | + * @throws EE_Error |
|
369 | + */ |
|
370 | + public function po_number() |
|
371 | + { |
|
372 | + return $this->get('PAY_po_number'); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * get Extra Accounting Field |
|
378 | + * |
|
379 | + * @access public |
|
380 | + * @throws EE_Error |
|
381 | + */ |
|
382 | + public function extra_accntng() |
|
383 | + { |
|
384 | + return $this->get('PAY_extra_accntng'); |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * get Payment made via admin source |
|
390 | + * |
|
391 | + * @access public |
|
392 | + * @throws EE_Error |
|
393 | + */ |
|
394 | + public function payment_made_via_admin() |
|
395 | + { |
|
396 | + return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
397 | + } |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * get Payment Details |
|
402 | + * |
|
403 | + * @access public |
|
404 | + * @throws EE_Error |
|
405 | + */ |
|
406 | + public function details() |
|
407 | + { |
|
408 | + return $this->get('PAY_details'); |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * Gets redirect_url |
|
414 | + * |
|
415 | + * @return string |
|
416 | + * @throws EE_Error |
|
417 | + */ |
|
418 | + public function redirect_url() |
|
419 | + { |
|
420 | + return $this->get('PAY_redirect_url'); |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * Gets redirect_args |
|
426 | + * |
|
427 | + * @return array |
|
428 | + * @throws EE_Error |
|
429 | + */ |
|
430 | + public function redirect_args() |
|
431 | + { |
|
432 | + return $this->get('PAY_redirect_args'); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * echoes $this->pretty_status() |
|
438 | + * |
|
439 | + * @param bool $show_icons |
|
440 | + * @return void |
|
441 | + * @throws EE_Error |
|
442 | + */ |
|
443 | + public function e_pretty_status($show_icons = false) |
|
444 | + { |
|
445 | + echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags()); |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * returns a pretty version of the status, good for displaying to users |
|
451 | + * |
|
452 | + * @param bool $show_icons |
|
453 | + * @return string |
|
454 | + * @throws EE_Error |
|
455 | + */ |
|
456 | + public function pretty_status($show_icons = false) |
|
457 | + { |
|
458 | + $status = EEM_Status::instance()->localized_status( |
|
459 | + array($this->STS_ID() => esc_html__('unknown', 'event_espresso')), |
|
460 | + false, |
|
461 | + 'sentence' |
|
462 | + ); |
|
463 | + $icon = ''; |
|
464 | + switch ($this->STS_ID()) { |
|
465 | + case EEM_Payment::status_id_approved: |
|
466 | + $icon = $show_icons |
|
467 | + ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
468 | + : ''; |
|
469 | + break; |
|
470 | + case EEM_Payment::status_id_pending: |
|
471 | + $icon = $show_icons |
|
472 | + ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
473 | + : ''; |
|
474 | + break; |
|
475 | + case EEM_Payment::status_id_cancelled: |
|
476 | + $icon = $show_icons |
|
477 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
478 | + : ''; |
|
479 | + break; |
|
480 | + case EEM_Payment::status_id_declined: |
|
481 | + $icon = $show_icons |
|
482 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
483 | + : ''; |
|
484 | + break; |
|
485 | + } |
|
486 | + return $icon . $status[ $this->STS_ID() ]; |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * For determining the status of the payment |
|
492 | + * |
|
493 | + * @return boolean whether the payment is approved or not |
|
494 | + * @throws EE_Error |
|
495 | + */ |
|
496 | + public function is_approved() |
|
497 | + { |
|
498 | + return $this->status_is(EEM_Payment::status_id_approved); |
|
499 | + } |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * Generally determines if the status of this payment equals |
|
504 | + * the $STS_ID string |
|
505 | + * |
|
506 | + * @param string $STS_ID an ID from the esp_status table/ |
|
507 | + * one of the status_id_* on the EEM_Payment model |
|
508 | + * @return boolean whether the status of this payment equals the status id |
|
509 | + * @throws EE_Error |
|
510 | + */ |
|
511 | + protected function status_is($STS_ID) |
|
512 | + { |
|
513 | + return $STS_ID === $this->STS_ID() ? true : false; |
|
514 | + } |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * For determining the status of the payment |
|
519 | + * |
|
520 | + * @return boolean whether the payment is pending or not |
|
521 | + * @throws EE_Error |
|
522 | + */ |
|
523 | + public function is_pending() |
|
524 | + { |
|
525 | + return $this->status_is(EEM_Payment::status_id_pending); |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * For determining the status of the payment |
|
531 | + * |
|
532 | + * @return boolean |
|
533 | + * @throws EE_Error |
|
534 | + */ |
|
535 | + public function is_cancelled() |
|
536 | + { |
|
537 | + return $this->status_is(EEM_Payment::status_id_cancelled); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * For determining the status of the payment |
|
543 | + * |
|
544 | + * @return boolean |
|
545 | + * @throws EE_Error |
|
546 | + */ |
|
547 | + public function is_declined() |
|
548 | + { |
|
549 | + return $this->status_is(EEM_Payment::status_id_declined); |
|
550 | + } |
|
551 | + |
|
552 | + |
|
553 | + /** |
|
554 | + * For determining the status of the payment |
|
555 | + * |
|
556 | + * @return boolean |
|
557 | + * @throws EE_Error |
|
558 | + */ |
|
559 | + public function is_failed() |
|
560 | + { |
|
561 | + return $this->status_is(EEM_Payment::status_id_failed); |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
567 | + * |
|
568 | + * @return boolean |
|
569 | + * @throws EE_Error |
|
570 | + */ |
|
571 | + public function is_a_refund() |
|
572 | + { |
|
573 | + return $this->amount() < 0 ? true : false; |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * Get the status object of this object |
|
579 | + * |
|
580 | + * @return EE_Status |
|
581 | + * @throws EE_Error |
|
582 | + */ |
|
583 | + public function status_obj() |
|
584 | + { |
|
585 | + return $this->get_first_related('Status'); |
|
586 | + } |
|
587 | + |
|
588 | + |
|
589 | + /** |
|
590 | + * Gets all the extra meta info on this payment |
|
591 | + * |
|
592 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
593 | + * @return EE_Extra_Meta |
|
594 | + * @throws EE_Error |
|
595 | + */ |
|
596 | + public function extra_meta($query_params = array()) |
|
597 | + { |
|
598 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * Gets the last-used payment method on this transaction |
|
604 | + * (we COULD just use the last-made payment, but some payment methods, namely |
|
605 | + * offline ones, dont' create payments) |
|
606 | + * |
|
607 | + * @return EE_Payment_Method |
|
608 | + * @throws EE_Error |
|
609 | + */ |
|
610 | + public function payment_method() |
|
611 | + { |
|
612 | + return $this->get_first_related('Payment_Method'); |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * Gets the HTML for redirecting the user to an offsite gateway |
|
618 | + * You can pass it special content to put inside the form, or use |
|
619 | + * the default inner content (or possibly generate this all yourself using |
|
620 | + * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
621 | + * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
622 | + * (and any querystring variables in the redirect_url are converted into html inputs |
|
623 | + * so browsers submit them properly) |
|
624 | + * |
|
625 | + * @param string $inside_form_html |
|
626 | + * @return string html |
|
627 | + * @throws EE_Error |
|
628 | + */ |
|
629 | + public function redirect_form($inside_form_html = null) |
|
630 | + { |
|
631 | + $redirect_url = $this->redirect_url(); |
|
632 | + if (! empty($redirect_url)) { |
|
633 | + // what ? no inner form content? |
|
634 | + if ($inside_form_html === null) { |
|
635 | + $inside_form_html = EEH_HTML::p( |
|
636 | + sprintf( |
|
637 | + esc_html__( |
|
638 | + 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
639 | + 'event_espresso' |
|
640 | + ), |
|
641 | + EEH_HTML::br(2), |
|
642 | + '<input type="submit" value="', |
|
643 | + '">' |
|
644 | + ), |
|
645 | + '', |
|
646 | + '', |
|
647 | + 'text-align:center;' |
|
648 | + ); |
|
649 | + } |
|
650 | + $method = apply_filters( |
|
651 | + 'FHEE__EE_Payment__redirect_form__method', |
|
652 | + $this->redirect_args() ? 'POST' : 'GET', |
|
653 | + $this |
|
654 | + ); |
|
655 | + // if it's a GET request, we need to remove all the GET params in the querystring |
|
656 | + // and put them into the form instead |
|
657 | + if ($method === 'GET') { |
|
658 | + $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
659 | + $get_params = null; |
|
660 | + parse_str($querystring, $get_params); |
|
661 | + $inside_form_html .= $this->_args_as_inputs($get_params); |
|
662 | + $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
663 | + } |
|
664 | + $form = EEH_HTML::nl(1) |
|
665 | + . '<form method="' |
|
666 | + . $method |
|
667 | + . '" name="gateway_form" action="' |
|
668 | + . $redirect_url |
|
669 | + . '">'; |
|
670 | + $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
671 | + $form .= $inside_form_html; |
|
672 | + $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
673 | + return $form; |
|
674 | + } else { |
|
675 | + return null; |
|
676 | + } |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * Changes all the name-value pairs of the redirect args into html inputs |
|
682 | + * and returns the html as a string |
|
683 | + * |
|
684 | + * @return string |
|
685 | + * @throws EE_Error |
|
686 | + */ |
|
687 | + public function redirect_args_as_inputs() |
|
688 | + { |
|
689 | + return $this->_args_as_inputs($this->redirect_args()); |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * Converts a 2d array of key-value pairs into html hidden inputs |
|
695 | + * and returns the string of html |
|
696 | + * |
|
697 | + * @param array $args key-value pairs |
|
698 | + * @return string |
|
699 | + */ |
|
700 | + protected function _args_as_inputs($args) |
|
701 | + { |
|
702 | + $html = ''; |
|
703 | + if ($args !== null && is_array($args)) { |
|
704 | + foreach ($args as $name => $value) { |
|
705 | + $html .= $this->generateInput($name, $value); |
|
706 | + } |
|
707 | + } |
|
708 | + return $html; |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * Converts either a single name and value or array of values into html hidden inputs |
|
713 | + * and returns the string of html |
|
714 | + * |
|
715 | + * @param string $name |
|
716 | + * @param string|array $value |
|
717 | + * @return string |
|
718 | + */ |
|
719 | + private function generateInput($name, $value) |
|
720 | + { |
|
721 | + if (is_array($value)) { |
|
722 | + $html = ''; |
|
723 | + $name = "{$name}[]"; |
|
724 | + foreach ($value as $array_value) { |
|
725 | + $html .= $this->generateInput($name, $array_value); |
|
726 | + } |
|
727 | + return $html; |
|
728 | + } |
|
729 | + return EEH_HTML::nl() |
|
730 | + . '<input type="hidden" name="' . $name . '"' |
|
731 | + . ' value="' . esc_attr($value) . '"/>'; |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + /** |
|
736 | + * Returns the currency of the payment. |
|
737 | + * (At the time of writing, this will always be the currency in the configuration; |
|
738 | + * however in the future it is anticipated that this will be stored on the payment |
|
739 | + * object itself) |
|
740 | + * |
|
741 | + * @return string for the currency code |
|
742 | + */ |
|
743 | + public function currency_code() |
|
744 | + { |
|
745 | + return EE_Config::instance()->currency->code; |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * apply wp_strip_all_tags to all elements within an array |
|
751 | + * |
|
752 | + * @access private |
|
753 | + * @param mixed $item |
|
754 | + */ |
|
755 | + private function _strip_all_tags_within_array(&$item) |
|
756 | + { |
|
757 | + if (is_object($item)) { |
|
758 | + $item = (array) $item; |
|
759 | + } |
|
760 | + if (is_array($item)) { |
|
761 | + array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
762 | + } else { |
|
763 | + $item = wp_strip_all_tags((string) $item); |
|
764 | + } |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * Returns TRUE is this payment was set to approved during this request (or |
|
770 | + * is approved and was created during this request). False otherwise. |
|
771 | + * |
|
772 | + * @return boolean |
|
773 | + * @throws EE_Error |
|
774 | + */ |
|
775 | + public function just_approved() |
|
776 | + { |
|
777 | + $original_status = EEH_Array::is_set( |
|
778 | + $this->_props_n_values_provided_in_constructor, |
|
779 | + 'STS_ID', |
|
780 | + $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
781 | + ); |
|
782 | + $current_status = $this->status(); |
|
783 | + if ( |
|
784 | + $original_status !== EEM_Payment::status_id_approved |
|
785 | + && $current_status === EEM_Payment::status_id_approved |
|
786 | + ) { |
|
787 | + return true; |
|
788 | + } else { |
|
789 | + return false; |
|
790 | + } |
|
791 | + } |
|
792 | + |
|
793 | + |
|
794 | + /** |
|
795 | + * Overrides parents' get_pretty() function just for legacy reasons |
|
796 | + * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
797 | + * |
|
798 | + * @param string $field_name |
|
799 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
800 | + * (in cases where the same property may be used for different outputs |
|
801 | + * - i.e. datetime, money etc.) |
|
802 | + * @return mixed |
|
803 | + * @throws EE_Error |
|
804 | + */ |
|
805 | + public function get_pretty($field_name, $extra_cache_ref = null) |
|
806 | + { |
|
807 | + if ($field_name === 'PAY_gateway') { |
|
808 | + return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
809 | + } |
|
810 | + return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
811 | + } |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * Gets details regarding which registrations this payment was applied to |
|
816 | + * |
|
817 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
818 | + * @return EE_Registration_Payment[] |
|
819 | + * @throws EE_Error |
|
820 | + */ |
|
821 | + public function registration_payments($query_params = array()) |
|
822 | + { |
|
823 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
824 | + } |
|
825 | + |
|
826 | + |
|
827 | + /** |
|
828 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
829 | + * |
|
830 | + * @return EE_Event|null |
|
831 | + */ |
|
832 | + public function get_first_event() |
|
833 | + { |
|
834 | + $transaction = $this->transaction(); |
|
835 | + if ($transaction instanceof EE_Transaction) { |
|
836 | + $primary_registrant = $transaction->primary_registration(); |
|
837 | + if ($primary_registrant instanceof EE_Registration) { |
|
838 | + return $primary_registrant->event_obj(); |
|
839 | + } |
|
840 | + } |
|
841 | + return null; |
|
842 | + } |
|
843 | + |
|
844 | + |
|
845 | + /** |
|
846 | + * Gets the name of the first event for which is being paid |
|
847 | + * |
|
848 | + * @return string |
|
849 | + */ |
|
850 | + public function get_first_event_name() |
|
851 | + { |
|
852 | + $event = $this->get_first_event(); |
|
853 | + return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso'); |
|
854 | + } |
|
855 | + |
|
856 | + |
|
857 | + /** |
|
858 | + * Returns the payment's transaction's primary registration |
|
859 | + * |
|
860 | + * @return EE_Registration|null |
|
861 | + */ |
|
862 | + public function get_primary_registration() |
|
863 | + { |
|
864 | + if ($this->transaction() instanceof EE_Transaction) { |
|
865 | + return $this->transaction()->primary_registration(); |
|
866 | + } |
|
867 | + return null; |
|
868 | + } |
|
869 | + |
|
870 | + |
|
871 | + /** |
|
872 | + * Gets the payment's transaction's primary registration's attendee, or null |
|
873 | + * |
|
874 | + * @return EE_Attendee|null |
|
875 | + */ |
|
876 | + public function get_primary_attendee() |
|
877 | + { |
|
878 | + $primary_reg = $this->get_primary_registration(); |
|
879 | + if ($primary_reg instanceof EE_Registration) { |
|
880 | + return $primary_reg->attendee(); |
|
881 | + } |
|
882 | + return null; |
|
883 | + } |
|
884 | 884 | } |
@@ -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 | } |
@@ -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 | } |