@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | <ul class="wp-people-group" id="ee-people-group-owners"> |
4 | 4 | <li class="wp-person" id="ee-person-sshoultes"> |
5 | 5 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
6 | - <?php echo esp_gravatar_image( '[email protected]', 'Seth Shoultes' ); ?> |
|
6 | + <?php echo esp_gravatar_image('[email protected]', 'Seth Shoultes'); ?> |
|
7 | 7 | </a> |
8 | 8 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
9 | 9 | Seth Shoultes |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | </li> |
13 | 13 | <li class="wp-person" id="ee-person-gkoyle"> |
14 | 14 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
15 | - <?php echo esp_gravatar_image( '[email protected]', 'Garth Koyle' ); ?> |
|
15 | + <?php echo esp_gravatar_image('[email protected]', 'Garth Koyle'); ?> |
|
16 | 16 | </a> |
17 | 17 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
18 | 18 | Garth Koyle |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | <ul class="wp-people-group" id="ee-people-group-core-developers"> |
25 | 25 | <li class="wp-person" id="ee-person-bchristensen"> |
26 | 26 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
27 | - <?php echo esp_gravatar_image( '[email protected]', 'Brent Christensen' ); ?> |
|
27 | + <?php echo esp_gravatar_image('[email protected]', 'Brent Christensen'); ?> |
|
28 | 28 | </a> |
29 | 29 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
30 | 30 | Brent Christensen |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | </li> |
34 | 34 | <li class="wp-person" id="ee-person-dethier"> |
35 | 35 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
36 | - <?php echo esp_gravatar_image( '[email protected]', 'Darren Ethier' ); ?> |
|
36 | + <?php echo esp_gravatar_image('[email protected]', 'Darren Ethier'); ?> |
|
37 | 37 | </a> |
38 | 38 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
39 | 39 | Darren Ethier |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | </li> |
43 | 43 | <li class="wp-person" id="ee-person-mnelson"> |
44 | 44 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
45 | - <?php echo esp_gravatar_image( '[email protected]', 'Michael Nelson' ); ?> |
|
45 | + <?php echo esp_gravatar_image('[email protected]', 'Michael Nelson'); ?> |
|
46 | 46 | </a> |
47 | 47 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
48 | 48 | Michael Nelson |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | </li> |
52 | 52 | <li class="wp-person" id="ee-person-nkolivoshka"> |
53 | 53 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
54 | - <?php echo esp_gravatar_image( '[email protected]', 'Nazar Kolivoshka' ); ?> |
|
54 | + <?php echo esp_gravatar_image('[email protected]', 'Nazar Kolivoshka'); ?> |
|
55 | 55 | </a> |
56 | 56 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
57 | 57 | Nazar Kolivoshka |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | <ul class="wp-people-group" id="ee-people-group-support-staff"> |
64 | 64 | <li class="wp-person" id="ee-person-jfeck"> |
65 | 65 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
66 | - <?php echo esp_gravatar_image( '[email protected]', 'Josh Feck' ); ?> |
|
66 | + <?php echo esp_gravatar_image('[email protected]', 'Josh Feck'); ?> |
|
67 | 67 | </a> |
68 | 68 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
69 | 69 | Josh Feck |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | </li> |
72 | 72 | <li class="wp-person" id="ee-person-twarwick"> |
73 | 73 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
74 | - <?php echo esp_gravatar_image( '[email protected]', 'Tony Warwick' ); ?> |
|
74 | + <?php echo esp_gravatar_image('[email protected]', 'Tony Warwick'); ?> |
|
75 | 75 | </a> |
76 | 76 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
77 | 77 | Tony Warwick |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | </li> |
80 | 80 | <li class="wp-person" id="ee-person-lcaum"> |
81 | 81 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
82 | - <?php echo esp_gravatar_image( '[email protected]', 'Lorenzo Caum' ); ?> |
|
82 | + <?php echo esp_gravatar_image('[email protected]', 'Lorenzo Caum'); ?> |
|
83 | 83 | </a> |
84 | 84 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
85 | 85 | Lorenzo Caum |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | </ul> |
90 | 90 | <h3 class="wp-people-group"><?php _e('Contributor Recognition', 'event_espresso'); ?></h3> |
91 | 91 | <p class="description"> |
92 | - <?php printf( __('For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.', 'event_espresso'), '<a href="https://github.com/eventespresso/event-espresso-core" title="Contribute to Event Espresso by making a pull request via GitHub">', '</a>' ); ?> |
|
92 | + <?php printf(__('For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.', 'event_espresso'), '<a href="https://github.com/eventespresso/event-espresso-core" title="Contribute to Event Espresso by making a pull request via GitHub">', '</a>'); ?> |
|
93 | 93 | </p> |
94 | 94 | <p class="wp-credits-list"> |
95 | 95 | <ul> |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | </p> |
104 | 104 | <h3 class="wp-people-group"><?php _e('External Libraries', 'event_espresso'); ?></h3> |
105 | 105 | <p class="description"> |
106 | - <?php printf( __('Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:', 'event_espresso'), '<a href="credits.php">', '</a>' ); ?> |
|
106 | + <?php printf(__('Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:', 'event_espresso'), '<a href="credits.php">', '</a>'); ?> |
|
107 | 107 | </p> |
108 | 108 | <p class="wp-credits-list"> |
109 | 109 | <a href="http://josscrowcroft.github.io/accounting.js/"><?php _e('accounting.js', 'event_espresso'); ?></a>, |
@@ -119,10 +119,10 @@ discard block |
||
119 | 119 | |
120 | 120 | <?php |
121 | 121 | function esp_gravatar_profile($email) { |
122 | - echo 'http://www.gravatar.com/' . md5($email); |
|
122 | + echo 'http://www.gravatar.com/'.md5($email); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | function esp_gravatar_image($email, $name) { |
126 | - echo '<img src="http://0.gravatar.com/avatar/' . md5($email) . '?s=60" class="gravatar" alt="' . $name . '"/>'; |
|
126 | + echo '<img src="http://0.gravatar.com/avatar/'.md5($email).'?s=60" class="gravatar" alt="'.$name.'"/>'; |
|
127 | 127 | } |
128 | 128 | ?> |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\interfaces\ResettableInterface; |
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 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
8 | 8 | |
@@ -23,421 +23,421 @@ discard block |
||
23 | 23 | class EE_Cart implements ResettableInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * instance of the EE_Cart object |
|
28 | - * |
|
29 | - * @access private |
|
30 | - * @var EE_Cart $_instance |
|
31 | - */ |
|
32 | - private static $_instance; |
|
33 | - |
|
34 | - /** |
|
35 | - * instance of the EE_Session object |
|
36 | - * |
|
37 | - * @access protected |
|
38 | - * @var EE_Session $_session |
|
39 | - */ |
|
40 | - protected $_session; |
|
41 | - |
|
42 | - /** |
|
43 | - * The total Line item which comprises all the children line-item subtotals, |
|
44 | - * which in turn each have their line items. |
|
45 | - * Typically, the line item structure will look like: |
|
46 | - * grand total |
|
47 | - * -tickets-sub-total |
|
48 | - * --ticket1 |
|
49 | - * --ticket2 |
|
50 | - * --... |
|
51 | - * -taxes-sub-total |
|
52 | - * --tax1 |
|
53 | - * --tax2 |
|
54 | - * |
|
55 | - * @var EE_Line_Item |
|
56 | - */ |
|
57 | - private $_grand_total; |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @singleton method used to instantiate class object |
|
63 | - * @access public |
|
64 | - * @param EE_Line_Item $grand_total |
|
65 | - * @param EE_Session $session |
|
66 | - * @return \EE_Cart |
|
67 | - * @throws \EE_Error |
|
68 | - */ |
|
69 | - public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
70 | - { |
|
71 | - if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
72 | - self::$_instance = new self($grand_total, $session); |
|
73 | - } |
|
74 | - // or maybe retrieve an existing one ? |
|
75 | - if ( ! self::$_instance instanceof EE_Cart) { |
|
76 | - // try getting the cart out of the session |
|
77 | - $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
78 | - self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
79 | - unset($saved_cart); |
|
80 | - } |
|
81 | - // verify that cart is ok and grand total line item exists |
|
82 | - if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
83 | - self::$_instance = new self($grand_total, $session); |
|
84 | - } |
|
85 | - self::$_instance->get_grand_total(); |
|
86 | - // once everything is all said and done, save the cart to the EE_Session |
|
87 | - add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
88 | - return self::$_instance; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * private constructor to prevent direct creation |
|
95 | - * |
|
96 | - * @Constructor |
|
97 | - * @access private |
|
98 | - * @param EE_Line_Item $grand_total |
|
99 | - * @param EE_Session $session |
|
100 | - */ |
|
101 | - private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
102 | - { |
|
103 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
104 | - $this->set_session($session); |
|
105 | - if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
106 | - $this->set_grand_total_line_item($grand_total); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Resets the cart completely (whereas empty_cart |
|
114 | - * |
|
115 | - * @param EE_Line_Item $grand_total |
|
116 | - * @param EE_Session $session |
|
117 | - * @return EE_Cart |
|
118 | - * @throws \EE_Error |
|
119 | - */ |
|
120 | - public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
121 | - { |
|
122 | - remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
123 | - if ($session instanceof EE_Session) { |
|
124 | - $session->reset_cart(); |
|
125 | - } |
|
126 | - self::$_instance = null; |
|
127 | - return self::instance($grand_total, $session); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return \EE_Session |
|
134 | - */ |
|
135 | - public function session() |
|
136 | - { |
|
137 | - if ( ! $this->_session instanceof EE_Session) { |
|
138 | - $this->set_session(); |
|
139 | - } |
|
140 | - return $this->_session; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param EE_Session $session |
|
147 | - */ |
|
148 | - public function set_session(EE_Session $session = null) |
|
149 | - { |
|
150 | - $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
157 | - * know the grand total line item on it |
|
158 | - * |
|
159 | - * @param EE_Line_Item $line_item |
|
160 | - */ |
|
161 | - public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
162 | - { |
|
163 | - $this->_grand_total = $line_item; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * get_cart_from_reg_url_link |
|
170 | - * |
|
171 | - * @access public |
|
172 | - * @param EE_Transaction $transaction |
|
173 | - * @param EE_Session $session |
|
174 | - * @return \EE_Cart |
|
175 | - * @throws \EE_Error |
|
176 | - */ |
|
177 | - public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
178 | - { |
|
179 | - $grand_total = $transaction->total_line_item(); |
|
180 | - $grand_total->get_items(); |
|
181 | - $grand_total->tax_descendants(); |
|
182 | - return EE_Cart::instance($grand_total, $session); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
189 | - * |
|
190 | - * @return EE_Line_Item |
|
191 | - * @throws \EE_Error |
|
192 | - */ |
|
193 | - private function _create_grand_total() |
|
194 | - { |
|
195 | - $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
196 | - return $this->_grand_total; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Gets all the line items of object type Ticket |
|
203 | - * |
|
204 | - * @access public |
|
205 | - * @return \EE_Line_Item[] |
|
206 | - */ |
|
207 | - public function get_tickets() |
|
208 | - { |
|
209 | - if ($this->_grand_total === null ) { |
|
210 | - return array(); |
|
211 | - } |
|
212 | - return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * returns the total quantity of tickets in the cart |
|
219 | - * |
|
220 | - * @access public |
|
221 | - * @return int |
|
222 | - * @throws \EE_Error |
|
223 | - */ |
|
224 | - public function all_ticket_quantity_count() |
|
225 | - { |
|
226 | - $tickets = $this->get_tickets(); |
|
227 | - if (empty($tickets)) { |
|
228 | - return 0; |
|
229 | - } |
|
230 | - $count = 0; |
|
231 | - foreach ($tickets as $ticket) { |
|
232 | - $count += $ticket->get('LIN_quantity'); |
|
233 | - } |
|
234 | - return $count; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Gets all the tax line items |
|
241 | - * |
|
242 | - * @return \EE_Line_Item[] |
|
243 | - * @throws \EE_Error |
|
244 | - */ |
|
245 | - public function get_taxes() |
|
246 | - { |
|
247 | - return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Gets the total line item (which is a parent of all other line items) on this cart |
|
254 | - * |
|
255 | - * @return EE_Line_Item |
|
256 | - * @throws \EE_Error |
|
257 | - */ |
|
258 | - public function get_grand_total() |
|
259 | - { |
|
260 | - return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @process items for adding to cart |
|
267 | - * @access public |
|
268 | - * @param EE_Ticket $ticket |
|
269 | - * @param int $qty |
|
270 | - * @return TRUE on success, FALSE on fail |
|
271 | - * @throws \EE_Error |
|
272 | - */ |
|
273 | - public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
274 | - { |
|
275 | - EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
276 | - return $this->save_cart() ? true : false; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * get_cart_total_before_tax |
|
283 | - * |
|
284 | - * @access public |
|
285 | - * @return float |
|
286 | - * @throws \EE_Error |
|
287 | - */ |
|
288 | - public function get_cart_total_before_tax() |
|
289 | - { |
|
290 | - return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * gets the total amount of tax paid for items in this cart |
|
297 | - * |
|
298 | - * @access public |
|
299 | - * @return float |
|
300 | - * @throws \EE_Error |
|
301 | - */ |
|
302 | - public function get_applied_taxes() |
|
303 | - { |
|
304 | - return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
311 | - * |
|
312 | - * @access public |
|
313 | - * @return float |
|
314 | - * @throws \EE_Error |
|
315 | - */ |
|
316 | - public function get_cart_grand_total() |
|
317 | - { |
|
318 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
319 | - return $this->get_grand_total()->total(); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
326 | - * |
|
327 | - * @access public |
|
328 | - * @return float |
|
329 | - * @throws \EE_Error |
|
330 | - */ |
|
331 | - public function recalculate_all_cart_totals() |
|
332 | - { |
|
333 | - $pre_tax_total = $this->get_cart_total_before_tax(); |
|
334 | - $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
335 | - $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
336 | - $this->_grand_total->save_this_and_descendants_to_txn(); |
|
337 | - return $this->get_grand_total()->total(); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * deletes an item from the cart |
|
344 | - * |
|
345 | - * @access public |
|
346 | - * @param array|bool|string $line_item_codes |
|
347 | - * @return int on success, FALSE on fail |
|
348 | - * @throws \EE_Error |
|
349 | - */ |
|
350 | - public function delete_items($line_item_codes = false) |
|
351 | - { |
|
352 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
353 | - return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * @remove ALL items from cart and zero ALL totals |
|
360 | - * @access public |
|
361 | - * @return bool |
|
362 | - * @throws \EE_Error |
|
363 | - */ |
|
364 | - public function empty_cart() |
|
365 | - { |
|
366 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
367 | - $this->_grand_total = $this->_create_grand_total(); |
|
368 | - return $this->save_cart(true); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * @remove ALL items from cart and delete total as well |
|
375 | - * @access public |
|
376 | - * @return bool |
|
377 | - * @throws \EE_Error |
|
378 | - */ |
|
379 | - public function delete_cart() |
|
380 | - { |
|
381 | - if ($this->_grand_total instanceof EE_Line_Item) { |
|
382 | - $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
383 | - if ($deleted) { |
|
384 | - $deleted += $this->_grand_total->delete(); |
|
385 | - $this->_grand_total = null; |
|
386 | - return true; |
|
387 | - } |
|
388 | - } |
|
389 | - return false; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * @save cart to session |
|
396 | - * @access public |
|
397 | - * @param bool $apply_taxes |
|
398 | - * @return TRUE on success, FALSE on fail |
|
399 | - * @throws \EE_Error |
|
400 | - */ |
|
401 | - public function save_cart($apply_taxes = true) |
|
402 | - { |
|
403 | - if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
404 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
405 | - //make sure we don't cache the transaction because it can get stale |
|
406 | - if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
407 | - && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
408 | - ) { |
|
409 | - $this->_grand_total->clear_cache('Transaction', null, true); |
|
410 | - } |
|
411 | - } |
|
412 | - if ($this->session() instanceof EE_Session) { |
|
413 | - return $this->session()->set_cart($this); |
|
414 | - } else { |
|
415 | - return false; |
|
416 | - } |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - |
|
421 | - public function __wakeup() |
|
422 | - { |
|
423 | - if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
424 | - // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
425 | - $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
426 | - } |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * @return array |
|
433 | - */ |
|
434 | - public function __sleep() |
|
435 | - { |
|
436 | - if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
437 | - $this->_grand_total = $this->_grand_total->ID(); |
|
438 | - } |
|
439 | - return array('_grand_total'); |
|
440 | - } |
|
26 | + /** |
|
27 | + * instance of the EE_Cart object |
|
28 | + * |
|
29 | + * @access private |
|
30 | + * @var EE_Cart $_instance |
|
31 | + */ |
|
32 | + private static $_instance; |
|
33 | + |
|
34 | + /** |
|
35 | + * instance of the EE_Session object |
|
36 | + * |
|
37 | + * @access protected |
|
38 | + * @var EE_Session $_session |
|
39 | + */ |
|
40 | + protected $_session; |
|
41 | + |
|
42 | + /** |
|
43 | + * The total Line item which comprises all the children line-item subtotals, |
|
44 | + * which in turn each have their line items. |
|
45 | + * Typically, the line item structure will look like: |
|
46 | + * grand total |
|
47 | + * -tickets-sub-total |
|
48 | + * --ticket1 |
|
49 | + * --ticket2 |
|
50 | + * --... |
|
51 | + * -taxes-sub-total |
|
52 | + * --tax1 |
|
53 | + * --tax2 |
|
54 | + * |
|
55 | + * @var EE_Line_Item |
|
56 | + */ |
|
57 | + private $_grand_total; |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @singleton method used to instantiate class object |
|
63 | + * @access public |
|
64 | + * @param EE_Line_Item $grand_total |
|
65 | + * @param EE_Session $session |
|
66 | + * @return \EE_Cart |
|
67 | + * @throws \EE_Error |
|
68 | + */ |
|
69 | + public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
70 | + { |
|
71 | + if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
72 | + self::$_instance = new self($grand_total, $session); |
|
73 | + } |
|
74 | + // or maybe retrieve an existing one ? |
|
75 | + if ( ! self::$_instance instanceof EE_Cart) { |
|
76 | + // try getting the cart out of the session |
|
77 | + $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
78 | + self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
79 | + unset($saved_cart); |
|
80 | + } |
|
81 | + // verify that cart is ok and grand total line item exists |
|
82 | + if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
83 | + self::$_instance = new self($grand_total, $session); |
|
84 | + } |
|
85 | + self::$_instance->get_grand_total(); |
|
86 | + // once everything is all said and done, save the cart to the EE_Session |
|
87 | + add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
88 | + return self::$_instance; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * private constructor to prevent direct creation |
|
95 | + * |
|
96 | + * @Constructor |
|
97 | + * @access private |
|
98 | + * @param EE_Line_Item $grand_total |
|
99 | + * @param EE_Session $session |
|
100 | + */ |
|
101 | + private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
102 | + { |
|
103 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
104 | + $this->set_session($session); |
|
105 | + if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
106 | + $this->set_grand_total_line_item($grand_total); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Resets the cart completely (whereas empty_cart |
|
114 | + * |
|
115 | + * @param EE_Line_Item $grand_total |
|
116 | + * @param EE_Session $session |
|
117 | + * @return EE_Cart |
|
118 | + * @throws \EE_Error |
|
119 | + */ |
|
120 | + public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
121 | + { |
|
122 | + remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
123 | + if ($session instanceof EE_Session) { |
|
124 | + $session->reset_cart(); |
|
125 | + } |
|
126 | + self::$_instance = null; |
|
127 | + return self::instance($grand_total, $session); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return \EE_Session |
|
134 | + */ |
|
135 | + public function session() |
|
136 | + { |
|
137 | + if ( ! $this->_session instanceof EE_Session) { |
|
138 | + $this->set_session(); |
|
139 | + } |
|
140 | + return $this->_session; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param EE_Session $session |
|
147 | + */ |
|
148 | + public function set_session(EE_Session $session = null) |
|
149 | + { |
|
150 | + $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
157 | + * know the grand total line item on it |
|
158 | + * |
|
159 | + * @param EE_Line_Item $line_item |
|
160 | + */ |
|
161 | + public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
162 | + { |
|
163 | + $this->_grand_total = $line_item; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * get_cart_from_reg_url_link |
|
170 | + * |
|
171 | + * @access public |
|
172 | + * @param EE_Transaction $transaction |
|
173 | + * @param EE_Session $session |
|
174 | + * @return \EE_Cart |
|
175 | + * @throws \EE_Error |
|
176 | + */ |
|
177 | + public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
178 | + { |
|
179 | + $grand_total = $transaction->total_line_item(); |
|
180 | + $grand_total->get_items(); |
|
181 | + $grand_total->tax_descendants(); |
|
182 | + return EE_Cart::instance($grand_total, $session); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
189 | + * |
|
190 | + * @return EE_Line_Item |
|
191 | + * @throws \EE_Error |
|
192 | + */ |
|
193 | + private function _create_grand_total() |
|
194 | + { |
|
195 | + $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
196 | + return $this->_grand_total; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Gets all the line items of object type Ticket |
|
203 | + * |
|
204 | + * @access public |
|
205 | + * @return \EE_Line_Item[] |
|
206 | + */ |
|
207 | + public function get_tickets() |
|
208 | + { |
|
209 | + if ($this->_grand_total === null ) { |
|
210 | + return array(); |
|
211 | + } |
|
212 | + return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * returns the total quantity of tickets in the cart |
|
219 | + * |
|
220 | + * @access public |
|
221 | + * @return int |
|
222 | + * @throws \EE_Error |
|
223 | + */ |
|
224 | + public function all_ticket_quantity_count() |
|
225 | + { |
|
226 | + $tickets = $this->get_tickets(); |
|
227 | + if (empty($tickets)) { |
|
228 | + return 0; |
|
229 | + } |
|
230 | + $count = 0; |
|
231 | + foreach ($tickets as $ticket) { |
|
232 | + $count += $ticket->get('LIN_quantity'); |
|
233 | + } |
|
234 | + return $count; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Gets all the tax line items |
|
241 | + * |
|
242 | + * @return \EE_Line_Item[] |
|
243 | + * @throws \EE_Error |
|
244 | + */ |
|
245 | + public function get_taxes() |
|
246 | + { |
|
247 | + return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Gets the total line item (which is a parent of all other line items) on this cart |
|
254 | + * |
|
255 | + * @return EE_Line_Item |
|
256 | + * @throws \EE_Error |
|
257 | + */ |
|
258 | + public function get_grand_total() |
|
259 | + { |
|
260 | + return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @process items for adding to cart |
|
267 | + * @access public |
|
268 | + * @param EE_Ticket $ticket |
|
269 | + * @param int $qty |
|
270 | + * @return TRUE on success, FALSE on fail |
|
271 | + * @throws \EE_Error |
|
272 | + */ |
|
273 | + public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
274 | + { |
|
275 | + EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
276 | + return $this->save_cart() ? true : false; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * get_cart_total_before_tax |
|
283 | + * |
|
284 | + * @access public |
|
285 | + * @return float |
|
286 | + * @throws \EE_Error |
|
287 | + */ |
|
288 | + public function get_cart_total_before_tax() |
|
289 | + { |
|
290 | + return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * gets the total amount of tax paid for items in this cart |
|
297 | + * |
|
298 | + * @access public |
|
299 | + * @return float |
|
300 | + * @throws \EE_Error |
|
301 | + */ |
|
302 | + public function get_applied_taxes() |
|
303 | + { |
|
304 | + return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
311 | + * |
|
312 | + * @access public |
|
313 | + * @return float |
|
314 | + * @throws \EE_Error |
|
315 | + */ |
|
316 | + public function get_cart_grand_total() |
|
317 | + { |
|
318 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
319 | + return $this->get_grand_total()->total(); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
326 | + * |
|
327 | + * @access public |
|
328 | + * @return float |
|
329 | + * @throws \EE_Error |
|
330 | + */ |
|
331 | + public function recalculate_all_cart_totals() |
|
332 | + { |
|
333 | + $pre_tax_total = $this->get_cart_total_before_tax(); |
|
334 | + $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
335 | + $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
336 | + $this->_grand_total->save_this_and_descendants_to_txn(); |
|
337 | + return $this->get_grand_total()->total(); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * deletes an item from the cart |
|
344 | + * |
|
345 | + * @access public |
|
346 | + * @param array|bool|string $line_item_codes |
|
347 | + * @return int on success, FALSE on fail |
|
348 | + * @throws \EE_Error |
|
349 | + */ |
|
350 | + public function delete_items($line_item_codes = false) |
|
351 | + { |
|
352 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
353 | + return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * @remove ALL items from cart and zero ALL totals |
|
360 | + * @access public |
|
361 | + * @return bool |
|
362 | + * @throws \EE_Error |
|
363 | + */ |
|
364 | + public function empty_cart() |
|
365 | + { |
|
366 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
367 | + $this->_grand_total = $this->_create_grand_total(); |
|
368 | + return $this->save_cart(true); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * @remove ALL items from cart and delete total as well |
|
375 | + * @access public |
|
376 | + * @return bool |
|
377 | + * @throws \EE_Error |
|
378 | + */ |
|
379 | + public function delete_cart() |
|
380 | + { |
|
381 | + if ($this->_grand_total instanceof EE_Line_Item) { |
|
382 | + $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
383 | + if ($deleted) { |
|
384 | + $deleted += $this->_grand_total->delete(); |
|
385 | + $this->_grand_total = null; |
|
386 | + return true; |
|
387 | + } |
|
388 | + } |
|
389 | + return false; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * @save cart to session |
|
396 | + * @access public |
|
397 | + * @param bool $apply_taxes |
|
398 | + * @return TRUE on success, FALSE on fail |
|
399 | + * @throws \EE_Error |
|
400 | + */ |
|
401 | + public function save_cart($apply_taxes = true) |
|
402 | + { |
|
403 | + if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
404 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
405 | + //make sure we don't cache the transaction because it can get stale |
|
406 | + if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
407 | + && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
408 | + ) { |
|
409 | + $this->_grand_total->clear_cache('Transaction', null, true); |
|
410 | + } |
|
411 | + } |
|
412 | + if ($this->session() instanceof EE_Session) { |
|
413 | + return $this->session()->set_cart($this); |
|
414 | + } else { |
|
415 | + return false; |
|
416 | + } |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + |
|
421 | + public function __wakeup() |
|
422 | + { |
|
423 | + if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
424 | + // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
425 | + $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
426 | + } |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * @return array |
|
433 | + */ |
|
434 | + public function __sleep() |
|
435 | + { |
|
436 | + if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
437 | + $this->_grand_total = $this->_grand_total->ID(); |
|
438 | + } |
|
439 | + return array('_grand_total'); |
|
440 | + } |
|
441 | 441 | |
442 | 442 | |
443 | 443 | } |
@@ -23,14 +23,14 @@ |
||
23 | 23 | class CartFactory |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @return EE_Cart |
|
28 | - * @throws InvalidArgumentException |
|
29 | - * @throws InvalidInterfaceException |
|
30 | - * @throws InvalidDataTypeException |
|
31 | - */ |
|
32 | - public static function getCart() |
|
33 | - { |
|
34 | - return LoaderFactory::getLoader()->getShared('EE_Cart'); |
|
35 | - } |
|
26 | + /** |
|
27 | + * @return EE_Cart |
|
28 | + * @throws InvalidArgumentException |
|
29 | + * @throws InvalidInterfaceException |
|
30 | + * @throws InvalidDataTypeException |
|
31 | + */ |
|
32 | + public static function getCart() |
|
33 | + { |
|
34 | + return LoaderFactory::getLoader()->getShared('EE_Cart'); |
|
35 | + } |
|
36 | 36 | } |
@@ -25,17 +25,17 @@ |
||
25 | 25 | class ModelFactory |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @param string $model_name |
|
30 | - * @return bool|EEM_Base |
|
31 | - * @throws EE_Error |
|
32 | - * @throws InvalidDataTypeException |
|
33 | - * @throws InvalidInterfaceException |
|
34 | - * @throws InvalidArgumentException |
|
35 | - * @throws ReflectionException |
|
36 | - */ |
|
37 | - public static function getModel($model_name) |
|
38 | - { |
|
39 | - return EE_Registry::instance()->load_model($model_name); |
|
40 | - } |
|
28 | + /** |
|
29 | + * @param string $model_name |
|
30 | + * @return bool|EEM_Base |
|
31 | + * @throws EE_Error |
|
32 | + * @throws InvalidDataTypeException |
|
33 | + * @throws InvalidInterfaceException |
|
34 | + * @throws InvalidArgumentException |
|
35 | + * @throws ReflectionException |
|
36 | + */ |
|
37 | + public static function getModel($model_name) |
|
38 | + { |
|
39 | + return EE_Registry::instance()->load_model($model_name); |
|
40 | + } |
|
41 | 41 | } |
@@ -66,24 +66,24 @@ discard block |
||
66 | 66 | public function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
67 | 67 | { |
68 | 68 | // if the $_available_spaces array has not been set up yet... |
69 | - if (! isset($this->available_spaces['tickets'][ $ticket->ID() ])) { |
|
69 | + if ( ! isset($this->available_spaces['tickets'][$ticket->ID()])) { |
|
70 | 70 | $this->setInitialTicketDatetimeAvailability($ticket); |
71 | 71 | } |
72 | 72 | $available_spaces = $ticket->qty() - $ticket->sold(); |
73 | - if (isset($this->available_spaces['tickets'][ $ticket->ID() ])) { |
|
73 | + if (isset($this->available_spaces['tickets'][$ticket->ID()])) { |
|
74 | 74 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
75 | - foreach ($this->available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
75 | + foreach ($this->available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
76 | 76 | // if we want the original datetime availability BEFORE we started subtracting tickets ? |
77 | 77 | if ($get_original_ticket_spaces) { |
78 | 78 | // then grab the available spaces from the "tickets" array |
79 | 79 | // and compare with the above to get the lowest number |
80 | 80 | $available_spaces = min( |
81 | 81 | $available_spaces, |
82 | - $this->available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
82 | + $this->available_spaces['tickets'][$ticket->ID()][$DTD_ID] |
|
83 | 83 | ); |
84 | 84 | } else { |
85 | 85 | // we want the updated ticket availability as stored in the "datetimes" array |
86 | - $available_spaces = min($available_spaces, $this->available_spaces['datetimes'][ $DTD_ID ]); |
|
86 | + $available_spaces = min($available_spaces, $this->available_spaces['datetimes'][$DTD_ID]); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | 'order_by' => array('DTT_EVT_start' => 'ASC'), |
115 | 115 | ) |
116 | 116 | ); |
117 | - if (! empty($datetimes)) { |
|
117 | + if ( ! empty($datetimes)) { |
|
118 | 118 | // now loop thru all of the datetimes |
119 | 119 | foreach ($datetimes as $datetime) { |
120 | 120 | if ($datetime instanceof EE_Datetime) { |
@@ -122,17 +122,17 @@ discard block |
||
122 | 122 | $spaces_remaining = $datetime->spaces_remaining(); |
123 | 123 | // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
124 | 124 | // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
125 | - $this->available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
125 | + $this->available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
126 | 126 | $ticket->qty() - $ticket->sold(), |
127 | 127 | $spaces_remaining |
128 | 128 | ); |
129 | 129 | // if the remaining spaces for this datetime is already set, |
130 | 130 | // then compare that against the datetime spaces remaining, and take the lowest number, |
131 | 131 | // else just take the datetime spaces remaining, and assign to the datetimes array |
132 | - $this->available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
133 | - $this->available_spaces['datetimes'][ $datetime->ID() ] |
|
132 | + $this->available_spaces['datetimes'][$datetime->ID()] = isset( |
|
133 | + $this->available_spaces['datetimes'][$datetime->ID()] |
|
134 | 134 | ) |
135 | - ? min($this->available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
135 | + ? min($this->available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
136 | 136 | : $spaces_remaining; |
137 | 137 | } |
138 | 138 | } |
@@ -148,11 +148,11 @@ discard block |
||
148 | 148 | */ |
149 | 149 | public function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
150 | 150 | { |
151 | - if (isset($this->available_spaces['tickets'][ $ticket->ID() ])) { |
|
151 | + if (isset($this->available_spaces['tickets'][$ticket->ID()])) { |
|
152 | 152 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
153 | - foreach ($this->available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
153 | + foreach ($this->available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
154 | 154 | // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
155 | - $this->available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
155 | + $this->available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | } |
@@ -26,215 +26,215 @@ |
||
26 | 26 | class TicketDatetimeAvailabilityTracker |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * array of datetimes and the spaces available for them |
|
31 | - * |
|
32 | - * @var array[][] |
|
33 | - */ |
|
34 | - private $available_spaces = array(); |
|
35 | - |
|
36 | - /** |
|
37 | - * @var EEM_Datetime $datetime_model |
|
38 | - */ |
|
39 | - private $datetime_model; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * TicketDatetimeAvailabilityTracker constructor. |
|
44 | - * |
|
45 | - * @param EEM_Datetime $datetime_model |
|
46 | - */ |
|
47 | - public function __construct(EEM_Datetime $datetime_model) |
|
48 | - { |
|
49 | - $this->datetime_model = $datetime_model; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * ticketDatetimeAvailability |
|
55 | - * creates an array of tickets plus all of the datetimes available to each ticket |
|
56 | - * and tracks the spaces remaining for each of those datetimes |
|
57 | - * |
|
58 | - * @param EE_Ticket $ticket - selected ticket |
|
59 | - * @param bool $get_original_ticket_spaces |
|
60 | - * @return int |
|
61 | - * @throws EE_Error |
|
62 | - * @throws InvalidArgumentException |
|
63 | - * @throws InvalidDataTypeException |
|
64 | - * @throws InvalidInterfaceException |
|
65 | - */ |
|
66 | - public function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
67 | - { |
|
68 | - // if the $_available_spaces array has not been set up yet... |
|
69 | - if (! isset($this->available_spaces['tickets'][ $ticket->ID() ])) { |
|
70 | - $this->setInitialTicketDatetimeAvailability($ticket); |
|
71 | - } |
|
72 | - $available_spaces = $ticket->qty() - $ticket->sold(); |
|
73 | - if (isset($this->available_spaces['tickets'][ $ticket->ID() ])) { |
|
74 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
75 | - foreach ($this->available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
76 | - // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
77 | - if ($get_original_ticket_spaces) { |
|
78 | - // then grab the available spaces from the "tickets" array |
|
79 | - // and compare with the above to get the lowest number |
|
80 | - $available_spaces = min( |
|
81 | - $available_spaces, |
|
82 | - $this->available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
83 | - ); |
|
84 | - } else { |
|
85 | - // we want the updated ticket availability as stored in the "datetimes" array |
|
86 | - $available_spaces = min($available_spaces, $this->available_spaces['datetimes'][ $DTD_ID ]); |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
90 | - return $available_spaces; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @param EE_Ticket $ticket |
|
96 | - * @return void |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws InvalidInterfaceException |
|
99 | - * @throws InvalidDataTypeException |
|
100 | - * @throws EE_Error |
|
101 | - */ |
|
102 | - private function setInitialTicketDatetimeAvailability(EE_Ticket $ticket) |
|
103 | - { |
|
104 | - // first, get all of the datetimes that are available to this ticket |
|
105 | - $datetimes = $ticket->get_many_related( |
|
106 | - 'Datetime', |
|
107 | - array( |
|
108 | - array( |
|
109 | - 'DTT_EVT_end' => array( |
|
110 | - '>=', |
|
111 | - $this->datetime_model->current_time_for_query('DTT_EVT_end'), |
|
112 | - ), |
|
113 | - ), |
|
114 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
115 | - ) |
|
116 | - ); |
|
117 | - if (! empty($datetimes)) { |
|
118 | - // now loop thru all of the datetimes |
|
119 | - foreach ($datetimes as $datetime) { |
|
120 | - if ($datetime instanceof EE_Datetime) { |
|
121 | - // the number of spaces available for the datetime without considering individual ticket quantities |
|
122 | - $spaces_remaining = $datetime->spaces_remaining(); |
|
123 | - // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
124 | - // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
125 | - $this->available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
126 | - $ticket->qty() - $ticket->sold(), |
|
127 | - $spaces_remaining |
|
128 | - ); |
|
129 | - // if the remaining spaces for this datetime is already set, |
|
130 | - // then compare that against the datetime spaces remaining, and take the lowest number, |
|
131 | - // else just take the datetime spaces remaining, and assign to the datetimes array |
|
132 | - $this->available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
133 | - $this->available_spaces['datetimes'][ $datetime->ID() ] |
|
134 | - ) |
|
135 | - ? min($this->available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
136 | - : $spaces_remaining; |
|
137 | - } |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param EE_Ticket $ticket |
|
145 | - * @param int $qty |
|
146 | - * @return void |
|
147 | - * @throws EE_Error |
|
148 | - */ |
|
149 | - public function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
|
150 | - { |
|
151 | - if (isset($this->available_spaces['tickets'][ $ticket->ID() ])) { |
|
152 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
153 | - foreach ($this->available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
154 | - // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
155 | - $this->available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
156 | - } |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param EE_Ticket $ticket |
|
163 | - * @param $qty |
|
164 | - * @param int $total_ticket_count |
|
165 | - * @throws EE_Error |
|
166 | - * @throws InvalidArgumentException |
|
167 | - * @throws InvalidDataTypeException |
|
168 | - * @throws InvalidInterfaceException |
|
169 | - */ |
|
170 | - public function processAvailabilityError(EE_Ticket $ticket, $qty, $total_ticket_count = 1) |
|
171 | - { |
|
172 | - // tickets can not be purchased but let's find the exact number left |
|
173 | - // for the last ticket selected PRIOR to subtracting tickets |
|
174 | - $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
175 | - // greedy greedy greedy eh? |
|
176 | - if ($available_spaces > 0) { |
|
177 | - if ( |
|
178 | - apply_filters( |
|
179 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
180 | - true, |
|
181 | - $ticket, |
|
182 | - $qty, |
|
183 | - $available_spaces |
|
184 | - ) |
|
185 | - ) { |
|
186 | - $this->availabilityError( |
|
187 | - $available_spaces, |
|
188 | - $total_ticket_count |
|
189 | - ); |
|
190 | - } |
|
191 | - } else { |
|
192 | - EE_Error::add_error( |
|
193 | - esc_html__( |
|
194 | - 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
195 | - 'event_espresso' |
|
196 | - ), |
|
197 | - __FILE__, __FUNCTION__, __LINE__ |
|
198 | - ); |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @param int $available_spaces |
|
205 | - * @param int $total_ticket_count |
|
206 | - */ |
|
207 | - private function availabilityError($available_spaces = 1, $total_ticket_count = 1) |
|
208 | - { |
|
209 | - // add error messaging - we're using the _n function that will generate |
|
210 | - // the appropriate singular or plural message based on the number of $available_spaces |
|
211 | - if ($total_ticket_count) { |
|
212 | - $msg = sprintf( |
|
213 | - esc_html( |
|
214 | - _n( |
|
215 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
216 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
217 | - $available_spaces, |
|
218 | - 'event_espresso' |
|
219 | - ) |
|
220 | - ), |
|
221 | - $available_spaces, |
|
222 | - '<br />' |
|
223 | - ); |
|
224 | - } else { |
|
225 | - $msg = sprintf( |
|
226 | - esc_html( |
|
227 | - _n( |
|
228 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
229 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
230 | - $available_spaces, |
|
231 | - 'event_espresso' |
|
232 | - ) |
|
233 | - ), |
|
234 | - $available_spaces, |
|
235 | - '<br />' |
|
236 | - ); |
|
237 | - } |
|
238 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
239 | - } |
|
29 | + /** |
|
30 | + * array of datetimes and the spaces available for them |
|
31 | + * |
|
32 | + * @var array[][] |
|
33 | + */ |
|
34 | + private $available_spaces = array(); |
|
35 | + |
|
36 | + /** |
|
37 | + * @var EEM_Datetime $datetime_model |
|
38 | + */ |
|
39 | + private $datetime_model; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * TicketDatetimeAvailabilityTracker constructor. |
|
44 | + * |
|
45 | + * @param EEM_Datetime $datetime_model |
|
46 | + */ |
|
47 | + public function __construct(EEM_Datetime $datetime_model) |
|
48 | + { |
|
49 | + $this->datetime_model = $datetime_model; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * ticketDatetimeAvailability |
|
55 | + * creates an array of tickets plus all of the datetimes available to each ticket |
|
56 | + * and tracks the spaces remaining for each of those datetimes |
|
57 | + * |
|
58 | + * @param EE_Ticket $ticket - selected ticket |
|
59 | + * @param bool $get_original_ticket_spaces |
|
60 | + * @return int |
|
61 | + * @throws EE_Error |
|
62 | + * @throws InvalidArgumentException |
|
63 | + * @throws InvalidDataTypeException |
|
64 | + * @throws InvalidInterfaceException |
|
65 | + */ |
|
66 | + public function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
67 | + { |
|
68 | + // if the $_available_spaces array has not been set up yet... |
|
69 | + if (! isset($this->available_spaces['tickets'][ $ticket->ID() ])) { |
|
70 | + $this->setInitialTicketDatetimeAvailability($ticket); |
|
71 | + } |
|
72 | + $available_spaces = $ticket->qty() - $ticket->sold(); |
|
73 | + if (isset($this->available_spaces['tickets'][ $ticket->ID() ])) { |
|
74 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
75 | + foreach ($this->available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
76 | + // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
77 | + if ($get_original_ticket_spaces) { |
|
78 | + // then grab the available spaces from the "tickets" array |
|
79 | + // and compare with the above to get the lowest number |
|
80 | + $available_spaces = min( |
|
81 | + $available_spaces, |
|
82 | + $this->available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
83 | + ); |
|
84 | + } else { |
|
85 | + // we want the updated ticket availability as stored in the "datetimes" array |
|
86 | + $available_spaces = min($available_spaces, $this->available_spaces['datetimes'][ $DTD_ID ]); |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | + return $available_spaces; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @param EE_Ticket $ticket |
|
96 | + * @return void |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws InvalidInterfaceException |
|
99 | + * @throws InvalidDataTypeException |
|
100 | + * @throws EE_Error |
|
101 | + */ |
|
102 | + private function setInitialTicketDatetimeAvailability(EE_Ticket $ticket) |
|
103 | + { |
|
104 | + // first, get all of the datetimes that are available to this ticket |
|
105 | + $datetimes = $ticket->get_many_related( |
|
106 | + 'Datetime', |
|
107 | + array( |
|
108 | + array( |
|
109 | + 'DTT_EVT_end' => array( |
|
110 | + '>=', |
|
111 | + $this->datetime_model->current_time_for_query('DTT_EVT_end'), |
|
112 | + ), |
|
113 | + ), |
|
114 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
115 | + ) |
|
116 | + ); |
|
117 | + if (! empty($datetimes)) { |
|
118 | + // now loop thru all of the datetimes |
|
119 | + foreach ($datetimes as $datetime) { |
|
120 | + if ($datetime instanceof EE_Datetime) { |
|
121 | + // the number of spaces available for the datetime without considering individual ticket quantities |
|
122 | + $spaces_remaining = $datetime->spaces_remaining(); |
|
123 | + // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
124 | + // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
125 | + $this->available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
126 | + $ticket->qty() - $ticket->sold(), |
|
127 | + $spaces_remaining |
|
128 | + ); |
|
129 | + // if the remaining spaces for this datetime is already set, |
|
130 | + // then compare that against the datetime spaces remaining, and take the lowest number, |
|
131 | + // else just take the datetime spaces remaining, and assign to the datetimes array |
|
132 | + $this->available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
133 | + $this->available_spaces['datetimes'][ $datetime->ID() ] |
|
134 | + ) |
|
135 | + ? min($this->available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
136 | + : $spaces_remaining; |
|
137 | + } |
|
138 | + } |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param EE_Ticket $ticket |
|
145 | + * @param int $qty |
|
146 | + * @return void |
|
147 | + * @throws EE_Error |
|
148 | + */ |
|
149 | + public function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
|
150 | + { |
|
151 | + if (isset($this->available_spaces['tickets'][ $ticket->ID() ])) { |
|
152 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
153 | + foreach ($this->available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
154 | + // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
155 | + $this->available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
156 | + } |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param EE_Ticket $ticket |
|
163 | + * @param $qty |
|
164 | + * @param int $total_ticket_count |
|
165 | + * @throws EE_Error |
|
166 | + * @throws InvalidArgumentException |
|
167 | + * @throws InvalidDataTypeException |
|
168 | + * @throws InvalidInterfaceException |
|
169 | + */ |
|
170 | + public function processAvailabilityError(EE_Ticket $ticket, $qty, $total_ticket_count = 1) |
|
171 | + { |
|
172 | + // tickets can not be purchased but let's find the exact number left |
|
173 | + // for the last ticket selected PRIOR to subtracting tickets |
|
174 | + $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
175 | + // greedy greedy greedy eh? |
|
176 | + if ($available_spaces > 0) { |
|
177 | + if ( |
|
178 | + apply_filters( |
|
179 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
180 | + true, |
|
181 | + $ticket, |
|
182 | + $qty, |
|
183 | + $available_spaces |
|
184 | + ) |
|
185 | + ) { |
|
186 | + $this->availabilityError( |
|
187 | + $available_spaces, |
|
188 | + $total_ticket_count |
|
189 | + ); |
|
190 | + } |
|
191 | + } else { |
|
192 | + EE_Error::add_error( |
|
193 | + esc_html__( |
|
194 | + 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
195 | + 'event_espresso' |
|
196 | + ), |
|
197 | + __FILE__, __FUNCTION__, __LINE__ |
|
198 | + ); |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @param int $available_spaces |
|
205 | + * @param int $total_ticket_count |
|
206 | + */ |
|
207 | + private function availabilityError($available_spaces = 1, $total_ticket_count = 1) |
|
208 | + { |
|
209 | + // add error messaging - we're using the _n function that will generate |
|
210 | + // the appropriate singular or plural message based on the number of $available_spaces |
|
211 | + if ($total_ticket_count) { |
|
212 | + $msg = sprintf( |
|
213 | + esc_html( |
|
214 | + _n( |
|
215 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
216 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
217 | + $available_spaces, |
|
218 | + 'event_espresso' |
|
219 | + ) |
|
220 | + ), |
|
221 | + $available_spaces, |
|
222 | + '<br />' |
|
223 | + ); |
|
224 | + } else { |
|
225 | + $msg = sprintf( |
|
226 | + esc_html( |
|
227 | + _n( |
|
228 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
229 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
230 | + $available_spaces, |
|
231 | + 'event_espresso' |
|
232 | + ) |
|
233 | + ), |
|
234 | + $available_spaces, |
|
235 | + '<br />' |
|
236 | + ); |
|
237 | + } |
|
238 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
239 | + } |
|
240 | 240 | } |
@@ -20,470 +20,470 @@ |
||
20 | 20 | class EED_Ticket_Selector extends EED_Module |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var DisplayTicketSelector $ticket_selector |
|
25 | - */ |
|
26 | - private static $ticket_selector; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var TicketSelectorIframeEmbedButton $iframe_embed_button |
|
30 | - */ |
|
31 | - private static $iframe_embed_button; |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @return EED_Module|EED_Ticket_Selector |
|
37 | - */ |
|
38 | - public static function instance() |
|
39 | - { |
|
40 | - return parent::get_instance(__CLASS__); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - protected function set_config() |
|
49 | - { |
|
50 | - $this->set_config_section('template_settings'); |
|
51 | - $this->set_config_class('EE_Ticket_Selector_Config'); |
|
52 | - $this->set_config_name('EED_Ticket_Selector'); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
59 | - * |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public static function set_hooks() |
|
63 | - { |
|
64 | - // routing |
|
65 | - EE_Config::register_route( |
|
66 | - 'iframe', |
|
67 | - 'EED_Ticket_Selector', |
|
68 | - 'ticket_selector_iframe', |
|
69 | - 'ticket_selector' |
|
70 | - ); |
|
71 | - EE_Config::register_route( |
|
72 | - 'process_ticket_selections', |
|
73 | - 'EED_Ticket_Selector', |
|
74 | - 'process_ticket_selections' |
|
75 | - ); |
|
76 | - EE_Config::register_route( |
|
77 | - 'cancel_ticket_selections', |
|
78 | - 'EED_Ticket_Selector', |
|
79 | - 'cancel_ticket_selections' |
|
80 | - ); |
|
81 | - add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2); |
|
82 | - add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1); |
|
83 | - add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'translate_js_strings'), 0); |
|
84 | - add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10); |
|
85 | - EED_Ticket_Selector::loadIframeAssets(); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
92 | - * |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - public static function set_hooks_admin() |
|
96 | - { |
|
97 | - // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
98 | - // to load assets for "espresso_events" page on the "edit" route (action) |
|
99 | - add_action( |
|
100 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit', |
|
101 | - array('EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'), |
|
102 | - 10 |
|
103 | - ); |
|
104 | - /** |
|
105 | - * Make sure assets for the ticket selector are loaded on the espresso registrations route so admin side |
|
106 | - * registrations work. |
|
107 | - */ |
|
108 | - add_action( |
|
109 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration', |
|
110 | - array('EED_Ticket_Selector', 'set_definitions'), |
|
111 | - 10 |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * set_definitions |
|
119 | - * |
|
120 | - * @return void |
|
121 | - * @throws InvalidArgumentException |
|
122 | - * @throws InvalidDataTypeException |
|
123 | - * @throws InvalidInterfaceException |
|
124 | - */ |
|
125 | - public static function set_definitions() |
|
126 | - { |
|
127 | - // don't do this twice |
|
128 | - if (defined('TICKET_SELECTOR_ASSETS_URL')) { |
|
129 | - return; |
|
130 | - } |
|
131 | - define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
132 | - define( |
|
133 | - 'TICKET_SELECTOR_TEMPLATES_PATH', |
|
134 | - str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS |
|
135 | - ); |
|
136 | - //if config is not set, initialize |
|
137 | - if ( |
|
138 | - ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
139 | - ) { |
|
140 | - EED_Ticket_Selector::instance()->set_config(); |
|
141 | - EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = EED_Ticket_Selector::instance()->config(); |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @return DisplayTicketSelector |
|
149 | - */ |
|
150 | - public static function ticketSelector() |
|
151 | - { |
|
152 | - if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
153 | - EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(EED_Events_Archive::is_iframe()); |
|
154 | - } |
|
155 | - return EED_Ticket_Selector::$ticket_selector; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * gets the ball rolling |
|
161 | - * |
|
162 | - * @param WP $WP |
|
163 | - * @return void |
|
164 | - */ |
|
165 | - public function run($WP) |
|
166 | - { |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @return TicketSelectorIframeEmbedButton |
|
173 | - */ |
|
174 | - public static function getIframeEmbedButton() |
|
175 | - { |
|
176 | - if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
177 | - self::$iframe_embed_button = new TicketSelectorIframeEmbedButton(); |
|
178 | - } |
|
179 | - return self::$iframe_embed_button; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * ticket_selector_iframe_embed_button |
|
186 | - * |
|
187 | - * @return void |
|
188 | - * @throws EE_Error |
|
189 | - */ |
|
190 | - public static function ticket_selector_iframe_embed_button() |
|
191 | - { |
|
192 | - $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
193 | - $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * ticket_selector_iframe |
|
200 | - * |
|
201 | - * @return void |
|
202 | - * @throws DomainException |
|
203 | - * @throws EE_Error |
|
204 | - */ |
|
205 | - public function ticket_selector_iframe() |
|
206 | - { |
|
207 | - $ticket_selector_iframe = new TicketSelectorIframe(); |
|
208 | - $ticket_selector_iframe->display(); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * creates buttons for selecting number of attendees for an event |
|
215 | - * |
|
216 | - * @param WP_Post|int $event |
|
217 | - * @param bool $view_details |
|
218 | - * @return string |
|
219 | - * @throws EE_Error |
|
220 | - */ |
|
221 | - public static function display_ticket_selector($event = null, $view_details = false) |
|
222 | - { |
|
223 | - return EED_Ticket_Selector::ticketSelector()->display($event, $view_details); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * @return array or FALSE |
|
229 | - * @throws \ReflectionException |
|
230 | - * @throws \EE_Error |
|
231 | - * @throws InvalidArgumentException |
|
232 | - * @throws InvalidInterfaceException |
|
233 | - * @throws InvalidDataTypeException |
|
234 | - */ |
|
235 | - public function process_ticket_selections() |
|
236 | - { |
|
237 | - /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */ |
|
238 | - $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector'); |
|
239 | - return $form->processTicketSelections(); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @return string |
|
245 | - * @throws InvalidArgumentException |
|
246 | - * @throws InvalidInterfaceException |
|
247 | - * @throws InvalidDataTypeException |
|
248 | - * @throws EE_Error |
|
249 | - */ |
|
250 | - public static function cancel_ticket_selections() |
|
251 | - { |
|
252 | - /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */ |
|
253 | - $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector'); |
|
254 | - return $form->cancelTicketSelections(); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * @return void |
|
261 | - */ |
|
262 | - public static function translate_js_strings() |
|
263 | - { |
|
264 | - EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__( |
|
265 | - 'please select a datetime', |
|
266 | - 'event_espresso' |
|
267 | - ); |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * @return void |
|
274 | - */ |
|
275 | - public static function load_tckt_slctr_assets() |
|
276 | - { |
|
277 | - if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) { |
|
278 | - // add some style |
|
279 | - wp_register_style( |
|
280 | - 'ticket_selector', |
|
281 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
282 | - array(), |
|
283 | - EVENT_ESPRESSO_VERSION |
|
284 | - ); |
|
285 | - wp_enqueue_style('ticket_selector'); |
|
286 | - // make it dance |
|
287 | - wp_register_script( |
|
288 | - 'ticket_selector', |
|
289 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
290 | - array('espresso_core'), |
|
291 | - EVENT_ESPRESSO_VERSION, |
|
292 | - true |
|
293 | - ); |
|
294 | - wp_enqueue_script('ticket_selector'); |
|
295 | - require_once EE_LIBRARIES |
|
296 | - . 'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'; |
|
297 | - \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
298 | - } |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * @return void |
|
305 | - */ |
|
306 | - public static function loadIframeAssets() |
|
307 | - { |
|
308 | - // for event lists |
|
309 | - add_filter( |
|
310 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
311 | - array('EED_Ticket_Selector', 'iframeCss') |
|
312 | - ); |
|
313 | - add_filter( |
|
314 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
315 | - array('EED_Ticket_Selector', 'iframeJs') |
|
316 | - ); |
|
317 | - // for ticket selectors |
|
318 | - add_filter( |
|
319 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
320 | - array('EED_Ticket_Selector', 'iframeCss') |
|
321 | - ); |
|
322 | - add_filter( |
|
323 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
324 | - array('EED_Ticket_Selector', 'iframeJs') |
|
325 | - ); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
332 | - * |
|
333 | - * @param array $iframe_css |
|
334 | - * @return array |
|
335 | - */ |
|
336 | - public static function iframeCss(array $iframe_css) |
|
337 | - { |
|
338 | - $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
339 | - return $iframe_css; |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
346 | - * |
|
347 | - * @param array $iframe_js |
|
348 | - * @return array |
|
349 | - */ |
|
350 | - public static function iframeJs(array $iframe_js) |
|
351 | - { |
|
352 | - $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
353 | - return $iframe_js; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /****************************** DEPRECATED ******************************/ |
|
358 | - |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * @deprecated |
|
363 | - * @return string |
|
364 | - * @throws EE_Error |
|
365 | - */ |
|
366 | - public static function display_view_details_btn() |
|
367 | - { |
|
368 | - // todo add doing_it_wrong() notice during next major version |
|
369 | - return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton(); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * @deprecated |
|
376 | - * @return string |
|
377 | - * @throws EE_Error |
|
378 | - */ |
|
379 | - public static function display_ticket_selector_submit() |
|
380 | - { |
|
381 | - // todo add doing_it_wrong() notice during next major version |
|
382 | - return EED_Ticket_Selector::ticketSelector()->displaySubmitButton(); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * @deprecated |
|
389 | - * @param string $permalink_string |
|
390 | - * @param int $id |
|
391 | - * @param string $new_title |
|
392 | - * @param string $new_slug |
|
393 | - * @return string |
|
394 | - * @throws InvalidArgumentException |
|
395 | - * @throws InvalidDataTypeException |
|
396 | - * @throws InvalidInterfaceException |
|
397 | - */ |
|
398 | - public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
|
399 | - { |
|
400 | - // todo add doing_it_wrong() notice during next major version |
|
401 | - if ( |
|
402 | - EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
403 | - && EE_Registry::instance()->REQ->get('action') === 'edit' |
|
404 | - ) { |
|
405 | - $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
406 | - $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
407 | - } |
|
408 | - return ''; |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * @deprecated |
|
415 | - * @param int $ID |
|
416 | - * @param string $external_url |
|
417 | - * @return string |
|
418 | - */ |
|
419 | - public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
420 | - { |
|
421 | - // todo add doing_it_wrong() notice during next major version |
|
422 | - return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * @deprecated |
|
429 | - * @return string |
|
430 | - */ |
|
431 | - public static function ticket_selector_form_close() |
|
432 | - { |
|
433 | - // todo add doing_it_wrong() notice during next major version |
|
434 | - return EED_Ticket_Selector::ticketSelector()->formClose(); |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * @deprecated |
|
441 | - * @return string |
|
442 | - */ |
|
443 | - public static function no_tkt_slctr_end_dv() |
|
444 | - { |
|
445 | - // todo add doing_it_wrong() notice during next major version |
|
446 | - return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv(); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * @deprecated 4.9.13 |
|
453 | - * @return string |
|
454 | - */ |
|
455 | - public static function tkt_slctr_end_dv() |
|
456 | - { |
|
457 | - return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * @deprecated |
|
464 | - * @return string |
|
465 | - */ |
|
466 | - public static function clear_tkt_slctr() |
|
467 | - { |
|
468 | - return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
469 | - } |
|
470 | - |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * @deprecated |
|
475 | - */ |
|
476 | - public static function load_tckt_slctr_assets_admin() |
|
477 | - { |
|
478 | - // todo add doing_it_wrong() notice during next major version |
|
479 | - if ( |
|
480 | - EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
481 | - && EE_Registry::instance()->REQ->get('action') === 'edit' |
|
482 | - ) { |
|
483 | - $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
484 | - $iframe_embed_button->embedButtonAssets(); |
|
485 | - } |
|
486 | - } |
|
23 | + /** |
|
24 | + * @var DisplayTicketSelector $ticket_selector |
|
25 | + */ |
|
26 | + private static $ticket_selector; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var TicketSelectorIframeEmbedButton $iframe_embed_button |
|
30 | + */ |
|
31 | + private static $iframe_embed_button; |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @return EED_Module|EED_Ticket_Selector |
|
37 | + */ |
|
38 | + public static function instance() |
|
39 | + { |
|
40 | + return parent::get_instance(__CLASS__); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + protected function set_config() |
|
49 | + { |
|
50 | + $this->set_config_section('template_settings'); |
|
51 | + $this->set_config_class('EE_Ticket_Selector_Config'); |
|
52 | + $this->set_config_name('EED_Ticket_Selector'); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
59 | + * |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public static function set_hooks() |
|
63 | + { |
|
64 | + // routing |
|
65 | + EE_Config::register_route( |
|
66 | + 'iframe', |
|
67 | + 'EED_Ticket_Selector', |
|
68 | + 'ticket_selector_iframe', |
|
69 | + 'ticket_selector' |
|
70 | + ); |
|
71 | + EE_Config::register_route( |
|
72 | + 'process_ticket_selections', |
|
73 | + 'EED_Ticket_Selector', |
|
74 | + 'process_ticket_selections' |
|
75 | + ); |
|
76 | + EE_Config::register_route( |
|
77 | + 'cancel_ticket_selections', |
|
78 | + 'EED_Ticket_Selector', |
|
79 | + 'cancel_ticket_selections' |
|
80 | + ); |
|
81 | + add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2); |
|
82 | + add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1); |
|
83 | + add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'translate_js_strings'), 0); |
|
84 | + add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10); |
|
85 | + EED_Ticket_Selector::loadIframeAssets(); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
92 | + * |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + public static function set_hooks_admin() |
|
96 | + { |
|
97 | + // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
98 | + // to load assets for "espresso_events" page on the "edit" route (action) |
|
99 | + add_action( |
|
100 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit', |
|
101 | + array('EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'), |
|
102 | + 10 |
|
103 | + ); |
|
104 | + /** |
|
105 | + * Make sure assets for the ticket selector are loaded on the espresso registrations route so admin side |
|
106 | + * registrations work. |
|
107 | + */ |
|
108 | + add_action( |
|
109 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration', |
|
110 | + array('EED_Ticket_Selector', 'set_definitions'), |
|
111 | + 10 |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * set_definitions |
|
119 | + * |
|
120 | + * @return void |
|
121 | + * @throws InvalidArgumentException |
|
122 | + * @throws InvalidDataTypeException |
|
123 | + * @throws InvalidInterfaceException |
|
124 | + */ |
|
125 | + public static function set_definitions() |
|
126 | + { |
|
127 | + // don't do this twice |
|
128 | + if (defined('TICKET_SELECTOR_ASSETS_URL')) { |
|
129 | + return; |
|
130 | + } |
|
131 | + define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
132 | + define( |
|
133 | + 'TICKET_SELECTOR_TEMPLATES_PATH', |
|
134 | + str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS |
|
135 | + ); |
|
136 | + //if config is not set, initialize |
|
137 | + if ( |
|
138 | + ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
139 | + ) { |
|
140 | + EED_Ticket_Selector::instance()->set_config(); |
|
141 | + EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = EED_Ticket_Selector::instance()->config(); |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @return DisplayTicketSelector |
|
149 | + */ |
|
150 | + public static function ticketSelector() |
|
151 | + { |
|
152 | + if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
153 | + EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(EED_Events_Archive::is_iframe()); |
|
154 | + } |
|
155 | + return EED_Ticket_Selector::$ticket_selector; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * gets the ball rolling |
|
161 | + * |
|
162 | + * @param WP $WP |
|
163 | + * @return void |
|
164 | + */ |
|
165 | + public function run($WP) |
|
166 | + { |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @return TicketSelectorIframeEmbedButton |
|
173 | + */ |
|
174 | + public static function getIframeEmbedButton() |
|
175 | + { |
|
176 | + if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
177 | + self::$iframe_embed_button = new TicketSelectorIframeEmbedButton(); |
|
178 | + } |
|
179 | + return self::$iframe_embed_button; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * ticket_selector_iframe_embed_button |
|
186 | + * |
|
187 | + * @return void |
|
188 | + * @throws EE_Error |
|
189 | + */ |
|
190 | + public static function ticket_selector_iframe_embed_button() |
|
191 | + { |
|
192 | + $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
193 | + $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * ticket_selector_iframe |
|
200 | + * |
|
201 | + * @return void |
|
202 | + * @throws DomainException |
|
203 | + * @throws EE_Error |
|
204 | + */ |
|
205 | + public function ticket_selector_iframe() |
|
206 | + { |
|
207 | + $ticket_selector_iframe = new TicketSelectorIframe(); |
|
208 | + $ticket_selector_iframe->display(); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * creates buttons for selecting number of attendees for an event |
|
215 | + * |
|
216 | + * @param WP_Post|int $event |
|
217 | + * @param bool $view_details |
|
218 | + * @return string |
|
219 | + * @throws EE_Error |
|
220 | + */ |
|
221 | + public static function display_ticket_selector($event = null, $view_details = false) |
|
222 | + { |
|
223 | + return EED_Ticket_Selector::ticketSelector()->display($event, $view_details); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * @return array or FALSE |
|
229 | + * @throws \ReflectionException |
|
230 | + * @throws \EE_Error |
|
231 | + * @throws InvalidArgumentException |
|
232 | + * @throws InvalidInterfaceException |
|
233 | + * @throws InvalidDataTypeException |
|
234 | + */ |
|
235 | + public function process_ticket_selections() |
|
236 | + { |
|
237 | + /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */ |
|
238 | + $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector'); |
|
239 | + return $form->processTicketSelections(); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @return string |
|
245 | + * @throws InvalidArgumentException |
|
246 | + * @throws InvalidInterfaceException |
|
247 | + * @throws InvalidDataTypeException |
|
248 | + * @throws EE_Error |
|
249 | + */ |
|
250 | + public static function cancel_ticket_selections() |
|
251 | + { |
|
252 | + /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */ |
|
253 | + $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector'); |
|
254 | + return $form->cancelTicketSelections(); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * @return void |
|
261 | + */ |
|
262 | + public static function translate_js_strings() |
|
263 | + { |
|
264 | + EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__( |
|
265 | + 'please select a datetime', |
|
266 | + 'event_espresso' |
|
267 | + ); |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * @return void |
|
274 | + */ |
|
275 | + public static function load_tckt_slctr_assets() |
|
276 | + { |
|
277 | + if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) { |
|
278 | + // add some style |
|
279 | + wp_register_style( |
|
280 | + 'ticket_selector', |
|
281 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
282 | + array(), |
|
283 | + EVENT_ESPRESSO_VERSION |
|
284 | + ); |
|
285 | + wp_enqueue_style('ticket_selector'); |
|
286 | + // make it dance |
|
287 | + wp_register_script( |
|
288 | + 'ticket_selector', |
|
289 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
290 | + array('espresso_core'), |
|
291 | + EVENT_ESPRESSO_VERSION, |
|
292 | + true |
|
293 | + ); |
|
294 | + wp_enqueue_script('ticket_selector'); |
|
295 | + require_once EE_LIBRARIES |
|
296 | + . 'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'; |
|
297 | + \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
298 | + } |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * @return void |
|
305 | + */ |
|
306 | + public static function loadIframeAssets() |
|
307 | + { |
|
308 | + // for event lists |
|
309 | + add_filter( |
|
310 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
311 | + array('EED_Ticket_Selector', 'iframeCss') |
|
312 | + ); |
|
313 | + add_filter( |
|
314 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
315 | + array('EED_Ticket_Selector', 'iframeJs') |
|
316 | + ); |
|
317 | + // for ticket selectors |
|
318 | + add_filter( |
|
319 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
320 | + array('EED_Ticket_Selector', 'iframeCss') |
|
321 | + ); |
|
322 | + add_filter( |
|
323 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
324 | + array('EED_Ticket_Selector', 'iframeJs') |
|
325 | + ); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
332 | + * |
|
333 | + * @param array $iframe_css |
|
334 | + * @return array |
|
335 | + */ |
|
336 | + public static function iframeCss(array $iframe_css) |
|
337 | + { |
|
338 | + $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
339 | + return $iframe_css; |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
346 | + * |
|
347 | + * @param array $iframe_js |
|
348 | + * @return array |
|
349 | + */ |
|
350 | + public static function iframeJs(array $iframe_js) |
|
351 | + { |
|
352 | + $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
353 | + return $iframe_js; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /****************************** DEPRECATED ******************************/ |
|
358 | + |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * @deprecated |
|
363 | + * @return string |
|
364 | + * @throws EE_Error |
|
365 | + */ |
|
366 | + public static function display_view_details_btn() |
|
367 | + { |
|
368 | + // todo add doing_it_wrong() notice during next major version |
|
369 | + return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton(); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * @deprecated |
|
376 | + * @return string |
|
377 | + * @throws EE_Error |
|
378 | + */ |
|
379 | + public static function display_ticket_selector_submit() |
|
380 | + { |
|
381 | + // todo add doing_it_wrong() notice during next major version |
|
382 | + return EED_Ticket_Selector::ticketSelector()->displaySubmitButton(); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * @deprecated |
|
389 | + * @param string $permalink_string |
|
390 | + * @param int $id |
|
391 | + * @param string $new_title |
|
392 | + * @param string $new_slug |
|
393 | + * @return string |
|
394 | + * @throws InvalidArgumentException |
|
395 | + * @throws InvalidDataTypeException |
|
396 | + * @throws InvalidInterfaceException |
|
397 | + */ |
|
398 | + public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
|
399 | + { |
|
400 | + // todo add doing_it_wrong() notice during next major version |
|
401 | + if ( |
|
402 | + EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
403 | + && EE_Registry::instance()->REQ->get('action') === 'edit' |
|
404 | + ) { |
|
405 | + $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
406 | + $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
407 | + } |
|
408 | + return ''; |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * @deprecated |
|
415 | + * @param int $ID |
|
416 | + * @param string $external_url |
|
417 | + * @return string |
|
418 | + */ |
|
419 | + public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
420 | + { |
|
421 | + // todo add doing_it_wrong() notice during next major version |
|
422 | + return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * @deprecated |
|
429 | + * @return string |
|
430 | + */ |
|
431 | + public static function ticket_selector_form_close() |
|
432 | + { |
|
433 | + // todo add doing_it_wrong() notice during next major version |
|
434 | + return EED_Ticket_Selector::ticketSelector()->formClose(); |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * @deprecated |
|
441 | + * @return string |
|
442 | + */ |
|
443 | + public static function no_tkt_slctr_end_dv() |
|
444 | + { |
|
445 | + // todo add doing_it_wrong() notice during next major version |
|
446 | + return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv(); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * @deprecated 4.9.13 |
|
453 | + * @return string |
|
454 | + */ |
|
455 | + public static function tkt_slctr_end_dv() |
|
456 | + { |
|
457 | + return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * @deprecated |
|
464 | + * @return string |
|
465 | + */ |
|
466 | + public static function clear_tkt_slctr() |
|
467 | + { |
|
468 | + return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
469 | + } |
|
470 | + |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * @deprecated |
|
475 | + */ |
|
476 | + public static function load_tckt_slctr_assets_admin() |
|
477 | + { |
|
478 | + // todo add doing_it_wrong() notice during next major version |
|
479 | + if ( |
|
480 | + EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
481 | + && EE_Registry::instance()->REQ->get('action') === 'edit' |
|
482 | + ) { |
|
483 | + $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
484 | + $iframe_embed_button->embedButtonAssets(); |
|
485 | + } |
|
486 | + } |
|
487 | 487 | |
488 | 488 | |
489 | 489 | } |
@@ -241,7 +241,7 @@ |
||
241 | 241 | |
242 | 242 | |
243 | 243 | /** |
244 | - * @return string |
|
244 | + * @return boolean |
|
245 | 245 | * @throws InvalidArgumentException |
246 | 246 | * @throws InvalidInterfaceException |
247 | 247 | * @throws InvalidDataTypeException |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | |
212 | 212 | /** |
213 | 213 | * @param EE_Registration $registration |
214 | - * @return EE_Form_Section_Base |
|
214 | + * @return EE_Form_Section_Proper|null |
|
215 | 215 | * @throws EE_Error |
216 | 216 | * @throws InvalidArgumentException |
217 | 217 | * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
@@ -610,6 +610,7 @@ discard block |
||
610 | 610 | * @param EE_Registration $registration |
611 | 611 | * @param EE_Question $question |
612 | 612 | * @param mixed EE_Answer|NULL $answer |
613 | + * @param EE_Answer $answer |
|
613 | 614 | * @return EE_Form_Input_Base |
614 | 615 | * @throws \EE_Error |
615 | 616 | */ |
@@ -17,1346 +17,1346 @@ |
||
17 | 17 | class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @type bool $_print_copy_info |
|
22 | - */ |
|
23 | - private $_print_copy_info = false; |
|
24 | - |
|
25 | - /** |
|
26 | - * @type array $_attendee_data |
|
27 | - */ |
|
28 | - private $_attendee_data = array(); |
|
29 | - |
|
30 | - /** |
|
31 | - * @type array $_required_questions |
|
32 | - */ |
|
33 | - private $_required_questions = array(); |
|
34 | - |
|
35 | - /** |
|
36 | - * @type array $_registration_answers |
|
37 | - */ |
|
38 | - private $_registration_answers = array(); |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * class constructor |
|
43 | - * |
|
44 | - * @access public |
|
45 | - * @param EE_Checkout $checkout |
|
46 | - */ |
|
47 | - public function __construct(EE_Checkout $checkout) |
|
48 | - { |
|
49 | - $this->_slug = 'attendee_information'; |
|
50 | - $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
51 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
52 | - $this->checkout = $checkout; |
|
53 | - $this->_reset_success_message(); |
|
54 | - $this->set_instructions( |
|
55 | - esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - public function translate_js_strings() |
|
61 | - { |
|
62 | - EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
63 | - ' is a required question.', |
|
64 | - 'event_espresso' |
|
65 | - ); |
|
66 | - EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
67 | - ' is a required question. Please enter a value for at least one of the options.', |
|
68 | - 'event_espresso' |
|
69 | - ); |
|
70 | - EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
71 | - 'Please answer all required questions correctly before proceeding.', |
|
72 | - 'event_espresso' |
|
73 | - ); |
|
74 | - EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
75 | - esc_html__( |
|
76 | - 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
77 | - 'event_espresso' |
|
78 | - ), |
|
79 | - '<br/>' |
|
80 | - ); |
|
81 | - EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
82 | - 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
83 | - 'event_espresso' |
|
84 | - ); |
|
85 | - EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
86 | - 'You must enter a valid email address.', |
|
87 | - 'event_espresso' |
|
88 | - ); |
|
89 | - EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
90 | - 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
91 | - 'event_espresso' |
|
92 | - ); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - public function enqueue_styles_and_scripts() |
|
97 | - { |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return boolean |
|
103 | - */ |
|
104 | - public function initialize_reg_step() |
|
105 | - { |
|
106 | - return true; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @return EE_Form_Section_Proper |
|
112 | - * @throws EE_Error |
|
113 | - * @throws InvalidArgumentException |
|
114 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
115 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
116 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
117 | - */ |
|
118 | - public function generate_reg_form() |
|
119 | - { |
|
120 | - $this->_print_copy_info = false; |
|
121 | - $primary_registrant = null; |
|
122 | - // autoload Line_Item_Display classes |
|
123 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
124 | - $Line_Item_Display = new EE_Line_Item_Display(); |
|
125 | - // calculate taxes |
|
126 | - $Line_Item_Display->display_line_item( |
|
127 | - $this->checkout->cart->get_grand_total(), |
|
128 | - array('set_tax_rate' => true) |
|
129 | - ); |
|
130 | - /** @var $subsections EE_Form_Section_Proper[] */ |
|
131 | - $subsections = array( |
|
132 | - 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
133 | - ); |
|
134 | - $template_args = array( |
|
135 | - 'revisit' => $this->checkout->revisit, |
|
136 | - 'registrations' => array(), |
|
137 | - 'ticket_count' => array(), |
|
138 | - ); |
|
139 | - // grab the saved registrations from the transaction |
|
140 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
141 | - if ($registrations) { |
|
142 | - foreach ($registrations as $registration) { |
|
143 | - // can this registration be processed during this visit ? |
|
144 | - if ($registration instanceof EE_Registration |
|
145 | - && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
146 | - ) { |
|
147 | - $subsection = $this->_registrations_reg_form($registration); |
|
148 | - if(!$subsection instanceof EE_Form_Section_Proper) { |
|
149 | - continue; |
|
150 | - } |
|
151 | - $subsections[ $registration->reg_url_link() ] = $subsection; |
|
152 | - if (! $this->checkout->admin_request) { |
|
153 | - $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
154 | - $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
155 | - $template_args['ticket_count'][$registration->ticket()->ID()] |
|
156 | - ) |
|
157 | - ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
158 | - : 1; |
|
159 | - $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
160 | - $this->checkout->cart->get_grand_total(), |
|
161 | - 'Ticket', |
|
162 | - array($registration->ticket()->ID()) |
|
163 | - ); |
|
164 | - $ticket_line_item = is_array($ticket_line_item) |
|
165 | - ? reset($ticket_line_item) |
|
166 | - : $ticket_line_item; |
|
167 | - $template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
168 | - $Line_Item_Display->display_line_item($ticket_line_item); |
|
169 | - } |
|
170 | - if ($registration->is_primary_registrant()) { |
|
171 | - $primary_registrant = $registration->reg_url_link(); |
|
172 | - } |
|
173 | - } |
|
174 | - } |
|
175 | - // print_copy_info ? |
|
176 | - if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
177 | - // TODO: add admin option for toggling copy attendee info, |
|
178 | - // then use that value to change $this->_print_copy_info |
|
179 | - $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
180 | - ? $this->_copy_attendee_info_form() |
|
181 | - : $this->_auto_copy_attendee_info(); |
|
182 | - // generate hidden input |
|
183 | - if (isset($subsections[$primary_registrant]) |
|
184 | - && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
185 | - ) { |
|
186 | - $subsections[$primary_registrant]->add_subsections( |
|
187 | - $copy_options, |
|
188 | - 'primary_registrant', |
|
189 | - false |
|
190 | - ); |
|
191 | - } |
|
192 | - } |
|
193 | - } |
|
194 | - return new EE_Form_Section_Proper( |
|
195 | - array( |
|
196 | - 'name' => $this->reg_form_name(), |
|
197 | - 'html_id' => $this->reg_form_name(), |
|
198 | - 'subsections' => $subsections, |
|
199 | - 'layout_strategy' => $this->checkout->admin_request ? |
|
200 | - new EE_Div_Per_Section_Layout() : |
|
201 | - new EE_Template_Layout( |
|
202 | - array( |
|
203 | - 'layout_template_file' => $this->_template, // layout_template |
|
204 | - 'template_args' => $template_args, |
|
205 | - ) |
|
206 | - ), |
|
207 | - ) |
|
208 | - ); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @param EE_Registration $registration |
|
214 | - * @return EE_Form_Section_Base |
|
215 | - * @throws EE_Error |
|
216 | - * @throws InvalidArgumentException |
|
217 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
218 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
219 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
220 | - */ |
|
221 | - private function _registrations_reg_form(EE_Registration $registration) |
|
222 | - { |
|
223 | - static $attendee_nmbr = 1; |
|
224 | - $form_args = array(); |
|
225 | - // verify that registration has valid event |
|
226 | - if ($registration->event() instanceof EE_Event) { |
|
227 | - $question_groups = $registration->event()->question_groups( |
|
228 | - apply_filters( |
|
229 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
230 | - array( |
|
231 | - array( |
|
232 | - 'Event.EVT_ID' => $registration->event()->ID(), |
|
233 | - 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
234 | - ), |
|
235 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
236 | - ), |
|
237 | - $registration, |
|
238 | - $this |
|
239 | - ) |
|
240 | - ); |
|
241 | - if ($question_groups) { |
|
242 | - // array of params to pass to parent constructor |
|
243 | - $form_args = array( |
|
244 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
245 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
246 | - 'html_style' => $this->checkout->admin_request |
|
247 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
248 | - : '', |
|
249 | - 'subsections' => array(), |
|
250 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
251 | - array( |
|
252 | - 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
253 | - 'legend_text' => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr), |
|
254 | - ) |
|
255 | - ), |
|
256 | - ); |
|
257 | - foreach ($question_groups as $question_group) { |
|
258 | - if ($question_group instanceof EE_Question_Group) { |
|
259 | - $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form( |
|
260 | - $registration, |
|
261 | - $question_group |
|
262 | - ); |
|
263 | - } |
|
264 | - } |
|
265 | - // add hidden input |
|
266 | - $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
267 | - $registration |
|
268 | - ); |
|
269 | - // if we have question groups for additional attendees, then display the copy options |
|
270 | - $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
|
271 | - if ($registration->is_primary_registrant()) { |
|
272 | - // generate hidden input |
|
273 | - $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
274 | - $registration |
|
275 | - ); |
|
276 | - } |
|
277 | - } |
|
278 | - } |
|
279 | - $attendee_nmbr++; |
|
280 | - return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : null; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * _additional_attendee_reg_info_input |
|
286 | - * |
|
287 | - * @access public |
|
288 | - * @param EE_Registration $registration |
|
289 | - * @param bool $additional_attendee_reg_info |
|
290 | - * @return EE_Form_Input_Base |
|
291 | - * @throws \EE_Error |
|
292 | - */ |
|
293 | - private function _additional_attendee_reg_info_input( |
|
294 | - EE_Registration $registration, |
|
295 | - $additional_attendee_reg_info = true |
|
296 | - ) { |
|
297 | - // generate hidden input |
|
298 | - return new EE_Hidden_Input( |
|
299 | - array( |
|
300 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
301 | - 'default' => $additional_attendee_reg_info, |
|
302 | - ) |
|
303 | - ); |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * @param EE_Registration $registration |
|
309 | - * @param EE_Question_Group $question_group |
|
310 | - * @return EE_Form_Section_Proper |
|
311 | - * @throws EE_Error |
|
312 | - * @throws InvalidArgumentException |
|
313 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
314 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
315 | - */ |
|
316 | - private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
317 | - { |
|
318 | - // array of params to pass to parent constructor |
|
319 | - $form_args = array( |
|
320 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
321 | - 'html_class' => $this->checkout->admin_request |
|
322 | - ? 'form-table ee-reg-form-qstn-grp-dv' |
|
323 | - : 'ee-reg-form-qstn-grp-dv', |
|
324 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID() . '-lbl', |
|
325 | - 'subsections' => array( |
|
326 | - 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
327 | - ), |
|
328 | - 'layout_strategy' => $this->checkout->admin_request |
|
329 | - ? new EE_Admin_Two_Column_Layout() |
|
330 | - : new EE_Div_Per_Section_Layout(), |
|
331 | - ); |
|
332 | - // where params |
|
333 | - $query_params = array('QST_deleted' => 0); |
|
334 | - // don't load admin only questions on the frontend |
|
335 | - if (! $this->checkout->admin_request) { |
|
336 | - $query_params['QST_admin_only'] = array('!=', true); |
|
337 | - } |
|
338 | - $questions = $question_group->get_many_related( |
|
339 | - 'Question', |
|
340 | - apply_filters( |
|
341 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
342 | - array( |
|
343 | - $query_params, |
|
344 | - 'order_by' => array( |
|
345 | - 'Question_Group_Question.QGQ_order' => 'ASC', |
|
346 | - ), |
|
347 | - ), |
|
348 | - $question_group, |
|
349 | - $registration, |
|
350 | - $this |
|
351 | - ) |
|
352 | - ); |
|
353 | - // filter for additional content before questions |
|
354 | - $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
355 | - apply_filters( |
|
356 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
357 | - '', |
|
358 | - $registration, |
|
359 | - $question_group, |
|
360 | - $this |
|
361 | - ) |
|
362 | - ); |
|
363 | - // loop thru questions |
|
364 | - foreach ($questions as $question) { |
|
365 | - if ($question instanceof EE_Question) { |
|
366 | - $identifier = $question->is_system_question() |
|
367 | - ? $question->system_ID() |
|
368 | - : $question->ID(); |
|
369 | - $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question); |
|
370 | - } |
|
371 | - } |
|
372 | - $form_args['subsections'] = apply_filters( |
|
373 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
374 | - $form_args['subsections'], |
|
375 | - $registration, |
|
376 | - $question_group, |
|
377 | - $this |
|
378 | - ); |
|
379 | - // filter for additional content after questions |
|
380 | - $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
381 | - apply_filters( |
|
382 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
383 | - '', |
|
384 | - $registration, |
|
385 | - $question_group, |
|
386 | - $this |
|
387 | - ) |
|
388 | - ); |
|
20 | + /** |
|
21 | + * @type bool $_print_copy_info |
|
22 | + */ |
|
23 | + private $_print_copy_info = false; |
|
24 | + |
|
25 | + /** |
|
26 | + * @type array $_attendee_data |
|
27 | + */ |
|
28 | + private $_attendee_data = array(); |
|
29 | + |
|
30 | + /** |
|
31 | + * @type array $_required_questions |
|
32 | + */ |
|
33 | + private $_required_questions = array(); |
|
34 | + |
|
35 | + /** |
|
36 | + * @type array $_registration_answers |
|
37 | + */ |
|
38 | + private $_registration_answers = array(); |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * class constructor |
|
43 | + * |
|
44 | + * @access public |
|
45 | + * @param EE_Checkout $checkout |
|
46 | + */ |
|
47 | + public function __construct(EE_Checkout $checkout) |
|
48 | + { |
|
49 | + $this->_slug = 'attendee_information'; |
|
50 | + $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
51 | + $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
52 | + $this->checkout = $checkout; |
|
53 | + $this->_reset_success_message(); |
|
54 | + $this->set_instructions( |
|
55 | + esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + public function translate_js_strings() |
|
61 | + { |
|
62 | + EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
63 | + ' is a required question.', |
|
64 | + 'event_espresso' |
|
65 | + ); |
|
66 | + EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
67 | + ' is a required question. Please enter a value for at least one of the options.', |
|
68 | + 'event_espresso' |
|
69 | + ); |
|
70 | + EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
71 | + 'Please answer all required questions correctly before proceeding.', |
|
72 | + 'event_espresso' |
|
73 | + ); |
|
74 | + EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
75 | + esc_html__( |
|
76 | + 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
77 | + 'event_espresso' |
|
78 | + ), |
|
79 | + '<br/>' |
|
80 | + ); |
|
81 | + EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
82 | + 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
83 | + 'event_espresso' |
|
84 | + ); |
|
85 | + EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
86 | + 'You must enter a valid email address.', |
|
87 | + 'event_espresso' |
|
88 | + ); |
|
89 | + EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
90 | + 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
91 | + 'event_espresso' |
|
92 | + ); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + public function enqueue_styles_and_scripts() |
|
97 | + { |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return boolean |
|
103 | + */ |
|
104 | + public function initialize_reg_step() |
|
105 | + { |
|
106 | + return true; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @return EE_Form_Section_Proper |
|
112 | + * @throws EE_Error |
|
113 | + * @throws InvalidArgumentException |
|
114 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
115 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
116 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
117 | + */ |
|
118 | + public function generate_reg_form() |
|
119 | + { |
|
120 | + $this->_print_copy_info = false; |
|
121 | + $primary_registrant = null; |
|
122 | + // autoload Line_Item_Display classes |
|
123 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
124 | + $Line_Item_Display = new EE_Line_Item_Display(); |
|
125 | + // calculate taxes |
|
126 | + $Line_Item_Display->display_line_item( |
|
127 | + $this->checkout->cart->get_grand_total(), |
|
128 | + array('set_tax_rate' => true) |
|
129 | + ); |
|
130 | + /** @var $subsections EE_Form_Section_Proper[] */ |
|
131 | + $subsections = array( |
|
132 | + 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
133 | + ); |
|
134 | + $template_args = array( |
|
135 | + 'revisit' => $this->checkout->revisit, |
|
136 | + 'registrations' => array(), |
|
137 | + 'ticket_count' => array(), |
|
138 | + ); |
|
139 | + // grab the saved registrations from the transaction |
|
140 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
141 | + if ($registrations) { |
|
142 | + foreach ($registrations as $registration) { |
|
143 | + // can this registration be processed during this visit ? |
|
144 | + if ($registration instanceof EE_Registration |
|
145 | + && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
146 | + ) { |
|
147 | + $subsection = $this->_registrations_reg_form($registration); |
|
148 | + if(!$subsection instanceof EE_Form_Section_Proper) { |
|
149 | + continue; |
|
150 | + } |
|
151 | + $subsections[ $registration->reg_url_link() ] = $subsection; |
|
152 | + if (! $this->checkout->admin_request) { |
|
153 | + $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
154 | + $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
155 | + $template_args['ticket_count'][$registration->ticket()->ID()] |
|
156 | + ) |
|
157 | + ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
158 | + : 1; |
|
159 | + $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
160 | + $this->checkout->cart->get_grand_total(), |
|
161 | + 'Ticket', |
|
162 | + array($registration->ticket()->ID()) |
|
163 | + ); |
|
164 | + $ticket_line_item = is_array($ticket_line_item) |
|
165 | + ? reset($ticket_line_item) |
|
166 | + : $ticket_line_item; |
|
167 | + $template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
168 | + $Line_Item_Display->display_line_item($ticket_line_item); |
|
169 | + } |
|
170 | + if ($registration->is_primary_registrant()) { |
|
171 | + $primary_registrant = $registration->reg_url_link(); |
|
172 | + } |
|
173 | + } |
|
174 | + } |
|
175 | + // print_copy_info ? |
|
176 | + if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
177 | + // TODO: add admin option for toggling copy attendee info, |
|
178 | + // then use that value to change $this->_print_copy_info |
|
179 | + $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
180 | + ? $this->_copy_attendee_info_form() |
|
181 | + : $this->_auto_copy_attendee_info(); |
|
182 | + // generate hidden input |
|
183 | + if (isset($subsections[$primary_registrant]) |
|
184 | + && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
185 | + ) { |
|
186 | + $subsections[$primary_registrant]->add_subsections( |
|
187 | + $copy_options, |
|
188 | + 'primary_registrant', |
|
189 | + false |
|
190 | + ); |
|
191 | + } |
|
192 | + } |
|
193 | + } |
|
194 | + return new EE_Form_Section_Proper( |
|
195 | + array( |
|
196 | + 'name' => $this->reg_form_name(), |
|
197 | + 'html_id' => $this->reg_form_name(), |
|
198 | + 'subsections' => $subsections, |
|
199 | + 'layout_strategy' => $this->checkout->admin_request ? |
|
200 | + new EE_Div_Per_Section_Layout() : |
|
201 | + new EE_Template_Layout( |
|
202 | + array( |
|
203 | + 'layout_template_file' => $this->_template, // layout_template |
|
204 | + 'template_args' => $template_args, |
|
205 | + ) |
|
206 | + ), |
|
207 | + ) |
|
208 | + ); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @param EE_Registration $registration |
|
214 | + * @return EE_Form_Section_Base |
|
215 | + * @throws EE_Error |
|
216 | + * @throws InvalidArgumentException |
|
217 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
218 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
219 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
220 | + */ |
|
221 | + private function _registrations_reg_form(EE_Registration $registration) |
|
222 | + { |
|
223 | + static $attendee_nmbr = 1; |
|
224 | + $form_args = array(); |
|
225 | + // verify that registration has valid event |
|
226 | + if ($registration->event() instanceof EE_Event) { |
|
227 | + $question_groups = $registration->event()->question_groups( |
|
228 | + apply_filters( |
|
229 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
230 | + array( |
|
231 | + array( |
|
232 | + 'Event.EVT_ID' => $registration->event()->ID(), |
|
233 | + 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
234 | + ), |
|
235 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
236 | + ), |
|
237 | + $registration, |
|
238 | + $this |
|
239 | + ) |
|
240 | + ); |
|
241 | + if ($question_groups) { |
|
242 | + // array of params to pass to parent constructor |
|
243 | + $form_args = array( |
|
244 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
245 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
246 | + 'html_style' => $this->checkout->admin_request |
|
247 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
248 | + : '', |
|
249 | + 'subsections' => array(), |
|
250 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
251 | + array( |
|
252 | + 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
253 | + 'legend_text' => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr), |
|
254 | + ) |
|
255 | + ), |
|
256 | + ); |
|
257 | + foreach ($question_groups as $question_group) { |
|
258 | + if ($question_group instanceof EE_Question_Group) { |
|
259 | + $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form( |
|
260 | + $registration, |
|
261 | + $question_group |
|
262 | + ); |
|
263 | + } |
|
264 | + } |
|
265 | + // add hidden input |
|
266 | + $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
267 | + $registration |
|
268 | + ); |
|
269 | + // if we have question groups for additional attendees, then display the copy options |
|
270 | + $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
|
271 | + if ($registration->is_primary_registrant()) { |
|
272 | + // generate hidden input |
|
273 | + $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
274 | + $registration |
|
275 | + ); |
|
276 | + } |
|
277 | + } |
|
278 | + } |
|
279 | + $attendee_nmbr++; |
|
280 | + return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : null; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * _additional_attendee_reg_info_input |
|
286 | + * |
|
287 | + * @access public |
|
288 | + * @param EE_Registration $registration |
|
289 | + * @param bool $additional_attendee_reg_info |
|
290 | + * @return EE_Form_Input_Base |
|
291 | + * @throws \EE_Error |
|
292 | + */ |
|
293 | + private function _additional_attendee_reg_info_input( |
|
294 | + EE_Registration $registration, |
|
295 | + $additional_attendee_reg_info = true |
|
296 | + ) { |
|
297 | + // generate hidden input |
|
298 | + return new EE_Hidden_Input( |
|
299 | + array( |
|
300 | + 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
301 | + 'default' => $additional_attendee_reg_info, |
|
302 | + ) |
|
303 | + ); |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * @param EE_Registration $registration |
|
309 | + * @param EE_Question_Group $question_group |
|
310 | + * @return EE_Form_Section_Proper |
|
311 | + * @throws EE_Error |
|
312 | + * @throws InvalidArgumentException |
|
313 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
314 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
315 | + */ |
|
316 | + private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
317 | + { |
|
318 | + // array of params to pass to parent constructor |
|
319 | + $form_args = array( |
|
320 | + 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
321 | + 'html_class' => $this->checkout->admin_request |
|
322 | + ? 'form-table ee-reg-form-qstn-grp-dv' |
|
323 | + : 'ee-reg-form-qstn-grp-dv', |
|
324 | + 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID() . '-lbl', |
|
325 | + 'subsections' => array( |
|
326 | + 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
327 | + ), |
|
328 | + 'layout_strategy' => $this->checkout->admin_request |
|
329 | + ? new EE_Admin_Two_Column_Layout() |
|
330 | + : new EE_Div_Per_Section_Layout(), |
|
331 | + ); |
|
332 | + // where params |
|
333 | + $query_params = array('QST_deleted' => 0); |
|
334 | + // don't load admin only questions on the frontend |
|
335 | + if (! $this->checkout->admin_request) { |
|
336 | + $query_params['QST_admin_only'] = array('!=', true); |
|
337 | + } |
|
338 | + $questions = $question_group->get_many_related( |
|
339 | + 'Question', |
|
340 | + apply_filters( |
|
341 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
342 | + array( |
|
343 | + $query_params, |
|
344 | + 'order_by' => array( |
|
345 | + 'Question_Group_Question.QGQ_order' => 'ASC', |
|
346 | + ), |
|
347 | + ), |
|
348 | + $question_group, |
|
349 | + $registration, |
|
350 | + $this |
|
351 | + ) |
|
352 | + ); |
|
353 | + // filter for additional content before questions |
|
354 | + $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
355 | + apply_filters( |
|
356 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
357 | + '', |
|
358 | + $registration, |
|
359 | + $question_group, |
|
360 | + $this |
|
361 | + ) |
|
362 | + ); |
|
363 | + // loop thru questions |
|
364 | + foreach ($questions as $question) { |
|
365 | + if ($question instanceof EE_Question) { |
|
366 | + $identifier = $question->is_system_question() |
|
367 | + ? $question->system_ID() |
|
368 | + : $question->ID(); |
|
369 | + $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question); |
|
370 | + } |
|
371 | + } |
|
372 | + $form_args['subsections'] = apply_filters( |
|
373 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
374 | + $form_args['subsections'], |
|
375 | + $registration, |
|
376 | + $question_group, |
|
377 | + $this |
|
378 | + ); |
|
379 | + // filter for additional content after questions |
|
380 | + $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
381 | + apply_filters( |
|
382 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
383 | + '', |
|
384 | + $registration, |
|
385 | + $question_group, |
|
386 | + $this |
|
387 | + ) |
|
388 | + ); |
|
389 | 389 | // d( $form_args ); |
390 | - $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
391 | - return apply_filters( |
|
392 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
393 | - $question_group_reg_form, |
|
394 | - $registration, |
|
395 | - $question_group, |
|
396 | - $this |
|
397 | - ); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * @access public |
|
403 | - * @param EE_Question_Group $question_group |
|
404 | - * @return EE_Form_Section_HTML |
|
405 | - */ |
|
406 | - private function _question_group_header(EE_Question_Group $question_group) |
|
407 | - { |
|
408 | - $html = ''; |
|
409 | - // group_name |
|
410 | - if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
411 | - if ($this->checkout->admin_request) { |
|
412 | - $html .= EEH_HTML::br(); |
|
413 | - $html .= EEH_HTML::h3( |
|
414 | - $question_group->name(), |
|
415 | - '', |
|
416 | - 'ee-reg-form-qstn-grp-title title', |
|
417 | - 'font-size: 1.3em; padding-left:0;' |
|
418 | - ); |
|
419 | - } else { |
|
420 | - $html .= EEH_HTML::h4( |
|
421 | - $question_group->name(), |
|
422 | - '', |
|
423 | - 'ee-reg-form-qstn-grp-title section-title' |
|
424 | - ); |
|
425 | - } |
|
426 | - } |
|
427 | - // group_desc |
|
428 | - if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
429 | - $html .= EEH_HTML::p( |
|
430 | - $question_group->desc(), |
|
431 | - '', |
|
432 | - $this->checkout->admin_request |
|
433 | - ? 'ee-reg-form-qstn-grp-desc-pg' |
|
434 | - : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
435 | - ); |
|
436 | - } |
|
437 | - return new EE_Form_Section_HTML($html); |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * @access public |
|
443 | - * @return EE_Form_Section_Proper |
|
444 | - * @throws \EE_Error |
|
445 | - */ |
|
446 | - private function _copy_attendee_info_form() |
|
447 | - { |
|
448 | - // array of params to pass to parent constructor |
|
449 | - return new EE_Form_Section_Proper( |
|
450 | - array( |
|
451 | - 'subsections' => $this->_copy_attendee_info_inputs(), |
|
452 | - 'layout_strategy' => new EE_Template_Layout( |
|
453 | - array( |
|
454 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
455 | - . $this->_slug |
|
456 | - . DS |
|
457 | - . 'copy_attendee_info.template.php', |
|
458 | - 'begin_template_file' => null, |
|
459 | - 'input_template_file' => null, |
|
460 | - 'subsection_template_file' => null, |
|
461 | - 'end_template_file' => null, |
|
462 | - ) |
|
463 | - ), |
|
464 | - ) |
|
465 | - ); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * _auto_copy_attendee_info |
|
471 | - * |
|
472 | - * @access public |
|
473 | - * @return EE_Form_Section_HTML |
|
474 | - */ |
|
475 | - private function _auto_copy_attendee_info() |
|
476 | - { |
|
477 | - return new EE_Form_Section_HTML( |
|
478 | - EEH_Template::locate_template( |
|
479 | - SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
480 | - apply_filters( |
|
481 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
482 | - array() |
|
483 | - ), |
|
484 | - true, |
|
485 | - true |
|
486 | - ) |
|
487 | - ); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * _copy_attendee_info_inputs |
|
493 | - * |
|
494 | - * @access public |
|
495 | - * @return array |
|
496 | - * @throws \EE_Error |
|
497 | - */ |
|
498 | - private function _copy_attendee_info_inputs() |
|
499 | - { |
|
500 | - $copy_attendee_info_inputs = array(); |
|
501 | - $prev_ticket = null; |
|
502 | - // grab the saved registrations from the transaction |
|
503 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
504 | - foreach ($registrations as $registration) { |
|
505 | - // for all attendees other than the primary attendee |
|
506 | - if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
507 | - // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
508 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
509 | - $item_name = $registration->ticket()->name(); |
|
510 | - $item_name .= $registration->ticket()->description() !== '' |
|
511 | - ? ' - ' . $registration->ticket()->description() |
|
512 | - : ''; |
|
513 | - $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] = |
|
514 | - new EE_Form_Section_HTML( |
|
515 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
516 | - ); |
|
517 | - $prev_ticket = $registration->ticket()->ID(); |
|
518 | - } |
|
519 | - |
|
520 | - $copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] = |
|
521 | - new EE_Checkbox_Multi_Input( |
|
522 | - array( |
|
523 | - $registration->ID() => sprintf( |
|
524 | - esc_html__('Attendee #%s', 'event_espresso'), |
|
525 | - $registration->count() |
|
526 | - ), |
|
527 | - ), |
|
528 | - array( |
|
529 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
530 | - 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
531 | - 'display_html_label_text' => false, |
|
532 | - ) |
|
533 | - ); |
|
534 | - } |
|
535 | - } |
|
536 | - return $copy_attendee_info_inputs; |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * _additional_primary_registrant_inputs |
|
542 | - * |
|
543 | - * @access public |
|
544 | - * @param EE_Registration $registration |
|
545 | - * @return EE_Form_Input_Base |
|
546 | - * @throws \EE_Error |
|
547 | - */ |
|
548 | - private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
549 | - { |
|
550 | - // generate hidden input |
|
551 | - return new EE_Hidden_Input( |
|
552 | - array( |
|
553 | - 'html_id' => 'primary_registrant', |
|
554 | - 'default' => $registration->reg_url_link(), |
|
555 | - ) |
|
556 | - ); |
|
557 | - } |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * @access public |
|
562 | - * @param EE_Registration $registration |
|
563 | - * @param EE_Question $question |
|
564 | - * @return EE_Form_Input_Base |
|
565 | - * @throws EE_Error |
|
566 | - * @throws InvalidArgumentException |
|
567 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
568 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
569 | - */ |
|
570 | - public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
571 | - { |
|
572 | - |
|
573 | - // if this question was for an attendee detail, then check for that answer |
|
574 | - $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
575 | - $registration, |
|
576 | - $question->system_ID() |
|
577 | - ); |
|
578 | - $answer = $answer_value === null |
|
579 | - ? EEM_Answer::instance()->get_one( |
|
580 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
581 | - ) |
|
582 | - : null; |
|
583 | - // if NOT returning to edit an existing registration |
|
584 | - // OR if this question is for an attendee property |
|
585 | - // OR we still don't have an EE_Answer object |
|
586 | - if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
587 | - // create an EE_Answer object for storing everything in |
|
588 | - $answer = EE_Answer::new_instance(array( |
|
589 | - 'QST_ID' => $question->ID(), |
|
590 | - 'REG_ID' => $registration->ID(), |
|
591 | - )); |
|
592 | - } |
|
593 | - // verify instance |
|
594 | - if ($answer instanceof EE_Answer) { |
|
595 | - if (! empty($answer_value)) { |
|
596 | - $answer->set('ANS_value', $answer_value); |
|
597 | - } |
|
598 | - $answer->cache('Question', $question); |
|
599 | - //remember system ID had a bug where sometimes it could be null |
|
600 | - $answer_cache_id = $question->is_system_question() |
|
601 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
602 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
603 | - $registration->cache('Answer', $answer, $answer_cache_id); |
|
604 | - } |
|
605 | - return $this->_generate_question_input($registration, $question, $answer); |
|
606 | - } |
|
607 | - |
|
608 | - |
|
609 | - /** |
|
610 | - * @param EE_Registration $registration |
|
611 | - * @param EE_Question $question |
|
612 | - * @param mixed EE_Answer|NULL $answer |
|
613 | - * @return EE_Form_Input_Base |
|
614 | - * @throws \EE_Error |
|
615 | - */ |
|
616 | - private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
617 | - { |
|
618 | - $identifier = $question->is_system_question() |
|
619 | - ? $question->system_ID() |
|
620 | - : $question->ID(); |
|
621 | - $this->_required_questions[$identifier] = $question->required() ? true : false; |
|
622 | - add_filter( |
|
623 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
624 | - array($this, 'use_cached_countries_for_form_input'), |
|
625 | - 10, |
|
626 | - 4 |
|
627 | - ); |
|
628 | - add_filter( |
|
629 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
630 | - array($this, 'use_cached_states_for_form_input'), |
|
631 | - 10, |
|
632 | - 4 |
|
633 | - ); |
|
634 | - $input_constructor_args = array( |
|
635 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
636 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
637 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
638 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
639 | - 'html_label_class' => 'ee-reg-qstn', |
|
640 | - ); |
|
641 | - $input_constructor_args['html_label_id'] .= '-lbl'; |
|
642 | - if ($answer instanceof EE_Answer && $answer->ID()) { |
|
643 | - $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
644 | - $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
645 | - $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
646 | - } |
|
647 | - $form_input = $question->generate_form_input( |
|
648 | - $registration, |
|
649 | - $answer, |
|
650 | - $input_constructor_args |
|
651 | - ); |
|
652 | - remove_filter( |
|
653 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
654 | - array($this, 'use_cached_countries_for_form_input') |
|
655 | - ); |
|
656 | - remove_filter( |
|
657 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
658 | - array($this, 'use_cached_states_for_form_input') |
|
659 | - ); |
|
660 | - return $form_input; |
|
661 | - } |
|
662 | - |
|
663 | - |
|
664 | - /** |
|
665 | - * Gets the list of countries for the form input |
|
666 | - * |
|
667 | - * @param array|null $countries_list |
|
668 | - * @param \EE_Question $question |
|
669 | - * @param \EE_Registration $registration |
|
670 | - * @param \EE_Answer $answer |
|
671 | - * @return array 2d keys are country IDs, values are their names |
|
672 | - * @throws EE_Error |
|
673 | - * @throws InvalidArgumentException |
|
674 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
675 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
676 | - */ |
|
677 | - public function use_cached_countries_for_form_input( |
|
678 | - $countries_list, |
|
679 | - \EE_Question $question = null, |
|
680 | - \EE_Registration $registration = null, |
|
681 | - \EE_Answer $answer = null |
|
682 | - ) { |
|
683 | - $country_options = array('' => ''); |
|
684 | - // get possibly cached list of countries |
|
685 | - $countries = $this->checkout->action === 'process_reg_step' |
|
686 | - ? EEM_Country::instance()->get_all_countries() |
|
687 | - : EEM_Country::instance()->get_all_active_countries(); |
|
688 | - if (! empty($countries)) { |
|
689 | - foreach ($countries as $country) { |
|
690 | - if ($country instanceof EE_Country) { |
|
691 | - $country_options[$country->ID()] = $country->name(); |
|
692 | - } |
|
693 | - } |
|
694 | - } |
|
695 | - if ($question instanceof EE_Question |
|
696 | - && $registration instanceof EE_Registration) { |
|
697 | - $answer = EEM_Answer::instance()->get_one( |
|
698 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
699 | - ); |
|
700 | - } else { |
|
701 | - $answer = EE_Answer::new_instance(); |
|
702 | - } |
|
703 | - $country_options = apply_filters( |
|
704 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
705 | - $country_options, |
|
706 | - $this, |
|
707 | - $registration, |
|
708 | - $question, |
|
709 | - $answer |
|
710 | - ); |
|
711 | - return $country_options; |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * Gets the list of states for the form input |
|
717 | - * |
|
718 | - * @param array|null $states_list |
|
719 | - * @param \EE_Question $question |
|
720 | - * @param \EE_Registration $registration |
|
721 | - * @param \EE_Answer $answer |
|
722 | - * @return array 2d keys are state IDs, values are their names |
|
723 | - * @throws EE_Error |
|
724 | - * @throws InvalidArgumentException |
|
725 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
726 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
727 | - */ |
|
728 | - public function use_cached_states_for_form_input( |
|
729 | - $states_list, |
|
730 | - \EE_Question $question = null, |
|
731 | - \EE_Registration $registration = null, |
|
732 | - \EE_Answer $answer = null |
|
733 | - ) { |
|
734 | - $state_options = array('' => array('' => '')); |
|
735 | - $states = $this->checkout->action === 'process_reg_step' |
|
736 | - ? EEM_State::instance()->get_all_states() |
|
737 | - : EEM_State::instance()->get_all_active_states(); |
|
738 | - if (! empty($states)) { |
|
739 | - foreach ($states as $state) { |
|
740 | - if ($state instanceof EE_State) { |
|
741 | - $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
742 | - } |
|
743 | - } |
|
744 | - } |
|
745 | - $state_options = apply_filters( |
|
746 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
747 | - $state_options, |
|
748 | - $this, |
|
749 | - $registration, |
|
750 | - $question, |
|
751 | - $answer |
|
752 | - ); |
|
753 | - return $state_options; |
|
754 | - } |
|
755 | - |
|
756 | - |
|
757 | - |
|
758 | - |
|
759 | - |
|
760 | - |
|
761 | - /********************************************************************************************************/ |
|
762 | - /**************************************** PROCESS REG STEP ****************************************/ |
|
763 | - /********************************************************************************************************/ |
|
764 | - /** |
|
765 | - * @return bool |
|
766 | - * @throws EE_Error |
|
767 | - * @throws InvalidArgumentException |
|
768 | - * @throws ReflectionException |
|
769 | - * @throws RuntimeException |
|
770 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
771 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
772 | - */ |
|
773 | - public function process_reg_step() |
|
774 | - { |
|
775 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
776 | - // grab validated data from form |
|
777 | - $valid_data = $this->checkout->current_step->valid_data(); |
|
778 | - // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
779 | - // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
780 | - // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
781 | - if (empty($valid_data)) { |
|
782 | - EE_Error::add_error( |
|
783 | - esc_html__('No valid question responses were received.', 'event_espresso'), |
|
784 | - __FILE__, |
|
785 | - __FUNCTION__, |
|
786 | - __LINE__ |
|
787 | - ); |
|
788 | - return false; |
|
789 | - } |
|
790 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
791 | - EE_Error::add_error( |
|
792 | - esc_html__( |
|
793 | - 'A valid transaction could not be initiated for processing your registrations.', |
|
794 | - 'event_espresso' |
|
795 | - ), |
|
796 | - __FILE__, |
|
797 | - __FUNCTION__, |
|
798 | - __LINE__ |
|
799 | - ); |
|
800 | - return false; |
|
801 | - } |
|
802 | - // get cached registrations |
|
803 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
804 | - // verify we got the goods |
|
805 | - if (empty($registrations)) { |
|
806 | - //combine the old translated string with a new one, in order to not break translations |
|
807 | - $error_message = esc_html__( 'Your form data could not be applied to any valid registrations.', 'event_espresso' ) |
|
808 | - . sprintf( |
|
809 | - esc_html__('%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', 'event_espresso'), |
|
810 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
811 | - '</a>', |
|
812 | - '<br />' |
|
813 | - ); |
|
814 | - EE_Error::add_error( |
|
815 | - $error_message, |
|
816 | - __FILE__, |
|
817 | - __FUNCTION__, |
|
818 | - __LINE__ |
|
819 | - ); |
|
820 | - return false; |
|
821 | - } |
|
822 | - // extract attendee info from form data and save to model objects |
|
823 | - $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
824 | - // if first pass thru SPCO, |
|
825 | - // then let's check processed registrations against the total number of tickets in the cart |
|
826 | - if ($registrations_processed === false) { |
|
827 | - // but return immediately if the previous step exited early due to errors |
|
828 | - return false; |
|
829 | - } elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
830 | - // generate a correctly translated string for all possible singular/plural combinations |
|
831 | - if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
832 | - $error_msg = sprintf( |
|
833 | - esc_html__( |
|
834 | - 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
835 | - 'event_espresso' |
|
836 | - ), |
|
837 | - $this->checkout->total_ticket_count, |
|
838 | - $registrations_processed |
|
839 | - ); |
|
840 | - } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
841 | - $error_msg = sprintf( |
|
842 | - esc_html__( |
|
843 | - 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
844 | - 'event_espresso' |
|
845 | - ), |
|
846 | - $this->checkout->total_ticket_count, |
|
847 | - $registrations_processed |
|
848 | - ); |
|
849 | - } else { |
|
850 | - $error_msg = sprintf( |
|
851 | - esc_html__( |
|
852 | - 'There was a total of %1$d tickets in the Event Queue, but %2$ds registrations were processed', |
|
853 | - 'event_espresso' |
|
854 | - ), |
|
855 | - $this->checkout->total_ticket_count, |
|
856 | - $registrations_processed |
|
857 | - ); |
|
858 | - } |
|
859 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
860 | - return false; |
|
861 | - } |
|
862 | - // mark this reg step as completed |
|
863 | - $this->set_completed(); |
|
864 | - $this->_set_success_message( |
|
865 | - esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
866 | - ); |
|
867 | - //do action in case a plugin wants to do something with the data submitted in step 1. |
|
868 | - //passes EE_Single_Page_Checkout, and it's posted data |
|
869 | - do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
870 | - return true; |
|
871 | - } |
|
872 | - |
|
873 | - |
|
874 | - /** |
|
875 | - * _process_registrations |
|
876 | - * |
|
877 | - * @param EE_Registration[] $registrations |
|
878 | - * @param array $valid_data |
|
879 | - * @return bool|int |
|
880 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
881 | - * @throws EE_Error |
|
882 | - * @throws InvalidArgumentException |
|
883 | - * @throws ReflectionException |
|
884 | - * @throws RuntimeException |
|
885 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
886 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
887 | - */ |
|
888 | - private function _process_registrations($registrations = array(), $valid_data = array()) |
|
889 | - { |
|
890 | - // load resources and set some defaults |
|
891 | - EE_Registry::instance()->load_model('Attendee'); |
|
892 | - // holder for primary registrant attendee object |
|
893 | - $this->checkout->primary_attendee_obj = null; |
|
894 | - // array for tracking reg form data for the primary registrant |
|
895 | - $primary_registrant = array( |
|
896 | - 'line_item_id' => null, |
|
897 | - ); |
|
898 | - $copy_primary = false; |
|
899 | - // reg form sections that do not contain inputs |
|
900 | - $non_input_form_sections = array( |
|
901 | - 'primary_registrant', |
|
902 | - 'additional_attendee_reg_info', |
|
903 | - 'spco_copy_attendee_chk', |
|
904 | - ); |
|
905 | - // attendee counter |
|
906 | - $att_nmbr = 0; |
|
907 | - // grab the saved registrations from the transaction |
|
908 | - foreach ($registrations as $registration) { |
|
909 | - // verify EE_Registration object |
|
910 | - if (! $registration instanceof EE_Registration) { |
|
911 | - EE_Error::add_error( |
|
912 | - esc_html__( |
|
913 | - 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
914 | - 'event_espresso' |
|
915 | - ), |
|
916 | - __FILE__, |
|
917 | - __FUNCTION__, |
|
918 | - __LINE__ |
|
919 | - ); |
|
920 | - return false; |
|
921 | - } |
|
922 | - /** @var string $reg_url_link */ |
|
923 | - $reg_url_link = $registration->reg_url_link(); |
|
924 | - // reg_url_link exists ? |
|
925 | - if (! empty($reg_url_link)) { |
|
926 | - // should this registration be processed during this visit ? |
|
927 | - if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
928 | - // if NOT revisiting, then let's save the registration now, |
|
929 | - // so that we have a REG_ID to use when generating other objects |
|
930 | - if (! $this->checkout->revisit) { |
|
931 | - $registration->save(); |
|
932 | - } |
|
933 | - /** |
|
934 | - * This allows plugins to trigger a fail on processing of a |
|
935 | - * registration for any conditions they may have for it to pass. |
|
936 | - * |
|
937 | - * @var bool if true is returned by the plugin then the |
|
938 | - * registration processing is halted. |
|
939 | - */ |
|
940 | - if (apply_filters( |
|
941 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
942 | - false, |
|
943 | - $att_nmbr, |
|
944 | - $registration, |
|
945 | - $registrations, |
|
946 | - $valid_data, |
|
947 | - $this |
|
948 | - )) { |
|
949 | - return false; |
|
950 | - } |
|
951 | - |
|
952 | - // Houston, we have a registration! |
|
953 | - $att_nmbr++; |
|
954 | - $this->_attendee_data[$reg_url_link] = array(); |
|
955 | - // grab any existing related answer objects |
|
956 | - $this->_registration_answers = $registration->answers(); |
|
957 | - // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
958 | - if (isset($valid_data[$reg_url_link])) { |
|
959 | - // do we need to copy basic info from primary attendee ? |
|
960 | - $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info']) |
|
961 | - && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0 |
|
962 | - ? true |
|
963 | - : false; |
|
964 | - // filter form input data for this registration |
|
965 | - $valid_data[$reg_url_link] = (array)apply_filters( |
|
966 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
967 | - $valid_data[$reg_url_link] |
|
968 | - ); |
|
969 | - if (isset($valid_data['primary_attendee'])) { |
|
970 | - $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
971 | - ? $valid_data['primary_attendee'] |
|
972 | - : false; |
|
973 | - unset($valid_data['primary_attendee']); |
|
974 | - } |
|
975 | - // now loop through our array of valid post data && process attendee reg forms |
|
976 | - foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
|
977 | - if (! in_array($form_section, $non_input_form_sections)) { |
|
978 | - foreach ($form_inputs as $form_input => $input_value) { |
|
979 | - // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
980 | - // check for critical inputs |
|
981 | - if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
982 | - $form_input, |
|
983 | - $input_value |
|
984 | - ) |
|
985 | - ) { |
|
986 | - return false; |
|
987 | - } |
|
988 | - // store a bit of data about the primary attendee |
|
989 | - if ($att_nmbr === 1 |
|
990 | - && ! empty($input_value) |
|
991 | - && $reg_url_link === $primary_registrant['line_item_id'] |
|
992 | - ) { |
|
993 | - $primary_registrant[$form_input] = $input_value; |
|
994 | - } elseif ($copy_primary |
|
995 | - && $input_value === null |
|
996 | - && isset($primary_registrant[$form_input]) |
|
997 | - ) { |
|
998 | - $input_value = $primary_registrant[$form_input]; |
|
999 | - } |
|
1000 | - // now attempt to save the input data |
|
1001 | - if (! $this->_save_registration_form_input( |
|
1002 | - $registration, |
|
1003 | - $form_input, |
|
1004 | - $input_value |
|
1005 | - ) |
|
1006 | - ) { |
|
1007 | - EE_Error::add_error( |
|
1008 | - sprintf( |
|
1009 | - esc_html__( |
|
1010 | - 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
1011 | - 'event_espresso' |
|
1012 | - ), |
|
1013 | - $form_input, |
|
1014 | - $input_value |
|
1015 | - ), |
|
1016 | - __FILE__, |
|
1017 | - __FUNCTION__, |
|
1018 | - __LINE__ |
|
1019 | - ); |
|
1020 | - return false; |
|
1021 | - } |
|
1022 | - } |
|
1023 | - } |
|
1024 | - } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
1025 | - } |
|
1026 | - //EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
1027 | - // this registration does not require additional attendee information ? |
|
1028 | - if ($copy_primary |
|
1029 | - && $att_nmbr > 1 |
|
1030 | - && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
1031 | - ) { |
|
1032 | - // just copy the primary registrant |
|
1033 | - $attendee = $this->checkout->primary_attendee_obj; |
|
1034 | - } else { |
|
1035 | - // ensure critical details are set for additional attendees |
|
1036 | - $this->_attendee_data[$reg_url_link] = $att_nmbr > 1 |
|
1037 | - ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
1038 | - $this->_attendee_data[$reg_url_link] |
|
1039 | - ) |
|
1040 | - : $this->_attendee_data[$reg_url_link]; |
|
1041 | - // execute create attendee command (which may return an existing attendee) |
|
1042 | - $attendee = EE_Registry::instance()->BUS->execute( |
|
1043 | - new CreateAttendeeCommand( |
|
1044 | - $this->_attendee_data[$reg_url_link], |
|
1045 | - $registration |
|
1046 | - ) |
|
1047 | - ); |
|
1048 | - // who's #1 ? |
|
1049 | - if ($att_nmbr === 1) { |
|
1050 | - $this->checkout->primary_attendee_obj = $attendee; |
|
1051 | - } |
|
1052 | - } |
|
1053 | - // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
1054 | - // add relation to registration, set attendee ID, and cache attendee |
|
1055 | - $this->_associate_attendee_with_registration($registration, $attendee); |
|
1056 | - // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
1057 | - if (! $registration->attendee() instanceof EE_Attendee) { |
|
1058 | - EE_Error::add_error( |
|
1059 | - sprintf( |
|
1060 | - esc_html__( |
|
1061 | - 'Registration %s has an invalid or missing Attendee object.', |
|
1062 | - 'event_espresso' |
|
1063 | - ), |
|
1064 | - $reg_url_link |
|
1065 | - ), |
|
1066 | - __FILE__, |
|
1067 | - __FUNCTION__, |
|
1068 | - __LINE__ |
|
1069 | - ); |
|
1070 | - return false; |
|
1071 | - } |
|
1072 | - /** @type EE_Registration_Processor $registration_processor */ |
|
1073 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1074 | - // at this point, we should have enough details about the registrant to consider the registration |
|
1075 | - // NOT incomplete |
|
1076 | - $registration_processor->toggle_incomplete_registration_status_to_default( |
|
1077 | - $registration, |
|
1078 | - false, |
|
1079 | - new Context( |
|
1080 | - 'spco_reg_step_attendee_information_process_registrations', |
|
1081 | - esc_html__( |
|
1082 | - 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
1083 | - 'event_espresso' |
|
1084 | - ) |
|
1085 | - ) |
|
1086 | - ); |
|
1087 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
1088 | - // abandoned |
|
1089 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1090 | - // if we've gotten this far, then let's save what we have |
|
1091 | - $registration->save(); |
|
1092 | - // add relation between TXN and registration |
|
1093 | - $this->_associate_registration_with_transaction($registration); |
|
1094 | - } |
|
1095 | - } else { |
|
1096 | - EE_Error::add_error( |
|
1097 | - esc_html__( |
|
1098 | - 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
1099 | - 'event_espresso' |
|
1100 | - ), |
|
1101 | - __FILE__, |
|
1102 | - __FUNCTION__, |
|
1103 | - __LINE__ |
|
1104 | - ); |
|
1105 | - // remove malformed data |
|
1106 | - unset($valid_data[$reg_url_link]); |
|
1107 | - return false; |
|
1108 | - } |
|
1109 | - |
|
1110 | - } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
1111 | - return $att_nmbr; |
|
1112 | - } |
|
1113 | - |
|
1114 | - |
|
1115 | - /** |
|
1116 | - * _save_registration_form_input |
|
1117 | - * |
|
1118 | - * @param EE_Registration $registration |
|
1119 | - * @param string $form_input |
|
1120 | - * @param string $input_value |
|
1121 | - * @return bool |
|
1122 | - * @throws EE_Error |
|
1123 | - * @throws InvalidArgumentException |
|
1124 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1125 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1126 | - */ |
|
1127 | - private function _save_registration_form_input( |
|
1128 | - EE_Registration $registration, |
|
1129 | - $form_input = '', |
|
1130 | - $input_value = '' |
|
1131 | - ) { |
|
1132 | - // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
1133 | - // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
1134 | - // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
1135 | - // allow for plugins to hook in and do their own processing of the form input. |
|
1136 | - // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
1137 | - if (apply_filters( |
|
1138 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
1139 | - false, |
|
1140 | - $registration, |
|
1141 | - $form_input, |
|
1142 | - $input_value, |
|
1143 | - $this |
|
1144 | - )) { |
|
1145 | - return true; |
|
1146 | - } |
|
1147 | - /* |
|
390 | + $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
391 | + return apply_filters( |
|
392 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
393 | + $question_group_reg_form, |
|
394 | + $registration, |
|
395 | + $question_group, |
|
396 | + $this |
|
397 | + ); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * @access public |
|
403 | + * @param EE_Question_Group $question_group |
|
404 | + * @return EE_Form_Section_HTML |
|
405 | + */ |
|
406 | + private function _question_group_header(EE_Question_Group $question_group) |
|
407 | + { |
|
408 | + $html = ''; |
|
409 | + // group_name |
|
410 | + if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
411 | + if ($this->checkout->admin_request) { |
|
412 | + $html .= EEH_HTML::br(); |
|
413 | + $html .= EEH_HTML::h3( |
|
414 | + $question_group->name(), |
|
415 | + '', |
|
416 | + 'ee-reg-form-qstn-grp-title title', |
|
417 | + 'font-size: 1.3em; padding-left:0;' |
|
418 | + ); |
|
419 | + } else { |
|
420 | + $html .= EEH_HTML::h4( |
|
421 | + $question_group->name(), |
|
422 | + '', |
|
423 | + 'ee-reg-form-qstn-grp-title section-title' |
|
424 | + ); |
|
425 | + } |
|
426 | + } |
|
427 | + // group_desc |
|
428 | + if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
429 | + $html .= EEH_HTML::p( |
|
430 | + $question_group->desc(), |
|
431 | + '', |
|
432 | + $this->checkout->admin_request |
|
433 | + ? 'ee-reg-form-qstn-grp-desc-pg' |
|
434 | + : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
435 | + ); |
|
436 | + } |
|
437 | + return new EE_Form_Section_HTML($html); |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * @access public |
|
443 | + * @return EE_Form_Section_Proper |
|
444 | + * @throws \EE_Error |
|
445 | + */ |
|
446 | + private function _copy_attendee_info_form() |
|
447 | + { |
|
448 | + // array of params to pass to parent constructor |
|
449 | + return new EE_Form_Section_Proper( |
|
450 | + array( |
|
451 | + 'subsections' => $this->_copy_attendee_info_inputs(), |
|
452 | + 'layout_strategy' => new EE_Template_Layout( |
|
453 | + array( |
|
454 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
455 | + . $this->_slug |
|
456 | + . DS |
|
457 | + . 'copy_attendee_info.template.php', |
|
458 | + 'begin_template_file' => null, |
|
459 | + 'input_template_file' => null, |
|
460 | + 'subsection_template_file' => null, |
|
461 | + 'end_template_file' => null, |
|
462 | + ) |
|
463 | + ), |
|
464 | + ) |
|
465 | + ); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * _auto_copy_attendee_info |
|
471 | + * |
|
472 | + * @access public |
|
473 | + * @return EE_Form_Section_HTML |
|
474 | + */ |
|
475 | + private function _auto_copy_attendee_info() |
|
476 | + { |
|
477 | + return new EE_Form_Section_HTML( |
|
478 | + EEH_Template::locate_template( |
|
479 | + SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
480 | + apply_filters( |
|
481 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
482 | + array() |
|
483 | + ), |
|
484 | + true, |
|
485 | + true |
|
486 | + ) |
|
487 | + ); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * _copy_attendee_info_inputs |
|
493 | + * |
|
494 | + * @access public |
|
495 | + * @return array |
|
496 | + * @throws \EE_Error |
|
497 | + */ |
|
498 | + private function _copy_attendee_info_inputs() |
|
499 | + { |
|
500 | + $copy_attendee_info_inputs = array(); |
|
501 | + $prev_ticket = null; |
|
502 | + // grab the saved registrations from the transaction |
|
503 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
504 | + foreach ($registrations as $registration) { |
|
505 | + // for all attendees other than the primary attendee |
|
506 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
507 | + // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
508 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
509 | + $item_name = $registration->ticket()->name(); |
|
510 | + $item_name .= $registration->ticket()->description() !== '' |
|
511 | + ? ' - ' . $registration->ticket()->description() |
|
512 | + : ''; |
|
513 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] = |
|
514 | + new EE_Form_Section_HTML( |
|
515 | + '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
516 | + ); |
|
517 | + $prev_ticket = $registration->ticket()->ID(); |
|
518 | + } |
|
519 | + |
|
520 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] = |
|
521 | + new EE_Checkbox_Multi_Input( |
|
522 | + array( |
|
523 | + $registration->ID() => sprintf( |
|
524 | + esc_html__('Attendee #%s', 'event_espresso'), |
|
525 | + $registration->count() |
|
526 | + ), |
|
527 | + ), |
|
528 | + array( |
|
529 | + 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
530 | + 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
531 | + 'display_html_label_text' => false, |
|
532 | + ) |
|
533 | + ); |
|
534 | + } |
|
535 | + } |
|
536 | + return $copy_attendee_info_inputs; |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * _additional_primary_registrant_inputs |
|
542 | + * |
|
543 | + * @access public |
|
544 | + * @param EE_Registration $registration |
|
545 | + * @return EE_Form_Input_Base |
|
546 | + * @throws \EE_Error |
|
547 | + */ |
|
548 | + private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
549 | + { |
|
550 | + // generate hidden input |
|
551 | + return new EE_Hidden_Input( |
|
552 | + array( |
|
553 | + 'html_id' => 'primary_registrant', |
|
554 | + 'default' => $registration->reg_url_link(), |
|
555 | + ) |
|
556 | + ); |
|
557 | + } |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * @access public |
|
562 | + * @param EE_Registration $registration |
|
563 | + * @param EE_Question $question |
|
564 | + * @return EE_Form_Input_Base |
|
565 | + * @throws EE_Error |
|
566 | + * @throws InvalidArgumentException |
|
567 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
568 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
569 | + */ |
|
570 | + public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
571 | + { |
|
572 | + |
|
573 | + // if this question was for an attendee detail, then check for that answer |
|
574 | + $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
575 | + $registration, |
|
576 | + $question->system_ID() |
|
577 | + ); |
|
578 | + $answer = $answer_value === null |
|
579 | + ? EEM_Answer::instance()->get_one( |
|
580 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
581 | + ) |
|
582 | + : null; |
|
583 | + // if NOT returning to edit an existing registration |
|
584 | + // OR if this question is for an attendee property |
|
585 | + // OR we still don't have an EE_Answer object |
|
586 | + if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
587 | + // create an EE_Answer object for storing everything in |
|
588 | + $answer = EE_Answer::new_instance(array( |
|
589 | + 'QST_ID' => $question->ID(), |
|
590 | + 'REG_ID' => $registration->ID(), |
|
591 | + )); |
|
592 | + } |
|
593 | + // verify instance |
|
594 | + if ($answer instanceof EE_Answer) { |
|
595 | + if (! empty($answer_value)) { |
|
596 | + $answer->set('ANS_value', $answer_value); |
|
597 | + } |
|
598 | + $answer->cache('Question', $question); |
|
599 | + //remember system ID had a bug where sometimes it could be null |
|
600 | + $answer_cache_id = $question->is_system_question() |
|
601 | + ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
602 | + : $question->ID() . '-' . $registration->reg_url_link(); |
|
603 | + $registration->cache('Answer', $answer, $answer_cache_id); |
|
604 | + } |
|
605 | + return $this->_generate_question_input($registration, $question, $answer); |
|
606 | + } |
|
607 | + |
|
608 | + |
|
609 | + /** |
|
610 | + * @param EE_Registration $registration |
|
611 | + * @param EE_Question $question |
|
612 | + * @param mixed EE_Answer|NULL $answer |
|
613 | + * @return EE_Form_Input_Base |
|
614 | + * @throws \EE_Error |
|
615 | + */ |
|
616 | + private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
617 | + { |
|
618 | + $identifier = $question->is_system_question() |
|
619 | + ? $question->system_ID() |
|
620 | + : $question->ID(); |
|
621 | + $this->_required_questions[$identifier] = $question->required() ? true : false; |
|
622 | + add_filter( |
|
623 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
624 | + array($this, 'use_cached_countries_for_form_input'), |
|
625 | + 10, |
|
626 | + 4 |
|
627 | + ); |
|
628 | + add_filter( |
|
629 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
630 | + array($this, 'use_cached_states_for_form_input'), |
|
631 | + 10, |
|
632 | + 4 |
|
633 | + ); |
|
634 | + $input_constructor_args = array( |
|
635 | + 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
636 | + 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
637 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
638 | + 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
639 | + 'html_label_class' => 'ee-reg-qstn', |
|
640 | + ); |
|
641 | + $input_constructor_args['html_label_id'] .= '-lbl'; |
|
642 | + if ($answer instanceof EE_Answer && $answer->ID()) { |
|
643 | + $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
644 | + $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
645 | + $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
646 | + } |
|
647 | + $form_input = $question->generate_form_input( |
|
648 | + $registration, |
|
649 | + $answer, |
|
650 | + $input_constructor_args |
|
651 | + ); |
|
652 | + remove_filter( |
|
653 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
654 | + array($this, 'use_cached_countries_for_form_input') |
|
655 | + ); |
|
656 | + remove_filter( |
|
657 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
658 | + array($this, 'use_cached_states_for_form_input') |
|
659 | + ); |
|
660 | + return $form_input; |
|
661 | + } |
|
662 | + |
|
663 | + |
|
664 | + /** |
|
665 | + * Gets the list of countries for the form input |
|
666 | + * |
|
667 | + * @param array|null $countries_list |
|
668 | + * @param \EE_Question $question |
|
669 | + * @param \EE_Registration $registration |
|
670 | + * @param \EE_Answer $answer |
|
671 | + * @return array 2d keys are country IDs, values are their names |
|
672 | + * @throws EE_Error |
|
673 | + * @throws InvalidArgumentException |
|
674 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
675 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
676 | + */ |
|
677 | + public function use_cached_countries_for_form_input( |
|
678 | + $countries_list, |
|
679 | + \EE_Question $question = null, |
|
680 | + \EE_Registration $registration = null, |
|
681 | + \EE_Answer $answer = null |
|
682 | + ) { |
|
683 | + $country_options = array('' => ''); |
|
684 | + // get possibly cached list of countries |
|
685 | + $countries = $this->checkout->action === 'process_reg_step' |
|
686 | + ? EEM_Country::instance()->get_all_countries() |
|
687 | + : EEM_Country::instance()->get_all_active_countries(); |
|
688 | + if (! empty($countries)) { |
|
689 | + foreach ($countries as $country) { |
|
690 | + if ($country instanceof EE_Country) { |
|
691 | + $country_options[$country->ID()] = $country->name(); |
|
692 | + } |
|
693 | + } |
|
694 | + } |
|
695 | + if ($question instanceof EE_Question |
|
696 | + && $registration instanceof EE_Registration) { |
|
697 | + $answer = EEM_Answer::instance()->get_one( |
|
698 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
699 | + ); |
|
700 | + } else { |
|
701 | + $answer = EE_Answer::new_instance(); |
|
702 | + } |
|
703 | + $country_options = apply_filters( |
|
704 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
705 | + $country_options, |
|
706 | + $this, |
|
707 | + $registration, |
|
708 | + $question, |
|
709 | + $answer |
|
710 | + ); |
|
711 | + return $country_options; |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * Gets the list of states for the form input |
|
717 | + * |
|
718 | + * @param array|null $states_list |
|
719 | + * @param \EE_Question $question |
|
720 | + * @param \EE_Registration $registration |
|
721 | + * @param \EE_Answer $answer |
|
722 | + * @return array 2d keys are state IDs, values are their names |
|
723 | + * @throws EE_Error |
|
724 | + * @throws InvalidArgumentException |
|
725 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
726 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
727 | + */ |
|
728 | + public function use_cached_states_for_form_input( |
|
729 | + $states_list, |
|
730 | + \EE_Question $question = null, |
|
731 | + \EE_Registration $registration = null, |
|
732 | + \EE_Answer $answer = null |
|
733 | + ) { |
|
734 | + $state_options = array('' => array('' => '')); |
|
735 | + $states = $this->checkout->action === 'process_reg_step' |
|
736 | + ? EEM_State::instance()->get_all_states() |
|
737 | + : EEM_State::instance()->get_all_active_states(); |
|
738 | + if (! empty($states)) { |
|
739 | + foreach ($states as $state) { |
|
740 | + if ($state instanceof EE_State) { |
|
741 | + $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
742 | + } |
|
743 | + } |
|
744 | + } |
|
745 | + $state_options = apply_filters( |
|
746 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
747 | + $state_options, |
|
748 | + $this, |
|
749 | + $registration, |
|
750 | + $question, |
|
751 | + $answer |
|
752 | + ); |
|
753 | + return $state_options; |
|
754 | + } |
|
755 | + |
|
756 | + |
|
757 | + |
|
758 | + |
|
759 | + |
|
760 | + |
|
761 | + /********************************************************************************************************/ |
|
762 | + /**************************************** PROCESS REG STEP ****************************************/ |
|
763 | + /********************************************************************************************************/ |
|
764 | + /** |
|
765 | + * @return bool |
|
766 | + * @throws EE_Error |
|
767 | + * @throws InvalidArgumentException |
|
768 | + * @throws ReflectionException |
|
769 | + * @throws RuntimeException |
|
770 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
771 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
772 | + */ |
|
773 | + public function process_reg_step() |
|
774 | + { |
|
775 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
776 | + // grab validated data from form |
|
777 | + $valid_data = $this->checkout->current_step->valid_data(); |
|
778 | + // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
779 | + // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
780 | + // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
781 | + if (empty($valid_data)) { |
|
782 | + EE_Error::add_error( |
|
783 | + esc_html__('No valid question responses were received.', 'event_espresso'), |
|
784 | + __FILE__, |
|
785 | + __FUNCTION__, |
|
786 | + __LINE__ |
|
787 | + ); |
|
788 | + return false; |
|
789 | + } |
|
790 | + if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
791 | + EE_Error::add_error( |
|
792 | + esc_html__( |
|
793 | + 'A valid transaction could not be initiated for processing your registrations.', |
|
794 | + 'event_espresso' |
|
795 | + ), |
|
796 | + __FILE__, |
|
797 | + __FUNCTION__, |
|
798 | + __LINE__ |
|
799 | + ); |
|
800 | + return false; |
|
801 | + } |
|
802 | + // get cached registrations |
|
803 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
804 | + // verify we got the goods |
|
805 | + if (empty($registrations)) { |
|
806 | + //combine the old translated string with a new one, in order to not break translations |
|
807 | + $error_message = esc_html__( 'Your form data could not be applied to any valid registrations.', 'event_espresso' ) |
|
808 | + . sprintf( |
|
809 | + esc_html__('%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', 'event_espresso'), |
|
810 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
811 | + '</a>', |
|
812 | + '<br />' |
|
813 | + ); |
|
814 | + EE_Error::add_error( |
|
815 | + $error_message, |
|
816 | + __FILE__, |
|
817 | + __FUNCTION__, |
|
818 | + __LINE__ |
|
819 | + ); |
|
820 | + return false; |
|
821 | + } |
|
822 | + // extract attendee info from form data and save to model objects |
|
823 | + $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
824 | + // if first pass thru SPCO, |
|
825 | + // then let's check processed registrations against the total number of tickets in the cart |
|
826 | + if ($registrations_processed === false) { |
|
827 | + // but return immediately if the previous step exited early due to errors |
|
828 | + return false; |
|
829 | + } elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
830 | + // generate a correctly translated string for all possible singular/plural combinations |
|
831 | + if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
832 | + $error_msg = sprintf( |
|
833 | + esc_html__( |
|
834 | + 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
835 | + 'event_espresso' |
|
836 | + ), |
|
837 | + $this->checkout->total_ticket_count, |
|
838 | + $registrations_processed |
|
839 | + ); |
|
840 | + } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
841 | + $error_msg = sprintf( |
|
842 | + esc_html__( |
|
843 | + 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
844 | + 'event_espresso' |
|
845 | + ), |
|
846 | + $this->checkout->total_ticket_count, |
|
847 | + $registrations_processed |
|
848 | + ); |
|
849 | + } else { |
|
850 | + $error_msg = sprintf( |
|
851 | + esc_html__( |
|
852 | + 'There was a total of %1$d tickets in the Event Queue, but %2$ds registrations were processed', |
|
853 | + 'event_espresso' |
|
854 | + ), |
|
855 | + $this->checkout->total_ticket_count, |
|
856 | + $registrations_processed |
|
857 | + ); |
|
858 | + } |
|
859 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
860 | + return false; |
|
861 | + } |
|
862 | + // mark this reg step as completed |
|
863 | + $this->set_completed(); |
|
864 | + $this->_set_success_message( |
|
865 | + esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
866 | + ); |
|
867 | + //do action in case a plugin wants to do something with the data submitted in step 1. |
|
868 | + //passes EE_Single_Page_Checkout, and it's posted data |
|
869 | + do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
870 | + return true; |
|
871 | + } |
|
872 | + |
|
873 | + |
|
874 | + /** |
|
875 | + * _process_registrations |
|
876 | + * |
|
877 | + * @param EE_Registration[] $registrations |
|
878 | + * @param array $valid_data |
|
879 | + * @return bool|int |
|
880 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
881 | + * @throws EE_Error |
|
882 | + * @throws InvalidArgumentException |
|
883 | + * @throws ReflectionException |
|
884 | + * @throws RuntimeException |
|
885 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
886 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
887 | + */ |
|
888 | + private function _process_registrations($registrations = array(), $valid_data = array()) |
|
889 | + { |
|
890 | + // load resources and set some defaults |
|
891 | + EE_Registry::instance()->load_model('Attendee'); |
|
892 | + // holder for primary registrant attendee object |
|
893 | + $this->checkout->primary_attendee_obj = null; |
|
894 | + // array for tracking reg form data for the primary registrant |
|
895 | + $primary_registrant = array( |
|
896 | + 'line_item_id' => null, |
|
897 | + ); |
|
898 | + $copy_primary = false; |
|
899 | + // reg form sections that do not contain inputs |
|
900 | + $non_input_form_sections = array( |
|
901 | + 'primary_registrant', |
|
902 | + 'additional_attendee_reg_info', |
|
903 | + 'spco_copy_attendee_chk', |
|
904 | + ); |
|
905 | + // attendee counter |
|
906 | + $att_nmbr = 0; |
|
907 | + // grab the saved registrations from the transaction |
|
908 | + foreach ($registrations as $registration) { |
|
909 | + // verify EE_Registration object |
|
910 | + if (! $registration instanceof EE_Registration) { |
|
911 | + EE_Error::add_error( |
|
912 | + esc_html__( |
|
913 | + 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
914 | + 'event_espresso' |
|
915 | + ), |
|
916 | + __FILE__, |
|
917 | + __FUNCTION__, |
|
918 | + __LINE__ |
|
919 | + ); |
|
920 | + return false; |
|
921 | + } |
|
922 | + /** @var string $reg_url_link */ |
|
923 | + $reg_url_link = $registration->reg_url_link(); |
|
924 | + // reg_url_link exists ? |
|
925 | + if (! empty($reg_url_link)) { |
|
926 | + // should this registration be processed during this visit ? |
|
927 | + if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
928 | + // if NOT revisiting, then let's save the registration now, |
|
929 | + // so that we have a REG_ID to use when generating other objects |
|
930 | + if (! $this->checkout->revisit) { |
|
931 | + $registration->save(); |
|
932 | + } |
|
933 | + /** |
|
934 | + * This allows plugins to trigger a fail on processing of a |
|
935 | + * registration for any conditions they may have for it to pass. |
|
936 | + * |
|
937 | + * @var bool if true is returned by the plugin then the |
|
938 | + * registration processing is halted. |
|
939 | + */ |
|
940 | + if (apply_filters( |
|
941 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
942 | + false, |
|
943 | + $att_nmbr, |
|
944 | + $registration, |
|
945 | + $registrations, |
|
946 | + $valid_data, |
|
947 | + $this |
|
948 | + )) { |
|
949 | + return false; |
|
950 | + } |
|
951 | + |
|
952 | + // Houston, we have a registration! |
|
953 | + $att_nmbr++; |
|
954 | + $this->_attendee_data[$reg_url_link] = array(); |
|
955 | + // grab any existing related answer objects |
|
956 | + $this->_registration_answers = $registration->answers(); |
|
957 | + // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
958 | + if (isset($valid_data[$reg_url_link])) { |
|
959 | + // do we need to copy basic info from primary attendee ? |
|
960 | + $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info']) |
|
961 | + && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0 |
|
962 | + ? true |
|
963 | + : false; |
|
964 | + // filter form input data for this registration |
|
965 | + $valid_data[$reg_url_link] = (array)apply_filters( |
|
966 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
967 | + $valid_data[$reg_url_link] |
|
968 | + ); |
|
969 | + if (isset($valid_data['primary_attendee'])) { |
|
970 | + $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
971 | + ? $valid_data['primary_attendee'] |
|
972 | + : false; |
|
973 | + unset($valid_data['primary_attendee']); |
|
974 | + } |
|
975 | + // now loop through our array of valid post data && process attendee reg forms |
|
976 | + foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
|
977 | + if (! in_array($form_section, $non_input_form_sections)) { |
|
978 | + foreach ($form_inputs as $form_input => $input_value) { |
|
979 | + // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
980 | + // check for critical inputs |
|
981 | + if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
982 | + $form_input, |
|
983 | + $input_value |
|
984 | + ) |
|
985 | + ) { |
|
986 | + return false; |
|
987 | + } |
|
988 | + // store a bit of data about the primary attendee |
|
989 | + if ($att_nmbr === 1 |
|
990 | + && ! empty($input_value) |
|
991 | + && $reg_url_link === $primary_registrant['line_item_id'] |
|
992 | + ) { |
|
993 | + $primary_registrant[$form_input] = $input_value; |
|
994 | + } elseif ($copy_primary |
|
995 | + && $input_value === null |
|
996 | + && isset($primary_registrant[$form_input]) |
|
997 | + ) { |
|
998 | + $input_value = $primary_registrant[$form_input]; |
|
999 | + } |
|
1000 | + // now attempt to save the input data |
|
1001 | + if (! $this->_save_registration_form_input( |
|
1002 | + $registration, |
|
1003 | + $form_input, |
|
1004 | + $input_value |
|
1005 | + ) |
|
1006 | + ) { |
|
1007 | + EE_Error::add_error( |
|
1008 | + sprintf( |
|
1009 | + esc_html__( |
|
1010 | + 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
1011 | + 'event_espresso' |
|
1012 | + ), |
|
1013 | + $form_input, |
|
1014 | + $input_value |
|
1015 | + ), |
|
1016 | + __FILE__, |
|
1017 | + __FUNCTION__, |
|
1018 | + __LINE__ |
|
1019 | + ); |
|
1020 | + return false; |
|
1021 | + } |
|
1022 | + } |
|
1023 | + } |
|
1024 | + } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
1025 | + } |
|
1026 | + //EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
1027 | + // this registration does not require additional attendee information ? |
|
1028 | + if ($copy_primary |
|
1029 | + && $att_nmbr > 1 |
|
1030 | + && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
1031 | + ) { |
|
1032 | + // just copy the primary registrant |
|
1033 | + $attendee = $this->checkout->primary_attendee_obj; |
|
1034 | + } else { |
|
1035 | + // ensure critical details are set for additional attendees |
|
1036 | + $this->_attendee_data[$reg_url_link] = $att_nmbr > 1 |
|
1037 | + ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
1038 | + $this->_attendee_data[$reg_url_link] |
|
1039 | + ) |
|
1040 | + : $this->_attendee_data[$reg_url_link]; |
|
1041 | + // execute create attendee command (which may return an existing attendee) |
|
1042 | + $attendee = EE_Registry::instance()->BUS->execute( |
|
1043 | + new CreateAttendeeCommand( |
|
1044 | + $this->_attendee_data[$reg_url_link], |
|
1045 | + $registration |
|
1046 | + ) |
|
1047 | + ); |
|
1048 | + // who's #1 ? |
|
1049 | + if ($att_nmbr === 1) { |
|
1050 | + $this->checkout->primary_attendee_obj = $attendee; |
|
1051 | + } |
|
1052 | + } |
|
1053 | + // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
1054 | + // add relation to registration, set attendee ID, and cache attendee |
|
1055 | + $this->_associate_attendee_with_registration($registration, $attendee); |
|
1056 | + // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
1057 | + if (! $registration->attendee() instanceof EE_Attendee) { |
|
1058 | + EE_Error::add_error( |
|
1059 | + sprintf( |
|
1060 | + esc_html__( |
|
1061 | + 'Registration %s has an invalid or missing Attendee object.', |
|
1062 | + 'event_espresso' |
|
1063 | + ), |
|
1064 | + $reg_url_link |
|
1065 | + ), |
|
1066 | + __FILE__, |
|
1067 | + __FUNCTION__, |
|
1068 | + __LINE__ |
|
1069 | + ); |
|
1070 | + return false; |
|
1071 | + } |
|
1072 | + /** @type EE_Registration_Processor $registration_processor */ |
|
1073 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1074 | + // at this point, we should have enough details about the registrant to consider the registration |
|
1075 | + // NOT incomplete |
|
1076 | + $registration_processor->toggle_incomplete_registration_status_to_default( |
|
1077 | + $registration, |
|
1078 | + false, |
|
1079 | + new Context( |
|
1080 | + 'spco_reg_step_attendee_information_process_registrations', |
|
1081 | + esc_html__( |
|
1082 | + 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
1083 | + 'event_espresso' |
|
1084 | + ) |
|
1085 | + ) |
|
1086 | + ); |
|
1087 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
1088 | + // abandoned |
|
1089 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1090 | + // if we've gotten this far, then let's save what we have |
|
1091 | + $registration->save(); |
|
1092 | + // add relation between TXN and registration |
|
1093 | + $this->_associate_registration_with_transaction($registration); |
|
1094 | + } |
|
1095 | + } else { |
|
1096 | + EE_Error::add_error( |
|
1097 | + esc_html__( |
|
1098 | + 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
1099 | + 'event_espresso' |
|
1100 | + ), |
|
1101 | + __FILE__, |
|
1102 | + __FUNCTION__, |
|
1103 | + __LINE__ |
|
1104 | + ); |
|
1105 | + // remove malformed data |
|
1106 | + unset($valid_data[$reg_url_link]); |
|
1107 | + return false; |
|
1108 | + } |
|
1109 | + |
|
1110 | + } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
1111 | + return $att_nmbr; |
|
1112 | + } |
|
1113 | + |
|
1114 | + |
|
1115 | + /** |
|
1116 | + * _save_registration_form_input |
|
1117 | + * |
|
1118 | + * @param EE_Registration $registration |
|
1119 | + * @param string $form_input |
|
1120 | + * @param string $input_value |
|
1121 | + * @return bool |
|
1122 | + * @throws EE_Error |
|
1123 | + * @throws InvalidArgumentException |
|
1124 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1125 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1126 | + */ |
|
1127 | + private function _save_registration_form_input( |
|
1128 | + EE_Registration $registration, |
|
1129 | + $form_input = '', |
|
1130 | + $input_value = '' |
|
1131 | + ) { |
|
1132 | + // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
1133 | + // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
1134 | + // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
1135 | + // allow for plugins to hook in and do their own processing of the form input. |
|
1136 | + // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
1137 | + if (apply_filters( |
|
1138 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
1139 | + false, |
|
1140 | + $registration, |
|
1141 | + $form_input, |
|
1142 | + $input_value, |
|
1143 | + $this |
|
1144 | + )) { |
|
1145 | + return true; |
|
1146 | + } |
|
1147 | + /* |
|
1148 | 1148 | * $answer_cache_id is the key used to find the EE_Answer we want |
1149 | 1149 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
1150 | 1150 | */ |
1151 | - $answer_cache_id = $this->checkout->reg_url_link |
|
1152 | - ? $form_input . '-' . $registration->reg_url_link() |
|
1153 | - : $form_input; |
|
1154 | - $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
1155 | - && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer |
|
1156 | - ? true |
|
1157 | - : false; |
|
1158 | - //rename form_inputs if they are EE_Attendee properties |
|
1159 | - switch ((string) $form_input) { |
|
1160 | - case 'state': |
|
1161 | - case 'STA_ID': |
|
1162 | - $attendee_property = true; |
|
1163 | - $form_input = 'STA_ID'; |
|
1164 | - break; |
|
1165 | - |
|
1166 | - case 'country': |
|
1167 | - case 'CNT_ISO': |
|
1168 | - $attendee_property = true; |
|
1169 | - $form_input = 'CNT_ISO'; |
|
1170 | - break; |
|
1171 | - |
|
1172 | - default: |
|
1173 | - $ATT_input = 'ATT_' . $form_input; |
|
1174 | - //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
1175 | - $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
1176 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1177 | - } |
|
1178 | - // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
1179 | - // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
1180 | - // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
1181 | - // if this form input has a corresponding attendee property |
|
1182 | - if ($attendee_property) { |
|
1183 | - $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
1184 | - if ($answer_is_obj) { |
|
1185 | - // and delete the corresponding answer since we won't be storing this data in that object |
|
1186 | - $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
1187 | - $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
1188 | - } |
|
1189 | - return true; |
|
1190 | - } elseif ($answer_is_obj) { |
|
1191 | - // save this data to the answer object |
|
1192 | - $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
1193 | - $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
1194 | - return $result !== false ? true : false; |
|
1195 | - } else { |
|
1196 | - foreach ($this->_registration_answers as $answer) { |
|
1197 | - if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
1198 | - $answer->set_value($input_value); |
|
1199 | - $result = $answer->save(); |
|
1200 | - return $result !== false ? true : false; |
|
1201 | - } |
|
1202 | - } |
|
1203 | - } |
|
1204 | - return false; |
|
1205 | - } |
|
1206 | - |
|
1207 | - |
|
1208 | - /** |
|
1209 | - * _verify_critical_attendee_details_are_set |
|
1210 | - * |
|
1211 | - * @param string $form_input |
|
1212 | - * @param string $input_value |
|
1213 | - * @return boolean |
|
1214 | - */ |
|
1215 | - private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
1216 | - $form_input = '', |
|
1217 | - $input_value = '' |
|
1218 | - ) { |
|
1219 | - if (empty($input_value)) { |
|
1220 | - // if the form input isn't marked as being required, then just return |
|
1221 | - if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
1222 | - return true; |
|
1223 | - } |
|
1224 | - switch ($form_input) { |
|
1225 | - case 'fname': |
|
1226 | - EE_Error::add_error( |
|
1227 | - esc_html__('First Name is a required value.', 'event_espresso'), |
|
1228 | - __FILE__, |
|
1229 | - __FUNCTION__, |
|
1230 | - __LINE__ |
|
1231 | - ); |
|
1232 | - return false; |
|
1233 | - break; |
|
1234 | - case 'lname': |
|
1235 | - EE_Error::add_error( |
|
1236 | - esc_html__('Last Name is a required value.', 'event_espresso'), |
|
1237 | - __FILE__, |
|
1238 | - __FUNCTION__, |
|
1239 | - __LINE__ |
|
1240 | - ); |
|
1241 | - return false; |
|
1242 | - break; |
|
1243 | - case 'email': |
|
1244 | - EE_Error::add_error( |
|
1245 | - esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
1246 | - __FILE__, |
|
1247 | - __FUNCTION__, |
|
1248 | - __LINE__ |
|
1249 | - ); |
|
1250 | - return false; |
|
1251 | - break; |
|
1252 | - } |
|
1253 | - } |
|
1254 | - return true; |
|
1255 | - } |
|
1256 | - |
|
1257 | - |
|
1258 | - /** |
|
1259 | - * _associate_attendee_with_registration |
|
1260 | - * |
|
1261 | - * @param EE_Registration $registration |
|
1262 | - * @param EE_Attendee $attendee |
|
1263 | - * @return void |
|
1264 | - * @throws EE_Error |
|
1265 | - * @throws RuntimeException |
|
1266 | - */ |
|
1267 | - private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
1268 | - { |
|
1269 | - // add relation to attendee |
|
1270 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
1271 | - $registration->set_attendee_id($attendee->ID()); |
|
1272 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1273 | - } |
|
1274 | - |
|
1275 | - |
|
1276 | - /** |
|
1277 | - * _associate_registration_with_transaction |
|
1278 | - * |
|
1279 | - * @param EE_Registration $registration |
|
1280 | - * @return void |
|
1281 | - * @throws \EE_Error |
|
1282 | - */ |
|
1283 | - private function _associate_registration_with_transaction(EE_Registration $registration) |
|
1284 | - { |
|
1285 | - // add relation to registration |
|
1286 | - $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
1287 | - $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
1288 | - } |
|
1289 | - |
|
1290 | - |
|
1291 | - /** |
|
1292 | - * _copy_critical_attendee_details_from_primary_registrant |
|
1293 | - * ensures that all attendees at least have data for first name, last name, and email address |
|
1294 | - * |
|
1295 | - * @param array $attendee_data |
|
1296 | - * @return array |
|
1297 | - * @throws \EE_Error |
|
1298 | - */ |
|
1299 | - private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
1300 | - { |
|
1301 | - // bare minimum critical details include first name, last name, email address |
|
1302 | - $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1303 | - // add address info to critical details? |
|
1304 | - if (apply_filters( |
|
1305 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
1306 | - false |
|
1307 | - )) { |
|
1308 | - $address_details = array( |
|
1309 | - 'ATT_address', |
|
1310 | - 'ATT_address2', |
|
1311 | - 'ATT_city', |
|
1312 | - 'STA_ID', |
|
1313 | - 'CNT_ISO', |
|
1314 | - 'ATT_zip', |
|
1315 | - 'ATT_phone', |
|
1316 | - ); |
|
1317 | - $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
1318 | - } |
|
1319 | - foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
1320 | - if (! isset($attendee_data[$critical_attendee_detail]) |
|
1321 | - || empty($attendee_data[$critical_attendee_detail]) |
|
1322 | - ) { |
|
1323 | - $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
1324 | - $critical_attendee_detail |
|
1325 | - ); |
|
1326 | - } |
|
1327 | - } |
|
1328 | - return $attendee_data; |
|
1329 | - } |
|
1330 | - |
|
1331 | - |
|
1332 | - /** |
|
1333 | - * update_reg_step |
|
1334 | - * this is the final step after a user revisits the site to edit their attendee information |
|
1335 | - * this gets called AFTER the process_reg_step() method above |
|
1336 | - * |
|
1337 | - * @return bool |
|
1338 | - * @throws EE_Error |
|
1339 | - * @throws InvalidArgumentException |
|
1340 | - * @throws ReflectionException |
|
1341 | - * @throws RuntimeException |
|
1342 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1343 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1344 | - */ |
|
1345 | - public function update_reg_step() |
|
1346 | - { |
|
1347 | - // save everything |
|
1348 | - if ($this->process_reg_step()) { |
|
1349 | - $this->checkout->redirect = true; |
|
1350 | - $this->checkout->redirect_url = add_query_arg( |
|
1351 | - array( |
|
1352 | - 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
1353 | - 'revisit' => true, |
|
1354 | - ), |
|
1355 | - $this->checkout->thank_you_page_url |
|
1356 | - ); |
|
1357 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1358 | - return true; |
|
1359 | - } |
|
1360 | - return false; |
|
1361 | - } |
|
1151 | + $answer_cache_id = $this->checkout->reg_url_link |
|
1152 | + ? $form_input . '-' . $registration->reg_url_link() |
|
1153 | + : $form_input; |
|
1154 | + $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
1155 | + && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer |
|
1156 | + ? true |
|
1157 | + : false; |
|
1158 | + //rename form_inputs if they are EE_Attendee properties |
|
1159 | + switch ((string) $form_input) { |
|
1160 | + case 'state': |
|
1161 | + case 'STA_ID': |
|
1162 | + $attendee_property = true; |
|
1163 | + $form_input = 'STA_ID'; |
|
1164 | + break; |
|
1165 | + |
|
1166 | + case 'country': |
|
1167 | + case 'CNT_ISO': |
|
1168 | + $attendee_property = true; |
|
1169 | + $form_input = 'CNT_ISO'; |
|
1170 | + break; |
|
1171 | + |
|
1172 | + default: |
|
1173 | + $ATT_input = 'ATT_' . $form_input; |
|
1174 | + //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
1175 | + $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
1176 | + $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1177 | + } |
|
1178 | + // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
1179 | + // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
1180 | + // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
1181 | + // if this form input has a corresponding attendee property |
|
1182 | + if ($attendee_property) { |
|
1183 | + $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
1184 | + if ($answer_is_obj) { |
|
1185 | + // and delete the corresponding answer since we won't be storing this data in that object |
|
1186 | + $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
1187 | + $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
1188 | + } |
|
1189 | + return true; |
|
1190 | + } elseif ($answer_is_obj) { |
|
1191 | + // save this data to the answer object |
|
1192 | + $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
1193 | + $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
1194 | + return $result !== false ? true : false; |
|
1195 | + } else { |
|
1196 | + foreach ($this->_registration_answers as $answer) { |
|
1197 | + if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
1198 | + $answer->set_value($input_value); |
|
1199 | + $result = $answer->save(); |
|
1200 | + return $result !== false ? true : false; |
|
1201 | + } |
|
1202 | + } |
|
1203 | + } |
|
1204 | + return false; |
|
1205 | + } |
|
1206 | + |
|
1207 | + |
|
1208 | + /** |
|
1209 | + * _verify_critical_attendee_details_are_set |
|
1210 | + * |
|
1211 | + * @param string $form_input |
|
1212 | + * @param string $input_value |
|
1213 | + * @return boolean |
|
1214 | + */ |
|
1215 | + private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
1216 | + $form_input = '', |
|
1217 | + $input_value = '' |
|
1218 | + ) { |
|
1219 | + if (empty($input_value)) { |
|
1220 | + // if the form input isn't marked as being required, then just return |
|
1221 | + if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
1222 | + return true; |
|
1223 | + } |
|
1224 | + switch ($form_input) { |
|
1225 | + case 'fname': |
|
1226 | + EE_Error::add_error( |
|
1227 | + esc_html__('First Name is a required value.', 'event_espresso'), |
|
1228 | + __FILE__, |
|
1229 | + __FUNCTION__, |
|
1230 | + __LINE__ |
|
1231 | + ); |
|
1232 | + return false; |
|
1233 | + break; |
|
1234 | + case 'lname': |
|
1235 | + EE_Error::add_error( |
|
1236 | + esc_html__('Last Name is a required value.', 'event_espresso'), |
|
1237 | + __FILE__, |
|
1238 | + __FUNCTION__, |
|
1239 | + __LINE__ |
|
1240 | + ); |
|
1241 | + return false; |
|
1242 | + break; |
|
1243 | + case 'email': |
|
1244 | + EE_Error::add_error( |
|
1245 | + esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
1246 | + __FILE__, |
|
1247 | + __FUNCTION__, |
|
1248 | + __LINE__ |
|
1249 | + ); |
|
1250 | + return false; |
|
1251 | + break; |
|
1252 | + } |
|
1253 | + } |
|
1254 | + return true; |
|
1255 | + } |
|
1256 | + |
|
1257 | + |
|
1258 | + /** |
|
1259 | + * _associate_attendee_with_registration |
|
1260 | + * |
|
1261 | + * @param EE_Registration $registration |
|
1262 | + * @param EE_Attendee $attendee |
|
1263 | + * @return void |
|
1264 | + * @throws EE_Error |
|
1265 | + * @throws RuntimeException |
|
1266 | + */ |
|
1267 | + private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
1268 | + { |
|
1269 | + // add relation to attendee |
|
1270 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1271 | + $registration->set_attendee_id($attendee->ID()); |
|
1272 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1273 | + } |
|
1274 | + |
|
1275 | + |
|
1276 | + /** |
|
1277 | + * _associate_registration_with_transaction |
|
1278 | + * |
|
1279 | + * @param EE_Registration $registration |
|
1280 | + * @return void |
|
1281 | + * @throws \EE_Error |
|
1282 | + */ |
|
1283 | + private function _associate_registration_with_transaction(EE_Registration $registration) |
|
1284 | + { |
|
1285 | + // add relation to registration |
|
1286 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
1287 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
1288 | + } |
|
1289 | + |
|
1290 | + |
|
1291 | + /** |
|
1292 | + * _copy_critical_attendee_details_from_primary_registrant |
|
1293 | + * ensures that all attendees at least have data for first name, last name, and email address |
|
1294 | + * |
|
1295 | + * @param array $attendee_data |
|
1296 | + * @return array |
|
1297 | + * @throws \EE_Error |
|
1298 | + */ |
|
1299 | + private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
1300 | + { |
|
1301 | + // bare minimum critical details include first name, last name, email address |
|
1302 | + $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1303 | + // add address info to critical details? |
|
1304 | + if (apply_filters( |
|
1305 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
1306 | + false |
|
1307 | + )) { |
|
1308 | + $address_details = array( |
|
1309 | + 'ATT_address', |
|
1310 | + 'ATT_address2', |
|
1311 | + 'ATT_city', |
|
1312 | + 'STA_ID', |
|
1313 | + 'CNT_ISO', |
|
1314 | + 'ATT_zip', |
|
1315 | + 'ATT_phone', |
|
1316 | + ); |
|
1317 | + $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
1318 | + } |
|
1319 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
1320 | + if (! isset($attendee_data[$critical_attendee_detail]) |
|
1321 | + || empty($attendee_data[$critical_attendee_detail]) |
|
1322 | + ) { |
|
1323 | + $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
1324 | + $critical_attendee_detail |
|
1325 | + ); |
|
1326 | + } |
|
1327 | + } |
|
1328 | + return $attendee_data; |
|
1329 | + } |
|
1330 | + |
|
1331 | + |
|
1332 | + /** |
|
1333 | + * update_reg_step |
|
1334 | + * this is the final step after a user revisits the site to edit their attendee information |
|
1335 | + * this gets called AFTER the process_reg_step() method above |
|
1336 | + * |
|
1337 | + * @return bool |
|
1338 | + * @throws EE_Error |
|
1339 | + * @throws InvalidArgumentException |
|
1340 | + * @throws ReflectionException |
|
1341 | + * @throws RuntimeException |
|
1342 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1343 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1344 | + */ |
|
1345 | + public function update_reg_step() |
|
1346 | + { |
|
1347 | + // save everything |
|
1348 | + if ($this->process_reg_step()) { |
|
1349 | + $this->checkout->redirect = true; |
|
1350 | + $this->checkout->redirect_url = add_query_arg( |
|
1351 | + array( |
|
1352 | + 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
1353 | + 'revisit' => true, |
|
1354 | + ), |
|
1355 | + $this->checkout->thank_you_page_url |
|
1356 | + ); |
|
1357 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1358 | + return true; |
|
1359 | + } |
|
1360 | + return false; |
|
1361 | + } |
|
1362 | 1362 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | { |
49 | 49 | $this->_slug = 'attendee_information'; |
50 | 50 | $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
51 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
51 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'attendee_info_main.template.php'; |
|
52 | 52 | $this->checkout = $checkout; |
53 | 53 | $this->_reset_success_message(); |
54 | 54 | $this->set_instructions( |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | |
60 | 60 | public function translate_js_strings() |
61 | 61 | { |
62 | - EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
62 | + EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
63 | 63 | ' is a required question.', |
64 | 64 | 'event_espresso' |
65 | 65 | ); |
66 | - EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
66 | + EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
67 | 67 | ' is a required question. Please enter a value for at least one of the options.', |
68 | 68 | 'event_espresso' |
69 | 69 | ); |
@@ -71,18 +71,18 @@ discard block |
||
71 | 71 | 'Please answer all required questions correctly before proceeding.', |
72 | 72 | 'event_espresso' |
73 | 73 | ); |
74 | - EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
74 | + EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
75 | 75 | esc_html__( |
76 | 76 | 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
77 | 77 | 'event_espresso' |
78 | 78 | ), |
79 | 79 | '<br/>' |
80 | 80 | ); |
81 | - EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
81 | + EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
82 | 82 | 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
83 | 83 | 'event_espresso' |
84 | 84 | ); |
85 | - EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
85 | + EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
86 | 86 | 'You must enter a valid email address.', |
87 | 87 | 'event_espresso' |
88 | 88 | ); |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | && $this->checkout->visit_allows_processing_of_this_registration($registration) |
146 | 146 | ) { |
147 | 147 | $subsection = $this->_registrations_reg_form($registration); |
148 | - if(!$subsection instanceof EE_Form_Section_Proper) { |
|
148 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
149 | 149 | continue; |
150 | 150 | } |
151 | - $subsections[ $registration->reg_url_link() ] = $subsection; |
|
152 | - if (! $this->checkout->admin_request) { |
|
151 | + $subsections[$registration->reg_url_link()] = $subsection; |
|
152 | + if ( ! $this->checkout->admin_request) { |
|
153 | 153 | $template_args['registrations'][$registration->reg_url_link()] = $registration; |
154 | 154 | $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
155 | 155 | $template_args['ticket_count'][$registration->ticket()->ID()] |
@@ -197,8 +197,7 @@ discard block |
||
197 | 197 | 'html_id' => $this->reg_form_name(), |
198 | 198 | 'subsections' => $subsections, |
199 | 199 | 'layout_strategy' => $this->checkout->admin_request ? |
200 | - new EE_Div_Per_Section_Layout() : |
|
201 | - new EE_Template_Layout( |
|
200 | + new EE_Div_Per_Section_Layout() : new EE_Template_Layout( |
|
202 | 201 | array( |
203 | 202 | 'layout_template_file' => $this->_template, // layout_template |
204 | 203 | 'template_args' => $template_args, |
@@ -241,7 +240,7 @@ discard block |
||
241 | 240 | if ($question_groups) { |
242 | 241 | // array of params to pass to parent constructor |
243 | 242 | $form_args = array( |
244 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
243 | + 'html_id' => 'ee-registration-'.$registration->reg_url_link(), |
|
245 | 244 | 'html_class' => 'ee-reg-form-attendee-dv', |
246 | 245 | 'html_style' => $this->checkout->admin_request |
247 | 246 | ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
@@ -297,7 +296,7 @@ discard block |
||
297 | 296 | // generate hidden input |
298 | 297 | return new EE_Hidden_Input( |
299 | 298 | array( |
300 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
299 | + 'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(), |
|
301 | 300 | 'default' => $additional_attendee_reg_info, |
302 | 301 | ) |
303 | 302 | ); |
@@ -317,11 +316,11 @@ discard block |
||
317 | 316 | { |
318 | 317 | // array of params to pass to parent constructor |
319 | 318 | $form_args = array( |
320 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
319 | + 'html_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-'.$registration->ID(), |
|
321 | 320 | 'html_class' => $this->checkout->admin_request |
322 | 321 | ? 'form-table ee-reg-form-qstn-grp-dv' |
323 | 322 | : 'ee-reg-form-qstn-grp-dv', |
324 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID() . '-lbl', |
|
323 | + 'html_label_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-'.$registration->ID().'-lbl', |
|
325 | 324 | 'subsections' => array( |
326 | 325 | 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
327 | 326 | ), |
@@ -332,7 +331,7 @@ discard block |
||
332 | 331 | // where params |
333 | 332 | $query_params = array('QST_deleted' => 0); |
334 | 333 | // don't load admin only questions on the frontend |
335 | - if (! $this->checkout->admin_request) { |
|
334 | + if ( ! $this->checkout->admin_request) { |
|
336 | 335 | $query_params['QST_admin_only'] = array('!=', true); |
337 | 336 | } |
338 | 337 | $questions = $question_group->get_many_related( |
@@ -476,7 +475,7 @@ discard block |
||
476 | 475 | { |
477 | 476 | return new EE_Form_Section_HTML( |
478 | 477 | EEH_Template::locate_template( |
479 | - SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
478 | + SPCO_REG_STEPS_PATH.$this->_slug.DS.'_auto_copy_attendee_info.template.php', |
|
480 | 479 | apply_filters( |
481 | 480 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
482 | 481 | array() |
@@ -508,16 +507,16 @@ discard block |
||
508 | 507 | if ($registration->ticket()->ID() !== $prev_ticket) { |
509 | 508 | $item_name = $registration->ticket()->name(); |
510 | 509 | $item_name .= $registration->ticket()->description() !== '' |
511 | - ? ' - ' . $registration->ticket()->description() |
|
510 | + ? ' - '.$registration->ticket()->description() |
|
512 | 511 | : ''; |
513 | - $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] = |
|
512 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID().']'] = |
|
514 | 513 | new EE_Form_Section_HTML( |
515 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
514 | + '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>' |
|
516 | 515 | ); |
517 | 516 | $prev_ticket = $registration->ticket()->ID(); |
518 | 517 | } |
519 | 518 | |
520 | - $copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] = |
|
519 | + $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] = |
|
521 | 520 | new EE_Checkbox_Multi_Input( |
522 | 521 | array( |
523 | 522 | $registration->ID() => sprintf( |
@@ -526,7 +525,7 @@ discard block |
||
526 | 525 | ), |
527 | 526 | ), |
528 | 527 | array( |
529 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
528 | + 'html_id' => 'spco-copy-attendee-chk-'.$registration->reg_url_link(), |
|
530 | 529 | 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
531 | 530 | 'display_html_label_text' => false, |
532 | 531 | ) |
@@ -575,7 +574,7 @@ discard block |
||
575 | 574 | $registration, |
576 | 575 | $question->system_ID() |
577 | 576 | ); |
578 | - $answer = $answer_value === null |
|
577 | + $answer = $answer_value === null |
|
579 | 578 | ? EEM_Answer::instance()->get_one( |
580 | 579 | array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
581 | 580 | ) |
@@ -592,14 +591,14 @@ discard block |
||
592 | 591 | } |
593 | 592 | // verify instance |
594 | 593 | if ($answer instanceof EE_Answer) { |
595 | - if (! empty($answer_value)) { |
|
594 | + if ( ! empty($answer_value)) { |
|
596 | 595 | $answer->set('ANS_value', $answer_value); |
597 | 596 | } |
598 | 597 | $answer->cache('Question', $question); |
599 | 598 | //remember system ID had a bug where sometimes it could be null |
600 | 599 | $answer_cache_id = $question->is_system_question() |
601 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
602 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
600 | + ? $question->system_ID().'-'.$registration->reg_url_link() |
|
601 | + : $question->ID().'-'.$registration->reg_url_link(); |
|
603 | 602 | $registration->cache('Answer', $answer, $answer_cache_id); |
604 | 603 | } |
605 | 604 | return $this->_generate_question_input($registration, $question, $answer); |
@@ -631,18 +630,18 @@ discard block |
||
631 | 630 | 10, |
632 | 631 | 4 |
633 | 632 | ); |
634 | - $input_constructor_args = array( |
|
635 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
636 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
637 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
638 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
633 | + $input_constructor_args = array( |
|
634 | + 'html_name' => 'ee_reg_qstn['.$registration->ID().']['.$identifier.']', |
|
635 | + 'html_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
636 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-'.$identifier, |
|
637 | + 'html_label_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
639 | 638 | 'html_label_class' => 'ee-reg-qstn', |
640 | 639 | ); |
641 | 640 | $input_constructor_args['html_label_id'] .= '-lbl'; |
642 | 641 | if ($answer instanceof EE_Answer && $answer->ID()) { |
643 | - $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
644 | - $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
645 | - $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
642 | + $input_constructor_args['html_name'] .= '['.$answer->ID().']'; |
|
643 | + $input_constructor_args['html_id'] .= '-'.$answer->ID(); |
|
644 | + $input_constructor_args['html_label_id'] .= '-'.$answer->ID(); |
|
646 | 645 | } |
647 | 646 | $form_input = $question->generate_form_input( |
648 | 647 | $registration, |
@@ -685,7 +684,7 @@ discard block |
||
685 | 684 | $countries = $this->checkout->action === 'process_reg_step' |
686 | 685 | ? EEM_Country::instance()->get_all_countries() |
687 | 686 | : EEM_Country::instance()->get_all_active_countries(); |
688 | - if (! empty($countries)) { |
|
687 | + if ( ! empty($countries)) { |
|
689 | 688 | foreach ($countries as $country) { |
690 | 689 | if ($country instanceof EE_Country) { |
691 | 690 | $country_options[$country->ID()] = $country->name(); |
@@ -735,7 +734,7 @@ discard block |
||
735 | 734 | $states = $this->checkout->action === 'process_reg_step' |
736 | 735 | ? EEM_State::instance()->get_all_states() |
737 | 736 | : EEM_State::instance()->get_all_active_states(); |
738 | - if (! empty($states)) { |
|
737 | + if ( ! empty($states)) { |
|
739 | 738 | foreach ($states as $state) { |
740 | 739 | if ($state instanceof EE_State) { |
741 | 740 | $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
@@ -787,7 +786,7 @@ discard block |
||
787 | 786 | ); |
788 | 787 | return false; |
789 | 788 | } |
790 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
789 | + if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
791 | 790 | EE_Error::add_error( |
792 | 791 | esc_html__( |
793 | 792 | 'A valid transaction could not be initiated for processing your registrations.', |
@@ -804,10 +803,10 @@ discard block |
||
804 | 803 | // verify we got the goods |
805 | 804 | if (empty($registrations)) { |
806 | 805 | //combine the old translated string with a new one, in order to not break translations |
807 | - $error_message = esc_html__( 'Your form data could not be applied to any valid registrations.', 'event_espresso' ) |
|
806 | + $error_message = esc_html__('Your form data could not be applied to any valid registrations.', 'event_espresso') |
|
808 | 807 | . sprintf( |
809 | 808 | esc_html__('%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', 'event_espresso'), |
810 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
809 | + '<a href="'.get_post_type_archive_link('espresso_events').'" >', |
|
811 | 810 | '</a>', |
812 | 811 | '<br />' |
813 | 812 | ); |
@@ -826,7 +825,7 @@ discard block |
||
826 | 825 | if ($registrations_processed === false) { |
827 | 826 | // but return immediately if the previous step exited early due to errors |
828 | 827 | return false; |
829 | - } elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
828 | + } elseif ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
830 | 829 | // generate a correctly translated string for all possible singular/plural combinations |
831 | 830 | if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
832 | 831 | $error_msg = sprintf( |
@@ -907,7 +906,7 @@ discard block |
||
907 | 906 | // grab the saved registrations from the transaction |
908 | 907 | foreach ($registrations as $registration) { |
909 | 908 | // verify EE_Registration object |
910 | - if (! $registration instanceof EE_Registration) { |
|
909 | + if ( ! $registration instanceof EE_Registration) { |
|
911 | 910 | EE_Error::add_error( |
912 | 911 | esc_html__( |
913 | 912 | 'An invalid Registration object was discovered when attempting to process your registration information.', |
@@ -922,12 +921,12 @@ discard block |
||
922 | 921 | /** @var string $reg_url_link */ |
923 | 922 | $reg_url_link = $registration->reg_url_link(); |
924 | 923 | // reg_url_link exists ? |
925 | - if (! empty($reg_url_link)) { |
|
924 | + if ( ! empty($reg_url_link)) { |
|
926 | 925 | // should this registration be processed during this visit ? |
927 | 926 | if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
928 | 927 | // if NOT revisiting, then let's save the registration now, |
929 | 928 | // so that we have a REG_ID to use when generating other objects |
930 | - if (! $this->checkout->revisit) { |
|
929 | + if ( ! $this->checkout->revisit) { |
|
931 | 930 | $registration->save(); |
932 | 931 | } |
933 | 932 | /** |
@@ -962,7 +961,7 @@ discard block |
||
962 | 961 | ? true |
963 | 962 | : false; |
964 | 963 | // filter form input data for this registration |
965 | - $valid_data[$reg_url_link] = (array)apply_filters( |
|
964 | + $valid_data[$reg_url_link] = (array) apply_filters( |
|
966 | 965 | 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
967 | 966 | $valid_data[$reg_url_link] |
968 | 967 | ); |
@@ -974,11 +973,11 @@ discard block |
||
974 | 973 | } |
975 | 974 | // now loop through our array of valid post data && process attendee reg forms |
976 | 975 | foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
977 | - if (! in_array($form_section, $non_input_form_sections)) { |
|
976 | + if ( ! in_array($form_section, $non_input_form_sections)) { |
|
978 | 977 | foreach ($form_inputs as $form_input => $input_value) { |
979 | 978 | // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
980 | 979 | // check for critical inputs |
981 | - if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
980 | + if ( ! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
982 | 981 | $form_input, |
983 | 982 | $input_value |
984 | 983 | ) |
@@ -998,7 +997,7 @@ discard block |
||
998 | 997 | $input_value = $primary_registrant[$form_input]; |
999 | 998 | } |
1000 | 999 | // now attempt to save the input data |
1001 | - if (! $this->_save_registration_form_input( |
|
1000 | + if ( ! $this->_save_registration_form_input( |
|
1002 | 1001 | $registration, |
1003 | 1002 | $form_input, |
1004 | 1003 | $input_value |
@@ -1054,7 +1053,7 @@ discard block |
||
1054 | 1053 | // add relation to registration, set attendee ID, and cache attendee |
1055 | 1054 | $this->_associate_attendee_with_registration($registration, $attendee); |
1056 | 1055 | // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
1057 | - if (! $registration->attendee() instanceof EE_Attendee) { |
|
1056 | + if ( ! $registration->attendee() instanceof EE_Attendee) { |
|
1058 | 1057 | EE_Error::add_error( |
1059 | 1058 | sprintf( |
1060 | 1059 | esc_html__( |
@@ -1149,7 +1148,7 @@ discard block |
||
1149 | 1148 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
1150 | 1149 | */ |
1151 | 1150 | $answer_cache_id = $this->checkout->reg_url_link |
1152 | - ? $form_input . '-' . $registration->reg_url_link() |
|
1151 | + ? $form_input.'-'.$registration->reg_url_link() |
|
1153 | 1152 | : $form_input; |
1154 | 1153 | $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
1155 | 1154 | && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer |
@@ -1170,10 +1169,10 @@ discard block |
||
1170 | 1169 | break; |
1171 | 1170 | |
1172 | 1171 | default: |
1173 | - $ATT_input = 'ATT_' . $form_input; |
|
1172 | + $ATT_input = 'ATT_'.$form_input; |
|
1174 | 1173 | //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
1175 | 1174 | $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
1176 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1175 | + $form_input = $attendee_property ? 'ATT_'.$form_input : $form_input; |
|
1177 | 1176 | } |
1178 | 1177 | // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
1179 | 1178 | // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
@@ -1218,7 +1217,7 @@ discard block |
||
1218 | 1217 | ) { |
1219 | 1218 | if (empty($input_value)) { |
1220 | 1219 | // if the form input isn't marked as being required, then just return |
1221 | - if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
1220 | + if ( ! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
1222 | 1221 | return true; |
1223 | 1222 | } |
1224 | 1223 | switch ($form_input) { |
@@ -1305,7 +1304,7 @@ discard block |
||
1305 | 1304 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
1306 | 1305 | false |
1307 | 1306 | )) { |
1308 | - $address_details = array( |
|
1307 | + $address_details = array( |
|
1309 | 1308 | 'ATT_address', |
1310 | 1309 | 'ATT_address2', |
1311 | 1310 | 'ATT_city', |
@@ -1317,7 +1316,7 @@ discard block |
||
1317 | 1316 | $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
1318 | 1317 | } |
1319 | 1318 | foreach ($critical_attendee_details as $critical_attendee_detail) { |
1320 | - if (! isset($attendee_data[$critical_attendee_detail]) |
|
1319 | + if ( ! isset($attendee_data[$critical_attendee_detail]) |
|
1321 | 1320 | || empty($attendee_data[$critical_attendee_detail]) |
1322 | 1321 | ) { |
1323 | 1322 | $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
@@ -22,382 +22,382 @@ |
||
22 | 22 | class EED_Recaptcha extends EED_Module |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var EE_Registration_Config $config |
|
27 | - */ |
|
28 | - private static $config; |
|
29 | - |
|
30 | - /** |
|
31 | - * @type bool $_not_a_robot |
|
32 | - */ |
|
33 | - private static $_not_a_robot; |
|
34 | - |
|
35 | - /** |
|
36 | - * @type string $_recaptcha_response |
|
37 | - */ |
|
38 | - private static $_recaptcha_response; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * @return EED_Module|EED_Recaptcha |
|
43 | - */ |
|
44 | - public static function instance() |
|
45 | - { |
|
46 | - return parent::get_instance(__CLASS__); |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
52 | - * |
|
53 | - * @return void |
|
54 | - * @throws InvalidArgumentException |
|
55 | - * @throws InvalidInterfaceException |
|
56 | - * @throws InvalidDataTypeException |
|
57 | - */ |
|
58 | - public static function set_hooks() |
|
59 | - { |
|
60 | - EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration; |
|
61 | - // use_captcha ? |
|
62 | - if ( |
|
63 | - EED_Recaptcha::useRecaptcha() |
|
64 | - && EED_Recaptcha::notPaymentOptionsRevisit() |
|
65 | - ) { |
|
66 | - EED_Recaptcha::set_definitions(); |
|
67 | - EED_Recaptcha::enqueue_styles_and_scripts(); |
|
68 | - add_action('wp', array('EED_Recaptcha', 'set_late_hooks'), 1, 0); |
|
69 | - add_action( |
|
70 | - 'AHEE__before_spco_whats_next_buttons', |
|
71 | - array('EED_Recaptcha', 'display_recaptcha'), 10, 0 |
|
72 | - ); |
|
73 | - add_filter( |
|
74 | - 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
75 | - array('EED_Recaptcha', 'not_a_robot') |
|
76 | - ); |
|
77 | - add_filter( |
|
78 | - 'FHEE__EE_SPCO_Reg_Step__set_completed___completed', |
|
79 | - array('EED_Recaptcha', 'not_a_robot') |
|
80 | - ); |
|
81 | - add_filter( |
|
82 | - 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', |
|
83 | - array('EED_Recaptcha', 'recaptcha_response') |
|
84 | - ); |
|
85 | - add_filter( |
|
86 | - 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
87 | - array('EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method') |
|
88 | - ); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
95 | - * |
|
96 | - * @return void |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws InvalidInterfaceException |
|
99 | - * @throws InvalidDataTypeException |
|
100 | - */ |
|
101 | - public static function set_hooks_admin() |
|
102 | - { |
|
103 | - EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration; |
|
104 | - EED_Recaptcha::set_definitions(); |
|
105 | - // use_captcha ? |
|
106 | - if ( |
|
107 | - EED_Recaptcha::useRecaptcha() |
|
108 | - && EED_Recaptcha::notPaymentOptionsRevisit() |
|
109 | - && EE_Registry::instance()->REQ->get('step', '') !== '' |
|
110 | - ) { |
|
111 | - EED_Recaptcha::enqueue_styles_and_scripts(); |
|
112 | - add_filter( |
|
113 | - 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
114 | - array('EED_Recaptcha', 'not_a_robot') |
|
115 | - ); |
|
116 | - add_filter( |
|
117 | - 'FHEE__EE_SPCO_Reg_Step__set_completed___completed', |
|
118 | - array('EED_Recaptcha', 'not_a_robot') |
|
119 | - ); |
|
120 | - add_filter( |
|
121 | - 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', |
|
122 | - array('EED_Recaptcha', 'recaptcha_response') |
|
123 | - ); |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @return void |
|
130 | - */ |
|
131 | - public static function set_definitions() |
|
132 | - { |
|
133 | - if (is_user_logged_in()) { |
|
134 | - EED_Recaptcha::$_not_a_robot = true; |
|
135 | - } |
|
136 | - define( |
|
137 | - 'RECAPTCHA_BASE_PATH', |
|
138 | - rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
139 | - ); |
|
140 | - define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__)); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - public static function set_late_hooks() |
|
148 | - { |
|
149 | - add_filter( |
|
150 | - 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
151 | - array('EED_Recaptcha', 'not_a_robot') |
|
152 | - ); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @return boolean |
|
158 | - */ |
|
159 | - public static function useRecaptcha() |
|
160 | - { |
|
161 | - return EED_Recaptcha::$config->use_captcha |
|
162 | - && EED_Recaptcha::$config->recaptcha_theme !== 'invisible'; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @return boolean |
|
168 | - * @throws InvalidArgumentException |
|
169 | - * @throws InvalidInterfaceException |
|
170 | - * @throws InvalidDataTypeException |
|
171 | - */ |
|
172 | - public static function notPaymentOptionsRevisit() |
|
173 | - { |
|
174 | - return ! ( |
|
175 | - EE_Registry::instance()->REQ->get('step', '') === 'payment_options' |
|
176 | - && (boolean) EE_Registry::instance()->REQ->get('revisit', false) === true |
|
177 | - ); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * @return void |
|
183 | - * @throws InvalidArgumentException |
|
184 | - * @throws InvalidInterfaceException |
|
185 | - * @throws InvalidDataTypeException |
|
186 | - */ |
|
187 | - public static function enqueue_styles_and_scripts() |
|
188 | - { |
|
189 | - wp_register_script( |
|
190 | - 'espresso_recaptcha', |
|
191 | - RECAPTCHA_BASE_URL . 'scripts' . DS . 'espresso_recaptcha.js', |
|
192 | - array('single_page_checkout'), |
|
193 | - EVENT_ESPRESSO_VERSION, |
|
194 | - true |
|
195 | - ); |
|
196 | - wp_register_script( |
|
197 | - 'google_recaptcha', |
|
198 | - 'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language, |
|
199 | - array('espresso_recaptcha'), |
|
200 | - EVENT_ESPRESSO_VERSION, |
|
201 | - true |
|
202 | - ); |
|
203 | - EE_Registry::$i18n_js_strings['no_SPCO_error'] = __( |
|
204 | - 'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.', |
|
205 | - 'event_espresso' |
|
206 | - ); |
|
207 | - EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __( |
|
208 | - 'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.', |
|
209 | - 'event_espresso' |
|
210 | - ); |
|
211 | - EE_Registry::$i18n_js_strings['recaptcha_fail'] = __( |
|
212 | - 'Please complete the anti-spam test before proceeding.', |
|
213 | - 'event_espresso' |
|
214 | - ); |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * @param \WP $WP |
|
220 | - */ |
|
221 | - public function run($WP) |
|
222 | - { |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * @return boolean |
|
228 | - * @throws InvalidArgumentException |
|
229 | - * @throws InvalidInterfaceException |
|
230 | - * @throws InvalidDataTypeException |
|
231 | - */ |
|
232 | - public static function not_a_robot() |
|
233 | - { |
|
234 | - $not_a_robot = is_bool(EED_Recaptcha::$_not_a_robot) |
|
235 | - ? EED_Recaptcha::$_not_a_robot |
|
236 | - : EED_Recaptcha::recaptcha_passed(); |
|
237 | - return $not_a_robot; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @return void |
|
243 | - * @throws DomainException |
|
244 | - * @throws InvalidArgumentException |
|
245 | - * @throws InvalidInterfaceException |
|
246 | - * @throws InvalidDataTypeException |
|
247 | - */ |
|
248 | - public static function display_recaptcha() |
|
249 | - { |
|
250 | - // logged in means you have already passed a turing test of sorts |
|
251 | - if (is_user_logged_in()) { |
|
252 | - return; |
|
253 | - } |
|
254 | - // don't display if not using recaptcha or user is logged in |
|
255 | - if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) { |
|
256 | - // only display if they have NOT passed the test yet |
|
257 | - EEH_Template::display_template( |
|
258 | - RECAPTCHA_BASE_PATH . DS . 'templates' . DS . 'recaptcha.template.php', |
|
259 | - array( |
|
260 | - 'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey, |
|
261 | - 'recaptcha_theme' => EED_Recaptcha::$config->recaptcha_theme, |
|
262 | - 'recaptcha_type' => EED_Recaptcha::$config->recaptcha_type, |
|
263 | - ) |
|
264 | - ); |
|
265 | - wp_enqueue_script('google_recaptcha'); |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * @return array |
|
272 | - * @throws InvalidArgumentException |
|
273 | - * @throws InvalidInterfaceException |
|
274 | - * @throws InvalidDataTypeException |
|
275 | - */ |
|
276 | - public static function bypass_recaptcha_for_spco_load_payment_method() |
|
277 | - { |
|
278 | - return array( |
|
279 | - 'EESID' => EE_Registry::instance()->SSN->id(), |
|
280 | - 'step' => 'payment_options', |
|
281 | - 'action' => 'switch_spco_billing_form', |
|
282 | - ); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @return boolean |
|
288 | - * @throws InvalidArgumentException |
|
289 | - * @throws InvalidInterfaceException |
|
290 | - * @throws InvalidDataTypeException |
|
291 | - */ |
|
292 | - public static function recaptcha_passed() |
|
293 | - { |
|
294 | - // logged in means you have already passed a turing test of sorts |
|
295 | - if (is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha()) { |
|
296 | - return true; |
|
297 | - } |
|
298 | - // was test already passed? |
|
299 | - $recaptcha_passed = EE_Registry::instance()->SSN->get_session_data('recaptcha_passed'); |
|
300 | - $recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN); |
|
301 | - // verify recaptcha |
|
302 | - EED_Recaptcha::_get_recaptcha_response(); |
|
303 | - if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) { |
|
304 | - $recaptcha_passed = EED_Recaptcha::_process_recaptcha_response(); |
|
305 | - EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed)); |
|
306 | - } |
|
307 | - EED_Recaptcha::$_not_a_robot = $recaptcha_passed; |
|
308 | - return $recaptcha_passed; |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * @param array $recaptcha_response |
|
314 | - * @return array |
|
315 | - */ |
|
316 | - public static function recaptcha_response($recaptcha_response = array()) |
|
317 | - { |
|
318 | - if (EED_Recaptcha::_bypass_recaptcha()) { |
|
319 | - $recaptcha_response['bypass_recaptcha'] = true; |
|
320 | - $recaptcha_response['recaptcha_passed'] = true; |
|
321 | - } else { |
|
322 | - $recaptcha_response['recaptcha_passed'] = EED_Recaptcha::$_not_a_robot; |
|
323 | - } |
|
324 | - return $recaptcha_response; |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * @return boolean |
|
330 | - */ |
|
331 | - private static function _bypass_recaptcha() |
|
332 | - { |
|
333 | - // an array of key value pairs that must match exactly with the incoming request, |
|
334 | - // in order to bypass recaptcha for the current request ONLY |
|
335 | - $bypass_request_params_array = (array) apply_filters( |
|
336 | - 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
337 | - array() |
|
338 | - ); |
|
339 | - // does $bypass_request_params_array have any values ? |
|
340 | - if (empty($bypass_request_params_array)) { |
|
341 | - return false; |
|
342 | - } |
|
343 | - // initially set bypass to TRUE |
|
344 | - $bypass_recaptcha = true; |
|
345 | - foreach ($bypass_request_params_array as $key => $value) { |
|
346 | - // if $key is not found or value doesn't match exactly, then toggle bypass to FALSE, |
|
347 | - // otherwise carry over it's value. This way, one missed setting results in no bypass |
|
348 | - $bypass_recaptcha = isset($_REQUEST[ $key ]) && $_REQUEST[ $key ] === $value |
|
349 | - ? $bypass_recaptcha |
|
350 | - : false; |
|
351 | - } |
|
352 | - return $bypass_recaptcha; |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * @return void |
|
358 | - * @throws InvalidArgumentException |
|
359 | - * @throws InvalidInterfaceException |
|
360 | - * @throws InvalidDataTypeException |
|
361 | - */ |
|
362 | - private static function _get_recaptcha_response() |
|
363 | - { |
|
364 | - EED_Recaptcha::$_recaptcha_response = EE_Registry::instance()->REQ->get( |
|
365 | - 'g-recaptcha-response', |
|
366 | - false |
|
367 | - ); |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * @return boolean |
|
373 | - * @throws InvalidArgumentException |
|
374 | - * @throws InvalidInterfaceException |
|
375 | - * @throws InvalidDataTypeException |
|
376 | - */ |
|
377 | - private static function _process_recaptcha_response() |
|
378 | - { |
|
379 | - // verify library is loaded |
|
380 | - if (! class_exists('\ReCaptcha\ReCaptcha')) { |
|
381 | - require_once RECAPTCHA_BASE_PATH . DS . 'autoload.php'; |
|
382 | - } |
|
383 | - // The response from reCAPTCHA |
|
384 | - EED_Recaptcha::_get_recaptcha_response(); |
|
385 | - $recaptcha_response = EED_Recaptcha::$_recaptcha_response; |
|
386 | - // Was there a reCAPTCHA response? |
|
387 | - if ($recaptcha_response) { |
|
388 | - // if allow_url_fopen is Off, then set a different request method |
|
389 | - $request_method = ! ini_get('allow_url_fopen') ? new SocketPost() : null; |
|
390 | - $recaptcha = new ReCaptcha( |
|
391 | - EED_Recaptcha::$config->recaptcha_privatekey, |
|
392 | - $request_method |
|
393 | - ); |
|
394 | - $recaptcha_response = $recaptcha->verify( |
|
395 | - EED_Recaptcha::$_recaptcha_response, |
|
396 | - $_SERVER['REMOTE_ADDR'] |
|
397 | - ); |
|
398 | - } |
|
399 | - return $recaptcha_response instanceof Response && $recaptcha_response->isSuccess(); |
|
400 | - } |
|
25 | + /** |
|
26 | + * @var EE_Registration_Config $config |
|
27 | + */ |
|
28 | + private static $config; |
|
29 | + |
|
30 | + /** |
|
31 | + * @type bool $_not_a_robot |
|
32 | + */ |
|
33 | + private static $_not_a_robot; |
|
34 | + |
|
35 | + /** |
|
36 | + * @type string $_recaptcha_response |
|
37 | + */ |
|
38 | + private static $_recaptcha_response; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * @return EED_Module|EED_Recaptcha |
|
43 | + */ |
|
44 | + public static function instance() |
|
45 | + { |
|
46 | + return parent::get_instance(__CLASS__); |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
52 | + * |
|
53 | + * @return void |
|
54 | + * @throws InvalidArgumentException |
|
55 | + * @throws InvalidInterfaceException |
|
56 | + * @throws InvalidDataTypeException |
|
57 | + */ |
|
58 | + public static function set_hooks() |
|
59 | + { |
|
60 | + EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration; |
|
61 | + // use_captcha ? |
|
62 | + if ( |
|
63 | + EED_Recaptcha::useRecaptcha() |
|
64 | + && EED_Recaptcha::notPaymentOptionsRevisit() |
|
65 | + ) { |
|
66 | + EED_Recaptcha::set_definitions(); |
|
67 | + EED_Recaptcha::enqueue_styles_and_scripts(); |
|
68 | + add_action('wp', array('EED_Recaptcha', 'set_late_hooks'), 1, 0); |
|
69 | + add_action( |
|
70 | + 'AHEE__before_spco_whats_next_buttons', |
|
71 | + array('EED_Recaptcha', 'display_recaptcha'), 10, 0 |
|
72 | + ); |
|
73 | + add_filter( |
|
74 | + 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
75 | + array('EED_Recaptcha', 'not_a_robot') |
|
76 | + ); |
|
77 | + add_filter( |
|
78 | + 'FHEE__EE_SPCO_Reg_Step__set_completed___completed', |
|
79 | + array('EED_Recaptcha', 'not_a_robot') |
|
80 | + ); |
|
81 | + add_filter( |
|
82 | + 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', |
|
83 | + array('EED_Recaptcha', 'recaptcha_response') |
|
84 | + ); |
|
85 | + add_filter( |
|
86 | + 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
87 | + array('EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method') |
|
88 | + ); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
95 | + * |
|
96 | + * @return void |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws InvalidInterfaceException |
|
99 | + * @throws InvalidDataTypeException |
|
100 | + */ |
|
101 | + public static function set_hooks_admin() |
|
102 | + { |
|
103 | + EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration; |
|
104 | + EED_Recaptcha::set_definitions(); |
|
105 | + // use_captcha ? |
|
106 | + if ( |
|
107 | + EED_Recaptcha::useRecaptcha() |
|
108 | + && EED_Recaptcha::notPaymentOptionsRevisit() |
|
109 | + && EE_Registry::instance()->REQ->get('step', '') !== '' |
|
110 | + ) { |
|
111 | + EED_Recaptcha::enqueue_styles_and_scripts(); |
|
112 | + add_filter( |
|
113 | + 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
114 | + array('EED_Recaptcha', 'not_a_robot') |
|
115 | + ); |
|
116 | + add_filter( |
|
117 | + 'FHEE__EE_SPCO_Reg_Step__set_completed___completed', |
|
118 | + array('EED_Recaptcha', 'not_a_robot') |
|
119 | + ); |
|
120 | + add_filter( |
|
121 | + 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', |
|
122 | + array('EED_Recaptcha', 'recaptcha_response') |
|
123 | + ); |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @return void |
|
130 | + */ |
|
131 | + public static function set_definitions() |
|
132 | + { |
|
133 | + if (is_user_logged_in()) { |
|
134 | + EED_Recaptcha::$_not_a_robot = true; |
|
135 | + } |
|
136 | + define( |
|
137 | + 'RECAPTCHA_BASE_PATH', |
|
138 | + rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
139 | + ); |
|
140 | + define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__)); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + public static function set_late_hooks() |
|
148 | + { |
|
149 | + add_filter( |
|
150 | + 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
151 | + array('EED_Recaptcha', 'not_a_robot') |
|
152 | + ); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @return boolean |
|
158 | + */ |
|
159 | + public static function useRecaptcha() |
|
160 | + { |
|
161 | + return EED_Recaptcha::$config->use_captcha |
|
162 | + && EED_Recaptcha::$config->recaptcha_theme !== 'invisible'; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @return boolean |
|
168 | + * @throws InvalidArgumentException |
|
169 | + * @throws InvalidInterfaceException |
|
170 | + * @throws InvalidDataTypeException |
|
171 | + */ |
|
172 | + public static function notPaymentOptionsRevisit() |
|
173 | + { |
|
174 | + return ! ( |
|
175 | + EE_Registry::instance()->REQ->get('step', '') === 'payment_options' |
|
176 | + && (boolean) EE_Registry::instance()->REQ->get('revisit', false) === true |
|
177 | + ); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * @return void |
|
183 | + * @throws InvalidArgumentException |
|
184 | + * @throws InvalidInterfaceException |
|
185 | + * @throws InvalidDataTypeException |
|
186 | + */ |
|
187 | + public static function enqueue_styles_and_scripts() |
|
188 | + { |
|
189 | + wp_register_script( |
|
190 | + 'espresso_recaptcha', |
|
191 | + RECAPTCHA_BASE_URL . 'scripts' . DS . 'espresso_recaptcha.js', |
|
192 | + array('single_page_checkout'), |
|
193 | + EVENT_ESPRESSO_VERSION, |
|
194 | + true |
|
195 | + ); |
|
196 | + wp_register_script( |
|
197 | + 'google_recaptcha', |
|
198 | + 'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language, |
|
199 | + array('espresso_recaptcha'), |
|
200 | + EVENT_ESPRESSO_VERSION, |
|
201 | + true |
|
202 | + ); |
|
203 | + EE_Registry::$i18n_js_strings['no_SPCO_error'] = __( |
|
204 | + 'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.', |
|
205 | + 'event_espresso' |
|
206 | + ); |
|
207 | + EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __( |
|
208 | + 'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.', |
|
209 | + 'event_espresso' |
|
210 | + ); |
|
211 | + EE_Registry::$i18n_js_strings['recaptcha_fail'] = __( |
|
212 | + 'Please complete the anti-spam test before proceeding.', |
|
213 | + 'event_espresso' |
|
214 | + ); |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * @param \WP $WP |
|
220 | + */ |
|
221 | + public function run($WP) |
|
222 | + { |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * @return boolean |
|
228 | + * @throws InvalidArgumentException |
|
229 | + * @throws InvalidInterfaceException |
|
230 | + * @throws InvalidDataTypeException |
|
231 | + */ |
|
232 | + public static function not_a_robot() |
|
233 | + { |
|
234 | + $not_a_robot = is_bool(EED_Recaptcha::$_not_a_robot) |
|
235 | + ? EED_Recaptcha::$_not_a_robot |
|
236 | + : EED_Recaptcha::recaptcha_passed(); |
|
237 | + return $not_a_robot; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @return void |
|
243 | + * @throws DomainException |
|
244 | + * @throws InvalidArgumentException |
|
245 | + * @throws InvalidInterfaceException |
|
246 | + * @throws InvalidDataTypeException |
|
247 | + */ |
|
248 | + public static function display_recaptcha() |
|
249 | + { |
|
250 | + // logged in means you have already passed a turing test of sorts |
|
251 | + if (is_user_logged_in()) { |
|
252 | + return; |
|
253 | + } |
|
254 | + // don't display if not using recaptcha or user is logged in |
|
255 | + if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) { |
|
256 | + // only display if they have NOT passed the test yet |
|
257 | + EEH_Template::display_template( |
|
258 | + RECAPTCHA_BASE_PATH . DS . 'templates' . DS . 'recaptcha.template.php', |
|
259 | + array( |
|
260 | + 'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey, |
|
261 | + 'recaptcha_theme' => EED_Recaptcha::$config->recaptcha_theme, |
|
262 | + 'recaptcha_type' => EED_Recaptcha::$config->recaptcha_type, |
|
263 | + ) |
|
264 | + ); |
|
265 | + wp_enqueue_script('google_recaptcha'); |
|
266 | + } |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * @return array |
|
272 | + * @throws InvalidArgumentException |
|
273 | + * @throws InvalidInterfaceException |
|
274 | + * @throws InvalidDataTypeException |
|
275 | + */ |
|
276 | + public static function bypass_recaptcha_for_spco_load_payment_method() |
|
277 | + { |
|
278 | + return array( |
|
279 | + 'EESID' => EE_Registry::instance()->SSN->id(), |
|
280 | + 'step' => 'payment_options', |
|
281 | + 'action' => 'switch_spco_billing_form', |
|
282 | + ); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @return boolean |
|
288 | + * @throws InvalidArgumentException |
|
289 | + * @throws InvalidInterfaceException |
|
290 | + * @throws InvalidDataTypeException |
|
291 | + */ |
|
292 | + public static function recaptcha_passed() |
|
293 | + { |
|
294 | + // logged in means you have already passed a turing test of sorts |
|
295 | + if (is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha()) { |
|
296 | + return true; |
|
297 | + } |
|
298 | + // was test already passed? |
|
299 | + $recaptcha_passed = EE_Registry::instance()->SSN->get_session_data('recaptcha_passed'); |
|
300 | + $recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN); |
|
301 | + // verify recaptcha |
|
302 | + EED_Recaptcha::_get_recaptcha_response(); |
|
303 | + if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) { |
|
304 | + $recaptcha_passed = EED_Recaptcha::_process_recaptcha_response(); |
|
305 | + EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed)); |
|
306 | + } |
|
307 | + EED_Recaptcha::$_not_a_robot = $recaptcha_passed; |
|
308 | + return $recaptcha_passed; |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * @param array $recaptcha_response |
|
314 | + * @return array |
|
315 | + */ |
|
316 | + public static function recaptcha_response($recaptcha_response = array()) |
|
317 | + { |
|
318 | + if (EED_Recaptcha::_bypass_recaptcha()) { |
|
319 | + $recaptcha_response['bypass_recaptcha'] = true; |
|
320 | + $recaptcha_response['recaptcha_passed'] = true; |
|
321 | + } else { |
|
322 | + $recaptcha_response['recaptcha_passed'] = EED_Recaptcha::$_not_a_robot; |
|
323 | + } |
|
324 | + return $recaptcha_response; |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * @return boolean |
|
330 | + */ |
|
331 | + private static function _bypass_recaptcha() |
|
332 | + { |
|
333 | + // an array of key value pairs that must match exactly with the incoming request, |
|
334 | + // in order to bypass recaptcha for the current request ONLY |
|
335 | + $bypass_request_params_array = (array) apply_filters( |
|
336 | + 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
337 | + array() |
|
338 | + ); |
|
339 | + // does $bypass_request_params_array have any values ? |
|
340 | + if (empty($bypass_request_params_array)) { |
|
341 | + return false; |
|
342 | + } |
|
343 | + // initially set bypass to TRUE |
|
344 | + $bypass_recaptcha = true; |
|
345 | + foreach ($bypass_request_params_array as $key => $value) { |
|
346 | + // if $key is not found or value doesn't match exactly, then toggle bypass to FALSE, |
|
347 | + // otherwise carry over it's value. This way, one missed setting results in no bypass |
|
348 | + $bypass_recaptcha = isset($_REQUEST[ $key ]) && $_REQUEST[ $key ] === $value |
|
349 | + ? $bypass_recaptcha |
|
350 | + : false; |
|
351 | + } |
|
352 | + return $bypass_recaptcha; |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * @return void |
|
358 | + * @throws InvalidArgumentException |
|
359 | + * @throws InvalidInterfaceException |
|
360 | + * @throws InvalidDataTypeException |
|
361 | + */ |
|
362 | + private static function _get_recaptcha_response() |
|
363 | + { |
|
364 | + EED_Recaptcha::$_recaptcha_response = EE_Registry::instance()->REQ->get( |
|
365 | + 'g-recaptcha-response', |
|
366 | + false |
|
367 | + ); |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * @return boolean |
|
373 | + * @throws InvalidArgumentException |
|
374 | + * @throws InvalidInterfaceException |
|
375 | + * @throws InvalidDataTypeException |
|
376 | + */ |
|
377 | + private static function _process_recaptcha_response() |
|
378 | + { |
|
379 | + // verify library is loaded |
|
380 | + if (! class_exists('\ReCaptcha\ReCaptcha')) { |
|
381 | + require_once RECAPTCHA_BASE_PATH . DS . 'autoload.php'; |
|
382 | + } |
|
383 | + // The response from reCAPTCHA |
|
384 | + EED_Recaptcha::_get_recaptcha_response(); |
|
385 | + $recaptcha_response = EED_Recaptcha::$_recaptcha_response; |
|
386 | + // Was there a reCAPTCHA response? |
|
387 | + if ($recaptcha_response) { |
|
388 | + // if allow_url_fopen is Off, then set a different request method |
|
389 | + $request_method = ! ini_get('allow_url_fopen') ? new SocketPost() : null; |
|
390 | + $recaptcha = new ReCaptcha( |
|
391 | + EED_Recaptcha::$config->recaptcha_privatekey, |
|
392 | + $request_method |
|
393 | + ); |
|
394 | + $recaptcha_response = $recaptcha->verify( |
|
395 | + EED_Recaptcha::$_recaptcha_response, |
|
396 | + $_SERVER['REMOTE_ADDR'] |
|
397 | + ); |
|
398 | + } |
|
399 | + return $recaptcha_response instanceof Response && $recaptcha_response->isSuccess(); |
|
400 | + } |
|
401 | 401 | } |
402 | 402 | // End of file EED_Recaptcha.module.php |
403 | 403 | // Location: /modules/recaptcha/EED_Recaptcha.module.php |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | } |
136 | 136 | define( |
137 | 137 | 'RECAPTCHA_BASE_PATH', |
138 | - rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
138 | + rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS |
|
139 | 139 | ); |
140 | 140 | define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__)); |
141 | 141 | } |
@@ -188,19 +188,19 @@ discard block |
||
188 | 188 | { |
189 | 189 | wp_register_script( |
190 | 190 | 'espresso_recaptcha', |
191 | - RECAPTCHA_BASE_URL . 'scripts' . DS . 'espresso_recaptcha.js', |
|
191 | + RECAPTCHA_BASE_URL.'scripts'.DS.'espresso_recaptcha.js', |
|
192 | 192 | array('single_page_checkout'), |
193 | 193 | EVENT_ESPRESSO_VERSION, |
194 | 194 | true |
195 | 195 | ); |
196 | 196 | wp_register_script( |
197 | 197 | 'google_recaptcha', |
198 | - 'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language, |
|
198 | + 'https://www.google.com/recaptcha/api.js?hl='.EED_Recaptcha::$config->recaptcha_language, |
|
199 | 199 | array('espresso_recaptcha'), |
200 | 200 | EVENT_ESPRESSO_VERSION, |
201 | 201 | true |
202 | 202 | ); |
203 | - EE_Registry::$i18n_js_strings['no_SPCO_error'] = __( |
|
203 | + EE_Registry::$i18n_js_strings['no_SPCO_error'] = __( |
|
204 | 204 | 'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.', |
205 | 205 | 'event_espresso' |
206 | 206 | ); |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | 'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.', |
209 | 209 | 'event_espresso' |
210 | 210 | ); |
211 | - EE_Registry::$i18n_js_strings['recaptcha_fail'] = __( |
|
211 | + EE_Registry::$i18n_js_strings['recaptcha_fail'] = __( |
|
212 | 212 | 'Please complete the anti-spam test before proceeding.', |
213 | 213 | 'event_espresso' |
214 | 214 | ); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) { |
256 | 256 | // only display if they have NOT passed the test yet |
257 | 257 | EEH_Template::display_template( |
258 | - RECAPTCHA_BASE_PATH . DS . 'templates' . DS . 'recaptcha.template.php', |
|
258 | + RECAPTCHA_BASE_PATH.DS.'templates'.DS.'recaptcha.template.php', |
|
259 | 259 | array( |
260 | 260 | 'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey, |
261 | 261 | 'recaptcha_theme' => EED_Recaptcha::$config->recaptcha_theme, |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | $recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN); |
301 | 301 | // verify recaptcha |
302 | 302 | EED_Recaptcha::_get_recaptcha_response(); |
303 | - if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) { |
|
303 | + if ( ! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) { |
|
304 | 304 | $recaptcha_passed = EED_Recaptcha::_process_recaptcha_response(); |
305 | 305 | EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed)); |
306 | 306 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | foreach ($bypass_request_params_array as $key => $value) { |
346 | 346 | // if $key is not found or value doesn't match exactly, then toggle bypass to FALSE, |
347 | 347 | // otherwise carry over it's value. This way, one missed setting results in no bypass |
348 | - $bypass_recaptcha = isset($_REQUEST[ $key ]) && $_REQUEST[ $key ] === $value |
|
348 | + $bypass_recaptcha = isset($_REQUEST[$key]) && $_REQUEST[$key] === $value |
|
349 | 349 | ? $bypass_recaptcha |
350 | 350 | : false; |
351 | 351 | } |
@@ -377,8 +377,8 @@ discard block |
||
377 | 377 | private static function _process_recaptcha_response() |
378 | 378 | { |
379 | 379 | // verify library is loaded |
380 | - if (! class_exists('\ReCaptcha\ReCaptcha')) { |
|
381 | - require_once RECAPTCHA_BASE_PATH . DS . 'autoload.php'; |
|
380 | + if ( ! class_exists('\ReCaptcha\ReCaptcha')) { |
|
381 | + require_once RECAPTCHA_BASE_PATH.DS.'autoload.php'; |
|
382 | 382 | } |
383 | 383 | // The response from reCAPTCHA |
384 | 384 | EED_Recaptcha::_get_recaptcha_response(); |
@@ -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,673 +16,673 @@ 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 | - } |
|
485 | - // hidden inputs for frontend registrations |
|
486 | - return new EE_Form_Section_Proper( |
|
487 | - array( |
|
488 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
489 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
490 | - 'subsections' => array( |
|
491 | - 'action' => new EE_Fixed_Hidden_Input( |
|
492 | - array( |
|
493 | - 'html_name' => 'action', |
|
494 | - 'html_id' => 'spco-' . $this->slug() . '-action', |
|
495 | - 'default' => apply_filters( |
|
496 | - 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
|
497 | - empty($this->checkout->reg_url_link) |
|
498 | - ? 'process_reg_step' |
|
499 | - : 'update_reg_step', |
|
500 | - $this |
|
501 | - ), |
|
502 | - ) |
|
503 | - ), |
|
504 | - 'next_step' => new EE_Fixed_Hidden_Input( |
|
505 | - array( |
|
506 | - 'html_name' => 'next_step', |
|
507 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
508 | - 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
509 | - ? $this->checkout->next_step->slug() |
|
510 | - : '', |
|
511 | - ) |
|
512 | - ), |
|
513 | - 'e_reg_url_link' => new EE_Fixed_Hidden_Input( |
|
514 | - array( |
|
515 | - 'html_name' => 'e_reg_url_link', |
|
516 | - 'html_id' => 'spco-reg_url_link', |
|
517 | - 'default' => $this->checkout->reg_url_link, |
|
518 | - ) |
|
519 | - ), |
|
520 | - 'revisit' => new EE_Fixed_Hidden_Input( |
|
521 | - array( |
|
522 | - 'html_name' => 'revisit', |
|
523 | - 'html_id' => 'spco-revisit', |
|
524 | - 'default' => $this->checkout->revisit, |
|
525 | - ) |
|
526 | - ), |
|
527 | - ), |
|
528 | - ) |
|
529 | - ); |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * generate_reg_form_for_actions |
|
536 | - * |
|
537 | - * @param array $actions |
|
538 | - * @return void |
|
539 | - */ |
|
540 | - public function generate_reg_form_for_actions($actions = array()) |
|
541 | - { |
|
542 | - $actions = array_merge( |
|
543 | - array( |
|
544 | - 'generate_reg_form', |
|
545 | - 'display_spco_reg_step', |
|
546 | - 'process_reg_step', |
|
547 | - 'update_reg_step', |
|
548 | - ), |
|
549 | - $actions |
|
550 | - ); |
|
551 | - $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true) ? true : false; |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * @return string |
|
558 | - * @throws \EE_Error |
|
559 | - */ |
|
560 | - public function display_reg_form() |
|
561 | - { |
|
562 | - $html = ''; |
|
563 | - if ($this->reg_form instanceof EE_Form_Section_Proper) { |
|
564 | - do_action('AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', $this->reg_form, $this); |
|
565 | - $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : ''; |
|
566 | - if (EE_Registry::instance()->REQ->ajax) { |
|
567 | - $this->reg_form->localize_validation_rules(); |
|
568 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
569 | - } |
|
570 | - $html .= $this->reg_form->get_html(); |
|
571 | - $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : ''; |
|
572 | - $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : ''; |
|
573 | - } |
|
574 | - return $html; |
|
575 | - } |
|
576 | - |
|
577 | - |
|
578 | - |
|
579 | - /** |
|
580 | - * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
581 | - * |
|
582 | - * @return string |
|
583 | - * @throws \EE_Error |
|
584 | - */ |
|
585 | - public function reg_step_submit_button() |
|
586 | - { |
|
587 | - if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
588 | - return ''; |
|
589 | - } |
|
590 | - ob_start(); |
|
591 | - do_action( |
|
592 | - 'AHEE__before_spco_whats_next_buttons', |
|
593 | - $this->slug(), |
|
594 | - $this->checkout->next_step->slug(), |
|
595 | - $this->checkout |
|
596 | - ); |
|
597 | - $html = ob_get_clean(); |
|
598 | - // generate submit button |
|
599 | - $sbmt_btn = new EE_Submit_Input( |
|
600 | - 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 | - ); |
|
608 | - $sbmt_btn->set_button_css_attributes(true, 'large'); |
|
609 | - $sbmt_btn_html = $sbmt_btn->get_html_for_input(); |
|
610 | - $html .= EEH_HTML::div( |
|
611 | - apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this), |
|
612 | - 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
613 | - 'spco-whats-next-buttons' |
|
614 | - ); |
|
615 | - return $html; |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - |
|
620 | - /** |
|
621 | - * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
622 | - * |
|
623 | - * @return string |
|
624 | - */ |
|
625 | - public function div_class() |
|
626 | - { |
|
627 | - return $this->is_current_step() ? '' : ' hidden'; |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
634 | - * |
|
635 | - * @return string |
|
636 | - */ |
|
637 | - public function edit_lnk_url() |
|
638 | - { |
|
639 | - return add_query_arg(array('step' => $this->slug()), $this->checkout->reg_page_base_url); |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
646 | - * |
|
647 | - * @return string |
|
648 | - */ |
|
649 | - public function edit_link_class() |
|
650 | - { |
|
651 | - return $this->is_current_step() ? ' hidden' : ''; |
|
652 | - } |
|
653 | - |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * update_checkout with changes that have been made to the cart |
|
658 | - * |
|
659 | - * @return void |
|
660 | - * @throws \EE_Error |
|
661 | - */ |
|
662 | - public function update_checkout() |
|
663 | - { |
|
664 | - // grab the cart grand total and reset TXN total |
|
665 | - $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total()); |
|
666 | - $this->checkout->stash_transaction_and_checkout(); |
|
667 | - } |
|
668 | - |
|
669 | - |
|
670 | - |
|
671 | - |
|
672 | - |
|
673 | - /** |
|
674 | - * __sleep |
|
675 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
676 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
677 | - * reg form, because if needed, it will be regenerated anyways |
|
678 | - * |
|
679 | - * @return array |
|
680 | - */ |
|
681 | - public function __sleep() |
|
682 | - { |
|
683 | - // remove the reg form and the checkout |
|
684 | - return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout')); |
|
685 | - } |
|
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 | + } |
|
485 | + // hidden inputs for frontend registrations |
|
486 | + return new EE_Form_Section_Proper( |
|
487 | + array( |
|
488 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
489 | + 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
490 | + 'subsections' => array( |
|
491 | + 'action' => new EE_Fixed_Hidden_Input( |
|
492 | + array( |
|
493 | + 'html_name' => 'action', |
|
494 | + 'html_id' => 'spco-' . $this->slug() . '-action', |
|
495 | + 'default' => apply_filters( |
|
496 | + 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
|
497 | + empty($this->checkout->reg_url_link) |
|
498 | + ? 'process_reg_step' |
|
499 | + : 'update_reg_step', |
|
500 | + $this |
|
501 | + ), |
|
502 | + ) |
|
503 | + ), |
|
504 | + 'next_step' => new EE_Fixed_Hidden_Input( |
|
505 | + array( |
|
506 | + 'html_name' => 'next_step', |
|
507 | + 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
508 | + 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
509 | + ? $this->checkout->next_step->slug() |
|
510 | + : '', |
|
511 | + ) |
|
512 | + ), |
|
513 | + 'e_reg_url_link' => new EE_Fixed_Hidden_Input( |
|
514 | + array( |
|
515 | + 'html_name' => 'e_reg_url_link', |
|
516 | + 'html_id' => 'spco-reg_url_link', |
|
517 | + 'default' => $this->checkout->reg_url_link, |
|
518 | + ) |
|
519 | + ), |
|
520 | + 'revisit' => new EE_Fixed_Hidden_Input( |
|
521 | + array( |
|
522 | + 'html_name' => 'revisit', |
|
523 | + 'html_id' => 'spco-revisit', |
|
524 | + 'default' => $this->checkout->revisit, |
|
525 | + ) |
|
526 | + ), |
|
527 | + ), |
|
528 | + ) |
|
529 | + ); |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * generate_reg_form_for_actions |
|
536 | + * |
|
537 | + * @param array $actions |
|
538 | + * @return void |
|
539 | + */ |
|
540 | + public function generate_reg_form_for_actions($actions = array()) |
|
541 | + { |
|
542 | + $actions = array_merge( |
|
543 | + array( |
|
544 | + 'generate_reg_form', |
|
545 | + 'display_spco_reg_step', |
|
546 | + 'process_reg_step', |
|
547 | + 'update_reg_step', |
|
548 | + ), |
|
549 | + $actions |
|
550 | + ); |
|
551 | + $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true) ? true : false; |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * @return string |
|
558 | + * @throws \EE_Error |
|
559 | + */ |
|
560 | + public function display_reg_form() |
|
561 | + { |
|
562 | + $html = ''; |
|
563 | + if ($this->reg_form instanceof EE_Form_Section_Proper) { |
|
564 | + do_action('AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', $this->reg_form, $this); |
|
565 | + $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : ''; |
|
566 | + if (EE_Registry::instance()->REQ->ajax) { |
|
567 | + $this->reg_form->localize_validation_rules(); |
|
568 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
569 | + } |
|
570 | + $html .= $this->reg_form->get_html(); |
|
571 | + $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : ''; |
|
572 | + $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : ''; |
|
573 | + } |
|
574 | + return $html; |
|
575 | + } |
|
576 | + |
|
577 | + |
|
578 | + |
|
579 | + /** |
|
580 | + * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
581 | + * |
|
582 | + * @return string |
|
583 | + * @throws \EE_Error |
|
584 | + */ |
|
585 | + public function reg_step_submit_button() |
|
586 | + { |
|
587 | + if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
588 | + return ''; |
|
589 | + } |
|
590 | + ob_start(); |
|
591 | + do_action( |
|
592 | + 'AHEE__before_spco_whats_next_buttons', |
|
593 | + $this->slug(), |
|
594 | + $this->checkout->next_step->slug(), |
|
595 | + $this->checkout |
|
596 | + ); |
|
597 | + $html = ob_get_clean(); |
|
598 | + // generate submit button |
|
599 | + $sbmt_btn = new EE_Submit_Input( |
|
600 | + 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 | + ); |
|
608 | + $sbmt_btn->set_button_css_attributes(true, 'large'); |
|
609 | + $sbmt_btn_html = $sbmt_btn->get_html_for_input(); |
|
610 | + $html .= EEH_HTML::div( |
|
611 | + apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this), |
|
612 | + 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
613 | + 'spco-whats-next-buttons' |
|
614 | + ); |
|
615 | + return $html; |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + |
|
620 | + /** |
|
621 | + * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
622 | + * |
|
623 | + * @return string |
|
624 | + */ |
|
625 | + public function div_class() |
|
626 | + { |
|
627 | + return $this->is_current_step() ? '' : ' hidden'; |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
634 | + * |
|
635 | + * @return string |
|
636 | + */ |
|
637 | + public function edit_lnk_url() |
|
638 | + { |
|
639 | + return add_query_arg(array('step' => $this->slug()), $this->checkout->reg_page_base_url); |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
646 | + * |
|
647 | + * @return string |
|
648 | + */ |
|
649 | + public function edit_link_class() |
|
650 | + { |
|
651 | + return $this->is_current_step() ? ' hidden' : ''; |
|
652 | + } |
|
653 | + |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * update_checkout with changes that have been made to the cart |
|
658 | + * |
|
659 | + * @return void |
|
660 | + * @throws \EE_Error |
|
661 | + */ |
|
662 | + public function update_checkout() |
|
663 | + { |
|
664 | + // grab the cart grand total and reset TXN total |
|
665 | + $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total()); |
|
666 | + $this->checkout->stash_transaction_and_checkout(); |
|
667 | + } |
|
668 | + |
|
669 | + |
|
670 | + |
|
671 | + |
|
672 | + |
|
673 | + /** |
|
674 | + * __sleep |
|
675 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
676 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
677 | + * reg form, because if needed, it will be regenerated anyways |
|
678 | + * |
|
679 | + * @return array |
|
680 | + */ |
|
681 | + public function __sleep() |
|
682 | + { |
|
683 | + // remove the reg form and the checkout |
|
684 | + return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout')); |
|
685 | + } |
|
686 | 686 | |
687 | 687 | |
688 | 688 |
@@ -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 | : '', |
@@ -486,12 +486,12 @@ discard block |
||
486 | 486 | return new EE_Form_Section_Proper( |
487 | 487 | array( |
488 | 488 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
489 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
489 | + 'html_id' => 'ee-'.$this->slug().'-hidden-inputs', |
|
490 | 490 | 'subsections' => array( |
491 | 491 | 'action' => new EE_Fixed_Hidden_Input( |
492 | 492 | array( |
493 | 493 | 'html_name' => 'action', |
494 | - 'html_id' => 'spco-' . $this->slug() . '-action', |
|
494 | + 'html_id' => 'spco-'.$this->slug().'-action', |
|
495 | 495 | 'default' => apply_filters( |
496 | 496 | 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
497 | 497 | empty($this->checkout->reg_url_link) |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | 'next_step' => new EE_Fixed_Hidden_Input( |
505 | 505 | array( |
506 | 506 | 'html_name' => 'next_step', |
507 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
507 | + 'html_id' => 'spco-'.$this->slug().'-next-step', |
|
508 | 508 | 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
509 | 509 | ? $this->checkout->next_step->slug() |
510 | 510 | : '', |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | */ |
585 | 585 | public function reg_step_submit_button() |
586 | 586 | { |
587 | - if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
587 | + if ( ! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
588 | 588 | return ''; |
589 | 589 | } |
590 | 590 | ob_start(); |
@@ -598,10 +598,10 @@ discard block |
||
598 | 598 | // generate submit button |
599 | 599 | $sbmt_btn = new EE_Submit_Input( |
600 | 600 | 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 | ); |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | $sbmt_btn_html = $sbmt_btn->get_html_for_input(); |
610 | 610 | $html .= EEH_HTML::div( |
611 | 611 | apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this), |
612 | - 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
612 | + 'spco-'.$this->slug().'-whats-next-buttons-dv', |
|
613 | 613 | 'spco-whats-next-buttons' |
614 | 614 | ); |
615 | 615 | return $html; |