@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | use EventEspresso\core\services\commands\CommandInterface; |
8 | 8 | |
9 | 9 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
10 | - exit('No direct script access allowed'); |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | |
@@ -23,50 +23,50 @@ discard block |
||
23 | 23 | class CreateRegistrationCommandHandler extends CommandHandler |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var CreateRegistrationService $registration_service |
|
28 | - */ |
|
29 | - private $registration_service; |
|
26 | + /** |
|
27 | + * @var CreateRegistrationService $registration_service |
|
28 | + */ |
|
29 | + private $registration_service; |
|
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * Command constructor |
|
35 | - * |
|
36 | - * @param CreateRegistrationService $registration_service |
|
37 | - */ |
|
38 | - public function __construct(CreateRegistrationService $registration_service) |
|
39 | - { |
|
40 | - $this->registration_service = $registration_service; |
|
41 | - } |
|
33 | + /** |
|
34 | + * Command constructor |
|
35 | + * |
|
36 | + * @param CreateRegistrationService $registration_service |
|
37 | + */ |
|
38 | + public function __construct(CreateRegistrationService $registration_service) |
|
39 | + { |
|
40 | + $this->registration_service = $registration_service; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @param CommandInterface $command |
|
47 | - * @return mixed |
|
48 | - * @throws \OutOfRangeException |
|
49 | - * @throws \EventEspresso\core\exceptions\UnexpectedEntityException |
|
50 | - * @throws \EE_Error |
|
51 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
52 | - */ |
|
53 | - public function handle(CommandInterface $command) |
|
54 | - { |
|
55 | - /** @var CreateRegistrationCommand $command */ |
|
56 | - if ( ! $command instanceof CreateRegistrationCommand) { |
|
57 | - throw new InvalidEntityException(get_class($command), 'CreateRegistrationCommand'); |
|
58 | - } |
|
59 | - // now create a new registration for the ticket |
|
60 | - return $this->registration_service->create( |
|
61 | - $command->ticket()->get_related_event(), |
|
62 | - $command->transaction(), |
|
63 | - $command->ticket(), |
|
64 | - $command->ticketLineItem(), |
|
65 | - $command->regCount(), |
|
66 | - $command->regGroupSize(), |
|
67 | - $command->regStatus() |
|
68 | - ); |
|
69 | - } |
|
45 | + /** |
|
46 | + * @param CommandInterface $command |
|
47 | + * @return mixed |
|
48 | + * @throws \OutOfRangeException |
|
49 | + * @throws \EventEspresso\core\exceptions\UnexpectedEntityException |
|
50 | + * @throws \EE_Error |
|
51 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
52 | + */ |
|
53 | + public function handle(CommandInterface $command) |
|
54 | + { |
|
55 | + /** @var CreateRegistrationCommand $command */ |
|
56 | + if ( ! $command instanceof CreateRegistrationCommand) { |
|
57 | + throw new InvalidEntityException(get_class($command), 'CreateRegistrationCommand'); |
|
58 | + } |
|
59 | + // now create a new registration for the ticket |
|
60 | + return $this->registration_service->create( |
|
61 | + $command->ticket()->get_related_event(), |
|
62 | + $command->transaction(), |
|
63 | + $command->ticket(), |
|
64 | + $command->ticketLineItem(), |
|
65 | + $command->regCount(), |
|
66 | + $command->regGroupSize(), |
|
67 | + $command->regStatus() |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | 72 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -16,672 +16,672 @@ discard block |
||
16 | 16 | abstract class EE_SPCO_Reg_Step |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * $_completed - TRUE if this step has fully completed it's duties |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @type bool $_completed |
|
24 | - */ |
|
25 | - protected $_completed = false; |
|
26 | - |
|
27 | - /** |
|
28 | - * $_is_current_step - TRUE if this is the current step |
|
29 | - * |
|
30 | - * @access protected |
|
31 | - * @type bool $_is_current_step |
|
32 | - */ |
|
33 | - protected $_is_current_step = false; |
|
34 | - |
|
35 | - /** |
|
36 | - * $_order - when the reg step should be run relative to other steps |
|
37 | - * |
|
38 | - * @access protected |
|
39 | - * @type int $_template |
|
40 | - */ |
|
41 | - protected $_order = 0; |
|
42 | - |
|
43 | - /** |
|
44 | - * $_slug - URL param for this step |
|
45 | - * |
|
46 | - * @access protected |
|
47 | - * @type string $_slug |
|
48 | - */ |
|
49 | - protected $_slug; |
|
50 | - |
|
51 | - /** |
|
52 | - * $_name - Step Name - translatable string |
|
53 | - * |
|
54 | - * @access protected |
|
55 | - * @type string $_slug |
|
56 | - */ |
|
57 | - protected $_name; |
|
58 | - |
|
59 | - /** |
|
60 | - * $_submit_button_text - translatable string that appears on this step's submit button |
|
61 | - * |
|
62 | - * @access protected |
|
63 | - * @type string $_slug |
|
64 | - */ |
|
65 | - protected $_submit_button_text; |
|
66 | - |
|
67 | - /** |
|
68 | - * $_template - template name |
|
69 | - * |
|
70 | - * @access protected |
|
71 | - * @type string $_template |
|
72 | - */ |
|
73 | - protected $_template; |
|
74 | - |
|
75 | - /** |
|
76 | - * $_reg_form_name - the form input name and id attribute |
|
77 | - * |
|
78 | - * @access protected |
|
79 | - * @var string $_reg_form_name |
|
80 | - */ |
|
81 | - protected $_reg_form_name; |
|
82 | - |
|
83 | - /** |
|
84 | - * $_success_message - text to display upon successful form submission |
|
85 | - * |
|
86 | - * @access private |
|
87 | - * @var string $_success_message |
|
88 | - */ |
|
89 | - protected $_success_message; |
|
90 | - |
|
91 | - /** |
|
92 | - * $_instructions - a brief description of how to complete the reg step. |
|
93 | - * Usually displayed in conjunction with the previous step's success message. |
|
94 | - * |
|
95 | - * @access private |
|
96 | - * @var string $_instructions |
|
97 | - */ |
|
98 | - protected $_instructions; |
|
99 | - |
|
100 | - /** |
|
101 | - * $_valid_data - the normalized and validated data for this step |
|
102 | - * |
|
103 | - * @access public |
|
104 | - * @var array $_valid_data |
|
105 | - */ |
|
106 | - protected $_valid_data = array(); |
|
107 | - |
|
108 | - /** |
|
109 | - * $reg_form - the registration form for this step |
|
110 | - * |
|
111 | - * @access public |
|
112 | - * @var EE_Form_Section_Proper $reg_form |
|
113 | - */ |
|
114 | - public $reg_form; |
|
115 | - |
|
116 | - /** |
|
117 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @var EE_Checkout $checkout |
|
121 | - */ |
|
122 | - public $checkout; |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - abstract public function translate_js_strings(); |
|
130 | - |
|
131 | - |
|
19 | + /** |
|
20 | + * $_completed - TRUE if this step has fully completed it's duties |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @type bool $_completed |
|
24 | + */ |
|
25 | + protected $_completed = false; |
|
26 | + |
|
27 | + /** |
|
28 | + * $_is_current_step - TRUE if this is the current step |
|
29 | + * |
|
30 | + * @access protected |
|
31 | + * @type bool $_is_current_step |
|
32 | + */ |
|
33 | + protected $_is_current_step = false; |
|
34 | + |
|
35 | + /** |
|
36 | + * $_order - when the reg step should be run relative to other steps |
|
37 | + * |
|
38 | + * @access protected |
|
39 | + * @type int $_template |
|
40 | + */ |
|
41 | + protected $_order = 0; |
|
42 | + |
|
43 | + /** |
|
44 | + * $_slug - URL param for this step |
|
45 | + * |
|
46 | + * @access protected |
|
47 | + * @type string $_slug |
|
48 | + */ |
|
49 | + protected $_slug; |
|
50 | + |
|
51 | + /** |
|
52 | + * $_name - Step Name - translatable string |
|
53 | + * |
|
54 | + * @access protected |
|
55 | + * @type string $_slug |
|
56 | + */ |
|
57 | + protected $_name; |
|
58 | + |
|
59 | + /** |
|
60 | + * $_submit_button_text - translatable string that appears on this step's submit button |
|
61 | + * |
|
62 | + * @access protected |
|
63 | + * @type string $_slug |
|
64 | + */ |
|
65 | + protected $_submit_button_text; |
|
66 | + |
|
67 | + /** |
|
68 | + * $_template - template name |
|
69 | + * |
|
70 | + * @access protected |
|
71 | + * @type string $_template |
|
72 | + */ |
|
73 | + protected $_template; |
|
74 | + |
|
75 | + /** |
|
76 | + * $_reg_form_name - the form input name and id attribute |
|
77 | + * |
|
78 | + * @access protected |
|
79 | + * @var string $_reg_form_name |
|
80 | + */ |
|
81 | + protected $_reg_form_name; |
|
82 | + |
|
83 | + /** |
|
84 | + * $_success_message - text to display upon successful form submission |
|
85 | + * |
|
86 | + * @access private |
|
87 | + * @var string $_success_message |
|
88 | + */ |
|
89 | + protected $_success_message; |
|
90 | + |
|
91 | + /** |
|
92 | + * $_instructions - a brief description of how to complete the reg step. |
|
93 | + * Usually displayed in conjunction with the previous step's success message. |
|
94 | + * |
|
95 | + * @access private |
|
96 | + * @var string $_instructions |
|
97 | + */ |
|
98 | + protected $_instructions; |
|
99 | + |
|
100 | + /** |
|
101 | + * $_valid_data - the normalized and validated data for this step |
|
102 | + * |
|
103 | + * @access public |
|
104 | + * @var array $_valid_data |
|
105 | + */ |
|
106 | + protected $_valid_data = array(); |
|
107 | + |
|
108 | + /** |
|
109 | + * $reg_form - the registration form for this step |
|
110 | + * |
|
111 | + * @access public |
|
112 | + * @var EE_Form_Section_Proper $reg_form |
|
113 | + */ |
|
114 | + public $reg_form; |
|
115 | + |
|
116 | + /** |
|
117 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @var EE_Checkout $checkout |
|
121 | + */ |
|
122 | + public $checkout; |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + abstract public function translate_js_strings(); |
|
130 | + |
|
131 | + |
|
132 | 132 | |
133 | - /** |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - abstract public function enqueue_styles_and_scripts(); |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @return boolean |
|
142 | - */ |
|
143 | - abstract public function initialize_reg_step(); |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - abstract public function generate_reg_form(); |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return boolean |
|
156 | - */ |
|
157 | - abstract public function process_reg_step(); |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @return boolean |
|
163 | - */ |
|
164 | - abstract public function update_reg_step(); |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @return boolean |
|
170 | - */ |
|
171 | - public function completed() |
|
172 | - { |
|
173 | - return $this->_completed; |
|
174 | - } |
|
133 | + /** |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + abstract public function enqueue_styles_and_scripts(); |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @return boolean |
|
142 | + */ |
|
143 | + abstract public function initialize_reg_step(); |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + abstract public function generate_reg_form(); |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return boolean |
|
156 | + */ |
|
157 | + abstract public function process_reg_step(); |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @return boolean |
|
163 | + */ |
|
164 | + abstract public function update_reg_step(); |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @return boolean |
|
170 | + */ |
|
171 | + public function completed() |
|
172 | + { |
|
173 | + return $this->_completed; |
|
174 | + } |
|
175 | 175 | |
176 | 176 | |
177 | 177 | |
178 | - /** |
|
179 | - * set_completed - toggles $_completed to TRUE |
|
180 | - */ |
|
181 | - public function set_completed() |
|
182 | - { |
|
183 | - // DEBUG LOG |
|
184 | - //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
185 | - $this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this); |
|
186 | - } |
|
178 | + /** |
|
179 | + * set_completed - toggles $_completed to TRUE |
|
180 | + */ |
|
181 | + public function set_completed() |
|
182 | + { |
|
183 | + // DEBUG LOG |
|
184 | + //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
185 | + $this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this); |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | 189 | |
190 | - /** |
|
191 | - * set_completed - toggles $_completed to FALSE |
|
192 | - */ |
|
193 | - public function set_not_completed() |
|
194 | - { |
|
195 | - $this->_completed = false; |
|
196 | - } |
|
190 | + /** |
|
191 | + * set_completed - toggles $_completed to FALSE |
|
192 | + */ |
|
193 | + public function set_not_completed() |
|
194 | + { |
|
195 | + $this->_completed = false; |
|
196 | + } |
|
197 | 197 | |
198 | 198 | |
199 | 199 | |
200 | - /** |
|
201 | - * @return string |
|
202 | - */ |
|
203 | - public function name() |
|
204 | - { |
|
205 | - return $this->_name; |
|
206 | - } |
|
200 | + /** |
|
201 | + * @return string |
|
202 | + */ |
|
203 | + public function name() |
|
204 | + { |
|
205 | + return $this->_name; |
|
206 | + } |
|
207 | 207 | |
208 | 208 | |
209 | 209 | |
210 | - /** |
|
211 | - * @return string |
|
212 | - */ |
|
213 | - public function slug() |
|
214 | - { |
|
215 | - return $this->_slug; |
|
216 | - } |
|
210 | + /** |
|
211 | + * @return string |
|
212 | + */ |
|
213 | + public function slug() |
|
214 | + { |
|
215 | + return $this->_slug; |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | 219 | |
220 | - /** |
|
221 | - * submit_button_text |
|
222 | - * the text that appears on the reg step form submit button |
|
223 | - * |
|
224 | - * @return string |
|
225 | - */ |
|
226 | - public function submit_button_text() |
|
227 | - { |
|
228 | - return $this->_submit_button_text; |
|
229 | - } |
|
220 | + /** |
|
221 | + * submit_button_text |
|
222 | + * the text that appears on the reg step form submit button |
|
223 | + * |
|
224 | + * @return string |
|
225 | + */ |
|
226 | + public function submit_button_text() |
|
227 | + { |
|
228 | + return $this->_submit_button_text; |
|
229 | + } |
|
230 | 230 | |
231 | 231 | |
232 | 232 | |
233 | - /** |
|
234 | - * set_submit_button_text |
|
235 | - * sets the text that appears on the reg step form submit button |
|
236 | - * |
|
237 | - * @param string $submit_button_text |
|
238 | - */ |
|
239 | - public function set_submit_button_text($submit_button_text = '') |
|
240 | - { |
|
241 | - if (! empty($submit_button_text)) { |
|
242 | - $this->_submit_button_text = $submit_button_text; |
|
243 | - } else if ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
244 | - if ($this->checkout->revisit) { |
|
245 | - $this->_submit_button_text = sprintf( |
|
246 | - __('Update %s', 'event_espresso'), |
|
247 | - $this->checkout->current_step->name() |
|
248 | - ); |
|
249 | - } else { |
|
250 | - $this->_submit_button_text = sprintf( |
|
251 | - __('Proceed to %s', 'event_espresso'), |
|
252 | - $this->checkout->next_step->name() |
|
253 | - ); |
|
254 | - } |
|
255 | - } |
|
256 | - // filters the submit button text |
|
257 | - $this->_submit_button_text = apply_filters( |
|
258 | - 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
259 | - $this->_submit_button_text, |
|
260 | - $this->checkout |
|
261 | - ); |
|
262 | - } |
|
233 | + /** |
|
234 | + * set_submit_button_text |
|
235 | + * sets the text that appears on the reg step form submit button |
|
236 | + * |
|
237 | + * @param string $submit_button_text |
|
238 | + */ |
|
239 | + public function set_submit_button_text($submit_button_text = '') |
|
240 | + { |
|
241 | + if (! empty($submit_button_text)) { |
|
242 | + $this->_submit_button_text = $submit_button_text; |
|
243 | + } else if ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
244 | + if ($this->checkout->revisit) { |
|
245 | + $this->_submit_button_text = sprintf( |
|
246 | + __('Update %s', 'event_espresso'), |
|
247 | + $this->checkout->current_step->name() |
|
248 | + ); |
|
249 | + } else { |
|
250 | + $this->_submit_button_text = sprintf( |
|
251 | + __('Proceed to %s', 'event_espresso'), |
|
252 | + $this->checkout->next_step->name() |
|
253 | + ); |
|
254 | + } |
|
255 | + } |
|
256 | + // filters the submit button text |
|
257 | + $this->_submit_button_text = apply_filters( |
|
258 | + 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
259 | + $this->_submit_button_text, |
|
260 | + $this->checkout |
|
261 | + ); |
|
262 | + } |
|
263 | 263 | |
264 | 264 | |
265 | 265 | |
266 | - /** |
|
267 | - * @param boolean $is_current_step |
|
268 | - */ |
|
269 | - public function set_is_current_step($is_current_step) |
|
270 | - { |
|
271 | - $this->_is_current_step = $is_current_step; |
|
272 | - } |
|
266 | + /** |
|
267 | + * @param boolean $is_current_step |
|
268 | + */ |
|
269 | + public function set_is_current_step($is_current_step) |
|
270 | + { |
|
271 | + $this->_is_current_step = $is_current_step; |
|
272 | + } |
|
273 | 273 | |
274 | 274 | |
275 | 275 | |
276 | - /** |
|
277 | - * @return boolean |
|
278 | - */ |
|
279 | - public function is_current_step() |
|
280 | - { |
|
281 | - return $this->_is_current_step; |
|
282 | - } |
|
276 | + /** |
|
277 | + * @return boolean |
|
278 | + */ |
|
279 | + public function is_current_step() |
|
280 | + { |
|
281 | + return $this->_is_current_step; |
|
282 | + } |
|
283 | 283 | |
284 | 284 | |
285 | 285 | |
286 | - /** |
|
287 | - * @return boolean |
|
288 | - */ |
|
289 | - public function is_final_step() |
|
290 | - { |
|
291 | - return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration ? true : false; |
|
292 | - } |
|
286 | + /** |
|
287 | + * @return boolean |
|
288 | + */ |
|
289 | + public function is_final_step() |
|
290 | + { |
|
291 | + return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration ? true : false; |
|
292 | + } |
|
293 | 293 | |
294 | 294 | |
295 | 295 | |
296 | - /** |
|
297 | - * @param int $order |
|
298 | - */ |
|
299 | - public function set_order($order) |
|
300 | - { |
|
301 | - $this->_order = $order; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
296 | + /** |
|
297 | + * @param int $order |
|
298 | + */ |
|
299 | + public function set_order($order) |
|
300 | + { |
|
301 | + $this->_order = $order; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | 305 | |
306 | - /** |
|
307 | - * @return int |
|
308 | - */ |
|
309 | - public function order() |
|
310 | - { |
|
311 | - return $this->_order; |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * @return string |
|
318 | - */ |
|
319 | - public function template() |
|
320 | - { |
|
321 | - return $this->_template; |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @return string |
|
328 | - */ |
|
329 | - public function success_message() |
|
330 | - { |
|
331 | - return $this->_success_message; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * _set_success_message |
|
338 | - * |
|
339 | - * @param string $success_message |
|
340 | - */ |
|
341 | - protected function _set_success_message($success_message) |
|
342 | - { |
|
343 | - $this->_success_message = $success_message; |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * _reset_success_message |
|
350 | - * |
|
351 | - * @return void |
|
352 | - */ |
|
353 | - protected function _reset_success_message() |
|
354 | - { |
|
355 | - $this->_success_message = ''; |
|
356 | - } |
|
306 | + /** |
|
307 | + * @return int |
|
308 | + */ |
|
309 | + public function order() |
|
310 | + { |
|
311 | + return $this->_order; |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * @return string |
|
318 | + */ |
|
319 | + public function template() |
|
320 | + { |
|
321 | + return $this->_template; |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @return string |
|
328 | + */ |
|
329 | + public function success_message() |
|
330 | + { |
|
331 | + return $this->_success_message; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * _set_success_message |
|
338 | + * |
|
339 | + * @param string $success_message |
|
340 | + */ |
|
341 | + protected function _set_success_message($success_message) |
|
342 | + { |
|
343 | + $this->_success_message = $success_message; |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * _reset_success_message |
|
350 | + * |
|
351 | + * @return void |
|
352 | + */ |
|
353 | + protected function _reset_success_message() |
|
354 | + { |
|
355 | + $this->_success_message = ''; |
|
356 | + } |
|
357 | 357 | |
358 | 358 | |
359 | 359 | |
360 | - /** |
|
361 | - * @return string |
|
362 | - */ |
|
363 | - public function _instructions() |
|
364 | - { |
|
365 | - return $this->_instructions; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * @param string $instructions |
|
372 | - */ |
|
373 | - public function set_instructions($instructions) |
|
374 | - { |
|
375 | - $this->_instructions = apply_filters( |
|
376 | - 'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions', |
|
377 | - $instructions, |
|
378 | - $this |
|
379 | - ); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * @param array $valid_data |
|
386 | - */ |
|
387 | - public function set_valid_data($valid_data) |
|
388 | - { |
|
389 | - $this->_valid_data = $valid_data; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * @return array |
|
396 | - */ |
|
397 | - public function valid_data() |
|
398 | - { |
|
399 | - if (empty($this->_valid_data)) { |
|
400 | - $this->_valid_data = $this->reg_form->valid_data(); |
|
401 | - } |
|
402 | - return $this->_valid_data; |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * @return string |
|
409 | - */ |
|
410 | - public function reg_form_name() |
|
411 | - { |
|
412 | - if (empty($this->_reg_form_name)) { |
|
413 | - $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
414 | - } |
|
415 | - return $this->_reg_form_name; |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * @param string $reg_form_name |
|
422 | - */ |
|
423 | - protected function set_reg_form_name($reg_form_name) |
|
424 | - { |
|
425 | - $this->_reg_form_name = $reg_form_name; |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * reg_step_url |
|
432 | - * |
|
433 | - * @param string $action |
|
434 | - * @return string |
|
435 | - */ |
|
436 | - public function reg_step_url($action = '') |
|
437 | - { |
|
438 | - $query_args = array('step' => $this->slug()); |
|
439 | - if (! empty($action)) { |
|
440 | - $query_args['action'] = $action; |
|
441 | - } |
|
442 | - // final step has no display |
|
443 | - if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') { |
|
444 | - $query_args['action'] = 'process_reg_step'; |
|
445 | - } |
|
446 | - if ($this->checkout->revisit) { |
|
447 | - $query_args['revisit'] = true; |
|
448 | - } |
|
449 | - if ($this->checkout->reg_url_link) { |
|
450 | - $query_args['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
451 | - } |
|
452 | - return add_query_arg($query_args, $this->checkout->reg_page_base_url); |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - |
|
457 | - /** |
|
458 | - * creates the default hidden inputs section |
|
459 | - * |
|
460 | - * @return EE_Form_Section_Proper |
|
461 | - * @throws \EE_Error |
|
462 | - */ |
|
463 | - public function reg_step_hidden_inputs() |
|
464 | - { |
|
465 | - // hidden inputs for admin registrations |
|
466 | - if ($this->checkout->admin_request) { |
|
467 | - return new EE_Form_Section_Proper( |
|
468 | - array( |
|
469 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
470 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
471 | - 'subsections' => array( |
|
472 | - 'next_step' => new EE_Fixed_Hidden_Input( |
|
473 | - array( |
|
474 | - 'html_name' => 'next_step', |
|
475 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
476 | - 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
477 | - ? $this->checkout->next_step->slug() |
|
478 | - : '', |
|
479 | - ) |
|
480 | - ), |
|
481 | - ), |
|
482 | - ) |
|
483 | - ); |
|
484 | - } else { |
|
485 | - $default_form_action = apply_filters( |
|
486 | - 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
|
487 | - empty($this->checkout->reg_url_link) |
|
488 | - ? 'process_reg_step' |
|
489 | - : 'update_reg_step', |
|
490 | - $this |
|
491 | - ); |
|
492 | - // hidden inputs for frontend registrations |
|
493 | - return new EE_Form_Section_Proper( |
|
494 | - array( |
|
495 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
496 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
497 | - 'subsections' => array( |
|
498 | - 'action' => new EE_Fixed_Hidden_Input( |
|
499 | - array( |
|
500 | - 'html_name' => 'action', |
|
501 | - 'html_id' => 'spco-' . $this->slug() . '-action', |
|
502 | - 'default' => $default_form_action, |
|
503 | - ) |
|
504 | - ), |
|
505 | - 'next_step' => new EE_Fixed_Hidden_Input( |
|
506 | - array( |
|
507 | - 'html_name' => 'next_step', |
|
508 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
509 | - 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
510 | - ? $this->checkout->next_step->slug() |
|
511 | - : '', |
|
512 | - ) |
|
513 | - ), |
|
514 | - 'e_reg_url_link' => new EE_Fixed_Hidden_Input( |
|
515 | - array( |
|
516 | - 'html_name' => 'e_reg_url_link', |
|
517 | - 'html_id' => 'spco-reg_url_link', |
|
518 | - 'default' => $this->checkout->reg_url_link, |
|
519 | - ) |
|
520 | - ), |
|
521 | - 'revisit' => new EE_Fixed_Hidden_Input( |
|
522 | - array( |
|
523 | - 'html_name' => 'revisit', |
|
524 | - 'html_id' => 'spco-revisit', |
|
525 | - 'default' => $this->checkout->revisit, |
|
526 | - ) |
|
527 | - ), |
|
528 | - ), |
|
529 | - ) |
|
530 | - ); |
|
531 | - } |
|
532 | - } |
|
533 | - |
|
534 | - |
|
535 | - |
|
536 | - /** |
|
537 | - * generate_reg_form_for_actions |
|
538 | - * |
|
539 | - * @param array $actions |
|
540 | - * @return void |
|
541 | - */ |
|
542 | - public function generate_reg_form_for_actions($actions = array()) |
|
543 | - { |
|
544 | - $actions = array_merge( |
|
545 | - array( |
|
546 | - 'generate_reg_form', |
|
547 | - 'display_spco_reg_step', |
|
548 | - 'process_reg_step', |
|
549 | - 'update_reg_step', |
|
550 | - ), |
|
551 | - $actions |
|
552 | - ); |
|
553 | - $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true) ? true : false; |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * @return string |
|
560 | - * @throws \EE_Error |
|
561 | - */ |
|
562 | - public function display_reg_form() |
|
563 | - { |
|
564 | - $html = ''; |
|
565 | - if ($this->reg_form instanceof EE_Form_Section_Proper) { |
|
566 | - $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : ''; |
|
567 | - if (EE_Registry::instance()->REQ->ajax) { |
|
568 | - $this->reg_form->localize_validation_rules(); |
|
569 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
570 | - } |
|
571 | - $html .= $this->reg_form->get_html(); |
|
572 | - $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : ''; |
|
573 | - $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : ''; |
|
574 | - } |
|
575 | - return $html; |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
582 | - * |
|
583 | - * @return string |
|
584 | - * @throws \EE_Error |
|
585 | - */ |
|
586 | - public function reg_step_submit_button() |
|
587 | - { |
|
588 | - if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
589 | - return ''; |
|
590 | - } |
|
591 | - ob_start(); |
|
592 | - do_action( |
|
593 | - 'AHEE__before_spco_whats_next_buttons', |
|
594 | - $this->slug(), |
|
595 | - $this->checkout->next_step->slug(), |
|
596 | - $this->checkout |
|
597 | - ); |
|
598 | - $html = ob_get_clean(); |
|
599 | - // generate submit button |
|
600 | - $sbmt_btn = new EE_Submit_Input(array( |
|
601 | - 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
602 | - 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
603 | - 'html_class' => 'spco-next-step-btn', |
|
604 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
605 | - 'default' => $this->submit_button_text(), |
|
606 | - )); |
|
607 | - $sbmt_btn->set_button_css_attributes(true, 'large'); |
|
608 | - $sbmt_btn_html = $sbmt_btn->get_html_for_input(); |
|
609 | - $html .= EEH_HTML::div( |
|
610 | - apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this), |
|
611 | - 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
612 | - 'spco-whats-next-buttons' |
|
613 | - ); |
|
614 | - return $html; |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
621 | - * |
|
622 | - * @return string |
|
623 | - */ |
|
624 | - public function div_class() |
|
625 | - { |
|
626 | - return $this->is_current_step() ? '' : ' hidden'; |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
633 | - * |
|
634 | - * @return string |
|
635 | - */ |
|
636 | - public function edit_lnk_url() |
|
637 | - { |
|
638 | - return add_query_arg(array('step' => $this->slug()), $this->checkout->reg_page_base_url); |
|
639 | - } |
|
640 | - |
|
641 | - |
|
642 | - |
|
643 | - /** |
|
644 | - * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
645 | - * |
|
646 | - * @return string |
|
647 | - */ |
|
648 | - public function edit_link_class() |
|
649 | - { |
|
650 | - return $this->is_current_step() ? ' hidden' : ''; |
|
651 | - } |
|
652 | - |
|
653 | - |
|
654 | - |
|
655 | - /** |
|
656 | - * update_checkout with changes that have been made to the cart |
|
657 | - * |
|
658 | - * @return void |
|
659 | - * @throws \EE_Error |
|
660 | - */ |
|
661 | - public function update_checkout() |
|
662 | - { |
|
663 | - // grab the cart grand total and reset TXN total |
|
664 | - $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total()); |
|
665 | - $this->checkout->stash_transaction_and_checkout(); |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - |
|
670 | - |
|
671 | - |
|
672 | - /** |
|
673 | - * __sleep |
|
674 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
675 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
676 | - * reg form, because if needed, it will be regenerated anyways |
|
677 | - * |
|
678 | - * @return array |
|
679 | - */ |
|
680 | - public function __sleep() |
|
681 | - { |
|
682 | - // remove the reg form and the checkout |
|
683 | - return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout')); |
|
684 | - } |
|
360 | + /** |
|
361 | + * @return string |
|
362 | + */ |
|
363 | + public function _instructions() |
|
364 | + { |
|
365 | + return $this->_instructions; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * @param string $instructions |
|
372 | + */ |
|
373 | + public function set_instructions($instructions) |
|
374 | + { |
|
375 | + $this->_instructions = apply_filters( |
|
376 | + 'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions', |
|
377 | + $instructions, |
|
378 | + $this |
|
379 | + ); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * @param array $valid_data |
|
386 | + */ |
|
387 | + public function set_valid_data($valid_data) |
|
388 | + { |
|
389 | + $this->_valid_data = $valid_data; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * @return array |
|
396 | + */ |
|
397 | + public function valid_data() |
|
398 | + { |
|
399 | + if (empty($this->_valid_data)) { |
|
400 | + $this->_valid_data = $this->reg_form->valid_data(); |
|
401 | + } |
|
402 | + return $this->_valid_data; |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * @return string |
|
409 | + */ |
|
410 | + public function reg_form_name() |
|
411 | + { |
|
412 | + if (empty($this->_reg_form_name)) { |
|
413 | + $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
414 | + } |
|
415 | + return $this->_reg_form_name; |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * @param string $reg_form_name |
|
422 | + */ |
|
423 | + protected function set_reg_form_name($reg_form_name) |
|
424 | + { |
|
425 | + $this->_reg_form_name = $reg_form_name; |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + |
|
430 | + /** |
|
431 | + * reg_step_url |
|
432 | + * |
|
433 | + * @param string $action |
|
434 | + * @return string |
|
435 | + */ |
|
436 | + public function reg_step_url($action = '') |
|
437 | + { |
|
438 | + $query_args = array('step' => $this->slug()); |
|
439 | + if (! empty($action)) { |
|
440 | + $query_args['action'] = $action; |
|
441 | + } |
|
442 | + // final step has no display |
|
443 | + if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') { |
|
444 | + $query_args['action'] = 'process_reg_step'; |
|
445 | + } |
|
446 | + if ($this->checkout->revisit) { |
|
447 | + $query_args['revisit'] = true; |
|
448 | + } |
|
449 | + if ($this->checkout->reg_url_link) { |
|
450 | + $query_args['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
451 | + } |
|
452 | + return add_query_arg($query_args, $this->checkout->reg_page_base_url); |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + |
|
457 | + /** |
|
458 | + * creates the default hidden inputs section |
|
459 | + * |
|
460 | + * @return EE_Form_Section_Proper |
|
461 | + * @throws \EE_Error |
|
462 | + */ |
|
463 | + public function reg_step_hidden_inputs() |
|
464 | + { |
|
465 | + // hidden inputs for admin registrations |
|
466 | + if ($this->checkout->admin_request) { |
|
467 | + return new EE_Form_Section_Proper( |
|
468 | + array( |
|
469 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
470 | + 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
471 | + 'subsections' => array( |
|
472 | + 'next_step' => new EE_Fixed_Hidden_Input( |
|
473 | + array( |
|
474 | + 'html_name' => 'next_step', |
|
475 | + 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
476 | + 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
477 | + ? $this->checkout->next_step->slug() |
|
478 | + : '', |
|
479 | + ) |
|
480 | + ), |
|
481 | + ), |
|
482 | + ) |
|
483 | + ); |
|
484 | + } else { |
|
485 | + $default_form_action = apply_filters( |
|
486 | + 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
|
487 | + empty($this->checkout->reg_url_link) |
|
488 | + ? 'process_reg_step' |
|
489 | + : 'update_reg_step', |
|
490 | + $this |
|
491 | + ); |
|
492 | + // hidden inputs for frontend registrations |
|
493 | + return new EE_Form_Section_Proper( |
|
494 | + array( |
|
495 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
496 | + 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
497 | + 'subsections' => array( |
|
498 | + 'action' => new EE_Fixed_Hidden_Input( |
|
499 | + array( |
|
500 | + 'html_name' => 'action', |
|
501 | + 'html_id' => 'spco-' . $this->slug() . '-action', |
|
502 | + 'default' => $default_form_action, |
|
503 | + ) |
|
504 | + ), |
|
505 | + 'next_step' => new EE_Fixed_Hidden_Input( |
|
506 | + array( |
|
507 | + 'html_name' => 'next_step', |
|
508 | + 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
509 | + 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
510 | + ? $this->checkout->next_step->slug() |
|
511 | + : '', |
|
512 | + ) |
|
513 | + ), |
|
514 | + 'e_reg_url_link' => new EE_Fixed_Hidden_Input( |
|
515 | + array( |
|
516 | + 'html_name' => 'e_reg_url_link', |
|
517 | + 'html_id' => 'spco-reg_url_link', |
|
518 | + 'default' => $this->checkout->reg_url_link, |
|
519 | + ) |
|
520 | + ), |
|
521 | + 'revisit' => new EE_Fixed_Hidden_Input( |
|
522 | + array( |
|
523 | + 'html_name' => 'revisit', |
|
524 | + 'html_id' => 'spco-revisit', |
|
525 | + 'default' => $this->checkout->revisit, |
|
526 | + ) |
|
527 | + ), |
|
528 | + ), |
|
529 | + ) |
|
530 | + ); |
|
531 | + } |
|
532 | + } |
|
533 | + |
|
534 | + |
|
535 | + |
|
536 | + /** |
|
537 | + * generate_reg_form_for_actions |
|
538 | + * |
|
539 | + * @param array $actions |
|
540 | + * @return void |
|
541 | + */ |
|
542 | + public function generate_reg_form_for_actions($actions = array()) |
|
543 | + { |
|
544 | + $actions = array_merge( |
|
545 | + array( |
|
546 | + 'generate_reg_form', |
|
547 | + 'display_spco_reg_step', |
|
548 | + 'process_reg_step', |
|
549 | + 'update_reg_step', |
|
550 | + ), |
|
551 | + $actions |
|
552 | + ); |
|
553 | + $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true) ? true : false; |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * @return string |
|
560 | + * @throws \EE_Error |
|
561 | + */ |
|
562 | + public function display_reg_form() |
|
563 | + { |
|
564 | + $html = ''; |
|
565 | + if ($this->reg_form instanceof EE_Form_Section_Proper) { |
|
566 | + $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : ''; |
|
567 | + if (EE_Registry::instance()->REQ->ajax) { |
|
568 | + $this->reg_form->localize_validation_rules(); |
|
569 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
570 | + } |
|
571 | + $html .= $this->reg_form->get_html(); |
|
572 | + $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : ''; |
|
573 | + $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : ''; |
|
574 | + } |
|
575 | + return $html; |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
582 | + * |
|
583 | + * @return string |
|
584 | + * @throws \EE_Error |
|
585 | + */ |
|
586 | + public function reg_step_submit_button() |
|
587 | + { |
|
588 | + if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
589 | + return ''; |
|
590 | + } |
|
591 | + ob_start(); |
|
592 | + do_action( |
|
593 | + 'AHEE__before_spco_whats_next_buttons', |
|
594 | + $this->slug(), |
|
595 | + $this->checkout->next_step->slug(), |
|
596 | + $this->checkout |
|
597 | + ); |
|
598 | + $html = ob_get_clean(); |
|
599 | + // generate submit button |
|
600 | + $sbmt_btn = new EE_Submit_Input(array( |
|
601 | + 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
602 | + 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
603 | + 'html_class' => 'spco-next-step-btn', |
|
604 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
605 | + 'default' => $this->submit_button_text(), |
|
606 | + )); |
|
607 | + $sbmt_btn->set_button_css_attributes(true, 'large'); |
|
608 | + $sbmt_btn_html = $sbmt_btn->get_html_for_input(); |
|
609 | + $html .= EEH_HTML::div( |
|
610 | + apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this), |
|
611 | + 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
612 | + 'spco-whats-next-buttons' |
|
613 | + ); |
|
614 | + return $html; |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
621 | + * |
|
622 | + * @return string |
|
623 | + */ |
|
624 | + public function div_class() |
|
625 | + { |
|
626 | + return $this->is_current_step() ? '' : ' hidden'; |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
633 | + * |
|
634 | + * @return string |
|
635 | + */ |
|
636 | + public function edit_lnk_url() |
|
637 | + { |
|
638 | + return add_query_arg(array('step' => $this->slug()), $this->checkout->reg_page_base_url); |
|
639 | + } |
|
640 | + |
|
641 | + |
|
642 | + |
|
643 | + /** |
|
644 | + * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
645 | + * |
|
646 | + * @return string |
|
647 | + */ |
|
648 | + public function edit_link_class() |
|
649 | + { |
|
650 | + return $this->is_current_step() ? ' hidden' : ''; |
|
651 | + } |
|
652 | + |
|
653 | + |
|
654 | + |
|
655 | + /** |
|
656 | + * update_checkout with changes that have been made to the cart |
|
657 | + * |
|
658 | + * @return void |
|
659 | + * @throws \EE_Error |
|
660 | + */ |
|
661 | + public function update_checkout() |
|
662 | + { |
|
663 | + // grab the cart grand total and reset TXN total |
|
664 | + $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total()); |
|
665 | + $this->checkout->stash_transaction_and_checkout(); |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + |
|
670 | + |
|
671 | + |
|
672 | + /** |
|
673 | + * __sleep |
|
674 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
675 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
676 | + * reg form, because if needed, it will be regenerated anyways |
|
677 | + * |
|
678 | + * @return array |
|
679 | + */ |
|
680 | + public function __sleep() |
|
681 | + { |
|
682 | + // remove the reg form and the checkout |
|
683 | + return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout')); |
|
684 | + } |
|
685 | 685 | |
686 | 686 | |
687 | 687 |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | */ |
239 | 239 | public function set_submit_button_text($submit_button_text = '') |
240 | 240 | { |
241 | - if (! empty($submit_button_text)) { |
|
241 | + if ( ! empty($submit_button_text)) { |
|
242 | 242 | $this->_submit_button_text = $submit_button_text; |
243 | 243 | } else if ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
244 | 244 | if ($this->checkout->revisit) { |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | public function reg_form_name() |
411 | 411 | { |
412 | 412 | if (empty($this->_reg_form_name)) { |
413 | - $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
413 | + $this->set_reg_form_name('ee-spco-'.$this->slug().'-reg-step-form'); |
|
414 | 414 | } |
415 | 415 | return $this->_reg_form_name; |
416 | 416 | } |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | public function reg_step_url($action = '') |
437 | 437 | { |
438 | 438 | $query_args = array('step' => $this->slug()); |
439 | - if (! empty($action)) { |
|
439 | + if ( ! empty($action)) { |
|
440 | 440 | $query_args['action'] = $action; |
441 | 441 | } |
442 | 442 | // final step has no display |
@@ -467,12 +467,12 @@ discard block |
||
467 | 467 | return new EE_Form_Section_Proper( |
468 | 468 | array( |
469 | 469 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
470 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
470 | + 'html_id' => 'ee-'.$this->slug().'-hidden-inputs', |
|
471 | 471 | 'subsections' => array( |
472 | 472 | 'next_step' => new EE_Fixed_Hidden_Input( |
473 | 473 | array( |
474 | 474 | 'html_name' => 'next_step', |
475 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
475 | + 'html_id' => 'spco-'.$this->slug().'-next-step', |
|
476 | 476 | 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
477 | 477 | ? $this->checkout->next_step->slug() |
478 | 478 | : '', |
@@ -493,19 +493,19 @@ discard block |
||
493 | 493 | return new EE_Form_Section_Proper( |
494 | 494 | array( |
495 | 495 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
496 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
496 | + 'html_id' => 'ee-'.$this->slug().'-hidden-inputs', |
|
497 | 497 | 'subsections' => array( |
498 | 498 | 'action' => new EE_Fixed_Hidden_Input( |
499 | 499 | array( |
500 | 500 | 'html_name' => 'action', |
501 | - 'html_id' => 'spco-' . $this->slug() . '-action', |
|
501 | + 'html_id' => 'spco-'.$this->slug().'-action', |
|
502 | 502 | 'default' => $default_form_action, |
503 | 503 | ) |
504 | 504 | ), |
505 | 505 | 'next_step' => new EE_Fixed_Hidden_Input( |
506 | 506 | array( |
507 | 507 | 'html_name' => 'next_step', |
508 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
508 | + 'html_id' => 'spco-'.$this->slug().'-next-step', |
|
509 | 509 | 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
510 | 510 | ? $this->checkout->next_step->slug() |
511 | 511 | : '', |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | */ |
586 | 586 | public function reg_step_submit_button() |
587 | 587 | { |
588 | - if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
588 | + if ( ! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
589 | 589 | return ''; |
590 | 590 | } |
591 | 591 | ob_start(); |
@@ -598,17 +598,17 @@ discard block |
||
598 | 598 | $html = ob_get_clean(); |
599 | 599 | // generate submit button |
600 | 600 | $sbmt_btn = new EE_Submit_Input(array( |
601 | - 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
602 | - 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
601 | + 'html_name' => 'spco-go-to-step-'.$this->checkout->next_step->slug(), |
|
602 | + 'html_id' => 'spco-go-to-step-'.$this->checkout->next_step->slug(), |
|
603 | 603 | 'html_class' => 'spco-next-step-btn', |
604 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
604 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
605 | 605 | 'default' => $this->submit_button_text(), |
606 | 606 | )); |
607 | 607 | $sbmt_btn->set_button_css_attributes(true, 'large'); |
608 | 608 | $sbmt_btn_html = $sbmt_btn->get_html_for_input(); |
609 | 609 | $html .= EEH_HTML::div( |
610 | 610 | apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this), |
611 | - 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
611 | + 'spco-'.$this->slug().'-whats-next-buttons-dv', |
|
612 | 612 | 'spco-whats-next-buttons' |
613 | 613 | ); |
614 | 614 | return $html; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use EventEspresso\core\services\commands\CommandRequiresCapCheckInterface; |
14 | 14 | |
15 | 15 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
16 | - exit('No direct script access allowed'); |
|
16 | + exit('No direct script access allowed'); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | |
@@ -29,162 +29,162 @@ discard block |
||
29 | 29 | class CreateRegistrationCommand extends Command implements CommandRequiresCapCheckInterface |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * @var EE_Transaction $transaction |
|
34 | - */ |
|
35 | - private $transaction; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var EE_Ticket $ticket |
|
39 | - */ |
|
40 | - private $ticket; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Line_Item $ticket_line_item |
|
44 | - */ |
|
45 | - private $ticket_line_item; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var int $reg_count |
|
49 | - */ |
|
50 | - private $reg_count; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var int $reg_group_size |
|
54 | - */ |
|
55 | - private $reg_group_size; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var string $reg_status |
|
59 | - */ |
|
60 | - private $reg_status; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var EE_Registration $registration |
|
64 | - */ |
|
65 | - protected $registration; |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * CreateRegistrationCommand constructor. |
|
71 | - * |
|
72 | - * @param EE_Transaction $transaction |
|
73 | - * @param EE_Line_Item $ticket_line_item |
|
74 | - * @param int $reg_count |
|
75 | - * @param int $reg_group_size |
|
76 | - * @param string $reg_status |
|
77 | - * @throws InvalidEntityException |
|
78 | - */ |
|
79 | - public function __construct( |
|
80 | - EE_Transaction $transaction, |
|
81 | - EE_Line_Item $ticket_line_item, |
|
82 | - $reg_count = 1, |
|
83 | - $reg_group_size = 0, |
|
84 | - $reg_status = EEM_Registration::status_id_incomplete |
|
85 | - ) { |
|
86 | - // grab the related ticket object for this line_item |
|
87 | - $this->ticket = $ticket_line_item->ticket(); |
|
88 | - if ( ! $this->ticket instanceof EE_Ticket) { |
|
89 | - throw new InvalidEntityException( |
|
90 | - is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
91 | - 'EE_Ticket', |
|
92 | - sprintf( |
|
93 | - __('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
94 | - $ticket_line_item->ID() |
|
95 | - ) |
|
96 | - ); |
|
97 | - } |
|
98 | - $this->transaction = $transaction; |
|
99 | - $this->ticket_line_item = $ticket_line_item; |
|
100 | - $this->reg_count = absint($reg_count); |
|
101 | - $this->reg_group_size = absint($reg_group_size); |
|
102 | - $this->reg_status = $reg_status; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @return \EventEspresso\core\domain\services\capabilities\CapCheckInterface |
|
109 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
110 | - */ |
|
111 | - public function getCapCheck() |
|
112 | - { |
|
113 | - if ( ! $this->cap_check instanceof CapCheckInterface) { |
|
114 | - return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
|
115 | - } |
|
116 | - return $this->cap_check; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @return EE_Transaction |
|
123 | - */ |
|
124 | - public function transaction() |
|
125 | - { |
|
126 | - return $this->transaction; |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @return EE_Ticket |
|
133 | - */ |
|
134 | - public function ticket() |
|
135 | - { |
|
136 | - return $this->ticket; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @return EE_Line_Item |
|
143 | - */ |
|
144 | - public function ticketLineItem() |
|
145 | - { |
|
146 | - return $this->ticket_line_item; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @return int |
|
153 | - */ |
|
154 | - public function regCount() |
|
155 | - { |
|
156 | - return $this->reg_count; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @return int |
|
163 | - */ |
|
164 | - public function regGroupSize() |
|
165 | - { |
|
166 | - return $this->reg_group_size; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - public function regStatus() |
|
175 | - { |
|
176 | - return $this->reg_status; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * @return EE_Registration |
|
183 | - */ |
|
184 | - public function registration() |
|
185 | - { |
|
186 | - return $this->registration; |
|
187 | - } |
|
32 | + /** |
|
33 | + * @var EE_Transaction $transaction |
|
34 | + */ |
|
35 | + private $transaction; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var EE_Ticket $ticket |
|
39 | + */ |
|
40 | + private $ticket; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Line_Item $ticket_line_item |
|
44 | + */ |
|
45 | + private $ticket_line_item; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var int $reg_count |
|
49 | + */ |
|
50 | + private $reg_count; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var int $reg_group_size |
|
54 | + */ |
|
55 | + private $reg_group_size; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var string $reg_status |
|
59 | + */ |
|
60 | + private $reg_status; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var EE_Registration $registration |
|
64 | + */ |
|
65 | + protected $registration; |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * CreateRegistrationCommand constructor. |
|
71 | + * |
|
72 | + * @param EE_Transaction $transaction |
|
73 | + * @param EE_Line_Item $ticket_line_item |
|
74 | + * @param int $reg_count |
|
75 | + * @param int $reg_group_size |
|
76 | + * @param string $reg_status |
|
77 | + * @throws InvalidEntityException |
|
78 | + */ |
|
79 | + public function __construct( |
|
80 | + EE_Transaction $transaction, |
|
81 | + EE_Line_Item $ticket_line_item, |
|
82 | + $reg_count = 1, |
|
83 | + $reg_group_size = 0, |
|
84 | + $reg_status = EEM_Registration::status_id_incomplete |
|
85 | + ) { |
|
86 | + // grab the related ticket object for this line_item |
|
87 | + $this->ticket = $ticket_line_item->ticket(); |
|
88 | + if ( ! $this->ticket instanceof EE_Ticket) { |
|
89 | + throw new InvalidEntityException( |
|
90 | + is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
91 | + 'EE_Ticket', |
|
92 | + sprintf( |
|
93 | + __('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
94 | + $ticket_line_item->ID() |
|
95 | + ) |
|
96 | + ); |
|
97 | + } |
|
98 | + $this->transaction = $transaction; |
|
99 | + $this->ticket_line_item = $ticket_line_item; |
|
100 | + $this->reg_count = absint($reg_count); |
|
101 | + $this->reg_group_size = absint($reg_group_size); |
|
102 | + $this->reg_status = $reg_status; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @return \EventEspresso\core\domain\services\capabilities\CapCheckInterface |
|
109 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
110 | + */ |
|
111 | + public function getCapCheck() |
|
112 | + { |
|
113 | + if ( ! $this->cap_check instanceof CapCheckInterface) { |
|
114 | + return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
|
115 | + } |
|
116 | + return $this->cap_check; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @return EE_Transaction |
|
123 | + */ |
|
124 | + public function transaction() |
|
125 | + { |
|
126 | + return $this->transaction; |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @return EE_Ticket |
|
133 | + */ |
|
134 | + public function ticket() |
|
135 | + { |
|
136 | + return $this->ticket; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @return EE_Line_Item |
|
143 | + */ |
|
144 | + public function ticketLineItem() |
|
145 | + { |
|
146 | + return $this->ticket_line_item; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @return int |
|
153 | + */ |
|
154 | + public function regCount() |
|
155 | + { |
|
156 | + return $this->reg_count; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @return int |
|
163 | + */ |
|
164 | + public function regGroupSize() |
|
165 | + { |
|
166 | + return $this->reg_group_size; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + public function regStatus() |
|
175 | + { |
|
176 | + return $this->reg_status; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * @return EE_Registration |
|
183 | + */ |
|
184 | + public function registration() |
|
185 | + { |
|
186 | + return $this->registration; |
|
187 | + } |
|
188 | 188 | |
189 | 189 | |
190 | 190 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | use InvalidArgumentException; |
8 | 8 | |
9 | 9 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
10 | - exit('No direct script access allowed'); |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | |
@@ -23,103 +23,103 @@ discard block |
||
23 | 23 | class RegUrlLink |
24 | 24 | { |
25 | 25 | |
26 | - /* |
|
26 | + /* |
|
27 | 27 | * @var string $reg_url_link |
28 | 28 | */ |
29 | - private $reg_url_link; |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @param string $reg_url_link |
|
35 | - * @return RegUrlLink |
|
36 | - * @throws InvalidArgumentException |
|
37 | - */ |
|
38 | - public static function fromRegUrlLinkString($reg_url_link) |
|
39 | - { |
|
40 | - if (empty($reg_url_link) || ! is_string($reg_url_link)) { |
|
41 | - throw new InvalidArgumentException( |
|
42 | - __( |
|
43 | - 'You must supply a valid non-empty string to generate a reg_url_link.', |
|
44 | - 'event_espresso' |
|
45 | - ) |
|
46 | - ); |
|
47 | - } |
|
48 | - return new RegUrlLink(1, '', $reg_url_link); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @param EE_Registration $registration |
|
55 | - * @return RegUrlLink |
|
56 | - * @throws EntityNotFoundException |
|
57 | - * @throws EE_Error |
|
58 | - * @throws InvalidArgumentException |
|
59 | - */ |
|
60 | - public static function fromRegistration(EE_Registration $registration) |
|
61 | - { |
|
62 | - return new RegUrlLink( |
|
63 | - $registration->count(), |
|
64 | - $registration->ticket_line_item() |
|
65 | - ); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * CreateRegUrlLinkCommand constructor. |
|
72 | - * |
|
73 | - * @param int $reg_count |
|
74 | - * @param mixed $base_code |
|
75 | - * @param string $reg_url_link |
|
76 | - * @throws InvalidArgumentException |
|
77 | - */ |
|
78 | - public function __construct( |
|
79 | - $reg_count = 1, |
|
80 | - $base_code = '', |
|
81 | - $reg_url_link = '' |
|
82 | - ) { |
|
83 | - if ( ! empty($reg_url_link) && is_string($reg_url_link)) { |
|
84 | - $this->reg_url_link = apply_filters( |
|
85 | - 'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link', |
|
86 | - $reg_url_link, |
|
87 | - $reg_count, |
|
88 | - $base_code, |
|
89 | - $reg_url_link |
|
90 | - ); |
|
91 | - return; |
|
92 | - } |
|
93 | - $reg_count = max(1, absint($reg_count)); |
|
94 | - $base_code = $base_code instanceof \EE_Line_Item ? $base_code->code() : $base_code; |
|
95 | - if (empty($base_code) || ! is_string($base_code)) { |
|
96 | - throw new InvalidArgumentException( |
|
97 | - __( |
|
98 | - 'You must supply a valid EE_Line_Item or a non-empty string to generate a reg_url_link.', |
|
99 | - 'event_espresso' |
|
100 | - ) |
|
101 | - ); |
|
102 | - } |
|
103 | - $this->reg_url_link = (string) apply_filters( |
|
104 | - 'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link', |
|
105 | - $reg_count . '-' . md5($base_code . microtime()), |
|
106 | - $reg_count, |
|
107 | - $base_code, |
|
108 | - $reg_url_link |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * Return the object as a string |
|
116 | - * |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - public function __toString() |
|
120 | - { |
|
121 | - return $this->reg_url_link; |
|
122 | - } |
|
29 | + private $reg_url_link; |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @param string $reg_url_link |
|
35 | + * @return RegUrlLink |
|
36 | + * @throws InvalidArgumentException |
|
37 | + */ |
|
38 | + public static function fromRegUrlLinkString($reg_url_link) |
|
39 | + { |
|
40 | + if (empty($reg_url_link) || ! is_string($reg_url_link)) { |
|
41 | + throw new InvalidArgumentException( |
|
42 | + __( |
|
43 | + 'You must supply a valid non-empty string to generate a reg_url_link.', |
|
44 | + 'event_espresso' |
|
45 | + ) |
|
46 | + ); |
|
47 | + } |
|
48 | + return new RegUrlLink(1, '', $reg_url_link); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @param EE_Registration $registration |
|
55 | + * @return RegUrlLink |
|
56 | + * @throws EntityNotFoundException |
|
57 | + * @throws EE_Error |
|
58 | + * @throws InvalidArgumentException |
|
59 | + */ |
|
60 | + public static function fromRegistration(EE_Registration $registration) |
|
61 | + { |
|
62 | + return new RegUrlLink( |
|
63 | + $registration->count(), |
|
64 | + $registration->ticket_line_item() |
|
65 | + ); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * CreateRegUrlLinkCommand constructor. |
|
72 | + * |
|
73 | + * @param int $reg_count |
|
74 | + * @param mixed $base_code |
|
75 | + * @param string $reg_url_link |
|
76 | + * @throws InvalidArgumentException |
|
77 | + */ |
|
78 | + public function __construct( |
|
79 | + $reg_count = 1, |
|
80 | + $base_code = '', |
|
81 | + $reg_url_link = '' |
|
82 | + ) { |
|
83 | + if ( ! empty($reg_url_link) && is_string($reg_url_link)) { |
|
84 | + $this->reg_url_link = apply_filters( |
|
85 | + 'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link', |
|
86 | + $reg_url_link, |
|
87 | + $reg_count, |
|
88 | + $base_code, |
|
89 | + $reg_url_link |
|
90 | + ); |
|
91 | + return; |
|
92 | + } |
|
93 | + $reg_count = max(1, absint($reg_count)); |
|
94 | + $base_code = $base_code instanceof \EE_Line_Item ? $base_code->code() : $base_code; |
|
95 | + if (empty($base_code) || ! is_string($base_code)) { |
|
96 | + throw new InvalidArgumentException( |
|
97 | + __( |
|
98 | + 'You must supply a valid EE_Line_Item or a non-empty string to generate a reg_url_link.', |
|
99 | + 'event_espresso' |
|
100 | + ) |
|
101 | + ); |
|
102 | + } |
|
103 | + $this->reg_url_link = (string) apply_filters( |
|
104 | + 'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link', |
|
105 | + $reg_count . '-' . md5($base_code . microtime()), |
|
106 | + $reg_count, |
|
107 | + $base_code, |
|
108 | + $reg_url_link |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * Return the object as a string |
|
116 | + * |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + public function __toString() |
|
120 | + { |
|
121 | + return $this->reg_url_link; |
|
122 | + } |
|
123 | 123 | } |
124 | 124 | // End of file RegUrlLink.php |
125 | 125 | // Location: /RegUrlLink.php |
126 | 126 | \ No newline at end of file |
@@ -102,7 +102,7 @@ |
||
102 | 102 | } |
103 | 103 | $this->reg_url_link = (string) apply_filters( |
104 | 104 | 'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link', |
105 | - $reg_count . '-' . md5($base_code . microtime()), |
|
105 | + $reg_count.'-'.md5($base_code.microtime()), |
|
106 | 106 | $reg_count, |
107 | 107 | $base_code, |
108 | 108 | $reg_url_link |
@@ -462,29 +462,29 @@ discard block |
||
462 | 462 | |
463 | 463 | |
464 | 464 | |
465 | - /** |
|
466 | - * Gets all payments which have not been approved |
|
467 | - * @return \EEI_Payment[] |
|
468 | - * @throws EE_Error if a model is misconfigured somehow |
|
469 | - */ |
|
465 | + /** |
|
466 | + * Gets all payments which have not been approved |
|
467 | + * @return \EEI_Payment[] |
|
468 | + * @throws EE_Error if a model is misconfigured somehow |
|
469 | + */ |
|
470 | 470 | public function pending_payments() |
471 | - { |
|
472 | - return $this->get_many_related( |
|
473 | - 'Payment', |
|
474 | - array( |
|
475 | - array( |
|
476 | - 'STS_ID' => EEM_Payment::status_id_pending |
|
477 | - ), |
|
478 | - 'order_by' => array( |
|
479 | - 'PAY_timestamp' => 'DESC' |
|
480 | - ) |
|
481 | - ) |
|
482 | - ); |
|
483 | - } |
|
484 | - |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
471 | + { |
|
472 | + return $this->get_many_related( |
|
473 | + 'Payment', |
|
474 | + array( |
|
475 | + array( |
|
476 | + 'STS_ID' => EEM_Payment::status_id_pending |
|
477 | + ), |
|
478 | + 'order_by' => array( |
|
479 | + 'PAY_timestamp' => 'DESC' |
|
480 | + ) |
|
481 | + ) |
|
482 | + ); |
|
483 | + } |
|
484 | + |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | 488 | * echoes $this->pretty_status() |
489 | 489 | * |
490 | 490 | * @param bool $show_icons |
@@ -645,20 +645,20 @@ discard block |
||
645 | 645 | * @throws \EE_Error |
646 | 646 | */ |
647 | 647 | public function primary_registration() { |
648 | - $registrations = (array) $this->get_many_related( |
|
649 | - 'Registration', array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)) |
|
650 | - ); |
|
651 | - foreach ($registrations as $registration) { |
|
652 | - // valid registration that is NOT cancelled or declined ? |
|
653 | - if( |
|
654 | - $registration instanceof EE_Registration |
|
655 | - && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true) |
|
656 | - ) { |
|
657 | - return $registration; |
|
658 | - } |
|
659 | - } |
|
660 | - // nothing valid found, so just return first thing from array of results |
|
661 | - return reset($registrations); |
|
648 | + $registrations = (array) $this->get_many_related( |
|
649 | + 'Registration', array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)) |
|
650 | + ); |
|
651 | + foreach ($registrations as $registration) { |
|
652 | + // valid registration that is NOT cancelled or declined ? |
|
653 | + if( |
|
654 | + $registration instanceof EE_Registration |
|
655 | + && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true) |
|
656 | + ) { |
|
657 | + return $registration; |
|
658 | + } |
|
659 | + } |
|
660 | + // nothing valid found, so just return first thing from array of results |
|
661 | + return reset($registrations); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * EE_Transaction class |
@@ -34,13 +34,13 @@ discard block |
||
34 | 34 | * @return EE_Transaction |
35 | 35 | * @throws \EE_Error |
36 | 36 | */ |
37 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
38 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
37 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
38 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
39 | 39 | $txn = $has_object |
40 | 40 | ? $has_object |
41 | - : new self( $props_n_values, false, $timezone, $date_formats ); |
|
42 | - if ( ! $has_object ) { |
|
43 | - $txn->set_old_txn_status( $txn->status_ID() ); |
|
41 | + : new self($props_n_values, false, $timezone, $date_formats); |
|
42 | + if ( ! $has_object) { |
|
43 | + $txn->set_old_txn_status($txn->status_ID()); |
|
44 | 44 | } |
45 | 45 | return $txn; |
46 | 46 | } |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | * @return EE_Transaction |
55 | 55 | * @throws \EE_Error |
56 | 56 | */ |
57 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
58 | - $txn = new self( $props_n_values, TRUE, $timezone ); |
|
59 | - $txn->set_old_txn_status( $txn->status_ID() ); |
|
57 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
58 | + $txn = new self($props_n_values, TRUE, $timezone); |
|
59 | + $txn->set_old_txn_status($txn->status_ID()); |
|
60 | 60 | return $txn; |
61 | 61 | } |
62 | 62 | |
@@ -73,16 +73,16 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function lock() { |
75 | 75 | // attempt to set lock, but if that fails... |
76 | - if ( ! $this->add_extra_meta( 'lock', time(), true ) ) { |
|
76 | + if ( ! $this->add_extra_meta('lock', time(), true)) { |
|
77 | 77 | // then attempt to remove the lock in case it is expired |
78 | - if ( $this->_remove_expired_lock() ) { |
|
78 | + if ($this->_remove_expired_lock()) { |
|
79 | 79 | // if removal was successful, then try setting lock again |
80 | 80 | $this->lock(); |
81 | 81 | } else { |
82 | 82 | // but if the lock can not be removed, then throw an exception |
83 | 83 | throw new EE_Error( |
84 | 84 | sprintf( |
85 | - __( 'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', 'event_espresso' ), |
|
85 | + __('Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', 'event_espresso'), |
|
86 | 86 | $this->ID() |
87 | 87 | ) |
88 | 88 | ); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @throws \EE_Error |
102 | 102 | */ |
103 | 103 | public function unlock() { |
104 | - return $this->delete_extra_meta( 'lock' ); |
|
104 | + return $this->delete_extra_meta('lock'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function is_locked() { |
124 | 124 | // if TXN is not locked, then return false immediately |
125 | - if ( ! $this->_get_lock() ) { |
|
125 | + if ( ! $this->_get_lock()) { |
|
126 | 126 | return false; |
127 | 127 | } |
128 | 128 | // if not, then let's try and remove the lock in case it's expired... |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @throws \EE_Error |
144 | 144 | */ |
145 | 145 | protected function _get_lock() { |
146 | - return (int)$this->get_extra_meta( 'lock', true, 0 ); |
|
146 | + return (int) $this->get_extra_meta('lock', true, 0); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | protected function _remove_expired_lock() { |
160 | 160 | $locked = $this->_get_lock(); |
161 | - if ( $locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked ) { |
|
161 | + if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) { |
|
162 | 162 | return $this->unlock(); |
163 | 163 | } |
164 | 164 | return 0; |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | * @param float $total total value of transaction |
174 | 174 | * @throws \EE_Error |
175 | 175 | */ |
176 | - public function set_total( $total = 0.00 ) { |
|
177 | - $this->set( 'TXN_total', (float)$total ); |
|
176 | + public function set_total($total = 0.00) { |
|
177 | + $this->set('TXN_total', (float) $total); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | * @param float $total_paid total amount paid to date (sum of all payments) |
187 | 187 | * @throws \EE_Error |
188 | 188 | */ |
189 | - public function set_paid( $total_paid = 0.00 ) { |
|
190 | - $this->set( 'TXN_paid', (float)$total_paid ); |
|
189 | + public function set_paid($total_paid = 0.00) { |
|
190 | + $this->set('TXN_paid', (float) $total_paid); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | |
@@ -199,8 +199,8 @@ discard block |
||
199 | 199 | * @param string $status whether the transaction is open, declined, accepted, or any number of custom values that can be set |
200 | 200 | * @throws \EE_Error |
201 | 201 | */ |
202 | - public function set_status( $status = '' ) { |
|
203 | - $this->set( 'STS_ID', $status ); |
|
202 | + public function set_status($status = '') { |
|
203 | + $this->set('STS_ID', $status); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | * @param string $hash_salt required for some payment gateways |
213 | 213 | * @throws \EE_Error |
214 | 214 | */ |
215 | - public function set_hash_salt( $hash_salt = '' ) { |
|
216 | - $this->set( 'TXN_hash_salt', $hash_salt ); |
|
215 | + public function set_hash_salt($hash_salt = '') { |
|
216 | + $this->set('TXN_hash_salt', $hash_salt); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | * @param array $txn_reg_steps |
225 | 225 | * @throws \EE_Error |
226 | 226 | */ |
227 | - public function set_reg_steps( array $txn_reg_steps ) { |
|
228 | - $this->set( 'TXN_reg_steps', $txn_reg_steps ); |
|
227 | + public function set_reg_steps(array $txn_reg_steps) { |
|
228 | + $this->set('TXN_reg_steps', $txn_reg_steps); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | |
@@ -237,8 +237,8 @@ discard block |
||
237 | 237 | * @throws \EE_Error |
238 | 238 | */ |
239 | 239 | public function reg_steps() { |
240 | - $TXN_reg_steps = $this->get( 'TXN_reg_steps' ); |
|
241 | - return is_array( $TXN_reg_steps ) ? (array)$TXN_reg_steps : array(); |
|
240 | + $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
241 | + return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array(); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | * @throws \EE_Error |
249 | 249 | */ |
250 | 250 | public function pretty_total() { |
251 | - return $this->get_pretty( 'TXN_total' ); |
|
251 | + return $this->get_pretty('TXN_total'); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @throws \EE_Error |
261 | 261 | */ |
262 | 262 | public function pretty_paid() { |
263 | - return $this->get_pretty( 'TXN_paid' ); |
|
263 | + return $this->get_pretty('TXN_paid'); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * @throws \EE_Error |
274 | 274 | */ |
275 | 275 | public function remaining() { |
276 | - return (float)( $this->total() - $this->paid() ); |
|
276 | + return (float) ($this->total() - $this->paid()); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | * @throws \EE_Error |
287 | 287 | */ |
288 | 288 | public function total() { |
289 | - return (float)$this->get( 'TXN_total' ); |
|
289 | + return (float) $this->get('TXN_total'); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @throws \EE_Error |
300 | 300 | */ |
301 | 301 | public function paid() { |
302 | - return (float)$this->get( 'TXN_paid' ); |
|
302 | + return (float) $this->get('TXN_paid'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -311,9 +311,9 @@ discard block |
||
311 | 311 | * @throws \EE_Error |
312 | 312 | */ |
313 | 313 | public function get_cart_session() { |
314 | - $session_data = (array)$this->get( 'TXN_session_data' ); |
|
315 | - return isset( $session_data[ 'cart' ] ) && $session_data[ 'cart' ] instanceof EE_Cart |
|
316 | - ? $session_data[ 'cart' ] |
|
314 | + $session_data = (array) $this->get('TXN_session_data'); |
|
315 | + return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
|
316 | + ? $session_data['cart'] |
|
317 | 317 | : null; |
318 | 318 | } |
319 | 319 | |
@@ -326,8 +326,8 @@ discard block |
||
326 | 326 | * @throws \EE_Error |
327 | 327 | */ |
328 | 328 | public function session_data() { |
329 | - $session_data = $this->get( 'TXN_session_data' ); |
|
330 | - if ( empty( $session_data ) ) { |
|
329 | + $session_data = $this->get('TXN_session_data'); |
|
330 | + if (empty($session_data)) { |
|
331 | 331 | $session_data = array( |
332 | 332 | 'id' => null, |
333 | 333 | 'user_id' => null, |
@@ -350,11 +350,11 @@ discard block |
||
350 | 350 | * @param EE_Session|array $session_data |
351 | 351 | * @throws \EE_Error |
352 | 352 | */ |
353 | - public function set_txn_session_data( $session_data ) { |
|
354 | - if ( $session_data instanceof EE_Session ) { |
|
355 | - $this->set( 'TXN_session_data', $session_data->get_session_data( NULL, TRUE )); |
|
353 | + public function set_txn_session_data($session_data) { |
|
354 | + if ($session_data instanceof EE_Session) { |
|
355 | + $this->set('TXN_session_data', $session_data->get_session_data(NULL, TRUE)); |
|
356 | 356 | } else { |
357 | - $this->set( 'TXN_session_data', $session_data ); |
|
357 | + $this->set('TXN_session_data', $session_data); |
|
358 | 358 | } |
359 | 359 | } |
360 | 360 | |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | * @throws \EE_Error |
368 | 368 | */ |
369 | 369 | public function hash_salt_() { |
370 | - return $this->get( 'TXN_hash_salt' ); |
|
370 | + return $this->get('TXN_hash_salt'); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | |
@@ -387,13 +387,13 @@ discard block |
||
387 | 387 | * @return string | int |
388 | 388 | * @throws \EE_Error |
389 | 389 | */ |
390 | - public function datetime( $format = FALSE, $gmt = FALSE ) { |
|
391 | - if ( $format ) { |
|
392 | - return $this->get_pretty( 'TXN_timestamp' ); |
|
393 | - } else if ( $gmt ) { |
|
394 | - return $this->get_raw( 'TXN_timestamp' ); |
|
390 | + public function datetime($format = FALSE, $gmt = FALSE) { |
|
391 | + if ($format) { |
|
392 | + return $this->get_pretty('TXN_timestamp'); |
|
393 | + } else if ($gmt) { |
|
394 | + return $this->get_raw('TXN_timestamp'); |
|
395 | 395 | } else { |
396 | - return $this->get( 'TXN_timestamp' ); |
|
396 | + return $this->get('TXN_timestamp'); |
|
397 | 397 | } |
398 | 398 | } |
399 | 399 | |
@@ -407,8 +407,8 @@ discard block |
||
407 | 407 | * @return EE_Registration[] |
408 | 408 | * @throws \EE_Error |
409 | 409 | */ |
410 | - public function registrations( $query_params = array(), $get_cached = FALSE ) { |
|
411 | - $query_params = ( empty( $query_params ) || ! is_array( $query_params ) ) |
|
410 | + public function registrations($query_params = array(), $get_cached = FALSE) { |
|
411 | + $query_params = (empty($query_params) || ! is_array($query_params)) |
|
412 | 412 | ? array( |
413 | 413 | 'order_by' => array( |
414 | 414 | 'Event.EVT_name' => 'ASC', |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | ) |
419 | 419 | : $query_params; |
420 | 420 | $query_params = $get_cached ? array() : $query_params; |
421 | - return $this->get_many_related( 'Registration', $query_params ); |
|
421 | + return $this->get_many_related('Registration', $query_params); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | * @throws \EE_Error |
432 | 432 | */ |
433 | 433 | public function attendees() { |
434 | - return $this->get_many_related( 'Attendee', array( array( 'Registration.Transaction.TXN_ID' => $this->ID() ) ) ); |
|
434 | + return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | |
@@ -443,8 +443,8 @@ discard block |
||
443 | 443 | * @return EE_Payment[] |
444 | 444 | * @throws \EE_Error |
445 | 445 | */ |
446 | - public function payments( $query_params = array() ) { |
|
447 | - return $this->get_many_related( 'Payment', $query_params ); |
|
446 | + public function payments($query_params = array()) { |
|
447 | + return $this->get_many_related('Payment', $query_params); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | |
@@ -456,8 +456,8 @@ discard block |
||
456 | 456 | * @throws \EE_Error |
457 | 457 | */ |
458 | 458 | public function approved_payments() { |
459 | - EE_Registry::instance()->load_model( 'Payment' ); |
|
460 | - return $this->get_many_related( 'Payment', array( array( 'STS_ID' => EEM_Payment::status_id_approved ), 'order_by' => array( 'PAY_timestamp' => 'DESC' ) ) ); |
|
459 | + EE_Registry::instance()->load_model('Payment'); |
|
460 | + return $this->get_many_related('Payment', array(array('STS_ID' => EEM_Payment::status_id_approved), 'order_by' => array('PAY_timestamp' => 'DESC'))); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | |
@@ -491,8 +491,8 @@ discard block |
||
491 | 491 | * @return string |
492 | 492 | * @throws \EE_Error |
493 | 493 | */ |
494 | - public function e_pretty_status( $show_icons = FALSE ) { |
|
495 | - echo $this->pretty_status( $show_icons ); |
|
494 | + public function e_pretty_status($show_icons = FALSE) { |
|
495 | + echo $this->pretty_status($show_icons); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | |
@@ -504,10 +504,10 @@ discard block |
||
504 | 504 | * @return string |
505 | 505 | * @throws \EE_Error |
506 | 506 | */ |
507 | - public function pretty_status( $show_icons = FALSE ) { |
|
508 | - $status = EEM_Status::instance()->localized_status( array( $this->status_ID() => __( 'unknown', 'event_espresso' ) ), FALSE, 'sentence' ); |
|
507 | + public function pretty_status($show_icons = FALSE) { |
|
508 | + $status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')), FALSE, 'sentence'); |
|
509 | 509 | $icon = ''; |
510 | - switch ( $this->status_ID() ) { |
|
510 | + switch ($this->status_ID()) { |
|
511 | 511 | case EEM_Transaction::complete_status_code: |
512 | 512 | $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
513 | 513 | break; |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
525 | 525 | break; |
526 | 526 | } |
527 | - return $icon . $status[ $this->status_ID() ]; |
|
527 | + return $icon.$status[$this->status_ID()]; |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | * @throws \EE_Error |
537 | 537 | */ |
538 | 538 | public function status_ID() { |
539 | - return $this->get( 'STS_ID' ); |
|
539 | + return $this->get('STS_ID'); |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | * @throws \EE_Error |
549 | 549 | */ |
550 | 550 | public function is_free() { |
551 | - return EEH_Money::compare_floats( $this->get( 'TXN_total' ), 0, '==' ); |
|
551 | + return EEH_Money::compare_floats($this->get('TXN_total'), 0, '=='); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | |
@@ -628,12 +628,12 @@ discard block |
||
628 | 628 | * @return string |
629 | 629 | * @throws \EE_Error |
630 | 630 | */ |
631 | - public function invoice_url( $type = 'html' ) { |
|
631 | + public function invoice_url($type = 'html') { |
|
632 | 632 | $REG = $this->primary_registration(); |
633 | - if ( ! $REG instanceof EE_Registration ) { |
|
633 | + if ( ! $REG instanceof EE_Registration) { |
|
634 | 634 | return ''; |
635 | 635 | } |
636 | - return $REG->invoice_url( $type ); |
|
636 | + return $REG->invoice_url($type); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | ); |
651 | 651 | foreach ($registrations as $registration) { |
652 | 652 | // valid registration that is NOT cancelled or declined ? |
653 | - if( |
|
653 | + if ( |
|
654 | 654 | $registration instanceof EE_Registration |
655 | 655 | && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true) |
656 | 656 | ) { |
@@ -670,12 +670,12 @@ discard block |
||
670 | 670 | * @return string |
671 | 671 | * @throws \EE_Error |
672 | 672 | */ |
673 | - public function receipt_url( $type = 'html' ) { |
|
673 | + public function receipt_url($type = 'html') { |
|
674 | 674 | $REG = $this->primary_registration(); |
675 | - if ( ! $REG instanceof EE_Registration ) { |
|
675 | + if ( ! $REG instanceof EE_Registration) { |
|
676 | 676 | return ''; |
677 | 677 | } |
678 | - return $REG->receipt_url( $type ); |
|
678 | + return $REG->receipt_url($type); |
|
679 | 679 | } |
680 | 680 | |
681 | 681 | |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | * @throws \EE_Error |
701 | 701 | */ |
702 | 702 | public function gateway_response_on_transaction() { |
703 | - $payment = $this->get_first_related( 'Payment' ); |
|
703 | + $payment = $this->get_first_related('Payment'); |
|
704 | 704 | return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
705 | 705 | } |
706 | 706 | |
@@ -713,7 +713,7 @@ discard block |
||
713 | 713 | * @throws \EE_Error |
714 | 714 | */ |
715 | 715 | public function status_obj() { |
716 | - return $this->get_first_related( 'Status' ); |
|
716 | + return $this->get_first_related('Status'); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | |
@@ -725,8 +725,8 @@ discard block |
||
725 | 725 | * @return EE_Extra_Meta |
726 | 726 | * @throws \EE_Error |
727 | 727 | */ |
728 | - public function extra_meta( $query_params = array() ) { |
|
729 | - return $this->get_many_related( 'Extra_Meta', $query_params ); |
|
728 | + public function extra_meta($query_params = array()) { |
|
729 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | |
@@ -738,8 +738,8 @@ discard block |
||
738 | 738 | * @return EE_Base_Class the relation was added to |
739 | 739 | * @throws \EE_Error |
740 | 740 | */ |
741 | - public function add_registration( EE_Registration $registration ) { |
|
742 | - return $this->_add_relation_to( $registration, 'Registration' ); |
|
741 | + public function add_registration(EE_Registration $registration) { |
|
742 | + return $this->_add_relation_to($registration, 'Registration'); |
|
743 | 743 | } |
744 | 744 | |
745 | 745 | |
@@ -752,8 +752,8 @@ discard block |
||
752 | 752 | * @return EE_Base_Class that was removed from being related |
753 | 753 | * @throws \EE_Error |
754 | 754 | */ |
755 | - public function remove_registration_with_id( $registration_or_id ) { |
|
756 | - return $this->_remove_relation_to( $registration_or_id, 'Registration' ); |
|
755 | + public function remove_registration_with_id($registration_or_id) { |
|
756 | + return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | |
@@ -765,7 +765,7 @@ discard block |
||
765 | 765 | * @throws \EE_Error |
766 | 766 | */ |
767 | 767 | public function items_purchased() { |
768 | - return $this->line_items( array( array( 'LIN_type' => EEM_Line_Item::type_line_item ) ) ); |
|
768 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | |
@@ -777,8 +777,8 @@ discard block |
||
777 | 777 | * @return EE_Base_Class the relation was added to |
778 | 778 | * @throws \EE_Error |
779 | 779 | */ |
780 | - public function add_line_item( EE_Line_Item $line_item ) { |
|
781 | - return $this->_add_relation_to( $line_item, 'Line_Item' ); |
|
780 | + public function add_line_item(EE_Line_Item $line_item) { |
|
781 | + return $this->_add_relation_to($line_item, 'Line_Item'); |
|
782 | 782 | } |
783 | 783 | |
784 | 784 | |
@@ -790,8 +790,8 @@ discard block |
||
790 | 790 | * @return EE_Line_Item[] |
791 | 791 | * @throws \EE_Error |
792 | 792 | */ |
793 | - public function line_items( $query_params = array() ) { |
|
794 | - return $this->get_many_related( 'Line_Item', $query_params ); |
|
793 | + public function line_items($query_params = array()) { |
|
794 | + return $this->get_many_related('Line_Item', $query_params); |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | * @throws \EE_Error |
804 | 804 | */ |
805 | 805 | public function tax_items() { |
806 | - return $this->line_items( array( array( 'LIN_type' => EEM_Line_Item::type_tax ) ) ); |
|
806 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | |
@@ -816,10 +816,10 @@ discard block |
||
816 | 816 | * @return \EE_Line_Item |
817 | 817 | * @throws \EE_Error |
818 | 818 | */ |
819 | - public function total_line_item( $create_if_not_found = true ) { |
|
820 | - $item = $this->get_first_related( 'Line_Item', array( array( 'LIN_type' => EEM_Line_Item::type_total ) ) ); |
|
821 | - if( ! $item && $create_if_not_found ){ |
|
822 | - $item = EEH_Line_Item::create_total_line_item( $this ); |
|
819 | + public function total_line_item($create_if_not_found = true) { |
|
820 | + $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
821 | + if ( ! $item && $create_if_not_found) { |
|
822 | + $item = EEH_Line_Item::create_total_line_item($this); |
|
823 | 823 | } |
824 | 824 | return $item; |
825 | 825 | } |
@@ -835,10 +835,10 @@ discard block |
||
835 | 835 | */ |
836 | 836 | public function tax_total() { |
837 | 837 | $tax_line_item = $this->tax_total_line_item(); |
838 | - if ( $tax_line_item ) { |
|
839 | - return (float)$tax_line_item->total(); |
|
838 | + if ($tax_line_item) { |
|
839 | + return (float) $tax_line_item->total(); |
|
840 | 840 | } else { |
841 | - return (float)0; |
|
841 | + return (float) 0; |
|
842 | 842 | } |
843 | 843 | } |
844 | 844 | |
@@ -851,7 +851,7 @@ discard block |
||
851 | 851 | * @throws \EE_Error |
852 | 852 | */ |
853 | 853 | public function tax_total_line_item() { |
854 | - return EEH_Line_Item::get_taxes_subtotal( $this->total_line_item() ); |
|
854 | + return EEH_Line_Item::get_taxes_subtotal($this->total_line_item()); |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | |
@@ -862,20 +862,20 @@ discard block |
||
862 | 862 | * @return EE_Form_Section_Proper |
863 | 863 | * @throws \EE_Error |
864 | 864 | */ |
865 | - public function billing_info(){ |
|
865 | + public function billing_info() { |
|
866 | 866 | $payment_method = $this->payment_method(); |
867 | - if ( !$payment_method){ |
|
867 | + if ( ! $payment_method) { |
|
868 | 868 | EE_Error::add_error(__("Could not find billing info for transaction because no gateway has been used for it yet", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
869 | 869 | return false; |
870 | 870 | } |
871 | 871 | $primary_reg = $this->primary_registration(); |
872 | - if ( ! $primary_reg ) { |
|
873 | - EE_Error::add_error( __( "Cannot get billing info for gateway %s on transaction because no primary registration exists", "event_espresso" ), __FILE__, __FUNCTION__, __LINE__ ); |
|
872 | + if ( ! $primary_reg) { |
|
873 | + EE_Error::add_error(__("Cannot get billing info for gateway %s on transaction because no primary registration exists", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
874 | 874 | return FALSE; |
875 | 875 | } |
876 | 876 | $attendee = $primary_reg->attendee(); |
877 | - if ( ! $attendee ) { |
|
878 | - EE_Error::add_error( __( "Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists", "event_espresso" ), __FILE__, __FUNCTION__, __LINE__ ); |
|
877 | + if ( ! $attendee) { |
|
878 | + EE_Error::add_error(__("Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
879 | 879 | return FALSE; |
880 | 880 | } |
881 | 881 | return $attendee->billing_info_for_payment_method($payment_method); |
@@ -916,15 +916,15 @@ discard block |
||
916 | 916 | * @return EE_Payment_Method |
917 | 917 | * @throws \EE_Error |
918 | 918 | */ |
919 | - public function payment_method(){ |
|
919 | + public function payment_method() { |
|
920 | 920 | $pm = $this->get_first_related('Payment_Method'); |
921 | - if( $pm instanceof EE_Payment_Method ){ |
|
921 | + if ($pm instanceof EE_Payment_Method) { |
|
922 | 922 | return $pm; |
923 | - }else{ |
|
923 | + } else { |
|
924 | 924 | $last_payment = $this->last_payment(); |
925 | - if( $last_payment instanceof EE_Payment && $last_payment->payment_method() ){ |
|
925 | + if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
926 | 926 | return $last_payment->payment_method(); |
927 | - }else{ |
|
927 | + } else { |
|
928 | 928 | return NULL; |
929 | 929 | } |
930 | 930 | } |
@@ -939,7 +939,7 @@ discard block |
||
939 | 939 | * @throws \EE_Error |
940 | 940 | */ |
941 | 941 | public function last_payment() { |
942 | - return $this->get_first_related( 'Payment', array( 'order_by' => array( 'PAY_ID' => 'desc' ) ) ); |
|
942 | + return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
943 | 943 | } |
944 | 944 | |
945 | 945 | |
@@ -950,8 +950,8 @@ discard block |
||
950 | 950 | * @return EE_Line_Item[] |
951 | 951 | * @throws \EE_Error |
952 | 952 | */ |
953 | - public function non_ticket_line_items(){ |
|
954 | - return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction( $this->ID() ); |
|
953 | + public function non_ticket_line_items() { |
|
954 | + return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
955 | 955 | } |
956 | 956 | |
957 | 957 | |
@@ -999,7 +999,7 @@ discard block |
||
999 | 999 | public function update_based_on_payments() |
1000 | 1000 | { |
1001 | 1001 | EE_Error::doing_it_wrong( |
1002 | - __CLASS__ . '::' . __FUNCTION__, |
|
1002 | + __CLASS__.'::'.__FUNCTION__, |
|
1003 | 1003 | sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
1004 | 1004 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
1005 | 1005 | '4.6.0' |
@@ -1023,9 +1023,9 @@ discard block |
||
1023 | 1023 | /** |
1024 | 1024 | * @param string $old_txn_status |
1025 | 1025 | */ |
1026 | - public function set_old_txn_status( $old_txn_status ) { |
|
1026 | + public function set_old_txn_status($old_txn_status) { |
|
1027 | 1027 | // only set the first time |
1028 | - if ( $this->_old_txn_status === null ) { |
|
1028 | + if ($this->_old_txn_status === null) { |
|
1029 | 1029 | $this->_old_txn_status = $old_txn_status; |
1030 | 1030 | } |
1031 | 1031 | } |
@@ -1054,17 +1054,17 @@ discard block |
||
1054 | 1054 | * @param bool $check_all |
1055 | 1055 | * @return boolean | int |
1056 | 1056 | */ |
1057 | - private function _reg_steps_completed( $reg_step_slug = '', $check_all = true ) { |
|
1057 | + private function _reg_steps_completed($reg_step_slug = '', $check_all = true) { |
|
1058 | 1058 | $reg_steps = $this->reg_steps(); |
1059 | - if ( ! is_array( $reg_steps ) || empty( $reg_steps ) ) { |
|
1059 | + if ( ! is_array($reg_steps) || empty($reg_steps)) { |
|
1060 | 1060 | return false; |
1061 | 1061 | } |
1062 | 1062 | // loop thru reg steps array) |
1063 | - foreach ( $reg_steps as $slug => $reg_step_completed ) { |
|
1063 | + foreach ($reg_steps as $slug => $reg_step_completed) { |
|
1064 | 1064 | // if NOT checking ALL steps (only checking one step) |
1065 | - if ( ! $check_all ) { |
|
1065 | + if ( ! $check_all) { |
|
1066 | 1066 | // and this is the one |
1067 | - if ( $slug === $reg_step_slug ) { |
|
1067 | + if ($slug === $reg_step_slug) { |
|
1068 | 1068 | return $reg_step_completed; |
1069 | 1069 | } else { |
1070 | 1070 | // skip to next reg step in loop |
@@ -1072,7 +1072,7 @@ discard block |
||
1072 | 1072 | } |
1073 | 1073 | } |
1074 | 1074 | // $check_all must be true, else we would never have gotten to this point |
1075 | - if ( $slug === $reg_step_slug ) { |
|
1075 | + if ($slug === $reg_step_slug) { |
|
1076 | 1076 | // if we reach this point, then we are testing either: |
1077 | 1077 | // all_reg_steps_completed_except() or |
1078 | 1078 | // all_reg_steps_completed_except_final_step(), |
@@ -1081,7 +1081,7 @@ discard block |
||
1081 | 1081 | // ie: "is everything completed except the final step?" |
1082 | 1082 | // "that is correct... the final step is not completed, but all others are." |
1083 | 1083 | return $reg_step_completed !== true ? true : false; |
1084 | - } else if ( $reg_step_completed !== true ) { |
|
1084 | + } else if ($reg_step_completed !== true) { |
|
1085 | 1085 | // if any reg step is NOT completed, then ALL steps are not completed |
1086 | 1086 | return false; |
1087 | 1087 | } |
@@ -1115,8 +1115,8 @@ discard block |
||
1115 | 1115 | * @param string $exception |
1116 | 1116 | * @return boolean |
1117 | 1117 | */ |
1118 | - public function all_reg_steps_completed_except( $exception = '' ) { |
|
1119 | - return $this->_reg_steps_completed( $exception ); |
|
1118 | + public function all_reg_steps_completed_except($exception = '') { |
|
1119 | + return $this->_reg_steps_completed($exception); |
|
1120 | 1120 | } |
1121 | 1121 | |
1122 | 1122 | |
@@ -1131,7 +1131,7 @@ discard block |
||
1131 | 1131 | * @return boolean |
1132 | 1132 | */ |
1133 | 1133 | public function all_reg_steps_completed_except_final_step() { |
1134 | - return $this->_reg_steps_completed( 'finalize_registration' ); |
|
1134 | + return $this->_reg_steps_completed('finalize_registration'); |
|
1135 | 1135 | } |
1136 | 1136 | |
1137 | 1137 | |
@@ -1146,8 +1146,8 @@ discard block |
||
1146 | 1146 | * @param string $reg_step_slug |
1147 | 1147 | * @return boolean | int |
1148 | 1148 | */ |
1149 | - public function reg_step_completed( $reg_step_slug ) { |
|
1150 | - return $this->_reg_steps_completed( $reg_step_slug, false ); |
|
1149 | + public function reg_step_completed($reg_step_slug) { |
|
1150 | + return $this->_reg_steps_completed($reg_step_slug, false); |
|
1151 | 1151 | } |
1152 | 1152 | |
1153 | 1153 | |
@@ -1162,7 +1162,7 @@ discard block |
||
1162 | 1162 | * @return boolean | int |
1163 | 1163 | */ |
1164 | 1164 | public function final_reg_step_completed() { |
1165 | - return $this->_reg_steps_completed( 'finalize_registration', false ); |
|
1165 | + return $this->_reg_steps_completed('finalize_registration', false); |
|
1166 | 1166 | } |
1167 | 1167 | |
1168 | 1168 | |
@@ -1176,8 +1176,8 @@ discard block |
||
1176 | 1176 | * @return boolean |
1177 | 1177 | * @throws \EE_Error |
1178 | 1178 | */ |
1179 | - public function set_reg_step_initiated( $reg_step_slug ) { |
|
1180 | - return $this->_set_reg_step_completed_status( $reg_step_slug, time() ); |
|
1179 | + public function set_reg_step_initiated($reg_step_slug) { |
|
1180 | + return $this->_set_reg_step_completed_status($reg_step_slug, time()); |
|
1181 | 1181 | } |
1182 | 1182 | |
1183 | 1183 | |
@@ -1191,8 +1191,8 @@ discard block |
||
1191 | 1191 | * @return boolean |
1192 | 1192 | * @throws \EE_Error |
1193 | 1193 | */ |
1194 | - public function set_reg_step_completed( $reg_step_slug ) { |
|
1195 | - return $this->_set_reg_step_completed_status( $reg_step_slug, true ); |
|
1194 | + public function set_reg_step_completed($reg_step_slug) { |
|
1195 | + return $this->_set_reg_step_completed_status($reg_step_slug, true); |
|
1196 | 1196 | } |
1197 | 1197 | |
1198 | 1198 | |
@@ -1206,8 +1206,8 @@ discard block |
||
1206 | 1206 | * @return boolean |
1207 | 1207 | * @throws \EE_Error |
1208 | 1208 | */ |
1209 | - public function set_reg_step_not_completed( $reg_step_slug ) { |
|
1210 | - return $this->_set_reg_step_completed_status( $reg_step_slug, false ); |
|
1209 | + public function set_reg_step_not_completed($reg_step_slug) { |
|
1210 | + return $this->_set_reg_step_completed_status($reg_step_slug, false); |
|
1211 | 1211 | } |
1212 | 1212 | |
1213 | 1213 | |
@@ -1222,37 +1222,37 @@ discard block |
||
1222 | 1222 | * @return boolean |
1223 | 1223 | * @throws \EE_Error |
1224 | 1224 | */ |
1225 | - private function _set_reg_step_completed_status( $reg_step_slug, $status ) { |
|
1225 | + private function _set_reg_step_completed_status($reg_step_slug, $status) { |
|
1226 | 1226 | // validate status |
1227 | - $status = is_bool( $status ) || is_int( $status ) ? $status : false; |
|
1227 | + $status = is_bool($status) || is_int($status) ? $status : false; |
|
1228 | 1228 | // get reg steps array |
1229 | 1229 | $txn_reg_steps = $this->reg_steps(); |
1230 | 1230 | // if reg step does NOT exist |
1231 | - if ( ! isset( $txn_reg_steps[ $reg_step_slug ] ) ) { |
|
1231 | + if ( ! isset($txn_reg_steps[$reg_step_slug])) { |
|
1232 | 1232 | return false; |
1233 | 1233 | } |
1234 | 1234 | // if we're trying to complete a step that is already completed |
1235 | - if ( $txn_reg_steps[ $reg_step_slug ] === true ) { |
|
1235 | + if ($txn_reg_steps[$reg_step_slug] === true) { |
|
1236 | 1236 | return true; |
1237 | 1237 | } |
1238 | 1238 | // if we're trying to complete a step that hasn't even started |
1239 | - if ( $status === true && $txn_reg_steps[ $reg_step_slug ] === false ) { |
|
1239 | + if ($status === true && $txn_reg_steps[$reg_step_slug] === false) { |
|
1240 | 1240 | return false; |
1241 | 1241 | } |
1242 | 1242 | // if current status value matches the incoming value (no change) |
1243 | 1243 | // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890 |
1244 | - if ( (int) $txn_reg_steps[ $reg_step_slug ] === (int) $status ) { |
|
1244 | + if ((int) $txn_reg_steps[$reg_step_slug] === (int) $status) { |
|
1245 | 1245 | // this will happen in cases where multiple AJAX requests occur during the same step |
1246 | 1246 | return true; |
1247 | 1247 | } |
1248 | 1248 | // if we're trying to set a start time, but it has already been set... |
1249 | - if ( is_numeric( $status ) && is_numeric( $txn_reg_steps[ $reg_step_slug ] ) ) { |
|
1249 | + if (is_numeric($status) && is_numeric($txn_reg_steps[$reg_step_slug])) { |
|
1250 | 1250 | // skip the update below, but don't return FALSE so that errors won't be displayed |
1251 | 1251 | return true; |
1252 | 1252 | } |
1253 | 1253 | // update completed status |
1254 | - $txn_reg_steps[ $reg_step_slug ] = $status; |
|
1255 | - $this->set_reg_steps( $txn_reg_steps ); |
|
1254 | + $txn_reg_steps[$reg_step_slug] = $status; |
|
1255 | + $this->set_reg_steps($txn_reg_steps); |
|
1256 | 1256 | $this->save(); |
1257 | 1257 | return true; |
1258 | 1258 | } |
@@ -1268,11 +1268,11 @@ discard block |
||
1268 | 1268 | * @param string $reg_step_slug |
1269 | 1269 | * @return void |
1270 | 1270 | */ |
1271 | - public function remove_reg_step( $reg_step_slug ) { |
|
1271 | + public function remove_reg_step($reg_step_slug) { |
|
1272 | 1272 | // get reg steps array |
1273 | 1273 | $txn_reg_steps = $this->reg_steps(); |
1274 | - unset( $txn_reg_steps[ $reg_step_slug ] ); |
|
1275 | - $this->set_reg_steps( $txn_reg_steps ); |
|
1274 | + unset($txn_reg_steps[$reg_step_slug]); |
|
1275 | + $this->set_reg_steps($txn_reg_steps); |
|
1276 | 1276 | } |
1277 | 1277 | |
1278 | 1278 | |
@@ -1286,11 +1286,11 @@ discard block |
||
1286 | 1286 | * @param bool $save |
1287 | 1287 | * @return bool |
1288 | 1288 | */ |
1289 | - public function toggle_failed_transaction_status( $save = true ) { |
|
1289 | + public function toggle_failed_transaction_status($save = true) { |
|
1290 | 1290 | // if TXN status is still set as "failed"... |
1291 | - if ( $this->status_ID() === EEM_Transaction::failed_status_code ) { |
|
1292 | - $this->set_status( EEM_Transaction::abandoned_status_code ); |
|
1293 | - if ( $save ) { |
|
1291 | + if ($this->status_ID() === EEM_Transaction::failed_status_code) { |
|
1292 | + $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1293 | + if ($save) { |
|
1294 | 1294 | $this->save(); |
1295 | 1295 | } |
1296 | 1296 | return true; |
@@ -1319,10 +1319,10 @@ discard block |
||
1319 | 1319 | $this->primary_registration() instanceof EE_Registration |
1320 | 1320 | && $this->primary_registration()->attendee() instanceof EE_Attendee |
1321 | 1321 | ) { |
1322 | - $this->set_status( EEM_Transaction::incomplete_status_code ); |
|
1322 | + $this->set_status(EEM_Transaction::incomplete_status_code); |
|
1323 | 1323 | } else { |
1324 | 1324 | // no contact record? yer abandoned! |
1325 | - $this->set_status( EEM_Transaction::abandoned_status_code ); |
|
1325 | + $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1326 | 1326 | } |
1327 | 1327 | return true; |
1328 | 1328 | } |
@@ -1336,16 +1336,16 @@ discard block |
||
1336 | 1336 | * updates the TXN status based on the amount paid |
1337 | 1337 | */ |
1338 | 1338 | public function verify_abandoned_transaction_status() { |
1339 | - if ( $this->status_ID() !== EEM_Transaction::abandoned_status_code ) { |
|
1339 | + if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) { |
|
1340 | 1340 | return; |
1341 | 1341 | } |
1342 | - $payments = $this->get_many_related( 'Payment' ); |
|
1343 | - if ( ! empty( $payments ) ) { |
|
1344 | - foreach ( $payments as $payment ) { |
|
1345 | - if ( $payment instanceof EE_Payment ) { |
|
1342 | + $payments = $this->get_many_related('Payment'); |
|
1343 | + if ( ! empty($payments)) { |
|
1344 | + foreach ($payments as $payment) { |
|
1345 | + if ($payment instanceof EE_Payment) { |
|
1346 | 1346 | // kk this TXN should NOT be abandoned |
1347 | 1347 | $this->update_status_based_on_total_paid(); |
1348 | - if ( is_admin() && ! ( defined('DOING_AJAX') && DOING_AJAX ) ) { |
|
1348 | + if (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
1349 | 1349 | EE_Error::add_attention( |
1350 | 1350 | sprintf( |
1351 | 1351 | esc_html__( |
@@ -1361,8 +1361,8 @@ discard block |
||
1361 | 1361 | $finalized = $this->final_reg_step_completed(); |
1362 | 1362 | // if the 'finalize_registration' step has been initiated (has a timestamp) |
1363 | 1363 | // but has not yet been fully completed (TRUE) |
1364 | - if ( is_int( $finalized ) && $finalized !== false && $finalized !== true ) { |
|
1365 | - $this->set_reg_step_completed( 'finalize_registration' ); |
|
1364 | + if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
1365 | + $this->set_reg_step_completed('finalize_registration'); |
|
1366 | 1366 | $this->save(); |
1367 | 1367 | } |
1368 | 1368 | } |
@@ -14,56 +14,56 @@ |
||
14 | 14 | class EE_Number_Input_Display_Strategy extends EE_Display_Strategy_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * minimum value for number field |
|
19 | - * |
|
20 | - * @var int|null $min |
|
21 | - */ |
|
22 | - protected $min; |
|
17 | + /** |
|
18 | + * minimum value for number field |
|
19 | + * |
|
20 | + * @var int|null $min |
|
21 | + */ |
|
22 | + protected $min; |
|
23 | 23 | |
24 | - /** |
|
25 | - * maximum value for number field |
|
26 | - * |
|
27 | - * @var int|null $max |
|
28 | - */ |
|
29 | - protected $max; |
|
24 | + /** |
|
25 | + * maximum value for number field |
|
26 | + * |
|
27 | + * @var int|null $max |
|
28 | + */ |
|
29 | + protected $max; |
|
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * EE_Number_Input_Display_Strategy constructor. |
|
35 | - * |
|
36 | - * @param int $min |
|
37 | - * @param int $max |
|
38 | - */ |
|
39 | - public function __construct($min = null, $max = null) |
|
40 | - { |
|
41 | - $this->min = $min; |
|
42 | - $this->max = $max; |
|
43 | - } |
|
33 | + /** |
|
34 | + * EE_Number_Input_Display_Strategy constructor. |
|
35 | + * |
|
36 | + * @param int $min |
|
37 | + * @param int $max |
|
38 | + */ |
|
39 | + public function __construct($min = null, $max = null) |
|
40 | + { |
|
41 | + $this->min = $min; |
|
42 | + $this->max = $max; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * @return string of html to display the field |
|
49 | - */ |
|
50 | - public function display() |
|
51 | - { |
|
52 | - $input = $this->_opening_tag('input'); |
|
53 | - $input .= $this->_attributes_string( |
|
54 | - array_merge( |
|
55 | - $this->_standard_attributes_array(), |
|
56 | - array( |
|
57 | - 'type' => 'number', |
|
58 | - 'min' => $this->min, |
|
59 | - 'max' => $this->max, |
|
60 | - 'value' => $this->_input->raw_value_in_form() |
|
61 | - ) |
|
62 | - ) |
|
63 | - ); |
|
64 | - $input .= $this->_close_tag(); |
|
65 | - return $input; |
|
66 | - } |
|
47 | + /** |
|
48 | + * @return string of html to display the field |
|
49 | + */ |
|
50 | + public function display() |
|
51 | + { |
|
52 | + $input = $this->_opening_tag('input'); |
|
53 | + $input .= $this->_attributes_string( |
|
54 | + array_merge( |
|
55 | + $this->_standard_attributes_array(), |
|
56 | + array( |
|
57 | + 'type' => 'number', |
|
58 | + 'min' => $this->min, |
|
59 | + 'max' => $this->max, |
|
60 | + 'value' => $this->_input->raw_value_in_form() |
|
61 | + ) |
|
62 | + ) |
|
63 | + ); |
|
64 | + $input .= $this->_close_tag(); |
|
65 | + return $input; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | } |
69 | 69 | // End of file EE_Number_Input_Display_Strategy.php |
@@ -589,9 +589,9 @@ |
||
589 | 589 | */ |
590 | 590 | private function _load_assests() { |
591 | 591 | do_action( 'AHEE__EED_Events_Archive_Filters__before_load_assests' ); |
592 | - wp_enqueue_style('espresso_default'); |
|
593 | - wp_enqueue_style('espresso_custom_css'); |
|
594 | - add_filter( 'FHEE_load_EE_Session', '__return_true' ); |
|
592 | + wp_enqueue_style('espresso_default'); |
|
593 | + wp_enqueue_style('espresso_custom_css'); |
|
594 | + add_filter( 'FHEE_load_EE_Session', '__return_true' ); |
|
595 | 595 | add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 ); |
596 | 596 | if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) { |
597 | 597 | add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 ); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @return EED_Events_Archive_Filters |
30 | 30 | */ |
31 | 31 | public static function instance() { |
32 | - return parent::get_instance( __CLASS__ ); |
|
32 | + return parent::get_instance(__CLASS__); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @var $_types |
72 | 72 | * @access protected |
73 | 73 | */ |
74 | - protected static $_types = array( 'grid', 'text', 'dates' ); |
|
74 | + protected static $_types = array('grid', 'text', 'dates'); |
|
75 | 75 | |
76 | 76 | |
77 | 77 | // public static $espresso_event_list_ID = 0; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @access public |
126 | 126 | * @return void |
127 | 127 | */ |
128 | - public function run( $WP ) { |
|
128 | + public function run($WP) { |
|
129 | 129 | // do_action( 'AHEE__EED_Events_Archive_Filters__before_run' ); |
130 | 130 | // // set config |
131 | 131 | // if ( ! isset( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters ) || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters instanceof EE_Events_Archive_Config ) { |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | */ |
171 | 171 | private function _filter_query_parts() { |
172 | 172 | // build event list query |
173 | - add_filter( 'posts_join', array( $this, 'posts_join' ), 1, 2 ); |
|
174 | - add_filter( 'posts_where', array( $this, 'posts_where' ), 1, 2 ); |
|
175 | - add_filter( 'posts_orderby', array( $this, 'posts_orderby' ), 1, 2 ); |
|
173 | + add_filter('posts_join', array($this, 'posts_join'), 1, 2); |
|
174 | + add_filter('posts_where', array($this, 'posts_where'), 1, 2); |
|
175 | + add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -182,13 +182,13 @@ discard block |
||
182 | 182 | * @return string |
183 | 183 | */ |
184 | 184 | public static function set_type() { |
185 | - do_action( 'AHEE__EED_Events_Archive_Filters__before_set_type' ); |
|
186 | - EED_Events_Archive_Filters::$_types = apply_filters( 'EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types ); |
|
187 | - $view = isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid'; |
|
188 | - $elf_type = EE_Registry::instance()->REQ->is_set( 'elf_type' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_type' )) : ''; |
|
189 | - $view = ! empty( $elf_type ) ? $elf_type : $view; |
|
190 | - $view = apply_filters( 'EED_Events_Archive_Filters__set_type__type', $view ); |
|
191 | - if ( ! empty( $view ) && in_array( $view, EED_Events_Archive_Filters::$_types )) { |
|
185 | + do_action('AHEE__EED_Events_Archive_Filters__before_set_type'); |
|
186 | + EED_Events_Archive_Filters::$_types = apply_filters('EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types); |
|
187 | + $view = isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid'; |
|
188 | + $elf_type = EE_Registry::instance()->REQ->is_set('elf_type') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_type')) : ''; |
|
189 | + $view = ! empty($elf_type) ? $elf_type : $view; |
|
190 | + $view = apply_filters('EED_Events_Archive_Filters__set_type__type', $view); |
|
191 | + if ( ! empty($view) && in_array($view, EED_Events_Archive_Filters::$_types)) { |
|
192 | 192 | self::$_type = $view; |
193 | 193 | } |
194 | 194 | } |
@@ -200,11 +200,11 @@ discard block |
||
200 | 200 | * @param boolean $req_only if TRUE, then ignore defaults and only return $_POST value |
201 | 201 | * @return boolean |
202 | 202 | */ |
203 | - private static function _show_expired( $req_only = FALSE ) { |
|
203 | + private static function _show_expired($req_only = FALSE) { |
|
204 | 204 | // get default value for "display_expired_events" as set in the EE General Settings > Templates > Event Listings |
205 | - $show_expired = ! $req_only && isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE; |
|
205 | + $show_expired = ! $req_only && isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE; |
|
206 | 206 | // override default expired option if set via filter |
207 | - $show_expired = EE_Registry::instance()->REQ->is_set( 'elf_expired_chk' ) ? absint( EE_Registry::instance()->REQ->get( 'elf_expired_chk' )) : $show_expired; |
|
207 | + $show_expired = EE_Registry::instance()->REQ->is_set('elf_expired_chk') ? absint(EE_Registry::instance()->REQ->get('elf_expired_chk')) : $show_expired; |
|
208 | 208 | return $show_expired ? TRUE : FALSE; |
209 | 209 | } |
210 | 210 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @return string |
216 | 216 | */ |
217 | 217 | private static function _event_category_slug() { |
218 | - return EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : ''; |
|
218 | + return EE_Registry::instance()->REQ->is_set('elf_category_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_category_dd')) : ''; |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @return string |
226 | 226 | */ |
227 | 227 | private static function _display_month() { |
228 | - return EE_Registry::instance()->REQ->is_set( 'elf_month_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_month_dd' )) : ''; |
|
228 | + return EE_Registry::instance()->REQ->is_set('elf_month_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_month_dd')) : ''; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | public function get_post_data() { |
240 | 240 | $this->_elf_month = EED_Events_Archive_Filters::_display_month(); |
241 | 241 | $this->_elf_category = EED_Events_Archive_Filters::_event_category_slug(); |
242 | - $this->_show_expired = EED_Events_Archive_Filters::_show_expired( TRUE ); |
|
242 | + $this->_show_expired = EED_Events_Archive_Filters::_show_expired(TRUE); |
|
243 | 243 | // EEH_Debug_Tools::printr( EE_Registry::instance()->REQ, 'EE_Registry::instance()->REQ <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
244 | 244 | // echo '<h4>$this->_elf_month : ' . $this->_elf_month . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
245 | 245 | // echo '<h4>$this->_elf_category : ' . $this->_elf_category . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
@@ -256,11 +256,11 @@ discard block |
||
256 | 256 | * @access public |
257 | 257 | * @return void |
258 | 258 | */ |
259 | - public function posts_join( $SQL, WP_Query $wp_query ) { |
|
260 | - if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) { |
|
259 | + public function posts_join($SQL, WP_Query $wp_query) { |
|
260 | + if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') { |
|
261 | 261 | // Category |
262 | 262 | // $elf_category = EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : ''; |
263 | - $SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms( EED_Events_Archive_Filters::_event_category_slug() ); |
|
263 | + $SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms(EED_Events_Archive_Filters::_event_category_slug()); |
|
264 | 264 | } |
265 | 265 | return $SQL; |
266 | 266 | } |
@@ -273,9 +273,9 @@ discard block |
||
273 | 273 | * @param mixed boolean|string $join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get used for anything yet |
274 | 274 | * @return string |
275 | 275 | */ |
276 | - public static function posts_join_sql_for_terms( $join_terms = NULL ) { |
|
277 | - $SQL= ''; |
|
278 | - if ( ! empty( $join_terms )) { |
|
276 | + public static function posts_join_sql_for_terms($join_terms = NULL) { |
|
277 | + $SQL = ''; |
|
278 | + if ( ! empty($join_terms)) { |
|
279 | 279 | global $wpdb; |
280 | 280 | $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)"; |
281 | 281 | $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; |
@@ -293,28 +293,28 @@ discard block |
||
293 | 293 | * @param array $orderby_params |
294 | 294 | * @return string |
295 | 295 | */ |
296 | - public static function posts_join_for_orderby( $orderby_params = array() ) { |
|
296 | + public static function posts_join_for_orderby($orderby_params = array()) { |
|
297 | 297 | global $wpdb; |
298 | - $SQL= ''; |
|
299 | - $orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params ); |
|
300 | - foreach( $orderby_params as $orderby ) { |
|
301 | - switch ( $orderby ) { |
|
298 | + $SQL = ''; |
|
299 | + $orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params); |
|
300 | + foreach ($orderby_params as $orderby) { |
|
301 | + switch ($orderby) { |
|
302 | 302 | |
303 | 303 | case 'ticket_start' : |
304 | 304 | case 'ticket_end' : |
305 | - $SQL .= ' LEFT JOIN ' . EEM_Datetime_Ticket::instance()->table() . ' ON (' . EEM_Datetime::instance()->table() . '.DTT_ID = ' . EEM_Datetime_Ticket::instance()->table() . '.DTT_ID )'; |
|
306 | - $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table() . ' ON (' . EEM_Datetime_Ticket::instance()->table() . '.TKT_ID = ' . EEM_Ticket::instance()->table() . '.TKT_ID )'; |
|
305 | + $SQL .= ' LEFT JOIN '.EEM_Datetime_Ticket::instance()->table().' ON ('.EEM_Datetime::instance()->table().'.DTT_ID = '.EEM_Datetime_Ticket::instance()->table().'.DTT_ID )'; |
|
306 | + $SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table().' ON ('.EEM_Datetime_Ticket::instance()->table().'.TKT_ID = '.EEM_Ticket::instance()->table().'.TKT_ID )'; |
|
307 | 307 | break; |
308 | 308 | |
309 | 309 | case 'venue_title' : |
310 | 310 | case 'city' : |
311 | - $SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )'; |
|
312 | - $SQL .= ' LEFT JOIN ' . EEM_Venue::instance()->table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Venue::instance()->table() . '.VNU_ID )'; |
|
311 | + $SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )'; |
|
312 | + $SQL .= ' LEFT JOIN '.EEM_Venue::instance()->table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Venue::instance()->table().'.VNU_ID )'; |
|
313 | 313 | break; |
314 | 314 | |
315 | 315 | case 'state' : |
316 | - $SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )'; |
|
317 | - $SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->second_table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Event_Venue::instance()->second_table() . '.VNU_ID )'; |
|
316 | + $SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )'; |
|
317 | + $SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->second_table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Event_Venue::instance()->second_table().'.VNU_ID )'; |
|
318 | 318 | break; |
319 | 319 | |
320 | 320 | break; |
@@ -331,16 +331,16 @@ discard block |
||
331 | 331 | * @access public |
332 | 332 | * @return void |
333 | 333 | */ |
334 | - public function posts_where( $SQL, WP_Query $wp_query ) { |
|
335 | - if ( isset( $wp_query->query_vars ) && isset( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'espresso_events' ) { |
|
334 | + public function posts_where($SQL, WP_Query $wp_query) { |
|
335 | + if (isset($wp_query->query_vars) && isset($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'espresso_events') { |
|
336 | 336 | // Show Expired ? |
337 | - $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired( EED_Events_Archive_Filters::_show_expired() ); |
|
337 | + $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired(EED_Events_Archive_Filters::_show_expired()); |
|
338 | 338 | // Category |
339 | 339 | //$elf_category = EED_Events_Archive_Filters::_event_category_slug(); |
340 | - $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug( EED_Events_Archive_Filters::_event_category_slug() ); |
|
340 | + $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug(EED_Events_Archive_Filters::_event_category_slug()); |
|
341 | 341 | // Start Date |
342 | 342 | //$elf_month = EED_Events_Archive_Filters::_display_month(); |
343 | - $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month( EED_Events_Archive_Filters::_display_month() ); |
|
343 | + $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month(EED_Events_Archive_Filters::_display_month()); |
|
344 | 344 | } |
345 | 345 | return $SQL; |
346 | 346 | } |
@@ -353,8 +353,8 @@ discard block |
||
353 | 353 | * @param boolean $show_expired if TRUE, then displayed past events |
354 | 354 | * @return string |
355 | 355 | */ |
356 | - public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) { |
|
357 | - return ! $show_expired ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > "' . date('Y-m-d H:s:i') . '" ' : ''; |
|
356 | + public static function posts_where_sql_for_show_expired($show_expired = FALSE) { |
|
357 | + return ! $show_expired ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > "'.date('Y-m-d H:s:i').'" ' : ''; |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | |
@@ -365,9 +365,9 @@ discard block |
||
365 | 365 | * @param boolean $event_category_slug |
366 | 366 | * @return string |
367 | 367 | */ |
368 | - public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) { |
|
368 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) { |
|
369 | 369 | global $wpdb; |
370 | - return ! empty( $event_category_slug ) ? ' AND ' . $wpdb->terms . '.slug = "' . $event_category_slug . '" ' : ''; |
|
370 | + return ! empty($event_category_slug) ? ' AND '.$wpdb->terms.'.slug = "'.$event_category_slug.'" ' : ''; |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -377,15 +377,15 @@ discard block |
||
377 | 377 | * @param boolean $month |
378 | 378 | * @return string |
379 | 379 | */ |
380 | - public static function posts_where_sql_for_event_list_month( $month = NULL ) { |
|
381 | - $SQL= ''; |
|
382 | - if ( ! empty( $month )) { |
|
380 | + public static function posts_where_sql_for_event_list_month($month = NULL) { |
|
381 | + $SQL = ''; |
|
382 | + if ( ! empty($month)) { |
|
383 | 383 | // event start date is LESS than the end of the month ( so nothing that doesn't start until next month ) |
384 | - $SQL = ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start'; |
|
385 | - $SQL .= ' <= "' . date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '"'; |
|
384 | + $SQL = ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_start'; |
|
385 | + $SQL .= ' <= "'.date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)).'"'; |
|
386 | 386 | // event end date is GREATER than the start of the month ( so nothing that ended before this month ) |
387 | - $SQL .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end'; |
|
388 | - $SQL .= ' >= "' . date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '" '; |
|
387 | + $SQL .= ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end'; |
|
388 | + $SQL .= ' >= "'.date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)).'" '; |
|
389 | 389 | } |
390 | 390 | return $SQL; |
391 | 391 | } |
@@ -397,9 +397,9 @@ discard block |
||
397 | 397 | * @access public |
398 | 398 | * @return void |
399 | 399 | */ |
400 | - public function posts_orderby( $SQL, WP_Query $wp_query ) { |
|
401 | - if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) { |
|
402 | - $SQL = EED_Events_Archive_Filters::posts_orderby_sql( array( 'start_date' )); |
|
400 | + public function posts_orderby($SQL, WP_Query $wp_query) { |
|
401 | + if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') { |
|
402 | + $SQL = EED_Events_Archive_Filters::posts_orderby_sql(array('start_date')); |
|
403 | 403 | } |
404 | 404 | return $SQL; |
405 | 405 | } |
@@ -428,54 +428,54 @@ discard block |
||
428 | 428 | * @param boolean $orderby_params |
429 | 429 | * @return string |
430 | 430 | */ |
431 | - public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) { |
|
431 | + public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') { |
|
432 | 432 | global $wpdb; |
433 | 433 | $SQL = ''; |
434 | 434 | $cntr = 1; |
435 | - $orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params ); |
|
436 | - foreach( $orderby_params as $orderby ) { |
|
437 | - $glue = $cntr == 1 || $cntr == count( $orderby_params ) ? ' ' : ', '; |
|
438 | - switch ( $orderby ) { |
|
435 | + $orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params); |
|
436 | + foreach ($orderby_params as $orderby) { |
|
437 | + $glue = $cntr == 1 || $cntr == count($orderby_params) ? ' ' : ', '; |
|
438 | + switch ($orderby) { |
|
439 | 439 | |
440 | 440 | case 'id' : |
441 | 441 | case 'ID' : |
442 | - $SQL .= $glue . $wpdb->posts . '.ID ' . $sort; |
|
442 | + $SQL .= $glue.$wpdb->posts.'.ID '.$sort; |
|
443 | 443 | break; |
444 | 444 | |
445 | 445 | case 'start_date' : |
446 | - $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_start ' . $sort; |
|
446 | + $SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_start '.$sort; |
|
447 | 447 | break; |
448 | 448 | |
449 | 449 | case 'end_date' : |
450 | - $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort; |
|
450 | + $SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort; |
|
451 | 451 | break; |
452 | 452 | |
453 | 453 | case 'event_name' : |
454 | - $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort; |
|
454 | + $SQL .= $glue.$wpdb->posts.'.post_title '.$sort; |
|
455 | 455 | break; |
456 | 456 | |
457 | 457 | case 'category_slug' : |
458 | - $SQL .= $glue . $wpdb->terms . '.slug ' . $sort; |
|
458 | + $SQL .= $glue.$wpdb->terms.'.slug '.$sort; |
|
459 | 459 | break; |
460 | 460 | |
461 | 461 | case 'ticket_start' : |
462 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort; |
|
462 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort; |
|
463 | 463 | break; |
464 | 464 | |
465 | 465 | case 'ticket_end' : |
466 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort; |
|
466 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort; |
|
467 | 467 | break; |
468 | 468 | |
469 | 469 | case 'venue_title' : |
470 | - $SQL .= $glue . 'venue_title ' . $sort; |
|
470 | + $SQL .= $glue.'venue_title '.$sort; |
|
471 | 471 | break; |
472 | 472 | |
473 | 473 | case 'city' : |
474 | - $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort; |
|
474 | + $SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort; |
|
475 | 475 | break; |
476 | 476 | |
477 | 477 | case 'state' : |
478 | - $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort; |
|
478 | + $SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort; |
|
479 | 479 | break; |
480 | 480 | |
481 | 481 | } |
@@ -495,26 +495,26 @@ discard block |
||
495 | 495 | */ |
496 | 496 | public function template_redirect() { |
497 | 497 | // add event list filters |
498 | - add_action( 'loop_start', array( $this, 'event_list_template_filters' )); |
|
498 | + add_action('loop_start', array($this, 'event_list_template_filters')); |
|
499 | 499 | // and pagination |
500 | - add_action( 'loop_start', array( $this, 'event_list_pagination' )); |
|
501 | - add_action( 'loop_end', array( $this, 'event_list_pagination' )); |
|
500 | + add_action('loop_start', array($this, 'event_list_pagination')); |
|
501 | + add_action('loop_end', array($this, 'event_list_pagination')); |
|
502 | 502 | // if NOT a custom template |
503 | - if ( EE_Registry::instance()->load_core( 'Front_Controller', array(), false, true )->get_selected_template() != 'archive-espresso_events.php' ) { |
|
503 | + if (EE_Registry::instance()->load_core('Front_Controller', array(), false, true)->get_selected_template() != 'archive-espresso_events.php') { |
|
504 | 504 | // don't know if theme uses the_excerpt |
505 | - add_filter( 'the_excerpt', array( $this, 'event_details' ), 100 ); |
|
506 | - add_filter( 'the_excerpt', array( $this, 'event_tickets' ), 110 ); |
|
507 | - add_filter( 'the_excerpt', array( $this, 'event_datetimes' ), 120 ); |
|
508 | - add_filter( 'the_excerpt', array( $this, 'event_venues' ), 130 ); |
|
505 | + add_filter('the_excerpt', array($this, 'event_details'), 100); |
|
506 | + add_filter('the_excerpt', array($this, 'event_tickets'), 110); |
|
507 | + add_filter('the_excerpt', array($this, 'event_datetimes'), 120); |
|
508 | + add_filter('the_excerpt', array($this, 'event_venues'), 130); |
|
509 | 509 | // or the_content |
510 | - add_filter( 'the_content', array( $this, 'event_details' ), 100 ); |
|
511 | - add_filter( 'the_content', array( $this, 'event_tickets' ), 110 ); |
|
512 | - add_filter( 'the_content', array( $this, 'event_datetimes' ), 120 ); |
|
513 | - add_filter( 'the_content', array( $this, 'event_venues' ), 130 ); |
|
510 | + add_filter('the_content', array($this, 'event_details'), 100); |
|
511 | + add_filter('the_content', array($this, 'event_tickets'), 110); |
|
512 | + add_filter('the_content', array($this, 'event_datetimes'), 120); |
|
513 | + add_filter('the_content', array($this, 'event_venues'), 130); |
|
514 | 514 | } else { |
515 | - remove_all_filters( 'excerpt_length' ); |
|
516 | - add_filter( 'excerpt_length', array( $this, 'excerpt_length' ), 10 ); |
|
517 | - add_filter( 'excerpt_more', array( $this, 'excerpt_more' ), 10 ); |
|
515 | + remove_all_filters('excerpt_length'); |
|
516 | + add_filter('excerpt_length', array($this, 'excerpt_length'), 10); |
|
517 | + add_filter('excerpt_more', array($this, 'excerpt_more'), 10); |
|
518 | 518 | } |
519 | 519 | } |
520 | 520 | |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | * @return void |
528 | 528 | */ |
529 | 529 | public function event_list_pagination() { |
530 | - echo '<div class="ee-pagination-dv clear">' . espresso_event_list_pagination() . '</div>'; |
|
530 | + echo '<div class="ee-pagination-dv clear">'.espresso_event_list_pagination().'</div>'; |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | * @param string $content |
539 | 539 | * @return void |
540 | 540 | */ |
541 | - public function event_details( $content ) { |
|
542 | - return EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-details.php', array( 'the_content' => $content ), TRUE ); |
|
541 | + public function event_details($content) { |
|
542 | + return EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-details.php', array('the_content' => $content), TRUE); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | * @param string $content |
551 | 551 | * @return void |
552 | 552 | */ |
553 | - public function event_tickets( $content ) { |
|
554 | - return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-tickets.php', array(), TRUE ); |
|
553 | + public function event_tickets($content) { |
|
554 | + return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-tickets.php', array(), TRUE); |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
@@ -561,8 +561,8 @@ discard block |
||
561 | 561 | * @param string $content |
562 | 562 | * @return void |
563 | 563 | */ |
564 | - public function event_datetimes( $content ) { |
|
565 | - return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-datetimes.php', array(), TRUE ); |
|
564 | + public function event_datetimes($content) { |
|
565 | + return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-datetimes.php', array(), TRUE); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
@@ -572,8 +572,8 @@ discard block |
||
572 | 572 | * @param string $content |
573 | 573 | * @return void |
574 | 574 | */ |
575 | - public function event_venues( $content ) { |
|
576 | - return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-venues.php', array(), TRUE ); |
|
575 | + public function event_venues($content) { |
|
576 | + return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-venues.php', array(), TRUE); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | |
@@ -588,13 +588,13 @@ discard block |
||
588 | 588 | * @return void |
589 | 589 | */ |
590 | 590 | private function _load_assests() { |
591 | - do_action( 'AHEE__EED_Events_Archive_Filters__before_load_assests' ); |
|
591 | + do_action('AHEE__EED_Events_Archive_Filters__before_load_assests'); |
|
592 | 592 | wp_enqueue_style('espresso_default'); |
593 | 593 | wp_enqueue_style('espresso_custom_css'); |
594 | - add_filter( 'FHEE_load_EE_Session', '__return_true' ); |
|
595 | - add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 ); |
|
596 | - if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) { |
|
597 | - add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 ); |
|
594 | + add_filter('FHEE_load_EE_Session', '__return_true'); |
|
595 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
596 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
597 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
598 | 598 | } |
599 | 599 | //add_filter( 'the_excerpt', array( $this, 'the_excerpt' ), 999 ); |
600 | 600 | } |
@@ -609,8 +609,8 @@ discard block |
||
609 | 609 | * @access private |
610 | 610 | * @return string |
611 | 611 | */ |
612 | - private function _get_template( $which = 'part' ) { |
|
613 | - return EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php'; |
|
612 | + private function _get_template($which = 'part') { |
|
613 | + return EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php'; |
|
614 | 614 | } |
615 | 615 | |
616 | 616 | |
@@ -621,13 +621,13 @@ discard block |
||
621 | 621 | * @access public |
622 | 622 | * @return void |
623 | 623 | */ |
624 | - public function excerpt_length( $length ) { |
|
624 | + public function excerpt_length($length) { |
|
625 | 625 | |
626 | - if ( self::$_type == 'grid' ) { |
|
626 | + if (self::$_type == 'grid') { |
|
627 | 627 | return 36; |
628 | 628 | } |
629 | 629 | |
630 | - switch ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) { |
|
630 | + switch (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) { |
|
631 | 631 | case 'tiny' : |
632 | 632 | return 12; |
633 | 633 | break; |
@@ -651,7 +651,7 @@ discard block |
||
651 | 651 | * @access public |
652 | 652 | * @return void |
653 | 653 | */ |
654 | - public function excerpt_more( $more ) { |
|
654 | + public function excerpt_more($more) { |
|
655 | 655 | return '…'; |
656 | 656 | } |
657 | 657 | |
@@ -681,22 +681,22 @@ discard block |
||
681 | 681 | */ |
682 | 682 | public function wp_enqueue_scripts() { |
683 | 683 | // get some style |
684 | - if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) { |
|
684 | + if (apply_filters('FHEE_enable_default_espresso_css', FALSE)) { |
|
685 | 685 | // first check uploads folder |
686 | - if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css' )) { |
|
687 | - wp_register_style( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' )); |
|
686 | + if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.css')) { |
|
687 | + wp_register_style('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default')); |
|
688 | 688 | } else { |
689 | - wp_register_style( 'archive-espresso_events', EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' )); |
|
689 | + wp_register_style('archive-espresso_events', EE_TEMPLATES_URL.EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default')); |
|
690 | 690 | } |
691 | - if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js' )) { |
|
692 | - wp_register_script( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE ); |
|
691 | + if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.js')) { |
|
692 | + wp_register_script('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE); |
|
693 | 693 | } else { |
694 | - wp_register_script( 'archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE ); |
|
694 | + wp_register_script('archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE); |
|
695 | 695 | } |
696 | - wp_enqueue_style( 'archive-espresso_events' ); |
|
697 | - wp_enqueue_script( 'jquery-masonry' ); |
|
698 | - wp_enqueue_script( 'archive-espresso_events' ); |
|
699 | - add_action( 'wp_footer', array( 'EED_Events_Archive_Filters', 'localize_grid_event_lists' ), 1 ); |
|
696 | + wp_enqueue_style('archive-espresso_events'); |
|
697 | + wp_enqueue_script('jquery-masonry'); |
|
698 | + wp_enqueue_script('archive-espresso_events'); |
|
699 | + add_action('wp_footer', array('EED_Events_Archive_Filters', 'localize_grid_event_lists'), 1); |
|
700 | 700 | } |
701 | 701 | } |
702 | 702 | |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | * @return void |
712 | 712 | */ |
713 | 713 | public static function localize_grid_event_lists() { |
714 | - wp_localize_script( 'archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists ); |
|
714 | + wp_localize_script('archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | |
@@ -726,9 +726,9 @@ discard block |
||
726 | 726 | */ |
727 | 727 | public static function template_settings_form() { |
728 | 728 | $EE = EE_Registry::instance(); |
729 | - $EE->CFG->template_settings->EED_Events_Archive_Filters = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config(); |
|
730 | - $EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters( 'FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters ); |
|
731 | - EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters ); |
|
729 | + $EE->CFG->template_settings->EED_Events_Archive_Filters = isset($EE->CFG->template_settings->EED_Events_Archive_Filters) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config(); |
|
730 | + $EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters('FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters); |
|
731 | + EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters); |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | |
@@ -742,16 +742,16 @@ discard block |
||
742 | 742 | * @static |
743 | 743 | * @return void |
744 | 744 | */ |
745 | - public static function set_default_settings( $CFG ) { |
|
745 | + public static function set_default_settings($CFG) { |
|
746 | 746 | //EEH_Debug_Tools::printr( $CFG, '$CFG <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
747 | - $CFG->display_description = isset( $CFG->display_description ) && ! empty( $CFG->display_description ) ? $CFG->display_description : 1; |
|
748 | - $CFG->display_address = isset( $CFG->display_address ) && ! empty( $CFG->display_address ) ? $CFG->display_address : TRUE; |
|
749 | - $CFG->display_venue_details = isset( $CFG->display_venue_details ) && ! empty( $CFG->display_venue_details ) ? $CFG->display_venue_details : TRUE; |
|
750 | - $CFG->display_expired_events = isset( $CFG->display_expired_events ) && ! empty( $CFG->display_expired_events ) ? $CFG->display_expired_events : FALSE; |
|
751 | - $CFG->default_type = isset( $CFG->default_type ) && ! empty( $CFG->default_type ) ? $CFG->default_type : 'grid'; |
|
752 | - $CFG->event_list_grid_size = isset( $CFG->event_list_grid_size ) && ! empty( $CFG->event_list_grid_size ) ? $CFG->event_list_grid_size : 'medium'; |
|
753 | - $CFG->templates['full'] = isset( $CFG->templates['full'] ) && ! empty( $CFG->templates['full'] ) ? $CFG->templates['full'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php'; |
|
754 | - $CFG->templates['part'] = isset( $CFG->templates['part'] ) && ! empty( $CFG->templates['part'] ) ? $CFG->templates['part'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php'; |
|
747 | + $CFG->display_description = isset($CFG->display_description) && ! empty($CFG->display_description) ? $CFG->display_description : 1; |
|
748 | + $CFG->display_address = isset($CFG->display_address) && ! empty($CFG->display_address) ? $CFG->display_address : TRUE; |
|
749 | + $CFG->display_venue_details = isset($CFG->display_venue_details) && ! empty($CFG->display_venue_details) ? $CFG->display_venue_details : TRUE; |
|
750 | + $CFG->display_expired_events = isset($CFG->display_expired_events) && ! empty($CFG->display_expired_events) ? $CFG->display_expired_events : FALSE; |
|
751 | + $CFG->default_type = isset($CFG->default_type) && ! empty($CFG->default_type) ? $CFG->default_type : 'grid'; |
|
752 | + $CFG->event_list_grid_size = isset($CFG->event_list_grid_size) && ! empty($CFG->event_list_grid_size) ? $CFG->event_list_grid_size : 'medium'; |
|
753 | + $CFG->templates['full'] = isset($CFG->templates['full']) && ! empty($CFG->templates['full']) ? $CFG->templates['full'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php'; |
|
754 | + $CFG->templates['part'] = isset($CFG->templates['part']) && ! empty($CFG->templates['part']) ? $CFG->templates['part'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php'; |
|
755 | 755 | return $CFG; |
756 | 756 | } |
757 | 757 | |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | * @access public |
764 | 764 | * @return void |
765 | 765 | */ |
766 | - public function filter_config( $CFG ) { |
|
766 | + public function filter_config($CFG) { |
|
767 | 767 | return $CFG; |
768 | 768 | } |
769 | 769 | |
@@ -776,32 +776,32 @@ discard block |
||
776 | 776 | * @access public |
777 | 777 | * @return void |
778 | 778 | */ |
779 | - public static function update_template_settings( $CFG, $REQ ) { |
|
779 | + public static function update_template_settings($CFG, $REQ) { |
|
780 | 780 | // EEH_Debug_Tools::printr( $REQ, '$REQ <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
781 | 781 | // EEH_Debug_Tools::printr( $CFG, '$CFG <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
782 | 782 | //$CFG->template_settings->EED_Events_Archive_Filters = new stdClass(); |
783 | - $CFG->EED_Events_Archive_Filters->display_description = isset( $REQ['display_description_in_event_list'] ) ? absint( $REQ['display_description_in_event_list'] ) : 1; |
|
784 | - $CFG->EED_Events_Archive_Filters->display_address = isset( $REQ['display_address_in_event_list'] ) ? absint( $REQ['display_address_in_event_list'] ) : TRUE; |
|
785 | - $CFG->EED_Events_Archive_Filters->display_venue_details = isset( $REQ['display_venue_details_in_event_list'] ) ? absint( $REQ['display_venue_details_in_event_list'] ) : TRUE; |
|
786 | - $CFG->EED_Events_Archive_Filters->display_expired_events = isset( $REQ['display_expired_events'] ) ? absint( $REQ['display_expired_events'] ) : FALSE; |
|
787 | - $CFG->EED_Events_Archive_Filters->default_type = isset( $REQ['default_type'] ) ? sanitize_text_field( $REQ['default_type'] ) : 'grid'; |
|
788 | - $CFG->EED_Events_Archive_Filters->event_list_grid_size = isset( $REQ['event_list_grid_size'] ) ? sanitize_text_field( $REQ['event_list_grid_size'] ) : 'medium'; |
|
783 | + $CFG->EED_Events_Archive_Filters->display_description = isset($REQ['display_description_in_event_list']) ? absint($REQ['display_description_in_event_list']) : 1; |
|
784 | + $CFG->EED_Events_Archive_Filters->display_address = isset($REQ['display_address_in_event_list']) ? absint($REQ['display_address_in_event_list']) : TRUE; |
|
785 | + $CFG->EED_Events_Archive_Filters->display_venue_details = isset($REQ['display_venue_details_in_event_list']) ? absint($REQ['display_venue_details_in_event_list']) : TRUE; |
|
786 | + $CFG->EED_Events_Archive_Filters->display_expired_events = isset($REQ['display_expired_events']) ? absint($REQ['display_expired_events']) : FALSE; |
|
787 | + $CFG->EED_Events_Archive_Filters->default_type = isset($REQ['default_type']) ? sanitize_text_field($REQ['default_type']) : 'grid'; |
|
788 | + $CFG->EED_Events_Archive_Filters->event_list_grid_size = isset($REQ['event_list_grid_size']) ? sanitize_text_field($REQ['event_list_grid_size']) : 'medium'; |
|
789 | 789 | $CFG->EED_Events_Archive_Filters->templates = array( |
790 | - 'full' => EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php' |
|
790 | + 'full' => EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php' |
|
791 | 791 | ); |
792 | 792 | |
793 | - switch ( $CFG->EED_Events_Archive_Filters->default_type ) { |
|
793 | + switch ($CFG->EED_Events_Archive_Filters->default_type) { |
|
794 | 794 | case 'dates' : |
795 | - $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-dates-view.php'; |
|
795 | + $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-dates-view.php'; |
|
796 | 796 | break; |
797 | 797 | case 'text' : |
798 | - $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-text-view.php'; |
|
798 | + $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-text-view.php'; |
|
799 | 799 | break; |
800 | 800 | default : |
801 | - $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php'; |
|
801 | + $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php'; |
|
802 | 802 | } |
803 | 803 | |
804 | - $CFG->EED_Events_Archive_Filters = isset( $REQ['reset_event_list_settings'] ) && absint( $REQ['reset_event_list_settings'] ) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters; |
|
804 | + $CFG->EED_Events_Archive_Filters = isset($REQ['reset_event_list_settings']) && absint($REQ['reset_event_list_settings']) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters; |
|
805 | 805 | return $CFG; |
806 | 806 | } |
807 | 807 | |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | * @return void |
817 | 817 | */ |
818 | 818 | public static function get_template_part() { |
819 | - switch ( self::$_type ) { |
|
819 | + switch (self::$_type) { |
|
820 | 820 | case 'dates' : |
821 | 821 | return 'archive-espresso_events-dates-view.php'; |
822 | 822 | break; |
@@ -840,13 +840,13 @@ discard block |
||
840 | 840 | */ |
841 | 841 | public function event_list_template_filters() { |
842 | 842 | $args = array( |
843 | - 'form_url' => get_post_type_archive_link( 'espresso_events' ), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ), |
|
843 | + 'form_url' => get_post_type_archive_link('espresso_events'), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ), |
|
844 | 844 | 'elf_month' => EED_Events_Archive_Filters::_display_month(), |
845 | 845 | 'elf_category' => EED_Events_Archive_Filters::_event_category_slug(), |
846 | 846 | 'elf_show_expired' => EED_Events_Archive_Filters::_show_expired(), |
847 | 847 | 'elf_type' => self::$_type |
848 | 848 | ); |
849 | - EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-filters.php', $args ); |
|
849 | + EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-filters.php', $args); |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | |
@@ -859,16 +859,16 @@ discard block |
||
859 | 859 | * @access public |
860 | 860 | * @return void |
861 | 861 | */ |
862 | - public static function event_list_css( $extra_class = '' ) { |
|
862 | + public static function event_list_css($extra_class = '') { |
|
863 | 863 | $EE = EE_Registry::instance(); |
864 | - $event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array(); |
|
864 | + $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
865 | 865 | $event_list_css[] = 'espresso-event-list-event'; |
866 | - if ( self::$_type == 'grid' ) { |
|
867 | - $event_list_grid_size = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium'; |
|
868 | - $event_list_css[] = $event_list_grid_size . '-event-list-grid'; |
|
866 | + if (self::$_type == 'grid') { |
|
867 | + $event_list_grid_size = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium'; |
|
868 | + $event_list_css[] = $event_list_grid_size.'-event-list-grid'; |
|
869 | 869 | } |
870 | - $event_list_css = apply_filters( 'EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css ); |
|
871 | - return implode( ' ', $event_list_css ); |
|
870 | + $event_list_css = apply_filters('EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css); |
|
871 | + return implode(' ', $event_list_css); |
|
872 | 872 | } |
873 | 873 | |
874 | 874 | |
@@ -894,9 +894,9 @@ discard block |
||
894 | 894 | * @access public |
895 | 895 | * @return void |
896 | 896 | */ |
897 | - public static function display_description( $value ) { |
|
897 | + public static function display_description($value) { |
|
898 | 898 | $EE = EE_Registry::instance(); |
899 | - $display_description= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1; |
|
899 | + $display_description = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_description) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1; |
|
900 | 900 | return $display_description === $value ? TRUE : FALSE; |
901 | 901 | } |
902 | 902 | |
@@ -910,9 +910,9 @@ discard block |
||
910 | 910 | */ |
911 | 911 | public static function display_venue_details() { |
912 | 912 | $EE = EE_Registry::instance(); |
913 | - $display_venue_details= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE; |
|
913 | + $display_venue_details = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE; |
|
914 | 914 | $venue_name = EEH_Venue_View::venue_name(); |
915 | - return $display_venue_details && ! empty( $venue_name ) ? TRUE : FALSE; |
|
915 | + return $display_venue_details && ! empty($venue_name) ? TRUE : FALSE; |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | |
@@ -924,9 +924,9 @@ discard block |
||
924 | 924 | */ |
925 | 925 | public static function display_address() { |
926 | 926 | $EE = EE_Registry::instance(); |
927 | - $display_address= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE; |
|
927 | + $display_address = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_address) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE; |
|
928 | 928 | $venue_name = EEH_Venue_View::venue_name(); |
929 | - return $display_address && ! empty( $venue_name ) ? TRUE : FALSE; |
|
929 | + return $display_address && ! empty($venue_name) ? TRUE : FALSE; |
|
930 | 930 | } |
931 | 931 | |
932 | 932 | |
@@ -940,22 +940,22 @@ discard block |
||
940 | 940 | public static function pagination() { |
941 | 941 | global $wp_query; |
942 | 942 | $big = 999999999; // need an unlikely integer |
943 | - $pagination = paginate_links( array( |
|
944 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
943 | + $pagination = paginate_links(array( |
|
944 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
945 | 945 | 'format' => '?paged=%#%', |
946 | - 'current' => max( 1, get_query_var('paged') ), |
|
946 | + 'current' => max(1, get_query_var('paged')), |
|
947 | 947 | 'total' => $wp_query->max_num_pages, |
948 | 948 | 'show_all' => TRUE, |
949 | 949 | 'end_size' => 10, |
950 | 950 | 'mid_size' => 6, |
951 | 951 | 'prev_next' => TRUE, |
952 | - 'prev_text' => __( '‹ PREV', 'event_espresso' ), |
|
953 | - 'next_text' => __( 'NEXT ›', 'event_espresso' ), |
|
952 | + 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
953 | + 'next_text' => __('NEXT ›', 'event_espresso'), |
|
954 | 954 | 'type' => 'plain', |
955 | 955 | 'add_args' => FALSE, |
956 | 956 | 'add_fragment' => '' |
957 | 957 | )); |
958 | - return ! empty( $pagination ) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : ''; |
|
958 | + return ! empty($pagination) ? '<div class="ee-pagination-dv clear">'.$pagination.'</div>' : ''; |
|
959 | 959 | } |
960 | 960 | |
961 | 961 | |
@@ -969,7 +969,7 @@ discard block |
||
969 | 969 | * @return void |
970 | 970 | */ |
971 | 971 | public static function event_list_title() { |
972 | - return apply_filters( 'EED_Events_Archive_Filters__event_list_title__event_list_title', __( 'Upcoming Events', 'event_espresso' )); |
|
972 | + return apply_filters('EED_Events_Archive_Filters__event_list_title__event_list_title', __('Upcoming Events', 'event_espresso')); |
|
973 | 973 | } |
974 | 974 | |
975 | 975 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter; |
3 | 3 | |
4 | 4 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -19,480 +19,480 @@ discard block |
||
19 | 19 | abstract class EE_Form_Section_Base |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * the URL the form is submitted to |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $_action; |
|
28 | - |
|
29 | - /** |
|
30 | - * POST (default) or GET |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $_method; |
|
35 | - |
|
36 | - /** |
|
37 | - * html_id and html_name are derived from this by default |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $_name; |
|
42 | - |
|
43 | - /** |
|
44 | - * $_html_id |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - protected $_html_id; |
|
48 | - |
|
49 | - /** |
|
50 | - * $_html_class |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $_html_class; |
|
54 | - |
|
55 | - /** |
|
56 | - * $_html_style |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - protected $_html_style; |
|
60 | - |
|
61 | - /** |
|
62 | - * $_other_html_attributes |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - protected $_other_html_attributes; |
|
66 | - |
|
67 | - /** |
|
68 | - * The form section of which this form section is a part |
|
69 | - * |
|
70 | - * @var EE_Form_Section_Proper |
|
71 | - */ |
|
72 | - protected $_parent_section; |
|
73 | - |
|
74 | - /** |
|
75 | - * flag indicating that _construct_finalize has been called. |
|
76 | - * If it hasn't been called and we try to use functions which require it, we call it |
|
77 | - * with no parameters. But normally, _construct_finalize should be called by the instantiating class |
|
78 | - * |
|
79 | - * @var boolean |
|
80 | - */ |
|
81 | - protected $_construction_finalized; |
|
82 | - |
|
83 | - /** |
|
84 | - * Strategy for parsing the form HTML upon display |
|
85 | - * |
|
86 | - * @var FormHtmlFilter |
|
87 | - */ |
|
88 | - protected $_form_html_filter; |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @param array $options_array { |
|
94 | - * @type $name string the name for this form section, if you want to explicitly define it |
|
95 | - * } |
|
96 | - */ |
|
97 | - public function __construct($options_array = array()) |
|
98 | - { |
|
99 | - // used by display strategies |
|
100 | - // assign incoming values to properties |
|
101 | - foreach ($options_array as $key => $value) { |
|
102 | - $key = '_' . $key; |
|
103 | - if (property_exists($this, $key) && empty($this->{$key})) { |
|
104 | - $this->{$key} = $value; |
|
105 | - } |
|
106 | - } |
|
107 | - // set parser which allows the form section's rendered HTML to be filtered |
|
108 | - if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) { |
|
109 | - $this->_form_html_filter = $options_array['form_html_filter']; |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @param $parent_form_section |
|
117 | - * @param $name |
|
118 | - * @throws \EE_Error |
|
119 | - */ |
|
120 | - protected function _construct_finalize($parent_form_section, $name) |
|
121 | - { |
|
122 | - $this->_construction_finalized = true; |
|
123 | - $this->_parent_section = $parent_form_section; |
|
124 | - if ($name !== null) { |
|
125 | - $this->_name = $name; |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * make sure construction finalized was called, otherwise children might not be ready |
|
133 | - * |
|
134 | - * @return void |
|
135 | - * @throws \EE_Error |
|
136 | - */ |
|
137 | - public function ensure_construct_finalized_called() |
|
138 | - { |
|
139 | - if (! $this->_construction_finalized) { |
|
140 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function action() |
|
150 | - { |
|
151 | - return $this->_action; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @param string $action |
|
158 | - */ |
|
159 | - public function set_action($action) |
|
160 | - { |
|
161 | - $this->_action = $action; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - public function method() |
|
170 | - { |
|
171 | - return ! empty($this->_method) ? $this->_method : 'POST'; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @param string $method |
|
178 | - */ |
|
179 | - public function set_method($method) |
|
180 | - { |
|
181 | - switch ($method) { |
|
182 | - case 'get' : |
|
183 | - case 'GET' : |
|
184 | - $this->_method = 'GET'; |
|
185 | - break; |
|
186 | - default : |
|
187 | - $this->_method = 'POST'; |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * Sets the html_id to its default value, if none was specified in the constructor. |
|
195 | - * Calculation involves using the name and the parent's html id |
|
196 | - * return void |
|
197 | - * |
|
198 | - * @throws \EE_Error |
|
199 | - */ |
|
200 | - protected function _set_default_html_id_if_empty() |
|
201 | - { |
|
202 | - if (! $this->_html_id) { |
|
203 | - if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
204 | - $this->_html_id = $this->_parent_section->html_id() |
|
205 | - . '-' |
|
206 | - . $this->_prep_name_for_html_id($this->name()); |
|
207 | - } else { |
|
208 | - $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
209 | - } |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * _prep_name_for_html_id |
|
217 | - * |
|
218 | - * @param $name |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - private function _prep_name_for_html_id($name) |
|
222 | - { |
|
223 | - return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
224 | - } |
|
22 | + /** |
|
23 | + * the URL the form is submitted to |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $_action; |
|
28 | + |
|
29 | + /** |
|
30 | + * POST (default) or GET |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $_method; |
|
35 | + |
|
36 | + /** |
|
37 | + * html_id and html_name are derived from this by default |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $_name; |
|
42 | + |
|
43 | + /** |
|
44 | + * $_html_id |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + protected $_html_id; |
|
48 | + |
|
49 | + /** |
|
50 | + * $_html_class |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $_html_class; |
|
54 | + |
|
55 | + /** |
|
56 | + * $_html_style |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + protected $_html_style; |
|
60 | + |
|
61 | + /** |
|
62 | + * $_other_html_attributes |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + protected $_other_html_attributes; |
|
66 | + |
|
67 | + /** |
|
68 | + * The form section of which this form section is a part |
|
69 | + * |
|
70 | + * @var EE_Form_Section_Proper |
|
71 | + */ |
|
72 | + protected $_parent_section; |
|
73 | + |
|
74 | + /** |
|
75 | + * flag indicating that _construct_finalize has been called. |
|
76 | + * If it hasn't been called and we try to use functions which require it, we call it |
|
77 | + * with no parameters. But normally, _construct_finalize should be called by the instantiating class |
|
78 | + * |
|
79 | + * @var boolean |
|
80 | + */ |
|
81 | + protected $_construction_finalized; |
|
82 | + |
|
83 | + /** |
|
84 | + * Strategy for parsing the form HTML upon display |
|
85 | + * |
|
86 | + * @var FormHtmlFilter |
|
87 | + */ |
|
88 | + protected $_form_html_filter; |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @param array $options_array { |
|
94 | + * @type $name string the name for this form section, if you want to explicitly define it |
|
95 | + * } |
|
96 | + */ |
|
97 | + public function __construct($options_array = array()) |
|
98 | + { |
|
99 | + // used by display strategies |
|
100 | + // assign incoming values to properties |
|
101 | + foreach ($options_array as $key => $value) { |
|
102 | + $key = '_' . $key; |
|
103 | + if (property_exists($this, $key) && empty($this->{$key})) { |
|
104 | + $this->{$key} = $value; |
|
105 | + } |
|
106 | + } |
|
107 | + // set parser which allows the form section's rendered HTML to be filtered |
|
108 | + if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) { |
|
109 | + $this->_form_html_filter = $options_array['form_html_filter']; |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @param $parent_form_section |
|
117 | + * @param $name |
|
118 | + * @throws \EE_Error |
|
119 | + */ |
|
120 | + protected function _construct_finalize($parent_form_section, $name) |
|
121 | + { |
|
122 | + $this->_construction_finalized = true; |
|
123 | + $this->_parent_section = $parent_form_section; |
|
124 | + if ($name !== null) { |
|
125 | + $this->_name = $name; |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * make sure construction finalized was called, otherwise children might not be ready |
|
133 | + * |
|
134 | + * @return void |
|
135 | + * @throws \EE_Error |
|
136 | + */ |
|
137 | + public function ensure_construct_finalized_called() |
|
138 | + { |
|
139 | + if (! $this->_construction_finalized) { |
|
140 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function action() |
|
150 | + { |
|
151 | + return $this->_action; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @param string $action |
|
158 | + */ |
|
159 | + public function set_action($action) |
|
160 | + { |
|
161 | + $this->_action = $action; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + public function method() |
|
170 | + { |
|
171 | + return ! empty($this->_method) ? $this->_method : 'POST'; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @param string $method |
|
178 | + */ |
|
179 | + public function set_method($method) |
|
180 | + { |
|
181 | + switch ($method) { |
|
182 | + case 'get' : |
|
183 | + case 'GET' : |
|
184 | + $this->_method = 'GET'; |
|
185 | + break; |
|
186 | + default : |
|
187 | + $this->_method = 'POST'; |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * Sets the html_id to its default value, if none was specified in the constructor. |
|
195 | + * Calculation involves using the name and the parent's html id |
|
196 | + * return void |
|
197 | + * |
|
198 | + * @throws \EE_Error |
|
199 | + */ |
|
200 | + protected function _set_default_html_id_if_empty() |
|
201 | + { |
|
202 | + if (! $this->_html_id) { |
|
203 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
204 | + $this->_html_id = $this->_parent_section->html_id() |
|
205 | + . '-' |
|
206 | + . $this->_prep_name_for_html_id($this->name()); |
|
207 | + } else { |
|
208 | + $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
209 | + } |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * _prep_name_for_html_id |
|
217 | + * |
|
218 | + * @param $name |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + private function _prep_name_for_html_id($name) |
|
222 | + { |
|
223 | + return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
224 | + } |
|
225 | 225 | |
226 | 226 | |
227 | 227 | |
228 | - /** |
|
229 | - * Returns the HTML, JS, and CSS necessary to display this form section on a page. |
|
230 | - * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action, |
|
231 | - * and call get_html when you want to output the html. Calling get_html_and_js after |
|
232 | - * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary |
|
233 | - * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/ |
|
234 | - * and so might stop working anytime. |
|
235 | - * |
|
236 | - * @return string |
|
237 | - */ |
|
238 | - public function get_html_and_js() |
|
239 | - { |
|
240 | - return $this->get_html(); |
|
241 | - } |
|
228 | + /** |
|
229 | + * Returns the HTML, JS, and CSS necessary to display this form section on a page. |
|
230 | + * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action, |
|
231 | + * and call get_html when you want to output the html. Calling get_html_and_js after |
|
232 | + * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary |
|
233 | + * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/ |
|
234 | + * and so might stop working anytime. |
|
235 | + * |
|
236 | + * @return string |
|
237 | + */ |
|
238 | + public function get_html_and_js() |
|
239 | + { |
|
240 | + return $this->get_html(); |
|
241 | + } |
|
242 | 242 | |
243 | 243 | |
244 | 244 | |
245 | - /** |
|
246 | - * Gets the HTML for displaying this form section |
|
247 | - * |
|
248 | - * @return string |
|
249 | - */ |
|
250 | - public abstract function get_html(); |
|
245 | + /** |
|
246 | + * Gets the HTML for displaying this form section |
|
247 | + * |
|
248 | + * @return string |
|
249 | + */ |
|
250 | + public abstract function get_html(); |
|
251 | 251 | |
252 | 252 | |
253 | 253 | |
254 | - /** |
|
255 | - * @param bool $add_pound_sign |
|
256 | - * @return string |
|
257 | - */ |
|
258 | - public function html_id($add_pound_sign = false) |
|
259 | - { |
|
260 | - $this->_set_default_html_id_if_empty(); |
|
261 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
262 | - } |
|
254 | + /** |
|
255 | + * @param bool $add_pound_sign |
|
256 | + * @return string |
|
257 | + */ |
|
258 | + public function html_id($add_pound_sign = false) |
|
259 | + { |
|
260 | + $this->_set_default_html_id_if_empty(); |
|
261 | + return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
262 | + } |
|
263 | 263 | |
264 | 264 | |
265 | - |
|
266 | - /** |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public function html_class() |
|
270 | - { |
|
271 | - return $this->_html_class; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * @return string |
|
278 | - */ |
|
279 | - public function html_style() |
|
280 | - { |
|
281 | - return $this->_html_style; |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @param mixed $html_class |
|
288 | - */ |
|
289 | - public function set_html_class($html_class) |
|
290 | - { |
|
291 | - $this->_html_class = $html_class; |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * @param mixed $html_id |
|
298 | - */ |
|
299 | - public function set_html_id($html_id) |
|
300 | - { |
|
301 | - $this->_html_id = $html_id; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * @param mixed $html_style |
|
308 | - */ |
|
309 | - public function set_html_style($html_style) |
|
310 | - { |
|
311 | - $this->_html_style = $html_style; |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * @param string $other_html_attributes |
|
318 | - */ |
|
319 | - public function set_other_html_attributes($other_html_attributes) |
|
320 | - { |
|
321 | - $this->_other_html_attributes = $other_html_attributes; |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @return string |
|
328 | - */ |
|
329 | - public function other_html_attributes() |
|
330 | - { |
|
331 | - return $this->_other_html_attributes; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * Gets the name of the form section. This is not the same as the HTML name. |
|
338 | - * |
|
339 | - * @throws EE_Error |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - public function name() |
|
343 | - { |
|
344 | - if (! $this->_construction_finalized) { |
|
345 | - throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', |
|
346 | - 'event_espresso'), get_class($this))); |
|
347 | - } |
|
348 | - return $this->_name; |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * Gets the parent section |
|
355 | - * |
|
356 | - * @return EE_Form_Section_Proper |
|
357 | - */ |
|
358 | - public function parent_section() |
|
359 | - { |
|
360 | - return $this->_parent_section; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * returns HTML for generating the opening form HTML tag (<form>) |
|
367 | - * |
|
368 | - * @param string $action the URL the form is submitted to |
|
369 | - * @param string $method POST (default) or GET |
|
370 | - * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
|
371 | - * @return string |
|
372 | - */ |
|
373 | - public function form_open($action = '', $method = '', $other_attributes = '') |
|
374 | - { |
|
375 | - if (! empty($action)) { |
|
376 | - $this->set_action($action); |
|
377 | - } |
|
378 | - if (! empty($method)) { |
|
379 | - $this->set_method($method); |
|
380 | - } |
|
381 | - $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
382 | - $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
383 | - $html .= ' action="' . $this->action() . '"'; |
|
384 | - $html .= ' method="' . $this->method() . '"'; |
|
385 | - $html .= $other_attributes . '>'; |
|
386 | - return $html; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * ensures that html id for form either ends in "-form" or "-frm" |
|
393 | - * so that id doesn't conflict/collide with other elements |
|
394 | - * |
|
395 | - * @param string $html_id |
|
396 | - * @return string |
|
397 | - */ |
|
398 | - protected function get_html_id_for_form($html_id) |
|
399 | - { |
|
400 | - $strlen = strlen($html_id); |
|
401 | - $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4 |
|
402 | - ? $html_id |
|
403 | - : $html_id . '-frm'; |
|
404 | - return $html_id; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * returns HTML for generating the closing form HTML tag (</form>) |
|
411 | - * |
|
412 | - * @return string |
|
413 | - */ |
|
414 | - public function form_close() |
|
415 | - { |
|
416 | - return EEH_HTML::nl(-1, 'form') |
|
417 | - . '</form>' |
|
418 | - . EEH_HTML::nl() |
|
419 | - . '<!-- end of ee-' |
|
420 | - . $this->html_id() |
|
421 | - . '-form -->' |
|
422 | - . EEH_HTML::nl(); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and |
|
429 | - * wp_enqueue_style; the scripts could have optionally been registered earlier) |
|
430 | - * Default does nothing, but child classes can override |
|
431 | - * |
|
432 | - * @return void |
|
433 | - */ |
|
434 | - public function enqueue_js() |
|
435 | - { |
|
436 | - //defaults to enqueue NO js or css |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * Adds any extra data needed by js. Eventually we'll call wp_localize_script |
|
443 | - * with it, and it will be on each form section's 'other_data' property. |
|
444 | - * By default nothing is added, but child classes can extend this method to add something. |
|
445 | - * Eg, if you have an input that will cause a modal dialog to appear, |
|
446 | - * here you could add an entry like 'modal_dialog_inputs' to this array |
|
447 | - * to map between the input's html ID and the modal dialogue's ID, so that |
|
448 | - * your JS code will know where to find the modal dialog when the input is pressed. |
|
449 | - * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id'; |
|
450 | - * |
|
451 | - * @param array $form_other_js_data |
|
452 | - * @return array |
|
453 | - */ |
|
454 | - public function get_other_js_data($form_other_js_data = array()) |
|
455 | - { |
|
456 | - return $form_other_js_data; |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
463 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
464 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
465 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
466 | - * which will be returned. |
|
467 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
468 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
469 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
470 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
471 | - * Etc |
|
472 | - * |
|
473 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
474 | - * @return EE_Form_Section_Base |
|
475 | - */ |
|
476 | - public function find_section_from_path($form_section_path) |
|
477 | - { |
|
478 | - if (strpos($form_section_path, '/') === 0) { |
|
479 | - $form_section_path = substr($form_section_path, strlen('/')); |
|
480 | - } |
|
481 | - if (empty($form_section_path)) { |
|
482 | - return $this; |
|
483 | - } |
|
484 | - if (strpos($form_section_path, '../') === 0) { |
|
485 | - $parent = $this->parent_section(); |
|
486 | - $form_section_path = substr($form_section_path, strlen('../')); |
|
487 | - if ($parent instanceof EE_Form_Section_Base) { |
|
488 | - return $parent->find_section_from_path($form_section_path); |
|
489 | - } elseif (empty($form_section_path)) { |
|
490 | - return $this; |
|
491 | - } |
|
492 | - } |
|
493 | - //couldn't find it using simple parent following |
|
494 | - return null; |
|
495 | - } |
|
265 | + |
|
266 | + /** |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public function html_class() |
|
270 | + { |
|
271 | + return $this->_html_class; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * @return string |
|
278 | + */ |
|
279 | + public function html_style() |
|
280 | + { |
|
281 | + return $this->_html_style; |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @param mixed $html_class |
|
288 | + */ |
|
289 | + public function set_html_class($html_class) |
|
290 | + { |
|
291 | + $this->_html_class = $html_class; |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * @param mixed $html_id |
|
298 | + */ |
|
299 | + public function set_html_id($html_id) |
|
300 | + { |
|
301 | + $this->_html_id = $html_id; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * @param mixed $html_style |
|
308 | + */ |
|
309 | + public function set_html_style($html_style) |
|
310 | + { |
|
311 | + $this->_html_style = $html_style; |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * @param string $other_html_attributes |
|
318 | + */ |
|
319 | + public function set_other_html_attributes($other_html_attributes) |
|
320 | + { |
|
321 | + $this->_other_html_attributes = $other_html_attributes; |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @return string |
|
328 | + */ |
|
329 | + public function other_html_attributes() |
|
330 | + { |
|
331 | + return $this->_other_html_attributes; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * Gets the name of the form section. This is not the same as the HTML name. |
|
338 | + * |
|
339 | + * @throws EE_Error |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + public function name() |
|
343 | + { |
|
344 | + if (! $this->_construction_finalized) { |
|
345 | + throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', |
|
346 | + 'event_espresso'), get_class($this))); |
|
347 | + } |
|
348 | + return $this->_name; |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * Gets the parent section |
|
355 | + * |
|
356 | + * @return EE_Form_Section_Proper |
|
357 | + */ |
|
358 | + public function parent_section() |
|
359 | + { |
|
360 | + return $this->_parent_section; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * returns HTML for generating the opening form HTML tag (<form>) |
|
367 | + * |
|
368 | + * @param string $action the URL the form is submitted to |
|
369 | + * @param string $method POST (default) or GET |
|
370 | + * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
|
371 | + * @return string |
|
372 | + */ |
|
373 | + public function form_open($action = '', $method = '', $other_attributes = '') |
|
374 | + { |
|
375 | + if (! empty($action)) { |
|
376 | + $this->set_action($action); |
|
377 | + } |
|
378 | + if (! empty($method)) { |
|
379 | + $this->set_method($method); |
|
380 | + } |
|
381 | + $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
382 | + $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
383 | + $html .= ' action="' . $this->action() . '"'; |
|
384 | + $html .= ' method="' . $this->method() . '"'; |
|
385 | + $html .= $other_attributes . '>'; |
|
386 | + return $html; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * ensures that html id for form either ends in "-form" or "-frm" |
|
393 | + * so that id doesn't conflict/collide with other elements |
|
394 | + * |
|
395 | + * @param string $html_id |
|
396 | + * @return string |
|
397 | + */ |
|
398 | + protected function get_html_id_for_form($html_id) |
|
399 | + { |
|
400 | + $strlen = strlen($html_id); |
|
401 | + $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4 |
|
402 | + ? $html_id |
|
403 | + : $html_id . '-frm'; |
|
404 | + return $html_id; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * returns HTML for generating the closing form HTML tag (</form>) |
|
411 | + * |
|
412 | + * @return string |
|
413 | + */ |
|
414 | + public function form_close() |
|
415 | + { |
|
416 | + return EEH_HTML::nl(-1, 'form') |
|
417 | + . '</form>' |
|
418 | + . EEH_HTML::nl() |
|
419 | + . '<!-- end of ee-' |
|
420 | + . $this->html_id() |
|
421 | + . '-form -->' |
|
422 | + . EEH_HTML::nl(); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and |
|
429 | + * wp_enqueue_style; the scripts could have optionally been registered earlier) |
|
430 | + * Default does nothing, but child classes can override |
|
431 | + * |
|
432 | + * @return void |
|
433 | + */ |
|
434 | + public function enqueue_js() |
|
435 | + { |
|
436 | + //defaults to enqueue NO js or css |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * Adds any extra data needed by js. Eventually we'll call wp_localize_script |
|
443 | + * with it, and it will be on each form section's 'other_data' property. |
|
444 | + * By default nothing is added, but child classes can extend this method to add something. |
|
445 | + * Eg, if you have an input that will cause a modal dialog to appear, |
|
446 | + * here you could add an entry like 'modal_dialog_inputs' to this array |
|
447 | + * to map between the input's html ID and the modal dialogue's ID, so that |
|
448 | + * your JS code will know where to find the modal dialog when the input is pressed. |
|
449 | + * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id'; |
|
450 | + * |
|
451 | + * @param array $form_other_js_data |
|
452 | + * @return array |
|
453 | + */ |
|
454 | + public function get_other_js_data($form_other_js_data = array()) |
|
455 | + { |
|
456 | + return $form_other_js_data; |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
463 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
464 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
465 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
466 | + * which will be returned. |
|
467 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
468 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
469 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
470 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
471 | + * Etc |
|
472 | + * |
|
473 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
474 | + * @return EE_Form_Section_Base |
|
475 | + */ |
|
476 | + public function find_section_from_path($form_section_path) |
|
477 | + { |
|
478 | + if (strpos($form_section_path, '/') === 0) { |
|
479 | + $form_section_path = substr($form_section_path, strlen('/')); |
|
480 | + } |
|
481 | + if (empty($form_section_path)) { |
|
482 | + return $this; |
|
483 | + } |
|
484 | + if (strpos($form_section_path, '../') === 0) { |
|
485 | + $parent = $this->parent_section(); |
|
486 | + $form_section_path = substr($form_section_path, strlen('../')); |
|
487 | + if ($parent instanceof EE_Form_Section_Base) { |
|
488 | + return $parent->find_section_from_path($form_section_path); |
|
489 | + } elseif (empty($form_section_path)) { |
|
490 | + return $this; |
|
491 | + } |
|
492 | + } |
|
493 | + //couldn't find it using simple parent following |
|
494 | + return null; |
|
495 | + } |
|
496 | 496 | |
497 | 497 | |
498 | 498 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter; |
3 | 3 | |
4 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | 5 | exit('No direct script access allowed'); |
6 | 6 | } |
7 | 7 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | // used by display strategies |
100 | 100 | // assign incoming values to properties |
101 | 101 | foreach ($options_array as $key => $value) { |
102 | - $key = '_' . $key; |
|
102 | + $key = '_'.$key; |
|
103 | 103 | if (property_exists($this, $key) && empty($this->{$key})) { |
104 | 104 | $this->{$key} = $value; |
105 | 105 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function ensure_construct_finalized_called() |
138 | 138 | { |
139 | - if (! $this->_construction_finalized) { |
|
139 | + if ( ! $this->_construction_finalized) { |
|
140 | 140 | $this->_construct_finalize($this->_parent_section, $this->_name); |
141 | 141 | } |
142 | 142 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | protected function _set_default_html_id_if_empty() |
201 | 201 | { |
202 | - if (! $this->_html_id) { |
|
202 | + if ( ! $this->_html_id) { |
|
203 | 203 | if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
204 | 204 | $this->_html_id = $this->_parent_section->html_id() |
205 | 205 | . '-' |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | public function html_id($add_pound_sign = false) |
259 | 259 | { |
260 | 260 | $this->_set_default_html_id_if_empty(); |
261 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
261 | + return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id; |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | */ |
342 | 342 | public function name() |
343 | 343 | { |
344 | - if (! $this->_construction_finalized) { |
|
344 | + if ( ! $this->_construction_finalized) { |
|
345 | 345 | throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', |
346 | 346 | 'event_espresso'), get_class($this))); |
347 | 347 | } |
@@ -372,17 +372,17 @@ discard block |
||
372 | 372 | */ |
373 | 373 | public function form_open($action = '', $method = '', $other_attributes = '') |
374 | 374 | { |
375 | - if (! empty($action)) { |
|
375 | + if ( ! empty($action)) { |
|
376 | 376 | $this->set_action($action); |
377 | 377 | } |
378 | - if (! empty($method)) { |
|
378 | + if ( ! empty($method)) { |
|
379 | 379 | $this->set_method($method); |
380 | 380 | } |
381 | - $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
382 | - $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
383 | - $html .= ' action="' . $this->action() . '"'; |
|
384 | - $html .= ' method="' . $this->method() . '"'; |
|
385 | - $html .= $other_attributes . '>'; |
|
381 | + $html = EEH_HTML::nl(1, 'form').'<form'; |
|
382 | + $html .= $this->html_id() !== '' ? ' id="'.$this->get_html_id_for_form($this->html_id()).'"' : ''; |
|
383 | + $html .= ' action="'.$this->action().'"'; |
|
384 | + $html .= ' method="'.$this->method().'"'; |
|
385 | + $html .= $other_attributes.'>'; |
|
386 | 386 | return $html; |
387 | 387 | } |
388 | 388 | |
@@ -398,9 +398,9 @@ discard block |
||
398 | 398 | protected function get_html_id_for_form($html_id) |
399 | 399 | { |
400 | 400 | $strlen = strlen($html_id); |
401 | - $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4 |
|
401 | + $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4 |
|
402 | 402 | ? $html_id |
403 | - : $html_id . '-frm'; |
|
403 | + : $html_id.'-frm'; |
|
404 | 404 | return $html_id; |
405 | 405 | } |
406 | 406 |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function __construct($options_array = array()) |
86 | 86 | { |
87 | - $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
87 | + $options_array = (array) apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
88 | 88 | $this); |
89 | 89 | //call parent first, as it may be setting the name |
90 | 90 | parent::__construct($options_array); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | if (isset($options_array['layout_strategy'])) { |
108 | 108 | $this->_layout_strategy = $options_array['layout_strategy']; |
109 | 109 | } |
110 | - if (! $this->_layout_strategy) { |
|
110 | + if ( ! $this->_layout_strategy) { |
|
111 | 111 | $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
112 | 112 | } |
113 | 113 | $this->_layout_strategy->_construct_finalize($this); |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | if ($validate) { |
259 | 259 | $this->_validate(); |
260 | 260 | //if it's invalid, we're going to want to re-display so remember what they submitted |
261 | - if (! $this->is_valid()) { |
|
261 | + if ( ! $this->is_valid()) { |
|
262 | 262 | $this->store_submitted_form_data_in_session(); |
263 | 263 | } |
264 | 264 | } |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | public function get_input($name, $require_construction_to_be_finalized = true) |
439 | 439 | { |
440 | 440 | $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
441 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
441 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
442 | 442 | throw new EE_Error( |
443 | 443 | sprintf( |
444 | 444 | __( |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
474 | 474 | { |
475 | 475 | $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
476 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
476 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
477 | 477 | throw new EE_Error( |
478 | 478 | sprintf( |
479 | 479 | __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | */ |
512 | 512 | public function is_valid() |
513 | 513 | { |
514 | - if (! $this->has_received_submission()) { |
|
514 | + if ( ! $this->has_received_submission()) { |
|
515 | 515 | throw new EE_Error( |
516 | 516 | sprintf( |
517 | 517 | __( |
@@ -521,14 +521,14 @@ discard block |
||
521 | 521 | ) |
522 | 522 | ); |
523 | 523 | } |
524 | - if (! parent::is_valid()) { |
|
524 | + if ( ! parent::is_valid()) { |
|
525 | 525 | return false; |
526 | 526 | } |
527 | 527 | // ok so no general errors to this entire form section. |
528 | 528 | // so let's check the subsections, but only set errors if that hasn't been done yet |
529 | 529 | $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
530 | 530 | foreach ($this->get_validatable_subsections() as $subsection) { |
531 | - if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
531 | + if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
532 | 532 | if ($set_submission_errors) { |
533 | 533 | $this->set_submission_error_message($subsection->get_validation_error_string()); |
534 | 534 | } |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | */ |
548 | 548 | protected function _set_default_name_if_empty() |
549 | 549 | { |
550 | - if (! $this->_name) { |
|
550 | + if ( ! $this->_name) { |
|
551 | 551 | $classname = get_class($this); |
552 | 552 | $default_name = str_replace("EE_", "", $classname); |
553 | 553 | $this->_name = $default_name; |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | { |
633 | 633 | wp_register_script( |
634 | 634 | 'ee_form_section_validation', |
635 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
635 | + EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js', |
|
636 | 636 | array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
637 | 637 | EVENT_ESPRESSO_VERSION, |
638 | 638 | true |
@@ -778,7 +778,7 @@ discard block |
||
778 | 778 | */ |
779 | 779 | public function ensure_scripts_localized() |
780 | 780 | { |
781 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
781 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
782 | 782 | $this->_enqueue_and_localize_form_js(); |
783 | 783 | } |
784 | 784 | } |
@@ -874,8 +874,8 @@ discard block |
||
874 | 874 | protected function _validate() |
875 | 875 | { |
876 | 876 | foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
877 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
878 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
877 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
878 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
879 | 879 | } |
880 | 880 | $subsection->_validate(); |
881 | 881 | } |
@@ -1151,7 +1151,7 @@ discard block |
||
1151 | 1151 | public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
1152 | 1152 | { |
1153 | 1153 | foreach ($new_subsections as $subsection_name => $subsection) { |
1154 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1154 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
1155 | 1155 | EE_Error::add_error( |
1156 | 1156 | sprintf( |
1157 | 1157 | __( |
@@ -1249,7 +1249,7 @@ discard block |
||
1249 | 1249 | public function html_name_prefix() |
1250 | 1250 | { |
1251 | 1251 | if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
1252 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1252 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
1253 | 1253 | } else { |
1254 | 1254 | return $this->name(); |
1255 | 1255 | } |
@@ -1293,7 +1293,7 @@ discard block |
||
1293 | 1293 | */ |
1294 | 1294 | public function ensure_construct_finalized_called() |
1295 | 1295 | { |
1296 | - if (! $this->_construction_finalized) { |
|
1296 | + if ( ! $this->_construction_finalized) { |
|
1297 | 1297 | $this->_construct_finalize($this->_parent_section, $this->_name); |
1298 | 1298 | } |
1299 | 1299 | } |
@@ -11,1385 +11,1385 @@ |
||
11 | 11 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
12 | 12 | { |
13 | 13 | |
14 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
15 | - |
|
16 | - /** |
|
17 | - * Subsections |
|
18 | - * |
|
19 | - * @var EE_Form_Section_Validatable[] |
|
20 | - */ |
|
21 | - protected $_subsections = array(); |
|
22 | - |
|
23 | - /** |
|
24 | - * Strategy for laying out the form |
|
25 | - * |
|
26 | - * @var EE_Form_Section_Layout_Base |
|
27 | - */ |
|
28 | - protected $_layout_strategy; |
|
29 | - |
|
30 | - /** |
|
31 | - * Whether or not this form has received and validated a form submission yet |
|
32 | - * |
|
33 | - * @var boolean |
|
34 | - */ |
|
35 | - protected $_received_submission = false; |
|
36 | - |
|
37 | - /** |
|
38 | - * message displayed to users upon successful form submission |
|
39 | - * |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $_form_submission_success_message = ''; |
|
43 | - |
|
44 | - /** |
|
45 | - * message displayed to users upon unsuccessful form submission |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - protected $_form_submission_error_message = ''; |
|
50 | - |
|
51 | - /** |
|
52 | - * Stores all the data that will localized for form validation |
|
53 | - * |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - static protected $_js_localization = array(); |
|
57 | - |
|
58 | - /** |
|
59 | - * whether or not the form's localized validation JS vars have been set |
|
60 | - * |
|
61 | - * @type boolean |
|
62 | - */ |
|
63 | - static protected $_scripts_localized = false; |
|
64 | - |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * when constructing a proper form section, calls _construct_finalize on children |
|
69 | - * so that they know who their parent is, and what name they've been given. |
|
70 | - * |
|
71 | - * @param array $options_array { |
|
72 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
73 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
74 | - * and in that order. This is handy if you want |
|
75 | - * the subsections to be ordered differently than the default, and if you override |
|
76 | - * which fields are shown |
|
77 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
78 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
79 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
80 | - * items from that list of inclusions) |
|
81 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
82 | - * } @see EE_Form_Section_Validatable::__construct() |
|
83 | - * @throws \EE_Error |
|
84 | - */ |
|
85 | - public function __construct($options_array = array()) |
|
86 | - { |
|
87 | - $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
88 | - $this); |
|
89 | - //call parent first, as it may be setting the name |
|
90 | - parent::__construct($options_array); |
|
91 | - //if they've included subsections in the constructor, add them now |
|
92 | - if (isset($options_array['include'])) { |
|
93 | - //we are going to make sure we ONLY have those subsections to include |
|
94 | - //AND we are going to make sure they're in that specified order |
|
95 | - $reordered_subsections = array(); |
|
96 | - foreach ($options_array['include'] as $input_name) { |
|
97 | - if (isset($this->_subsections[$input_name])) { |
|
98 | - $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
99 | - } |
|
100 | - } |
|
101 | - $this->_subsections = $reordered_subsections; |
|
102 | - } |
|
103 | - if (isset($options_array['exclude'])) { |
|
104 | - $exclude = $options_array['exclude']; |
|
105 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
106 | - } |
|
107 | - if (isset($options_array['layout_strategy'])) { |
|
108 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
109 | - } |
|
110 | - if (! $this->_layout_strategy) { |
|
111 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
112 | - } |
|
113 | - $this->_layout_strategy->_construct_finalize($this); |
|
114 | - //ok so we are definitely going to want the forms JS, |
|
115 | - //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
116 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
117 | - //ok so they've constructed this object after when they should have. |
|
118 | - //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
119 | - \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
120 | - } else { |
|
121 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
122 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
123 | - } |
|
124 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
125 | - |
|
126 | - /** |
|
127 | - * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't |
|
128 | - * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to |
|
129 | - * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
130 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
131 | - * @since 4.9.32 |
|
132 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling |
|
133 | - * _construct_finalize has been done |
|
134 | - * @param array $options_array options passed into the constructor |
|
135 | - */ |
|
136 | - do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array); |
|
137 | - |
|
138 | - if (isset($options_array['name'])) { |
|
139 | - $this->_construct_finalize(null, $options_array['name']); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * Finishes construction given the parent form section and this form section's name |
|
147 | - * |
|
148 | - * @param EE_Form_Section_Proper $parent_form_section |
|
149 | - * @param string $name |
|
150 | - * @throws \EE_Error |
|
151 | - */ |
|
152 | - public function _construct_finalize($parent_form_section, $name) |
|
153 | - { |
|
154 | - parent::_construct_finalize($parent_form_section, $name); |
|
155 | - $this->_set_default_name_if_empty(); |
|
156 | - $this->_set_default_html_id_if_empty(); |
|
157 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
158 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
159 | - $subsection->_construct_finalize($this, $subsection_name); |
|
160 | - } else { |
|
161 | - throw new EE_Error( |
|
162 | - sprintf( |
|
163 | - __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
164 | - 'event_espresso'), |
|
165 | - $subsection_name, |
|
166 | - get_class($this), |
|
167 | - $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
168 | - ) |
|
169 | - ); |
|
170 | - } |
|
171 | - } |
|
172 | - /** |
|
173 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
174 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived |
|
175 | - * from the name like the HTML label id, etc), this is where it should be done. |
|
176 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
177 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
178 | - * ensured it has a name, HTML IDs, etc |
|
179 | - * @param EE_Form_Section_Proper $this |
|
180 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
181 | - * @param string $name |
|
182 | - */ |
|
183 | - do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Gets the layout strategy for this form section |
|
190 | - * |
|
191 | - * @return EE_Form_Section_Layout_Base |
|
192 | - */ |
|
193 | - public function get_layout_strategy() |
|
194 | - { |
|
195 | - return $this->_layout_strategy; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Gets the HTML for a single input for this form section according |
|
202 | - * to the layout strategy |
|
203 | - * |
|
204 | - * @param EE_Form_Input_Base $input |
|
205 | - * @return string |
|
206 | - */ |
|
207 | - public function get_html_for_input($input) |
|
208 | - { |
|
209 | - return $this->_layout_strategy->layout_input($input); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * was_submitted - checks if form inputs are present in request data |
|
216 | - * Basically an alias for form_data_present_in() (which is used by both |
|
217 | - * proper form sections and form inputs) |
|
218 | - * |
|
219 | - * @param null $form_data |
|
220 | - * @return boolean |
|
221 | - */ |
|
222 | - public function was_submitted($form_data = null) |
|
223 | - { |
|
224 | - return $this->form_data_present_in($form_data); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
231 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
232 | - * |
|
233 | - * @param array|null $req_data should usually be $_POST (the default). |
|
234 | - * However, you CAN supply a different array. |
|
235 | - * Consider using set_defaults() instead however. |
|
236 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
237 | - * the inputs will have the correct name in the request data for this function |
|
238 | - * to find them and populate the form with them. |
|
239 | - * If you have a flat form (with only input subsections), |
|
240 | - * you can supply a flat array where keys |
|
241 | - * are the form input names and values are their values) |
|
242 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
243 | - * of course, to validate that data, and set errors on the invalid values. |
|
244 | - * But if the data has already been validated |
|
245 | - * (eg you validated the data then stored it in the DB) |
|
246 | - * you may want to skip this step. |
|
247 | - */ |
|
248 | - public function receive_form_submission($req_data = null, $validate = true) |
|
249 | - { |
|
250 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
251 | - $validate); |
|
252 | - if ($req_data === null) { |
|
253 | - $req_data = array_merge($_GET, $_POST); |
|
254 | - } |
|
255 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
256 | - $this); |
|
257 | - $this->_normalize($req_data); |
|
258 | - if ($validate) { |
|
259 | - $this->_validate(); |
|
260 | - //if it's invalid, we're going to want to re-display so remember what they submitted |
|
261 | - if (! $this->is_valid()) { |
|
262 | - $this->store_submitted_form_data_in_session(); |
|
263 | - } |
|
264 | - } |
|
265 | - do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * caches the originally submitted input values in the session |
|
272 | - * so that they can be used to repopulate the form if it failed validation |
|
273 | - * |
|
274 | - * @return boolean whether or not the data was successfully stored in the session |
|
275 | - */ |
|
276 | - protected function store_submitted_form_data_in_session() |
|
277 | - { |
|
278 | - return EE_Registry::instance()->SSN->set_session_data( |
|
279 | - array( |
|
280 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
281 | - ) |
|
282 | - ); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * retrieves the originally submitted input values in the session |
|
289 | - * so that they can be used to repopulate the form if it failed validation |
|
290 | - * |
|
291 | - * @return array |
|
292 | - */ |
|
293 | - protected function get_submitted_form_data_from_session() |
|
294 | - { |
|
295 | - $session = EE_Registry::instance()->SSN; |
|
296 | - if ($session instanceof EE_Session) { |
|
297 | - return $session->get_session_data( |
|
298 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
299 | - ); |
|
300 | - } else { |
|
301 | - return array(); |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * flushed the originally submitted input values from the session |
|
309 | - * |
|
310 | - * @return boolean whether or not the data was successfully removed from the session |
|
311 | - */ |
|
312 | - protected function flush_submitted_form_data_from_session() |
|
313 | - { |
|
314 | - return EE_Registry::instance()->SSN->reset_data( |
|
315 | - array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
316 | - ); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * Populates this form and its subsections with data from the session. |
|
323 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
324 | - * validation errors when displaying too) |
|
325 | - * Returns true if the form was populated from the session, false otherwise |
|
326 | - * |
|
327 | - * @return boolean |
|
328 | - */ |
|
329 | - public function populate_from_session() |
|
330 | - { |
|
331 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
332 | - if (empty($form_data_in_session)) { |
|
333 | - return false; |
|
334 | - } |
|
335 | - $this->receive_form_submission($form_data_in_session); |
|
336 | - $this->flush_submitted_form_data_from_session(); |
|
337 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
338 | - return true; |
|
339 | - } else { |
|
340 | - return false; |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * Populates the default data for the form, given an array where keys are |
|
348 | - * the input names, and values are their values (preferably normalized to be their |
|
349 | - * proper PHP types, not all strings... although that should be ok too). |
|
350 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
351 | - * the value being an array formatted in teh same way |
|
352 | - * |
|
353 | - * @param array $default_data |
|
354 | - */ |
|
355 | - public function populate_defaults($default_data) |
|
356 | - { |
|
357 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
358 | - if (isset($default_data[$subsection_name])) { |
|
359 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
360 | - $subsection->set_default($default_data[$subsection_name]); |
|
361 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
362 | - $subsection->populate_defaults($default_data[$subsection_name]); |
|
363 | - } |
|
364 | - } |
|
365 | - } |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * returns true if subsection exists |
|
372 | - * |
|
373 | - * @param string $name |
|
374 | - * @return boolean |
|
375 | - */ |
|
376 | - public function subsection_exists($name) |
|
377 | - { |
|
378 | - return isset($this->_subsections[$name]) ? true : false; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * Gets the subsection specified by its name |
|
385 | - * |
|
386 | - * @param string $name |
|
387 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
388 | - * so that the inputs will be properly configured. |
|
389 | - * However, some client code may be ok |
|
390 | - * with construction finalize being called later |
|
391 | - * (realizing that the subsections' html names |
|
392 | - * might not be set yet, etc.) |
|
393 | - * @return EE_Form_Section_Base |
|
394 | - * @throws \EE_Error |
|
395 | - */ |
|
396 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
397 | - { |
|
398 | - if ($require_construction_to_be_finalized) { |
|
399 | - $this->ensure_construct_finalized_called(); |
|
400 | - } |
|
401 | - return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * Gets all the validatable subsections of this form section |
|
408 | - * |
|
409 | - * @return EE_Form_Section_Validatable[] |
|
410 | - */ |
|
411 | - public function get_validatable_subsections() |
|
412 | - { |
|
413 | - $validatable_subsections = array(); |
|
414 | - foreach ($this->subsections() as $name => $obj) { |
|
415 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
416 | - $validatable_subsections[$name] = $obj; |
|
417 | - } |
|
418 | - } |
|
419 | - return $validatable_subsections; |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
426 | - * throw an EE_Error. |
|
427 | - * |
|
428 | - * @param string $name |
|
429 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
430 | - * leave this as TRUE so that the inputs will be properly |
|
431 | - * configured. However, some client code may be ok with |
|
432 | - * construction finalize being called later |
|
433 | - * (realizing that the subsections' html names might not be |
|
434 | - * set yet, etc.) |
|
435 | - * @return EE_Form_Input_Base |
|
436 | - * @throws EE_Error |
|
437 | - */ |
|
438 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
439 | - { |
|
440 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
441 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
442 | - throw new EE_Error( |
|
443 | - sprintf( |
|
444 | - __( |
|
445 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
446 | - 'event_espresso' |
|
447 | - ), |
|
448 | - $name, |
|
449 | - get_class($this), |
|
450 | - $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
451 | - ) |
|
452 | - ); |
|
453 | - } |
|
454 | - return $subsection; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
461 | - * otherwise throws an EE_Error |
|
462 | - * |
|
463 | - * @param string $name |
|
464 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
465 | - * leave this as TRUE so that the inputs will be properly |
|
466 | - * configured. However, some client code may be ok with |
|
467 | - * construction finalize being called later |
|
468 | - * (realizing that the subsections' html names might not be |
|
469 | - * set yet, etc.) |
|
470 | - * @return EE_Form_Section_Proper |
|
471 | - * @throws EE_Error |
|
472 | - */ |
|
473 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
474 | - { |
|
475 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
476 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
477 | - throw new EE_Error( |
|
478 | - sprintf( |
|
479 | - __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
480 | - $name, |
|
481 | - get_class($this) |
|
482 | - ) |
|
483 | - ); |
|
484 | - } |
|
485 | - return $subsection; |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
492 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
493 | - * |
|
494 | - * @param string $name |
|
495 | - * @return mixed depending on the input's type and its normalization strategy |
|
496 | - * @throws \EE_Error |
|
497 | - */ |
|
498 | - public function get_input_value($name) |
|
499 | - { |
|
500 | - $input = $this->get_input($name); |
|
501 | - return $input->normalized_value(); |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * Checks if this form section itself is valid, and then checks its subsections |
|
508 | - * |
|
509 | - * @throws EE_Error |
|
510 | - * @return boolean |
|
511 | - */ |
|
512 | - public function is_valid() |
|
513 | - { |
|
514 | - if (! $this->has_received_submission()) { |
|
515 | - throw new EE_Error( |
|
516 | - sprintf( |
|
517 | - __( |
|
518 | - "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
519 | - "event_espresso" |
|
520 | - ) |
|
521 | - ) |
|
522 | - ); |
|
523 | - } |
|
524 | - if (! parent::is_valid()) { |
|
525 | - return false; |
|
526 | - } |
|
527 | - // ok so no general errors to this entire form section. |
|
528 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
529 | - $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
530 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
531 | - if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
532 | - if ($set_submission_errors) { |
|
533 | - $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
534 | - } |
|
535 | - return false; |
|
536 | - } |
|
537 | - } |
|
538 | - return true; |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * gets teh default name of this form section if none is specified |
|
545 | - * |
|
546 | - * @return string |
|
547 | - */ |
|
548 | - protected function _set_default_name_if_empty() |
|
549 | - { |
|
550 | - if (! $this->_name) { |
|
551 | - $classname = get_class($this); |
|
552 | - $default_name = str_replace("EE_", "", $classname); |
|
553 | - $this->_name = $default_name; |
|
554 | - } |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
561 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
562 | - * and except for a submit button. Enqueus JS and CSS; if called early enough we will |
|
563 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
564 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
565 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
566 | - * any CSS. |
|
567 | - * |
|
568 | - * @throws \EE_Error |
|
569 | - */ |
|
570 | - public function get_html_and_js() |
|
571 | - { |
|
572 | - $this->enqueue_js(); |
|
573 | - return $this->get_html(); |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
580 | - * |
|
581 | - * @param bool $display_previously_submitted_data |
|
582 | - * @return string |
|
583 | - */ |
|
584 | - public function get_html($display_previously_submitted_data = true) |
|
585 | - { |
|
586 | - $this->ensure_construct_finalized_called(); |
|
587 | - if ($display_previously_submitted_data) { |
|
588 | - $this->populate_from_session(); |
|
589 | - } |
|
590 | - return $this->_form_html_filter |
|
591 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
592 | - : $this->_layout_strategy->layout_form(); |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * enqueues JS and CSS for the form. |
|
599 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
600 | - * scripts and styles can be put in the header, but if called later |
|
601 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
602 | - * only be in the header; but in HTML5 its ok in the body. |
|
603 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
604 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
605 | - * |
|
606 | - * @return string |
|
607 | - * @throws \EE_Error |
|
608 | - */ |
|
609 | - public function enqueue_js() |
|
610 | - { |
|
611 | - $this->_enqueue_and_localize_form_js(); |
|
612 | - foreach ($this->subsections() as $subsection) { |
|
613 | - $subsection->enqueue_js(); |
|
614 | - } |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
621 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
622 | - * the wp_enqueue_scripts hook. |
|
623 | - * However, registering the form js and localizing it can happen when we |
|
624 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
625 | - * could change until it's actually outputted) |
|
626 | - * |
|
627 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
628 | - * to be triggered automatically or not |
|
629 | - * @return void |
|
630 | - */ |
|
631 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
632 | - { |
|
633 | - wp_register_script( |
|
634 | - 'ee_form_section_validation', |
|
635 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
636 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
637 | - EVENT_ESPRESSO_VERSION, |
|
638 | - true |
|
639 | - ); |
|
640 | - wp_localize_script( |
|
641 | - 'ee_form_section_validation', |
|
642 | - 'ee_form_section_validation_init', |
|
643 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
644 | - ); |
|
645 | - } |
|
646 | - |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * gets the variables used by form_section_validation.js. |
|
651 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
652 | - * but before the wordpress hook wp_loaded |
|
653 | - * |
|
654 | - * @throws \EE_Error |
|
655 | - */ |
|
656 | - public function _enqueue_and_localize_form_js() |
|
657 | - { |
|
658 | - $this->ensure_construct_finalized_called(); |
|
659 | - //actually, we don't want to localize just yet. There may be other forms on the page. |
|
660 | - //so we need to add our form section data to a static variable accessible by all form sections |
|
661 | - //and localize it just before the footer |
|
662 | - $this->localize_validation_rules(); |
|
663 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
664 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
665 | - } |
|
666 | - |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * add our form section data to a static variable accessible by all form sections |
|
671 | - * |
|
672 | - * @param bool $return_for_subsection |
|
673 | - * @return void |
|
674 | - * @throws \EE_Error |
|
675 | - */ |
|
676 | - public function localize_validation_rules($return_for_subsection = false) |
|
677 | - { |
|
678 | - // we only want to localize vars ONCE for the entire form, |
|
679 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
680 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
681 | - EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
682 | - 'form_section_id' => $this->html_id(true), |
|
683 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
684 | - 'other_data' => $this->get_other_js_data(), |
|
685 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
686 | - ); |
|
687 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
688 | - } |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
695 | - * This is primarily data added by inputs and forms in addition to any |
|
696 | - * scripts they might enqueue |
|
697 | - * |
|
698 | - * @param array $form_other_js_data |
|
699 | - * @return array |
|
700 | - */ |
|
701 | - public function get_other_js_data($form_other_js_data = array()) |
|
702 | - { |
|
703 | - foreach ($this->subsections() as $subsection) { |
|
704 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
705 | - } |
|
706 | - return $form_other_js_data; |
|
707 | - } |
|
708 | - |
|
709 | - |
|
710 | - |
|
711 | - /** |
|
712 | - * Gets a flat array of inputs for this form section and its subsections. |
|
713 | - * Keys are their form names, and values are the inputs themselves |
|
714 | - * |
|
715 | - * @return EE_Form_Input_Base |
|
716 | - */ |
|
717 | - public function inputs_in_subsections() |
|
718 | - { |
|
719 | - $inputs = array(); |
|
720 | - foreach ($this->subsections() as $subsection) { |
|
721 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
722 | - $inputs[$subsection->html_name()] = $subsection; |
|
723 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
724 | - $inputs += $subsection->inputs_in_subsections(); |
|
725 | - } |
|
726 | - } |
|
727 | - return $inputs; |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - |
|
732 | - /** |
|
733 | - * Gets a flat array of all the validation errors. |
|
734 | - * Keys are html names (because those should be unique) |
|
735 | - * and values are a string of all their validation errors |
|
736 | - * |
|
737 | - * @return string[] |
|
738 | - */ |
|
739 | - public function subsection_validation_errors_by_html_name() |
|
740 | - { |
|
741 | - $inputs = $this->inputs(); |
|
742 | - $errors = array(); |
|
743 | - foreach ($inputs as $form_input) { |
|
744 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
745 | - $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
746 | - } |
|
747 | - } |
|
748 | - return $errors; |
|
749 | - } |
|
750 | - |
|
751 | - |
|
752 | - |
|
753 | - /** |
|
754 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
755 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
756 | - */ |
|
757 | - public static function localize_script_for_all_forms() |
|
758 | - { |
|
759 | - //allow inputs and stuff to hook in their JS and stuff here |
|
760 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
761 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
762 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
763 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
764 | - : 'wp_default'; |
|
765 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
766 | - wp_enqueue_script('ee_form_section_validation'); |
|
767 | - wp_localize_script( |
|
768 | - 'ee_form_section_validation', |
|
769 | - 'ee_form_section_vars', |
|
770 | - EE_Form_Section_Proper::$_js_localization |
|
771 | - ); |
|
772 | - } |
|
773 | - |
|
774 | - |
|
775 | - |
|
776 | - /** |
|
777 | - * ensure_scripts_localized |
|
778 | - */ |
|
779 | - public function ensure_scripts_localized() |
|
780 | - { |
|
781 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
782 | - $this->_enqueue_and_localize_form_js(); |
|
783 | - } |
|
784 | - } |
|
785 | - |
|
786 | - |
|
787 | - |
|
788 | - /** |
|
789 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
790 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
791 | - * |
|
792 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
793 | - */ |
|
794 | - private static function _get_localized_error_messages() |
|
795 | - { |
|
796 | - return array( |
|
797 | - 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
798 | - 'regex' => __('Please check your input', 'event_espresso'), |
|
799 | - ); |
|
800 | - } |
|
801 | - |
|
802 | - |
|
803 | - |
|
804 | - /** |
|
805 | - * @return array |
|
806 | - */ |
|
807 | - public static function js_localization() |
|
808 | - { |
|
809 | - return self::$_js_localization; |
|
810 | - } |
|
811 | - |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * @return array |
|
816 | - */ |
|
817 | - public static function reset_js_localization() |
|
818 | - { |
|
819 | - self::$_js_localization = array(); |
|
820 | - } |
|
821 | - |
|
822 | - |
|
823 | - |
|
824 | - /** |
|
825 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
826 | - * See parent function for more... |
|
827 | - * |
|
828 | - * @return array |
|
829 | - */ |
|
830 | - public function get_jquery_validation_rules() |
|
831 | - { |
|
832 | - $jquery_validation_rules = array(); |
|
833 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
834 | - $jquery_validation_rules = array_merge( |
|
835 | - $jquery_validation_rules, |
|
836 | - $subsection->get_jquery_validation_rules() |
|
837 | - ); |
|
838 | - } |
|
839 | - return $jquery_validation_rules; |
|
840 | - } |
|
841 | - |
|
842 | - |
|
843 | - |
|
844 | - /** |
|
845 | - * Sanitizes all the data and sets the sanitized value of each field |
|
846 | - * |
|
847 | - * @param array $req_data like $_POST |
|
848 | - * @return void |
|
849 | - */ |
|
850 | - protected function _normalize($req_data) |
|
851 | - { |
|
852 | - $this->_received_submission = true; |
|
853 | - $this->_validation_errors = array(); |
|
854 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
855 | - try { |
|
856 | - $subsection->_normalize($req_data); |
|
857 | - } catch (EE_Validation_Error $e) { |
|
858 | - $subsection->add_validation_error($e); |
|
859 | - } |
|
860 | - } |
|
861 | - } |
|
862 | - |
|
863 | - |
|
864 | - |
|
865 | - /** |
|
866 | - * Performs validation on this form section and its subsections. |
|
867 | - * For each subsection, |
|
868 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
869 | - * and passes it the subsection, then calls _validate on that subsection. |
|
870 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
871 | - * you would be best to override this _validate method, |
|
872 | - * calling parent::_validate() first. |
|
873 | - */ |
|
874 | - protected function _validate() |
|
875 | - { |
|
876 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
877 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
878 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
879 | - } |
|
880 | - $subsection->_validate(); |
|
881 | - } |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - |
|
886 | - /** |
|
887 | - * Gets all the validated inputs for the form section |
|
888 | - * |
|
889 | - * @return array |
|
890 | - */ |
|
891 | - public function valid_data() |
|
892 | - { |
|
893 | - $inputs = array(); |
|
894 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
895 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
896 | - $inputs[$subsection_name] = $subsection->valid_data(); |
|
897 | - } else if ($subsection instanceof EE_Form_Input_Base) { |
|
898 | - $inputs[$subsection_name] = $subsection->normalized_value(); |
|
899 | - } |
|
900 | - } |
|
901 | - return $inputs; |
|
902 | - } |
|
903 | - |
|
904 | - |
|
905 | - |
|
906 | - /** |
|
907 | - * Gets all the inputs on this form section |
|
908 | - * |
|
909 | - * @return EE_Form_Input_Base[] |
|
910 | - */ |
|
911 | - public function inputs() |
|
912 | - { |
|
913 | - $inputs = array(); |
|
914 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
915 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
916 | - $inputs[$subsection_name] = $subsection; |
|
917 | - } |
|
918 | - } |
|
919 | - return $inputs; |
|
920 | - } |
|
921 | - |
|
922 | - |
|
923 | - |
|
924 | - /** |
|
925 | - * Gets all the subsections which are a proper form |
|
926 | - * |
|
927 | - * @return EE_Form_Section_Proper[] |
|
928 | - */ |
|
929 | - public function subforms() |
|
930 | - { |
|
931 | - $form_sections = array(); |
|
932 | - foreach ($this->subsections() as $name => $obj) { |
|
933 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
934 | - $form_sections[$name] = $obj; |
|
935 | - } |
|
936 | - } |
|
937 | - return $form_sections; |
|
938 | - } |
|
939 | - |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
944 | - * Consider using inputs() or subforms() |
|
945 | - * if you only want form inputs or proper form sections. |
|
946 | - * |
|
947 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
948 | - * leave this as TRUE so that the inputs will be properly |
|
949 | - * configured. However, some client code may be ok with |
|
950 | - * construction finalize being called later |
|
951 | - * (realizing that the subsections' html names might not be |
|
952 | - * set yet, etc.) |
|
953 | - * @return EE_Form_Section_Proper[] |
|
954 | - */ |
|
955 | - public function subsections($require_construction_to_be_finalized = true) |
|
956 | - { |
|
957 | - if ($require_construction_to_be_finalized) { |
|
958 | - $this->ensure_construct_finalized_called(); |
|
959 | - } |
|
960 | - return $this->_subsections; |
|
961 | - } |
|
962 | - |
|
963 | - |
|
964 | - |
|
965 | - /** |
|
966 | - * Returns a simple array where keys are input names, and values are their normalized |
|
967 | - * values. (Similar to calling get_input_value on inputs) |
|
968 | - * |
|
969 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
970 | - * or just this forms' direct children inputs |
|
971 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
972 | - * or allow multidimensional array |
|
973 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
974 | - * with array keys being input names |
|
975 | - * (regardless of whether they are from a subsection or not), |
|
976 | - * and if $flatten is FALSE it can be a multidimensional array |
|
977 | - * where keys are always subsection names and values are either |
|
978 | - * the input's normalized value, or an array like the top-level array |
|
979 | - */ |
|
980 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
981 | - { |
|
982 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
983 | - } |
|
984 | - |
|
985 | - |
|
986 | - |
|
987 | - /** |
|
988 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
989 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
990 | - * is not necessarily the value we want to display to users. This creates an array |
|
991 | - * where keys are the input names, and values are their display values |
|
992 | - * |
|
993 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
994 | - * or just this forms' direct children inputs |
|
995 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
996 | - * or allow multidimensional array |
|
997 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
998 | - * with array keys being input names |
|
999 | - * (regardless of whether they are from a subsection or not), |
|
1000 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1001 | - * where keys are always subsection names and values are either |
|
1002 | - * the input's normalized value, or an array like the top-level array |
|
1003 | - */ |
|
1004 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1005 | - { |
|
1006 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1007 | - } |
|
1008 | - |
|
1009 | - |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * Gets the input values from the form |
|
1013 | - * |
|
1014 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
1015 | - * or just the normalized value |
|
1016 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1017 | - * or just this forms' direct children inputs |
|
1018 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1019 | - * or allow multidimensional array |
|
1020 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1021 | - * input names (regardless of whether they are from a subsection or not), |
|
1022 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1023 | - * where keys are always subsection names and values are either |
|
1024 | - * the input's normalized value, or an array like the top-level array |
|
1025 | - */ |
|
1026 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1027 | - { |
|
1028 | - $input_values = array(); |
|
1029 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1030 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1031 | - $input_values[$subsection_name] = $pretty |
|
1032 | - ? $subsection->pretty_value() |
|
1033 | - : $subsection->normalized_value(); |
|
1034 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1035 | - $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
1036 | - if ($flatten) { |
|
1037 | - $input_values = array_merge($input_values, $subform_input_values); |
|
1038 | - } else { |
|
1039 | - $input_values[$subsection_name] = $subform_input_values; |
|
1040 | - } |
|
1041 | - } |
|
1042 | - } |
|
1043 | - return $input_values; |
|
1044 | - } |
|
1045 | - |
|
1046 | - |
|
1047 | - |
|
1048 | - /** |
|
1049 | - * Gets the originally submitted input values from the form |
|
1050 | - * |
|
1051 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1052 | - * or just this forms' direct children inputs |
|
1053 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1054 | - * with array keys being input names |
|
1055 | - * (regardless of whether they are from a subsection or not), |
|
1056 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1057 | - * where keys are always subsection names and values are either |
|
1058 | - * the input's normalized value, or an array like the top-level array |
|
1059 | - */ |
|
1060 | - public function submitted_values($include_subforms = false) |
|
1061 | - { |
|
1062 | - $submitted_values = array(); |
|
1063 | - foreach ($this->subsections() as $subsection) { |
|
1064 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1065 | - // is this input part of an array of inputs? |
|
1066 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
1067 | - $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
1068 | - explode('[', str_replace(']', '', $subsection->html_name())), |
|
1069 | - $subsection->raw_value() |
|
1070 | - ); |
|
1071 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1072 | - } else { |
|
1073 | - $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
1074 | - } |
|
1075 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1076 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1077 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1078 | - } |
|
1079 | - } |
|
1080 | - return $submitted_values; |
|
1081 | - } |
|
1082 | - |
|
1083 | - |
|
1084 | - |
|
1085 | - /** |
|
1086 | - * Indicates whether or not this form has received a submission yet |
|
1087 | - * (ie, had receive_form_submission called on it yet) |
|
1088 | - * |
|
1089 | - * @return boolean |
|
1090 | - * @throws \EE_Error |
|
1091 | - */ |
|
1092 | - public function has_received_submission() |
|
1093 | - { |
|
1094 | - $this->ensure_construct_finalized_called(); |
|
1095 | - return $this->_received_submission; |
|
1096 | - } |
|
1097 | - |
|
1098 | - |
|
1099 | - |
|
1100 | - /** |
|
1101 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
1102 | - * Removes the listed inputs from the form |
|
1103 | - * |
|
1104 | - * @param array $inputs_to_exclude values are the input names |
|
1105 | - * @return void |
|
1106 | - */ |
|
1107 | - public function exclude(array $inputs_to_exclude = array()) |
|
1108 | - { |
|
1109 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1110 | - unset($this->_subsections[$input_to_exclude_name]); |
|
1111 | - } |
|
1112 | - } |
|
1113 | - |
|
1114 | - |
|
1115 | - |
|
1116 | - /** |
|
1117 | - * @param array $inputs_to_hide |
|
1118 | - * @throws \EE_Error |
|
1119 | - */ |
|
1120 | - public function hide(array $inputs_to_hide = array()) |
|
1121 | - { |
|
1122 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
1123 | - $input = $this->get_input($input_to_hide); |
|
1124 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1125 | - } |
|
1126 | - } |
|
1127 | - |
|
1128 | - |
|
1129 | - |
|
1130 | - /** |
|
1131 | - * add_subsections |
|
1132 | - * Adds the listed subsections to the form section. |
|
1133 | - * If $subsection_name_to_target is provided, |
|
1134 | - * then new subsections are added before or after that subsection, |
|
1135 | - * otherwise to the start or end of the entire subsections array. |
|
1136 | - * |
|
1137 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1138 | - * where keys are their names |
|
1139 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1140 | - * should be added before or after |
|
1141 | - * IF $subsection_name_to_target is null, |
|
1142 | - * then $new_subsections will be added to |
|
1143 | - * the beginning or end of the entire subsections array |
|
1144 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
1145 | - * $subsection_name_to_target, |
|
1146 | - * or if $subsection_name_to_target is null, |
|
1147 | - * before or after entire subsections array |
|
1148 | - * @return void |
|
1149 | - * @throws \EE_Error |
|
1150 | - */ |
|
1151 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1152 | - { |
|
1153 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
1154 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1155 | - EE_Error::add_error( |
|
1156 | - sprintf( |
|
1157 | - __( |
|
1158 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1159 | - "event_espresso" |
|
1160 | - ), |
|
1161 | - get_class($subsection), |
|
1162 | - $subsection_name, |
|
1163 | - $this->name() |
|
1164 | - ) |
|
1165 | - ); |
|
1166 | - unset($new_subsections[$subsection_name]); |
|
1167 | - } |
|
1168 | - } |
|
1169 | - $this->_subsections = EEH_Array::insert_into_array( |
|
1170 | - $this->_subsections, |
|
1171 | - $new_subsections, |
|
1172 | - $subsection_name_to_target, |
|
1173 | - $add_before |
|
1174 | - ); |
|
1175 | - if ($this->_construction_finalized) { |
|
1176 | - foreach ($this->_subsections as $name => $subsection) { |
|
1177 | - $subsection->_construct_finalize($this, $name); |
|
1178 | - } |
|
1179 | - } |
|
1180 | - } |
|
1181 | - |
|
1182 | - |
|
1183 | - |
|
1184 | - /** |
|
1185 | - * Just gets all validatable subsections to clean their sensitive data |
|
1186 | - */ |
|
1187 | - public function clean_sensitive_data() |
|
1188 | - { |
|
1189 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1190 | - $subsection->clean_sensitive_data(); |
|
1191 | - } |
|
1192 | - } |
|
1193 | - |
|
1194 | - |
|
1195 | - |
|
1196 | - /** |
|
1197 | - * @param string $form_submission_error_message |
|
1198 | - */ |
|
1199 | - public function set_submission_error_message($form_submission_error_message = '') |
|
1200 | - { |
|
1201 | - $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
1202 | - ? $form_submission_error_message |
|
1203 | - : __('Form submission failed due to errors', 'event_espresso'); |
|
1204 | - } |
|
1205 | - |
|
1206 | - |
|
1207 | - |
|
1208 | - /** |
|
1209 | - * @return string |
|
1210 | - */ |
|
1211 | - public function submission_error_message() |
|
1212 | - { |
|
1213 | - return $this->_form_submission_error_message; |
|
1214 | - } |
|
1215 | - |
|
1216 | - |
|
1217 | - |
|
1218 | - /** |
|
1219 | - * @param string $form_submission_success_message |
|
1220 | - */ |
|
1221 | - public function set_submission_success_message($form_submission_success_message) |
|
1222 | - { |
|
1223 | - $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
1224 | - ? $form_submission_success_message |
|
1225 | - : __('Form submitted successfully', 'event_espresso'); |
|
1226 | - } |
|
1227 | - |
|
1228 | - |
|
1229 | - |
|
1230 | - /** |
|
1231 | - * @return string |
|
1232 | - */ |
|
1233 | - public function submission_success_message() |
|
1234 | - { |
|
1235 | - return $this->_form_submission_success_message; |
|
1236 | - } |
|
1237 | - |
|
1238 | - |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * Returns the prefix that should be used on child of this form section for |
|
1242 | - * their html names. If this form section itself has a parent, prepends ITS |
|
1243 | - * prefix onto this form section's prefix. Used primarily by |
|
1244 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1245 | - * |
|
1246 | - * @return string |
|
1247 | - * @throws \EE_Error |
|
1248 | - */ |
|
1249 | - public function html_name_prefix() |
|
1250 | - { |
|
1251 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1252 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1253 | - } else { |
|
1254 | - return $this->name(); |
|
1255 | - } |
|
1256 | - } |
|
1257 | - |
|
1258 | - |
|
1259 | - |
|
1260 | - /** |
|
1261 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1262 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
1263 | - * was set, which is probably nothing, or the classname) |
|
1264 | - * |
|
1265 | - * @return string |
|
1266 | - * @throws \EE_Error |
|
1267 | - */ |
|
1268 | - public function name() |
|
1269 | - { |
|
1270 | - $this->ensure_construct_finalized_called(); |
|
1271 | - return parent::name(); |
|
1272 | - } |
|
1273 | - |
|
1274 | - |
|
1275 | - |
|
1276 | - /** |
|
1277 | - * @return EE_Form_Section_Proper |
|
1278 | - * @throws \EE_Error |
|
1279 | - */ |
|
1280 | - public function parent_section() |
|
1281 | - { |
|
1282 | - $this->ensure_construct_finalized_called(); |
|
1283 | - return parent::parent_section(); |
|
1284 | - } |
|
1285 | - |
|
1286 | - |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * make sure construction finalized was called, otherwise children might not be ready |
|
1290 | - * |
|
1291 | - * @return void |
|
1292 | - * @throws \EE_Error |
|
1293 | - */ |
|
1294 | - public function ensure_construct_finalized_called() |
|
1295 | - { |
|
1296 | - if (! $this->_construction_finalized) { |
|
1297 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1298 | - } |
|
1299 | - } |
|
1300 | - |
|
1301 | - |
|
1302 | - |
|
1303 | - /** |
|
1304 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1305 | - * are in teh form data. If any are found, returns true. Else false |
|
1306 | - * |
|
1307 | - * @param array $req_data |
|
1308 | - * @return boolean |
|
1309 | - */ |
|
1310 | - public function form_data_present_in($req_data = null) |
|
1311 | - { |
|
1312 | - if ($req_data === null) { |
|
1313 | - $req_data = $_POST; |
|
1314 | - } |
|
1315 | - foreach ($this->subsections() as $subsection) { |
|
1316 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1317 | - if ($subsection->form_data_present_in($req_data)) { |
|
1318 | - return true; |
|
1319 | - } |
|
1320 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1321 | - if ($subsection->form_data_present_in($req_data)) { |
|
1322 | - return true; |
|
1323 | - } |
|
1324 | - } |
|
1325 | - } |
|
1326 | - return false; |
|
1327 | - } |
|
1328 | - |
|
1329 | - |
|
1330 | - |
|
1331 | - /** |
|
1332 | - * Gets validation errors for this form section and subsections |
|
1333 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1334 | - * gets the validation errors for ALL subsection |
|
1335 | - * |
|
1336 | - * @return EE_Validation_Error[] |
|
1337 | - */ |
|
1338 | - public function get_validation_errors_accumulated() |
|
1339 | - { |
|
1340 | - $validation_errors = $this->get_validation_errors(); |
|
1341 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1342 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
1343 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1344 | - } else { |
|
1345 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1346 | - } |
|
1347 | - if ($validation_errors_on_this_subsection) { |
|
1348 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1349 | - } |
|
1350 | - } |
|
1351 | - return $validation_errors; |
|
1352 | - } |
|
1353 | - |
|
1354 | - |
|
1355 | - |
|
1356 | - /** |
|
1357 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
1358 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1359 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
1360 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1361 | - * which will be returned. |
|
1362 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1363 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1364 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1365 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1366 | - * Etc |
|
1367 | - * |
|
1368 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1369 | - * @return EE_Form_Section_Base |
|
1370 | - */ |
|
1371 | - public function find_section_from_path($form_section_path) |
|
1372 | - { |
|
1373 | - //check if we can find the input from purely going straight up the tree |
|
1374 | - $input = parent::find_section_from_path($form_section_path); |
|
1375 | - if ($input instanceof EE_Form_Section_Base) { |
|
1376 | - return $input; |
|
1377 | - } |
|
1378 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
1379 | - if ($next_slash_pos !== false) { |
|
1380 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1381 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1382 | - } else { |
|
1383 | - $child_section_name = $form_section_path; |
|
1384 | - $subpath = ''; |
|
1385 | - } |
|
1386 | - $child_section = $this->get_subsection($child_section_name); |
|
1387 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
1388 | - return $child_section->find_section_from_path($subpath); |
|
1389 | - } else { |
|
1390 | - return null; |
|
1391 | - } |
|
1392 | - } |
|
14 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
15 | + |
|
16 | + /** |
|
17 | + * Subsections |
|
18 | + * |
|
19 | + * @var EE_Form_Section_Validatable[] |
|
20 | + */ |
|
21 | + protected $_subsections = array(); |
|
22 | + |
|
23 | + /** |
|
24 | + * Strategy for laying out the form |
|
25 | + * |
|
26 | + * @var EE_Form_Section_Layout_Base |
|
27 | + */ |
|
28 | + protected $_layout_strategy; |
|
29 | + |
|
30 | + /** |
|
31 | + * Whether or not this form has received and validated a form submission yet |
|
32 | + * |
|
33 | + * @var boolean |
|
34 | + */ |
|
35 | + protected $_received_submission = false; |
|
36 | + |
|
37 | + /** |
|
38 | + * message displayed to users upon successful form submission |
|
39 | + * |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $_form_submission_success_message = ''; |
|
43 | + |
|
44 | + /** |
|
45 | + * message displayed to users upon unsuccessful form submission |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + protected $_form_submission_error_message = ''; |
|
50 | + |
|
51 | + /** |
|
52 | + * Stores all the data that will localized for form validation |
|
53 | + * |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + static protected $_js_localization = array(); |
|
57 | + |
|
58 | + /** |
|
59 | + * whether or not the form's localized validation JS vars have been set |
|
60 | + * |
|
61 | + * @type boolean |
|
62 | + */ |
|
63 | + static protected $_scripts_localized = false; |
|
64 | + |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * when constructing a proper form section, calls _construct_finalize on children |
|
69 | + * so that they know who their parent is, and what name they've been given. |
|
70 | + * |
|
71 | + * @param array $options_array { |
|
72 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
73 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
74 | + * and in that order. This is handy if you want |
|
75 | + * the subsections to be ordered differently than the default, and if you override |
|
76 | + * which fields are shown |
|
77 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
78 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
79 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
80 | + * items from that list of inclusions) |
|
81 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
82 | + * } @see EE_Form_Section_Validatable::__construct() |
|
83 | + * @throws \EE_Error |
|
84 | + */ |
|
85 | + public function __construct($options_array = array()) |
|
86 | + { |
|
87 | + $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
88 | + $this); |
|
89 | + //call parent first, as it may be setting the name |
|
90 | + parent::__construct($options_array); |
|
91 | + //if they've included subsections in the constructor, add them now |
|
92 | + if (isset($options_array['include'])) { |
|
93 | + //we are going to make sure we ONLY have those subsections to include |
|
94 | + //AND we are going to make sure they're in that specified order |
|
95 | + $reordered_subsections = array(); |
|
96 | + foreach ($options_array['include'] as $input_name) { |
|
97 | + if (isset($this->_subsections[$input_name])) { |
|
98 | + $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
99 | + } |
|
100 | + } |
|
101 | + $this->_subsections = $reordered_subsections; |
|
102 | + } |
|
103 | + if (isset($options_array['exclude'])) { |
|
104 | + $exclude = $options_array['exclude']; |
|
105 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
106 | + } |
|
107 | + if (isset($options_array['layout_strategy'])) { |
|
108 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
109 | + } |
|
110 | + if (! $this->_layout_strategy) { |
|
111 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
112 | + } |
|
113 | + $this->_layout_strategy->_construct_finalize($this); |
|
114 | + //ok so we are definitely going to want the forms JS, |
|
115 | + //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
116 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
117 | + //ok so they've constructed this object after when they should have. |
|
118 | + //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
119 | + \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
120 | + } else { |
|
121 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
122 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
123 | + } |
|
124 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
125 | + |
|
126 | + /** |
|
127 | + * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't |
|
128 | + * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to |
|
129 | + * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
130 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
131 | + * @since 4.9.32 |
|
132 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling |
|
133 | + * _construct_finalize has been done |
|
134 | + * @param array $options_array options passed into the constructor |
|
135 | + */ |
|
136 | + do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array); |
|
137 | + |
|
138 | + if (isset($options_array['name'])) { |
|
139 | + $this->_construct_finalize(null, $options_array['name']); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * Finishes construction given the parent form section and this form section's name |
|
147 | + * |
|
148 | + * @param EE_Form_Section_Proper $parent_form_section |
|
149 | + * @param string $name |
|
150 | + * @throws \EE_Error |
|
151 | + */ |
|
152 | + public function _construct_finalize($parent_form_section, $name) |
|
153 | + { |
|
154 | + parent::_construct_finalize($parent_form_section, $name); |
|
155 | + $this->_set_default_name_if_empty(); |
|
156 | + $this->_set_default_html_id_if_empty(); |
|
157 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
158 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
159 | + $subsection->_construct_finalize($this, $subsection_name); |
|
160 | + } else { |
|
161 | + throw new EE_Error( |
|
162 | + sprintf( |
|
163 | + __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
164 | + 'event_espresso'), |
|
165 | + $subsection_name, |
|
166 | + get_class($this), |
|
167 | + $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
168 | + ) |
|
169 | + ); |
|
170 | + } |
|
171 | + } |
|
172 | + /** |
|
173 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
174 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived |
|
175 | + * from the name like the HTML label id, etc), this is where it should be done. |
|
176 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
177 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
178 | + * ensured it has a name, HTML IDs, etc |
|
179 | + * @param EE_Form_Section_Proper $this |
|
180 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
181 | + * @param string $name |
|
182 | + */ |
|
183 | + do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Gets the layout strategy for this form section |
|
190 | + * |
|
191 | + * @return EE_Form_Section_Layout_Base |
|
192 | + */ |
|
193 | + public function get_layout_strategy() |
|
194 | + { |
|
195 | + return $this->_layout_strategy; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Gets the HTML for a single input for this form section according |
|
202 | + * to the layout strategy |
|
203 | + * |
|
204 | + * @param EE_Form_Input_Base $input |
|
205 | + * @return string |
|
206 | + */ |
|
207 | + public function get_html_for_input($input) |
|
208 | + { |
|
209 | + return $this->_layout_strategy->layout_input($input); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * was_submitted - checks if form inputs are present in request data |
|
216 | + * Basically an alias for form_data_present_in() (which is used by both |
|
217 | + * proper form sections and form inputs) |
|
218 | + * |
|
219 | + * @param null $form_data |
|
220 | + * @return boolean |
|
221 | + */ |
|
222 | + public function was_submitted($form_data = null) |
|
223 | + { |
|
224 | + return $this->form_data_present_in($form_data); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
231 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
232 | + * |
|
233 | + * @param array|null $req_data should usually be $_POST (the default). |
|
234 | + * However, you CAN supply a different array. |
|
235 | + * Consider using set_defaults() instead however. |
|
236 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
237 | + * the inputs will have the correct name in the request data for this function |
|
238 | + * to find them and populate the form with them. |
|
239 | + * If you have a flat form (with only input subsections), |
|
240 | + * you can supply a flat array where keys |
|
241 | + * are the form input names and values are their values) |
|
242 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
243 | + * of course, to validate that data, and set errors on the invalid values. |
|
244 | + * But if the data has already been validated |
|
245 | + * (eg you validated the data then stored it in the DB) |
|
246 | + * you may want to skip this step. |
|
247 | + */ |
|
248 | + public function receive_form_submission($req_data = null, $validate = true) |
|
249 | + { |
|
250 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
251 | + $validate); |
|
252 | + if ($req_data === null) { |
|
253 | + $req_data = array_merge($_GET, $_POST); |
|
254 | + } |
|
255 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
256 | + $this); |
|
257 | + $this->_normalize($req_data); |
|
258 | + if ($validate) { |
|
259 | + $this->_validate(); |
|
260 | + //if it's invalid, we're going to want to re-display so remember what they submitted |
|
261 | + if (! $this->is_valid()) { |
|
262 | + $this->store_submitted_form_data_in_session(); |
|
263 | + } |
|
264 | + } |
|
265 | + do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * caches the originally submitted input values in the session |
|
272 | + * so that they can be used to repopulate the form if it failed validation |
|
273 | + * |
|
274 | + * @return boolean whether or not the data was successfully stored in the session |
|
275 | + */ |
|
276 | + protected function store_submitted_form_data_in_session() |
|
277 | + { |
|
278 | + return EE_Registry::instance()->SSN->set_session_data( |
|
279 | + array( |
|
280 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
281 | + ) |
|
282 | + ); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * retrieves the originally submitted input values in the session |
|
289 | + * so that they can be used to repopulate the form if it failed validation |
|
290 | + * |
|
291 | + * @return array |
|
292 | + */ |
|
293 | + protected function get_submitted_form_data_from_session() |
|
294 | + { |
|
295 | + $session = EE_Registry::instance()->SSN; |
|
296 | + if ($session instanceof EE_Session) { |
|
297 | + return $session->get_session_data( |
|
298 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
299 | + ); |
|
300 | + } else { |
|
301 | + return array(); |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * flushed the originally submitted input values from the session |
|
309 | + * |
|
310 | + * @return boolean whether or not the data was successfully removed from the session |
|
311 | + */ |
|
312 | + protected function flush_submitted_form_data_from_session() |
|
313 | + { |
|
314 | + return EE_Registry::instance()->SSN->reset_data( |
|
315 | + array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
316 | + ); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * Populates this form and its subsections with data from the session. |
|
323 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
324 | + * validation errors when displaying too) |
|
325 | + * Returns true if the form was populated from the session, false otherwise |
|
326 | + * |
|
327 | + * @return boolean |
|
328 | + */ |
|
329 | + public function populate_from_session() |
|
330 | + { |
|
331 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
332 | + if (empty($form_data_in_session)) { |
|
333 | + return false; |
|
334 | + } |
|
335 | + $this->receive_form_submission($form_data_in_session); |
|
336 | + $this->flush_submitted_form_data_from_session(); |
|
337 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
338 | + return true; |
|
339 | + } else { |
|
340 | + return false; |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * Populates the default data for the form, given an array where keys are |
|
348 | + * the input names, and values are their values (preferably normalized to be their |
|
349 | + * proper PHP types, not all strings... although that should be ok too). |
|
350 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
351 | + * the value being an array formatted in teh same way |
|
352 | + * |
|
353 | + * @param array $default_data |
|
354 | + */ |
|
355 | + public function populate_defaults($default_data) |
|
356 | + { |
|
357 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
358 | + if (isset($default_data[$subsection_name])) { |
|
359 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
360 | + $subsection->set_default($default_data[$subsection_name]); |
|
361 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
362 | + $subsection->populate_defaults($default_data[$subsection_name]); |
|
363 | + } |
|
364 | + } |
|
365 | + } |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * returns true if subsection exists |
|
372 | + * |
|
373 | + * @param string $name |
|
374 | + * @return boolean |
|
375 | + */ |
|
376 | + public function subsection_exists($name) |
|
377 | + { |
|
378 | + return isset($this->_subsections[$name]) ? true : false; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * Gets the subsection specified by its name |
|
385 | + * |
|
386 | + * @param string $name |
|
387 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
388 | + * so that the inputs will be properly configured. |
|
389 | + * However, some client code may be ok |
|
390 | + * with construction finalize being called later |
|
391 | + * (realizing that the subsections' html names |
|
392 | + * might not be set yet, etc.) |
|
393 | + * @return EE_Form_Section_Base |
|
394 | + * @throws \EE_Error |
|
395 | + */ |
|
396 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
397 | + { |
|
398 | + if ($require_construction_to_be_finalized) { |
|
399 | + $this->ensure_construct_finalized_called(); |
|
400 | + } |
|
401 | + return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * Gets all the validatable subsections of this form section |
|
408 | + * |
|
409 | + * @return EE_Form_Section_Validatable[] |
|
410 | + */ |
|
411 | + public function get_validatable_subsections() |
|
412 | + { |
|
413 | + $validatable_subsections = array(); |
|
414 | + foreach ($this->subsections() as $name => $obj) { |
|
415 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
416 | + $validatable_subsections[$name] = $obj; |
|
417 | + } |
|
418 | + } |
|
419 | + return $validatable_subsections; |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
426 | + * throw an EE_Error. |
|
427 | + * |
|
428 | + * @param string $name |
|
429 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
430 | + * leave this as TRUE so that the inputs will be properly |
|
431 | + * configured. However, some client code may be ok with |
|
432 | + * construction finalize being called later |
|
433 | + * (realizing that the subsections' html names might not be |
|
434 | + * set yet, etc.) |
|
435 | + * @return EE_Form_Input_Base |
|
436 | + * @throws EE_Error |
|
437 | + */ |
|
438 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
439 | + { |
|
440 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
441 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
442 | + throw new EE_Error( |
|
443 | + sprintf( |
|
444 | + __( |
|
445 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
446 | + 'event_espresso' |
|
447 | + ), |
|
448 | + $name, |
|
449 | + get_class($this), |
|
450 | + $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
451 | + ) |
|
452 | + ); |
|
453 | + } |
|
454 | + return $subsection; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
461 | + * otherwise throws an EE_Error |
|
462 | + * |
|
463 | + * @param string $name |
|
464 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
465 | + * leave this as TRUE so that the inputs will be properly |
|
466 | + * configured. However, some client code may be ok with |
|
467 | + * construction finalize being called later |
|
468 | + * (realizing that the subsections' html names might not be |
|
469 | + * set yet, etc.) |
|
470 | + * @return EE_Form_Section_Proper |
|
471 | + * @throws EE_Error |
|
472 | + */ |
|
473 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
474 | + { |
|
475 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
476 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
477 | + throw new EE_Error( |
|
478 | + sprintf( |
|
479 | + __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
480 | + $name, |
|
481 | + get_class($this) |
|
482 | + ) |
|
483 | + ); |
|
484 | + } |
|
485 | + return $subsection; |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
492 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
493 | + * |
|
494 | + * @param string $name |
|
495 | + * @return mixed depending on the input's type and its normalization strategy |
|
496 | + * @throws \EE_Error |
|
497 | + */ |
|
498 | + public function get_input_value($name) |
|
499 | + { |
|
500 | + $input = $this->get_input($name); |
|
501 | + return $input->normalized_value(); |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * Checks if this form section itself is valid, and then checks its subsections |
|
508 | + * |
|
509 | + * @throws EE_Error |
|
510 | + * @return boolean |
|
511 | + */ |
|
512 | + public function is_valid() |
|
513 | + { |
|
514 | + if (! $this->has_received_submission()) { |
|
515 | + throw new EE_Error( |
|
516 | + sprintf( |
|
517 | + __( |
|
518 | + "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
519 | + "event_espresso" |
|
520 | + ) |
|
521 | + ) |
|
522 | + ); |
|
523 | + } |
|
524 | + if (! parent::is_valid()) { |
|
525 | + return false; |
|
526 | + } |
|
527 | + // ok so no general errors to this entire form section. |
|
528 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
529 | + $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
530 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
531 | + if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
532 | + if ($set_submission_errors) { |
|
533 | + $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
534 | + } |
|
535 | + return false; |
|
536 | + } |
|
537 | + } |
|
538 | + return true; |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * gets teh default name of this form section if none is specified |
|
545 | + * |
|
546 | + * @return string |
|
547 | + */ |
|
548 | + protected function _set_default_name_if_empty() |
|
549 | + { |
|
550 | + if (! $this->_name) { |
|
551 | + $classname = get_class($this); |
|
552 | + $default_name = str_replace("EE_", "", $classname); |
|
553 | + $this->_name = $default_name; |
|
554 | + } |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
561 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
562 | + * and except for a submit button. Enqueus JS and CSS; if called early enough we will |
|
563 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
564 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
565 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
566 | + * any CSS. |
|
567 | + * |
|
568 | + * @throws \EE_Error |
|
569 | + */ |
|
570 | + public function get_html_and_js() |
|
571 | + { |
|
572 | + $this->enqueue_js(); |
|
573 | + return $this->get_html(); |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
580 | + * |
|
581 | + * @param bool $display_previously_submitted_data |
|
582 | + * @return string |
|
583 | + */ |
|
584 | + public function get_html($display_previously_submitted_data = true) |
|
585 | + { |
|
586 | + $this->ensure_construct_finalized_called(); |
|
587 | + if ($display_previously_submitted_data) { |
|
588 | + $this->populate_from_session(); |
|
589 | + } |
|
590 | + return $this->_form_html_filter |
|
591 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
592 | + : $this->_layout_strategy->layout_form(); |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * enqueues JS and CSS for the form. |
|
599 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
600 | + * scripts and styles can be put in the header, but if called later |
|
601 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
602 | + * only be in the header; but in HTML5 its ok in the body. |
|
603 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
604 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
605 | + * |
|
606 | + * @return string |
|
607 | + * @throws \EE_Error |
|
608 | + */ |
|
609 | + public function enqueue_js() |
|
610 | + { |
|
611 | + $this->_enqueue_and_localize_form_js(); |
|
612 | + foreach ($this->subsections() as $subsection) { |
|
613 | + $subsection->enqueue_js(); |
|
614 | + } |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
621 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
622 | + * the wp_enqueue_scripts hook. |
|
623 | + * However, registering the form js and localizing it can happen when we |
|
624 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
625 | + * could change until it's actually outputted) |
|
626 | + * |
|
627 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
628 | + * to be triggered automatically or not |
|
629 | + * @return void |
|
630 | + */ |
|
631 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
632 | + { |
|
633 | + wp_register_script( |
|
634 | + 'ee_form_section_validation', |
|
635 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
636 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
637 | + EVENT_ESPRESSO_VERSION, |
|
638 | + true |
|
639 | + ); |
|
640 | + wp_localize_script( |
|
641 | + 'ee_form_section_validation', |
|
642 | + 'ee_form_section_validation_init', |
|
643 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
644 | + ); |
|
645 | + } |
|
646 | + |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * gets the variables used by form_section_validation.js. |
|
651 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
652 | + * but before the wordpress hook wp_loaded |
|
653 | + * |
|
654 | + * @throws \EE_Error |
|
655 | + */ |
|
656 | + public function _enqueue_and_localize_form_js() |
|
657 | + { |
|
658 | + $this->ensure_construct_finalized_called(); |
|
659 | + //actually, we don't want to localize just yet. There may be other forms on the page. |
|
660 | + //so we need to add our form section data to a static variable accessible by all form sections |
|
661 | + //and localize it just before the footer |
|
662 | + $this->localize_validation_rules(); |
|
663 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
664 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
665 | + } |
|
666 | + |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * add our form section data to a static variable accessible by all form sections |
|
671 | + * |
|
672 | + * @param bool $return_for_subsection |
|
673 | + * @return void |
|
674 | + * @throws \EE_Error |
|
675 | + */ |
|
676 | + public function localize_validation_rules($return_for_subsection = false) |
|
677 | + { |
|
678 | + // we only want to localize vars ONCE for the entire form, |
|
679 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
680 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
681 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
682 | + 'form_section_id' => $this->html_id(true), |
|
683 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
684 | + 'other_data' => $this->get_other_js_data(), |
|
685 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
686 | + ); |
|
687 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
688 | + } |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
695 | + * This is primarily data added by inputs and forms in addition to any |
|
696 | + * scripts they might enqueue |
|
697 | + * |
|
698 | + * @param array $form_other_js_data |
|
699 | + * @return array |
|
700 | + */ |
|
701 | + public function get_other_js_data($form_other_js_data = array()) |
|
702 | + { |
|
703 | + foreach ($this->subsections() as $subsection) { |
|
704 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
705 | + } |
|
706 | + return $form_other_js_data; |
|
707 | + } |
|
708 | + |
|
709 | + |
|
710 | + |
|
711 | + /** |
|
712 | + * Gets a flat array of inputs for this form section and its subsections. |
|
713 | + * Keys are their form names, and values are the inputs themselves |
|
714 | + * |
|
715 | + * @return EE_Form_Input_Base |
|
716 | + */ |
|
717 | + public function inputs_in_subsections() |
|
718 | + { |
|
719 | + $inputs = array(); |
|
720 | + foreach ($this->subsections() as $subsection) { |
|
721 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
722 | + $inputs[$subsection->html_name()] = $subsection; |
|
723 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
724 | + $inputs += $subsection->inputs_in_subsections(); |
|
725 | + } |
|
726 | + } |
|
727 | + return $inputs; |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + |
|
732 | + /** |
|
733 | + * Gets a flat array of all the validation errors. |
|
734 | + * Keys are html names (because those should be unique) |
|
735 | + * and values are a string of all their validation errors |
|
736 | + * |
|
737 | + * @return string[] |
|
738 | + */ |
|
739 | + public function subsection_validation_errors_by_html_name() |
|
740 | + { |
|
741 | + $inputs = $this->inputs(); |
|
742 | + $errors = array(); |
|
743 | + foreach ($inputs as $form_input) { |
|
744 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
745 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
746 | + } |
|
747 | + } |
|
748 | + return $errors; |
|
749 | + } |
|
750 | + |
|
751 | + |
|
752 | + |
|
753 | + /** |
|
754 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
755 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
756 | + */ |
|
757 | + public static function localize_script_for_all_forms() |
|
758 | + { |
|
759 | + //allow inputs and stuff to hook in their JS and stuff here |
|
760 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
761 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
762 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
763 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
764 | + : 'wp_default'; |
|
765 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
766 | + wp_enqueue_script('ee_form_section_validation'); |
|
767 | + wp_localize_script( |
|
768 | + 'ee_form_section_validation', |
|
769 | + 'ee_form_section_vars', |
|
770 | + EE_Form_Section_Proper::$_js_localization |
|
771 | + ); |
|
772 | + } |
|
773 | + |
|
774 | + |
|
775 | + |
|
776 | + /** |
|
777 | + * ensure_scripts_localized |
|
778 | + */ |
|
779 | + public function ensure_scripts_localized() |
|
780 | + { |
|
781 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
782 | + $this->_enqueue_and_localize_form_js(); |
|
783 | + } |
|
784 | + } |
|
785 | + |
|
786 | + |
|
787 | + |
|
788 | + /** |
|
789 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
790 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
791 | + * |
|
792 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
793 | + */ |
|
794 | + private static function _get_localized_error_messages() |
|
795 | + { |
|
796 | + return array( |
|
797 | + 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
798 | + 'regex' => __('Please check your input', 'event_espresso'), |
|
799 | + ); |
|
800 | + } |
|
801 | + |
|
802 | + |
|
803 | + |
|
804 | + /** |
|
805 | + * @return array |
|
806 | + */ |
|
807 | + public static function js_localization() |
|
808 | + { |
|
809 | + return self::$_js_localization; |
|
810 | + } |
|
811 | + |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * @return array |
|
816 | + */ |
|
817 | + public static function reset_js_localization() |
|
818 | + { |
|
819 | + self::$_js_localization = array(); |
|
820 | + } |
|
821 | + |
|
822 | + |
|
823 | + |
|
824 | + /** |
|
825 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
826 | + * See parent function for more... |
|
827 | + * |
|
828 | + * @return array |
|
829 | + */ |
|
830 | + public function get_jquery_validation_rules() |
|
831 | + { |
|
832 | + $jquery_validation_rules = array(); |
|
833 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
834 | + $jquery_validation_rules = array_merge( |
|
835 | + $jquery_validation_rules, |
|
836 | + $subsection->get_jquery_validation_rules() |
|
837 | + ); |
|
838 | + } |
|
839 | + return $jquery_validation_rules; |
|
840 | + } |
|
841 | + |
|
842 | + |
|
843 | + |
|
844 | + /** |
|
845 | + * Sanitizes all the data and sets the sanitized value of each field |
|
846 | + * |
|
847 | + * @param array $req_data like $_POST |
|
848 | + * @return void |
|
849 | + */ |
|
850 | + protected function _normalize($req_data) |
|
851 | + { |
|
852 | + $this->_received_submission = true; |
|
853 | + $this->_validation_errors = array(); |
|
854 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
855 | + try { |
|
856 | + $subsection->_normalize($req_data); |
|
857 | + } catch (EE_Validation_Error $e) { |
|
858 | + $subsection->add_validation_error($e); |
|
859 | + } |
|
860 | + } |
|
861 | + } |
|
862 | + |
|
863 | + |
|
864 | + |
|
865 | + /** |
|
866 | + * Performs validation on this form section and its subsections. |
|
867 | + * For each subsection, |
|
868 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
869 | + * and passes it the subsection, then calls _validate on that subsection. |
|
870 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
871 | + * you would be best to override this _validate method, |
|
872 | + * calling parent::_validate() first. |
|
873 | + */ |
|
874 | + protected function _validate() |
|
875 | + { |
|
876 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
877 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
878 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
879 | + } |
|
880 | + $subsection->_validate(); |
|
881 | + } |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + |
|
886 | + /** |
|
887 | + * Gets all the validated inputs for the form section |
|
888 | + * |
|
889 | + * @return array |
|
890 | + */ |
|
891 | + public function valid_data() |
|
892 | + { |
|
893 | + $inputs = array(); |
|
894 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
895 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
896 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
897 | + } else if ($subsection instanceof EE_Form_Input_Base) { |
|
898 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
899 | + } |
|
900 | + } |
|
901 | + return $inputs; |
|
902 | + } |
|
903 | + |
|
904 | + |
|
905 | + |
|
906 | + /** |
|
907 | + * Gets all the inputs on this form section |
|
908 | + * |
|
909 | + * @return EE_Form_Input_Base[] |
|
910 | + */ |
|
911 | + public function inputs() |
|
912 | + { |
|
913 | + $inputs = array(); |
|
914 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
915 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
916 | + $inputs[$subsection_name] = $subsection; |
|
917 | + } |
|
918 | + } |
|
919 | + return $inputs; |
|
920 | + } |
|
921 | + |
|
922 | + |
|
923 | + |
|
924 | + /** |
|
925 | + * Gets all the subsections which are a proper form |
|
926 | + * |
|
927 | + * @return EE_Form_Section_Proper[] |
|
928 | + */ |
|
929 | + public function subforms() |
|
930 | + { |
|
931 | + $form_sections = array(); |
|
932 | + foreach ($this->subsections() as $name => $obj) { |
|
933 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
934 | + $form_sections[$name] = $obj; |
|
935 | + } |
|
936 | + } |
|
937 | + return $form_sections; |
|
938 | + } |
|
939 | + |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
944 | + * Consider using inputs() or subforms() |
|
945 | + * if you only want form inputs or proper form sections. |
|
946 | + * |
|
947 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
948 | + * leave this as TRUE so that the inputs will be properly |
|
949 | + * configured. However, some client code may be ok with |
|
950 | + * construction finalize being called later |
|
951 | + * (realizing that the subsections' html names might not be |
|
952 | + * set yet, etc.) |
|
953 | + * @return EE_Form_Section_Proper[] |
|
954 | + */ |
|
955 | + public function subsections($require_construction_to_be_finalized = true) |
|
956 | + { |
|
957 | + if ($require_construction_to_be_finalized) { |
|
958 | + $this->ensure_construct_finalized_called(); |
|
959 | + } |
|
960 | + return $this->_subsections; |
|
961 | + } |
|
962 | + |
|
963 | + |
|
964 | + |
|
965 | + /** |
|
966 | + * Returns a simple array where keys are input names, and values are their normalized |
|
967 | + * values. (Similar to calling get_input_value on inputs) |
|
968 | + * |
|
969 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
970 | + * or just this forms' direct children inputs |
|
971 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
972 | + * or allow multidimensional array |
|
973 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
974 | + * with array keys being input names |
|
975 | + * (regardless of whether they are from a subsection or not), |
|
976 | + * and if $flatten is FALSE it can be a multidimensional array |
|
977 | + * where keys are always subsection names and values are either |
|
978 | + * the input's normalized value, or an array like the top-level array |
|
979 | + */ |
|
980 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
981 | + { |
|
982 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
983 | + } |
|
984 | + |
|
985 | + |
|
986 | + |
|
987 | + /** |
|
988 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
989 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
990 | + * is not necessarily the value we want to display to users. This creates an array |
|
991 | + * where keys are the input names, and values are their display values |
|
992 | + * |
|
993 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
994 | + * or just this forms' direct children inputs |
|
995 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
996 | + * or allow multidimensional array |
|
997 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
998 | + * with array keys being input names |
|
999 | + * (regardless of whether they are from a subsection or not), |
|
1000 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1001 | + * where keys are always subsection names and values are either |
|
1002 | + * the input's normalized value, or an array like the top-level array |
|
1003 | + */ |
|
1004 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1005 | + { |
|
1006 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1007 | + } |
|
1008 | + |
|
1009 | + |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * Gets the input values from the form |
|
1013 | + * |
|
1014 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
1015 | + * or just the normalized value |
|
1016 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1017 | + * or just this forms' direct children inputs |
|
1018 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1019 | + * or allow multidimensional array |
|
1020 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1021 | + * input names (regardless of whether they are from a subsection or not), |
|
1022 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1023 | + * where keys are always subsection names and values are either |
|
1024 | + * the input's normalized value, or an array like the top-level array |
|
1025 | + */ |
|
1026 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1027 | + { |
|
1028 | + $input_values = array(); |
|
1029 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1030 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1031 | + $input_values[$subsection_name] = $pretty |
|
1032 | + ? $subsection->pretty_value() |
|
1033 | + : $subsection->normalized_value(); |
|
1034 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1035 | + $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
1036 | + if ($flatten) { |
|
1037 | + $input_values = array_merge($input_values, $subform_input_values); |
|
1038 | + } else { |
|
1039 | + $input_values[$subsection_name] = $subform_input_values; |
|
1040 | + } |
|
1041 | + } |
|
1042 | + } |
|
1043 | + return $input_values; |
|
1044 | + } |
|
1045 | + |
|
1046 | + |
|
1047 | + |
|
1048 | + /** |
|
1049 | + * Gets the originally submitted input values from the form |
|
1050 | + * |
|
1051 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1052 | + * or just this forms' direct children inputs |
|
1053 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1054 | + * with array keys being input names |
|
1055 | + * (regardless of whether they are from a subsection or not), |
|
1056 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1057 | + * where keys are always subsection names and values are either |
|
1058 | + * the input's normalized value, or an array like the top-level array |
|
1059 | + */ |
|
1060 | + public function submitted_values($include_subforms = false) |
|
1061 | + { |
|
1062 | + $submitted_values = array(); |
|
1063 | + foreach ($this->subsections() as $subsection) { |
|
1064 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1065 | + // is this input part of an array of inputs? |
|
1066 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
1067 | + $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
1068 | + explode('[', str_replace(']', '', $subsection->html_name())), |
|
1069 | + $subsection->raw_value() |
|
1070 | + ); |
|
1071 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1072 | + } else { |
|
1073 | + $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
1074 | + } |
|
1075 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1076 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1077 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1078 | + } |
|
1079 | + } |
|
1080 | + return $submitted_values; |
|
1081 | + } |
|
1082 | + |
|
1083 | + |
|
1084 | + |
|
1085 | + /** |
|
1086 | + * Indicates whether or not this form has received a submission yet |
|
1087 | + * (ie, had receive_form_submission called on it yet) |
|
1088 | + * |
|
1089 | + * @return boolean |
|
1090 | + * @throws \EE_Error |
|
1091 | + */ |
|
1092 | + public function has_received_submission() |
|
1093 | + { |
|
1094 | + $this->ensure_construct_finalized_called(); |
|
1095 | + return $this->_received_submission; |
|
1096 | + } |
|
1097 | + |
|
1098 | + |
|
1099 | + |
|
1100 | + /** |
|
1101 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
1102 | + * Removes the listed inputs from the form |
|
1103 | + * |
|
1104 | + * @param array $inputs_to_exclude values are the input names |
|
1105 | + * @return void |
|
1106 | + */ |
|
1107 | + public function exclude(array $inputs_to_exclude = array()) |
|
1108 | + { |
|
1109 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1110 | + unset($this->_subsections[$input_to_exclude_name]); |
|
1111 | + } |
|
1112 | + } |
|
1113 | + |
|
1114 | + |
|
1115 | + |
|
1116 | + /** |
|
1117 | + * @param array $inputs_to_hide |
|
1118 | + * @throws \EE_Error |
|
1119 | + */ |
|
1120 | + public function hide(array $inputs_to_hide = array()) |
|
1121 | + { |
|
1122 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
1123 | + $input = $this->get_input($input_to_hide); |
|
1124 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1125 | + } |
|
1126 | + } |
|
1127 | + |
|
1128 | + |
|
1129 | + |
|
1130 | + /** |
|
1131 | + * add_subsections |
|
1132 | + * Adds the listed subsections to the form section. |
|
1133 | + * If $subsection_name_to_target is provided, |
|
1134 | + * then new subsections are added before or after that subsection, |
|
1135 | + * otherwise to the start or end of the entire subsections array. |
|
1136 | + * |
|
1137 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1138 | + * where keys are their names |
|
1139 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1140 | + * should be added before or after |
|
1141 | + * IF $subsection_name_to_target is null, |
|
1142 | + * then $new_subsections will be added to |
|
1143 | + * the beginning or end of the entire subsections array |
|
1144 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
1145 | + * $subsection_name_to_target, |
|
1146 | + * or if $subsection_name_to_target is null, |
|
1147 | + * before or after entire subsections array |
|
1148 | + * @return void |
|
1149 | + * @throws \EE_Error |
|
1150 | + */ |
|
1151 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1152 | + { |
|
1153 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
1154 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
1155 | + EE_Error::add_error( |
|
1156 | + sprintf( |
|
1157 | + __( |
|
1158 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1159 | + "event_espresso" |
|
1160 | + ), |
|
1161 | + get_class($subsection), |
|
1162 | + $subsection_name, |
|
1163 | + $this->name() |
|
1164 | + ) |
|
1165 | + ); |
|
1166 | + unset($new_subsections[$subsection_name]); |
|
1167 | + } |
|
1168 | + } |
|
1169 | + $this->_subsections = EEH_Array::insert_into_array( |
|
1170 | + $this->_subsections, |
|
1171 | + $new_subsections, |
|
1172 | + $subsection_name_to_target, |
|
1173 | + $add_before |
|
1174 | + ); |
|
1175 | + if ($this->_construction_finalized) { |
|
1176 | + foreach ($this->_subsections as $name => $subsection) { |
|
1177 | + $subsection->_construct_finalize($this, $name); |
|
1178 | + } |
|
1179 | + } |
|
1180 | + } |
|
1181 | + |
|
1182 | + |
|
1183 | + |
|
1184 | + /** |
|
1185 | + * Just gets all validatable subsections to clean their sensitive data |
|
1186 | + */ |
|
1187 | + public function clean_sensitive_data() |
|
1188 | + { |
|
1189 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1190 | + $subsection->clean_sensitive_data(); |
|
1191 | + } |
|
1192 | + } |
|
1193 | + |
|
1194 | + |
|
1195 | + |
|
1196 | + /** |
|
1197 | + * @param string $form_submission_error_message |
|
1198 | + */ |
|
1199 | + public function set_submission_error_message($form_submission_error_message = '') |
|
1200 | + { |
|
1201 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
1202 | + ? $form_submission_error_message |
|
1203 | + : __('Form submission failed due to errors', 'event_espresso'); |
|
1204 | + } |
|
1205 | + |
|
1206 | + |
|
1207 | + |
|
1208 | + /** |
|
1209 | + * @return string |
|
1210 | + */ |
|
1211 | + public function submission_error_message() |
|
1212 | + { |
|
1213 | + return $this->_form_submission_error_message; |
|
1214 | + } |
|
1215 | + |
|
1216 | + |
|
1217 | + |
|
1218 | + /** |
|
1219 | + * @param string $form_submission_success_message |
|
1220 | + */ |
|
1221 | + public function set_submission_success_message($form_submission_success_message) |
|
1222 | + { |
|
1223 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
1224 | + ? $form_submission_success_message |
|
1225 | + : __('Form submitted successfully', 'event_espresso'); |
|
1226 | + } |
|
1227 | + |
|
1228 | + |
|
1229 | + |
|
1230 | + /** |
|
1231 | + * @return string |
|
1232 | + */ |
|
1233 | + public function submission_success_message() |
|
1234 | + { |
|
1235 | + return $this->_form_submission_success_message; |
|
1236 | + } |
|
1237 | + |
|
1238 | + |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * Returns the prefix that should be used on child of this form section for |
|
1242 | + * their html names. If this form section itself has a parent, prepends ITS |
|
1243 | + * prefix onto this form section's prefix. Used primarily by |
|
1244 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1245 | + * |
|
1246 | + * @return string |
|
1247 | + * @throws \EE_Error |
|
1248 | + */ |
|
1249 | + public function html_name_prefix() |
|
1250 | + { |
|
1251 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1252 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1253 | + } else { |
|
1254 | + return $this->name(); |
|
1255 | + } |
|
1256 | + } |
|
1257 | + |
|
1258 | + |
|
1259 | + |
|
1260 | + /** |
|
1261 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1262 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
1263 | + * was set, which is probably nothing, or the classname) |
|
1264 | + * |
|
1265 | + * @return string |
|
1266 | + * @throws \EE_Error |
|
1267 | + */ |
|
1268 | + public function name() |
|
1269 | + { |
|
1270 | + $this->ensure_construct_finalized_called(); |
|
1271 | + return parent::name(); |
|
1272 | + } |
|
1273 | + |
|
1274 | + |
|
1275 | + |
|
1276 | + /** |
|
1277 | + * @return EE_Form_Section_Proper |
|
1278 | + * @throws \EE_Error |
|
1279 | + */ |
|
1280 | + public function parent_section() |
|
1281 | + { |
|
1282 | + $this->ensure_construct_finalized_called(); |
|
1283 | + return parent::parent_section(); |
|
1284 | + } |
|
1285 | + |
|
1286 | + |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * make sure construction finalized was called, otherwise children might not be ready |
|
1290 | + * |
|
1291 | + * @return void |
|
1292 | + * @throws \EE_Error |
|
1293 | + */ |
|
1294 | + public function ensure_construct_finalized_called() |
|
1295 | + { |
|
1296 | + if (! $this->_construction_finalized) { |
|
1297 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1298 | + } |
|
1299 | + } |
|
1300 | + |
|
1301 | + |
|
1302 | + |
|
1303 | + /** |
|
1304 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1305 | + * are in teh form data. If any are found, returns true. Else false |
|
1306 | + * |
|
1307 | + * @param array $req_data |
|
1308 | + * @return boolean |
|
1309 | + */ |
|
1310 | + public function form_data_present_in($req_data = null) |
|
1311 | + { |
|
1312 | + if ($req_data === null) { |
|
1313 | + $req_data = $_POST; |
|
1314 | + } |
|
1315 | + foreach ($this->subsections() as $subsection) { |
|
1316 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1317 | + if ($subsection->form_data_present_in($req_data)) { |
|
1318 | + return true; |
|
1319 | + } |
|
1320 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1321 | + if ($subsection->form_data_present_in($req_data)) { |
|
1322 | + return true; |
|
1323 | + } |
|
1324 | + } |
|
1325 | + } |
|
1326 | + return false; |
|
1327 | + } |
|
1328 | + |
|
1329 | + |
|
1330 | + |
|
1331 | + /** |
|
1332 | + * Gets validation errors for this form section and subsections |
|
1333 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1334 | + * gets the validation errors for ALL subsection |
|
1335 | + * |
|
1336 | + * @return EE_Validation_Error[] |
|
1337 | + */ |
|
1338 | + public function get_validation_errors_accumulated() |
|
1339 | + { |
|
1340 | + $validation_errors = $this->get_validation_errors(); |
|
1341 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1342 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
1343 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1344 | + } else { |
|
1345 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1346 | + } |
|
1347 | + if ($validation_errors_on_this_subsection) { |
|
1348 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1349 | + } |
|
1350 | + } |
|
1351 | + return $validation_errors; |
|
1352 | + } |
|
1353 | + |
|
1354 | + |
|
1355 | + |
|
1356 | + /** |
|
1357 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
1358 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1359 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
1360 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1361 | + * which will be returned. |
|
1362 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1363 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1364 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1365 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1366 | + * Etc |
|
1367 | + * |
|
1368 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1369 | + * @return EE_Form_Section_Base |
|
1370 | + */ |
|
1371 | + public function find_section_from_path($form_section_path) |
|
1372 | + { |
|
1373 | + //check if we can find the input from purely going straight up the tree |
|
1374 | + $input = parent::find_section_from_path($form_section_path); |
|
1375 | + if ($input instanceof EE_Form_Section_Base) { |
|
1376 | + return $input; |
|
1377 | + } |
|
1378 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
1379 | + if ($next_slash_pos !== false) { |
|
1380 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1381 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1382 | + } else { |
|
1383 | + $child_section_name = $form_section_path; |
|
1384 | + $subpath = ''; |
|
1385 | + } |
|
1386 | + $child_section = $this->get_subsection($child_section_name); |
|
1387 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
1388 | + return $child_section->find_section_from_path($subpath); |
|
1389 | + } else { |
|
1390 | + return null; |
|
1391 | + } |
|
1392 | + } |
|
1393 | 1393 | |
1394 | 1394 | } |
1395 | 1395 |