@@ -1104,8 +1104,8 @@ discard block |
||
1104 | 1104 | * @param array $datetime_tickets |
1105 | 1105 | * @param array $all_tickets |
1106 | 1106 | * @param bool $default |
1107 | - * @param array $all_datetimes |
|
1108 | - * @return mixed |
|
1107 | + * @param EE_Datetime[] $all_datetimes |
|
1108 | + * @return string |
|
1109 | 1109 | * @throws DomainException |
1110 | 1110 | * @throws EE_Error |
1111 | 1111 | */ |
@@ -1213,7 +1213,7 @@ discard block |
||
1213 | 1213 | * @param array $datetime_tickets |
1214 | 1214 | * @param array $all_tickets |
1215 | 1215 | * @param bool $default |
1216 | - * @return mixed |
|
1216 | + * @return string |
|
1217 | 1217 | * @throws DomainException |
1218 | 1218 | * @throws EE_Error |
1219 | 1219 | */ |
@@ -1282,7 +1282,7 @@ discard block |
||
1282 | 1282 | * @param EE_Ticket $ticket |
1283 | 1283 | * @param array $datetime_tickets |
1284 | 1284 | * @param bool $default |
1285 | - * @return mixed |
|
1285 | + * @return string |
|
1286 | 1286 | * @throws DomainException |
1287 | 1287 | * @throws EE_Error |
1288 | 1288 | */ |
@@ -1353,7 +1353,7 @@ discard block |
||
1353 | 1353 | * @param bool $default Whether default row being generated or not. |
1354 | 1354 | * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
1355 | 1355 | * (or empty in the case of defaults) |
1356 | - * @return mixed |
|
1356 | + * @return string |
|
1357 | 1357 | * @throws DomainException |
1358 | 1358 | * @throws EE_Error |
1359 | 1359 | */ |
@@ -1673,7 +1673,7 @@ discard block |
||
1673 | 1673 | * @param EE_Ticket|null $ticket |
1674 | 1674 | * @param bool $show_trash |
1675 | 1675 | * @param bool $show_create |
1676 | - * @return mixed |
|
1676 | + * @return string |
|
1677 | 1677 | * @throws DomainException |
1678 | 1678 | * @throws EE_Error |
1679 | 1679 | */ |
@@ -1769,7 +1769,7 @@ discard block |
||
1769 | 1769 | * @param EE_Price $price |
1770 | 1770 | * @param bool $default |
1771 | 1771 | * @param bool $disabled |
1772 | - * @return mixed |
|
1772 | + * @return string |
|
1773 | 1773 | * @throws DomainException |
1774 | 1774 | * @throws EE_Error |
1775 | 1775 | */ |
@@ -1788,7 +1788,7 @@ discard block |
||
1788 | 1788 | * @param int $price_row |
1789 | 1789 | * @param EE_Price $price |
1790 | 1790 | * @param bool $default |
1791 | - * @return mixed |
|
1791 | + * @return string |
|
1792 | 1792 | * @throws DomainException |
1793 | 1793 | * @throws EE_Error |
1794 | 1794 | */ |
@@ -1826,7 +1826,7 @@ discard block |
||
1826 | 1826 | * @param EE_Price $price |
1827 | 1827 | * @param bool $default |
1828 | 1828 | * @param bool $disabled |
1829 | - * @return mixed |
|
1829 | + * @return string |
|
1830 | 1830 | * @throws DomainException |
1831 | 1831 | * @throws EE_Error |
1832 | 1832 | */ |
@@ -1930,7 +1930,7 @@ discard block |
||
1930 | 1930 | * @param EE_Ticket|null $ticket |
1931 | 1931 | * @param array $ticket_datetimes |
1932 | 1932 | * @param bool $default |
1933 | - * @return mixed |
|
1933 | + * @return string |
|
1934 | 1934 | * @throws DomainException |
1935 | 1935 | * @throws EE_Error |
1936 | 1936 | */ |
@@ -1984,9 +1984,9 @@ discard block |
||
1984 | 1984 | |
1985 | 1985 | |
1986 | 1986 | /** |
1987 | - * @param array $all_datetimes |
|
1987 | + * @param EE_Datetime[] $all_datetimes |
|
1988 | 1988 | * @param array $all_tickets |
1989 | - * @return mixed |
|
1989 | + * @return string |
|
1990 | 1990 | * @throws DomainException |
1991 | 1991 | * @throws EE_Error |
1992 | 1992 | */ |
@@ -15,2116 +15,2116 @@ |
||
15 | 15 | class espresso_events_Pricing_Hooks extends EE_Admin_Hooks |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * This property is just used to hold the status of whether an event is currently being |
|
20 | - * created (true) or edited (false) |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @var bool |
|
24 | - */ |
|
25 | - protected $_is_creating_event; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Used to contain the format strings for date and time that will be used for php date and |
|
30 | - * time. |
|
31 | - * Is set in the _set_hooks_properties() method. |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $_date_format_strings; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string $_date_time_format |
|
40 | - */ |
|
41 | - protected $_date_time_format; |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * |
|
47 | - */ |
|
48 | - protected function _set_hooks_properties() |
|
49 | - { |
|
50 | - $this->_name = 'pricing'; |
|
51 | - //capability check |
|
52 | - if ( |
|
53 | - ! EE_Registry::instance()->CAP->current_user_can( |
|
54 | - 'ee_read_default_prices', |
|
55 | - 'advanced_ticket_datetime_metabox' |
|
56 | - ) |
|
57 | - ) { |
|
58 | - return; |
|
59 | - } |
|
60 | - $this->_setup_metaboxes(); |
|
61 | - $this->_set_date_time_formats(); |
|
62 | - $this->_validate_format_strings(); |
|
63 | - $this->_set_scripts_styles(); |
|
64 | - // commented out temporarily until logic is implemented in callback |
|
65 | - // add_action( |
|
66 | - // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
67 | - // array($this, 'autosave_handling') |
|
68 | - // ); |
|
69 | - add_filter( |
|
70 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
71 | - array($this, 'caf_updates') |
|
72 | - ); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - protected function _setup_metaboxes() |
|
81 | - { |
|
82 | - //if we were going to add our own metaboxes we'd use the below. |
|
83 | - $this->_metaboxes = array( |
|
84 | - 0 => array( |
|
85 | - 'page_route' => array('edit', 'create_new'), |
|
86 | - 'func' => 'pricing_metabox', |
|
87 | - 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
88 | - 'priority' => 'high', |
|
89 | - 'context' => 'normal', |
|
90 | - ), |
|
91 | - ); |
|
92 | - $this->_remove_metaboxes = array( |
|
93 | - 0 => array( |
|
94 | - 'page_route' => array('edit', 'create_new'), |
|
95 | - 'id' => 'espresso_event_editor_tickets', |
|
96 | - 'context' => 'normal', |
|
97 | - ), |
|
98 | - ); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - protected function _set_date_time_formats() |
|
107 | - { |
|
108 | - /** |
|
109 | - * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
110 | - * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
111 | - * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
112 | - * |
|
113 | - * @since 4.6.7 |
|
114 | - * @var array Expected an array returned with 'date' and 'time' keys. |
|
115 | - */ |
|
116 | - $this->_date_format_strings = apply_filters( |
|
117 | - 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
118 | - array( |
|
119 | - 'date' => 'Y-m-d', |
|
120 | - 'time' => 'h:i a', |
|
121 | - ) |
|
122 | - ); |
|
123 | - //validate |
|
124 | - $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
125 | - ? $this->_date_format_strings['date'] |
|
126 | - : null; |
|
127 | - $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
128 | - ? $this->_date_format_strings['time'] |
|
129 | - : null; |
|
130 | - $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @return void |
|
137 | - */ |
|
138 | - protected function _validate_format_strings() |
|
139 | - { |
|
140 | - //validate format strings |
|
141 | - $format_validation = EEH_DTT_Helper::validate_format_string( |
|
142 | - $this->_date_time_format |
|
143 | - ); |
|
144 | - if (is_array($format_validation)) { |
|
145 | - $msg = '<p>'; |
|
146 | - $msg .= sprintf( |
|
147 | - esc_html__( |
|
148 | - 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
149 | - 'event_espresso' |
|
150 | - ), |
|
151 | - $this->_date_time_format |
|
152 | - ); |
|
153 | - $msg .= '</p><ul>'; |
|
154 | - foreach ($format_validation as $error) { |
|
155 | - $msg .= '<li>' . $error . '</li>'; |
|
156 | - } |
|
157 | - $msg .= '</ul><p>'; |
|
158 | - $msg .= sprintf( |
|
159 | - esc_html__( |
|
160 | - '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
161 | - 'event_espresso' |
|
162 | - ), |
|
163 | - '<span style="color:#D54E21;">', |
|
164 | - '</span>' |
|
165 | - ); |
|
166 | - $msg .= '</p>'; |
|
167 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | - $this->_date_format_strings = array( |
|
169 | - 'date' => 'Y-m-d', |
|
170 | - 'time' => 'h:i a', |
|
171 | - ); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @return void |
|
179 | - */ |
|
180 | - protected function _set_scripts_styles() |
|
181 | - { |
|
182 | - $this->_scripts_styles = array( |
|
183 | - 'registers' => array( |
|
184 | - 'ee-tickets-datetimes-css' => array( |
|
185 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
186 | - 'type' => 'css', |
|
187 | - ), |
|
188 | - 'ee-dtt-ticket-metabox' => array( |
|
189 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
190 | - 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
191 | - ), |
|
192 | - ), |
|
193 | - 'deregisters' => array( |
|
194 | - 'event-editor-css' => array('type' => 'css'), |
|
195 | - 'event-datetime-metabox' => array('type' => 'js'), |
|
196 | - ), |
|
197 | - 'enqueues' => array( |
|
198 | - 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
199 | - 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
200 | - ), |
|
201 | - 'localize' => array( |
|
202 | - 'ee-dtt-ticket-metabox' => array( |
|
203 | - 'DTT_TRASH_BLOCK' => array( |
|
204 | - 'main_warning' => esc_html__( |
|
205 | - 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
206 | - 'event_espresso' |
|
207 | - ), |
|
208 | - 'after_warning' => esc_html__( |
|
209 | - 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
210 | - 'event_espresso' |
|
211 | - ), |
|
212 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
213 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
214 | - 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
215 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
216 | - 'single_warning_from_tkt' => esc_html__( |
|
217 | - 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - 'single_warning_from_dtt' => esc_html__( |
|
221 | - 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
222 | - 'event_espresso' |
|
223 | - ), |
|
224 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
225 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
226 | - ), |
|
227 | - 'DTT_ERROR_MSG' => array( |
|
228 | - 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
229 | - 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
|
230 | - . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
231 | - ), |
|
232 | - 'DTT_OVERSELL_WARNING' => array( |
|
233 | - 'datetime_ticket' => esc_html__( |
|
234 | - 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
235 | - 'event_espresso' |
|
236 | - ), |
|
237 | - 'ticket_datetime' => esc_html__( |
|
238 | - 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
239 | - 'event_espresso' |
|
240 | - ), |
|
241 | - ), |
|
242 | - 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
243 | - $this->_date_format_strings['date'], |
|
244 | - $this->_date_format_strings['time'] |
|
245 | - ), |
|
246 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
247 | - ), |
|
248 | - ), |
|
249 | - ); |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @param array $update_callbacks |
|
256 | - * @return array |
|
257 | - */ |
|
258 | - public function caf_updates(array $update_callbacks) |
|
259 | - { |
|
260 | - foreach ($update_callbacks as $key => $callback) { |
|
261 | - if ($callback[1] === '_default_tickets_update') { |
|
262 | - unset($update_callbacks[$key]); |
|
263 | - } |
|
264 | - } |
|
265 | - $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
266 | - return $update_callbacks; |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
272 | - * |
|
273 | - * @param EE_Event $event The Event object we're attaching data to |
|
274 | - * @param array $data The request data from the form |
|
275 | - * @throws EE_Error |
|
276 | - * @throws InvalidArgumentException |
|
277 | - */ |
|
278 | - public function datetime_and_tickets_caf_update($event, $data) |
|
279 | - { |
|
280 | - //first we need to start with datetimes cause they are the "root" items attached to events. |
|
281 | - $saved_datetimes = $this->_update_datetimes($event, $data); |
|
282 | - //next tackle the tickets (and prices?) |
|
283 | - $this->_update_tickets($event, $saved_datetimes, $data); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * update event_datetimes |
|
289 | - * |
|
290 | - * @param EE_Event $event Event being updated |
|
291 | - * @param array $data the request data from the form |
|
292 | - * @return EE_Datetime[] |
|
293 | - * @throws InvalidArgumentException |
|
294 | - * @throws EE_Error |
|
295 | - */ |
|
296 | - protected function _update_datetimes($event, $data) |
|
297 | - { |
|
298 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
299 | - $saved_dtt_ids = array(); |
|
300 | - $saved_dtt_objs = array(); |
|
301 | - if (empty($data['edit_event_datetimes']) || !is_array($data['edit_event_datetimes'])) { |
|
302 | - throw new InvalidArgumentException( |
|
303 | - esc_html__( |
|
304 | - 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
305 | - 'event_espresso' |
|
306 | - ) |
|
307 | - ); |
|
308 | - } |
|
309 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
310 | - //trim all values to ensure any excess whitespace is removed. |
|
311 | - $datetime_data = array_map( |
|
312 | - function ($datetime_data) { |
|
313 | - return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
314 | - }, |
|
315 | - $datetime_data |
|
316 | - ); |
|
317 | - $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
318 | - && ! empty($datetime_data['DTT_EVT_end']) |
|
319 | - ? $datetime_data['DTT_EVT_end'] |
|
320 | - : $datetime_data['DTT_EVT_start']; |
|
321 | - $datetime_values = array( |
|
322 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
323 | - ? $datetime_data['DTT_ID'] |
|
324 | - : null, |
|
325 | - 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
326 | - ? $datetime_data['DTT_name'] |
|
327 | - : '', |
|
328 | - 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
329 | - ? $datetime_data['DTT_description'] |
|
330 | - : '', |
|
331 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
332 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
333 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
334 | - ? EE_INF |
|
335 | - : $datetime_data['DTT_reg_limit'], |
|
336 | - 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
337 | - ? $row |
|
338 | - : $datetime_data['DTT_order'], |
|
339 | - ); |
|
340 | - // if we have an id then let's get existing object first and then set the new values. |
|
341 | - // Otherwise we instantiate a new object for save. |
|
342 | - if (! empty($datetime_data['DTT_ID'])) { |
|
343 | - $datetime = EE_Registry::instance() |
|
344 | - ->load_model('Datetime', array($timezone)) |
|
345 | - ->get_one_by_ID($datetime_data['DTT_ID']); |
|
346 | - //set date and time format according to what is set in this class. |
|
347 | - $datetime->set_date_format($this->_date_format_strings['date']); |
|
348 | - $datetime->set_time_format($this->_date_format_strings['time']); |
|
349 | - foreach ($datetime_values as $field => $value) { |
|
350 | - $datetime->set($field, $value); |
|
351 | - } |
|
352 | - // make sure the $dtt_id here is saved just in case |
|
353 | - // after the add_relation_to() the autosave replaces it. |
|
354 | - // We need to do this so we dont' TRASH the parent DTT. |
|
355 | - // (save the ID for both key and value to avoid duplications) |
|
356 | - $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
357 | - } else { |
|
358 | - $datetime = EE_Registry::instance()->load_class( |
|
359 | - 'Datetime', |
|
360 | - array( |
|
361 | - $datetime_values, |
|
362 | - $timezone, |
|
363 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
364 | - ), |
|
365 | - false, |
|
366 | - false |
|
367 | - ); |
|
368 | - foreach ($datetime_values as $field => $value) { |
|
369 | - $datetime->set($field, $value); |
|
370 | - } |
|
371 | - } |
|
372 | - $datetime->save(); |
|
373 | - $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
374 | - // before going any further make sure our dates are setup correctly |
|
375 | - // so that the end date is always equal or greater than the start date. |
|
376 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
377 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
378 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
379 | - $datetime->save(); |
|
380 | - } |
|
381 | - // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
382 | - // because it is possible there was a new one created for the autosave. |
|
383 | - // (save the ID for both key and value to avoid duplications) |
|
384 | - $DTT_ID = $datetime->ID(); |
|
385 | - $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
386 | - $saved_dtt_objs[$row] = $datetime; |
|
387 | - //todo if ANY of these updates fail then we want the appropriate global error message. |
|
388 | - } |
|
389 | - $event->save(); |
|
390 | - // now we need to REMOVE any datetimes that got deleted. |
|
391 | - // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
392 | - // So its safe to permanently delete at this point. |
|
393 | - $old_datetimes = explode(',', $data['datetime_IDs']); |
|
394 | - $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
395 | - if (is_array($old_datetimes)) { |
|
396 | - $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
397 | - foreach ($datetimes_to_delete as $id) { |
|
398 | - $id = absint($id); |
|
399 | - if (empty($id)) { |
|
400 | - continue; |
|
401 | - } |
|
402 | - $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
403 | - //remove tkt relationships. |
|
404 | - $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
405 | - foreach ($related_tickets as $tkt) { |
|
406 | - $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
407 | - } |
|
408 | - $event->_remove_relation_to($id, 'Datetime'); |
|
409 | - $dtt_to_remove->refresh_cache_of_related_objects(); |
|
410 | - } |
|
411 | - } |
|
412 | - return $saved_dtt_objs; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * update tickets |
|
418 | - * |
|
419 | - * @param EE_Event $event Event object being updated |
|
420 | - * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
421 | - * @param array $data incoming request data |
|
422 | - * @return EE_Ticket[] |
|
423 | - * @throws InvalidArgumentException |
|
424 | - * @throws EE_Error |
|
425 | - */ |
|
426 | - protected function _update_tickets($event, $saved_datetimes, $data) |
|
427 | - { |
|
428 | - $new_tkt = null; |
|
429 | - $new_default = null; |
|
430 | - //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
431 | - $data = stripslashes_deep($data); |
|
432 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
433 | - $saved_tickets = $datetimes_on_existing = array(); |
|
434 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
435 | - if(empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])){ |
|
436 | - throw new InvalidArgumentException( |
|
437 | - esc_html__( |
|
438 | - 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
439 | - 'event_espresso' |
|
440 | - ) |
|
441 | - ); |
|
442 | - } |
|
443 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
444 | - $update_prices = $create_new_TKT = false; |
|
445 | - // figure out what datetimes were added to the ticket |
|
446 | - // and what datetimes were removed from the ticket in the session. |
|
447 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
448 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
449 | - $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
450 | - $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
451 | - // trim inputs to ensure any excess whitespace is removed. |
|
452 | - $tkt = array_map( |
|
453 | - function ($ticket_data) { |
|
454 | - return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
455 | - }, |
|
456 | - $tkt |
|
457 | - ); |
|
458 | - // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
459 | - // because we're doing calculations prior to using the models. |
|
460 | - // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
461 | - $ticket_price = isset($tkt['TKT_price']) |
|
462 | - ? round((float)$tkt['TKT_price'], 3) |
|
463 | - : 0; |
|
464 | - //note incoming base price needs converted from localized value. |
|
465 | - $base_price = isset($tkt['TKT_base_price']) |
|
466 | - ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
467 | - : 0; |
|
468 | - //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
469 | - $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
470 | - ? $base_price |
|
471 | - : $ticket_price; |
|
472 | - $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
473 | - ? $tkt['TKT_base_price_ID'] |
|
474 | - : 0; |
|
475 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
476 | - ? $data['edit_prices'][$row] |
|
477 | - : array(); |
|
478 | - $now = null; |
|
479 | - if (empty($tkt['TKT_start_date'])) { |
|
480 | - //lets' use now in the set timezone. |
|
481 | - $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
482 | - $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
483 | - } |
|
484 | - if (empty($tkt['TKT_end_date'])) { |
|
485 | - /** |
|
486 | - * set the TKT_end_date to the first datetime attached to the ticket. |
|
487 | - */ |
|
488 | - $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
489 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
490 | - } |
|
491 | - $TKT_values = array( |
|
492 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
493 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
494 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
495 | - 'TKT_description' => ! empty($tkt['TKT_description']) |
|
496 | - && $tkt['TKT_description'] !== esc_html__( |
|
497 | - 'You can modify this description', |
|
498 | - 'event_espresso' |
|
499 | - ) |
|
500 | - ? $tkt['TKT_description'] |
|
501 | - : '', |
|
502 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
503 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
504 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
505 | - ? EE_INF |
|
506 | - : $tkt['TKT_qty'], |
|
507 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
508 | - ? EE_INF |
|
509 | - : $tkt['TKT_uses'], |
|
510 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
511 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
512 | - 'TKT_row' => $row, |
|
513 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
514 | - 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
515 | - 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
516 | - 'TKT_price' => $ticket_price, |
|
517 | - ); |
|
518 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
519 | - // which means in turn that the prices will become new prices as well. |
|
520 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
521 | - $TKT_values['TKT_ID'] = 0; |
|
522 | - $TKT_values['TKT_is_default'] = 0; |
|
523 | - $update_prices = true; |
|
524 | - } |
|
525 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
526 | - // we actually do our saves ahead of doing any add_relations to |
|
527 | - // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
528 | - // but DID have it's items modified. |
|
529 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
530 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
531 | - if (absint($TKT_values['TKT_ID'])) { |
|
532 | - $ticket = EE_Registry::instance() |
|
533 | - ->load_model('Ticket', array($timezone)) |
|
534 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
535 | - if ($ticket instanceof EE_Ticket) { |
|
536 | - $ticket = $this->_update_ticket_datetimes( |
|
537 | - $ticket, |
|
538 | - $saved_datetimes, |
|
539 | - $datetimes_added, |
|
540 | - $datetimes_removed |
|
541 | - ); |
|
542 | - // are there any registrations using this ticket ? |
|
543 | - $tickets_sold = $ticket->count_related( |
|
544 | - 'Registration', |
|
545 | - array( |
|
546 | - array( |
|
547 | - 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
548 | - ), |
|
549 | - ) |
|
550 | - ); |
|
551 | - //set ticket formats |
|
552 | - $ticket->set_date_format($this->_date_format_strings['date']); |
|
553 | - $ticket->set_time_format($this->_date_format_strings['time']); |
|
554 | - // let's just check the total price for the existing ticket |
|
555 | - // and determine if it matches the new total price. |
|
556 | - // if they are different then we create a new ticket (if tickets sold) |
|
557 | - // if they aren't different then we go ahead and modify existing ticket. |
|
558 | - $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
559 | - //set new values |
|
560 | - foreach ($TKT_values as $field => $value) { |
|
561 | - if ($field === 'TKT_qty') { |
|
562 | - $ticket->set_qty($value); |
|
563 | - } else { |
|
564 | - $ticket->set($field, $value); |
|
565 | - } |
|
566 | - } |
|
567 | - // if $create_new_TKT is false then we can safely update the existing ticket. |
|
568 | - // Otherwise we have to create a new ticket. |
|
569 | - if ($create_new_TKT) { |
|
570 | - $new_tkt = $this->_duplicate_ticket($ticket, $price_rows, $ticket_price, $base_price, |
|
571 | - $base_price_id); |
|
572 | - } |
|
573 | - } |
|
574 | - } else { |
|
575 | - // no TKT_id so a new TKT |
|
576 | - $ticket = EE_Ticket::new_instance( |
|
577 | - $TKT_values, |
|
578 | - $timezone, |
|
579 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
580 | - ); |
|
581 | - if ($ticket instanceof EE_Ticket) { |
|
582 | - // make sure ticket has an ID of setting relations won't work |
|
583 | - $ticket->save(); |
|
584 | - $ticket = $this->_update_ticket_datetimes( |
|
585 | - $ticket, |
|
586 | - $saved_datetimes, |
|
587 | - $datetimes_added, |
|
588 | - $datetimes_removed |
|
589 | - ); |
|
590 | - $update_prices = true; |
|
591 | - } |
|
592 | - } |
|
593 | - //make sure any current values have been saved. |
|
594 | - //$ticket->save(); |
|
595 | - // before going any further make sure our dates are setup correctly |
|
596 | - // so that the end date is always equal or greater than the start date. |
|
597 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
598 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
599 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
600 | - } |
|
601 | - //let's make sure the base price is handled |
|
602 | - $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $ticket, $update_prices, $base_price, |
|
603 | - $base_price_id) : $ticket; |
|
604 | - //add/update price_modifiers |
|
605 | - $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) : $ticket; |
|
606 | - //need to make sue that the TKT_price is accurate after saving the prices. |
|
607 | - $ticket->ensure_TKT_Price_correct(); |
|
608 | - //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
609 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
610 | - $update_prices = true; |
|
611 | - $new_default = clone $ticket; |
|
612 | - $new_default->set('TKT_ID', 0); |
|
613 | - $new_default->set('TKT_is_default', 1); |
|
614 | - $new_default->set('TKT_row', 1); |
|
615 | - $new_default->set('TKT_price', $ticket_price); |
|
616 | - // remove any dtt relations cause we DON'T want dtt relations attached |
|
617 | - // (note this is just removing the cached relations in the object) |
|
618 | - $new_default->_remove_relations('Datetime'); |
|
619 | - //todo we need to add the current attached prices as new prices to the new default ticket. |
|
620 | - $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
621 | - //don't forget the base price! |
|
622 | - $new_default = $this->_add_prices_to_ticket( |
|
623 | - array(), |
|
624 | - $new_default, |
|
625 | - $update_prices, |
|
626 | - $base_price, |
|
627 | - $base_price_id |
|
628 | - ); |
|
629 | - $new_default->save(); |
|
630 | - do_action( |
|
631 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
632 | - $new_default, |
|
633 | - $row, |
|
634 | - $ticket, |
|
635 | - $data |
|
636 | - ); |
|
637 | - } |
|
638 | - // DO ALL dtt relationships for both current tickets and any archived tickets |
|
639 | - // for the given dtt that are related to the current ticket. |
|
640 | - // TODO... not sure exactly how we're going to do this considering we don't know |
|
641 | - // what current ticket the archived tickets are related to |
|
642 | - // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
643 | - //let's assign any tickets that have been setup to the saved_tickets tracker |
|
644 | - //save existing TKT |
|
645 | - $ticket->save(); |
|
646 | - if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
647 | - //save new TKT |
|
648 | - $new_tkt->save(); |
|
649 | - //add new ticket to array |
|
650 | - $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
651 | - do_action( |
|
652 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
653 | - $new_tkt, |
|
654 | - $row, |
|
655 | - $tkt, |
|
656 | - $data |
|
657 | - ); |
|
658 | - } else { |
|
659 | - //add tkt to saved tkts |
|
660 | - $saved_tickets[$ticket->ID()] = $ticket; |
|
661 | - do_action( |
|
662 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
663 | - $ticket, |
|
664 | - $row, |
|
665 | - $tkt, |
|
666 | - $data |
|
667 | - ); |
|
668 | - } |
|
669 | - } |
|
670 | - // now we need to handle tickets actually "deleted permanently". |
|
671 | - // There are cases where we'd want this to happen |
|
672 | - // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
673 | - // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
674 | - // No sense in keeping all the related data in the db! |
|
675 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
676 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
677 | - foreach ($tickets_removed as $id) { |
|
678 | - $id = absint($id); |
|
679 | - //get the ticket for this id |
|
680 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
681 | - //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
682 | - if ($tkt_to_remove->get('TKT_is_default')) { |
|
683 | - continue; |
|
684 | - } |
|
685 | - // if this tkt has any registrations attached so then we just ARCHIVE |
|
686 | - // because we don't actually permanently delete these tickets. |
|
687 | - if ($tkt_to_remove->count_related('Registration') > 0) { |
|
688 | - $tkt_to_remove->delete(); |
|
689 | - continue; |
|
690 | - } |
|
691 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
692 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
693 | - $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
694 | - foreach ($datetimes as $datetime) { |
|
695 | - $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
696 | - } |
|
697 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
698 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
699 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
700 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
701 | - // finally let's delete this ticket |
|
702 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
703 | - $tkt_to_remove->delete_permanently(); |
|
704 | - } |
|
705 | - return $saved_tickets; |
|
706 | - } |
|
707 | - |
|
708 | - |
|
709 | - |
|
710 | - /** |
|
711 | - * @access protected |
|
712 | - * @param \EE_Ticket $ticket |
|
713 | - * @param \EE_Datetime[] $saved_datetimes |
|
714 | - * @param \EE_Datetime[] $added_datetimes |
|
715 | - * @param \EE_Datetime[] $removed_datetimes |
|
716 | - * @return \EE_Ticket |
|
717 | - * @throws \EE_Error |
|
718 | - */ |
|
719 | - protected function _update_ticket_datetimes( |
|
720 | - EE_Ticket $ticket, |
|
721 | - $saved_datetimes = array(), |
|
722 | - $added_datetimes = array(), |
|
723 | - $removed_datetimes = array() |
|
724 | - ) { |
|
725 | - // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
726 | - // and removing the ticket from datetimes it got removed from. |
|
727 | - // first let's add datetimes |
|
728 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
729 | - foreach ($added_datetimes as $row_id) { |
|
730 | - $row_id = (int)$row_id; |
|
731 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
732 | - $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
733 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
734 | - // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
735 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
736 | - $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
737 | - $saved_datetimes[$row_id]->save(); |
|
738 | - } |
|
739 | - } |
|
740 | - } |
|
741 | - } |
|
742 | - // then remove datetimes |
|
743 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
744 | - foreach ($removed_datetimes as $row_id) { |
|
745 | - $row_id = (int)$row_id; |
|
746 | - // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
747 | - // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
748 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
749 | - $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
750 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
751 | - // If so, then we need to remove it's sold from the DTT_sold. |
|
752 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
753 | - $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
754 | - $saved_datetimes[$row_id]->save(); |
|
755 | - } |
|
756 | - } |
|
757 | - } |
|
758 | - } |
|
759 | - // cap ticket qty by datetime reg limits |
|
760 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
761 | - return $ticket; |
|
762 | - } |
|
763 | - |
|
764 | - |
|
765 | - |
|
766 | - /** |
|
767 | - * @access protected |
|
768 | - * @param \EE_Ticket $ticket |
|
769 | - * @param array $price_rows |
|
770 | - * @param int $ticket_price |
|
771 | - * @param int $base_price |
|
772 | - * @param int $base_price_id |
|
773 | - * @return \EE_Ticket |
|
774 | - * @throws \EE_Error |
|
775 | - */ |
|
776 | - protected function _duplicate_ticket( |
|
777 | - EE_Ticket $ticket, |
|
778 | - $price_rows = array(), |
|
779 | - $ticket_price = 0, |
|
780 | - $base_price = 0, |
|
781 | - $base_price_id = 0 |
|
782 | - ) { |
|
783 | - // create new ticket that's a copy of the existing |
|
784 | - // except a new id of course (and not archived) |
|
785 | - // AND has the new TKT_price associated with it. |
|
786 | - $new_ticket = clone $ticket; |
|
787 | - $new_ticket->set('TKT_ID', 0); |
|
788 | - $new_ticket->set('TKT_deleted', 0); |
|
789 | - $new_ticket->set('TKT_price', $ticket_price); |
|
790 | - $new_ticket->set('TKT_sold', 0); |
|
791 | - // let's get a new ID for this ticket |
|
792 | - $new_ticket->save(); |
|
793 | - // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
794 | - $datetimes_on_existing = $ticket->get_many_related('Datetime'); |
|
795 | - $new_ticket = $this->_update_ticket_datetimes( |
|
796 | - $new_ticket, |
|
797 | - $datetimes_on_existing, |
|
798 | - array_keys($datetimes_on_existing) |
|
799 | - ); |
|
800 | - // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
801 | - // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
802 | - // available. |
|
803 | - if ($ticket->sold() > 0) { |
|
804 | - $new_qty = $ticket->qty() - $ticket->sold(); |
|
805 | - $new_ticket->set_qty($new_qty); |
|
806 | - } |
|
807 | - //now we update the prices just for this ticket |
|
808 | - $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
809 | - //and we update the base price |
|
810 | - $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
811 | - return $new_ticket; |
|
812 | - } |
|
813 | - |
|
814 | - |
|
815 | - |
|
816 | - /** |
|
817 | - * This attaches a list of given prices to a ticket. |
|
818 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
819 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
820 | - * price info and prices are automatically "archived" via the ticket. |
|
821 | - * |
|
822 | - * @access private |
|
823 | - * @param array $prices Array of prices from the form. |
|
824 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
825 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
826 | - * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
827 | - * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
828 | - * @return EE_Ticket |
|
829 | - * @throws EE_Error |
|
830 | - */ |
|
831 | - protected function _add_prices_to_ticket( |
|
832 | - $prices = array(), |
|
833 | - EE_Ticket $ticket, |
|
834 | - $new_prices = false, |
|
835 | - $base_price = false, |
|
836 | - $base_price_id = false |
|
837 | - ) { |
|
838 | - // let's just get any current prices that may exist on the given ticket |
|
839 | - // so we can remove any prices that got trashed in this session. |
|
840 | - $current_prices_on_ticket = $base_price !== false |
|
841 | - ? $ticket->base_price(true) |
|
842 | - : $ticket->price_modifiers(); |
|
843 | - $updated_prices = array(); |
|
844 | - // if $base_price ! FALSE then updating a base price. |
|
845 | - if ($base_price !== false) { |
|
846 | - $prices[1] = array( |
|
847 | - 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
848 | - 'PRT_ID' => 1, |
|
849 | - 'PRC_amount' => $base_price, |
|
850 | - 'PRC_name' => $ticket->get('TKT_name'), |
|
851 | - 'PRC_desc' => $ticket->get('TKT_description'), |
|
852 | - ); |
|
853 | - } |
|
854 | - //possibly need to save tkt |
|
855 | - if (! $ticket->ID()) { |
|
856 | - $ticket->save(); |
|
857 | - } |
|
858 | - foreach ($prices as $row => $prc) { |
|
859 | - $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
860 | - if (empty($prt_id)) { |
|
861 | - continue; |
|
862 | - } //prices MUST have a price type id. |
|
863 | - $PRC_values = array( |
|
864 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
865 | - 'PRT_ID' => $prt_id, |
|
866 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
867 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
868 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
869 | - 'PRC_is_default' => false, |
|
870 | - //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
871 | - 'PRC_order' => $row, |
|
872 | - ); |
|
873 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
874 | - $PRC_values['PRC_ID'] = 0; |
|
875 | - $price = EE_Registry::instance()->load_class( |
|
876 | - 'Price', |
|
877 | - array($PRC_values), |
|
878 | - false, |
|
879 | - false |
|
880 | - ); |
|
881 | - } else { |
|
882 | - $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
883 | - //update this price with new values |
|
884 | - foreach ($PRC_values as $field => $value) { |
|
885 | - $price->set($field, $value); |
|
886 | - } |
|
887 | - } |
|
888 | - $price->save(); |
|
889 | - $updated_prices[$price->ID()] = $price; |
|
890 | - $ticket->_add_relation_to($price, 'Price'); |
|
891 | - } |
|
892 | - //now let's remove any prices that got removed from the ticket |
|
893 | - if (! empty ($current_prices_on_ticket)) { |
|
894 | - $current = array_keys($current_prices_on_ticket); |
|
895 | - $updated = array_keys($updated_prices); |
|
896 | - $prices_to_remove = array_diff($current, $updated); |
|
897 | - if (! empty($prices_to_remove)) { |
|
898 | - foreach ($prices_to_remove as $prc_id) { |
|
899 | - $p = $current_prices_on_ticket[$prc_id]; |
|
900 | - $ticket->_remove_relation_to($p, 'Price'); |
|
901 | - //delete permanently the price |
|
902 | - $p->delete_permanently(); |
|
903 | - } |
|
904 | - } |
|
905 | - } |
|
906 | - return $ticket; |
|
907 | - } |
|
908 | - |
|
909 | - |
|
910 | - |
|
911 | - /** |
|
912 | - * @param Events_Admin_Page $event_admin_obj |
|
913 | - * @return Events_Admin_Page |
|
914 | - */ |
|
915 | - public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
916 | - { |
|
917 | - return $event_admin_obj; |
|
918 | - //doing nothing for the moment. |
|
919 | - // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
920 | - // (use the set_template_args() method) |
|
921 | - /** |
|
922 | - * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
923 | - * 1. TKT_is_default_selector (visible) |
|
924 | - * 2. TKT_is_default (hidden) |
|
925 | - * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
926 | - * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
927 | - * this ticket to be saved as a default. |
|
928 | - * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
929 | - * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
930 | - * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
931 | - * the TKT HAS been saved as a default.. |
|
932 | - * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
933 | - * On Autosave: |
|
934 | - * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
935 | - * then set the TKT_is_default to false. |
|
936 | - * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
937 | - * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
938 | - * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
939 | - */ |
|
940 | - } |
|
941 | - |
|
942 | - |
|
943 | - |
|
944 | - /** |
|
945 | - * @throws DomainException |
|
946 | - * @throws EE_Error |
|
947 | - */ |
|
948 | - public function pricing_metabox() |
|
949 | - { |
|
950 | - $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
951 | - $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
952 | - //set is_creating_event property. |
|
953 | - $EVT_ID = $event->ID(); |
|
954 | - $this->_is_creating_event = absint($EVT_ID) === 0; |
|
955 | - //default main template args |
|
956 | - $main_template_args = array( |
|
957 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
958 | - 'event_editor_event_datetimes_help_tab', |
|
959 | - $this->_adminpage_obj->page_slug, |
|
960 | - $this->_adminpage_obj->get_req_action(), |
|
961 | - false, |
|
962 | - false |
|
963 | - ), |
|
964 | - // todo need to add a filter to the template for the help text |
|
965 | - // in the Events_Admin_Page core file so we can add further help |
|
966 | - 'existing_datetime_ids' => '', |
|
967 | - 'total_dtt_rows' => 1, |
|
968 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
969 | - 'add_new_dtt_info', |
|
970 | - $this->_adminpage_obj->page_slug, |
|
971 | - $this->_adminpage_obj->get_req_action(), |
|
972 | - false, |
|
973 | - false |
|
974 | - ), |
|
975 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
976 | - 'datetime_rows' => '', |
|
977 | - 'show_tickets_container' => '', |
|
978 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
979 | - 'ticket_rows' => '', |
|
980 | - 'existing_ticket_ids' => '', |
|
981 | - 'total_ticket_rows' => 1, |
|
982 | - 'ticket_js_structure' => '', |
|
983 | - 'ee_collapsible_status' => ' ee-collapsible-open' |
|
984 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
985 | - ); |
|
986 | - $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
987 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
988 | - /** |
|
989 | - * 1. Start with retrieving Datetimes |
|
990 | - * 2. For each datetime get related tickets |
|
991 | - * 3. For each ticket get related prices |
|
992 | - */ |
|
993 | - /** @var EEM_Datetime $datetime_model */ |
|
994 | - $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
995 | - $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
996 | - $main_template_args['total_dtt_rows'] = count($datetimes); |
|
997 | - /** |
|
998 | - * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
999 | - * for why we are counting $datetime_row and then setting that on the Datetime object |
|
1000 | - */ |
|
1001 | - $datetime_row = 1; |
|
1002 | - foreach ($datetimes as $datetime) { |
|
1003 | - $DTT_ID = $datetime->get('DTT_ID'); |
|
1004 | - $datetime->set('DTT_order', $datetime_row); |
|
1005 | - $existing_datetime_ids[] = $DTT_ID; |
|
1006 | - //tickets attached |
|
1007 | - $related_tickets = $datetime->ID() > 0 |
|
1008 | - ? $datetime->get_many_related( |
|
1009 | - 'Ticket', |
|
1010 | - array( |
|
1011 | - array( |
|
1012 | - 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
1013 | - ), |
|
1014 | - 'default_where_conditions' => 'none', |
|
1015 | - 'order_by' => array('TKT_order' => 'ASC'), |
|
1016 | - ) |
|
1017 | - ) |
|
1018 | - : array(); |
|
1019 | - //if there are no related tickets this is likely a new event OR autodraft |
|
1020 | - // event so we need to generate the default tickets because datetimes |
|
1021 | - // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1022 | - // datetime on the event. |
|
1023 | - if (empty ($related_tickets) && count($datetimes) < 2) { |
|
1024 | - /** @var EEM_Ticket $ticket_model */ |
|
1025 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1026 | - $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1027 | - // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1028 | - // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1029 | - $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1030 | - $main_default_ticket = reset($related_tickets); |
|
1031 | - if ($main_default_ticket instanceof EE_Ticket) { |
|
1032 | - foreach ($default_prices as $default_price) { |
|
1033 | - if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1034 | - continue; |
|
1035 | - } |
|
1036 | - $main_default_ticket->cache('Price', $default_price); |
|
1037 | - } |
|
1038 | - } |
|
1039 | - } |
|
1040 | - // we can't actually setup rows in this loop yet cause we don't know all |
|
1041 | - // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1042 | - // So we're going to temporarily cache some of that information. |
|
1043 | - //loop through and setup the ticket rows and make sure the order is set. |
|
1044 | - foreach ($related_tickets as $ticket) { |
|
1045 | - $TKT_ID = $ticket->get('TKT_ID'); |
|
1046 | - $ticket_row = $ticket->get('TKT_row'); |
|
1047 | - //we only want unique tickets in our final display!! |
|
1048 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1049 | - $existing_ticket_ids[] = $TKT_ID; |
|
1050 | - $all_tickets[] = $ticket; |
|
1051 | - } |
|
1052 | - //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1053 | - $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
1054 | - //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1055 | - if ( |
|
1056 | - ! isset($ticket_datetimes[$TKT_ID]) |
|
1057 | - || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
1058 | - ) { |
|
1059 | - $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
1060 | - } |
|
1061 | - } |
|
1062 | - $datetime_row++; |
|
1063 | - } |
|
1064 | - $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1065 | - $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1066 | - $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1067 | - //sort $all_tickets by order |
|
1068 | - usort( |
|
1069 | - $all_tickets, |
|
1070 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
1071 | - $a_order = (int)$a->get('TKT_order'); |
|
1072 | - $b_order = (int)$b->get('TKT_order'); |
|
1073 | - if ($a_order === $b_order) { |
|
1074 | - return 0; |
|
1075 | - } |
|
1076 | - return ($a_order < $b_order) ? -1 : 1; |
|
1077 | - } |
|
1078 | - ); |
|
1079 | - // k NOW we have all the data we need for setting up the dtt rows |
|
1080 | - // and ticket rows so we start our dtt loop again. |
|
1081 | - $datetime_row = 1; |
|
1082 | - foreach ($datetimes as $datetime) { |
|
1083 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1084 | - $datetime_row, |
|
1085 | - $datetime, |
|
1086 | - $datetime_tickets, |
|
1087 | - $all_tickets, |
|
1088 | - false, |
|
1089 | - $datetimes |
|
1090 | - ); |
|
1091 | - $datetime_row++; |
|
1092 | - } |
|
1093 | - //then loop through all tickets for the ticket rows. |
|
1094 | - $ticket_row = 1; |
|
1095 | - foreach ($all_tickets as $ticket) { |
|
1096 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1097 | - $ticket_row, |
|
1098 | - $ticket, |
|
1099 | - $ticket_datetimes, |
|
1100 | - $datetimes, |
|
1101 | - false, |
|
1102 | - $all_tickets |
|
1103 | - ); |
|
1104 | - $ticket_row++; |
|
1105 | - } |
|
1106 | - $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1107 | - EEH_Template::display_template( |
|
1108 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1109 | - $main_template_args |
|
1110 | - ); |
|
1111 | - } |
|
1112 | - |
|
1113 | - |
|
1114 | - |
|
1115 | - /** |
|
1116 | - * @param int $datetime_row |
|
1117 | - * @param EE_Datetime $datetime |
|
1118 | - * @param array $datetime_tickets |
|
1119 | - * @param array $all_tickets |
|
1120 | - * @param bool $default |
|
1121 | - * @param array $all_datetimes |
|
1122 | - * @return mixed |
|
1123 | - * @throws DomainException |
|
1124 | - * @throws EE_Error |
|
1125 | - */ |
|
1126 | - protected function _get_datetime_row( |
|
1127 | - $datetime_row, |
|
1128 | - EE_Datetime $datetime, |
|
1129 | - $datetime_tickets = array(), |
|
1130 | - $all_tickets = array(), |
|
1131 | - $default = false, |
|
1132 | - $all_datetimes = array() |
|
1133 | - ) { |
|
1134 | - $dtt_display_template_args = array( |
|
1135 | - 'dtt_edit_row' => $this->_get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes), |
|
1136 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1137 | - $datetime_row, |
|
1138 | - $datetime, |
|
1139 | - $datetime_tickets, |
|
1140 | - $all_tickets, |
|
1141 | - $default |
|
1142 | - ), |
|
1143 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1144 | - ); |
|
1145 | - return EEH_Template::display_template( |
|
1146 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1147 | - $dtt_display_template_args, |
|
1148 | - true |
|
1149 | - ); |
|
1150 | - } |
|
1151 | - |
|
1152 | - |
|
1153 | - |
|
1154 | - /** |
|
1155 | - * This method is used to generate a dtt fields edit row. |
|
1156 | - * The same row is used to generate a row with valid DTT objects |
|
1157 | - * and the default row that is used as the skeleton by the js. |
|
1158 | - * |
|
1159 | - * @param int $datetime_row The row number for the row being generated. |
|
1160 | - * @param EE_Datetime $datetime |
|
1161 | - * @param bool $default Whether a default row is being generated or not. |
|
1162 | - * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1163 | - * @return string |
|
1164 | - * @throws DomainException |
|
1165 | - * @throws EE_Error |
|
1166 | - */ |
|
1167 | - protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1168 | - { |
|
1169 | - // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1170 | - $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1171 | - $template_args = array( |
|
1172 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1173 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1174 | - 'edit_dtt_expanded' => '', |
|
1175 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1176 | - 'DTT_name' => $default ? '' : $datetime->name(), |
|
1177 | - 'DTT_description' => $default ? '' : $datetime->description(), |
|
1178 | - 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1179 | - 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1180 | - 'DTT_reg_limit' => $default |
|
1181 | - ? '' |
|
1182 | - : $datetime->get_pretty( |
|
1183 | - 'DTT_reg_limit', |
|
1184 | - 'input' |
|
1185 | - ), |
|
1186 | - 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1187 | - 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1188 | - 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1189 | - 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1190 | - ? '' |
|
1191 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1192 | - 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1193 | - ? 'ee-lock-icon' |
|
1194 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1195 | - 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1196 | - ? '' |
|
1197 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
1198 | - array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
1199 | - REG_ADMIN_URL |
|
1200 | - ), |
|
1201 | - ); |
|
1202 | - $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1203 | - ? ' style="display:none"' |
|
1204 | - : ''; |
|
1205 | - //allow filtering of template args at this point. |
|
1206 | - $template_args = apply_filters( |
|
1207 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1208 | - $template_args, |
|
1209 | - $datetime_row, |
|
1210 | - $datetime, |
|
1211 | - $default, |
|
1212 | - $all_datetimes, |
|
1213 | - $this->_is_creating_event |
|
1214 | - ); |
|
1215 | - return EEH_Template::display_template( |
|
1216 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1217 | - $template_args, |
|
1218 | - true |
|
1219 | - ); |
|
1220 | - } |
|
1221 | - |
|
1222 | - |
|
1223 | - |
|
1224 | - /** |
|
1225 | - * @param int $datetime_row |
|
1226 | - * @param EE_Datetime $datetime |
|
1227 | - * @param array $datetime_tickets |
|
1228 | - * @param array $all_tickets |
|
1229 | - * @param bool $default |
|
1230 | - * @return mixed |
|
1231 | - * @throws DomainException |
|
1232 | - * @throws EE_Error |
|
1233 | - */ |
|
1234 | - protected function _get_dtt_attached_tickets_row( |
|
1235 | - $datetime_row, |
|
1236 | - $datetime, |
|
1237 | - $datetime_tickets = array(), |
|
1238 | - $all_tickets = array(), |
|
1239 | - $default |
|
1240 | - ) { |
|
1241 | - $template_args = array( |
|
1242 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1243 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1244 | - 'DTT_description' => $default ? '' : $datetime->description(), |
|
1245 | - 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1246 | - 'show_tickets_row' => ' style="display:none;"', |
|
1247 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1248 | - 'add_new_ticket_via_datetime', |
|
1249 | - $this->_adminpage_obj->page_slug, |
|
1250 | - $this->_adminpage_obj->get_req_action(), |
|
1251 | - false, |
|
1252 | - false |
|
1253 | - ), |
|
1254 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1255 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1256 | - ); |
|
1257 | - //need to setup the list items (but only if this isn't a default skeleton setup) |
|
1258 | - if (! $default) { |
|
1259 | - $ticket_row = 1; |
|
1260 | - foreach ($all_tickets as $ticket) { |
|
1261 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1262 | - $datetime_row, |
|
1263 | - $ticket_row, |
|
1264 | - $datetime, |
|
1265 | - $ticket, |
|
1266 | - $datetime_tickets, |
|
1267 | - $default |
|
1268 | - ); |
|
1269 | - $ticket_row++; |
|
1270 | - } |
|
1271 | - } |
|
1272 | - //filter template args at this point |
|
1273 | - $template_args = apply_filters( |
|
1274 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1275 | - $template_args, |
|
1276 | - $datetime_row, |
|
1277 | - $datetime, |
|
1278 | - $datetime_tickets, |
|
1279 | - $all_tickets, |
|
1280 | - $default, |
|
1281 | - $this->_is_creating_event |
|
1282 | - ); |
|
1283 | - return EEH_Template::display_template( |
|
1284 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1285 | - $template_args, |
|
1286 | - true |
|
1287 | - ); |
|
1288 | - } |
|
1289 | - |
|
1290 | - |
|
1291 | - |
|
1292 | - /** |
|
1293 | - * @param int $datetime_row |
|
1294 | - * @param int $ticket_row |
|
1295 | - * @param EE_Datetime $datetime |
|
1296 | - * @param EE_Ticket $ticket |
|
1297 | - * @param array $datetime_tickets |
|
1298 | - * @param bool $default |
|
1299 | - * @return mixed |
|
1300 | - * @throws DomainException |
|
1301 | - * @throws EE_Error |
|
1302 | - */ |
|
1303 | - protected function _get_datetime_tickets_list_item( |
|
1304 | - $datetime_row, |
|
1305 | - $ticket_row, |
|
1306 | - $datetime, |
|
1307 | - $ticket, |
|
1308 | - $datetime_tickets = array(), |
|
1309 | - $default |
|
1310 | - ) { |
|
1311 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
1312 | - ? $datetime_tickets[$datetime->ID()] |
|
1313 | - : array(); |
|
1314 | - $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1315 | - $no_ticket = $default && empty($ticket); |
|
1316 | - $template_args = array( |
|
1317 | - 'dtt_row' => $default |
|
1318 | - ? 'DTTNUM' |
|
1319 | - : $datetime_row, |
|
1320 | - 'tkt_row' => $no_ticket |
|
1321 | - ? 'TICKETNUM' |
|
1322 | - : $ticket_row, |
|
1323 | - 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1324 | - ? ' checked="checked"' |
|
1325 | - : '', |
|
1326 | - 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1327 | - ? ' ticket-selected' |
|
1328 | - : '', |
|
1329 | - 'TKT_name' => $no_ticket |
|
1330 | - ? 'TKTNAME' |
|
1331 | - : $ticket->get('TKT_name'), |
|
1332 | - 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1333 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1334 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
1335 | - ); |
|
1336 | - //filter template args |
|
1337 | - $template_args = apply_filters( |
|
1338 | - 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1339 | - $template_args, |
|
1340 | - $datetime_row, |
|
1341 | - $ticket_row, |
|
1342 | - $datetime, |
|
1343 | - $ticket, |
|
1344 | - $datetime_tickets, |
|
1345 | - $default, |
|
1346 | - $this->_is_creating_event |
|
1347 | - ); |
|
1348 | - return EEH_Template::display_template( |
|
1349 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1350 | - $template_args, |
|
1351 | - true |
|
1352 | - ); |
|
1353 | - } |
|
1354 | - |
|
1355 | - |
|
1356 | - |
|
1357 | - /** |
|
1358 | - * This generates the ticket row for tickets. |
|
1359 | - * This same method is used to generate both the actual rows and the js skeleton row |
|
1360 | - * (when default === true) |
|
1361 | - * |
|
1362 | - * @param int $ticket_row Represents the row number being generated. |
|
1363 | - * @param $ticket |
|
1364 | - * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1365 | - * or empty for default |
|
1366 | - * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1367 | - * @param bool $default Whether default row being generated or not. |
|
1368 | - * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1369 | - * (or empty in the case of defaults) |
|
1370 | - * @return mixed |
|
1371 | - * @throws DomainException |
|
1372 | - * @throws EE_Error |
|
1373 | - */ |
|
1374 | - protected function _get_ticket_row( |
|
1375 | - $ticket_row, |
|
1376 | - $ticket, |
|
1377 | - $ticket_datetimes, |
|
1378 | - $all_datetimes, |
|
1379 | - $default = false, |
|
1380 | - $all_tickets = array() |
|
1381 | - ) { |
|
1382 | - // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1383 | - $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1384 | - $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
1385 | - array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
1386 | - // if there is only one price (which would be the base price) |
|
1387 | - // or NO prices and this ticket is a default ticket, |
|
1388 | - // let's just make sure there are no cached default prices on the object. |
|
1389 | - // This is done by not including any query_params. |
|
1390 | - if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1391 | - $prices = $ticket->get_many_related('Price'); |
|
1392 | - } |
|
1393 | - // check if we're dealing with a default ticket in which case |
|
1394 | - // we don't want any starting_ticket_datetime_row values set |
|
1395 | - // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1396 | - // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1397 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')); |
|
1398 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1399 | - ? $ticket_datetimes[$ticket->ID()] |
|
1400 | - : array(); |
|
1401 | - $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1402 | - $base_price = $default ? null : $ticket->base_price(); |
|
1403 | - $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1404 | - //breaking out complicated condition for ticket_status |
|
1405 | - if ($default) { |
|
1406 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1407 | - } else { |
|
1408 | - $ticket_status_class = $ticket->is_default() |
|
1409 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1410 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
1411 | - } |
|
1412 | - //breaking out complicated condition for TKT_taxable |
|
1413 | - if ($default) { |
|
1414 | - $TKT_taxable = ''; |
|
1415 | - } else { |
|
1416 | - $TKT_taxable = $ticket->get('TKT_taxable') |
|
1417 | - ? ' checked="checked"' |
|
1418 | - : ''; |
|
1419 | - } |
|
1420 | - if ($default) { |
|
1421 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1422 | - } else if ($ticket->is_default()) { |
|
1423 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1424 | - } else { |
|
1425 | - $TKT_status = $ticket->ticket_status(true); |
|
1426 | - } |
|
1427 | - if ($default) { |
|
1428 | - $TKT_min = ''; |
|
1429 | - } else { |
|
1430 | - $TKT_min = $ticket->get('TKT_min'); |
|
1431 | - if ($TKT_min === -1 || $TKT_min === 0) { |
|
1432 | - $TKT_min = ''; |
|
1433 | - } |
|
1434 | - } |
|
1435 | - $template_args = array( |
|
1436 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1437 | - 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1438 | - //on initial page load this will always be the correct order. |
|
1439 | - 'tkt_status_class' => $ticket_status_class, |
|
1440 | - 'display_edit_tkt_row' => ' style="display:none;"', |
|
1441 | - 'edit_tkt_expanded' => '', |
|
1442 | - 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1443 | - 'TKT_name' => $default ? '' : $ticket->get('TKT_name'), |
|
1444 | - 'TKT_start_date' => $default |
|
1445 | - ? '' |
|
1446 | - : $ticket->get_date('TKT_start_date', |
|
1447 | - $this->_date_time_format), |
|
1448 | - 'TKT_end_date' => $default |
|
1449 | - ? '' |
|
1450 | - : $ticket->get_date('TKT_end_date', |
|
1451 | - $this->_date_time_format), |
|
1452 | - 'TKT_status' => $TKT_status, |
|
1453 | - 'TKT_price' => $default |
|
1454 | - ? '' |
|
1455 | - : EEH_Template::format_currency( |
|
1456 | - $ticket->get_ticket_total_with_taxes(), |
|
1457 | - false, |
|
1458 | - false |
|
1459 | - ), |
|
1460 | - 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1461 | - 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1462 | - 'TKT_qty' => $default |
|
1463 | - ? '' |
|
1464 | - : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1465 | - 'TKT_qty_for_input' => $default |
|
1466 | - ? '' |
|
1467 | - : $ticket->get_pretty('TKT_qty', 'input'), |
|
1468 | - 'TKT_uses' => $default |
|
1469 | - ? '' |
|
1470 | - : $ticket->get_pretty('TKT_uses', 'input'), |
|
1471 | - 'TKT_min' => $TKT_min, |
|
1472 | - 'TKT_max' => $default |
|
1473 | - ? '' |
|
1474 | - : $ticket->get_pretty('TKT_max', 'input'), |
|
1475 | - 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1476 | - 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1477 | - 'TKT_registrations' => $default |
|
1478 | - ? 0 |
|
1479 | - : $ticket->count_registrations( |
|
1480 | - array( |
|
1481 | - array( |
|
1482 | - 'STS_ID' => array( |
|
1483 | - '!=', |
|
1484 | - EEM_Registration::status_id_incomplete, |
|
1485 | - ), |
|
1486 | - ), |
|
1487 | - ) |
|
1488 | - ), |
|
1489 | - 'TKT_ID' => $default ? 0 : $ticket->get('TKT_ID'), |
|
1490 | - 'TKT_description' => $default ? '' : $ticket->get('TKT_description'), |
|
1491 | - 'TKT_is_default' => $default ? 0 : $ticket->get('TKT_is_default'), |
|
1492 | - 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1493 | - 'TKT_is_default_selector' => '', |
|
1494 | - 'ticket_price_rows' => '', |
|
1495 | - 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1496 | - ? '' |
|
1497 | - : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1498 | - 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1499 | - 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1500 | - ? '' |
|
1501 | - : ' style="display:none;"', |
|
1502 | - 'show_price_mod_button' => count($prices) > 1 |
|
1503 | - || ($default && $count_price_mods > 0) |
|
1504 | - || (! $default && $ticket->get('TKT_deleted')) |
|
1505 | - ? ' style="display:none;"' |
|
1506 | - : '', |
|
1507 | - 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1508 | - 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1509 | - 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1510 | - 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1511 | - 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1512 | - 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1513 | - 'TKT_taxable' => $TKT_taxable, |
|
1514 | - 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') |
|
1515 | - ? '' |
|
1516 | - : ' style="display:none"', |
|
1517 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1518 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1519 | - $ticket_subtotal, |
|
1520 | - false, |
|
1521 | - false |
|
1522 | - ), |
|
1523 | - 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1524 | - 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1525 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted'), |
|
1526 | - 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1527 | - ? ' ticket-archived' |
|
1528 | - : '', |
|
1529 | - 'trash_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1530 | - ? 'ee-lock-icon ' |
|
1531 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1532 | - 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1533 | - ? '' |
|
1534 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1535 | - ); |
|
1536 | - $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1537 | - ? ' style="display:none"' |
|
1538 | - : ''; |
|
1539 | - //handle rows that should NOT be empty |
|
1540 | - if (empty($template_args['TKT_start_date'])) { |
|
1541 | - //if empty then the start date will be now. |
|
1542 | - $template_args['TKT_start_date'] = date($this->_date_time_format, |
|
1543 | - current_time('timestamp')); |
|
1544 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1545 | - } |
|
1546 | - if (empty($template_args['TKT_end_date'])) { |
|
1547 | - //get the earliest datetime (if present); |
|
1548 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1549 | - ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1550 | - 'Datetime', |
|
1551 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1552 | - ) |
|
1553 | - : null; |
|
1554 | - if (! empty($earliest_dtt)) { |
|
1555 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1556 | - 'DTT_EVT_start', |
|
1557 | - $this->_date_time_format |
|
1558 | - ); |
|
1559 | - } else { |
|
1560 | - //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1561 | - $template_args['TKT_end_date'] = date( |
|
1562 | - $this->_date_time_format, |
|
1563 | - mktime(24, 0, 0, date('m'), date('d') + 29, date('Y') |
|
1564 | - ) |
|
1565 | - ); |
|
1566 | - } |
|
1567 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1568 | - } |
|
1569 | - //generate ticket_datetime items |
|
1570 | - if (! $default) { |
|
1571 | - $datetime_row = 1; |
|
1572 | - foreach ($all_datetimes as $datetime) { |
|
1573 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1574 | - $datetime_row, |
|
1575 | - $ticket_row, |
|
1576 | - $datetime, |
|
1577 | - $ticket, |
|
1578 | - $ticket_datetimes, |
|
1579 | - $default |
|
1580 | - ); |
|
1581 | - $datetime_row++; |
|
1582 | - } |
|
1583 | - } |
|
1584 | - $price_row = 1; |
|
1585 | - foreach ($prices as $price) { |
|
1586 | - if (! $price instanceof EE_Price) { |
|
1587 | - continue; |
|
1588 | - } |
|
1589 | - if ($price->is_base_price()) { |
|
1590 | - $price_row++; |
|
1591 | - continue; |
|
1592 | - } |
|
1593 | - $show_trash = !((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1594 | - $show_create = !(count($prices) > 1 && count($prices) !== $price_row); |
|
1595 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1596 | - $ticket_row, |
|
1597 | - $price_row, |
|
1598 | - $price, |
|
1599 | - $default, |
|
1600 | - $ticket, |
|
1601 | - $show_trash, |
|
1602 | - $show_create |
|
1603 | - ); |
|
1604 | - $price_row++; |
|
1605 | - } |
|
1606 | - //filter $template_args |
|
1607 | - $template_args = apply_filters( |
|
1608 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1609 | - $template_args, |
|
1610 | - $ticket_row, |
|
1611 | - $ticket, |
|
1612 | - $ticket_datetimes, |
|
1613 | - $all_datetimes, |
|
1614 | - $default, |
|
1615 | - $all_tickets, |
|
1616 | - $this->_is_creating_event |
|
1617 | - ); |
|
1618 | - return EEH_Template::display_template( |
|
1619 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1620 | - $template_args, |
|
1621 | - true |
|
1622 | - ); |
|
1623 | - } |
|
1624 | - |
|
1625 | - |
|
1626 | - |
|
1627 | - /** |
|
1628 | - * @param int $ticket_row |
|
1629 | - * @param EE_Ticket|null $ticket |
|
1630 | - * @return string |
|
1631 | - * @throws DomainException |
|
1632 | - * @throws EE_Error |
|
1633 | - */ |
|
1634 | - protected function _get_tax_rows($ticket_row, $ticket) |
|
1635 | - { |
|
1636 | - $tax_rows = ''; |
|
1637 | - /** @var EE_Price[] $taxes */ |
|
1638 | - $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1639 | - foreach ($taxes as $tax) { |
|
1640 | - $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1641 | - $template_args = array( |
|
1642 | - 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1643 | - ? '' |
|
1644 | - : ' style="display:none;"', |
|
1645 | - 'tax_id' => $tax->ID(), |
|
1646 | - 'tkt_row' => $ticket_row, |
|
1647 | - 'tax_label' => $tax->get('PRC_name'), |
|
1648 | - 'tax_added' => $tax_added, |
|
1649 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1650 | - 'tax_amount' => $tax->get('PRC_amount'), |
|
1651 | - ); |
|
1652 | - $template_args = apply_filters( |
|
1653 | - 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1654 | - $template_args, |
|
1655 | - $ticket_row, |
|
1656 | - $ticket, |
|
1657 | - $this->_is_creating_event |
|
1658 | - ); |
|
1659 | - $tax_rows .= EEH_Template::display_template( |
|
1660 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1661 | - $template_args, |
|
1662 | - true |
|
1663 | - ); |
|
1664 | - } |
|
1665 | - return $tax_rows; |
|
1666 | - } |
|
1667 | - |
|
1668 | - |
|
1669 | - |
|
1670 | - /** |
|
1671 | - * @param EE_Price $tax |
|
1672 | - * @param EE_Ticket|null $ticket |
|
1673 | - * @return float|int |
|
1674 | - * @throws EE_Error |
|
1675 | - */ |
|
1676 | - protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1677 | - { |
|
1678 | - $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1679 | - return $subtotal * $tax->get('PRC_amount') / 100; |
|
1680 | - } |
|
1681 | - |
|
1682 | - |
|
1683 | - |
|
1684 | - /** |
|
1685 | - * @param int $ticket_row |
|
1686 | - * @param int $price_row |
|
1687 | - * @param EE_Price|null $price |
|
1688 | - * @param bool $default |
|
1689 | - * @param EE_Ticket|null $ticket |
|
1690 | - * @param bool $show_trash |
|
1691 | - * @param bool $show_create |
|
1692 | - * @return mixed |
|
1693 | - * @throws DomainException |
|
1694 | - * @throws EE_Error |
|
1695 | - */ |
|
1696 | - protected function _get_ticket_price_row( |
|
1697 | - $ticket_row, |
|
1698 | - $price_row, |
|
1699 | - $price, |
|
1700 | - $default, |
|
1701 | - $ticket, |
|
1702 | - $show_trash = true, |
|
1703 | - $show_create = true |
|
1704 | - ) { |
|
1705 | - $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
1706 | - $template_args = array( |
|
1707 | - 'tkt_row' => $default && empty($ticket) |
|
1708 | - ? 'TICKETNUM' |
|
1709 | - : $ticket_row, |
|
1710 | - 'PRC_order' => $default && empty($price) |
|
1711 | - ? 'PRICENUM' |
|
1712 | - : $price_row, |
|
1713 | - 'edit_prices_name' => $default && empty($price) |
|
1714 | - ? 'PRICENAMEATTR' |
|
1715 | - : 'edit_prices', |
|
1716 | - 'price_type_selector' => $default && empty($price) |
|
1717 | - ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1718 | - : $this->_get_price_type_selector($ticket_row, $price_row, $price, $default, $send_disabled), |
|
1719 | - 'PRC_ID' => $default && empty($price) |
|
1720 | - ? 0 |
|
1721 | - : $price->ID(), |
|
1722 | - 'PRC_is_default' => $default && empty($price) |
|
1723 | - ? 0 |
|
1724 | - : $price->get('PRC_is_default'), |
|
1725 | - 'PRC_name' => $default && empty($price) |
|
1726 | - ? '' |
|
1727 | - : $price->get('PRC_name'), |
|
1728 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1729 | - 'show_plus_or_minus' => $default && empty($price) |
|
1730 | - ? '' |
|
1731 | - : ' style="display:none;"', |
|
1732 | - 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1733 | - ? ' style="display:none;"' |
|
1734 | - : '', |
|
1735 | - 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1736 | - ? ' style="display:none;"' |
|
1737 | - : '', |
|
1738 | - 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1739 | - ? ' style="display:none"' |
|
1740 | - : '', |
|
1741 | - 'PRC_amount' => $default && empty($price) |
|
1742 | - ? 0 |
|
1743 | - : $price->get_pretty('PRC_amount', |
|
1744 | - 'localized_float'), |
|
1745 | - 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1746 | - ? ' style="display:none;"' |
|
1747 | - : '', |
|
1748 | - 'show_trash_icon' => $show_trash |
|
1749 | - ? '' |
|
1750 | - : ' style="display:none;"', |
|
1751 | - 'show_create_button' => $show_create |
|
1752 | - ? '' |
|
1753 | - : ' style="display:none;"', |
|
1754 | - 'PRC_desc' => $default && empty($price) |
|
1755 | - ? '' |
|
1756 | - : $price->get('PRC_desc'), |
|
1757 | - 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
1758 | - ); |
|
1759 | - $template_args = apply_filters( |
|
1760 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1761 | - $template_args, |
|
1762 | - $ticket_row, |
|
1763 | - $price_row, |
|
1764 | - $price, |
|
1765 | - $default, |
|
1766 | - $ticket, |
|
1767 | - $show_trash, |
|
1768 | - $show_create, |
|
1769 | - $this->_is_creating_event |
|
1770 | - ); |
|
1771 | - return EEH_Template::display_template( |
|
1772 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1773 | - $template_args, |
|
1774 | - true |
|
1775 | - ); |
|
1776 | - } |
|
1777 | - |
|
1778 | - |
|
1779 | - |
|
1780 | - /** |
|
1781 | - * @param int $ticket_row |
|
1782 | - * @param int $price_row |
|
1783 | - * @param EE_Price $price |
|
1784 | - * @param bool $default |
|
1785 | - * @param bool $disabled |
|
1786 | - * @return mixed |
|
1787 | - * @throws DomainException |
|
1788 | - * @throws EE_Error |
|
1789 | - */ |
|
1790 | - protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1791 | - { |
|
1792 | - if ($price->is_base_price()) { |
|
1793 | - return $this->_get_base_price_template($ticket_row, $price_row, $price, $default); |
|
1794 | - } |
|
1795 | - return $this->_get_price_modifier_template($ticket_row, $price_row, $price, $default, $disabled); |
|
1796 | - } |
|
1797 | - |
|
1798 | - |
|
1799 | - |
|
1800 | - /** |
|
1801 | - * @param int $ticket_row |
|
1802 | - * @param int $price_row |
|
1803 | - * @param EE_Price $price |
|
1804 | - * @param bool $default |
|
1805 | - * @return mixed |
|
1806 | - * @throws DomainException |
|
1807 | - * @throws EE_Error |
|
1808 | - */ |
|
1809 | - protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1810 | - { |
|
1811 | - $template_args = array( |
|
1812 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1813 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1814 | - 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1815 | - 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1816 | - 'price_selected_operator' => '+', |
|
1817 | - 'price_selected_is_percent' => 0, |
|
1818 | - ); |
|
1819 | - $template_args = apply_filters( |
|
1820 | - 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1821 | - $template_args, |
|
1822 | - $ticket_row, |
|
1823 | - $price_row, |
|
1824 | - $price, |
|
1825 | - $default, |
|
1826 | - $this->_is_creating_event |
|
1827 | - ); |
|
1828 | - return EEH_Template::display_template( |
|
1829 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1830 | - $template_args, |
|
1831 | - true |
|
1832 | - ); |
|
1833 | - } |
|
1834 | - |
|
1835 | - |
|
1836 | - |
|
1837 | - /** |
|
1838 | - * @param int $ticket_row |
|
1839 | - * @param int $price_row |
|
1840 | - * @param EE_Price $price |
|
1841 | - * @param bool $default |
|
1842 | - * @param bool $disabled |
|
1843 | - * @return mixed |
|
1844 | - * @throws DomainException |
|
1845 | - * @throws EE_Error |
|
1846 | - */ |
|
1847 | - protected function _get_price_modifier_template( |
|
1848 | - $ticket_row, |
|
1849 | - $price_row, |
|
1850 | - $price, |
|
1851 | - $default, |
|
1852 | - $disabled = false |
|
1853 | - ) { |
|
1854 | - $select_name = $default && ! $price instanceof EE_Price |
|
1855 | - ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1856 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1857 | - /** @var EEM_Price_Type $price_type_model */ |
|
1858 | - $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1859 | - $price_types = $price_type_model->get_all(array( |
|
1860 | - array( |
|
1861 | - 'OR' => array( |
|
1862 | - 'PBT_ID' => '2', |
|
1863 | - 'PBT_ID*' => '3', |
|
1864 | - ), |
|
1865 | - ), |
|
1866 | - )); |
|
1867 | - $all_price_types = $default && ! $price instanceof EE_Price |
|
1868 | - ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
1869 | - : array(); |
|
1870 | - $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1871 | - $price_option_spans = ''; |
|
1872 | - //setup price types for selector |
|
1873 | - foreach ($price_types as $price_type) { |
|
1874 | - if (! $price_type instanceof EE_Price_Type) { |
|
1875 | - continue; |
|
1876 | - } |
|
1877 | - $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
|
1878 | - //while we're in the loop let's setup the option spans used by js |
|
1879 | - $span_args = array( |
|
1880 | - 'PRT_ID' => $price_type->ID(), |
|
1881 | - 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1882 | - 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1883 | - ); |
|
1884 | - $price_option_spans .= EEH_Template::display_template( |
|
1885 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1886 | - $span_args, |
|
1887 | - true |
|
1888 | - ); |
|
1889 | - } |
|
1890 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
1891 | - $select_input = new EE_Select_Input( |
|
1892 | - $all_price_types, |
|
1893 | - array( |
|
1894 | - 'default' => $selected_price_type_id, |
|
1895 | - 'html_name' => $select_name, |
|
1896 | - 'html_class' => 'edit-price-PRT_ID', |
|
1897 | - 'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1898 | - ) |
|
1899 | - ); |
|
1900 | - $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1901 | - $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1902 | - $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1903 | - $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1904 | - $template_args = array( |
|
1905 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1906 | - 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1907 | - 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1908 | - 'main_name' => $select_name, |
|
1909 | - 'selected_price_type_id' => $selected_price_type_id, |
|
1910 | - 'price_option_spans' => $price_option_spans, |
|
1911 | - 'price_selected_operator' => $price_selected_operator, |
|
1912 | - 'price_selected_is_percent' => $price_selected_is_percent, |
|
1913 | - 'disabled' => $disabled, |
|
1914 | - ); |
|
1915 | - $template_args = apply_filters( |
|
1916 | - 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
1917 | - $template_args, |
|
1918 | - $ticket_row, |
|
1919 | - $price_row, |
|
1920 | - $price, |
|
1921 | - $default, |
|
1922 | - $disabled, |
|
1923 | - $this->_is_creating_event |
|
1924 | - ); |
|
1925 | - return EEH_Template::display_template( |
|
1926 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
1927 | - $template_args, |
|
1928 | - true |
|
1929 | - ); |
|
1930 | - } |
|
1931 | - |
|
1932 | - |
|
1933 | - |
|
1934 | - /** |
|
1935 | - * @param int $datetime_row |
|
1936 | - * @param int $ticket_row |
|
1937 | - * @param EE_Datetime|null $datetime |
|
1938 | - * @param EE_Ticket|null $ticket |
|
1939 | - * @param array $ticket_datetimes |
|
1940 | - * @param bool $default |
|
1941 | - * @return mixed |
|
1942 | - * @throws DomainException |
|
1943 | - * @throws EE_Error |
|
1944 | - */ |
|
1945 | - protected function _get_ticket_datetime_list_item( |
|
1946 | - $datetime_row, |
|
1947 | - $ticket_row, |
|
1948 | - $datetime, |
|
1949 | - $ticket, |
|
1950 | - $ticket_datetimes = array(), |
|
1951 | - $default |
|
1952 | - ) { |
|
1953 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1954 | - ? $ticket_datetimes[$ticket->ID()] |
|
1955 | - : array(); |
|
1956 | - $template_args = array( |
|
1957 | - 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
1958 | - ? 'DTTNUM' |
|
1959 | - : $datetime_row, |
|
1960 | - 'tkt_row' => $default |
|
1961 | - ? 'TICKETNUM' |
|
1962 | - : $ticket_row, |
|
1963 | - 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
1964 | - ? ' ticket-selected' |
|
1965 | - : '', |
|
1966 | - 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
1967 | - ? ' checked="checked"' |
|
1968 | - : '', |
|
1969 | - 'DTT_name' => $default && empty($datetime) |
|
1970 | - ? 'DTTNAME' |
|
1971 | - : $datetime->get_dtt_display_name(true), |
|
1972 | - 'tkt_status_class' => '', |
|
1973 | - ); |
|
1974 | - $template_args = apply_filters( |
|
1975 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
1976 | - $template_args, |
|
1977 | - $datetime_row, |
|
1978 | - $ticket_row, |
|
1979 | - $datetime, |
|
1980 | - $ticket, |
|
1981 | - $ticket_datetimes, |
|
1982 | - $default, |
|
1983 | - $this->_is_creating_event |
|
1984 | - ); |
|
1985 | - return EEH_Template::display_template( |
|
1986 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1987 | - $template_args, |
|
1988 | - true |
|
1989 | - ); |
|
1990 | - } |
|
1991 | - |
|
1992 | - |
|
1993 | - |
|
1994 | - /** |
|
1995 | - * @param array $all_datetimes |
|
1996 | - * @param array $all_tickets |
|
1997 | - * @return mixed |
|
1998 | - * @throws DomainException |
|
1999 | - * @throws EE_Error |
|
2000 | - */ |
|
2001 | - protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
2002 | - { |
|
2003 | - $template_args = array( |
|
2004 | - 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
2005 | - 'DTTNUM', |
|
2006 | - null, |
|
2007 | - true, |
|
2008 | - $all_datetimes |
|
2009 | - ), |
|
2010 | - 'default_ticket_row' => $this->_get_ticket_row( |
|
2011 | - 'TICKETNUM', |
|
2012 | - null, |
|
2013 | - array(), |
|
2014 | - array(), |
|
2015 | - true |
|
2016 | - ), |
|
2017 | - 'default_price_row' => $this->_get_ticket_price_row( |
|
2018 | - 'TICKETNUM', |
|
2019 | - 'PRICENUM', |
|
2020 | - null, |
|
2021 | - true, |
|
2022 | - null |
|
2023 | - ), |
|
2024 | - 'default_price_rows' => '', |
|
2025 | - 'default_base_price_amount' => 0, |
|
2026 | - 'default_base_price_name' => '', |
|
2027 | - 'default_base_price_description' => '', |
|
2028 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2029 | - 'TICKETNUM', |
|
2030 | - 'PRICENUM', |
|
2031 | - null, |
|
2032 | - true |
|
2033 | - ), |
|
2034 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2035 | - 'DTTNUM', |
|
2036 | - null, |
|
2037 | - array(), |
|
2038 | - array(), |
|
2039 | - true |
|
2040 | - ), |
|
2041 | - 'existing_available_datetime_tickets_list' => '', |
|
2042 | - 'existing_available_ticket_datetimes_list' => '', |
|
2043 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2044 | - 'DTTNUM', |
|
2045 | - 'TICKETNUM', |
|
2046 | - null, |
|
2047 | - null, |
|
2048 | - array(), |
|
2049 | - true |
|
2050 | - ), |
|
2051 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2052 | - 'DTTNUM', |
|
2053 | - 'TICKETNUM', |
|
2054 | - null, |
|
2055 | - null, |
|
2056 | - array(), |
|
2057 | - true |
|
2058 | - ), |
|
2059 | - ); |
|
2060 | - $ticket_row = 1; |
|
2061 | - foreach ($all_tickets as $ticket) { |
|
2062 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2063 | - 'DTTNUM', |
|
2064 | - $ticket_row, |
|
2065 | - null, |
|
2066 | - $ticket, |
|
2067 | - array(), |
|
2068 | - true |
|
2069 | - ); |
|
2070 | - $ticket_row++; |
|
2071 | - } |
|
2072 | - $datetime_row = 1; |
|
2073 | - foreach ($all_datetimes as $datetime) { |
|
2074 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2075 | - $datetime_row, |
|
2076 | - 'TICKETNUM', |
|
2077 | - $datetime, |
|
2078 | - null, |
|
2079 | - array(), |
|
2080 | - true |
|
2081 | - ); |
|
2082 | - $datetime_row++; |
|
2083 | - } |
|
2084 | - /** @var EEM_Price $price_model */ |
|
2085 | - $price_model = EE_Registry::instance()->load_model('Price'); |
|
2086 | - $default_prices = $price_model->get_all_default_prices(); |
|
2087 | - $price_row = 1; |
|
2088 | - foreach ($default_prices as $price) { |
|
2089 | - if (! $price instanceof EE_Price) { |
|
2090 | - continue; |
|
2091 | - } |
|
2092 | - if ($price->is_base_price()) { |
|
2093 | - $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2094 | - 'PRC_amount', |
|
2095 | - 'localized_float' |
|
2096 | - ); |
|
2097 | - $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2098 | - $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2099 | - $price_row++; |
|
2100 | - continue; |
|
2101 | - } |
|
2102 | - $show_trash = !((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
2103 | - $show_create = !(count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
2104 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2105 | - 'TICKETNUM', |
|
2106 | - $price_row, |
|
2107 | - $price, |
|
2108 | - true, |
|
2109 | - null, |
|
2110 | - $show_trash, |
|
2111 | - $show_create |
|
2112 | - ); |
|
2113 | - $price_row++; |
|
2114 | - } |
|
2115 | - $template_args = apply_filters( |
|
2116 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2117 | - $template_args, |
|
2118 | - $all_datetimes, |
|
2119 | - $all_tickets, |
|
2120 | - $this->_is_creating_event |
|
2121 | - ); |
|
2122 | - return EEH_Template::display_template( |
|
2123 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2124 | - $template_args, |
|
2125 | - true |
|
2126 | - ); |
|
2127 | - } |
|
18 | + /** |
|
19 | + * This property is just used to hold the status of whether an event is currently being |
|
20 | + * created (true) or edited (false) |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @var bool |
|
24 | + */ |
|
25 | + protected $_is_creating_event; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Used to contain the format strings for date and time that will be used for php date and |
|
30 | + * time. |
|
31 | + * Is set in the _set_hooks_properties() method. |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $_date_format_strings; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string $_date_time_format |
|
40 | + */ |
|
41 | + protected $_date_time_format; |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * |
|
47 | + */ |
|
48 | + protected function _set_hooks_properties() |
|
49 | + { |
|
50 | + $this->_name = 'pricing'; |
|
51 | + //capability check |
|
52 | + if ( |
|
53 | + ! EE_Registry::instance()->CAP->current_user_can( |
|
54 | + 'ee_read_default_prices', |
|
55 | + 'advanced_ticket_datetime_metabox' |
|
56 | + ) |
|
57 | + ) { |
|
58 | + return; |
|
59 | + } |
|
60 | + $this->_setup_metaboxes(); |
|
61 | + $this->_set_date_time_formats(); |
|
62 | + $this->_validate_format_strings(); |
|
63 | + $this->_set_scripts_styles(); |
|
64 | + // commented out temporarily until logic is implemented in callback |
|
65 | + // add_action( |
|
66 | + // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
67 | + // array($this, 'autosave_handling') |
|
68 | + // ); |
|
69 | + add_filter( |
|
70 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
71 | + array($this, 'caf_updates') |
|
72 | + ); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + protected function _setup_metaboxes() |
|
81 | + { |
|
82 | + //if we were going to add our own metaboxes we'd use the below. |
|
83 | + $this->_metaboxes = array( |
|
84 | + 0 => array( |
|
85 | + 'page_route' => array('edit', 'create_new'), |
|
86 | + 'func' => 'pricing_metabox', |
|
87 | + 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
88 | + 'priority' => 'high', |
|
89 | + 'context' => 'normal', |
|
90 | + ), |
|
91 | + ); |
|
92 | + $this->_remove_metaboxes = array( |
|
93 | + 0 => array( |
|
94 | + 'page_route' => array('edit', 'create_new'), |
|
95 | + 'id' => 'espresso_event_editor_tickets', |
|
96 | + 'context' => 'normal', |
|
97 | + ), |
|
98 | + ); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + protected function _set_date_time_formats() |
|
107 | + { |
|
108 | + /** |
|
109 | + * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
110 | + * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
111 | + * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
112 | + * |
|
113 | + * @since 4.6.7 |
|
114 | + * @var array Expected an array returned with 'date' and 'time' keys. |
|
115 | + */ |
|
116 | + $this->_date_format_strings = apply_filters( |
|
117 | + 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
118 | + array( |
|
119 | + 'date' => 'Y-m-d', |
|
120 | + 'time' => 'h:i a', |
|
121 | + ) |
|
122 | + ); |
|
123 | + //validate |
|
124 | + $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
125 | + ? $this->_date_format_strings['date'] |
|
126 | + : null; |
|
127 | + $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
128 | + ? $this->_date_format_strings['time'] |
|
129 | + : null; |
|
130 | + $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @return void |
|
137 | + */ |
|
138 | + protected function _validate_format_strings() |
|
139 | + { |
|
140 | + //validate format strings |
|
141 | + $format_validation = EEH_DTT_Helper::validate_format_string( |
|
142 | + $this->_date_time_format |
|
143 | + ); |
|
144 | + if (is_array($format_validation)) { |
|
145 | + $msg = '<p>'; |
|
146 | + $msg .= sprintf( |
|
147 | + esc_html__( |
|
148 | + 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
149 | + 'event_espresso' |
|
150 | + ), |
|
151 | + $this->_date_time_format |
|
152 | + ); |
|
153 | + $msg .= '</p><ul>'; |
|
154 | + foreach ($format_validation as $error) { |
|
155 | + $msg .= '<li>' . $error . '</li>'; |
|
156 | + } |
|
157 | + $msg .= '</ul><p>'; |
|
158 | + $msg .= sprintf( |
|
159 | + esc_html__( |
|
160 | + '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
161 | + 'event_espresso' |
|
162 | + ), |
|
163 | + '<span style="color:#D54E21;">', |
|
164 | + '</span>' |
|
165 | + ); |
|
166 | + $msg .= '</p>'; |
|
167 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | + $this->_date_format_strings = array( |
|
169 | + 'date' => 'Y-m-d', |
|
170 | + 'time' => 'h:i a', |
|
171 | + ); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @return void |
|
179 | + */ |
|
180 | + protected function _set_scripts_styles() |
|
181 | + { |
|
182 | + $this->_scripts_styles = array( |
|
183 | + 'registers' => array( |
|
184 | + 'ee-tickets-datetimes-css' => array( |
|
185 | + 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
186 | + 'type' => 'css', |
|
187 | + ), |
|
188 | + 'ee-dtt-ticket-metabox' => array( |
|
189 | + 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
190 | + 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
191 | + ), |
|
192 | + ), |
|
193 | + 'deregisters' => array( |
|
194 | + 'event-editor-css' => array('type' => 'css'), |
|
195 | + 'event-datetime-metabox' => array('type' => 'js'), |
|
196 | + ), |
|
197 | + 'enqueues' => array( |
|
198 | + 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
199 | + 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
200 | + ), |
|
201 | + 'localize' => array( |
|
202 | + 'ee-dtt-ticket-metabox' => array( |
|
203 | + 'DTT_TRASH_BLOCK' => array( |
|
204 | + 'main_warning' => esc_html__( |
|
205 | + 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
206 | + 'event_espresso' |
|
207 | + ), |
|
208 | + 'after_warning' => esc_html__( |
|
209 | + 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
210 | + 'event_espresso' |
|
211 | + ), |
|
212 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
213 | + . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
214 | + 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
215 | + . esc_html__('Close', 'event_espresso') . '</button>', |
|
216 | + 'single_warning_from_tkt' => esc_html__( |
|
217 | + 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + 'single_warning_from_dtt' => esc_html__( |
|
221 | + 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
222 | + 'event_espresso' |
|
223 | + ), |
|
224 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
225 | + . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
226 | + ), |
|
227 | + 'DTT_ERROR_MSG' => array( |
|
228 | + 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
229 | + 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
|
230 | + . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
231 | + ), |
|
232 | + 'DTT_OVERSELL_WARNING' => array( |
|
233 | + 'datetime_ticket' => esc_html__( |
|
234 | + 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
235 | + 'event_espresso' |
|
236 | + ), |
|
237 | + 'ticket_datetime' => esc_html__( |
|
238 | + 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
239 | + 'event_espresso' |
|
240 | + ), |
|
241 | + ), |
|
242 | + 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
243 | + $this->_date_format_strings['date'], |
|
244 | + $this->_date_format_strings['time'] |
|
245 | + ), |
|
246 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
247 | + ), |
|
248 | + ), |
|
249 | + ); |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @param array $update_callbacks |
|
256 | + * @return array |
|
257 | + */ |
|
258 | + public function caf_updates(array $update_callbacks) |
|
259 | + { |
|
260 | + foreach ($update_callbacks as $key => $callback) { |
|
261 | + if ($callback[1] === '_default_tickets_update') { |
|
262 | + unset($update_callbacks[$key]); |
|
263 | + } |
|
264 | + } |
|
265 | + $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
266 | + return $update_callbacks; |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
272 | + * |
|
273 | + * @param EE_Event $event The Event object we're attaching data to |
|
274 | + * @param array $data The request data from the form |
|
275 | + * @throws EE_Error |
|
276 | + * @throws InvalidArgumentException |
|
277 | + */ |
|
278 | + public function datetime_and_tickets_caf_update($event, $data) |
|
279 | + { |
|
280 | + //first we need to start with datetimes cause they are the "root" items attached to events. |
|
281 | + $saved_datetimes = $this->_update_datetimes($event, $data); |
|
282 | + //next tackle the tickets (and prices?) |
|
283 | + $this->_update_tickets($event, $saved_datetimes, $data); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * update event_datetimes |
|
289 | + * |
|
290 | + * @param EE_Event $event Event being updated |
|
291 | + * @param array $data the request data from the form |
|
292 | + * @return EE_Datetime[] |
|
293 | + * @throws InvalidArgumentException |
|
294 | + * @throws EE_Error |
|
295 | + */ |
|
296 | + protected function _update_datetimes($event, $data) |
|
297 | + { |
|
298 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
299 | + $saved_dtt_ids = array(); |
|
300 | + $saved_dtt_objs = array(); |
|
301 | + if (empty($data['edit_event_datetimes']) || !is_array($data['edit_event_datetimes'])) { |
|
302 | + throw new InvalidArgumentException( |
|
303 | + esc_html__( |
|
304 | + 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
305 | + 'event_espresso' |
|
306 | + ) |
|
307 | + ); |
|
308 | + } |
|
309 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
310 | + //trim all values to ensure any excess whitespace is removed. |
|
311 | + $datetime_data = array_map( |
|
312 | + function ($datetime_data) { |
|
313 | + return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
314 | + }, |
|
315 | + $datetime_data |
|
316 | + ); |
|
317 | + $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
318 | + && ! empty($datetime_data['DTT_EVT_end']) |
|
319 | + ? $datetime_data['DTT_EVT_end'] |
|
320 | + : $datetime_data['DTT_EVT_start']; |
|
321 | + $datetime_values = array( |
|
322 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
323 | + ? $datetime_data['DTT_ID'] |
|
324 | + : null, |
|
325 | + 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
326 | + ? $datetime_data['DTT_name'] |
|
327 | + : '', |
|
328 | + 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
329 | + ? $datetime_data['DTT_description'] |
|
330 | + : '', |
|
331 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
332 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
333 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
334 | + ? EE_INF |
|
335 | + : $datetime_data['DTT_reg_limit'], |
|
336 | + 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
337 | + ? $row |
|
338 | + : $datetime_data['DTT_order'], |
|
339 | + ); |
|
340 | + // if we have an id then let's get existing object first and then set the new values. |
|
341 | + // Otherwise we instantiate a new object for save. |
|
342 | + if (! empty($datetime_data['DTT_ID'])) { |
|
343 | + $datetime = EE_Registry::instance() |
|
344 | + ->load_model('Datetime', array($timezone)) |
|
345 | + ->get_one_by_ID($datetime_data['DTT_ID']); |
|
346 | + //set date and time format according to what is set in this class. |
|
347 | + $datetime->set_date_format($this->_date_format_strings['date']); |
|
348 | + $datetime->set_time_format($this->_date_format_strings['time']); |
|
349 | + foreach ($datetime_values as $field => $value) { |
|
350 | + $datetime->set($field, $value); |
|
351 | + } |
|
352 | + // make sure the $dtt_id here is saved just in case |
|
353 | + // after the add_relation_to() the autosave replaces it. |
|
354 | + // We need to do this so we dont' TRASH the parent DTT. |
|
355 | + // (save the ID for both key and value to avoid duplications) |
|
356 | + $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
357 | + } else { |
|
358 | + $datetime = EE_Registry::instance()->load_class( |
|
359 | + 'Datetime', |
|
360 | + array( |
|
361 | + $datetime_values, |
|
362 | + $timezone, |
|
363 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
364 | + ), |
|
365 | + false, |
|
366 | + false |
|
367 | + ); |
|
368 | + foreach ($datetime_values as $field => $value) { |
|
369 | + $datetime->set($field, $value); |
|
370 | + } |
|
371 | + } |
|
372 | + $datetime->save(); |
|
373 | + $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
374 | + // before going any further make sure our dates are setup correctly |
|
375 | + // so that the end date is always equal or greater than the start date. |
|
376 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
377 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
378 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
379 | + $datetime->save(); |
|
380 | + } |
|
381 | + // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
382 | + // because it is possible there was a new one created for the autosave. |
|
383 | + // (save the ID for both key and value to avoid duplications) |
|
384 | + $DTT_ID = $datetime->ID(); |
|
385 | + $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
386 | + $saved_dtt_objs[$row] = $datetime; |
|
387 | + //todo if ANY of these updates fail then we want the appropriate global error message. |
|
388 | + } |
|
389 | + $event->save(); |
|
390 | + // now we need to REMOVE any datetimes that got deleted. |
|
391 | + // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
392 | + // So its safe to permanently delete at this point. |
|
393 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
394 | + $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
395 | + if (is_array($old_datetimes)) { |
|
396 | + $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
397 | + foreach ($datetimes_to_delete as $id) { |
|
398 | + $id = absint($id); |
|
399 | + if (empty($id)) { |
|
400 | + continue; |
|
401 | + } |
|
402 | + $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
403 | + //remove tkt relationships. |
|
404 | + $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
405 | + foreach ($related_tickets as $tkt) { |
|
406 | + $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
407 | + } |
|
408 | + $event->_remove_relation_to($id, 'Datetime'); |
|
409 | + $dtt_to_remove->refresh_cache_of_related_objects(); |
|
410 | + } |
|
411 | + } |
|
412 | + return $saved_dtt_objs; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * update tickets |
|
418 | + * |
|
419 | + * @param EE_Event $event Event object being updated |
|
420 | + * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
421 | + * @param array $data incoming request data |
|
422 | + * @return EE_Ticket[] |
|
423 | + * @throws InvalidArgumentException |
|
424 | + * @throws EE_Error |
|
425 | + */ |
|
426 | + protected function _update_tickets($event, $saved_datetimes, $data) |
|
427 | + { |
|
428 | + $new_tkt = null; |
|
429 | + $new_default = null; |
|
430 | + //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
431 | + $data = stripslashes_deep($data); |
|
432 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
433 | + $saved_tickets = $datetimes_on_existing = array(); |
|
434 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
435 | + if(empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])){ |
|
436 | + throw new InvalidArgumentException( |
|
437 | + esc_html__( |
|
438 | + 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
439 | + 'event_espresso' |
|
440 | + ) |
|
441 | + ); |
|
442 | + } |
|
443 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
444 | + $update_prices = $create_new_TKT = false; |
|
445 | + // figure out what datetimes were added to the ticket |
|
446 | + // and what datetimes were removed from the ticket in the session. |
|
447 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
448 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
449 | + $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
450 | + $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
451 | + // trim inputs to ensure any excess whitespace is removed. |
|
452 | + $tkt = array_map( |
|
453 | + function ($ticket_data) { |
|
454 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
455 | + }, |
|
456 | + $tkt |
|
457 | + ); |
|
458 | + // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
459 | + // because we're doing calculations prior to using the models. |
|
460 | + // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
461 | + $ticket_price = isset($tkt['TKT_price']) |
|
462 | + ? round((float)$tkt['TKT_price'], 3) |
|
463 | + : 0; |
|
464 | + //note incoming base price needs converted from localized value. |
|
465 | + $base_price = isset($tkt['TKT_base_price']) |
|
466 | + ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
467 | + : 0; |
|
468 | + //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
469 | + $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
470 | + ? $base_price |
|
471 | + : $ticket_price; |
|
472 | + $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
473 | + ? $tkt['TKT_base_price_ID'] |
|
474 | + : 0; |
|
475 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
476 | + ? $data['edit_prices'][$row] |
|
477 | + : array(); |
|
478 | + $now = null; |
|
479 | + if (empty($tkt['TKT_start_date'])) { |
|
480 | + //lets' use now in the set timezone. |
|
481 | + $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
482 | + $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
483 | + } |
|
484 | + if (empty($tkt['TKT_end_date'])) { |
|
485 | + /** |
|
486 | + * set the TKT_end_date to the first datetime attached to the ticket. |
|
487 | + */ |
|
488 | + $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
489 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
490 | + } |
|
491 | + $TKT_values = array( |
|
492 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
493 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
494 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
495 | + 'TKT_description' => ! empty($tkt['TKT_description']) |
|
496 | + && $tkt['TKT_description'] !== esc_html__( |
|
497 | + 'You can modify this description', |
|
498 | + 'event_espresso' |
|
499 | + ) |
|
500 | + ? $tkt['TKT_description'] |
|
501 | + : '', |
|
502 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
503 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
504 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
505 | + ? EE_INF |
|
506 | + : $tkt['TKT_qty'], |
|
507 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
508 | + ? EE_INF |
|
509 | + : $tkt['TKT_uses'], |
|
510 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
511 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
512 | + 'TKT_row' => $row, |
|
513 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
514 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
515 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
516 | + 'TKT_price' => $ticket_price, |
|
517 | + ); |
|
518 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
519 | + // which means in turn that the prices will become new prices as well. |
|
520 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
521 | + $TKT_values['TKT_ID'] = 0; |
|
522 | + $TKT_values['TKT_is_default'] = 0; |
|
523 | + $update_prices = true; |
|
524 | + } |
|
525 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
526 | + // we actually do our saves ahead of doing any add_relations to |
|
527 | + // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
528 | + // but DID have it's items modified. |
|
529 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
530 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
531 | + if (absint($TKT_values['TKT_ID'])) { |
|
532 | + $ticket = EE_Registry::instance() |
|
533 | + ->load_model('Ticket', array($timezone)) |
|
534 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
535 | + if ($ticket instanceof EE_Ticket) { |
|
536 | + $ticket = $this->_update_ticket_datetimes( |
|
537 | + $ticket, |
|
538 | + $saved_datetimes, |
|
539 | + $datetimes_added, |
|
540 | + $datetimes_removed |
|
541 | + ); |
|
542 | + // are there any registrations using this ticket ? |
|
543 | + $tickets_sold = $ticket->count_related( |
|
544 | + 'Registration', |
|
545 | + array( |
|
546 | + array( |
|
547 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
548 | + ), |
|
549 | + ) |
|
550 | + ); |
|
551 | + //set ticket formats |
|
552 | + $ticket->set_date_format($this->_date_format_strings['date']); |
|
553 | + $ticket->set_time_format($this->_date_format_strings['time']); |
|
554 | + // let's just check the total price for the existing ticket |
|
555 | + // and determine if it matches the new total price. |
|
556 | + // if they are different then we create a new ticket (if tickets sold) |
|
557 | + // if they aren't different then we go ahead and modify existing ticket. |
|
558 | + $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
559 | + //set new values |
|
560 | + foreach ($TKT_values as $field => $value) { |
|
561 | + if ($field === 'TKT_qty') { |
|
562 | + $ticket->set_qty($value); |
|
563 | + } else { |
|
564 | + $ticket->set($field, $value); |
|
565 | + } |
|
566 | + } |
|
567 | + // if $create_new_TKT is false then we can safely update the existing ticket. |
|
568 | + // Otherwise we have to create a new ticket. |
|
569 | + if ($create_new_TKT) { |
|
570 | + $new_tkt = $this->_duplicate_ticket($ticket, $price_rows, $ticket_price, $base_price, |
|
571 | + $base_price_id); |
|
572 | + } |
|
573 | + } |
|
574 | + } else { |
|
575 | + // no TKT_id so a new TKT |
|
576 | + $ticket = EE_Ticket::new_instance( |
|
577 | + $TKT_values, |
|
578 | + $timezone, |
|
579 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
580 | + ); |
|
581 | + if ($ticket instanceof EE_Ticket) { |
|
582 | + // make sure ticket has an ID of setting relations won't work |
|
583 | + $ticket->save(); |
|
584 | + $ticket = $this->_update_ticket_datetimes( |
|
585 | + $ticket, |
|
586 | + $saved_datetimes, |
|
587 | + $datetimes_added, |
|
588 | + $datetimes_removed |
|
589 | + ); |
|
590 | + $update_prices = true; |
|
591 | + } |
|
592 | + } |
|
593 | + //make sure any current values have been saved. |
|
594 | + //$ticket->save(); |
|
595 | + // before going any further make sure our dates are setup correctly |
|
596 | + // so that the end date is always equal or greater than the start date. |
|
597 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
598 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
599 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
600 | + } |
|
601 | + //let's make sure the base price is handled |
|
602 | + $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $ticket, $update_prices, $base_price, |
|
603 | + $base_price_id) : $ticket; |
|
604 | + //add/update price_modifiers |
|
605 | + $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) : $ticket; |
|
606 | + //need to make sue that the TKT_price is accurate after saving the prices. |
|
607 | + $ticket->ensure_TKT_Price_correct(); |
|
608 | + //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
609 | + if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
610 | + $update_prices = true; |
|
611 | + $new_default = clone $ticket; |
|
612 | + $new_default->set('TKT_ID', 0); |
|
613 | + $new_default->set('TKT_is_default', 1); |
|
614 | + $new_default->set('TKT_row', 1); |
|
615 | + $new_default->set('TKT_price', $ticket_price); |
|
616 | + // remove any dtt relations cause we DON'T want dtt relations attached |
|
617 | + // (note this is just removing the cached relations in the object) |
|
618 | + $new_default->_remove_relations('Datetime'); |
|
619 | + //todo we need to add the current attached prices as new prices to the new default ticket. |
|
620 | + $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
621 | + //don't forget the base price! |
|
622 | + $new_default = $this->_add_prices_to_ticket( |
|
623 | + array(), |
|
624 | + $new_default, |
|
625 | + $update_prices, |
|
626 | + $base_price, |
|
627 | + $base_price_id |
|
628 | + ); |
|
629 | + $new_default->save(); |
|
630 | + do_action( |
|
631 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
632 | + $new_default, |
|
633 | + $row, |
|
634 | + $ticket, |
|
635 | + $data |
|
636 | + ); |
|
637 | + } |
|
638 | + // DO ALL dtt relationships for both current tickets and any archived tickets |
|
639 | + // for the given dtt that are related to the current ticket. |
|
640 | + // TODO... not sure exactly how we're going to do this considering we don't know |
|
641 | + // what current ticket the archived tickets are related to |
|
642 | + // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
643 | + //let's assign any tickets that have been setup to the saved_tickets tracker |
|
644 | + //save existing TKT |
|
645 | + $ticket->save(); |
|
646 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
647 | + //save new TKT |
|
648 | + $new_tkt->save(); |
|
649 | + //add new ticket to array |
|
650 | + $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
651 | + do_action( |
|
652 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
653 | + $new_tkt, |
|
654 | + $row, |
|
655 | + $tkt, |
|
656 | + $data |
|
657 | + ); |
|
658 | + } else { |
|
659 | + //add tkt to saved tkts |
|
660 | + $saved_tickets[$ticket->ID()] = $ticket; |
|
661 | + do_action( |
|
662 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
663 | + $ticket, |
|
664 | + $row, |
|
665 | + $tkt, |
|
666 | + $data |
|
667 | + ); |
|
668 | + } |
|
669 | + } |
|
670 | + // now we need to handle tickets actually "deleted permanently". |
|
671 | + // There are cases where we'd want this to happen |
|
672 | + // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
673 | + // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
674 | + // No sense in keeping all the related data in the db! |
|
675 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
676 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
677 | + foreach ($tickets_removed as $id) { |
|
678 | + $id = absint($id); |
|
679 | + //get the ticket for this id |
|
680 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
681 | + //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
682 | + if ($tkt_to_remove->get('TKT_is_default')) { |
|
683 | + continue; |
|
684 | + } |
|
685 | + // if this tkt has any registrations attached so then we just ARCHIVE |
|
686 | + // because we don't actually permanently delete these tickets. |
|
687 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
688 | + $tkt_to_remove->delete(); |
|
689 | + continue; |
|
690 | + } |
|
691 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
692 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
693 | + $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
694 | + foreach ($datetimes as $datetime) { |
|
695 | + $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
696 | + } |
|
697 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
698 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
699 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
700 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
701 | + // finally let's delete this ticket |
|
702 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
703 | + $tkt_to_remove->delete_permanently(); |
|
704 | + } |
|
705 | + return $saved_tickets; |
|
706 | + } |
|
707 | + |
|
708 | + |
|
709 | + |
|
710 | + /** |
|
711 | + * @access protected |
|
712 | + * @param \EE_Ticket $ticket |
|
713 | + * @param \EE_Datetime[] $saved_datetimes |
|
714 | + * @param \EE_Datetime[] $added_datetimes |
|
715 | + * @param \EE_Datetime[] $removed_datetimes |
|
716 | + * @return \EE_Ticket |
|
717 | + * @throws \EE_Error |
|
718 | + */ |
|
719 | + protected function _update_ticket_datetimes( |
|
720 | + EE_Ticket $ticket, |
|
721 | + $saved_datetimes = array(), |
|
722 | + $added_datetimes = array(), |
|
723 | + $removed_datetimes = array() |
|
724 | + ) { |
|
725 | + // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
726 | + // and removing the ticket from datetimes it got removed from. |
|
727 | + // first let's add datetimes |
|
728 | + if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
729 | + foreach ($added_datetimes as $row_id) { |
|
730 | + $row_id = (int)$row_id; |
|
731 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
732 | + $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
733 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
734 | + // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
735 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
736 | + $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
737 | + $saved_datetimes[$row_id]->save(); |
|
738 | + } |
|
739 | + } |
|
740 | + } |
|
741 | + } |
|
742 | + // then remove datetimes |
|
743 | + if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
744 | + foreach ($removed_datetimes as $row_id) { |
|
745 | + $row_id = (int)$row_id; |
|
746 | + // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
747 | + // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
748 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
749 | + $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
750 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
751 | + // If so, then we need to remove it's sold from the DTT_sold. |
|
752 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
753 | + $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
754 | + $saved_datetimes[$row_id]->save(); |
|
755 | + } |
|
756 | + } |
|
757 | + } |
|
758 | + } |
|
759 | + // cap ticket qty by datetime reg limits |
|
760 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
761 | + return $ticket; |
|
762 | + } |
|
763 | + |
|
764 | + |
|
765 | + |
|
766 | + /** |
|
767 | + * @access protected |
|
768 | + * @param \EE_Ticket $ticket |
|
769 | + * @param array $price_rows |
|
770 | + * @param int $ticket_price |
|
771 | + * @param int $base_price |
|
772 | + * @param int $base_price_id |
|
773 | + * @return \EE_Ticket |
|
774 | + * @throws \EE_Error |
|
775 | + */ |
|
776 | + protected function _duplicate_ticket( |
|
777 | + EE_Ticket $ticket, |
|
778 | + $price_rows = array(), |
|
779 | + $ticket_price = 0, |
|
780 | + $base_price = 0, |
|
781 | + $base_price_id = 0 |
|
782 | + ) { |
|
783 | + // create new ticket that's a copy of the existing |
|
784 | + // except a new id of course (and not archived) |
|
785 | + // AND has the new TKT_price associated with it. |
|
786 | + $new_ticket = clone $ticket; |
|
787 | + $new_ticket->set('TKT_ID', 0); |
|
788 | + $new_ticket->set('TKT_deleted', 0); |
|
789 | + $new_ticket->set('TKT_price', $ticket_price); |
|
790 | + $new_ticket->set('TKT_sold', 0); |
|
791 | + // let's get a new ID for this ticket |
|
792 | + $new_ticket->save(); |
|
793 | + // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
794 | + $datetimes_on_existing = $ticket->get_many_related('Datetime'); |
|
795 | + $new_ticket = $this->_update_ticket_datetimes( |
|
796 | + $new_ticket, |
|
797 | + $datetimes_on_existing, |
|
798 | + array_keys($datetimes_on_existing) |
|
799 | + ); |
|
800 | + // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
801 | + // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
802 | + // available. |
|
803 | + if ($ticket->sold() > 0) { |
|
804 | + $new_qty = $ticket->qty() - $ticket->sold(); |
|
805 | + $new_ticket->set_qty($new_qty); |
|
806 | + } |
|
807 | + //now we update the prices just for this ticket |
|
808 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
809 | + //and we update the base price |
|
810 | + $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
811 | + return $new_ticket; |
|
812 | + } |
|
813 | + |
|
814 | + |
|
815 | + |
|
816 | + /** |
|
817 | + * This attaches a list of given prices to a ticket. |
|
818 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
819 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
820 | + * price info and prices are automatically "archived" via the ticket. |
|
821 | + * |
|
822 | + * @access private |
|
823 | + * @param array $prices Array of prices from the form. |
|
824 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
825 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
826 | + * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
827 | + * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
828 | + * @return EE_Ticket |
|
829 | + * @throws EE_Error |
|
830 | + */ |
|
831 | + protected function _add_prices_to_ticket( |
|
832 | + $prices = array(), |
|
833 | + EE_Ticket $ticket, |
|
834 | + $new_prices = false, |
|
835 | + $base_price = false, |
|
836 | + $base_price_id = false |
|
837 | + ) { |
|
838 | + // let's just get any current prices that may exist on the given ticket |
|
839 | + // so we can remove any prices that got trashed in this session. |
|
840 | + $current_prices_on_ticket = $base_price !== false |
|
841 | + ? $ticket->base_price(true) |
|
842 | + : $ticket->price_modifiers(); |
|
843 | + $updated_prices = array(); |
|
844 | + // if $base_price ! FALSE then updating a base price. |
|
845 | + if ($base_price !== false) { |
|
846 | + $prices[1] = array( |
|
847 | + 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
848 | + 'PRT_ID' => 1, |
|
849 | + 'PRC_amount' => $base_price, |
|
850 | + 'PRC_name' => $ticket->get('TKT_name'), |
|
851 | + 'PRC_desc' => $ticket->get('TKT_description'), |
|
852 | + ); |
|
853 | + } |
|
854 | + //possibly need to save tkt |
|
855 | + if (! $ticket->ID()) { |
|
856 | + $ticket->save(); |
|
857 | + } |
|
858 | + foreach ($prices as $row => $prc) { |
|
859 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
860 | + if (empty($prt_id)) { |
|
861 | + continue; |
|
862 | + } //prices MUST have a price type id. |
|
863 | + $PRC_values = array( |
|
864 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
865 | + 'PRT_ID' => $prt_id, |
|
866 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
867 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
868 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
869 | + 'PRC_is_default' => false, |
|
870 | + //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
871 | + 'PRC_order' => $row, |
|
872 | + ); |
|
873 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
874 | + $PRC_values['PRC_ID'] = 0; |
|
875 | + $price = EE_Registry::instance()->load_class( |
|
876 | + 'Price', |
|
877 | + array($PRC_values), |
|
878 | + false, |
|
879 | + false |
|
880 | + ); |
|
881 | + } else { |
|
882 | + $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
883 | + //update this price with new values |
|
884 | + foreach ($PRC_values as $field => $value) { |
|
885 | + $price->set($field, $value); |
|
886 | + } |
|
887 | + } |
|
888 | + $price->save(); |
|
889 | + $updated_prices[$price->ID()] = $price; |
|
890 | + $ticket->_add_relation_to($price, 'Price'); |
|
891 | + } |
|
892 | + //now let's remove any prices that got removed from the ticket |
|
893 | + if (! empty ($current_prices_on_ticket)) { |
|
894 | + $current = array_keys($current_prices_on_ticket); |
|
895 | + $updated = array_keys($updated_prices); |
|
896 | + $prices_to_remove = array_diff($current, $updated); |
|
897 | + if (! empty($prices_to_remove)) { |
|
898 | + foreach ($prices_to_remove as $prc_id) { |
|
899 | + $p = $current_prices_on_ticket[$prc_id]; |
|
900 | + $ticket->_remove_relation_to($p, 'Price'); |
|
901 | + //delete permanently the price |
|
902 | + $p->delete_permanently(); |
|
903 | + } |
|
904 | + } |
|
905 | + } |
|
906 | + return $ticket; |
|
907 | + } |
|
908 | + |
|
909 | + |
|
910 | + |
|
911 | + /** |
|
912 | + * @param Events_Admin_Page $event_admin_obj |
|
913 | + * @return Events_Admin_Page |
|
914 | + */ |
|
915 | + public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
916 | + { |
|
917 | + return $event_admin_obj; |
|
918 | + //doing nothing for the moment. |
|
919 | + // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
920 | + // (use the set_template_args() method) |
|
921 | + /** |
|
922 | + * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
923 | + * 1. TKT_is_default_selector (visible) |
|
924 | + * 2. TKT_is_default (hidden) |
|
925 | + * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
926 | + * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
927 | + * this ticket to be saved as a default. |
|
928 | + * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
929 | + * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
930 | + * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
931 | + * the TKT HAS been saved as a default.. |
|
932 | + * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
933 | + * On Autosave: |
|
934 | + * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
935 | + * then set the TKT_is_default to false. |
|
936 | + * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
937 | + * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
938 | + * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
939 | + */ |
|
940 | + } |
|
941 | + |
|
942 | + |
|
943 | + |
|
944 | + /** |
|
945 | + * @throws DomainException |
|
946 | + * @throws EE_Error |
|
947 | + */ |
|
948 | + public function pricing_metabox() |
|
949 | + { |
|
950 | + $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
951 | + $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
952 | + //set is_creating_event property. |
|
953 | + $EVT_ID = $event->ID(); |
|
954 | + $this->_is_creating_event = absint($EVT_ID) === 0; |
|
955 | + //default main template args |
|
956 | + $main_template_args = array( |
|
957 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
958 | + 'event_editor_event_datetimes_help_tab', |
|
959 | + $this->_adminpage_obj->page_slug, |
|
960 | + $this->_adminpage_obj->get_req_action(), |
|
961 | + false, |
|
962 | + false |
|
963 | + ), |
|
964 | + // todo need to add a filter to the template for the help text |
|
965 | + // in the Events_Admin_Page core file so we can add further help |
|
966 | + 'existing_datetime_ids' => '', |
|
967 | + 'total_dtt_rows' => 1, |
|
968 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
969 | + 'add_new_dtt_info', |
|
970 | + $this->_adminpage_obj->page_slug, |
|
971 | + $this->_adminpage_obj->get_req_action(), |
|
972 | + false, |
|
973 | + false |
|
974 | + ), |
|
975 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
976 | + 'datetime_rows' => '', |
|
977 | + 'show_tickets_container' => '', |
|
978 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
979 | + 'ticket_rows' => '', |
|
980 | + 'existing_ticket_ids' => '', |
|
981 | + 'total_ticket_rows' => 1, |
|
982 | + 'ticket_js_structure' => '', |
|
983 | + 'ee_collapsible_status' => ' ee-collapsible-open' |
|
984 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
985 | + ); |
|
986 | + $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
987 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
988 | + /** |
|
989 | + * 1. Start with retrieving Datetimes |
|
990 | + * 2. For each datetime get related tickets |
|
991 | + * 3. For each ticket get related prices |
|
992 | + */ |
|
993 | + /** @var EEM_Datetime $datetime_model */ |
|
994 | + $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
995 | + $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
996 | + $main_template_args['total_dtt_rows'] = count($datetimes); |
|
997 | + /** |
|
998 | + * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
999 | + * for why we are counting $datetime_row and then setting that on the Datetime object |
|
1000 | + */ |
|
1001 | + $datetime_row = 1; |
|
1002 | + foreach ($datetimes as $datetime) { |
|
1003 | + $DTT_ID = $datetime->get('DTT_ID'); |
|
1004 | + $datetime->set('DTT_order', $datetime_row); |
|
1005 | + $existing_datetime_ids[] = $DTT_ID; |
|
1006 | + //tickets attached |
|
1007 | + $related_tickets = $datetime->ID() > 0 |
|
1008 | + ? $datetime->get_many_related( |
|
1009 | + 'Ticket', |
|
1010 | + array( |
|
1011 | + array( |
|
1012 | + 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
1013 | + ), |
|
1014 | + 'default_where_conditions' => 'none', |
|
1015 | + 'order_by' => array('TKT_order' => 'ASC'), |
|
1016 | + ) |
|
1017 | + ) |
|
1018 | + : array(); |
|
1019 | + //if there are no related tickets this is likely a new event OR autodraft |
|
1020 | + // event so we need to generate the default tickets because datetimes |
|
1021 | + // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1022 | + // datetime on the event. |
|
1023 | + if (empty ($related_tickets) && count($datetimes) < 2) { |
|
1024 | + /** @var EEM_Ticket $ticket_model */ |
|
1025 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1026 | + $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1027 | + // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1028 | + // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1029 | + $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1030 | + $main_default_ticket = reset($related_tickets); |
|
1031 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
1032 | + foreach ($default_prices as $default_price) { |
|
1033 | + if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1034 | + continue; |
|
1035 | + } |
|
1036 | + $main_default_ticket->cache('Price', $default_price); |
|
1037 | + } |
|
1038 | + } |
|
1039 | + } |
|
1040 | + // we can't actually setup rows in this loop yet cause we don't know all |
|
1041 | + // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1042 | + // So we're going to temporarily cache some of that information. |
|
1043 | + //loop through and setup the ticket rows and make sure the order is set. |
|
1044 | + foreach ($related_tickets as $ticket) { |
|
1045 | + $TKT_ID = $ticket->get('TKT_ID'); |
|
1046 | + $ticket_row = $ticket->get('TKT_row'); |
|
1047 | + //we only want unique tickets in our final display!! |
|
1048 | + if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1049 | + $existing_ticket_ids[] = $TKT_ID; |
|
1050 | + $all_tickets[] = $ticket; |
|
1051 | + } |
|
1052 | + //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1053 | + $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
1054 | + //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1055 | + if ( |
|
1056 | + ! isset($ticket_datetimes[$TKT_ID]) |
|
1057 | + || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
1058 | + ) { |
|
1059 | + $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
1060 | + } |
|
1061 | + } |
|
1062 | + $datetime_row++; |
|
1063 | + } |
|
1064 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1065 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1066 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1067 | + //sort $all_tickets by order |
|
1068 | + usort( |
|
1069 | + $all_tickets, |
|
1070 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
1071 | + $a_order = (int)$a->get('TKT_order'); |
|
1072 | + $b_order = (int)$b->get('TKT_order'); |
|
1073 | + if ($a_order === $b_order) { |
|
1074 | + return 0; |
|
1075 | + } |
|
1076 | + return ($a_order < $b_order) ? -1 : 1; |
|
1077 | + } |
|
1078 | + ); |
|
1079 | + // k NOW we have all the data we need for setting up the dtt rows |
|
1080 | + // and ticket rows so we start our dtt loop again. |
|
1081 | + $datetime_row = 1; |
|
1082 | + foreach ($datetimes as $datetime) { |
|
1083 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1084 | + $datetime_row, |
|
1085 | + $datetime, |
|
1086 | + $datetime_tickets, |
|
1087 | + $all_tickets, |
|
1088 | + false, |
|
1089 | + $datetimes |
|
1090 | + ); |
|
1091 | + $datetime_row++; |
|
1092 | + } |
|
1093 | + //then loop through all tickets for the ticket rows. |
|
1094 | + $ticket_row = 1; |
|
1095 | + foreach ($all_tickets as $ticket) { |
|
1096 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1097 | + $ticket_row, |
|
1098 | + $ticket, |
|
1099 | + $ticket_datetimes, |
|
1100 | + $datetimes, |
|
1101 | + false, |
|
1102 | + $all_tickets |
|
1103 | + ); |
|
1104 | + $ticket_row++; |
|
1105 | + } |
|
1106 | + $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1107 | + EEH_Template::display_template( |
|
1108 | + PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1109 | + $main_template_args |
|
1110 | + ); |
|
1111 | + } |
|
1112 | + |
|
1113 | + |
|
1114 | + |
|
1115 | + /** |
|
1116 | + * @param int $datetime_row |
|
1117 | + * @param EE_Datetime $datetime |
|
1118 | + * @param array $datetime_tickets |
|
1119 | + * @param array $all_tickets |
|
1120 | + * @param bool $default |
|
1121 | + * @param array $all_datetimes |
|
1122 | + * @return mixed |
|
1123 | + * @throws DomainException |
|
1124 | + * @throws EE_Error |
|
1125 | + */ |
|
1126 | + protected function _get_datetime_row( |
|
1127 | + $datetime_row, |
|
1128 | + EE_Datetime $datetime, |
|
1129 | + $datetime_tickets = array(), |
|
1130 | + $all_tickets = array(), |
|
1131 | + $default = false, |
|
1132 | + $all_datetimes = array() |
|
1133 | + ) { |
|
1134 | + $dtt_display_template_args = array( |
|
1135 | + 'dtt_edit_row' => $this->_get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes), |
|
1136 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1137 | + $datetime_row, |
|
1138 | + $datetime, |
|
1139 | + $datetime_tickets, |
|
1140 | + $all_tickets, |
|
1141 | + $default |
|
1142 | + ), |
|
1143 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1144 | + ); |
|
1145 | + return EEH_Template::display_template( |
|
1146 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1147 | + $dtt_display_template_args, |
|
1148 | + true |
|
1149 | + ); |
|
1150 | + } |
|
1151 | + |
|
1152 | + |
|
1153 | + |
|
1154 | + /** |
|
1155 | + * This method is used to generate a dtt fields edit row. |
|
1156 | + * The same row is used to generate a row with valid DTT objects |
|
1157 | + * and the default row that is used as the skeleton by the js. |
|
1158 | + * |
|
1159 | + * @param int $datetime_row The row number for the row being generated. |
|
1160 | + * @param EE_Datetime $datetime |
|
1161 | + * @param bool $default Whether a default row is being generated or not. |
|
1162 | + * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1163 | + * @return string |
|
1164 | + * @throws DomainException |
|
1165 | + * @throws EE_Error |
|
1166 | + */ |
|
1167 | + protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1168 | + { |
|
1169 | + // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1170 | + $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1171 | + $template_args = array( |
|
1172 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1173 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1174 | + 'edit_dtt_expanded' => '', |
|
1175 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1176 | + 'DTT_name' => $default ? '' : $datetime->name(), |
|
1177 | + 'DTT_description' => $default ? '' : $datetime->description(), |
|
1178 | + 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1179 | + 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1180 | + 'DTT_reg_limit' => $default |
|
1181 | + ? '' |
|
1182 | + : $datetime->get_pretty( |
|
1183 | + 'DTT_reg_limit', |
|
1184 | + 'input' |
|
1185 | + ), |
|
1186 | + 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1187 | + 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1188 | + 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1189 | + 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1190 | + ? '' |
|
1191 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1192 | + 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1193 | + ? 'ee-lock-icon' |
|
1194 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1195 | + 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1196 | + ? '' |
|
1197 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
1198 | + array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
1199 | + REG_ADMIN_URL |
|
1200 | + ), |
|
1201 | + ); |
|
1202 | + $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1203 | + ? ' style="display:none"' |
|
1204 | + : ''; |
|
1205 | + //allow filtering of template args at this point. |
|
1206 | + $template_args = apply_filters( |
|
1207 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1208 | + $template_args, |
|
1209 | + $datetime_row, |
|
1210 | + $datetime, |
|
1211 | + $default, |
|
1212 | + $all_datetimes, |
|
1213 | + $this->_is_creating_event |
|
1214 | + ); |
|
1215 | + return EEH_Template::display_template( |
|
1216 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1217 | + $template_args, |
|
1218 | + true |
|
1219 | + ); |
|
1220 | + } |
|
1221 | + |
|
1222 | + |
|
1223 | + |
|
1224 | + /** |
|
1225 | + * @param int $datetime_row |
|
1226 | + * @param EE_Datetime $datetime |
|
1227 | + * @param array $datetime_tickets |
|
1228 | + * @param array $all_tickets |
|
1229 | + * @param bool $default |
|
1230 | + * @return mixed |
|
1231 | + * @throws DomainException |
|
1232 | + * @throws EE_Error |
|
1233 | + */ |
|
1234 | + protected function _get_dtt_attached_tickets_row( |
|
1235 | + $datetime_row, |
|
1236 | + $datetime, |
|
1237 | + $datetime_tickets = array(), |
|
1238 | + $all_tickets = array(), |
|
1239 | + $default |
|
1240 | + ) { |
|
1241 | + $template_args = array( |
|
1242 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1243 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1244 | + 'DTT_description' => $default ? '' : $datetime->description(), |
|
1245 | + 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1246 | + 'show_tickets_row' => ' style="display:none;"', |
|
1247 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1248 | + 'add_new_ticket_via_datetime', |
|
1249 | + $this->_adminpage_obj->page_slug, |
|
1250 | + $this->_adminpage_obj->get_req_action(), |
|
1251 | + false, |
|
1252 | + false |
|
1253 | + ), |
|
1254 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1255 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1256 | + ); |
|
1257 | + //need to setup the list items (but only if this isn't a default skeleton setup) |
|
1258 | + if (! $default) { |
|
1259 | + $ticket_row = 1; |
|
1260 | + foreach ($all_tickets as $ticket) { |
|
1261 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1262 | + $datetime_row, |
|
1263 | + $ticket_row, |
|
1264 | + $datetime, |
|
1265 | + $ticket, |
|
1266 | + $datetime_tickets, |
|
1267 | + $default |
|
1268 | + ); |
|
1269 | + $ticket_row++; |
|
1270 | + } |
|
1271 | + } |
|
1272 | + //filter template args at this point |
|
1273 | + $template_args = apply_filters( |
|
1274 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1275 | + $template_args, |
|
1276 | + $datetime_row, |
|
1277 | + $datetime, |
|
1278 | + $datetime_tickets, |
|
1279 | + $all_tickets, |
|
1280 | + $default, |
|
1281 | + $this->_is_creating_event |
|
1282 | + ); |
|
1283 | + return EEH_Template::display_template( |
|
1284 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1285 | + $template_args, |
|
1286 | + true |
|
1287 | + ); |
|
1288 | + } |
|
1289 | + |
|
1290 | + |
|
1291 | + |
|
1292 | + /** |
|
1293 | + * @param int $datetime_row |
|
1294 | + * @param int $ticket_row |
|
1295 | + * @param EE_Datetime $datetime |
|
1296 | + * @param EE_Ticket $ticket |
|
1297 | + * @param array $datetime_tickets |
|
1298 | + * @param bool $default |
|
1299 | + * @return mixed |
|
1300 | + * @throws DomainException |
|
1301 | + * @throws EE_Error |
|
1302 | + */ |
|
1303 | + protected function _get_datetime_tickets_list_item( |
|
1304 | + $datetime_row, |
|
1305 | + $ticket_row, |
|
1306 | + $datetime, |
|
1307 | + $ticket, |
|
1308 | + $datetime_tickets = array(), |
|
1309 | + $default |
|
1310 | + ) { |
|
1311 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
1312 | + ? $datetime_tickets[$datetime->ID()] |
|
1313 | + : array(); |
|
1314 | + $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1315 | + $no_ticket = $default && empty($ticket); |
|
1316 | + $template_args = array( |
|
1317 | + 'dtt_row' => $default |
|
1318 | + ? 'DTTNUM' |
|
1319 | + : $datetime_row, |
|
1320 | + 'tkt_row' => $no_ticket |
|
1321 | + ? 'TICKETNUM' |
|
1322 | + : $ticket_row, |
|
1323 | + 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1324 | + ? ' checked="checked"' |
|
1325 | + : '', |
|
1326 | + 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1327 | + ? ' ticket-selected' |
|
1328 | + : '', |
|
1329 | + 'TKT_name' => $no_ticket |
|
1330 | + ? 'TKTNAME' |
|
1331 | + : $ticket->get('TKT_name'), |
|
1332 | + 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1333 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1334 | + : ' tkt-status-' . $ticket->ticket_status(), |
|
1335 | + ); |
|
1336 | + //filter template args |
|
1337 | + $template_args = apply_filters( |
|
1338 | + 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1339 | + $template_args, |
|
1340 | + $datetime_row, |
|
1341 | + $ticket_row, |
|
1342 | + $datetime, |
|
1343 | + $ticket, |
|
1344 | + $datetime_tickets, |
|
1345 | + $default, |
|
1346 | + $this->_is_creating_event |
|
1347 | + ); |
|
1348 | + return EEH_Template::display_template( |
|
1349 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1350 | + $template_args, |
|
1351 | + true |
|
1352 | + ); |
|
1353 | + } |
|
1354 | + |
|
1355 | + |
|
1356 | + |
|
1357 | + /** |
|
1358 | + * This generates the ticket row for tickets. |
|
1359 | + * This same method is used to generate both the actual rows and the js skeleton row |
|
1360 | + * (when default === true) |
|
1361 | + * |
|
1362 | + * @param int $ticket_row Represents the row number being generated. |
|
1363 | + * @param $ticket |
|
1364 | + * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1365 | + * or empty for default |
|
1366 | + * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1367 | + * @param bool $default Whether default row being generated or not. |
|
1368 | + * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1369 | + * (or empty in the case of defaults) |
|
1370 | + * @return mixed |
|
1371 | + * @throws DomainException |
|
1372 | + * @throws EE_Error |
|
1373 | + */ |
|
1374 | + protected function _get_ticket_row( |
|
1375 | + $ticket_row, |
|
1376 | + $ticket, |
|
1377 | + $ticket_datetimes, |
|
1378 | + $all_datetimes, |
|
1379 | + $default = false, |
|
1380 | + $all_tickets = array() |
|
1381 | + ) { |
|
1382 | + // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1383 | + $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1384 | + $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
1385 | + array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
1386 | + // if there is only one price (which would be the base price) |
|
1387 | + // or NO prices and this ticket is a default ticket, |
|
1388 | + // let's just make sure there are no cached default prices on the object. |
|
1389 | + // This is done by not including any query_params. |
|
1390 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1391 | + $prices = $ticket->get_many_related('Price'); |
|
1392 | + } |
|
1393 | + // check if we're dealing with a default ticket in which case |
|
1394 | + // we don't want any starting_ticket_datetime_row values set |
|
1395 | + // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1396 | + // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1397 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')); |
|
1398 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1399 | + ? $ticket_datetimes[$ticket->ID()] |
|
1400 | + : array(); |
|
1401 | + $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1402 | + $base_price = $default ? null : $ticket->base_price(); |
|
1403 | + $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1404 | + //breaking out complicated condition for ticket_status |
|
1405 | + if ($default) { |
|
1406 | + $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1407 | + } else { |
|
1408 | + $ticket_status_class = $ticket->is_default() |
|
1409 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1410 | + : ' tkt-status-' . $ticket->ticket_status(); |
|
1411 | + } |
|
1412 | + //breaking out complicated condition for TKT_taxable |
|
1413 | + if ($default) { |
|
1414 | + $TKT_taxable = ''; |
|
1415 | + } else { |
|
1416 | + $TKT_taxable = $ticket->get('TKT_taxable') |
|
1417 | + ? ' checked="checked"' |
|
1418 | + : ''; |
|
1419 | + } |
|
1420 | + if ($default) { |
|
1421 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1422 | + } else if ($ticket->is_default()) { |
|
1423 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1424 | + } else { |
|
1425 | + $TKT_status = $ticket->ticket_status(true); |
|
1426 | + } |
|
1427 | + if ($default) { |
|
1428 | + $TKT_min = ''; |
|
1429 | + } else { |
|
1430 | + $TKT_min = $ticket->get('TKT_min'); |
|
1431 | + if ($TKT_min === -1 || $TKT_min === 0) { |
|
1432 | + $TKT_min = ''; |
|
1433 | + } |
|
1434 | + } |
|
1435 | + $template_args = array( |
|
1436 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1437 | + 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1438 | + //on initial page load this will always be the correct order. |
|
1439 | + 'tkt_status_class' => $ticket_status_class, |
|
1440 | + 'display_edit_tkt_row' => ' style="display:none;"', |
|
1441 | + 'edit_tkt_expanded' => '', |
|
1442 | + 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1443 | + 'TKT_name' => $default ? '' : $ticket->get('TKT_name'), |
|
1444 | + 'TKT_start_date' => $default |
|
1445 | + ? '' |
|
1446 | + : $ticket->get_date('TKT_start_date', |
|
1447 | + $this->_date_time_format), |
|
1448 | + 'TKT_end_date' => $default |
|
1449 | + ? '' |
|
1450 | + : $ticket->get_date('TKT_end_date', |
|
1451 | + $this->_date_time_format), |
|
1452 | + 'TKT_status' => $TKT_status, |
|
1453 | + 'TKT_price' => $default |
|
1454 | + ? '' |
|
1455 | + : EEH_Template::format_currency( |
|
1456 | + $ticket->get_ticket_total_with_taxes(), |
|
1457 | + false, |
|
1458 | + false |
|
1459 | + ), |
|
1460 | + 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1461 | + 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1462 | + 'TKT_qty' => $default |
|
1463 | + ? '' |
|
1464 | + : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1465 | + 'TKT_qty_for_input' => $default |
|
1466 | + ? '' |
|
1467 | + : $ticket->get_pretty('TKT_qty', 'input'), |
|
1468 | + 'TKT_uses' => $default |
|
1469 | + ? '' |
|
1470 | + : $ticket->get_pretty('TKT_uses', 'input'), |
|
1471 | + 'TKT_min' => $TKT_min, |
|
1472 | + 'TKT_max' => $default |
|
1473 | + ? '' |
|
1474 | + : $ticket->get_pretty('TKT_max', 'input'), |
|
1475 | + 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1476 | + 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1477 | + 'TKT_registrations' => $default |
|
1478 | + ? 0 |
|
1479 | + : $ticket->count_registrations( |
|
1480 | + array( |
|
1481 | + array( |
|
1482 | + 'STS_ID' => array( |
|
1483 | + '!=', |
|
1484 | + EEM_Registration::status_id_incomplete, |
|
1485 | + ), |
|
1486 | + ), |
|
1487 | + ) |
|
1488 | + ), |
|
1489 | + 'TKT_ID' => $default ? 0 : $ticket->get('TKT_ID'), |
|
1490 | + 'TKT_description' => $default ? '' : $ticket->get('TKT_description'), |
|
1491 | + 'TKT_is_default' => $default ? 0 : $ticket->get('TKT_is_default'), |
|
1492 | + 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1493 | + 'TKT_is_default_selector' => '', |
|
1494 | + 'ticket_price_rows' => '', |
|
1495 | + 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1496 | + ? '' |
|
1497 | + : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1498 | + 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1499 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1500 | + ? '' |
|
1501 | + : ' style="display:none;"', |
|
1502 | + 'show_price_mod_button' => count($prices) > 1 |
|
1503 | + || ($default && $count_price_mods > 0) |
|
1504 | + || (! $default && $ticket->get('TKT_deleted')) |
|
1505 | + ? ' style="display:none;"' |
|
1506 | + : '', |
|
1507 | + 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1508 | + 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1509 | + 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1510 | + 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1511 | + 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1512 | + 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1513 | + 'TKT_taxable' => $TKT_taxable, |
|
1514 | + 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') |
|
1515 | + ? '' |
|
1516 | + : ' style="display:none"', |
|
1517 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1518 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1519 | + $ticket_subtotal, |
|
1520 | + false, |
|
1521 | + false |
|
1522 | + ), |
|
1523 | + 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1524 | + 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1525 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted'), |
|
1526 | + 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1527 | + ? ' ticket-archived' |
|
1528 | + : '', |
|
1529 | + 'trash_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1530 | + ? 'ee-lock-icon ' |
|
1531 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1532 | + 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1533 | + ? '' |
|
1534 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1535 | + ); |
|
1536 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1537 | + ? ' style="display:none"' |
|
1538 | + : ''; |
|
1539 | + //handle rows that should NOT be empty |
|
1540 | + if (empty($template_args['TKT_start_date'])) { |
|
1541 | + //if empty then the start date will be now. |
|
1542 | + $template_args['TKT_start_date'] = date($this->_date_time_format, |
|
1543 | + current_time('timestamp')); |
|
1544 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1545 | + } |
|
1546 | + if (empty($template_args['TKT_end_date'])) { |
|
1547 | + //get the earliest datetime (if present); |
|
1548 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1549 | + ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1550 | + 'Datetime', |
|
1551 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1552 | + ) |
|
1553 | + : null; |
|
1554 | + if (! empty($earliest_dtt)) { |
|
1555 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1556 | + 'DTT_EVT_start', |
|
1557 | + $this->_date_time_format |
|
1558 | + ); |
|
1559 | + } else { |
|
1560 | + //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1561 | + $template_args['TKT_end_date'] = date( |
|
1562 | + $this->_date_time_format, |
|
1563 | + mktime(24, 0, 0, date('m'), date('d') + 29, date('Y') |
|
1564 | + ) |
|
1565 | + ); |
|
1566 | + } |
|
1567 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1568 | + } |
|
1569 | + //generate ticket_datetime items |
|
1570 | + if (! $default) { |
|
1571 | + $datetime_row = 1; |
|
1572 | + foreach ($all_datetimes as $datetime) { |
|
1573 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1574 | + $datetime_row, |
|
1575 | + $ticket_row, |
|
1576 | + $datetime, |
|
1577 | + $ticket, |
|
1578 | + $ticket_datetimes, |
|
1579 | + $default |
|
1580 | + ); |
|
1581 | + $datetime_row++; |
|
1582 | + } |
|
1583 | + } |
|
1584 | + $price_row = 1; |
|
1585 | + foreach ($prices as $price) { |
|
1586 | + if (! $price instanceof EE_Price) { |
|
1587 | + continue; |
|
1588 | + } |
|
1589 | + if ($price->is_base_price()) { |
|
1590 | + $price_row++; |
|
1591 | + continue; |
|
1592 | + } |
|
1593 | + $show_trash = !((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1594 | + $show_create = !(count($prices) > 1 && count($prices) !== $price_row); |
|
1595 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1596 | + $ticket_row, |
|
1597 | + $price_row, |
|
1598 | + $price, |
|
1599 | + $default, |
|
1600 | + $ticket, |
|
1601 | + $show_trash, |
|
1602 | + $show_create |
|
1603 | + ); |
|
1604 | + $price_row++; |
|
1605 | + } |
|
1606 | + //filter $template_args |
|
1607 | + $template_args = apply_filters( |
|
1608 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1609 | + $template_args, |
|
1610 | + $ticket_row, |
|
1611 | + $ticket, |
|
1612 | + $ticket_datetimes, |
|
1613 | + $all_datetimes, |
|
1614 | + $default, |
|
1615 | + $all_tickets, |
|
1616 | + $this->_is_creating_event |
|
1617 | + ); |
|
1618 | + return EEH_Template::display_template( |
|
1619 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1620 | + $template_args, |
|
1621 | + true |
|
1622 | + ); |
|
1623 | + } |
|
1624 | + |
|
1625 | + |
|
1626 | + |
|
1627 | + /** |
|
1628 | + * @param int $ticket_row |
|
1629 | + * @param EE_Ticket|null $ticket |
|
1630 | + * @return string |
|
1631 | + * @throws DomainException |
|
1632 | + * @throws EE_Error |
|
1633 | + */ |
|
1634 | + protected function _get_tax_rows($ticket_row, $ticket) |
|
1635 | + { |
|
1636 | + $tax_rows = ''; |
|
1637 | + /** @var EE_Price[] $taxes */ |
|
1638 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1639 | + foreach ($taxes as $tax) { |
|
1640 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1641 | + $template_args = array( |
|
1642 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1643 | + ? '' |
|
1644 | + : ' style="display:none;"', |
|
1645 | + 'tax_id' => $tax->ID(), |
|
1646 | + 'tkt_row' => $ticket_row, |
|
1647 | + 'tax_label' => $tax->get('PRC_name'), |
|
1648 | + 'tax_added' => $tax_added, |
|
1649 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1650 | + 'tax_amount' => $tax->get('PRC_amount'), |
|
1651 | + ); |
|
1652 | + $template_args = apply_filters( |
|
1653 | + 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1654 | + $template_args, |
|
1655 | + $ticket_row, |
|
1656 | + $ticket, |
|
1657 | + $this->_is_creating_event |
|
1658 | + ); |
|
1659 | + $tax_rows .= EEH_Template::display_template( |
|
1660 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1661 | + $template_args, |
|
1662 | + true |
|
1663 | + ); |
|
1664 | + } |
|
1665 | + return $tax_rows; |
|
1666 | + } |
|
1667 | + |
|
1668 | + |
|
1669 | + |
|
1670 | + /** |
|
1671 | + * @param EE_Price $tax |
|
1672 | + * @param EE_Ticket|null $ticket |
|
1673 | + * @return float|int |
|
1674 | + * @throws EE_Error |
|
1675 | + */ |
|
1676 | + protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1677 | + { |
|
1678 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1679 | + return $subtotal * $tax->get('PRC_amount') / 100; |
|
1680 | + } |
|
1681 | + |
|
1682 | + |
|
1683 | + |
|
1684 | + /** |
|
1685 | + * @param int $ticket_row |
|
1686 | + * @param int $price_row |
|
1687 | + * @param EE_Price|null $price |
|
1688 | + * @param bool $default |
|
1689 | + * @param EE_Ticket|null $ticket |
|
1690 | + * @param bool $show_trash |
|
1691 | + * @param bool $show_create |
|
1692 | + * @return mixed |
|
1693 | + * @throws DomainException |
|
1694 | + * @throws EE_Error |
|
1695 | + */ |
|
1696 | + protected function _get_ticket_price_row( |
|
1697 | + $ticket_row, |
|
1698 | + $price_row, |
|
1699 | + $price, |
|
1700 | + $default, |
|
1701 | + $ticket, |
|
1702 | + $show_trash = true, |
|
1703 | + $show_create = true |
|
1704 | + ) { |
|
1705 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
1706 | + $template_args = array( |
|
1707 | + 'tkt_row' => $default && empty($ticket) |
|
1708 | + ? 'TICKETNUM' |
|
1709 | + : $ticket_row, |
|
1710 | + 'PRC_order' => $default && empty($price) |
|
1711 | + ? 'PRICENUM' |
|
1712 | + : $price_row, |
|
1713 | + 'edit_prices_name' => $default && empty($price) |
|
1714 | + ? 'PRICENAMEATTR' |
|
1715 | + : 'edit_prices', |
|
1716 | + 'price_type_selector' => $default && empty($price) |
|
1717 | + ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1718 | + : $this->_get_price_type_selector($ticket_row, $price_row, $price, $default, $send_disabled), |
|
1719 | + 'PRC_ID' => $default && empty($price) |
|
1720 | + ? 0 |
|
1721 | + : $price->ID(), |
|
1722 | + 'PRC_is_default' => $default && empty($price) |
|
1723 | + ? 0 |
|
1724 | + : $price->get('PRC_is_default'), |
|
1725 | + 'PRC_name' => $default && empty($price) |
|
1726 | + ? '' |
|
1727 | + : $price->get('PRC_name'), |
|
1728 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1729 | + 'show_plus_or_minus' => $default && empty($price) |
|
1730 | + ? '' |
|
1731 | + : ' style="display:none;"', |
|
1732 | + 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1733 | + ? ' style="display:none;"' |
|
1734 | + : '', |
|
1735 | + 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1736 | + ? ' style="display:none;"' |
|
1737 | + : '', |
|
1738 | + 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1739 | + ? ' style="display:none"' |
|
1740 | + : '', |
|
1741 | + 'PRC_amount' => $default && empty($price) |
|
1742 | + ? 0 |
|
1743 | + : $price->get_pretty('PRC_amount', |
|
1744 | + 'localized_float'), |
|
1745 | + 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1746 | + ? ' style="display:none;"' |
|
1747 | + : '', |
|
1748 | + 'show_trash_icon' => $show_trash |
|
1749 | + ? '' |
|
1750 | + : ' style="display:none;"', |
|
1751 | + 'show_create_button' => $show_create |
|
1752 | + ? '' |
|
1753 | + : ' style="display:none;"', |
|
1754 | + 'PRC_desc' => $default && empty($price) |
|
1755 | + ? '' |
|
1756 | + : $price->get('PRC_desc'), |
|
1757 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
1758 | + ); |
|
1759 | + $template_args = apply_filters( |
|
1760 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1761 | + $template_args, |
|
1762 | + $ticket_row, |
|
1763 | + $price_row, |
|
1764 | + $price, |
|
1765 | + $default, |
|
1766 | + $ticket, |
|
1767 | + $show_trash, |
|
1768 | + $show_create, |
|
1769 | + $this->_is_creating_event |
|
1770 | + ); |
|
1771 | + return EEH_Template::display_template( |
|
1772 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1773 | + $template_args, |
|
1774 | + true |
|
1775 | + ); |
|
1776 | + } |
|
1777 | + |
|
1778 | + |
|
1779 | + |
|
1780 | + /** |
|
1781 | + * @param int $ticket_row |
|
1782 | + * @param int $price_row |
|
1783 | + * @param EE_Price $price |
|
1784 | + * @param bool $default |
|
1785 | + * @param bool $disabled |
|
1786 | + * @return mixed |
|
1787 | + * @throws DomainException |
|
1788 | + * @throws EE_Error |
|
1789 | + */ |
|
1790 | + protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1791 | + { |
|
1792 | + if ($price->is_base_price()) { |
|
1793 | + return $this->_get_base_price_template($ticket_row, $price_row, $price, $default); |
|
1794 | + } |
|
1795 | + return $this->_get_price_modifier_template($ticket_row, $price_row, $price, $default, $disabled); |
|
1796 | + } |
|
1797 | + |
|
1798 | + |
|
1799 | + |
|
1800 | + /** |
|
1801 | + * @param int $ticket_row |
|
1802 | + * @param int $price_row |
|
1803 | + * @param EE_Price $price |
|
1804 | + * @param bool $default |
|
1805 | + * @return mixed |
|
1806 | + * @throws DomainException |
|
1807 | + * @throws EE_Error |
|
1808 | + */ |
|
1809 | + protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1810 | + { |
|
1811 | + $template_args = array( |
|
1812 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1813 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1814 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1815 | + 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1816 | + 'price_selected_operator' => '+', |
|
1817 | + 'price_selected_is_percent' => 0, |
|
1818 | + ); |
|
1819 | + $template_args = apply_filters( |
|
1820 | + 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1821 | + $template_args, |
|
1822 | + $ticket_row, |
|
1823 | + $price_row, |
|
1824 | + $price, |
|
1825 | + $default, |
|
1826 | + $this->_is_creating_event |
|
1827 | + ); |
|
1828 | + return EEH_Template::display_template( |
|
1829 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1830 | + $template_args, |
|
1831 | + true |
|
1832 | + ); |
|
1833 | + } |
|
1834 | + |
|
1835 | + |
|
1836 | + |
|
1837 | + /** |
|
1838 | + * @param int $ticket_row |
|
1839 | + * @param int $price_row |
|
1840 | + * @param EE_Price $price |
|
1841 | + * @param bool $default |
|
1842 | + * @param bool $disabled |
|
1843 | + * @return mixed |
|
1844 | + * @throws DomainException |
|
1845 | + * @throws EE_Error |
|
1846 | + */ |
|
1847 | + protected function _get_price_modifier_template( |
|
1848 | + $ticket_row, |
|
1849 | + $price_row, |
|
1850 | + $price, |
|
1851 | + $default, |
|
1852 | + $disabled = false |
|
1853 | + ) { |
|
1854 | + $select_name = $default && ! $price instanceof EE_Price |
|
1855 | + ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1856 | + : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1857 | + /** @var EEM_Price_Type $price_type_model */ |
|
1858 | + $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1859 | + $price_types = $price_type_model->get_all(array( |
|
1860 | + array( |
|
1861 | + 'OR' => array( |
|
1862 | + 'PBT_ID' => '2', |
|
1863 | + 'PBT_ID*' => '3', |
|
1864 | + ), |
|
1865 | + ), |
|
1866 | + )); |
|
1867 | + $all_price_types = $default && ! $price instanceof EE_Price |
|
1868 | + ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
1869 | + : array(); |
|
1870 | + $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1871 | + $price_option_spans = ''; |
|
1872 | + //setup price types for selector |
|
1873 | + foreach ($price_types as $price_type) { |
|
1874 | + if (! $price_type instanceof EE_Price_Type) { |
|
1875 | + continue; |
|
1876 | + } |
|
1877 | + $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
|
1878 | + //while we're in the loop let's setup the option spans used by js |
|
1879 | + $span_args = array( |
|
1880 | + 'PRT_ID' => $price_type->ID(), |
|
1881 | + 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1882 | + 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1883 | + ); |
|
1884 | + $price_option_spans .= EEH_Template::display_template( |
|
1885 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1886 | + $span_args, |
|
1887 | + true |
|
1888 | + ); |
|
1889 | + } |
|
1890 | + $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
1891 | + $select_input = new EE_Select_Input( |
|
1892 | + $all_price_types, |
|
1893 | + array( |
|
1894 | + 'default' => $selected_price_type_id, |
|
1895 | + 'html_name' => $select_name, |
|
1896 | + 'html_class' => 'edit-price-PRT_ID', |
|
1897 | + 'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1898 | + ) |
|
1899 | + ); |
|
1900 | + $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1901 | + $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1902 | + $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1903 | + $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1904 | + $template_args = array( |
|
1905 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1906 | + 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1907 | + 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1908 | + 'main_name' => $select_name, |
|
1909 | + 'selected_price_type_id' => $selected_price_type_id, |
|
1910 | + 'price_option_spans' => $price_option_spans, |
|
1911 | + 'price_selected_operator' => $price_selected_operator, |
|
1912 | + 'price_selected_is_percent' => $price_selected_is_percent, |
|
1913 | + 'disabled' => $disabled, |
|
1914 | + ); |
|
1915 | + $template_args = apply_filters( |
|
1916 | + 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
1917 | + $template_args, |
|
1918 | + $ticket_row, |
|
1919 | + $price_row, |
|
1920 | + $price, |
|
1921 | + $default, |
|
1922 | + $disabled, |
|
1923 | + $this->_is_creating_event |
|
1924 | + ); |
|
1925 | + return EEH_Template::display_template( |
|
1926 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
1927 | + $template_args, |
|
1928 | + true |
|
1929 | + ); |
|
1930 | + } |
|
1931 | + |
|
1932 | + |
|
1933 | + |
|
1934 | + /** |
|
1935 | + * @param int $datetime_row |
|
1936 | + * @param int $ticket_row |
|
1937 | + * @param EE_Datetime|null $datetime |
|
1938 | + * @param EE_Ticket|null $ticket |
|
1939 | + * @param array $ticket_datetimes |
|
1940 | + * @param bool $default |
|
1941 | + * @return mixed |
|
1942 | + * @throws DomainException |
|
1943 | + * @throws EE_Error |
|
1944 | + */ |
|
1945 | + protected function _get_ticket_datetime_list_item( |
|
1946 | + $datetime_row, |
|
1947 | + $ticket_row, |
|
1948 | + $datetime, |
|
1949 | + $ticket, |
|
1950 | + $ticket_datetimes = array(), |
|
1951 | + $default |
|
1952 | + ) { |
|
1953 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1954 | + ? $ticket_datetimes[$ticket->ID()] |
|
1955 | + : array(); |
|
1956 | + $template_args = array( |
|
1957 | + 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
1958 | + ? 'DTTNUM' |
|
1959 | + : $datetime_row, |
|
1960 | + 'tkt_row' => $default |
|
1961 | + ? 'TICKETNUM' |
|
1962 | + : $ticket_row, |
|
1963 | + 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
1964 | + ? ' ticket-selected' |
|
1965 | + : '', |
|
1966 | + 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
1967 | + ? ' checked="checked"' |
|
1968 | + : '', |
|
1969 | + 'DTT_name' => $default && empty($datetime) |
|
1970 | + ? 'DTTNAME' |
|
1971 | + : $datetime->get_dtt_display_name(true), |
|
1972 | + 'tkt_status_class' => '', |
|
1973 | + ); |
|
1974 | + $template_args = apply_filters( |
|
1975 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
1976 | + $template_args, |
|
1977 | + $datetime_row, |
|
1978 | + $ticket_row, |
|
1979 | + $datetime, |
|
1980 | + $ticket, |
|
1981 | + $ticket_datetimes, |
|
1982 | + $default, |
|
1983 | + $this->_is_creating_event |
|
1984 | + ); |
|
1985 | + return EEH_Template::display_template( |
|
1986 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1987 | + $template_args, |
|
1988 | + true |
|
1989 | + ); |
|
1990 | + } |
|
1991 | + |
|
1992 | + |
|
1993 | + |
|
1994 | + /** |
|
1995 | + * @param array $all_datetimes |
|
1996 | + * @param array $all_tickets |
|
1997 | + * @return mixed |
|
1998 | + * @throws DomainException |
|
1999 | + * @throws EE_Error |
|
2000 | + */ |
|
2001 | + protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
2002 | + { |
|
2003 | + $template_args = array( |
|
2004 | + 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
2005 | + 'DTTNUM', |
|
2006 | + null, |
|
2007 | + true, |
|
2008 | + $all_datetimes |
|
2009 | + ), |
|
2010 | + 'default_ticket_row' => $this->_get_ticket_row( |
|
2011 | + 'TICKETNUM', |
|
2012 | + null, |
|
2013 | + array(), |
|
2014 | + array(), |
|
2015 | + true |
|
2016 | + ), |
|
2017 | + 'default_price_row' => $this->_get_ticket_price_row( |
|
2018 | + 'TICKETNUM', |
|
2019 | + 'PRICENUM', |
|
2020 | + null, |
|
2021 | + true, |
|
2022 | + null |
|
2023 | + ), |
|
2024 | + 'default_price_rows' => '', |
|
2025 | + 'default_base_price_amount' => 0, |
|
2026 | + 'default_base_price_name' => '', |
|
2027 | + 'default_base_price_description' => '', |
|
2028 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2029 | + 'TICKETNUM', |
|
2030 | + 'PRICENUM', |
|
2031 | + null, |
|
2032 | + true |
|
2033 | + ), |
|
2034 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2035 | + 'DTTNUM', |
|
2036 | + null, |
|
2037 | + array(), |
|
2038 | + array(), |
|
2039 | + true |
|
2040 | + ), |
|
2041 | + 'existing_available_datetime_tickets_list' => '', |
|
2042 | + 'existing_available_ticket_datetimes_list' => '', |
|
2043 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2044 | + 'DTTNUM', |
|
2045 | + 'TICKETNUM', |
|
2046 | + null, |
|
2047 | + null, |
|
2048 | + array(), |
|
2049 | + true |
|
2050 | + ), |
|
2051 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2052 | + 'DTTNUM', |
|
2053 | + 'TICKETNUM', |
|
2054 | + null, |
|
2055 | + null, |
|
2056 | + array(), |
|
2057 | + true |
|
2058 | + ), |
|
2059 | + ); |
|
2060 | + $ticket_row = 1; |
|
2061 | + foreach ($all_tickets as $ticket) { |
|
2062 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2063 | + 'DTTNUM', |
|
2064 | + $ticket_row, |
|
2065 | + null, |
|
2066 | + $ticket, |
|
2067 | + array(), |
|
2068 | + true |
|
2069 | + ); |
|
2070 | + $ticket_row++; |
|
2071 | + } |
|
2072 | + $datetime_row = 1; |
|
2073 | + foreach ($all_datetimes as $datetime) { |
|
2074 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2075 | + $datetime_row, |
|
2076 | + 'TICKETNUM', |
|
2077 | + $datetime, |
|
2078 | + null, |
|
2079 | + array(), |
|
2080 | + true |
|
2081 | + ); |
|
2082 | + $datetime_row++; |
|
2083 | + } |
|
2084 | + /** @var EEM_Price $price_model */ |
|
2085 | + $price_model = EE_Registry::instance()->load_model('Price'); |
|
2086 | + $default_prices = $price_model->get_all_default_prices(); |
|
2087 | + $price_row = 1; |
|
2088 | + foreach ($default_prices as $price) { |
|
2089 | + if (! $price instanceof EE_Price) { |
|
2090 | + continue; |
|
2091 | + } |
|
2092 | + if ($price->is_base_price()) { |
|
2093 | + $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2094 | + 'PRC_amount', |
|
2095 | + 'localized_float' |
|
2096 | + ); |
|
2097 | + $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2098 | + $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2099 | + $price_row++; |
|
2100 | + continue; |
|
2101 | + } |
|
2102 | + $show_trash = !((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
2103 | + $show_create = !(count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
2104 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2105 | + 'TICKETNUM', |
|
2106 | + $price_row, |
|
2107 | + $price, |
|
2108 | + true, |
|
2109 | + null, |
|
2110 | + $show_trash, |
|
2111 | + $show_create |
|
2112 | + ); |
|
2113 | + $price_row++; |
|
2114 | + } |
|
2115 | + $template_args = apply_filters( |
|
2116 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2117 | + $template_args, |
|
2118 | + $all_datetimes, |
|
2119 | + $all_tickets, |
|
2120 | + $this->_is_creating_event |
|
2121 | + ); |
|
2122 | + return EEH_Template::display_template( |
|
2123 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2124 | + $template_args, |
|
2125 | + true |
|
2126 | + ); |
|
2127 | + } |
|
2128 | 2128 | |
2129 | 2129 | |
2130 | 2130 | } //end class espresso_events_Pricing_Hooks |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
128 | 128 | ? $this->_date_format_strings['time'] |
129 | 129 | : null; |
130 | - $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
130 | + $this->_date_time_format = $this->_date_format_strings['date'].' '.$this->_date_format_strings['time']; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | ); |
153 | 153 | $msg .= '</p><ul>'; |
154 | 154 | foreach ($format_validation as $error) { |
155 | - $msg .= '<li>' . $error . '</li>'; |
|
155 | + $msg .= '<li>'.$error.'</li>'; |
|
156 | 156 | } |
157 | 157 | $msg .= '</ul><p>'; |
158 | 158 | $msg .= sprintf( |
@@ -182,11 +182,11 @@ discard block |
||
182 | 182 | $this->_scripts_styles = array( |
183 | 183 | 'registers' => array( |
184 | 184 | 'ee-tickets-datetimes-css' => array( |
185 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
185 | + 'url' => PRICING_ASSETS_URL.'event-tickets-datetimes.css', |
|
186 | 186 | 'type' => 'css', |
187 | 187 | ), |
188 | 188 | 'ee-dtt-ticket-metabox' => array( |
189 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
189 | + 'url' => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js', |
|
190 | 190 | 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
191 | 191 | ), |
192 | 192 | ), |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | 'event_espresso' |
211 | 211 | ), |
212 | 212 | 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
213 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
213 | + . esc_html__('Cancel', 'event_espresso').'</button>', |
|
214 | 214 | 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
215 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
215 | + . esc_html__('Close', 'event_espresso').'</button>', |
|
216 | 216 | 'single_warning_from_tkt' => esc_html__( |
217 | 217 | 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
218 | 218 | 'event_espresso' |
@@ -222,12 +222,12 @@ discard block |
||
222 | 222 | 'event_espresso' |
223 | 223 | ), |
224 | 224 | 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
225 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
225 | + . esc_html__('Dismiss', 'event_espresso').'</button>', |
|
226 | 226 | ), |
227 | 227 | 'DTT_ERROR_MSG' => array( |
228 | 228 | 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
229 | 229 | 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
230 | - . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
230 | + . esc_html__('Dismiss', 'event_espresso').'</button></div>', |
|
231 | 231 | ), |
232 | 232 | 'DTT_OVERSELL_WARNING' => array( |
233 | 233 | 'datetime_ticket' => esc_html__( |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $this->_date_format_strings['date'], |
244 | 244 | $this->_date_format_strings['time'] |
245 | 245 | ), |
246 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
246 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
247 | 247 | ), |
248 | 248 | ), |
249 | 249 | ); |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
299 | 299 | $saved_dtt_ids = array(); |
300 | 300 | $saved_dtt_objs = array(); |
301 | - if (empty($data['edit_event_datetimes']) || !is_array($data['edit_event_datetimes'])) { |
|
301 | + if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) { |
|
302 | 302 | throw new InvalidArgumentException( |
303 | 303 | esc_html__( |
304 | 304 | 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
310 | 310 | //trim all values to ensure any excess whitespace is removed. |
311 | 311 | $datetime_data = array_map( |
312 | - function ($datetime_data) { |
|
312 | + function($datetime_data) { |
|
313 | 313 | return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
314 | 314 | }, |
315 | 315 | $datetime_data |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | ); |
340 | 340 | // if we have an id then let's get existing object first and then set the new values. |
341 | 341 | // Otherwise we instantiate a new object for save. |
342 | - if (! empty($datetime_data['DTT_ID'])) { |
|
342 | + if ( ! empty($datetime_data['DTT_ID'])) { |
|
343 | 343 | $datetime = EE_Registry::instance() |
344 | 344 | ->load_model('Datetime', array($timezone)) |
345 | 345 | ->get_one_by_ID($datetime_data['DTT_ID']); |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
433 | 433 | $saved_tickets = $datetimes_on_existing = array(); |
434 | 434 | $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
435 | - if(empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])){ |
|
435 | + if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
436 | 436 | throw new InvalidArgumentException( |
437 | 437 | esc_html__( |
438 | 438 | 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
451 | 451 | // trim inputs to ensure any excess whitespace is removed. |
452 | 452 | $tkt = array_map( |
453 | - function ($ticket_data) { |
|
453 | + function($ticket_data) { |
|
454 | 454 | return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
455 | 455 | }, |
456 | 456 | $tkt |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | // because we're doing calculations prior to using the models. |
460 | 460 | // note incoming ['TKT_price'] value is already in standard notation (via js). |
461 | 461 | $ticket_price = isset($tkt['TKT_price']) |
462 | - ? round((float)$tkt['TKT_price'], 3) |
|
462 | + ? round((float) $tkt['TKT_price'], 3) |
|
463 | 463 | : 0; |
464 | 464 | //note incoming base price needs converted from localized value. |
465 | 465 | $base_price = isset($tkt['TKT_base_price']) |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | //need to make sue that the TKT_price is accurate after saving the prices. |
607 | 607 | $ticket->ensure_TKT_Price_correct(); |
608 | 608 | //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
609 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
609 | + if ( ! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
610 | 610 | $update_prices = true; |
611 | 611 | $new_default = clone $ticket; |
612 | 612 | $new_default->set('TKT_ID', 0); |
@@ -725,9 +725,9 @@ discard block |
||
725 | 725 | // to start we have to add the ticket to all the datetimes its supposed to be with, |
726 | 726 | // and removing the ticket from datetimes it got removed from. |
727 | 727 | // first let's add datetimes |
728 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
728 | + if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
|
729 | 729 | foreach ($added_datetimes as $row_id) { |
730 | - $row_id = (int)$row_id; |
|
730 | + $row_id = (int) $row_id; |
|
731 | 731 | if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
732 | 732 | $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
733 | 733 | // Is this an existing ticket (has an ID) and does it have any sold? |
@@ -740,9 +740,9 @@ discard block |
||
740 | 740 | } |
741 | 741 | } |
742 | 742 | // then remove datetimes |
743 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
743 | + if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
744 | 744 | foreach ($removed_datetimes as $row_id) { |
745 | - $row_id = (int)$row_id; |
|
745 | + $row_id = (int) $row_id; |
|
746 | 746 | // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
747 | 747 | // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
748 | 748 | if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
@@ -852,7 +852,7 @@ discard block |
||
852 | 852 | ); |
853 | 853 | } |
854 | 854 | //possibly need to save tkt |
855 | - if (! $ticket->ID()) { |
|
855 | + if ( ! $ticket->ID()) { |
|
856 | 856 | $ticket->save(); |
857 | 857 | } |
858 | 858 | foreach ($prices as $row => $prc) { |
@@ -890,11 +890,11 @@ discard block |
||
890 | 890 | $ticket->_add_relation_to($price, 'Price'); |
891 | 891 | } |
892 | 892 | //now let's remove any prices that got removed from the ticket |
893 | - if (! empty ($current_prices_on_ticket)) { |
|
893 | + if ( ! empty ($current_prices_on_ticket)) { |
|
894 | 894 | $current = array_keys($current_prices_on_ticket); |
895 | 895 | $updated = array_keys($updated_prices); |
896 | 896 | $prices_to_remove = array_diff($current, $updated); |
897 | - if (! empty($prices_to_remove)) { |
|
897 | + if ( ! empty($prices_to_remove)) { |
|
898 | 898 | foreach ($prices_to_remove as $prc_id) { |
899 | 899 | $p = $current_prices_on_ticket[$prc_id]; |
900 | 900 | $ticket->_remove_relation_to($p, 'Price'); |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | * @param Events_Admin_Page $event_admin_obj |
913 | 913 | * @return Events_Admin_Page |
914 | 914 | */ |
915 | - public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
915 | + public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
916 | 916 | { |
917 | 917 | return $event_admin_obj; |
918 | 918 | //doing nothing for the moment. |
@@ -1045,7 +1045,7 @@ discard block |
||
1045 | 1045 | $TKT_ID = $ticket->get('TKT_ID'); |
1046 | 1046 | $ticket_row = $ticket->get('TKT_row'); |
1047 | 1047 | //we only want unique tickets in our final display!! |
1048 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1048 | + if ( ! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1049 | 1049 | $existing_ticket_ids[] = $TKT_ID; |
1050 | 1050 | $all_tickets[] = $ticket; |
1051 | 1051 | } |
@@ -1067,9 +1067,9 @@ discard block |
||
1067 | 1067 | //sort $all_tickets by order |
1068 | 1068 | usort( |
1069 | 1069 | $all_tickets, |
1070 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
1071 | - $a_order = (int)$a->get('TKT_order'); |
|
1072 | - $b_order = (int)$b->get('TKT_order'); |
|
1070 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
1071 | + $a_order = (int) $a->get('TKT_order'); |
|
1072 | + $b_order = (int) $b->get('TKT_order'); |
|
1073 | 1073 | if ($a_order === $b_order) { |
1074 | 1074 | return 0; |
1075 | 1075 | } |
@@ -1105,7 +1105,7 @@ discard block |
||
1105 | 1105 | } |
1106 | 1106 | $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
1107 | 1107 | EEH_Template::display_template( |
1108 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1108 | + PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php', |
|
1109 | 1109 | $main_template_args |
1110 | 1110 | ); |
1111 | 1111 | } |
@@ -1143,7 +1143,7 @@ discard block |
||
1143 | 1143 | 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
1144 | 1144 | ); |
1145 | 1145 | return EEH_Template::display_template( |
1146 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1146 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php', |
|
1147 | 1147 | $dtt_display_template_args, |
1148 | 1148 | true |
1149 | 1149 | ); |
@@ -1213,7 +1213,7 @@ discard block |
||
1213 | 1213 | $this->_is_creating_event |
1214 | 1214 | ); |
1215 | 1215 | return EEH_Template::display_template( |
1216 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1216 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php', |
|
1217 | 1217 | $template_args, |
1218 | 1218 | true |
1219 | 1219 | ); |
@@ -1255,7 +1255,7 @@ discard block |
||
1255 | 1255 | 'DTT_ID' => $default ? '' : $datetime->ID(), |
1256 | 1256 | ); |
1257 | 1257 | //need to setup the list items (but only if this isn't a default skeleton setup) |
1258 | - if (! $default) { |
|
1258 | + if ( ! $default) { |
|
1259 | 1259 | $ticket_row = 1; |
1260 | 1260 | foreach ($all_tickets as $ticket) { |
1261 | 1261 | $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
@@ -1281,7 +1281,7 @@ discard block |
||
1281 | 1281 | $this->_is_creating_event |
1282 | 1282 | ); |
1283 | 1283 | return EEH_Template::display_template( |
1284 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1284 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php', |
|
1285 | 1285 | $template_args, |
1286 | 1286 | true |
1287 | 1287 | ); |
@@ -1330,8 +1330,8 @@ discard block |
||
1330 | 1330 | ? 'TKTNAME' |
1331 | 1331 | : $ticket->get('TKT_name'), |
1332 | 1332 | 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
1333 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1334 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
1333 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
1334 | + : ' tkt-status-'.$ticket->ticket_status(), |
|
1335 | 1335 | ); |
1336 | 1336 | //filter template args |
1337 | 1337 | $template_args = apply_filters( |
@@ -1346,7 +1346,7 @@ discard block |
||
1346 | 1346 | $this->_is_creating_event |
1347 | 1347 | ); |
1348 | 1348 | return EEH_Template::display_template( |
1349 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1349 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1350 | 1350 | $template_args, |
1351 | 1351 | true |
1352 | 1352 | ); |
@@ -1403,11 +1403,11 @@ discard block |
||
1403 | 1403 | $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
1404 | 1404 | //breaking out complicated condition for ticket_status |
1405 | 1405 | if ($default) { |
1406 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1406 | + $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale; |
|
1407 | 1407 | } else { |
1408 | 1408 | $ticket_status_class = $ticket->is_default() |
1409 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1410 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
1409 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
1410 | + : ' tkt-status-'.$ticket->ticket_status(); |
|
1411 | 1411 | } |
1412 | 1412 | //breaking out complicated condition for TKT_taxable |
1413 | 1413 | if ($default) { |
@@ -1501,7 +1501,7 @@ discard block |
||
1501 | 1501 | : ' style="display:none;"', |
1502 | 1502 | 'show_price_mod_button' => count($prices) > 1 |
1503 | 1503 | || ($default && $count_price_mods > 0) |
1504 | - || (! $default && $ticket->get('TKT_deleted')) |
|
1504 | + || ( ! $default && $ticket->get('TKT_deleted')) |
|
1505 | 1505 | ? ' style="display:none;"' |
1506 | 1506 | : '', |
1507 | 1507 | 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
@@ -1541,7 +1541,7 @@ discard block |
||
1541 | 1541 | //if empty then the start date will be now. |
1542 | 1542 | $template_args['TKT_start_date'] = date($this->_date_time_format, |
1543 | 1543 | current_time('timestamp')); |
1544 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1544 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
1545 | 1545 | } |
1546 | 1546 | if (empty($template_args['TKT_end_date'])) { |
1547 | 1547 | //get the earliest datetime (if present); |
@@ -1551,7 +1551,7 @@ discard block |
||
1551 | 1551 | array('order_by' => array('DTT_EVT_start' => 'ASC')) |
1552 | 1552 | ) |
1553 | 1553 | : null; |
1554 | - if (! empty($earliest_dtt)) { |
|
1554 | + if ( ! empty($earliest_dtt)) { |
|
1555 | 1555 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
1556 | 1556 | 'DTT_EVT_start', |
1557 | 1557 | $this->_date_time_format |
@@ -1564,10 +1564,10 @@ discard block |
||
1564 | 1564 | ) |
1565 | 1565 | ); |
1566 | 1566 | } |
1567 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1567 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
1568 | 1568 | } |
1569 | 1569 | //generate ticket_datetime items |
1570 | - if (! $default) { |
|
1570 | + if ( ! $default) { |
|
1571 | 1571 | $datetime_row = 1; |
1572 | 1572 | foreach ($all_datetimes as $datetime) { |
1573 | 1573 | $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
@@ -1583,15 +1583,15 @@ discard block |
||
1583 | 1583 | } |
1584 | 1584 | $price_row = 1; |
1585 | 1585 | foreach ($prices as $price) { |
1586 | - if (! $price instanceof EE_Price) { |
|
1586 | + if ( ! $price instanceof EE_Price) { |
|
1587 | 1587 | continue; |
1588 | 1588 | } |
1589 | 1589 | if ($price->is_base_price()) { |
1590 | 1590 | $price_row++; |
1591 | 1591 | continue; |
1592 | 1592 | } |
1593 | - $show_trash = !((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1594 | - $show_create = !(count($prices) > 1 && count($prices) !== $price_row); |
|
1593 | + $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1594 | + $show_create = ! (count($prices) > 1 && count($prices) !== $price_row); |
|
1595 | 1595 | $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
1596 | 1596 | $ticket_row, |
1597 | 1597 | $price_row, |
@@ -1616,7 +1616,7 @@ discard block |
||
1616 | 1616 | $this->_is_creating_event |
1617 | 1617 | ); |
1618 | 1618 | return EEH_Template::display_template( |
1619 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1619 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php', |
|
1620 | 1620 | $template_args, |
1621 | 1621 | true |
1622 | 1622 | ); |
@@ -1657,7 +1657,7 @@ discard block |
||
1657 | 1657 | $this->_is_creating_event |
1658 | 1658 | ); |
1659 | 1659 | $tax_rows .= EEH_Template::display_template( |
1660 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1660 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php', |
|
1661 | 1661 | $template_args, |
1662 | 1662 | true |
1663 | 1663 | ); |
@@ -1769,7 +1769,7 @@ discard block |
||
1769 | 1769 | $this->_is_creating_event |
1770 | 1770 | ); |
1771 | 1771 | return EEH_Template::display_template( |
1772 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1772 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php', |
|
1773 | 1773 | $template_args, |
1774 | 1774 | true |
1775 | 1775 | ); |
@@ -1826,7 +1826,7 @@ discard block |
||
1826 | 1826 | $this->_is_creating_event |
1827 | 1827 | ); |
1828 | 1828 | return EEH_Template::display_template( |
1829 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1829 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php', |
|
1830 | 1830 | $template_args, |
1831 | 1831 | true |
1832 | 1832 | ); |
@@ -1853,7 +1853,7 @@ discard block |
||
1853 | 1853 | ) { |
1854 | 1854 | $select_name = $default && ! $price instanceof EE_Price |
1855 | 1855 | ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
1856 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1856 | + : 'edit_prices['.$ticket_row.']['.$price_row.'][PRT_ID]'; |
|
1857 | 1857 | /** @var EEM_Price_Type $price_type_model */ |
1858 | 1858 | $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
1859 | 1859 | $price_types = $price_type_model->get_all(array( |
@@ -1871,7 +1871,7 @@ discard block |
||
1871 | 1871 | $price_option_spans = ''; |
1872 | 1872 | //setup price types for selector |
1873 | 1873 | foreach ($price_types as $price_type) { |
1874 | - if (! $price_type instanceof EE_Price_Type) { |
|
1874 | + if ( ! $price_type instanceof EE_Price_Type) { |
|
1875 | 1875 | continue; |
1876 | 1876 | } |
1877 | 1877 | $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
@@ -1882,12 +1882,12 @@ discard block |
||
1882 | 1882 | 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
1883 | 1883 | ); |
1884 | 1884 | $price_option_spans .= EEH_Template::display_template( |
1885 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1885 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php', |
|
1886 | 1886 | $span_args, |
1887 | 1887 | true |
1888 | 1888 | ); |
1889 | 1889 | } |
1890 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
1890 | + $select_name = $disabled ? 'archive_price['.$ticket_row.']['.$price_row.'][PRT_ID]' : $select_name; |
|
1891 | 1891 | $select_input = new EE_Select_Input( |
1892 | 1892 | $all_price_types, |
1893 | 1893 | array( |
@@ -1923,7 +1923,7 @@ discard block |
||
1923 | 1923 | $this->_is_creating_event |
1924 | 1924 | ); |
1925 | 1925 | return EEH_Template::display_template( |
1926 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
1926 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php', |
|
1927 | 1927 | $template_args, |
1928 | 1928 | true |
1929 | 1929 | ); |
@@ -1983,7 +1983,7 @@ discard block |
||
1983 | 1983 | $this->_is_creating_event |
1984 | 1984 | ); |
1985 | 1985 | return EEH_Template::display_template( |
1986 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1986 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1987 | 1987 | $template_args, |
1988 | 1988 | true |
1989 | 1989 | ); |
@@ -2086,7 +2086,7 @@ discard block |
||
2086 | 2086 | $default_prices = $price_model->get_all_default_prices(); |
2087 | 2087 | $price_row = 1; |
2088 | 2088 | foreach ($default_prices as $price) { |
2089 | - if (! $price instanceof EE_Price) { |
|
2089 | + if ( ! $price instanceof EE_Price) { |
|
2090 | 2090 | continue; |
2091 | 2091 | } |
2092 | 2092 | if ($price->is_base_price()) { |
@@ -2099,8 +2099,8 @@ discard block |
||
2099 | 2099 | $price_row++; |
2100 | 2100 | continue; |
2101 | 2101 | } |
2102 | - $show_trash = !((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
2103 | - $show_create = !(count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
2102 | + $show_trash = ! ((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
2103 | + $show_create = ! (count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
2104 | 2104 | $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
2105 | 2105 | 'TICKETNUM', |
2106 | 2106 | $price_row, |
@@ -2120,7 +2120,7 @@ discard block |
||
2120 | 2120 | $this->_is_creating_event |
2121 | 2121 | ); |
2122 | 2122 | return EEH_Template::display_template( |
2123 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2123 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php', |
|
2124 | 2124 | $template_args, |
2125 | 2125 | true |
2126 | 2126 | ); |
@@ -12,328 +12,328 @@ |
||
12 | 12 | class EEM_Ticket extends EEM_Soft_Delete_Base |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * private instance of the EEM_Ticket object |
|
17 | - * |
|
18 | - * @var EEM_Ticket $_instance |
|
19 | - */ |
|
20 | - protected static $_instance; |
|
15 | + /** |
|
16 | + * private instance of the EEM_Ticket object |
|
17 | + * |
|
18 | + * @var EEM_Ticket $_instance |
|
19 | + */ |
|
20 | + protected static $_instance; |
|
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * private constructor to prevent direct creation |
|
26 | - * |
|
27 | - * @Constructor |
|
28 | - * @access private |
|
29 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
30 | - * (and any incoming timezone data that gets saved). |
|
31 | - * Note this just sends the timezone info to the date time model field objects. |
|
32 | - * Default is NULL |
|
33 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
34 | - * @throws EE_Error |
|
35 | - */ |
|
36 | - protected function __construct($timezone) |
|
37 | - { |
|
38 | - $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
39 | - $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
40 | - $this->_tables = array( |
|
41 | - 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
42 | - ); |
|
43 | - $this->_fields = array( |
|
44 | - 'Ticket' => array( |
|
45 | - 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
46 | - 'TKT_ID', |
|
47 | - esc_html__('Ticket ID', 'event_espresso') |
|
48 | - ), |
|
49 | - 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
50 | - 'TTM_ID', |
|
51 | - esc_html__('Ticket Template ID', 'event_espresso'), |
|
52 | - false, |
|
53 | - 0, |
|
54 | - 'Ticket_Template' |
|
55 | - ), |
|
56 | - 'TKT_name' => new EE_Plain_Text_Field( |
|
57 | - 'TKT_name', |
|
58 | - esc_html__('Ticket Name', 'event_espresso'), |
|
59 | - false, |
|
60 | - '' |
|
61 | - ), |
|
62 | - 'TKT_description' => new EE_Post_Content_Field( |
|
63 | - 'TKT_description', |
|
64 | - esc_html__('Description of Ticket', 'event_espresso'), |
|
65 | - false, |
|
66 | - '' |
|
67 | - ), |
|
68 | - 'TKT_start_date' => new EE_Datetime_Field( |
|
69 | - 'TKT_start_date', |
|
70 | - esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
71 | - false, |
|
72 | - EE_Datetime_Field::now, |
|
73 | - $timezone |
|
74 | - ), |
|
75 | - 'TKT_end_date' => new EE_Datetime_Field( |
|
76 | - 'TKT_end_date', |
|
77 | - esc_html__('End time/date of Ticket', 'event_espresso'), |
|
78 | - false, |
|
79 | - EE_Datetime_Field::now, |
|
80 | - $timezone |
|
81 | - ), |
|
82 | - 'TKT_min' => new EE_Integer_Field( |
|
83 | - 'TKT_min', |
|
84 | - esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
85 | - false, |
|
86 | - 0 |
|
87 | - ), |
|
88 | - 'TKT_max' => new EE_Infinite_Integer_Field( |
|
89 | - 'TKT_max', |
|
90 | - esc_html__( |
|
91 | - 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
92 | - 'event_espresso' |
|
93 | - ), |
|
94 | - false, |
|
95 | - EE_INF |
|
96 | - ), |
|
97 | - 'TKT_price' => new EE_Money_Field( |
|
98 | - 'TKT_price', |
|
99 | - esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
100 | - false, |
|
101 | - 0 |
|
102 | - ), |
|
103 | - 'TKT_sold' => new EE_Integer_Field( |
|
104 | - 'TKT_sold', |
|
105 | - esc_html__('Number of this ticket sold', 'event_espresso'), |
|
106 | - false, |
|
107 | - 0 |
|
108 | - ), |
|
109 | - 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
110 | - 'TKT_qty', |
|
111 | - esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
112 | - false, |
|
113 | - EE_INF |
|
114 | - ), |
|
115 | - 'TKT_reserved' => new EE_Integer_Field( |
|
116 | - 'TKT_reserved', |
|
117 | - esc_html__( |
|
118 | - 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
119 | - 'event_espresso' |
|
120 | - ), |
|
121 | - false, |
|
122 | - 0 |
|
123 | - ), |
|
124 | - 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
125 | - 'TKT_uses', |
|
126 | - esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
127 | - false, |
|
128 | - EE_INF |
|
129 | - ), |
|
130 | - 'TKT_required' => new EE_Boolean_Field( |
|
131 | - 'TKT_required', |
|
132 | - esc_html__( |
|
133 | - 'Flag indicating whether this ticket must be purchased with a transaction', |
|
134 | - 'event_espresso' |
|
135 | - ), |
|
136 | - false, |
|
137 | - false |
|
138 | - ), |
|
139 | - 'TKT_taxable' => new EE_Boolean_Field( |
|
140 | - 'TKT_taxable', |
|
141 | - esc_html__( |
|
142 | - 'Flag indicating whether there is tax applied on this ticket', |
|
143 | - 'event_espresso' |
|
144 | - ), |
|
145 | - false, |
|
146 | - false |
|
147 | - ), |
|
148 | - 'TKT_is_default' => new EE_Boolean_Field( |
|
149 | - 'TKT_is_default', |
|
150 | - esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
151 | - false, |
|
152 | - false |
|
153 | - ), |
|
154 | - 'TKT_order' => new EE_Integer_Field( |
|
155 | - 'TKT_order', |
|
156 | - esc_html__( |
|
157 | - 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
158 | - 'event_espresso' |
|
159 | - ), |
|
160 | - false, |
|
161 | - 0 |
|
162 | - ), |
|
163 | - 'TKT_row' => new EE_Integer_Field( |
|
164 | - 'TKT_row', |
|
165 | - esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
166 | - false, |
|
167 | - 0 |
|
168 | - ), |
|
169 | - 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
170 | - 'TKT_deleted', |
|
171 | - esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
172 | - false, |
|
173 | - false |
|
174 | - ), |
|
175 | - 'TKT_wp_user' => new EE_WP_User_Field( |
|
176 | - 'TKT_wp_user', |
|
177 | - esc_html__('Ticket Creator ID', 'event_espresso'), |
|
178 | - false |
|
179 | - ), |
|
180 | - 'TKT_parent' => new EE_Integer_Field( |
|
181 | - 'TKT_parent', |
|
182 | - esc_html__( |
|
183 | - 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
184 | - 'event_espresso' |
|
185 | - ), |
|
186 | - true, |
|
187 | - 0 |
|
188 | - ), |
|
189 | - ), |
|
190 | - ); |
|
191 | - $this->_model_relations = array( |
|
192 | - 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
193 | - 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
194 | - 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
195 | - 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
196 | - 'Registration' => new EE_Has_Many_Relation(), |
|
197 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
198 | - ); |
|
199 | - //this model is generally available for reading |
|
200 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public( |
|
201 | - 'TKT_is_default', |
|
202 | - 'Datetime.Event' |
|
203 | - ); |
|
204 | - //account for default tickets in the caps |
|
205 | - $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected( |
|
206 | - 'TKT_is_default', |
|
207 | - 'Datetime.Event' |
|
208 | - ); |
|
209 | - $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected( |
|
210 | - 'TKT_is_default', |
|
211 | - 'Datetime.Event' |
|
212 | - ); |
|
213 | - $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected( |
|
214 | - 'TKT_is_default', |
|
215 | - 'Datetime.Event' |
|
216 | - ); |
|
217 | - parent::__construct($timezone); |
|
218 | - } |
|
24 | + /** |
|
25 | + * private constructor to prevent direct creation |
|
26 | + * |
|
27 | + * @Constructor |
|
28 | + * @access private |
|
29 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
30 | + * (and any incoming timezone data that gets saved). |
|
31 | + * Note this just sends the timezone info to the date time model field objects. |
|
32 | + * Default is NULL |
|
33 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
34 | + * @throws EE_Error |
|
35 | + */ |
|
36 | + protected function __construct($timezone) |
|
37 | + { |
|
38 | + $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
39 | + $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
40 | + $this->_tables = array( |
|
41 | + 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
42 | + ); |
|
43 | + $this->_fields = array( |
|
44 | + 'Ticket' => array( |
|
45 | + 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
46 | + 'TKT_ID', |
|
47 | + esc_html__('Ticket ID', 'event_espresso') |
|
48 | + ), |
|
49 | + 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
50 | + 'TTM_ID', |
|
51 | + esc_html__('Ticket Template ID', 'event_espresso'), |
|
52 | + false, |
|
53 | + 0, |
|
54 | + 'Ticket_Template' |
|
55 | + ), |
|
56 | + 'TKT_name' => new EE_Plain_Text_Field( |
|
57 | + 'TKT_name', |
|
58 | + esc_html__('Ticket Name', 'event_espresso'), |
|
59 | + false, |
|
60 | + '' |
|
61 | + ), |
|
62 | + 'TKT_description' => new EE_Post_Content_Field( |
|
63 | + 'TKT_description', |
|
64 | + esc_html__('Description of Ticket', 'event_espresso'), |
|
65 | + false, |
|
66 | + '' |
|
67 | + ), |
|
68 | + 'TKT_start_date' => new EE_Datetime_Field( |
|
69 | + 'TKT_start_date', |
|
70 | + esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
71 | + false, |
|
72 | + EE_Datetime_Field::now, |
|
73 | + $timezone |
|
74 | + ), |
|
75 | + 'TKT_end_date' => new EE_Datetime_Field( |
|
76 | + 'TKT_end_date', |
|
77 | + esc_html__('End time/date of Ticket', 'event_espresso'), |
|
78 | + false, |
|
79 | + EE_Datetime_Field::now, |
|
80 | + $timezone |
|
81 | + ), |
|
82 | + 'TKT_min' => new EE_Integer_Field( |
|
83 | + 'TKT_min', |
|
84 | + esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
85 | + false, |
|
86 | + 0 |
|
87 | + ), |
|
88 | + 'TKT_max' => new EE_Infinite_Integer_Field( |
|
89 | + 'TKT_max', |
|
90 | + esc_html__( |
|
91 | + 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
92 | + 'event_espresso' |
|
93 | + ), |
|
94 | + false, |
|
95 | + EE_INF |
|
96 | + ), |
|
97 | + 'TKT_price' => new EE_Money_Field( |
|
98 | + 'TKT_price', |
|
99 | + esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
100 | + false, |
|
101 | + 0 |
|
102 | + ), |
|
103 | + 'TKT_sold' => new EE_Integer_Field( |
|
104 | + 'TKT_sold', |
|
105 | + esc_html__('Number of this ticket sold', 'event_espresso'), |
|
106 | + false, |
|
107 | + 0 |
|
108 | + ), |
|
109 | + 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
110 | + 'TKT_qty', |
|
111 | + esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
112 | + false, |
|
113 | + EE_INF |
|
114 | + ), |
|
115 | + 'TKT_reserved' => new EE_Integer_Field( |
|
116 | + 'TKT_reserved', |
|
117 | + esc_html__( |
|
118 | + 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
119 | + 'event_espresso' |
|
120 | + ), |
|
121 | + false, |
|
122 | + 0 |
|
123 | + ), |
|
124 | + 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
125 | + 'TKT_uses', |
|
126 | + esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
127 | + false, |
|
128 | + EE_INF |
|
129 | + ), |
|
130 | + 'TKT_required' => new EE_Boolean_Field( |
|
131 | + 'TKT_required', |
|
132 | + esc_html__( |
|
133 | + 'Flag indicating whether this ticket must be purchased with a transaction', |
|
134 | + 'event_espresso' |
|
135 | + ), |
|
136 | + false, |
|
137 | + false |
|
138 | + ), |
|
139 | + 'TKT_taxable' => new EE_Boolean_Field( |
|
140 | + 'TKT_taxable', |
|
141 | + esc_html__( |
|
142 | + 'Flag indicating whether there is tax applied on this ticket', |
|
143 | + 'event_espresso' |
|
144 | + ), |
|
145 | + false, |
|
146 | + false |
|
147 | + ), |
|
148 | + 'TKT_is_default' => new EE_Boolean_Field( |
|
149 | + 'TKT_is_default', |
|
150 | + esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
151 | + false, |
|
152 | + false |
|
153 | + ), |
|
154 | + 'TKT_order' => new EE_Integer_Field( |
|
155 | + 'TKT_order', |
|
156 | + esc_html__( |
|
157 | + 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
158 | + 'event_espresso' |
|
159 | + ), |
|
160 | + false, |
|
161 | + 0 |
|
162 | + ), |
|
163 | + 'TKT_row' => new EE_Integer_Field( |
|
164 | + 'TKT_row', |
|
165 | + esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
166 | + false, |
|
167 | + 0 |
|
168 | + ), |
|
169 | + 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
170 | + 'TKT_deleted', |
|
171 | + esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
172 | + false, |
|
173 | + false |
|
174 | + ), |
|
175 | + 'TKT_wp_user' => new EE_WP_User_Field( |
|
176 | + 'TKT_wp_user', |
|
177 | + esc_html__('Ticket Creator ID', 'event_espresso'), |
|
178 | + false |
|
179 | + ), |
|
180 | + 'TKT_parent' => new EE_Integer_Field( |
|
181 | + 'TKT_parent', |
|
182 | + esc_html__( |
|
183 | + 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
184 | + 'event_espresso' |
|
185 | + ), |
|
186 | + true, |
|
187 | + 0 |
|
188 | + ), |
|
189 | + ), |
|
190 | + ); |
|
191 | + $this->_model_relations = array( |
|
192 | + 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
193 | + 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
194 | + 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
195 | + 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
196 | + 'Registration' => new EE_Has_Many_Relation(), |
|
197 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
198 | + ); |
|
199 | + //this model is generally available for reading |
|
200 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public( |
|
201 | + 'TKT_is_default', |
|
202 | + 'Datetime.Event' |
|
203 | + ); |
|
204 | + //account for default tickets in the caps |
|
205 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected( |
|
206 | + 'TKT_is_default', |
|
207 | + 'Datetime.Event' |
|
208 | + ); |
|
209 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected( |
|
210 | + 'TKT_is_default', |
|
211 | + 'Datetime.Event' |
|
212 | + ); |
|
213 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected( |
|
214 | + 'TKT_is_default', |
|
215 | + 'Datetime.Event' |
|
216 | + ); |
|
217 | + parent::__construct($timezone); |
|
218 | + } |
|
219 | 219 | |
220 | 220 | |
221 | 221 | |
222 | - /** |
|
223 | - * This returns all tickets that are defaults from the db |
|
224 | - * |
|
225 | - * @return EE_Ticket[] |
|
226 | - * @throws EE_Error |
|
227 | - */ |
|
228 | - public function get_all_default_tickets() |
|
229 | - { |
|
230 | - /** @type EE_Ticket[] $tickets */ |
|
231 | - $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
232 | - //we need to set the start date and end date to today's date and the start of the default dtt |
|
233 | - return $this->_set_default_dates($tickets); |
|
234 | - } |
|
222 | + /** |
|
223 | + * This returns all tickets that are defaults from the db |
|
224 | + * |
|
225 | + * @return EE_Ticket[] |
|
226 | + * @throws EE_Error |
|
227 | + */ |
|
228 | + public function get_all_default_tickets() |
|
229 | + { |
|
230 | + /** @type EE_Ticket[] $tickets */ |
|
231 | + $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
232 | + //we need to set the start date and end date to today's date and the start of the default dtt |
|
233 | + return $this->_set_default_dates($tickets); |
|
234 | + } |
|
235 | 235 | |
236 | 236 | |
237 | 237 | |
238 | - /** |
|
239 | - * sets up relevant start and end date for EE_Ticket (s) |
|
240 | - * |
|
241 | - * @param EE_Ticket[] $tickets |
|
242 | - * @return EE_Ticket[] |
|
243 | - * @throws EE_Error |
|
244 | - */ |
|
245 | - private function _set_default_dates($tickets) |
|
246 | - { |
|
247 | - foreach ($tickets as $ticket) { |
|
248 | - $ticket->set( |
|
249 | - 'TKT_start_date', |
|
250 | - (int)$this->current_time_for_query('TKT_start_date', true) |
|
251 | - ); |
|
252 | - $ticket->set( |
|
253 | - 'TKT_end_date', |
|
254 | - (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
255 | - ); |
|
256 | - $ticket->set_end_time( |
|
257 | - $this->convert_datetime_for_query( |
|
258 | - 'TKT_end_date', |
|
259 | - '11:59 pm', |
|
260 | - 'g:i a', $this->_timezone |
|
261 | - ) |
|
262 | - ); |
|
263 | - } |
|
264 | - return $tickets; |
|
265 | - } |
|
238 | + /** |
|
239 | + * sets up relevant start and end date for EE_Ticket (s) |
|
240 | + * |
|
241 | + * @param EE_Ticket[] $tickets |
|
242 | + * @return EE_Ticket[] |
|
243 | + * @throws EE_Error |
|
244 | + */ |
|
245 | + private function _set_default_dates($tickets) |
|
246 | + { |
|
247 | + foreach ($tickets as $ticket) { |
|
248 | + $ticket->set( |
|
249 | + 'TKT_start_date', |
|
250 | + (int)$this->current_time_for_query('TKT_start_date', true) |
|
251 | + ); |
|
252 | + $ticket->set( |
|
253 | + 'TKT_end_date', |
|
254 | + (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
255 | + ); |
|
256 | + $ticket->set_end_time( |
|
257 | + $this->convert_datetime_for_query( |
|
258 | + 'TKT_end_date', |
|
259 | + '11:59 pm', |
|
260 | + 'g:i a', $this->_timezone |
|
261 | + ) |
|
262 | + ); |
|
263 | + } |
|
264 | + return $tickets; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | |
268 | 268 | |
269 | - /** |
|
270 | - * Gets the total number of tickets available at a particular datetime (does |
|
271 | - * NOT take int account the datetime's spaces available) |
|
272 | - * |
|
273 | - * @param int $DTT_ID |
|
274 | - * @param array $query_params |
|
275 | - * @return int |
|
276 | - */ |
|
277 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
278 | - { |
|
279 | - return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
280 | - } |
|
269 | + /** |
|
270 | + * Gets the total number of tickets available at a particular datetime (does |
|
271 | + * NOT take int account the datetime's spaces available) |
|
272 | + * |
|
273 | + * @param int $DTT_ID |
|
274 | + * @param array $query_params |
|
275 | + * @return int |
|
276 | + */ |
|
277 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
278 | + { |
|
279 | + return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
280 | + } |
|
281 | 281 | |
282 | 282 | |
283 | 283 | |
284 | - /** |
|
285 | - * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
286 | - * |
|
287 | - * @param EE_Ticket[] $tickets |
|
288 | - * @return void |
|
289 | - * @throws EE_Error |
|
290 | - */ |
|
291 | - public function update_tickets_sold($tickets) |
|
292 | - { |
|
293 | - foreach ($tickets as $ticket) { |
|
294 | - /* @var $ticket EE_Ticket */ |
|
295 | - $ticket->update_tickets_sold(); |
|
296 | - } |
|
297 | - } |
|
284 | + /** |
|
285 | + * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
286 | + * |
|
287 | + * @param EE_Ticket[] $tickets |
|
288 | + * @return void |
|
289 | + * @throws EE_Error |
|
290 | + */ |
|
291 | + public function update_tickets_sold($tickets) |
|
292 | + { |
|
293 | + foreach ($tickets as $ticket) { |
|
294 | + /* @var $ticket EE_Ticket */ |
|
295 | + $ticket->update_tickets_sold(); |
|
296 | + } |
|
297 | + } |
|
298 | 298 | |
299 | 299 | |
300 | 300 | |
301 | - /** |
|
302 | - * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
303 | - * |
|
304 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
305 | - * @throws EE_Error |
|
306 | - */ |
|
307 | - public function get_tickets_with_reservations() |
|
308 | - { |
|
309 | - return $this->get_all( |
|
310 | - array( |
|
311 | - array( |
|
312 | - 'TKT_reserved' => array('>', 0), |
|
313 | - ), |
|
314 | - ) |
|
315 | - ); |
|
316 | - } |
|
301 | + /** |
|
302 | + * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
303 | + * |
|
304 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
305 | + * @throws EE_Error |
|
306 | + */ |
|
307 | + public function get_tickets_with_reservations() |
|
308 | + { |
|
309 | + return $this->get_all( |
|
310 | + array( |
|
311 | + array( |
|
312 | + 'TKT_reserved' => array('>', 0), |
|
313 | + ), |
|
314 | + ) |
|
315 | + ); |
|
316 | + } |
|
317 | 317 | |
318 | 318 | |
319 | 319 | |
320 | - /** |
|
321 | - * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
322 | - * |
|
323 | - * @param array $ticket_IDs |
|
324 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
325 | - * @throws EE_Error |
|
326 | - */ |
|
327 | - public function get_tickets_with_IDs(array $ticket_IDs) |
|
328 | - { |
|
329 | - return $this->get_all( |
|
330 | - array( |
|
331 | - array( |
|
332 | - 'TKT_ID' => array('IN', $ticket_IDs) |
|
333 | - ) |
|
334 | - ) |
|
335 | - ); |
|
336 | - } |
|
320 | + /** |
|
321 | + * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
322 | + * |
|
323 | + * @param array $ticket_IDs |
|
324 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
325 | + * @throws EE_Error |
|
326 | + */ |
|
327 | + public function get_tickets_with_IDs(array $ticket_IDs) |
|
328 | + { |
|
329 | + return $this->get_all( |
|
330 | + array( |
|
331 | + array( |
|
332 | + 'TKT_ID' => array('IN', $ticket_IDs) |
|
333 | + ) |
|
334 | + ) |
|
335 | + ); |
|
336 | + } |
|
337 | 337 | |
338 | 338 | |
339 | 339 |
@@ -247,11 +247,11 @@ |
||
247 | 247 | foreach ($tickets as $ticket) { |
248 | 248 | $ticket->set( |
249 | 249 | 'TKT_start_date', |
250 | - (int)$this->current_time_for_query('TKT_start_date', true) |
|
250 | + (int) $this->current_time_for_query('TKT_start_date', true) |
|
251 | 251 | ); |
252 | 252 | $ticket->set( |
253 | 253 | 'TKT_end_date', |
254 | - (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
254 | + (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
255 | 255 | ); |
256 | 256 | $ticket->set_end_time( |
257 | 257 | $this->convert_datetime_for_query( |
@@ -44,77 +44,76 @@ discard block |
||
44 | 44 | */ |
45 | 45 | protected $_image_url; |
46 | 46 | |
47 | - /** |
|
48 | - * gateway URL variable |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $_base_gateway_url = ''; |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * EEG_Paypal_Express constructor. |
|
58 | - */ |
|
59 | - public function __construct() |
|
60 | - { |
|
61 | - $this->_currencies_supported = array( |
|
62 | - 'USD', |
|
63 | - 'AUD', |
|
64 | - 'BRL', |
|
65 | - 'CAD', |
|
66 | - 'CZK', |
|
67 | - 'DKK', |
|
68 | - 'EUR', |
|
69 | - 'HKD', |
|
70 | - 'HUF', |
|
71 | - 'ILS', |
|
72 | - 'JPY', |
|
73 | - 'MYR', |
|
74 | - 'MXN', |
|
75 | - 'NOK', |
|
76 | - 'NZD', |
|
77 | - 'PHP', |
|
78 | - 'PLN', |
|
79 | - 'GBP', |
|
80 | - 'RUB', |
|
81 | - 'SGD', |
|
82 | - 'SEK', |
|
83 | - 'CHF', |
|
84 | - 'TWD', |
|
85 | - 'THB', |
|
86 | - 'TRY' |
|
87 | - ); |
|
88 | - parent::__construct(); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
47 | + /** |
|
48 | + * gateway URL variable |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $_base_gateway_url = ''; |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * EEG_Paypal_Express constructor. |
|
58 | + */ |
|
59 | + public function __construct() |
|
60 | + { |
|
61 | + $this->_currencies_supported = array( |
|
62 | + 'USD', |
|
63 | + 'AUD', |
|
64 | + 'BRL', |
|
65 | + 'CAD', |
|
66 | + 'CZK', |
|
67 | + 'DKK', |
|
68 | + 'EUR', |
|
69 | + 'HKD', |
|
70 | + 'HUF', |
|
71 | + 'ILS', |
|
72 | + 'JPY', |
|
73 | + 'MYR', |
|
74 | + 'MXN', |
|
75 | + 'NOK', |
|
76 | + 'NZD', |
|
77 | + 'PHP', |
|
78 | + 'PLN', |
|
79 | + 'GBP', |
|
80 | + 'RUB', |
|
81 | + 'SGD', |
|
82 | + 'SEK', |
|
83 | + 'CHF', |
|
84 | + 'TWD', |
|
85 | + 'THB', |
|
86 | + 'TRY' |
|
87 | + ); |
|
88 | + parent::__construct(); |
|
89 | + } |
|
90 | + |
|
95 | 91 | |
92 | + |
|
93 | + /** |
|
94 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
96 | 95 | * |
97 | 96 | *@param array $settings_array |
98 | 97 | */ |
99 | 98 | public function set_settings( $settings_array ) { |
100 | 99 | parent::set_settings($settings_array); |
101 | 100 | // Redirect URL. |
102 | - $this->_base_gateway_url = $this->_debug_mode |
|
103 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
104 | - : 'https://api-3t.paypal.com/nvp'; |
|
101 | + $this->_base_gateway_url = $this->_debug_mode |
|
102 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
103 | + : 'https://api-3t.paypal.com/nvp'; |
|
105 | 104 | } |
106 | 105 | |
107 | 106 | |
108 | 107 | |
109 | - /** |
|
110 | - * @param EEI_Payment $payment |
|
111 | - * @param array $billing_info |
|
112 | - * @param string $return_url |
|
113 | - * @param string $notify_url |
|
114 | - * @param string $cancel_url |
|
115 | - * @return \EE_Payment|\EEI_Payment |
|
116 | - * @throws \EE_Error |
|
117 | - */ |
|
108 | + /** |
|
109 | + * @param EEI_Payment $payment |
|
110 | + * @param array $billing_info |
|
111 | + * @param string $return_url |
|
112 | + * @param string $notify_url |
|
113 | + * @param string $cancel_url |
|
114 | + * @return \EE_Payment|\EEI_Payment |
|
115 | + * @throws \EE_Error |
|
116 | + */ |
|
118 | 117 | public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) { |
119 | 118 | if ( ! $payment instanceof EEI_Payment ) { |
120 | 119 | $payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) ); |
@@ -202,9 +201,9 @@ discard block |
||
202 | 201 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
203 | 202 | // Item quantity. |
204 | 203 | $token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1; |
205 | - // Digital item is sold. |
|
206 | - $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
207 | - $item_num++; |
|
204 | + // Digital item is sold. |
|
205 | + $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
206 | + $item_num++; |
|
208 | 207 | } |
209 | 208 | } else { |
210 | 209 | // Just one Item. |
@@ -277,7 +276,6 @@ discard block |
||
277 | 276 | |
278 | 277 | |
279 | 278 | /** |
280 | - |
|
281 | 279 | * @param array $update_info { |
282 | 280 | * @type string $gateway_txn_id |
283 | 281 | * @type string status an EEMI_Payment status |
@@ -297,8 +295,8 @@ discard block |
||
297 | 295 | return $payment; |
298 | 296 | } |
299 | 297 | $primary_registrant = $transaction->primary_registration(); |
300 | - $payment_details = $payment->details(); |
|
301 | - // Check if we still have the token. |
|
298 | + $payment_details = $payment->details(); |
|
299 | + // Check if we still have the token. |
|
302 | 300 | if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) { |
303 | 301 | $payment->set_status( $this->_pay_model->failed_status() ); |
304 | 302 | return $payment; |
@@ -407,35 +405,35 @@ discard block |
||
407 | 405 | */ |
408 | 406 | public function _ppExpress_check_response( $request_response ) { |
409 | 407 | if ( is_wp_error( $request_response ) || empty($request_response['body']) ) { |
410 | - // If we got here then there was an error in this request. |
|
411 | - return array('status' => false, 'args' => $request_response); |
|
412 | - } |
|
413 | - $response_args = array(); |
|
414 | - parse_str( urldecode($request_response['body']), $response_args ); |
|
415 | - if ( ! isset($response_args['ACK'])) { |
|
416 | - return array('status' => false, 'args' => $request_response); |
|
417 | - } |
|
418 | - if ( |
|
419 | - ( |
|
420 | - isset($response_args['PAYERID']) |
|
421 | - || isset($response_args['TOKEN']) |
|
422 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
423 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
424 | - ) |
|
425 | - && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
426 | - ) { |
|
427 | - // Response status OK, return response parameters for further processing. |
|
428 | - return array('status' => true, 'args' => $response_args); |
|
429 | - } |
|
430 | - $errors = $this->_get_errors($response_args); |
|
431 | - return array('status' => false, 'args' => $errors); |
|
408 | + // If we got here then there was an error in this request. |
|
409 | + return array('status' => false, 'args' => $request_response); |
|
410 | + } |
|
411 | + $response_args = array(); |
|
412 | + parse_str( urldecode($request_response['body']), $response_args ); |
|
413 | + if ( ! isset($response_args['ACK'])) { |
|
414 | + return array('status' => false, 'args' => $request_response); |
|
415 | + } |
|
416 | + if ( |
|
417 | + ( |
|
418 | + isset($response_args['PAYERID']) |
|
419 | + || isset($response_args['TOKEN']) |
|
420 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
421 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
422 | + ) |
|
423 | + && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
424 | + ) { |
|
425 | + // Response status OK, return response parameters for further processing. |
|
426 | + return array('status' => true, 'args' => $response_args); |
|
427 | + } |
|
428 | + $errors = $this->_get_errors($response_args); |
|
429 | + return array('status' => false, 'args' => $errors); |
|
432 | 430 | } |
433 | 431 | |
434 | 432 | |
435 | 433 | /** |
436 | - * Log a "Cleared" request. |
|
437 | - * |
|
438 | - * @param array $request |
|
434 | + * Log a "Cleared" request. |
|
435 | + * |
|
436 | + * @param array $request |
|
439 | 437 | * @param EEI_Payment $payment |
440 | 438 | * @param string $info |
441 | 439 | * @return void |
@@ -458,17 +456,17 @@ discard block |
||
458 | 456 | $n = 0; |
459 | 457 | while ( isset($data_array["L_ERRORCODE{$n}"]) ) { |
460 | 458 | $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
461 | - ? $data_array["L_ERRORCODE{$n}"] |
|
462 | - : ''; |
|
459 | + ? $data_array["L_ERRORCODE{$n}"] |
|
460 | + : ''; |
|
463 | 461 | $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
464 | - ? $data_array["L_SEVERITYCODE{$n}"] |
|
465 | - : ''; |
|
462 | + ? $data_array["L_SEVERITYCODE{$n}"] |
|
463 | + : ''; |
|
466 | 464 | $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
467 | - ? $data_array["L_SHORTMESSAGE{$n}"] |
|
468 | - : ''; |
|
465 | + ? $data_array["L_SHORTMESSAGE{$n}"] |
|
466 | + : ''; |
|
469 | 467 | $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
470 | - ? $data_array["L_LONGMESSAGE{$n}"] |
|
471 | - : ''; |
|
468 | + ? $data_array["L_LONGMESSAGE{$n}"] |
|
469 | + : ''; |
|
472 | 470 | |
473 | 471 | if ( $n === 0 ) { |
474 | 472 | $errors = array( |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' )) { exit('NO direct script access allowed'); } |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('NO direct script access allowed'); } |
|
2 | 2 | |
3 | 3 | /** |
4 | 4 | * ---------------------------------------------- |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * |
97 | 97 | *@param array $settings_array |
98 | 98 | */ |
99 | - public function set_settings( $settings_array ) { |
|
99 | + public function set_settings($settings_array) { |
|
100 | 100 | parent::set_settings($settings_array); |
101 | 101 | // Redirect URL. |
102 | 102 | $this->_base_gateway_url = $this->_debug_mode |
@@ -115,19 +115,19 @@ discard block |
||
115 | 115 | * @return \EE_Payment|\EEI_Payment |
116 | 116 | * @throws \EE_Error |
117 | 117 | */ |
118 | - public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) { |
|
119 | - if ( ! $payment instanceof EEI_Payment ) { |
|
120 | - $payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) ); |
|
121 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
118 | + public function set_redirection_info($payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL) { |
|
119 | + if ( ! $payment instanceof EEI_Payment) { |
|
120 | + $payment->set_gateway_response(__('Error. No associated payment was found.', 'event_espresso')); |
|
121 | + $payment->set_status($this->_pay_model->failed_status()); |
|
122 | 122 | return $payment; |
123 | 123 | } |
124 | 124 | $transaction = $payment->transaction(); |
125 | - if ( ! $transaction instanceof EEI_Transaction ) { |
|
126 | - $payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) ); |
|
127 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
125 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
126 | + $payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso')); |
|
127 | + $payment->set_status($this->_pay_model->failed_status()); |
|
128 | 128 | return $payment; |
129 | 129 | } |
130 | - $order_description = substr( $this->_format_order_description($payment), 0, 127 ); |
|
130 | + $order_description = substr($this->_format_order_description($payment), 0, 127); |
|
131 | 131 | $primary_registration = $transaction->primary_registration(); |
132 | 132 | $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : false; |
133 | 133 | $locale = explode('-', get_bloginfo('language')); |
@@ -141,37 +141,37 @@ discard block |
||
141 | 141 | 'RETURNURL' => $return_url, |
142 | 142 | 'CANCELURL' => $cancel_url, |
143 | 143 | 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
144 | - 'SOLUTIONTYPE' => 'Sole', // Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional. |
|
145 | - 'BUTTONSOURCE' => 'EventEspresso_SP',//EE will blow up if you change this |
|
144 | + 'SOLUTIONTYPE' => 'Sole', // Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional. |
|
145 | + 'BUTTONSOURCE' => 'EventEspresso_SP', //EE will blow up if you change this |
|
146 | 146 | 'LOCALECODE' => $locale[1] // Locale of the pages displayed by PayPal during Express Checkout. |
147 | 147 | ); |
148 | 148 | |
149 | 149 | // Show itemized list. |
150 | - if ( $this->_money->compare_floats( $payment->amount(), $transaction->total(), '==' ) ) { |
|
150 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
151 | 151 | $item_num = 0; |
152 | 152 | $itemized_sum = 0; |
153 | 153 | $total_line_items = $transaction->total_line_item(); |
154 | 154 | // Go through each item in the list. |
155 | - foreach ( $total_line_items->get_items() as $line_item ) { |
|
156 | - if ( $line_item instanceof EE_Line_Item ) { |
|
155 | + foreach ($total_line_items->get_items() as $line_item) { |
|
156 | + if ($line_item instanceof EE_Line_Item) { |
|
157 | 157 | // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
158 | - if ( EEH_Money::compare_floats( $line_item->total(), '0.00', '==' ) ) { |
|
158 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
159 | 159 | continue; |
160 | 160 | } |
161 | 161 | |
162 | 162 | $unit_price = $line_item->unit_price(); |
163 | 163 | $line_item_quantity = $line_item->quantity(); |
164 | 164 | // This is a discount. |
165 | - if ( $line_item->is_percent() ) { |
|
165 | + if ($line_item->is_percent()) { |
|
166 | 166 | $unit_price = $line_item->total(); |
167 | 167 | $line_item_quantity = 1; |
168 | 168 | } |
169 | 169 | // Item Name. |
170 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name( $line_item, $payment), 0, 127); |
|
170 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name($line_item, $payment), 0, 127); |
|
171 | 171 | // Item description. |
172 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc( $line_item, $payment), 0, 127); |
|
172 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc($line_item, $payment), 0, 127); |
|
173 | 173 | // Cost of individual item. |
174 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $unit_price ); |
|
174 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($unit_price); |
|
175 | 175 | // Item Number. |
176 | 176 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
177 | 177 | // Item quantity. |
@@ -188,16 +188,16 @@ discard block |
||
188 | 188 | $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
189 | 189 | $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
190 | 190 | |
191 | - $itemized_sum_diff_from_txn_total = round( $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2 ); |
|
191 | + $itemized_sum_diff_from_txn_total = round($transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2); |
|
192 | 192 | // If we were not able to recognize some item like promotion, surcharge or cancellation, |
193 | 193 | // add the difference as an extra line item. |
194 | - if ( $this->_money->compare_floats( $itemized_sum_diff_from_txn_total, 0, '!=' ) ) { |
|
194 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
195 | 195 | // Item Name. |
196 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr( __( 'Other (promotion/surcharge/cancellation)', 'event_espresso' ), 0, 127 ); |
|
196 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr(__('Other (promotion/surcharge/cancellation)', 'event_espresso'), 0, 127); |
|
197 | 197 | // Item description. |
198 | 198 | $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = ''; |
199 | 199 | // Cost of individual item. |
200 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $itemized_sum_diff_from_txn_total ); |
|
200 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($itemized_sum_diff_from_txn_total); |
|
201 | 201 | // Item Number. |
202 | 202 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
203 | 203 | // Item quantity. |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | } else { |
210 | 210 | // Just one Item. |
211 | 211 | // Item Name. |
212 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr( $this->_format_partial_payment_line_item_name($payment), 0, 127 ); |
|
212 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr($this->_format_partial_payment_line_item_name($payment), 0, 127); |
|
213 | 213 | // Item description. |
214 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr( $this->_format_partial_payment_line_item_desc($payment), 0, 127 ); |
|
214 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr($this->_format_partial_payment_line_item_desc($payment), 0, 127); |
|
215 | 215 | // Cost of individual item. |
216 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency( $payment->amount() ); |
|
216 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount()); |
|
217 | 217 | // Item Number. |
218 | 218 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
219 | 219 | // Item quantity. |
@@ -221,14 +221,14 @@ discard block |
||
221 | 221 | // Digital item is sold. |
222 | 222 | $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
223 | 223 | // Item's sales S/H and tax amount. |
224 | - $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency( $payment->amount() ); |
|
224 | + $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount()); |
|
225 | 225 | $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
226 | 226 | $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
227 | 227 | $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
228 | 228 | } |
229 | 229 | // Automatically filling out shipping and contact information. |
230 | - if ( $this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee ) { |
|
231 | - $token_request_dtls['NOSHIPPING'] = '2'; // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
230 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
231 | + $token_request_dtls['NOSHIPPING'] = '2'; // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
232 | 232 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
233 | 233 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
234 | 234 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
@@ -237,14 +237,14 @@ discard block |
||
237 | 237 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
238 | 238 | $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
239 | 239 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
240 | - } elseif ( ! $this->_request_shipping_addr ) { |
|
240 | + } elseif ( ! $this->_request_shipping_addr) { |
|
241 | 241 | // Do not request shipping details on the PP Checkout page. |
242 | 242 | $token_request_dtls['NOSHIPPING'] = '1'; |
243 | 243 | $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
244 | 244 | |
245 | 245 | } |
246 | 246 | // Used a business/personal logo on the PayPal page. |
247 | - if ( ! empty($this->_image_url) ) { |
|
247 | + if ( ! empty($this->_image_url)) { |
|
248 | 248 | $token_request_dtls['LOGOIMG'] = $this->_image_url; |
249 | 249 | } |
250 | 250 | $token_request_dtls = apply_filters( |
@@ -253,23 +253,23 @@ discard block |
||
253 | 253 | $this |
254 | 254 | ); |
255 | 255 | // Request PayPal token. |
256 | - $token_request_response = $this->_ppExpress_request( $token_request_dtls, 'Payment Token', $payment ); |
|
257 | - $token_rstatus = $this->_ppExpress_check_response( $token_request_response ); |
|
258 | - $response_args = ( isset($token_rstatus['args']) && is_array($token_rstatus['args']) ) ? $token_rstatus['args'] : array(); |
|
259 | - if ( $token_rstatus['status'] ) { |
|
256 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
257 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
258 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) ? $token_rstatus['args'] : array(); |
|
259 | + if ($token_rstatus['status']) { |
|
260 | 260 | // We got the Token so we may continue with the payment and redirect the client. |
261 | - $payment->set_details( $response_args ); |
|
261 | + $payment->set_details($response_args); |
|
262 | 262 | |
263 | 263 | $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
264 | - $payment->set_redirect_url( $gateway_url . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' . $response_args['TOKEN'] ); |
|
264 | + $payment->set_redirect_url($gateway_url.'/checkoutnow?useraction=commit&cmd=_express-checkout&token='.$response_args['TOKEN']); |
|
265 | 265 | } else { |
266 | - if ( isset($response_args['L_ERRORCODE']) ) { |
|
267 | - $payment->set_gateway_response( $response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE'] ); |
|
266 | + if (isset($response_args['L_ERRORCODE'])) { |
|
267 | + $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']); |
|
268 | 268 | } else { |
269 | - $payment->set_gateway_response( __( 'Error occurred while trying to setup the Express Checkout.', 'event_espresso' ) ); |
|
269 | + $payment->set_gateway_response(__('Error occurred while trying to setup the Express Checkout.', 'event_espresso')); |
|
270 | 270 | } |
271 | - $payment->set_details( $response_args ); |
|
272 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
271 | + $payment->set_details($response_args); |
|
272 | + $payment->set_status($this->_pay_model->failed_status()); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | return $payment; |
@@ -285,22 +285,22 @@ discard block |
||
285 | 285 | * @param EEI_Transaction $transaction |
286 | 286 | * @return EEI_Payment |
287 | 287 | */ |
288 | - public function handle_payment_update( $update_info, $transaction ) { |
|
288 | + public function handle_payment_update($update_info, $transaction) { |
|
289 | 289 | $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
290 | 290 | |
291 | - if ( $payment instanceof EEI_Payment ) { |
|
292 | - $this->log( array( 'Return from Authorization' => $update_info ), $payment ); |
|
291 | + if ($payment instanceof EEI_Payment) { |
|
292 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
293 | 293 | $transaction = $payment->transaction(); |
294 | - if ( ! $transaction instanceof EEI_Transaction ) { |
|
295 | - $payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) ); |
|
296 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
294 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
295 | + $payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso')); |
|
296 | + $payment->set_status($this->_pay_model->failed_status()); |
|
297 | 297 | return $payment; |
298 | 298 | } |
299 | 299 | $primary_registrant = $transaction->primary_registration(); |
300 | 300 | $payment_details = $payment->details(); |
301 | 301 | // Check if we still have the token. |
302 | - if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) { |
|
303 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
302 | + if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
303 | + $payment->set_status($this->_pay_model->failed_status()); |
|
304 | 304 | return $payment; |
305 | 305 | } |
306 | 306 | |
@@ -309,10 +309,10 @@ discard block |
||
309 | 309 | 'TOKEN' => $payment_details['TOKEN'] |
310 | 310 | ); |
311 | 311 | // Request Customer Details. |
312 | - $cdetails_request_response = $this->_ppExpress_request( $cdetails_request_dtls, 'Customer Details', $payment ); |
|
313 | - $cdetails_rstatus = $this->_ppExpress_check_response( $cdetails_request_response ); |
|
314 | - $cdata_response_args = ( isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']) ) ? $cdetails_rstatus['args'] : array(); |
|
315 | - if ( $cdetails_rstatus['status'] ) { |
|
312 | + $cdetails_request_response = $this->_ppExpress_request($cdetails_request_dtls, 'Customer Details', $payment); |
|
313 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
314 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) ? $cdetails_rstatus['args'] : array(); |
|
315 | + if ($cdetails_rstatus['status']) { |
|
316 | 316 | // We got the PayerID so now we can Complete the transaction. |
317 | 317 | $docheckout_request_dtls = array( |
318 | 318 | 'METHOD' => 'DoExpressCheckoutPayment', |
@@ -323,39 +323,39 @@ discard block |
||
323 | 323 | 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code() |
324 | 324 | ); |
325 | 325 | // Payment Checkout/Capture. |
326 | - $docheckout_request_response = $this->_ppExpress_request( $docheckout_request_dtls, 'Do Payment', $payment ); |
|
327 | - $docheckout_rstatus = $this->_ppExpress_check_response( $docheckout_request_response ); |
|
328 | - $docheckout_response_args = ( isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']) ) ? $docheckout_rstatus['args'] : array(); |
|
329 | - if ( $docheckout_rstatus['status'] ) { |
|
326 | + $docheckout_request_response = $this->_ppExpress_request($docheckout_request_dtls, 'Do Payment', $payment); |
|
327 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
328 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) ? $docheckout_rstatus['args'] : array(); |
|
329 | + if ($docheckout_rstatus['status']) { |
|
330 | 330 | // All is well, payment approved. |
331 | 331 | $primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : ''; |
332 | - $payment->set_extra_accntng( $primary_registration_code ); |
|
333 | - $payment->set_amount( isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0 ); |
|
334 | - $payment->set_txn_id_chq_nmbr( isset( $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] ) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null ); |
|
335 | - $payment->set_details( $cdata_response_args ); |
|
336 | - $payment->set_gateway_response( isset( $docheckout_response_args['PAYMENTINFO_0_ACK'] ) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : '' ); |
|
337 | - $payment->set_status( $this->_pay_model->approved_status() ); |
|
332 | + $payment->set_extra_accntng($primary_registration_code); |
|
333 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0); |
|
334 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null); |
|
335 | + $payment->set_details($cdata_response_args); |
|
336 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : ''); |
|
337 | + $payment->set_status($this->_pay_model->approved_status()); |
|
338 | 338 | } else { |
339 | - if ( isset($docheckout_response_args['L_ERRORCODE']) ) { |
|
340 | - $payment->set_gateway_response( $docheckout_response_args['L_ERRORCODE'] . '; ' . $docheckout_response_args['L_SHORTMESSAGE'] ); |
|
339 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
340 | + $payment->set_gateway_response($docheckout_response_args['L_ERRORCODE'].'; '.$docheckout_response_args['L_SHORTMESSAGE']); |
|
341 | 341 | } else { |
342 | - $payment->set_gateway_response( __( 'Error occurred while trying to Capture the funds.', 'event_espresso' ) ); |
|
342 | + $payment->set_gateway_response(__('Error occurred while trying to Capture the funds.', 'event_espresso')); |
|
343 | 343 | } |
344 | - $payment->set_details( $docheckout_response_args ); |
|
345 | - $payment->set_status( $this->_pay_model->declined_status() ); |
|
344 | + $payment->set_details($docheckout_response_args); |
|
345 | + $payment->set_status($this->_pay_model->declined_status()); |
|
346 | 346 | } |
347 | 347 | } else { |
348 | - if ( isset($cdata_response_args['L_ERRORCODE']) ) { |
|
349 | - $payment->set_gateway_response( $cdata_response_args['L_ERRORCODE'] . '; ' . $cdata_response_args['L_SHORTMESSAGE'] ); |
|
348 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
349 | + $payment->set_gateway_response($cdata_response_args['L_ERRORCODE'].'; '.$cdata_response_args['L_SHORTMESSAGE']); |
|
350 | 350 | } else { |
351 | - $payment->set_gateway_response( __( 'Error occurred while trying to get payment Details from PayPal.', 'event_espresso' ) ); |
|
351 | + $payment->set_gateway_response(__('Error occurred while trying to get payment Details from PayPal.', 'event_espresso')); |
|
352 | 352 | } |
353 | - $payment->set_details( $cdata_response_args ); |
|
354 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
353 | + $payment->set_details($cdata_response_args); |
|
354 | + $payment->set_status($this->_pay_model->failed_status()); |
|
355 | 355 | } |
356 | 356 | } else { |
357 | - $payment->set_gateway_response( __( 'Error occurred while trying to process the payment.', 'event_espresso' ) ); |
|
358 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
357 | + $payment->set_gateway_response(__('Error occurred while trying to process the payment.', 'event_espresso')); |
|
358 | + $payment->set_status($this->_pay_model->failed_status()); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | return $payment; |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | * @param EEI_Payment $payment |
371 | 371 | * @return mixed |
372 | 372 | */ |
373 | - public function _ppExpress_request( $request_params, $request_text, $payment ) { |
|
373 | + public function _ppExpress_request($request_params, $request_text, $payment) { |
|
374 | 374 | $request_dtls = array( |
375 | 375 | 'VERSION' => '204.0', |
376 | - 'USER' => urlencode( $this->_api_username ), |
|
377 | - 'PWD' => urlencode( $this->_api_password ), |
|
378 | - 'SIGNATURE' => urlencode( $this->_api_signature ) |
|
376 | + 'USER' => urlencode($this->_api_username), |
|
377 | + 'PWD' => urlencode($this->_api_password), |
|
378 | + 'SIGNATURE' => urlencode($this->_api_signature) |
|
379 | 379 | ); |
380 | - $dtls = array_merge( $request_dtls, $request_params ); |
|
380 | + $dtls = array_merge($request_dtls, $request_params); |
|
381 | 381 | |
382 | - $this->_log_clean_request( $dtls, $payment, $request_text . ' Request' ); |
|
382 | + $this->_log_clean_request($dtls, $payment, $request_text.' Request'); |
|
383 | 383 | // Request Customer Details. |
384 | 384 | $request_response = wp_remote_post( |
385 | 385 | $this->_base_gateway_url, |
@@ -389,11 +389,11 @@ discard block |
||
389 | 389 | 'httpversion' => '1.1', |
390 | 390 | 'cookies' => array(), |
391 | 391 | 'headers' => array(), |
392 | - 'body' => http_build_query( $dtls ) |
|
392 | + 'body' => http_build_query($dtls) |
|
393 | 393 | ) |
394 | 394 | ); |
395 | 395 | // Log the response. |
396 | - $this->log( array( $request_text . ' Response' => $request_response), $payment ); |
|
396 | + $this->log(array($request_text.' Response' => $request_response), $payment); |
|
397 | 397 | |
398 | 398 | return $request_response; |
399 | 399 | } |
@@ -405,13 +405,13 @@ discard block |
||
405 | 405 | * @param mixed $request_response |
406 | 406 | * @return array |
407 | 407 | */ |
408 | - public function _ppExpress_check_response( $request_response ) { |
|
409 | - if ( is_wp_error( $request_response ) || empty($request_response['body']) ) { |
|
408 | + public function _ppExpress_check_response($request_response) { |
|
409 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
410 | 410 | // If we got here then there was an error in this request. |
411 | 411 | return array('status' => false, 'args' => $request_response); |
412 | 412 | } |
413 | 413 | $response_args = array(); |
414 | - parse_str( urldecode($request_response['body']), $response_args ); |
|
414 | + parse_str(urldecode($request_response['body']), $response_args); |
|
415 | 415 | if ( ! isset($response_args['ACK'])) { |
416 | 416 | return array('status' => false, 'args' => $request_response); |
417 | 417 | } |
@@ -440,10 +440,10 @@ discard block |
||
440 | 440 | * @param string $info |
441 | 441 | * @return void |
442 | 442 | */ |
443 | - private function _log_clean_request($request, $payment, $info ) { |
|
443 | + private function _log_clean_request($request, $payment, $info) { |
|
444 | 444 | $cleaned_request_data = $request; |
445 | 445 | unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
446 | - $this->log( array($info => $cleaned_request_data), $payment ); |
|
446 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | |
@@ -453,10 +453,10 @@ discard block |
||
453 | 453 | * @param array $data_array |
454 | 454 | * @return array |
455 | 455 | */ |
456 | - private function _get_errors( $data_array ) { |
|
456 | + private function _get_errors($data_array) { |
|
457 | 457 | $errors = array(); |
458 | 458 | $n = 0; |
459 | - while ( isset($data_array["L_ERRORCODE{$n}"]) ) { |
|
459 | + while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
460 | 460 | $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
461 | 461 | ? $data_array["L_ERRORCODE{$n}"] |
462 | 462 | : ''; |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | ? $data_array["L_LONGMESSAGE{$n}"] |
471 | 471 | : ''; |
472 | 472 | |
473 | - if ( $n === 0 ) { |
|
473 | + if ($n === 0) { |
|
474 | 474 | $errors = array( |
475 | 475 | 'L_ERRORCODE' => $l_error_code, |
476 | 476 | 'L_SHORTMESSAGE' => $l_short_message, |
@@ -478,10 +478,10 @@ discard block |
||
478 | 478 | 'L_SEVERITYCODE' => $l_severity_code |
479 | 479 | ); |
480 | 480 | } else { |
481 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
482 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
483 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
484 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
481 | + $errors['L_ERRORCODE'] .= ', '.$l_error_code; |
|
482 | + $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message; |
|
483 | + $errors['L_LONGMESSAGE'] .= ', '.$l_long_message; |
|
484 | + $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | $n++; |
@@ -286,41 +286,41 @@ discard block |
||
286 | 286 | $this->checkout->revisit |
287 | 287 | ); |
288 | 288 | foreach ( $registrations as $REG_ID => $registration ) { |
289 | - /** @var $registration EE_Registration */ |
|
290 | - // has this registration lost it's space ? |
|
289 | + /** @var $registration EE_Registration */ |
|
290 | + // has this registration lost it's space ? |
|
291 | 291 | if ( isset( $ejected_registrations[ $REG_ID ] ) ) { |
292 | 292 | $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
293 | 293 | continue; |
294 | 294 | } |
295 | - // event requires admin approval |
|
296 | - if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
297 | - // add event to list of events with pre-approval reg status |
|
298 | - $registrations_requiring_pre_approval[$REG_ID] = $registration; |
|
299 | - do_action( |
|
300 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
301 | - $registration->event(), |
|
302 | - $this |
|
303 | - ); |
|
304 | - continue; |
|
305 | - } |
|
306 | - if ( |
|
295 | + // event requires admin approval |
|
296 | + if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
297 | + // add event to list of events with pre-approval reg status |
|
298 | + $registrations_requiring_pre_approval[$REG_ID] = $registration; |
|
299 | + do_action( |
|
300 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
301 | + $registration->event(), |
|
302 | + $this |
|
303 | + ); |
|
304 | + continue; |
|
305 | + } |
|
306 | + if ( |
|
307 | 307 | // returning registrant |
308 | 308 | $this->checkout->revisit |
309 | 309 | // anything other than Approved |
310 | 310 | && $registration->status_ID() !== EEM_Registration::status_id_approved |
311 | - && ( |
|
312 | - $registration->event()->is_sold_out() |
|
313 | - || $registration->event()->is_sold_out( true ) |
|
314 | - ) |
|
315 | - ) { |
|
316 | - // add event to list of events that are sold out |
|
317 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
318 | - do_action( |
|
319 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
320 | - $registration->event(), |
|
321 | - $this |
|
322 | - ); |
|
323 | - continue; |
|
311 | + && ( |
|
312 | + $registration->event()->is_sold_out() |
|
313 | + || $registration->event()->is_sold_out( true ) |
|
314 | + ) |
|
315 | + ) { |
|
316 | + // add event to list of events that are sold out |
|
317 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
318 | + do_action( |
|
319 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
320 | + $registration->event(), |
|
321 | + $this |
|
322 | + ); |
|
323 | + continue; |
|
324 | 324 | } |
325 | 325 | // are they allowed to pay now and is there monies owing? |
326 | 326 | if ( $registration->owes_monies_and_can_pay() ) { |
@@ -428,11 +428,11 @@ discard block |
||
428 | 428 | new EE_Billable_Line_Item_Filter( |
429 | 429 | EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
430 | 430 | EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
431 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
432 | - ) |
|
431 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
432 | + ) |
|
433 | 433 | ) |
434 | 434 | ) |
435 | - ); |
|
435 | + ); |
|
436 | 436 | $line_item_filter_collection->add( new EE_Non_Zero_Line_Item_Filter() ); |
437 | 437 | return $line_item_filter_collection; |
438 | 438 | } |
@@ -481,46 +481,46 @@ discard block |
||
481 | 481 | * @throws \EE_Error |
482 | 482 | */ |
483 | 483 | public static function find_registrations_that_lost_their_space( array $registrations, $revisit = false ) { |
484 | - // registrations per event |
|
484 | + // registrations per event |
|
485 | 485 | $event_reg_count = array(); |
486 | 486 | // spaces left per event |
487 | 487 | $event_spaces_remaining = array(); |
488 | - // tickets left sorted by ID |
|
489 | - $tickets_remaining = array(); |
|
490 | - // registrations that have lost their space |
|
488 | + // tickets left sorted by ID |
|
489 | + $tickets_remaining = array(); |
|
490 | + // registrations that have lost their space |
|
491 | 491 | $ejected_registrations = array(); |
492 | 492 | foreach ( $registrations as $REG_ID => $registration ) { |
493 | - if ( |
|
494 | - $registration->status_ID() === EEM_Registration::status_id_approved |
|
495 | - || apply_filters( |
|
496 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
497 | - false, |
|
498 | - $registration, |
|
499 | - $revisit |
|
500 | - ) |
|
501 | - ) { |
|
502 | - continue; |
|
493 | + if ( |
|
494 | + $registration->status_ID() === EEM_Registration::status_id_approved |
|
495 | + || apply_filters( |
|
496 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
497 | + false, |
|
498 | + $registration, |
|
499 | + $revisit |
|
500 | + ) |
|
501 | + ) { |
|
502 | + continue; |
|
503 | 503 | } |
504 | 504 | $EVT_ID = $registration->event_ID(); |
505 | - $ticket = $registration->ticket(); |
|
506 | - if ( ! isset($tickets_remaining[$ticket->ID()])) { |
|
507 | - $tickets_remaining[$ticket->ID()] = $ticket->remaining(); |
|
508 | - } |
|
509 | - if ($tickets_remaining[$ticket->ID()] > 0) { |
|
510 | - if ( ! isset($event_reg_count[$EVT_ID])) { |
|
511 | - $event_reg_count[$EVT_ID] = 0; |
|
512 | - } |
|
513 | - $event_reg_count[$EVT_ID]++; |
|
514 | - if ( ! isset($event_spaces_remaining[$EVT_ID])) { |
|
515 | - $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale(); |
|
516 | - } |
|
517 | - } |
|
505 | + $ticket = $registration->ticket(); |
|
506 | + if ( ! isset($tickets_remaining[$ticket->ID()])) { |
|
507 | + $tickets_remaining[$ticket->ID()] = $ticket->remaining(); |
|
508 | + } |
|
509 | + if ($tickets_remaining[$ticket->ID()] > 0) { |
|
510 | + if ( ! isset($event_reg_count[$EVT_ID])) { |
|
511 | + $event_reg_count[$EVT_ID] = 0; |
|
512 | + } |
|
513 | + $event_reg_count[$EVT_ID]++; |
|
514 | + if ( ! isset($event_spaces_remaining[$EVT_ID])) { |
|
515 | + $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale(); |
|
516 | + } |
|
517 | + } |
|
518 | 518 | if ( |
519 | 519 | $revisit |
520 | 520 | && ( |
521 | - $tickets_remaining[$ticket->ID()] === 0 |
|
522 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
523 | - ) |
|
521 | + $tickets_remaining[$ticket->ID()] === 0 |
|
522 | + || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
523 | + ) |
|
524 | 524 | ) { |
525 | 525 | $ejected_registrations[ $REG_ID ] = $registration->event(); |
526 | 526 | if ( $registration->status_ID() !== EEM_Registration::status_id_wait_list ) { |
@@ -589,9 +589,9 @@ discard block |
||
589 | 589 | 'layout_strategy' => new EE_Template_Layout( |
590 | 590 | array( |
591 | 591 | 'layout_template_file' => SPCO_REG_STEPS_PATH |
592 | - . $this->_slug |
|
593 | - . DS |
|
594 | - . 'sold_out_events.template.php', |
|
592 | + . $this->_slug |
|
593 | + . DS |
|
594 | + . 'sold_out_events.template.php', |
|
595 | 595 | 'template_args' => apply_filters( |
596 | 596 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
597 | 597 | array( |
@@ -644,9 +644,9 @@ discard block |
||
644 | 644 | 'layout_strategy' => new EE_Template_Layout( |
645 | 645 | array( |
646 | 646 | 'layout_template_file' => SPCO_REG_STEPS_PATH |
647 | - . $this->_slug |
|
648 | - . DS |
|
649 | - . 'sold_out_events.template.php', |
|
647 | + . $this->_slug |
|
648 | + . DS |
|
649 | + . 'sold_out_events.template.php', |
|
650 | 650 | 'template_args' => apply_filters( |
651 | 651 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
652 | 652 | array( |
@@ -694,9 +694,9 @@ discard block |
||
694 | 694 | 'layout_strategy' => new EE_Template_Layout( |
695 | 695 | array( |
696 | 696 | 'layout_template_file' => SPCO_REG_STEPS_PATH |
697 | - . $this->_slug |
|
698 | - . DS |
|
699 | - . 'events_requiring_pre_approval.template.php', // layout_template |
|
697 | + . $this->_slug |
|
698 | + . DS |
|
699 | + . 'events_requiring_pre_approval.template.php', // layout_template |
|
700 | 700 | 'template_args' => apply_filters( |
701 | 701 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
702 | 702 | array( |
@@ -734,9 +734,9 @@ discard block |
||
734 | 734 | 'layout_strategy' => new EE_Template_Layout( |
735 | 735 | array( |
736 | 736 | 'layout_template_file' => SPCO_REG_STEPS_PATH |
737 | - . $this->_slug |
|
738 | - . DS |
|
739 | - . 'no_payment_required.template.php', // layout_template |
|
737 | + . $this->_slug |
|
738 | + . DS |
|
739 | + . 'no_payment_required.template.php', // layout_template |
|
740 | 740 | 'template_args' => apply_filters( |
741 | 741 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
742 | 742 | array( |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
965 | 965 | } |
966 | 966 | $payment_methods_billing_info[ $payment_method->slug() |
967 | - . '-info' ] = $this->_payment_method_billing_info( |
|
967 | + . '-info' ] = $this->_payment_method_billing_info( |
|
968 | 968 | $payment_method |
969 | 969 | ); |
970 | 970 | } |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | // fill form with attendee info if applicable |
1153 | 1153 | if ( |
1154 | 1154 | $payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
1155 | - && $this->checkout->transaction_has_primary_registrant() |
|
1155 | + && $this->checkout->transaction_has_primary_registrant() |
|
1156 | 1156 | ) { |
1157 | 1157 | $payment_method_billing_form->populate_from_attendee( |
1158 | 1158 | $this->checkout->transaction->primary_registration()->attendee() |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | // and debug content |
1162 | 1162 | if ( |
1163 | 1163 | $payment_method_billing_form instanceof EE_Billing_Info_Form |
1164 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1164 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1165 | 1165 | ) { |
1166 | 1166 | $payment_method_billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
1167 | 1167 | $payment_method_billing_form |
@@ -1336,7 +1336,7 @@ discard block |
||
1336 | 1336 | } |
1337 | 1337 | // and debug content |
1338 | 1338 | if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form |
1339 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1339 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1340 | 1340 | ) { |
1341 | 1341 | $this->checkout->billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
1342 | 1342 | $this->checkout->billing_form |
@@ -1506,8 +1506,8 @@ discard block |
||
1506 | 1506 | } |
1507 | 1507 | // does this attendee already exist in the db ? we're searching using a combination of first name, last name, AND email address |
1508 | 1508 | if ( ! empty( $attendee_data['ATT_fname'] ) |
1509 | - && ! empty( $attendee_data['ATT_lname'] ) |
|
1510 | - && ! empty( $attendee_data['ATT_email'] ) |
|
1509 | + && ! empty( $attendee_data['ATT_lname'] ) |
|
1510 | + && ! empty( $attendee_data['ATT_email'] ) |
|
1511 | 1511 | ) { |
1512 | 1512 | $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
1513 | 1513 | array( |
@@ -1754,7 +1754,7 @@ discard block |
||
1754 | 1754 | $payment_status = $payment->status(); |
1755 | 1755 | if ( |
1756 | 1756 | $payment_status === EEM_Payment::status_id_approved |
1757 | - || $payment_status === EEM_Payment::status_id_pending |
|
1757 | + || $payment_status === EEM_Payment::status_id_pending |
|
1758 | 1758 | ) { |
1759 | 1759 | return true; |
1760 | 1760 | } else { |
@@ -1980,8 +1980,8 @@ discard block |
||
1980 | 1980 | return false; |
1981 | 1981 | } |
1982 | 1982 | if ( ! $primary_registration->_add_relation_to( $this->checkout->primary_attendee_obj, 'Attendee' ) |
1983 | - instanceof |
|
1984 | - EE_Attendee |
|
1983 | + instanceof |
|
1984 | + EE_Attendee |
|
1985 | 1985 | ) { |
1986 | 1986 | EE_Error::add_error( |
1987 | 1987 | sprintf( |
@@ -2454,14 +2454,14 @@ discard block |
||
2454 | 2454 | |
2455 | 2455 | |
2456 | 2456 | |
2457 | - /** |
|
2458 | - * _validate_return |
|
2459 | - * |
|
2460 | - * @access private |
|
2461 | - * @return void |
|
2462 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2463 | - * @throws \EE_Error |
|
2464 | - */ |
|
2457 | + /** |
|
2458 | + * _validate_return |
|
2459 | + * |
|
2460 | + * @access private |
|
2461 | + * @return void |
|
2462 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2463 | + * @throws \EE_Error |
|
2464 | + */ |
|
2465 | 2465 | private function _validate_offsite_return() { |
2466 | 2466 | $TXN_ID = (int)EE_Registry::instance()->REQ->get( 'spco_txn', 0 ); |
2467 | 2467 | if ( $TXN_ID !== $this->checkout->transaction->ID() ) { |
@@ -2487,20 +2487,20 @@ discard block |
||
2487 | 2487 | ? $primary_registrant->session_ID() |
2488 | 2488 | : null; |
2489 | 2489 | // validate current Session ID and compare against valid TXN session ID |
2490 | - if ( |
|
2491 | - $invalid_TXN // if this is already true, then skip other checks |
|
2492 | - || EE_Session::instance()->id() === null |
|
2493 | - || ( |
|
2494 | - // WARNING !!! |
|
2495 | - // this could be PayPal sending back duplicate requests (ya they do that) |
|
2496 | - // or it **could** mean someone is simply registering AGAIN after having just done so |
|
2497 | - // so now we need to determine if this current TXN looks valid or not |
|
2498 | - // and whether this reg step has even been started ? |
|
2499 | - EE_Session::instance()->id() === $valid_TXN_SID |
|
2500 | - // really? you're half way through this reg step, but you never started it ? |
|
2501 | - && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
2502 | - ) |
|
2503 | - ) { |
|
2490 | + if ( |
|
2491 | + $invalid_TXN // if this is already true, then skip other checks |
|
2492 | + || EE_Session::instance()->id() === null |
|
2493 | + || ( |
|
2494 | + // WARNING !!! |
|
2495 | + // this could be PayPal sending back duplicate requests (ya they do that) |
|
2496 | + // or it **could** mean someone is simply registering AGAIN after having just done so |
|
2497 | + // so now we need to determine if this current TXN looks valid or not |
|
2498 | + // and whether this reg step has even been started ? |
|
2499 | + EE_Session::instance()->id() === $valid_TXN_SID |
|
2500 | + // really? you're half way through this reg step, but you never started it ? |
|
2501 | + && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
2502 | + ) |
|
2503 | + ) { |
|
2504 | 2504 | $invalid_TXN = true; |
2505 | 2505 | } |
2506 | 2506 | if ( $invalid_TXN ) { |
@@ -2702,19 +2702,19 @@ discard block |
||
2702 | 2702 | |
2703 | 2703 | |
2704 | 2704 | |
2705 | - /** |
|
2706 | - * __sleep |
|
2707 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization |
|
2708 | - * EE_Checkout will handle the reimplementation of itself upon waking, |
|
2709 | - * but we won't bother with the reg form, because if needed, it will be regenerated anyways |
|
2710 | - * |
|
2711 | - * @return array |
|
2712 | - */ |
|
2713 | - public function __sleep() |
|
2714 | - { |
|
2715 | - // remove the reg form and the checkout |
|
2716 | - return array_diff( array_keys( get_object_vars( $this ) ), array( 'reg_form', 'checkout', 'line_item_display' ) ); |
|
2717 | - } |
|
2705 | + /** |
|
2706 | + * __sleep |
|
2707 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization |
|
2708 | + * EE_Checkout will handle the reimplementation of itself upon waking, |
|
2709 | + * but we won't bother with the reg form, because if needed, it will be regenerated anyways |
|
2710 | + * |
|
2711 | + * @return array |
|
2712 | + */ |
|
2713 | + public function __sleep() |
|
2714 | + { |
|
2715 | + // remove the reg form and the checkout |
|
2716 | + return array_diff( array_keys( get_object_vars( $this ) ), array( 'reg_form', 'checkout', 'line_item_display' ) ); |
|
2717 | + } |
|
2718 | 2718 | |
2719 | 2719 | |
2720 | 2720 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -38,32 +38,32 @@ discard block |
||
38 | 38 | public static function set_hooks() { |
39 | 39 | add_filter( |
40 | 40 | 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
41 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters' ) |
|
41 | + array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
42 | 42 | ); |
43 | 43 | add_action( |
44 | 44 | 'wp_ajax_switch_spco_billing_form', |
45 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form' ) |
|
45 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
46 | 46 | ); |
47 | 47 | add_action( |
48 | 48 | 'wp_ajax_nopriv_switch_spco_billing_form', |
49 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form' ) |
|
49 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
50 | 50 | ); |
51 | - add_action( 'wp_ajax_save_payer_details', array( 'EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details' ) ); |
|
51 | + add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
52 | 52 | add_action( |
53 | 53 | 'wp_ajax_nopriv_save_payer_details', |
54 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details' ) |
|
54 | + array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
55 | 55 | ); |
56 | 56 | add_action( |
57 | 57 | 'wp_ajax_get_transaction_details_for_gateways', |
58 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details' ) |
|
58 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
59 | 59 | ); |
60 | 60 | add_action( |
61 | 61 | 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
62 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details' ) |
|
62 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
63 | 63 | ); |
64 | 64 | add_filter( |
65 | 65 | 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
66 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method' ), |
|
66 | + array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
67 | 67 | 10, |
68 | 68 | 1 |
69 | 69 | ); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @throws \EE_Error |
78 | 78 | */ |
79 | 79 | public static function switch_spco_billing_form() { |
80 | - EED_Single_Page_Checkout::process_ajax_request( 'switch_payment_method' ); |
|
80 | + EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @throws \EE_Error |
89 | 89 | */ |
90 | 90 | public static function save_payer_details() { |
91 | - EED_Single_Page_Checkout::process_ajax_request( 'save_payer_details_via_ajax' ); |
|
91 | + EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @throws \EE_Error |
100 | 100 | */ |
101 | 101 | public static function get_transaction_details() { |
102 | - EED_Single_Page_Checkout::process_ajax_request( 'get_transaction_details_for_gateways' ); |
|
102 | + EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | * @access public |
127 | 127 | * @param EE_Checkout $checkout |
128 | 128 | */ |
129 | - public function __construct( EE_Checkout $checkout ) { |
|
129 | + public function __construct(EE_Checkout $checkout) { |
|
130 | 130 | $this->_slug = 'payment_options'; |
131 | - $this->_name = __( 'Payment Options', 'event_espresso' ); |
|
132 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
131 | + $this->_name = __('Payment Options', 'event_espresso'); |
|
132 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'payment_options_main.template.php'; |
|
133 | 133 | $this->checkout = $checkout; |
134 | 134 | $this->_reset_success_message(); |
135 | 135 | $this->set_instructions( |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | /** |
155 | 155 | * @param null $line_item_display |
156 | 156 | */ |
157 | - public function set_line_item_display( $line_item_display ) { |
|
157 | + public function set_line_item_display($line_item_display) { |
|
158 | 158 | $this->line_item_display = $line_item_display; |
159 | 159 | } |
160 | 160 | |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | /** |
173 | 173 | * @param boolean $handle_IPN_in_this_request |
174 | 174 | */ |
175 | - public function set_handle_IPN_in_this_request( $handle_IPN_in_this_request ) { |
|
176 | - $this->handle_IPN_in_this_request = filter_var( $handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN ); |
|
175 | + public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) { |
|
176 | + $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | public function enqueue_styles_and_scripts() { |
209 | 209 | $transaction = $this->checkout->transaction; |
210 | 210 | //if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
211 | - if( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats( $transaction->remaining(), 0 ) ) { |
|
211 | + if ( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
212 | 212 | return; |
213 | 213 | } |
214 | - foreach( EEM_Payment_Method::instance()->get_all_for_transaction( $transaction, EEM_Payment_Method::scope_cart ) as $payment_method ) { |
|
214 | + foreach (EEM_Payment_Method::instance()->get_all_for_transaction($transaction, EEM_Payment_Method::scope_cart) as $payment_method) { |
|
215 | 215 | $type_obj = $payment_method->type_obj(); |
216 | - if( $type_obj instanceof EE_PMT_Base ) { |
|
217 | - $billing_form = $type_obj->generate_new_billing_form( $transaction ); |
|
218 | - if( $billing_form instanceof EE_Form_Section_Proper ) { |
|
216 | + if ($type_obj instanceof EE_PMT_Base) { |
|
217 | + $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
218 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
219 | 219 | $billing_form->enqueue_js(); |
220 | 220 | } |
221 | 221 | } |
@@ -240,20 +240,20 @@ discard block |
||
240 | 240 | // $ 0.00 transactions (no payment required) |
241 | 241 | ! $this->checkout->payment_required() |
242 | 242 | // but do NOT remove if current action being called belongs to this reg step |
243 | - && ! is_callable( array( $this, $this->checkout->action ) ) |
|
243 | + && ! is_callable(array($this, $this->checkout->action)) |
|
244 | 244 | && ! $this->completed() |
245 | 245 | ) { |
246 | 246 | // and if so, then we no longer need the Payment Options step |
247 | - if ( $this->is_current_step() ) { |
|
247 | + if ($this->is_current_step()) { |
|
248 | 248 | $this->checkout->generate_reg_form = false; |
249 | 249 | } |
250 | - $this->checkout->remove_reg_step( $this->_slug ); |
|
250 | + $this->checkout->remove_reg_step($this->_slug); |
|
251 | 251 | // DEBUG LOG |
252 | 252 | //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
253 | 253 | return false; |
254 | 254 | } |
255 | 255 | // load EEM_Payment_Method |
256 | - EE_Registry::instance()->load_model( 'Payment_Method' ); |
|
256 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
257 | 257 | // get all active payment methods |
258 | 258 | $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
259 | 259 | $this->checkout->transaction, |
@@ -280,16 +280,16 @@ discard block |
||
280 | 280 | $insufficient_spaces_available = array(); |
281 | 281 | $no_payment_required = true; |
282 | 282 | // loop thru registrations to gather info |
283 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
283 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
284 | 284 | $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
285 | 285 | $registrations, |
286 | 286 | $this->checkout->revisit |
287 | 287 | ); |
288 | - foreach ( $registrations as $REG_ID => $registration ) { |
|
288 | + foreach ($registrations as $REG_ID => $registration) { |
|
289 | 289 | /** @var $registration EE_Registration */ |
290 | 290 | // has this registration lost it's space ? |
291 | - if ( isset( $ejected_registrations[ $REG_ID ] ) ) { |
|
292 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
291 | + if (isset($ejected_registrations[$REG_ID])) { |
|
292 | + $insufficient_spaces_available[$registration->event()->ID()] = $registration->event(); |
|
293 | 293 | continue; |
294 | 294 | } |
295 | 295 | // event requires admin approval |
@@ -310,11 +310,11 @@ discard block |
||
310 | 310 | && $registration->status_ID() !== EEM_Registration::status_id_approved |
311 | 311 | && ( |
312 | 312 | $registration->event()->is_sold_out() |
313 | - || $registration->event()->is_sold_out( true ) |
|
313 | + || $registration->event()->is_sold_out(true) |
|
314 | 314 | ) |
315 | 315 | ) { |
316 | 316 | // add event to list of events that are sold out |
317 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
317 | + $sold_out_events[$registration->event()->ID()] = $registration->event(); |
|
318 | 318 | do_action( |
319 | 319 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
320 | 320 | $registration->event(), |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | continue; |
324 | 324 | } |
325 | 325 | // are they allowed to pay now and is there monies owing? |
326 | - if ( $registration->owes_monies_and_can_pay() ) { |
|
327 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
326 | + if ($registration->owes_monies_and_can_pay()) { |
|
327 | + $registrations_requiring_payment[$REG_ID] = $registration; |
|
328 | 328 | do_action( |
329 | 329 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
330 | 330 | $registration->event(), |
@@ -335,29 +335,29 @@ discard block |
||
335 | 335 | && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
336 | 336 | && $registration->ticket()->is_free() |
337 | 337 | ) { |
338 | - $registrations_for_free_events[ $registration->event()->ID() ] = $registration; |
|
338 | + $registrations_for_free_events[$registration->event()->ID()] = $registration; |
|
339 | 339 | } |
340 | 340 | } |
341 | 341 | $subsections = array(); |
342 | 342 | // now decide which template to load |
343 | - if ( ! empty( $sold_out_events ) ) { |
|
344 | - $subsections['sold_out_events'] = $this->_sold_out_events( $sold_out_events ); |
|
343 | + if ( ! empty($sold_out_events)) { |
|
344 | + $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
345 | 345 | } |
346 | - if ( ! empty( $insufficient_spaces_available ) ) { |
|
346 | + if ( ! empty($insufficient_spaces_available)) { |
|
347 | 347 | $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
348 | 348 | $insufficient_spaces_available |
349 | 349 | ); |
350 | 350 | } |
351 | - if ( ! empty( $registrations_requiring_pre_approval ) ) { |
|
351 | + if ( ! empty($registrations_requiring_pre_approval)) { |
|
352 | 352 | $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
353 | 353 | $registrations_requiring_pre_approval |
354 | 354 | ); |
355 | 355 | } |
356 | - if ( ! empty( $registrations_for_free_events ) ) { |
|
357 | - $subsections['no_payment_required'] = $this->_no_payment_required( $registrations_for_free_events ); |
|
356 | + if ( ! empty($registrations_for_free_events)) { |
|
357 | + $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
358 | 358 | } |
359 | - if ( ! empty( $registrations_requiring_payment ) ) { |
|
360 | - if ( $this->checkout->amount_owing > 0 ) { |
|
359 | + if ( ! empty($registrations_requiring_payment)) { |
|
360 | + if ($this->checkout->amount_owing > 0) { |
|
361 | 361 | // autoload Line_Item_Display classes |
362 | 362 | EEH_Autoloader::register_line_item_filter_autoloaders(); |
363 | 363 | $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
@@ -370,15 +370,15 @@ discard block |
||
370 | 370 | /** @var EE_Line_Item $filtered_line_item_tree */ |
371 | 371 | $filtered_line_item_tree = $line_item_filter_processor->process(); |
372 | 372 | EEH_Autoloader::register_line_item_display_autoloaders(); |
373 | - $this->set_line_item_display( new EE_Line_Item_Display( 'spco' ) ); |
|
373 | + $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
374 | 374 | $subsections['payment_options'] = $this->_display_payment_options( |
375 | 375 | $this->line_item_display->display_line_item( |
376 | 376 | $filtered_line_item_tree, |
377 | - array( 'registrations' => $registrations ) |
|
377 | + array('registrations' => $registrations) |
|
378 | 378 | ) |
379 | 379 | ); |
380 | 380 | $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
381 | - $this->_apply_registration_payments_to_amount_owing( $registrations ); |
|
381 | + $this->_apply_registration_payments_to_amount_owing($registrations); |
|
382 | 382 | } |
383 | 383 | $no_payment_required = false; |
384 | 384 | } else { |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | $this->_save_selected_method_of_payment(); |
388 | 388 | |
389 | 389 | $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
390 | - $subsections['extra_hidden_inputs' ] = $this->_extra_hidden_inputs( $no_payment_required ); |
|
390 | + $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
391 | 391 | |
392 | 392 | return new EE_Form_Section_Proper( |
393 | 393 | array( |
@@ -414,14 +414,14 @@ discard block |
||
414 | 414 | * @return \EE_Line_Item_Filter_Collection |
415 | 415 | * @throws \EE_Error |
416 | 416 | */ |
417 | - public static function add_spco_line_item_filters( EE_Line_Item_Filter_Collection $line_item_filter_collection ) { |
|
418 | - if ( ! EE_Registry::instance()->SSN instanceof EE_Session ) { |
|
417 | + public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) { |
|
418 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
419 | 419 | return $line_item_filter_collection; |
420 | 420 | } |
421 | - if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout ) { |
|
421 | + if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
422 | 422 | return $line_item_filter_collection; |
423 | 423 | } |
424 | - if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction ) { |
|
424 | + if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
425 | 425 | return $line_item_filter_collection; |
426 | 426 | } |
427 | 427 | $line_item_filter_collection->add( |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | ) |
434 | 434 | ) |
435 | 435 | ); |
436 | - $line_item_filter_collection->add( new EE_Non_Zero_Line_Item_Filter() ); |
|
436 | + $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
437 | 437 | return $line_item_filter_collection; |
438 | 438 | } |
439 | 439 | |
@@ -449,15 +449,15 @@ discard block |
||
449 | 449 | * @return \EE_Registration[] |
450 | 450 | * @throws \EE_Error |
451 | 451 | */ |
452 | - public static function remove_ejected_registrations( array $registrations ) { |
|
452 | + public static function remove_ejected_registrations(array $registrations) { |
|
453 | 453 | $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
454 | 454 | $registrations, |
455 | 455 | EE_Registry::instance()->SSN->checkout()->revisit |
456 | 456 | ); |
457 | - foreach ( $registrations as $REG_ID => $registration ) { |
|
457 | + foreach ($registrations as $REG_ID => $registration) { |
|
458 | 458 | // has this registration lost it's space ? |
459 | - if ( isset( $ejected_registrations[ $REG_ID ] ) ) { |
|
460 | - unset( $registrations[ $REG_ID ] ); |
|
459 | + if (isset($ejected_registrations[$REG_ID])) { |
|
460 | + unset($registrations[$REG_ID]); |
|
461 | 461 | continue; |
462 | 462 | } |
463 | 463 | } |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * @return array |
481 | 481 | * @throws \EE_Error |
482 | 482 | */ |
483 | - public static function find_registrations_that_lost_their_space( array $registrations, $revisit = false ) { |
|
483 | + public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) { |
|
484 | 484 | // registrations per event |
485 | 485 | $event_reg_count = array(); |
486 | 486 | // spaces left per event |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | $tickets_remaining = array(); |
490 | 490 | // registrations that have lost their space |
491 | 491 | $ejected_registrations = array(); |
492 | - foreach ( $registrations as $REG_ID => $registration ) { |
|
492 | + foreach ($registrations as $REG_ID => $registration) { |
|
493 | 493 | if ( |
494 | 494 | $registration->status_ID() === EEM_Registration::status_id_approved |
495 | 495 | || apply_filters( |
@@ -519,13 +519,13 @@ discard block |
||
519 | 519 | $revisit |
520 | 520 | && ( |
521 | 521 | $tickets_remaining[$ticket->ID()] === 0 |
522 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
522 | + || $event_reg_count[$EVT_ID] > $event_spaces_remaining[$EVT_ID] |
|
523 | 523 | ) |
524 | 524 | ) { |
525 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
526 | - if ( $registration->status_ID() !== EEM_Registration::status_id_wait_list ) { |
|
525 | + $ejected_registrations[$REG_ID] = $registration->event(); |
|
526 | + if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
527 | 527 | /** @type EE_Registration_Processor $registration_processor */ |
528 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
528 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
529 | 529 | // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
530 | 530 | $registration_processor->manually_update_registration_status( |
531 | 531 | $registration, |
@@ -560,8 +560,8 @@ discard block |
||
560 | 560 | * @return void |
561 | 561 | */ |
562 | 562 | protected function _hide_reg_step_submit_button_if_revisit() { |
563 | - if ( $this->checkout->revisit ) { |
|
564 | - add_filter( 'FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string' ); |
|
563 | + if ($this->checkout->revisit) { |
|
564 | + add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
@@ -575,13 +575,13 @@ discard block |
||
575 | 575 | * @return \EE_Form_Section_Proper |
576 | 576 | * @throws \EE_Error |
577 | 577 | */ |
578 | - private function _sold_out_events( $sold_out_events_array = array() ) { |
|
578 | + private function _sold_out_events($sold_out_events_array = array()) { |
|
579 | 579 | // set some defaults |
580 | 580 | $this->checkout->selected_method_of_payment = 'events_sold_out'; |
581 | 581 | $sold_out_events = ''; |
582 | - foreach ( $sold_out_events_array as $sold_out_event ) { |
|
582 | + foreach ($sold_out_events_array as $sold_out_event) { |
|
583 | 583 | $sold_out_events .= EEH_HTML::li( |
584 | - EEH_HTML::span( ' ' .$sold_out_event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text' ) |
|
584 | + EEH_HTML::span(' '.$sold_out_event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
585 | 585 | ); |
586 | 586 | } |
587 | 587 | return new EE_Form_Section_Proper( |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | 'sold_out_events_msg' => apply_filters( |
600 | 600 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
601 | 601 | sprintf( |
602 | - __( 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', 'event_espresso' ), |
|
602 | + __('It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', 'event_espresso'), |
|
603 | 603 | '<strong>', |
604 | 604 | '</strong>', |
605 | 605 | '<br />' |
@@ -624,14 +624,14 @@ discard block |
||
624 | 624 | * @return \EE_Form_Section_Proper |
625 | 625 | * @throws \EE_Error |
626 | 626 | */ |
627 | - private function _insufficient_spaces_available( $insufficient_spaces_events_array = array() ) { |
|
627 | + private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) { |
|
628 | 628 | // set some defaults |
629 | 629 | $this->checkout->selected_method_of_payment = 'invoice'; |
630 | 630 | $insufficient_space_events = ''; |
631 | - foreach ( $insufficient_spaces_events_array as $event ) { |
|
632 | - if ( $event instanceof EE_Event ) { |
|
631 | + foreach ($insufficient_spaces_events_array as $event) { |
|
632 | + if ($event instanceof EE_Event) { |
|
633 | 633 | $insufficient_space_events .= EEH_HTML::li( |
634 | - EEH_HTML::span( ' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text' ) |
|
634 | + EEH_HTML::span(' '.$event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
635 | 635 | ); |
636 | 636 | } |
637 | 637 | } |
@@ -675,17 +675,17 @@ discard block |
||
675 | 675 | * @return \EE_Form_Section_Proper |
676 | 676 | * @throws \EE_Error |
677 | 677 | */ |
678 | - private function _registrations_requiring_pre_approval( $registrations_requiring_pre_approval = array() ) { |
|
678 | + private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) { |
|
679 | 679 | $events_requiring_pre_approval = ''; |
680 | - foreach ( $registrations_requiring_pre_approval as $registration ) { |
|
681 | - if ( $registration instanceof EE_Registration && $registration->event() instanceof EE_Event ) { |
|
682 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
680 | + foreach ($registrations_requiring_pre_approval as $registration) { |
|
681 | + if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
682 | + $events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li( |
|
683 | 683 | EEH_HTML::span( |
684 | 684 | '', |
685 | 685 | '', |
686 | 686 | 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
687 | 687 | ) |
688 | - . EEH_HTML::span( $registration->event()->name(), '', 'orange-text' ) |
|
688 | + . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
689 | 689 | ); |
690 | 690 | } |
691 | 691 | } |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | 'template_args' => apply_filters( |
701 | 701 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
702 | 702 | array( |
703 | - 'events_requiring_pre_approval' => implode( '', $events_requiring_pre_approval ), |
|
703 | + 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
704 | 704 | 'events_requiring_pre_approval_msg' => apply_filters( |
705 | 705 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
706 | 706 | __( |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | * @return \EE_Form_Section_Proper |
726 | 726 | * @throws \EE_Error |
727 | 727 | */ |
728 | - private function _no_payment_required( $registrations_for_free_events = array() ) { |
|
728 | + private function _no_payment_required($registrations_for_free_events = array()) { |
|
729 | 729 | // set some defaults |
730 | 730 | $this->checkout->selected_method_of_payment = 'no_payment_required'; |
731 | 731 | // generate no_payment_required form |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | 'ticket_count' => array(), |
746 | 746 | 'registrations_for_free_events' => $registrations_for_free_events, |
747 | 747 | 'no_payment_required_msg' => EEH_HTML::p( |
748 | - __( 'This is a free event, so no billing will occur.', 'event_espresso' ) |
|
748 | + __('This is a free event, so no billing will occur.', 'event_espresso') |
|
749 | 749 | ) |
750 | 750 | ) |
751 | 751 | ), |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | * @return \EE_Form_Section_Proper |
765 | 765 | * @throws \EE_Error |
766 | 766 | */ |
767 | - private function _display_payment_options( $transaction_details = '' ) { |
|
767 | + private function _display_payment_options($transaction_details = '') { |
|
768 | 768 | // has method_of_payment been set by no-js user? |
769 | 769 | $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
770 | 770 | // build payment options form |
@@ -776,14 +776,14 @@ discard block |
||
776 | 776 | 'before_payment_options' => apply_filters( |
777 | 777 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
778 | 778 | new EE_Form_Section_Proper( |
779 | - array( 'layout_strategy' => new EE_Div_Per_Section_Layout() ) |
|
779 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
780 | 780 | ) |
781 | 781 | ), |
782 | 782 | 'payment_options' => $this->_setup_payment_options(), |
783 | 783 | 'after_payment_options' => apply_filters( |
784 | 784 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
785 | 785 | new EE_Form_Section_Proper( |
786 | - array( 'layout_strategy' => new EE_Div_Per_Section_Layout() ) |
|
786 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
787 | 787 | ) |
788 | 788 | ), |
789 | 789 | ), |
@@ -814,10 +814,10 @@ discard block |
||
814 | 814 | * @return \EE_Form_Section_Proper |
815 | 815 | * @throws \EE_Error |
816 | 816 | */ |
817 | - private function _extra_hidden_inputs( $no_payment_required = true ) { |
|
817 | + private function _extra_hidden_inputs($no_payment_required = true) { |
|
818 | 818 | return new EE_Form_Section_Proper( |
819 | 819 | array( |
820 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
820 | + 'html_id' => 'ee-'.$this->slug().'-extra-hidden-inputs', |
|
821 | 821 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
822 | 822 | 'subsections' => array( |
823 | 823 | 'spco_no_payment_required' => new EE_Hidden_Input( |
@@ -849,16 +849,16 @@ discard block |
||
849 | 849 | * @access protected |
850 | 850 | * @param array $registrations |
851 | 851 | */ |
852 | - protected function _apply_registration_payments_to_amount_owing( array $registrations ) { |
|
852 | + protected function _apply_registration_payments_to_amount_owing(array $registrations) { |
|
853 | 853 | $payments = array(); |
854 | - foreach ( $registrations as $registration ) { |
|
855 | - if ( $registration instanceof EE_Registration && $registration->owes_monies_and_can_pay() ) { |
|
854 | + foreach ($registrations as $registration) { |
|
855 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
856 | 856 | $payments += $registration->registration_payments(); |
857 | 857 | } |
858 | 858 | } |
859 | - if ( ! empty( $payments ) ) { |
|
860 | - foreach ( $payments as $payment ) { |
|
861 | - if ( $payment instanceof EE_Registration_Payment ) { |
|
859 | + if ( ! empty($payments)) { |
|
860 | + foreach ($payments as $payment) { |
|
861 | + if ($payment instanceof EE_Registration_Payment) { |
|
862 | 862 | $this->checkout->amount_owing -= $payment->amount(); |
863 | 863 | } |
864 | 864 | } |
@@ -874,11 +874,11 @@ discard block |
||
874 | 874 | * @param bool $force_reset |
875 | 875 | * @return void |
876 | 876 | */ |
877 | - private function _reset_selected_method_of_payment( $force_reset = false ) { |
|
877 | + private function _reset_selected_method_of_payment($force_reset = false) { |
|
878 | 878 | $reset_payment_method = $force_reset |
879 | 879 | ? true |
880 | - : sanitize_text_field( EE_Registry::instance()->REQ->get( 'reset_payment_method', false ) ); |
|
881 | - if ( $reset_payment_method ) { |
|
880 | + : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
881 | + if ($reset_payment_method) { |
|
882 | 882 | $this->checkout->selected_method_of_payment = null; |
883 | 883 | $this->checkout->payment_method = null; |
884 | 884 | $this->checkout->billing_form = null; |
@@ -897,12 +897,12 @@ discard block |
||
897 | 897 | * @param string $selected_method_of_payment |
898 | 898 | * @return void |
899 | 899 | */ |
900 | - private function _save_selected_method_of_payment( $selected_method_of_payment = '' ) { |
|
901 | - $selected_method_of_payment = ! empty( $selected_method_of_payment ) |
|
900 | + private function _save_selected_method_of_payment($selected_method_of_payment = '') { |
|
901 | + $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
902 | 902 | ? $selected_method_of_payment |
903 | 903 | : $this->checkout->selected_method_of_payment; |
904 | 904 | EE_Registry::instance()->SSN->set_session_data( |
905 | - array( 'selected_method_of_payment' => $selected_method_of_payment ) |
|
905 | + array('selected_method_of_payment' => $selected_method_of_payment) |
|
906 | 906 | ); |
907 | 907 | } |
908 | 908 | |
@@ -918,19 +918,19 @@ discard block |
||
918 | 918 | // load payment method classes |
919 | 919 | $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
920 | 920 | // switch up header depending on number of available payment methods |
921 | - $payment_method_header = count( $this->checkout->available_payment_methods ) > 1 |
|
921 | + $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
922 | 922 | ? apply_filters( |
923 | 923 | 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
924 | - __( 'Please Select Your Method of Payment', 'event_espresso' ) |
|
924 | + __('Please Select Your Method of Payment', 'event_espresso') |
|
925 | 925 | ) |
926 | 926 | : apply_filters( |
927 | 927 | 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
928 | - __( 'Method of Payment', 'event_espresso' ) |
|
928 | + __('Method of Payment', 'event_espresso') |
|
929 | 929 | ); |
930 | 930 | $available_payment_methods = array( |
931 | 931 | // display the "Payment Method" header |
932 | 932 | 'payment_method_header' => new EE_Form_Section_HTML( |
933 | - EEH_HTML::h4( $payment_method_header, 'method-of-payment-hdr' ) |
|
933 | + EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr') |
|
934 | 934 | ) |
935 | 935 | ); |
936 | 936 | // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
@@ -939,32 +939,32 @@ discard block |
||
939 | 939 | // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
940 | 940 | $payment_methods_billing_info = array( |
941 | 941 | new EE_Form_Section_HTML( |
942 | - EEH_HTML::div( '<br />', '', '', 'clear:both;' ) |
|
942 | + EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
943 | 943 | ) |
944 | 944 | ); |
945 | 945 | // loop through payment methods |
946 | - foreach ( $this->checkout->available_payment_methods as $payment_method ) { |
|
947 | - if ( $payment_method instanceof EE_Payment_Method ) { |
|
946 | + foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
947 | + if ($payment_method instanceof EE_Payment_Method) { |
|
948 | 948 | $payment_method_button = EEH_HTML::img( |
949 | 949 | $payment_method->button_url(), |
950 | 950 | $payment_method->name(), |
951 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
951 | + 'spco-payment-method-'.$payment_method->slug().'-btn-img', |
|
952 | 952 | 'spco-payment-method-btn-img' |
953 | 953 | ); |
954 | 954 | // check if any payment methods are set as default |
955 | 955 | // if payment method is already selected OR nothing is selected and this payment method should be open_by_default |
956 | 956 | if ( |
957 | - ( $this->checkout->selected_method_of_payment === $payment_method->slug() ) |
|
958 | - || ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default() ) |
|
957 | + ($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
958 | + || ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
959 | 959 | ) { |
960 | 960 | $this->checkout->selected_method_of_payment = $payment_method->slug(); |
961 | 961 | $this->_save_selected_method_of_payment(); |
962 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
962 | + $default_payment_method_option[$payment_method->slug()] = $payment_method_button; |
|
963 | 963 | } else { |
964 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
964 | + $available_payment_method_options[$payment_method->slug()] = $payment_method_button; |
|
965 | 965 | } |
966 | - $payment_methods_billing_info[ $payment_method->slug() |
|
967 | - . '-info' ] = $this->_payment_method_billing_info( |
|
966 | + $payment_methods_billing_info[$payment_method->slug() |
|
967 | + . '-info'] = $this->_payment_method_billing_info( |
|
968 | 968 | $payment_method |
969 | 969 | ); |
970 | 970 | } |
@@ -994,12 +994,12 @@ discard block |
||
994 | 994 | * @return EE_Payment_Method[] |
995 | 995 | */ |
996 | 996 | protected function _get_available_payment_methods() { |
997 | - if ( ! empty( $this->checkout->available_payment_methods ) ) { |
|
997 | + if ( ! empty($this->checkout->available_payment_methods)) { |
|
998 | 998 | return $this->checkout->available_payment_methods; |
999 | 999 | } |
1000 | 1000 | $available_payment_methods = array(); |
1001 | 1001 | // load EEM_Payment_Method |
1002 | - EE_Registry::instance()->load_model( 'Payment_Method' ); |
|
1002 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
1003 | 1003 | /** @type EEM_Payment_Method $EEM_Payment_Method */ |
1004 | 1004 | $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
1005 | 1005 | // get all active payment methods |
@@ -1007,9 +1007,9 @@ discard block |
||
1007 | 1007 | $this->checkout->transaction, |
1008 | 1008 | EEM_Payment_Method::scope_cart |
1009 | 1009 | ); |
1010 | - foreach ( $payment_methods as $payment_method ) { |
|
1011 | - if ( $payment_method instanceof EE_Payment_Method ) { |
|
1012 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
1010 | + foreach ($payment_methods as $payment_method) { |
|
1011 | + if ($payment_method instanceof EE_Payment_Method) { |
|
1012 | + $available_payment_methods[$payment_method->slug()] = $payment_method; |
|
1013 | 1013 | } |
1014 | 1014 | } |
1015 | 1015 | return $available_payment_methods; |
@@ -1024,14 +1024,14 @@ discard block |
||
1024 | 1024 | * @param array $available_payment_method_options |
1025 | 1025 | * @return \EE_Form_Section_Proper |
1026 | 1026 | */ |
1027 | - private function _available_payment_method_inputs( $available_payment_method_options = array() ) { |
|
1027 | + private function _available_payment_method_inputs($available_payment_method_options = array()) { |
|
1028 | 1028 | // generate inputs |
1029 | 1029 | return new EE_Form_Section_Proper( |
1030 | 1030 | array( |
1031 | 1031 | 'html_id' => 'ee-available-payment-method-inputs', |
1032 | 1032 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
1033 | 1033 | 'subsections' => array( |
1034 | - '' => new EE_Radio_Button_Input ( |
|
1034 | + '' => new EE_Radio_Button_Input( |
|
1035 | 1035 | $available_payment_method_options, |
1036 | 1036 | array( |
1037 | 1037 | 'html_name' => 'selected_method_of_payment', |
@@ -1056,28 +1056,28 @@ discard block |
||
1056 | 1056 | * @return \EE_Form_Section_Proper |
1057 | 1057 | * @throws \EE_Error |
1058 | 1058 | */ |
1059 | - private function _payment_method_billing_info( EE_Payment_Method $payment_method ) { |
|
1059 | + private function _payment_method_billing_info(EE_Payment_Method $payment_method) { |
|
1060 | 1060 | $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
1061 | 1061 | ? true |
1062 | 1062 | : false; |
1063 | 1063 | // generate the billing form for payment method |
1064 | 1064 | $billing_form = $currently_selected |
1065 | - ? $this->_get_billing_form_for_payment_method( $payment_method ) |
|
1065 | + ? $this->_get_billing_form_for_payment_method($payment_method) |
|
1066 | 1066 | : new EE_Form_Section_HTML(); |
1067 | 1067 | $this->checkout->billing_form = $currently_selected |
1068 | 1068 | ? $billing_form |
1069 | 1069 | : $this->checkout->billing_form; |
1070 | 1070 | // it's all in the details |
1071 | 1071 | $info_html = EEH_HTML::h3( |
1072 | - __( 'Important information regarding your payment', 'event_espresso' ), |
|
1072 | + __('Important information regarding your payment', 'event_espresso'), |
|
1073 | 1073 | '', |
1074 | 1074 | 'spco-payment-method-hdr' |
1075 | 1075 | ); |
1076 | 1076 | // add some info regarding the step, either from what's saved in the admin, |
1077 | 1077 | // or a default string depending on whether the PM has a billing form or not |
1078 | - if ( $payment_method->description() ) { |
|
1078 | + if ($payment_method->description()) { |
|
1079 | 1079 | $payment_method_info = $payment_method->description(); |
1080 | - } elseif ( $billing_form instanceof EE_Billing_Info_Form ) { |
|
1080 | + } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
1081 | 1081 | $payment_method_info = sprintf( |
1082 | 1082 | __( |
1083 | 1083 | 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
@@ -1087,7 +1087,7 @@ discard block |
||
1087 | 1087 | ); |
1088 | 1088 | } else { |
1089 | 1089 | $payment_method_info = sprintf( |
1090 | - __( 'Please click the "%1$s" button below in order to proceed.', 'event_espresso' ), |
|
1090 | + __('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
1091 | 1091 | $this->submit_button_text() |
1092 | 1092 | ); |
1093 | 1093 | } |
@@ -1101,13 +1101,13 @@ discard block |
||
1101 | 1101 | ); |
1102 | 1102 | return new EE_Form_Section_Proper( |
1103 | 1103 | array( |
1104 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
1104 | + 'html_id' => 'spco-payment-method-info-'.$payment_method->slug(), |
|
1105 | 1105 | 'html_class' => 'spco-payment-method-info-dv', |
1106 | 1106 | // only display the selected or default PM |
1107 | 1107 | 'html_style' => $currently_selected ? '' : 'display:none;', |
1108 | 1108 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
1109 | 1109 | 'subsections' => array( |
1110 | - 'info' => new EE_Form_Section_HTML( $info_html ), |
|
1110 | + 'info' => new EE_Form_Section_HTML($info_html), |
|
1111 | 1111 | 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML() |
1112 | 1112 | ) |
1113 | 1113 | ) |
@@ -1125,15 +1125,15 @@ discard block |
||
1125 | 1125 | */ |
1126 | 1126 | public function get_billing_form_html_for_payment_method() { |
1127 | 1127 | // how have they chosen to pay? |
1128 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( true ); |
|
1128 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1129 | 1129 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
1130 | - if ( ! $this->checkout->payment_method instanceof EE_Payment_Method ) { |
|
1130 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1131 | 1131 | return false; |
1132 | 1132 | } |
1133 | - if ( apply_filters( |
|
1133 | + if (apply_filters( |
|
1134 | 1134 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
1135 | 1135 | false |
1136 | - ) ) { |
|
1136 | + )) { |
|
1137 | 1137 | EE_Error::add_success( |
1138 | 1138 | apply_filters( |
1139 | 1139 | 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
@@ -1148,7 +1148,7 @@ discard block |
||
1148 | 1148 | ); |
1149 | 1149 | } |
1150 | 1150 | // now generate billing form for selected method of payment |
1151 | - $payment_method_billing_form = $this->_get_billing_form_for_payment_method( $this->checkout->payment_method ); |
|
1151 | + $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
1152 | 1152 | // fill form with attendee info if applicable |
1153 | 1153 | if ( |
1154 | 1154 | $payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
@@ -1170,10 +1170,10 @@ discard block |
||
1170 | 1170 | $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
1171 | 1171 | ? $payment_method_billing_form->get_html() |
1172 | 1172 | : ''; |
1173 | - $this->checkout->json_response->set_return_data( array( 'payment_method_info' => $billing_info ) ); |
|
1173 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
1174 | 1174 | // localize validation rules for main form |
1175 | 1175 | $this->checkout->current_step->reg_form->localize_validation_rules(); |
1176 | - $this->checkout->json_response->add_validation_rules( EE_Form_Section_Proper::js_localization() ); |
|
1176 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1177 | 1177 | return true; |
1178 | 1178 | } |
1179 | 1179 | |
@@ -1187,18 +1187,18 @@ discard block |
||
1187 | 1187 | * @return \EE_Billing_Info_Form|\EE_Form_Section_HTML |
1188 | 1188 | * @throws \EE_Error |
1189 | 1189 | */ |
1190 | - private function _get_billing_form_for_payment_method( EE_Payment_Method $payment_method ) { |
|
1190 | + private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) { |
|
1191 | 1191 | $billing_form = $payment_method->type_obj()->billing_form( |
1192 | 1192 | $this->checkout->transaction, |
1193 | - array( 'amount_owing' => $this->checkout->amount_owing ) |
|
1193 | + array('amount_owing' => $this->checkout->amount_owing) |
|
1194 | 1194 | ); |
1195 | - if ( $billing_form instanceof EE_Billing_Info_Form ) { |
|
1195 | + if ($billing_form instanceof EE_Billing_Info_Form) { |
|
1196 | 1196 | if ( |
1197 | 1197 | apply_filters( |
1198 | 1198 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
1199 | 1199 | false |
1200 | 1200 | ) |
1201 | - && EE_Registry::instance()->REQ->is_set( 'payment_method' ) |
|
1201 | + && EE_Registry::instance()->REQ->is_set('payment_method') |
|
1202 | 1202 | ) { |
1203 | 1203 | EE_Error::add_success( |
1204 | 1204 | apply_filters( |
@@ -1240,15 +1240,15 @@ discard block |
||
1240 | 1240 | $request_param = 'selected_method_of_payment' |
1241 | 1241 | ) { |
1242 | 1242 | // is selected_method_of_payment set in the request ? |
1243 | - $selected_method_of_payment = EE_Registry::instance()->REQ->get( $request_param, false ); |
|
1244 | - if ( $selected_method_of_payment ) { |
|
1243 | + $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
1244 | + if ($selected_method_of_payment) { |
|
1245 | 1245 | // sanitize it |
1246 | - $selected_method_of_payment = is_array( $selected_method_of_payment ) |
|
1247 | - ? array_shift( $selected_method_of_payment ) |
|
1246 | + $selected_method_of_payment = is_array($selected_method_of_payment) |
|
1247 | + ? array_shift($selected_method_of_payment) |
|
1248 | 1248 | : $selected_method_of_payment; |
1249 | - $selected_method_of_payment = sanitize_text_field( $selected_method_of_payment ); |
|
1249 | + $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
1250 | 1250 | // store it in the session so that it's available for all subsequent requests including AJAX |
1251 | - $this->_save_selected_method_of_payment( $selected_method_of_payment ); |
|
1251 | + $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
1252 | 1252 | } else { |
1253 | 1253 | // or is is set in the session ? |
1254 | 1254 | $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
@@ -1256,7 +1256,7 @@ discard block |
||
1256 | 1256 | ); |
1257 | 1257 | } |
1258 | 1258 | // do ya really really gotta have it? |
1259 | - if ( empty( $selected_method_of_payment ) && $required ) { |
|
1259 | + if (empty($selected_method_of_payment) && $required) { |
|
1260 | 1260 | EE_Error::add_error( |
1261 | 1261 | sprintf( |
1262 | 1262 | __( |
@@ -1265,7 +1265,7 @@ discard block |
||
1265 | 1265 | ), |
1266 | 1266 | '<br/>', |
1267 | 1267 | '<br/>', |
1268 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
1268 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1269 | 1269 | ), |
1270 | 1270 | __FILE__, |
1271 | 1271 | __FUNCTION__, |
@@ -1292,13 +1292,13 @@ discard block |
||
1292 | 1292 | * @throws \EE_Error |
1293 | 1293 | */ |
1294 | 1294 | public function switch_payment_method() { |
1295 | - if ( ! $this->_verify_payment_method_is_set() ) { |
|
1295 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
1296 | 1296 | return false; |
1297 | 1297 | } |
1298 | - if ( apply_filters( |
|
1298 | + if (apply_filters( |
|
1299 | 1299 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
1300 | 1300 | false |
1301 | - ) ) { |
|
1301 | + )) { |
|
1302 | 1302 | EE_Error::add_success( |
1303 | 1303 | apply_filters( |
1304 | 1304 | 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
@@ -1313,7 +1313,7 @@ discard block |
||
1313 | 1313 | ); |
1314 | 1314 | } |
1315 | 1315 | // generate billing form for selected method of payment if it hasn't been done already |
1316 | - if ( $this->checkout->payment_method->type_obj()->has_billing_form() ) { |
|
1316 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1317 | 1317 | $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
1318 | 1318 | $this->checkout->payment_method |
1319 | 1319 | ); |
@@ -1335,7 +1335,7 @@ discard block |
||
1335 | 1335 | ); |
1336 | 1336 | } |
1337 | 1337 | // and debug content |
1338 | - if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
1338 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
1339 | 1339 | && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
1340 | 1340 | ) { |
1341 | 1341 | $this->checkout->billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
@@ -1343,15 +1343,15 @@ discard block |
||
1343 | 1343 | ); |
1344 | 1344 | } |
1345 | 1345 | // get html and validation rules for form |
1346 | - if ( $this->checkout->billing_form instanceof EE_Form_Section_Proper ) { |
|
1346 | + if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
1347 | 1347 | $this->checkout->json_response->set_return_data( |
1348 | - array( 'payment_method_info' => $this->checkout->billing_form->get_html() ) |
|
1348 | + array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
1349 | 1349 | ); |
1350 | 1350 | // localize validation rules for main form |
1351 | - $this->checkout->billing_form->localize_validation_rules( true ); |
|
1352 | - $this->checkout->json_response->add_validation_rules( EE_Form_Section_Proper::js_localization() ); |
|
1351 | + $this->checkout->billing_form->localize_validation_rules(true); |
|
1352 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1353 | 1353 | } else { |
1354 | - $this->checkout->json_response->set_return_data( array( 'payment_method_info' => '' ) ); |
|
1354 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
1355 | 1355 | } |
1356 | 1356 | //prevents advancement to next step |
1357 | 1357 | $this->checkout->continue_reg = false; |
@@ -1368,18 +1368,18 @@ discard block |
||
1368 | 1368 | */ |
1369 | 1369 | protected function _verify_payment_method_is_set() { |
1370 | 1370 | // generate billing form for selected method of payment if it hasn't been done already |
1371 | - if ( empty( $this->checkout->selected_method_of_payment ) ) { |
|
1371 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
1372 | 1372 | // how have they chosen to pay? |
1373 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( true ); |
|
1373 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1374 | 1374 | } else { |
1375 | 1375 | // choose your own adventure based on method_of_payment |
1376 | - switch ( $this->checkout->selected_method_of_payment ) { |
|
1376 | + switch ($this->checkout->selected_method_of_payment) { |
|
1377 | 1377 | case 'events_sold_out' : |
1378 | 1378 | EE_Error::add_attention( |
1379 | 1379 | apply_filters( |
1380 | 1380 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
1381 | - __( 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
1382 | - 'event_espresso' ) |
|
1381 | + __('It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
1382 | + 'event_espresso') |
|
1383 | 1383 | ), |
1384 | 1384 | __FILE__, __FUNCTION__, __LINE__ |
1385 | 1385 | ); |
@@ -1389,7 +1389,7 @@ discard block |
||
1389 | 1389 | EE_Error::add_attention( |
1390 | 1390 | apply_filters( |
1391 | 1391 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
1392 | - __( 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', 'event_espresso' ) |
|
1392 | + __('It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', 'event_espresso') |
|
1393 | 1393 | ), |
1394 | 1394 | __FILE__, __FUNCTION__, __LINE__ |
1395 | 1395 | ); |
@@ -1399,7 +1399,7 @@ discard block |
||
1399 | 1399 | EE_Error::add_attention( |
1400 | 1400 | apply_filters( |
1401 | 1401 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
1402 | - __( 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', 'event_espresso' ) |
|
1402 | + __('It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', 'event_espresso') |
|
1403 | 1403 | ), |
1404 | 1404 | __FILE__, __FUNCTION__, __LINE__ |
1405 | 1405 | ); |
@@ -1409,7 +1409,7 @@ discard block |
||
1409 | 1409 | } |
1410 | 1410 | } |
1411 | 1411 | // verify payment method |
1412 | - if ( ! $this->checkout->payment_method instanceof EE_Payment_Method ) { |
|
1412 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1413 | 1413 | // get payment method for selected method of payment |
1414 | 1414 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
1415 | 1415 | } |
@@ -1428,25 +1428,25 @@ discard block |
||
1428 | 1428 | * @throws \EE_Error |
1429 | 1429 | */ |
1430 | 1430 | public function save_payer_details_via_ajax() { |
1431 | - if ( ! $this->_verify_payment_method_is_set() ) { |
|
1431 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
1432 | 1432 | return; |
1433 | 1433 | } |
1434 | 1434 | // generate billing form for selected method of payment if it hasn't been done already |
1435 | - if ( $this->checkout->payment_method->type_obj()->has_billing_form() ) { |
|
1435 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1436 | 1436 | $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
1437 | 1437 | $this->checkout->payment_method |
1438 | 1438 | ); |
1439 | 1439 | } |
1440 | 1440 | // generate primary attendee from payer info if applicable |
1441 | - if ( ! $this->checkout->transaction_has_primary_registrant() ) { |
|
1441 | + if ( ! $this->checkout->transaction_has_primary_registrant()) { |
|
1442 | 1442 | $attendee = $this->_create_attendee_from_request_data(); |
1443 | - if ( $attendee instanceof EE_Attendee ) { |
|
1444 | - foreach ( $this->checkout->transaction->registrations() as $registration ) { |
|
1445 | - if ( $registration->is_primary_registrant() ) { |
|
1443 | + if ($attendee instanceof EE_Attendee) { |
|
1444 | + foreach ($this->checkout->transaction->registrations() as $registration) { |
|
1445 | + if ($registration->is_primary_registrant()) { |
|
1446 | 1446 | $this->checkout->primary_attendee_obj = $attendee; |
1447 | - $registration->_add_relation_to( $attendee, 'Attendee' ); |
|
1448 | - $registration->set_attendee_id( $attendee->ID() ); |
|
1449 | - $registration->update_cache_after_object_save( 'Attendee', $attendee ); |
|
1447 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1448 | + $registration->set_attendee_id($attendee->ID()); |
|
1449 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1450 | 1450 | } |
1451 | 1451 | } |
1452 | 1452 | } |
@@ -1464,50 +1464,50 @@ discard block |
||
1464 | 1464 | */ |
1465 | 1465 | protected function _create_attendee_from_request_data() { |
1466 | 1466 | // get State ID |
1467 | - $STA_ID = ! empty( $_REQUEST['state'] ) ? sanitize_text_field( $_REQUEST['state'] ) : ''; |
|
1468 | - if ( ! empty( $STA_ID ) ) { |
|
1467 | + $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
1468 | + if ( ! empty($STA_ID)) { |
|
1469 | 1469 | // can we get state object from name ? |
1470 | - EE_Registry::instance()->load_model( 'State' ); |
|
1471 | - $state = EEM_State::instance()->get_col( array( array( 'STA_name' => $STA_ID ), 'limit' => 1 ), 'STA_ID' ); |
|
1472 | - $STA_ID = is_array( $state ) && ! empty( $state ) ? reset( $state ) : $STA_ID; |
|
1470 | + EE_Registry::instance()->load_model('State'); |
|
1471 | + $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
1472 | + $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
1473 | 1473 | } |
1474 | 1474 | // get Country ISO |
1475 | - $CNT_ISO = ! empty( $_REQUEST['country'] ) ? sanitize_text_field( $_REQUEST['country'] ) : ''; |
|
1476 | - if ( ! empty( $CNT_ISO ) ) { |
|
1475 | + $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
1476 | + if ( ! empty($CNT_ISO)) { |
|
1477 | 1477 | // can we get country object from name ? |
1478 | - EE_Registry::instance()->load_model( 'Country' ); |
|
1478 | + EE_Registry::instance()->load_model('Country'); |
|
1479 | 1479 | $country = EEM_Country::instance()->get_col( |
1480 | - array( array( 'CNT_name' => $CNT_ISO ), 'limit' => 1 ), |
|
1480 | + array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
1481 | 1481 | 'CNT_ISO' |
1482 | 1482 | ); |
1483 | - $CNT_ISO = is_array( $country ) && ! empty( $country ) ? reset( $country ) : $CNT_ISO; |
|
1483 | + $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
1484 | 1484 | } |
1485 | 1485 | // grab attendee data |
1486 | 1486 | $attendee_data = array( |
1487 | - 'ATT_fname' => ! empty( $_REQUEST['first_name'] ) ? sanitize_text_field( $_REQUEST['first_name'] ) : '', |
|
1488 | - 'ATT_lname' => ! empty( $_REQUEST['last_name'] ) ? sanitize_text_field( $_REQUEST['last_name'] ) : '', |
|
1489 | - 'ATT_email' => ! empty( $_REQUEST['email'] ) ? sanitize_email( $_REQUEST['email'] ) : '', |
|
1490 | - 'ATT_address' => ! empty( $_REQUEST['address'] ) ? sanitize_text_field( $_REQUEST['address'] ) : '', |
|
1491 | - 'ATT_address2' => ! empty( $_REQUEST['address2'] ) ? sanitize_text_field( $_REQUEST['address2'] ) : '', |
|
1492 | - 'ATT_city' => ! empty( $_REQUEST['city'] ) ? sanitize_text_field( $_REQUEST['city'] ) : '', |
|
1487 | + 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
1488 | + 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
1489 | + 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
1490 | + 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
1491 | + 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
1492 | + 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
1493 | 1493 | 'STA_ID' => $STA_ID, |
1494 | 1494 | 'CNT_ISO' => $CNT_ISO, |
1495 | - 'ATT_zip' => ! empty( $_REQUEST['zip'] ) ? sanitize_text_field( $_REQUEST['zip'] ) : '', |
|
1496 | - 'ATT_phone' => ! empty( $_REQUEST['phone'] ) ? sanitize_text_field( $_REQUEST['phone'] ) : '', |
|
1495 | + 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
1496 | + 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
1497 | 1497 | ); |
1498 | 1498 | // validate the email address since it is the most important piece of info |
1499 | - if ( empty( $attendee_data['ATT_email'] ) || $attendee_data['ATT_email'] !== $_REQUEST['email'] ) { |
|
1499 | + if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
1500 | 1500 | EE_Error::add_error( |
1501 | - __( 'An invalid email address was submitted.', 'event_espresso' ), |
|
1501 | + __('An invalid email address was submitted.', 'event_espresso'), |
|
1502 | 1502 | __FILE__, |
1503 | 1503 | __FUNCTION__, |
1504 | 1504 | __LINE__ |
1505 | 1505 | ); |
1506 | 1506 | } |
1507 | 1507 | // does this attendee already exist in the db ? we're searching using a combination of first name, last name, AND email address |
1508 | - if ( ! empty( $attendee_data['ATT_fname'] ) |
|
1509 | - && ! empty( $attendee_data['ATT_lname'] ) |
|
1510 | - && ! empty( $attendee_data['ATT_email'] ) |
|
1508 | + if ( ! empty($attendee_data['ATT_fname']) |
|
1509 | + && ! empty($attendee_data['ATT_lname']) |
|
1510 | + && ! empty($attendee_data['ATT_email']) |
|
1511 | 1511 | ) { |
1512 | 1512 | $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
1513 | 1513 | array( |
@@ -1516,19 +1516,19 @@ discard block |
||
1516 | 1516 | 'ATT_email' => $attendee_data['ATT_email'] |
1517 | 1517 | ) |
1518 | 1518 | ); |
1519 | - if ( $existing_attendee instanceof EE_Attendee ) { |
|
1519 | + if ($existing_attendee instanceof EE_Attendee) { |
|
1520 | 1520 | return $existing_attendee; |
1521 | 1521 | } |
1522 | 1522 | } |
1523 | 1523 | // no existing attendee? kk let's create a new one |
1524 | 1524 | // kinda lame, but we need a first and last name to create an attendee, so use the email address if those don't exist |
1525 | - $attendee_data['ATT_fname'] = ! empty( $attendee_data['ATT_fname'] ) |
|
1525 | + $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
1526 | 1526 | ? $attendee_data['ATT_fname'] |
1527 | 1527 | : $attendee_data['ATT_email']; |
1528 | - $attendee_data['ATT_lname'] = ! empty( $attendee_data['ATT_lname'] ) |
|
1528 | + $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
1529 | 1529 | ? $attendee_data['ATT_lname'] |
1530 | 1530 | : $attendee_data['ATT_email']; |
1531 | - return EE_Attendee::new_instance( $attendee_data ); |
|
1531 | + return EE_Attendee::new_instance($attendee_data); |
|
1532 | 1532 | } |
1533 | 1533 | |
1534 | 1534 | |
@@ -1546,26 +1546,26 @@ discard block |
||
1546 | 1546 | // how have they chosen to pay? |
1547 | 1547 | $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
1548 | 1548 | ? 'no_payment_required' |
1549 | - : $this->_get_selected_method_of_payment( true ); |
|
1549 | + : $this->_get_selected_method_of_payment(true); |
|
1550 | 1550 | // choose your own adventure based on method_of_payment |
1551 | - switch ( $this->checkout->selected_method_of_payment ) { |
|
1551 | + switch ($this->checkout->selected_method_of_payment) { |
|
1552 | 1552 | |
1553 | 1553 | case 'events_sold_out' : |
1554 | 1554 | $this->checkout->redirect = true; |
1555 | 1555 | $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
1556 | - $this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url ); |
|
1556 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1557 | 1557 | // mark this reg step as completed |
1558 | 1558 | $this->set_completed(); |
1559 | 1559 | return false; |
1560 | 1560 | break; |
1561 | 1561 | |
1562 | 1562 | case 'payments_closed' : |
1563 | - if ( apply_filters( |
|
1563 | + if (apply_filters( |
|
1564 | 1564 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
1565 | 1565 | false |
1566 | - ) ) { |
|
1566 | + )) { |
|
1567 | 1567 | EE_Error::add_success( |
1568 | - __( 'no payment required at this time.', 'event_espresso' ), |
|
1568 | + __('no payment required at this time.', 'event_espresso'), |
|
1569 | 1569 | __FILE__, |
1570 | 1570 | __FUNCTION__, |
1571 | 1571 | __LINE__ |
@@ -1577,12 +1577,12 @@ discard block |
||
1577 | 1577 | break; |
1578 | 1578 | |
1579 | 1579 | case 'no_payment_required' : |
1580 | - if ( apply_filters( |
|
1580 | + if (apply_filters( |
|
1581 | 1581 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
1582 | 1582 | false |
1583 | - ) ) { |
|
1583 | + )) { |
|
1584 | 1584 | EE_Error::add_success( |
1585 | - __( 'no payment required.', 'event_espresso' ), |
|
1585 | + __('no payment required.', 'event_espresso'), |
|
1586 | 1586 | __FILE__, |
1587 | 1587 | __FUNCTION__, |
1588 | 1588 | __LINE__ |
@@ -1602,15 +1602,15 @@ discard block |
||
1602 | 1602 | EE_Registry::instance()->SSN->checkout()->revisit |
1603 | 1603 | ); |
1604 | 1604 | // calculate difference between the two arrays |
1605 | - $registrations = array_diff( $registrations, $ejected_registrations ); |
|
1606 | - if ( empty( $registrations ) ) { |
|
1605 | + $registrations = array_diff($registrations, $ejected_registrations); |
|
1606 | + if (empty($registrations)) { |
|
1607 | 1607 | $this->_redirect_because_event_sold_out(); |
1608 | 1608 | return false; |
1609 | 1609 | } |
1610 | 1610 | $payment_successful = $this->_process_payment(); |
1611 | - if ( $payment_successful ) { |
|
1611 | + if ($payment_successful) { |
|
1612 | 1612 | $this->checkout->continue_reg = true; |
1613 | - $this->_maybe_set_completed( $this->checkout->payment_method ); |
|
1613 | + $this->_maybe_set_completed($this->checkout->payment_method); |
|
1614 | 1614 | } else { |
1615 | 1615 | $this->checkout->continue_reg = false; |
1616 | 1616 | } |
@@ -1631,10 +1631,10 @@ discard block |
||
1631 | 1631 | $this->checkout->continue_reg = false; |
1632 | 1632 | // set redirect URL |
1633 | 1633 | $this->checkout->redirect_url = add_query_arg( |
1634 | - array( 'e_reg_url_link' => $this->checkout->reg_url_link ), |
|
1634 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1635 | 1635 | $this->checkout->current_step->reg_step_url() |
1636 | 1636 | ); |
1637 | - $this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url ); |
|
1637 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1638 | 1638 | } |
1639 | 1639 | |
1640 | 1640 | |
@@ -1647,8 +1647,8 @@ discard block |
||
1647 | 1647 | * @return void |
1648 | 1648 | * @throws \EE_Error |
1649 | 1649 | */ |
1650 | - protected function _maybe_set_completed( EE_Payment_Method $payment_method ) { |
|
1651 | - switch ( $payment_method->type_obj()->payment_occurs() ) { |
|
1650 | + protected function _maybe_set_completed(EE_Payment_Method $payment_method) { |
|
1651 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
1652 | 1652 | case EE_PMT_Base::offsite : |
1653 | 1653 | break; |
1654 | 1654 | case EE_PMT_Base::onsite : |
@@ -1671,7 +1671,7 @@ discard block |
||
1671 | 1671 | public function update_reg_step() { |
1672 | 1672 | $success = true; |
1673 | 1673 | // if payment required |
1674 | - if ( $this->checkout->transaction->total() > 0 ) { |
|
1674 | + if ($this->checkout->transaction->total() > 0) { |
|
1675 | 1675 | do_action( |
1676 | 1676 | 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
1677 | 1677 | $this->checkout->transaction |
@@ -1679,13 +1679,13 @@ discard block |
||
1679 | 1679 | // attempt payment via payment method |
1680 | 1680 | $success = $this->process_reg_step(); |
1681 | 1681 | } |
1682 | - if ( $success && ! $this->checkout->redirect ) { |
|
1682 | + if ($success && ! $this->checkout->redirect) { |
|
1683 | 1683 | $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
1684 | 1684 | $this->checkout->transaction->ID() |
1685 | 1685 | ); |
1686 | 1686 | // set return URL |
1687 | 1687 | $this->checkout->redirect_url = add_query_arg( |
1688 | - array( 'e_reg_url_link' => $this->checkout->reg_url_link ), |
|
1688 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1689 | 1689 | $this->checkout->thank_you_page_url |
1690 | 1690 | ); |
1691 | 1691 | } |
@@ -1703,36 +1703,36 @@ discard block |
||
1703 | 1703 | */ |
1704 | 1704 | private function _process_payment() { |
1705 | 1705 | // basically confirm that the event hasn't sold out since they hit the page |
1706 | - if ( ! $this->_last_second_ticket_verifications() ) { |
|
1706 | + if ( ! $this->_last_second_ticket_verifications()) { |
|
1707 | 1707 | return false; |
1708 | 1708 | } |
1709 | 1709 | // ya gotta make a choice man |
1710 | - if ( empty( $this->checkout->selected_method_of_payment ) ) { |
|
1710 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
1711 | 1711 | $this->checkout->json_response->set_plz_select_method_of_payment( |
1712 | - __( 'Please select a method of payment before proceeding.', 'event_espresso' ) |
|
1712 | + __('Please select a method of payment before proceeding.', 'event_espresso') |
|
1713 | 1713 | ); |
1714 | 1714 | return false; |
1715 | 1715 | } |
1716 | 1716 | // get EE_Payment_Method object |
1717 | - if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() ) { |
|
1717 | + if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1718 | 1718 | return false; |
1719 | 1719 | } |
1720 | 1720 | // setup billing form |
1721 | - if ( $this->checkout->payment_method->is_on_site() ) { |
|
1721 | + if ($this->checkout->payment_method->is_on_site()) { |
|
1722 | 1722 | $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
1723 | 1723 | $this->checkout->payment_method |
1724 | 1724 | ); |
1725 | 1725 | // bad billing form ? |
1726 | - if ( ! $this->_billing_form_is_valid() ) { |
|
1726 | + if ( ! $this->_billing_form_is_valid()) { |
|
1727 | 1727 | return false; |
1728 | 1728 | } |
1729 | 1729 | } |
1730 | 1730 | // ensure primary registrant has been fully processed |
1731 | - if ( ! $this->_setup_primary_registrant_prior_to_payment() ) { |
|
1731 | + if ( ! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1732 | 1732 | return false; |
1733 | 1733 | } |
1734 | 1734 | // if session is close to expiring (under 10 minutes by default) |
1735 | - if ( ( time() - EE_Registry::instance()->SSN->expiration() ) < EE_Registry::instance()->SSN->extension() ) { |
|
1735 | + if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
1736 | 1736 | // add some time to session expiration so that payment can be completed |
1737 | 1737 | EE_Registry::instance()->SSN->extend_expiration(); |
1738 | 1738 | } |
@@ -1741,12 +1741,12 @@ discard block |
||
1741 | 1741 | // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations for events with a default reg status of Approved |
1742 | 1742 | //$transaction_processor->toggle_registration_statuses_for_default_approved_events( $this->checkout->transaction, $this->checkout->reg_cache_where_params ); |
1743 | 1743 | // attempt payment |
1744 | - $payment = $this->_attempt_payment( $this->checkout->payment_method ); |
|
1744 | + $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
1745 | 1745 | // process results |
1746 | - $payment = $this->_validate_payment( $payment ); |
|
1747 | - $payment = $this->_post_payment_processing( $payment ); |
|
1746 | + $payment = $this->_validate_payment($payment); |
|
1747 | + $payment = $this->_post_payment_processing($payment); |
|
1748 | 1748 | // verify payment |
1749 | - if ( $payment instanceof EE_Payment ) { |
|
1749 | + if ($payment instanceof EE_Payment) { |
|
1750 | 1750 | // store that for later |
1751 | 1751 | $this->checkout->payment = $payment; |
1752 | 1752 | // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
@@ -1760,7 +1760,7 @@ discard block |
||
1760 | 1760 | } else { |
1761 | 1761 | return false; |
1762 | 1762 | } |
1763 | - } else if ( $payment === true ) { |
|
1763 | + } else if ($payment === true) { |
|
1764 | 1764 | // please note that offline payment methods will NOT make a payment, |
1765 | 1765 | // but instead just mark themselves as the PMD_ID on the transaction, and return true |
1766 | 1766 | $this->checkout->payment = $payment; |
@@ -1780,22 +1780,22 @@ discard block |
||
1780 | 1780 | */ |
1781 | 1781 | protected function _last_second_ticket_verifications() { |
1782 | 1782 | // don't bother re-validating if not a return visit |
1783 | - if ( ! $this->checkout->revisit ) { |
|
1783 | + if ( ! $this->checkout->revisit) { |
|
1784 | 1784 | return true; |
1785 | 1785 | } |
1786 | 1786 | $registrations = $this->checkout->transaction->registrations(); |
1787 | - if ( empty( $registrations ) ) { |
|
1787 | + if (empty($registrations)) { |
|
1788 | 1788 | return false; |
1789 | 1789 | } |
1790 | - foreach ( $registrations as $registration ) { |
|
1791 | - if ( $registration instanceof EE_Registration ) { |
|
1790 | + foreach ($registrations as $registration) { |
|
1791 | + if ($registration instanceof EE_Registration) { |
|
1792 | 1792 | $event = $registration->event_obj(); |
1793 | - if ( $event instanceof EE_Event && $event->is_sold_out( true ) ) { |
|
1793 | + if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
1794 | 1794 | EE_Error::add_error( |
1795 | 1795 | apply_filters( |
1796 | 1796 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
1797 | 1797 | sprintf( |
1798 | - __( 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', 'event_espresso' ), |
|
1798 | + __('It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', 'event_espresso'), |
|
1799 | 1799 | $event->name() |
1800 | 1800 | ) |
1801 | 1801 | ), |
@@ -1825,7 +1825,7 @@ discard block |
||
1825 | 1825 | ); |
1826 | 1826 | $html = $payment_method_billing_info->get_html(); |
1827 | 1827 | $html .= $this->checkout->redirect_form; |
1828 | - EE_Registry::instance()->REQ->add_output( $html ); |
|
1828 | + EE_Registry::instance()->REQ->add_output($html); |
|
1829 | 1829 | return true; |
1830 | 1830 | } |
1831 | 1831 | |
@@ -1839,28 +1839,28 @@ discard block |
||
1839 | 1839 | * @throws \EE_Error |
1840 | 1840 | */ |
1841 | 1841 | private function _billing_form_is_valid() { |
1842 | - if ( ! $this->checkout->payment_method->type_obj()->has_billing_form() ) { |
|
1842 | + if ( ! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1843 | 1843 | return true; |
1844 | 1844 | } |
1845 | - if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form ) { |
|
1846 | - if ( $this->checkout->billing_form->was_submitted() ) { |
|
1845 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
1846 | + if ($this->checkout->billing_form->was_submitted()) { |
|
1847 | 1847 | $this->checkout->billing_form->receive_form_submission(); |
1848 | - if ( $this->checkout->billing_form->is_valid() ) { |
|
1848 | + if ($this->checkout->billing_form->is_valid()) { |
|
1849 | 1849 | return true; |
1850 | 1850 | } |
1851 | 1851 | $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
1852 | 1852 | $error_strings = array(); |
1853 | - foreach ( $validation_errors as $validation_error ) { |
|
1854 | - if ( $validation_error instanceof EE_Validation_Error ) { |
|
1853 | + foreach ($validation_errors as $validation_error) { |
|
1854 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1855 | 1855 | $form_section = $validation_error->get_form_section(); |
1856 | - if ( $form_section instanceof EE_Form_Input_Base ) { |
|
1856 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
1857 | 1857 | $label = $form_section->html_label_text(); |
1858 | - } elseif ( $form_section instanceof EE_Form_Section_Base ) { |
|
1858 | + } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
1859 | 1859 | $label = $form_section->name(); |
1860 | 1860 | } else { |
1861 | - $label = __( 'Validation Error', 'event_espresso' ); |
|
1861 | + $label = __('Validation Error', 'event_espresso'); |
|
1862 | 1862 | } |
1863 | - $error_strings[] = sprintf( '%1$s: %2$s', $label, $validation_error->getMessage() ); |
|
1863 | + $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
1864 | 1864 | } |
1865 | 1865 | } |
1866 | 1866 | EE_Error::add_error( |
@@ -1870,7 +1870,7 @@ discard block |
||
1870 | 1870 | 'event_espresso' |
1871 | 1871 | ), |
1872 | 1872 | '<br/>', |
1873 | - implode( '<br/>', $error_strings ) |
|
1873 | + implode('<br/>', $error_strings) |
|
1874 | 1874 | ), |
1875 | 1875 | __FILE__, |
1876 | 1876 | __FUNCTION__, |
@@ -1889,7 +1889,7 @@ discard block |
||
1889 | 1889 | } |
1890 | 1890 | } else { |
1891 | 1891 | EE_Error::add_error( |
1892 | - __( 'The submitted billing form is invalid possibly due to a technical reason.', 'event_espresso' ), |
|
1892 | + __('The submitted billing form is invalid possibly due to a technical reason.', 'event_espresso'), |
|
1893 | 1893 | __FILE__, |
1894 | 1894 | __FUNCTION__, |
1895 | 1895 | __LINE__ |
@@ -1928,7 +1928,7 @@ discard block |
||
1928 | 1928 | // save the TXN ( which clears cached copy of primary_registration) |
1929 | 1929 | $this->checkout->transaction->save(); |
1930 | 1930 | // grab TXN ID and save it to the primary_registration |
1931 | - $primary_registration->set_transaction_id( $this->checkout->transaction->ID() ); |
|
1931 | + $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
1932 | 1932 | // save what we have so far |
1933 | 1933 | $primary_registration->save(); |
1934 | 1934 | return true; |
@@ -1946,7 +1946,7 @@ discard block |
||
1946 | 1946 | private function _capture_primary_registration_data_from_billing_form() { |
1947 | 1947 | // convert billing form data into an attendee |
1948 | 1948 | $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
1949 | - if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee ) { |
|
1949 | + if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
1950 | 1950 | EE_Error::add_error( |
1951 | 1951 | sprintf( |
1952 | 1952 | __( |
@@ -1954,7 +1954,7 @@ discard block |
||
1954 | 1954 | 'event_espresso' |
1955 | 1955 | ), |
1956 | 1956 | '<br/>', |
1957 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
1957 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1958 | 1958 | ), |
1959 | 1959 | __FILE__, |
1960 | 1960 | __FUNCTION__, |
@@ -1963,7 +1963,7 @@ discard block |
||
1963 | 1963 | return false; |
1964 | 1964 | } |
1965 | 1965 | $primary_registration = $this->checkout->transaction->primary_registration(); |
1966 | - if ( ! $primary_registration instanceof EE_Registration ) { |
|
1966 | + if ( ! $primary_registration instanceof EE_Registration) { |
|
1967 | 1967 | EE_Error::add_error( |
1968 | 1968 | sprintf( |
1969 | 1969 | __( |
@@ -1971,7 +1971,7 @@ discard block |
||
1971 | 1971 | 'event_espresso' |
1972 | 1972 | ), |
1973 | 1973 | '<br/>', |
1974 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
1974 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1975 | 1975 | ), |
1976 | 1976 | __FILE__, |
1977 | 1977 | __FUNCTION__, |
@@ -1979,7 +1979,7 @@ discard block |
||
1979 | 1979 | ); |
1980 | 1980 | return false; |
1981 | 1981 | } |
1982 | - if ( ! $primary_registration->_add_relation_to( $this->checkout->primary_attendee_obj, 'Attendee' ) |
|
1982 | + if ( ! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
1983 | 1983 | instanceof |
1984 | 1984 | EE_Attendee |
1985 | 1985 | ) { |
@@ -1990,7 +1990,7 @@ discard block |
||
1990 | 1990 | 'event_espresso' |
1991 | 1991 | ), |
1992 | 1992 | '<br/>', |
1993 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
1993 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1994 | 1994 | ), |
1995 | 1995 | __FILE__, |
1996 | 1996 | __FUNCTION__, |
@@ -1999,9 +1999,9 @@ discard block |
||
1999 | 1999 | return false; |
2000 | 2000 | } |
2001 | 2001 | /** @type EE_Registration_Processor $registration_processor */ |
2002 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
2002 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
2003 | 2003 | // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
2004 | - $registration_processor->toggle_incomplete_registration_status_to_default( $primary_registration ); |
|
2004 | + $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
2005 | 2005 | return true; |
2006 | 2006 | } |
2007 | 2007 | |
@@ -2016,22 +2016,22 @@ discard block |
||
2016 | 2016 | * @throws \EE_Error |
2017 | 2017 | */ |
2018 | 2018 | private function _get_payment_method_for_selected_method_of_payment() { |
2019 | - if ( $this->checkout->selected_method_of_payment === 'events_sold_out' ) { |
|
2019 | + if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
2020 | 2020 | $this->_redirect_because_event_sold_out(); |
2021 | 2021 | return null; |
2022 | 2022 | } |
2023 | 2023 | // get EE_Payment_Method object |
2024 | - if ( isset( $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ] ) ) { |
|
2025 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
2024 | + if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) { |
|
2025 | + $payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment]; |
|
2026 | 2026 | } else { |
2027 | 2027 | // load EEM_Payment_Method |
2028 | - EE_Registry::instance()->load_model( 'Payment_Method' ); |
|
2028 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
2029 | 2029 | /** @type EEM_Payment_Method $EEM_Payment_Method */ |
2030 | 2030 | $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
2031 | - $payment_method = $EEM_Payment_Method->get_one_by_slug( $this->checkout->selected_method_of_payment ); |
|
2031 | + $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
2032 | 2032 | } |
2033 | 2033 | // verify $payment_method |
2034 | - if ( ! $payment_method instanceof EE_Payment_Method ) { |
|
2034 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
2035 | 2035 | // not a payment |
2036 | 2036 | EE_Error::add_error( |
2037 | 2037 | sprintf( |
@@ -2040,7 +2040,7 @@ discard block |
||
2040 | 2040 | 'event_espresso' |
2041 | 2041 | ), |
2042 | 2042 | '<br/>', |
2043 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
2043 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2044 | 2044 | ), |
2045 | 2045 | __FILE__, |
2046 | 2046 | __FUNCTION__, |
@@ -2049,7 +2049,7 @@ discard block |
||
2049 | 2049 | return null; |
2050 | 2050 | } |
2051 | 2051 | // and verify it has a valid Payment_Method Type object |
2052 | - if ( ! $payment_method->type_obj() instanceof EE_PMT_Base ) { |
|
2052 | + if ( ! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2053 | 2053 | // not a payment |
2054 | 2054 | EE_Error::add_error( |
2055 | 2055 | sprintf( |
@@ -2058,7 +2058,7 @@ discard block |
||
2058 | 2058 | 'event_espresso' |
2059 | 2059 | ), |
2060 | 2060 | '<br/>', |
2061 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
2061 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2062 | 2062 | ), |
2063 | 2063 | __FILE__, |
2064 | 2064 | __FUNCTION__, |
@@ -2079,29 +2079,29 @@ discard block |
||
2079 | 2079 | * @return mixed EE_Payment | boolean |
2080 | 2080 | * @throws \EE_Error |
2081 | 2081 | */ |
2082 | - private function _attempt_payment( EE_Payment_Method $payment_method ) { |
|
2082 | + private function _attempt_payment(EE_Payment_Method $payment_method) { |
|
2083 | 2083 | $payment = null; |
2084 | 2084 | $this->checkout->transaction->save(); |
2085 | - $payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' ); |
|
2086 | - if ( ! $payment_processor instanceof EE_Payment_Processor ) { |
|
2085 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2086 | + if ( ! $payment_processor instanceof EE_Payment_Processor) { |
|
2087 | 2087 | return false; |
2088 | 2088 | } |
2089 | 2089 | try { |
2090 | - $payment_processor->set_revisit( $this->checkout->revisit ); |
|
2090 | + $payment_processor->set_revisit($this->checkout->revisit); |
|
2091 | 2091 | // generate payment object |
2092 | 2092 | $payment = $payment_processor->process_payment( |
2093 | 2093 | $payment_method, |
2094 | 2094 | $this->checkout->transaction, |
2095 | 2095 | $this->checkout->amount_owing, |
2096 | 2096 | $this->checkout->billing_form, |
2097 | - $this->_get_return_url( $payment_method ), |
|
2097 | + $this->_get_return_url($payment_method), |
|
2098 | 2098 | 'CART', |
2099 | 2099 | $this->checkout->admin_request, |
2100 | 2100 | true, |
2101 | 2101 | $this->reg_step_url() |
2102 | 2102 | ); |
2103 | - } catch ( Exception $e ) { |
|
2104 | - $this->_handle_payment_processor_exception( $e ); |
|
2103 | + } catch (Exception $e) { |
|
2104 | + $this->_handle_payment_processor_exception($e); |
|
2105 | 2105 | } |
2106 | 2106 | return $payment; |
2107 | 2107 | } |
@@ -2116,7 +2116,7 @@ discard block |
||
2116 | 2116 | * @return void |
2117 | 2117 | * @throws \EE_Error |
2118 | 2118 | */ |
2119 | - protected function _handle_payment_processor_exception( Exception $e ) { |
|
2119 | + protected function _handle_payment_processor_exception(Exception $e) { |
|
2120 | 2120 | EE_Error::add_error( |
2121 | 2121 | sprintf( |
2122 | 2122 | __( |
@@ -2124,7 +2124,7 @@ discard block |
||
2124 | 2124 | 'event_espresso' |
2125 | 2125 | ), |
2126 | 2126 | '<br/>', |
2127 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ), |
|
2127 | + EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
2128 | 2128 | $e->getMessage(), |
2129 | 2129 | $e->getFile(), |
2130 | 2130 | $e->getLine() |
@@ -2145,9 +2145,9 @@ discard block |
||
2145 | 2145 | * @return string |
2146 | 2146 | * @throws \EE_Error |
2147 | 2147 | */ |
2148 | - protected function _get_return_url( EE_Payment_Method $payment_method ) { |
|
2148 | + protected function _get_return_url(EE_Payment_Method $payment_method) { |
|
2149 | 2149 | $return_url = ''; |
2150 | - switch ( $payment_method->type_obj()->payment_occurs() ) { |
|
2150 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
2151 | 2151 | case EE_PMT_Base::offsite : |
2152 | 2152 | $return_url = add_query_arg( |
2153 | 2153 | array( |
@@ -2176,12 +2176,12 @@ discard block |
||
2176 | 2176 | * @return EE_Payment | FALSE |
2177 | 2177 | * @throws \EE_Error |
2178 | 2178 | */ |
2179 | - private function _validate_payment( $payment = null ) { |
|
2180 | - if ( $this->checkout->payment_method->is_off_line() ) { |
|
2179 | + private function _validate_payment($payment = null) { |
|
2180 | + if ($this->checkout->payment_method->is_off_line()) { |
|
2181 | 2181 | return true; |
2182 | 2182 | } |
2183 | 2183 | // verify payment object |
2184 | - if ( ! $payment instanceof EE_Payment ) { |
|
2184 | + if ( ! $payment instanceof EE_Payment) { |
|
2185 | 2185 | // not a payment |
2186 | 2186 | EE_Error::add_error( |
2187 | 2187 | sprintf( |
@@ -2190,7 +2190,7 @@ discard block |
||
2190 | 2190 | 'event_espresso' |
2191 | 2191 | ), |
2192 | 2192 | '<br/>', |
2193 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
2193 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2194 | 2194 | ), |
2195 | 2195 | __FILE__, |
2196 | 2196 | __FUNCTION__, |
@@ -2211,27 +2211,27 @@ discard block |
||
2211 | 2211 | * @return bool |
2212 | 2212 | * @throws \EE_Error |
2213 | 2213 | */ |
2214 | - private function _post_payment_processing( $payment = null ) { |
|
2214 | + private function _post_payment_processing($payment = null) { |
|
2215 | 2215 | // Off-Line payment? |
2216 | - if ( $payment === true ) { |
|
2216 | + if ($payment === true) { |
|
2217 | 2217 | //$this->_setup_redirect_for_next_step(); |
2218 | 2218 | return true; |
2219 | 2219 | // On-Site payment? |
2220 | - } else if ( $this->checkout->payment_method->is_on_site() ) { |
|
2221 | - if ( ! $this->_process_payment_status( $payment, EE_PMT_Base::onsite ) ) { |
|
2220 | + } else if ($this->checkout->payment_method->is_on_site()) { |
|
2221 | + if ( ! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2222 | 2222 | //$this->_setup_redirect_for_next_step(); |
2223 | 2223 | $this->checkout->continue_reg = false; |
2224 | 2224 | } |
2225 | 2225 | // Off-Site payment? |
2226 | - } else if ( $this->checkout->payment_method->is_off_site() ) { |
|
2226 | + } else if ($this->checkout->payment_method->is_off_site()) { |
|
2227 | 2227 | // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
2228 | - if ( $payment instanceof EE_Payment && $payment->redirect_url() ) { |
|
2229 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()' ); |
|
2228 | + if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
2229 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
2230 | 2230 | $this->checkout->redirect = true; |
2231 | 2231 | $this->checkout->redirect_form = $payment->redirect_form(); |
2232 | - $this->checkout->redirect_url = $this->reg_step_url( 'redirect_form' ); |
|
2232 | + $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
2233 | 2233 | // set JSON response |
2234 | - $this->checkout->json_response->set_redirect_form( $this->checkout->redirect_form ); |
|
2234 | + $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
2235 | 2235 | // set cron job for finalizing the TXN |
2236 | 2236 | // in case the user does not return from the off-site gateway |
2237 | 2237 | EE_Cron_Tasks::schedule_finalize_abandoned_transactions_check( |
@@ -2239,7 +2239,7 @@ discard block |
||
2239 | 2239 | $this->checkout->transaction->ID() |
2240 | 2240 | ); |
2241 | 2241 | // and lastly, let's bump the payment status to pending |
2242 | - $payment->set_status( EEM_Payment::status_id_pending ); |
|
2242 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
2243 | 2243 | $payment->save(); |
2244 | 2244 | } else { |
2245 | 2245 | // not a payment |
@@ -2251,7 +2251,7 @@ discard block |
||
2251 | 2251 | 'event_espresso' |
2252 | 2252 | ), |
2253 | 2253 | '<br/>', |
2254 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
2254 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2255 | 2255 | ), |
2256 | 2256 | __FILE__, |
2257 | 2257 | __FUNCTION__, |
@@ -2289,21 +2289,21 @@ discard block |
||
2289 | 2289 | * @return bool |
2290 | 2290 | * @throws \EE_Error |
2291 | 2291 | */ |
2292 | - private function _process_payment_status( $payment, $payment_occurs = EE_PMT_Base::offline ) { |
|
2292 | + private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) { |
|
2293 | 2293 | // off-line payment? carry on |
2294 | - if ( $payment_occurs === EE_PMT_Base::offline ) { |
|
2294 | + if ($payment_occurs === EE_PMT_Base::offline) { |
|
2295 | 2295 | return true; |
2296 | 2296 | } |
2297 | 2297 | // verify payment validity |
2298 | - if ( $payment instanceof EE_Payment ) { |
|
2299 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()' ); |
|
2298 | + if ($payment instanceof EE_Payment) { |
|
2299 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
2300 | 2300 | $msg = $payment->gateway_response(); |
2301 | 2301 | // check results |
2302 | - switch ( $payment->status() ) { |
|
2302 | + switch ($payment->status()) { |
|
2303 | 2303 | // good payment |
2304 | 2304 | case EEM_Payment::status_id_approved : |
2305 | 2305 | EE_Error::add_success( |
2306 | - __( 'Your payment was processed successfully.', 'event_espresso' ), |
|
2306 | + __('Your payment was processed successfully.', 'event_espresso'), |
|
2307 | 2307 | __FILE__, |
2308 | 2308 | __FUNCTION__, |
2309 | 2309 | __LINE__ |
@@ -2312,45 +2312,45 @@ discard block |
||
2312 | 2312 | break; |
2313 | 2313 | // slow payment |
2314 | 2314 | case EEM_Payment::status_id_pending : |
2315 | - if ( empty( $msg ) ) { |
|
2315 | + if (empty($msg)) { |
|
2316 | 2316 | $msg = __( |
2317 | 2317 | 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
2318 | 2318 | 'event_espresso' |
2319 | 2319 | ); |
2320 | 2320 | } |
2321 | - EE_Error::add_success( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
2321 | + EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2322 | 2322 | return true; |
2323 | 2323 | break; |
2324 | 2324 | // don't wanna payment |
2325 | 2325 | case EEM_Payment::status_id_cancelled : |
2326 | - if ( empty( $msg ) ) { |
|
2326 | + if (empty($msg)) { |
|
2327 | 2327 | $msg = _n( |
2328 | 2328 | 'Payment cancelled. Please try again.', |
2329 | 2329 | 'Payment cancelled. Please try again or select another method of payment.', |
2330 | - count( $this->checkout->available_payment_methods ), |
|
2330 | + count($this->checkout->available_payment_methods), |
|
2331 | 2331 | 'event_espresso' |
2332 | 2332 | ); |
2333 | 2333 | } |
2334 | - EE_Error::add_attention( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
2334 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2335 | 2335 | return false; |
2336 | 2336 | break; |
2337 | 2337 | // not enough payment |
2338 | 2338 | case EEM_Payment::status_id_declined : |
2339 | - if ( empty( $msg ) ) { |
|
2339 | + if (empty($msg)) { |
|
2340 | 2340 | $msg = _n( |
2341 | 2341 | 'We\'re sorry but your payment was declined. Please try again.', |
2342 | 2342 | 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
2343 | - count( $this->checkout->available_payment_methods ), |
|
2343 | + count($this->checkout->available_payment_methods), |
|
2344 | 2344 | 'event_espresso' |
2345 | 2345 | ); |
2346 | 2346 | } |
2347 | - EE_Error::add_attention( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
2347 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2348 | 2348 | return false; |
2349 | 2349 | break; |
2350 | 2350 | // bad payment |
2351 | 2351 | case EEM_Payment::status_id_failed : |
2352 | - if ( ! empty( $msg ) ) { |
|
2353 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
2352 | + if ( ! empty($msg)) { |
|
2353 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2354 | 2354 | return false; |
2355 | 2355 | } |
2356 | 2356 | // default to error below |
@@ -2359,7 +2359,7 @@ discard block |
||
2359 | 2359 | } |
2360 | 2360 | // off-site payment gateway responses are too unreliable, so let's just assume that |
2361 | 2361 | // the payment processing is just running slower than the registrant's request |
2362 | - if ( $payment_occurs === EE_PMT_Base::offsite ) { |
|
2362 | + if ($payment_occurs === EE_PMT_Base::offsite) { |
|
2363 | 2363 | return true; |
2364 | 2364 | } |
2365 | 2365 | EE_Error::add_error( |
@@ -2369,7 +2369,7 @@ discard block |
||
2369 | 2369 | 'event_espresso' |
2370 | 2370 | ), |
2371 | 2371 | '<br/>', |
2372 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
2372 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2373 | 2373 | ), |
2374 | 2374 | __FILE__, |
2375 | 2375 | __FUNCTION__, |
@@ -2402,13 +2402,13 @@ discard block |
||
2402 | 2402 | public function process_gateway_response() { |
2403 | 2403 | $payment = null; |
2404 | 2404 | // how have they chosen to pay? |
2405 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( true ); |
|
2405 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
2406 | 2406 | // get EE_Payment_Method object |
2407 | - if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() ) { |
|
2407 | + if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2408 | 2408 | $this->checkout->continue_reg = false; |
2409 | 2409 | return false; |
2410 | 2410 | } |
2411 | - if ( ! $this->checkout->payment_method->is_off_site() ) { |
|
2411 | + if ( ! $this->checkout->payment_method->is_off_site()) { |
|
2412 | 2412 | return false; |
2413 | 2413 | } |
2414 | 2414 | $this->_validate_offsite_return(); |
@@ -2422,23 +2422,23 @@ discard block |
||
2422 | 2422 | // true |
2423 | 2423 | //); |
2424 | 2424 | // verify TXN |
2425 | - if ( $this->checkout->transaction instanceof EE_Transaction ) { |
|
2425 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
2426 | 2426 | $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
2427 | - if ( ! $gateway instanceof EE_Offsite_Gateway ) { |
|
2427 | + if ( ! $gateway instanceof EE_Offsite_Gateway) { |
|
2428 | 2428 | $this->checkout->continue_reg = false; |
2429 | 2429 | return false; |
2430 | 2430 | } |
2431 | - $payment = $this->_process_off_site_payment( $gateway ); |
|
2432 | - $payment = $this->_process_cancelled_payments( $payment ); |
|
2433 | - $payment = $this->_validate_payment( $payment ); |
|
2431 | + $payment = $this->_process_off_site_payment($gateway); |
|
2432 | + $payment = $this->_process_cancelled_payments($payment); |
|
2433 | + $payment = $this->_validate_payment($payment); |
|
2434 | 2434 | // if payment was not declined by the payment gateway or cancelled by the registrant |
2435 | - if ( $this->_process_payment_status( $payment, EE_PMT_Base::offsite ) ) { |
|
2435 | + if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
2436 | 2436 | //$this->_setup_redirect_for_next_step(); |
2437 | 2437 | // store that for later |
2438 | 2438 | $this->checkout->payment = $payment; |
2439 | 2439 | // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
2440 | 2440 | // because we will complete this step during the IPN processing then |
2441 | - if ( $gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request() ) { |
|
2441 | + if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
2442 | 2442 | $this->set_completed(); |
2443 | 2443 | } |
2444 | 2444 | return true; |
@@ -2463,21 +2463,21 @@ discard block |
||
2463 | 2463 | * @throws \EE_Error |
2464 | 2464 | */ |
2465 | 2465 | private function _validate_offsite_return() { |
2466 | - $TXN_ID = (int)EE_Registry::instance()->REQ->get( 'spco_txn', 0 ); |
|
2467 | - if ( $TXN_ID !== $this->checkout->transaction->ID() ) { |
|
2466 | + $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
2467 | + if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
2468 | 2468 | // Houston... we might have a problem |
2469 | 2469 | $invalid_TXN = false; |
2470 | 2470 | // first gather some info |
2471 | - $valid_TXN = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID ); |
|
2471 | + $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2472 | 2472 | $primary_registrant = $valid_TXN instanceof EE_Transaction |
2473 | 2473 | ? $valid_TXN->primary_registration() |
2474 | 2474 | : null; |
2475 | 2475 | // let's start by retrieving the cart for this TXN |
2476 | - $cart = $this->checkout->get_cart_for_transaction( $this->checkout->transaction ); |
|
2477 | - if ( $cart instanceof EE_Cart ) { |
|
2476 | + $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
2477 | + if ($cart instanceof EE_Cart) { |
|
2478 | 2478 | // verify that the current cart has tickets |
2479 | 2479 | $tickets = $cart->get_tickets(); |
2480 | - if ( empty( $tickets ) ) { |
|
2480 | + if (empty($tickets)) { |
|
2481 | 2481 | $invalid_TXN = true; |
2482 | 2482 | } |
2483 | 2483 | } else { |
@@ -2503,21 +2503,21 @@ discard block |
||
2503 | 2503 | ) { |
2504 | 2504 | $invalid_TXN = true; |
2505 | 2505 | } |
2506 | - if ( $invalid_TXN ) { |
|
2506 | + if ($invalid_TXN) { |
|
2507 | 2507 | // is the valid TXN completed ? |
2508 | - if ( $valid_TXN instanceof EE_Transaction ) { |
|
2508 | + if ($valid_TXN instanceof EE_Transaction) { |
|
2509 | 2509 | // has this step even been started ? |
2510 | - $reg_step_completed = $valid_TXN->reg_step_completed( $this->slug() ); |
|
2511 | - if ( $reg_step_completed !== false && $reg_step_completed !== true ) { |
|
2510 | + $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
2511 | + if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
2512 | 2512 | // so it **looks** like this is a double request from PayPal |
2513 | 2513 | // so let's try to pick up where we left off |
2514 | 2514 | $this->checkout->transaction = $valid_TXN; |
2515 | - $this->checkout->refresh_all_entities( true ); |
|
2515 | + $this->checkout->refresh_all_entities(true); |
|
2516 | 2516 | return; |
2517 | 2517 | } |
2518 | 2518 | } |
2519 | 2519 | // you appear to be lost? |
2520 | - $this->_redirect_wayward_request( $primary_registrant ); |
|
2520 | + $this->_redirect_wayward_request($primary_registrant); |
|
2521 | 2521 | } |
2522 | 2522 | } |
2523 | 2523 | } |
@@ -2532,14 +2532,14 @@ discard block |
||
2532 | 2532 | * @return bool |
2533 | 2533 | * @throws \EE_Error |
2534 | 2534 | */ |
2535 | - private function _redirect_wayward_request( EE_Registration $primary_registrant ) { |
|
2536 | - if ( ! $primary_registrant instanceof EE_Registration ) { |
|
2535 | + private function _redirect_wayward_request(EE_Registration $primary_registrant) { |
|
2536 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
2537 | 2537 | // try redirecting based on the current TXN |
2538 | 2538 | $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
2539 | 2539 | ? $this->checkout->transaction->primary_registration() |
2540 | 2540 | : null; |
2541 | 2541 | } |
2542 | - if ( ! $primary_registrant instanceof EE_Registration ) { |
|
2542 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
2543 | 2543 | EE_Error::add_error( |
2544 | 2544 | sprintf( |
2545 | 2545 | __( |
@@ -2547,7 +2547,7 @@ discard block |
||
2547 | 2547 | 'event_espresso' |
2548 | 2548 | ), |
2549 | 2549 | '<br/>', |
2550 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
2550 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2551 | 2551 | ), |
2552 | 2552 | __FILE__, |
2553 | 2553 | __FUNCTION__, |
@@ -2578,17 +2578,17 @@ discard block |
||
2578 | 2578 | * @return \EE_Payment |
2579 | 2579 | * @throws \EE_Error |
2580 | 2580 | */ |
2581 | - private function _process_off_site_payment( EE_Offsite_Gateway $gateway ) { |
|
2581 | + private function _process_off_site_payment(EE_Offsite_Gateway $gateway) { |
|
2582 | 2582 | try { |
2583 | 2583 | $request_data = \EE_Registry::instance()->REQ->params(); |
2584 | 2584 | // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
2585 | 2585 | $this->set_handle_IPN_in_this_request( |
2586 | - $gateway->handle_IPN_in_this_request( $request_data, false ) |
|
2586 | + $gateway->handle_IPN_in_this_request($request_data, false) |
|
2587 | 2587 | ); |
2588 | - if ( $this->handle_IPN_in_this_request() ) { |
|
2588 | + if ($this->handle_IPN_in_this_request()) { |
|
2589 | 2589 | // get payment details and process results |
2590 | 2590 | /** @type EE_Payment_Processor $payment_processor */ |
2591 | - $payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' ); |
|
2591 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2592 | 2592 | $payment = $payment_processor->process_ipn( |
2593 | 2593 | $request_data, |
2594 | 2594 | $this->checkout->transaction, |
@@ -2601,14 +2601,14 @@ discard block |
||
2601 | 2601 | $payment = $this->checkout->transaction->last_payment(); |
2602 | 2602 | //$payment_source = 'last_payment'; |
2603 | 2603 | } |
2604 | - } catch ( Exception $e ) { |
|
2604 | + } catch (Exception $e) { |
|
2605 | 2605 | // let's just eat the exception and try to move on using any previously set payment info |
2606 | 2606 | $payment = $this->checkout->transaction->last_payment(); |
2607 | 2607 | //$payment_source = 'last_payment after Exception'; |
2608 | 2608 | // but if we STILL don't have a payment object |
2609 | - if ( ! $payment instanceof EE_Payment ) { |
|
2609 | + if ( ! $payment instanceof EE_Payment) { |
|
2610 | 2610 | // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
2611 | - $this->_handle_payment_processor_exception( $e ); |
|
2611 | + $this->_handle_payment_processor_exception($e); |
|
2612 | 2612 | } |
2613 | 2613 | } |
2614 | 2614 | // DEBUG LOG |
@@ -2633,13 +2633,13 @@ discard block |
||
2633 | 2633 | * @return EE_Payment | FALSE |
2634 | 2634 | * @throws \EE_Error |
2635 | 2635 | */ |
2636 | - private function _process_cancelled_payments( $payment = null ) { |
|
2636 | + private function _process_cancelled_payments($payment = null) { |
|
2637 | 2637 | if ( |
2638 | 2638 | $payment instanceof EE_Payment |
2639 | - && isset( $_REQUEST['ee_cancel_payment'] ) |
|
2639 | + && isset($_REQUEST['ee_cancel_payment']) |
|
2640 | 2640 | && $payment->status() === EEM_Payment::status_id_failed |
2641 | 2641 | ) { |
2642 | - $payment->set_status( EEM_Payment::status_id_cancelled ); |
|
2642 | + $payment->set_status(EEM_Payment::status_id_cancelled); |
|
2643 | 2643 | } |
2644 | 2644 | return $payment; |
2645 | 2645 | } |
@@ -2656,14 +2656,14 @@ discard block |
||
2656 | 2656 | public function get_transaction_details_for_gateways() { |
2657 | 2657 | $txn_details = array(); |
2658 | 2658 | // ya gotta make a choice man |
2659 | - if ( empty( $this->checkout->selected_method_of_payment ) ) { |
|
2659 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
2660 | 2660 | $txn_details = array( |
2661 | - 'error' => __( 'Please select a method of payment before proceeding.', 'event_espresso' ) |
|
2661 | + 'error' => __('Please select a method of payment before proceeding.', 'event_espresso') |
|
2662 | 2662 | ); |
2663 | 2663 | } |
2664 | 2664 | // get EE_Payment_Method object |
2665 | 2665 | if ( |
2666 | - empty( $txn_details ) |
|
2666 | + empty($txn_details) |
|
2667 | 2667 | && |
2668 | 2668 | ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
2669 | 2669 | ) { |
@@ -2675,8 +2675,8 @@ discard block |
||
2675 | 2675 | ) |
2676 | 2676 | ); |
2677 | 2677 | } |
2678 | - if ( empty( $txn_details ) && $this->checkout->transaction instanceof EE_Transaction ) { |
|
2679 | - $return_url = $this->_get_return_url( $this->checkout->payment_method ); |
|
2678 | + if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
2679 | + $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
2680 | 2680 | $txn_details = array( |
2681 | 2681 | 'TXN_ID' => $this->checkout->transaction->ID(), |
2682 | 2682 | 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
@@ -2687,7 +2687,7 @@ discard block |
||
2687 | 2687 | 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
2688 | 2688 | 'payment_amount' => $this->checkout->amount_owing, |
2689 | 2689 | 'return_url' => $return_url, |
2690 | - 'cancel_url' => add_query_arg( array( 'ee_cancel_payment' => true ), $return_url ), |
|
2690 | + 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
2691 | 2691 | 'notify_url' => EE_Config::instance()->core->txn_page_url( |
2692 | 2692 | array( |
2693 | 2693 | 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
@@ -2696,7 +2696,7 @@ discard block |
||
2696 | 2696 | ) |
2697 | 2697 | ); |
2698 | 2698 | } |
2699 | - echo wp_json_encode( $txn_details ); |
|
2699 | + echo wp_json_encode($txn_details); |
|
2700 | 2700 | exit(); |
2701 | 2701 | } |
2702 | 2702 | |
@@ -2713,7 +2713,7 @@ discard block |
||
2713 | 2713 | public function __sleep() |
2714 | 2714 | { |
2715 | 2715 | // remove the reg form and the checkout |
2716 | - return array_diff( array_keys( get_object_vars( $this ) ), array( 'reg_form', 'checkout', 'line_item_display' ) ); |
|
2716 | + return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
2717 | 2717 | } |
2718 | 2718 | |
2719 | 2719 |
@@ -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 | ?> |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | { |
121 | 121 | wp_register_style( |
122 | 122 | 'espresso-admin-toolbar', |
123 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css', |
|
123 | + EE_GLOBAL_ASSETS_URL.'css/espresso-admin-toolbar.css', |
|
124 | 124 | array('dashicons'), |
125 | 125 | EVENT_ESPRESSO_VERSION |
126 | 126 | ); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | 'href' => $this->events_admin_url, |
144 | 144 | 'meta' => array( |
145 | 145 | 'title' => esc_html__('Event Espresso', 'event_espresso'), |
146 | - 'class' => $this->menu_class . 'first', |
|
146 | + 'class' => $this->menu_class.'first', |
|
147 | 147 | ), |
148 | 148 | ) |
149 | 149 | ); |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | 'meta' => array( |
492 | 492 | 'title' => esc_html__('Approved', 'event_espresso'), |
493 | 493 | 'target' => '', |
494 | - 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
494 | + 'class' => $this->menu_class.' ee-toolbar-icon-approved', |
|
495 | 495 | ), |
496 | 496 | ) |
497 | 497 | ); |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | 'meta' => array( |
529 | 529 | 'title' => esc_html__('Pending Payment', 'event_espresso'), |
530 | 530 | 'target' => '', |
531 | - 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
531 | + 'class' => $this->menu_class.' ee-toolbar-icon-pending', |
|
532 | 532 | ), |
533 | 533 | ) |
534 | 534 | ); |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | 'meta' => array( |
566 | 566 | 'title' => esc_html__('Not Approved', 'event_espresso'), |
567 | 567 | 'target' => '', |
568 | - 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
568 | + 'class' => $this->menu_class.' ee-toolbar-icon-not-approved', |
|
569 | 569 | ), |
570 | 570 | ) |
571 | 571 | ); |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | 'meta' => array( |
603 | 603 | 'title' => esc_html__('Cancelled', 'event_espresso'), |
604 | 604 | 'target' => '', |
605 | - 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
605 | + 'class' => $this->menu_class.' ee-toolbar-icon-cancelled', |
|
606 | 606 | ), |
607 | 607 | ) |
608 | 608 | ); |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | 'meta' => array( |
675 | 675 | 'title' => esc_html__('Approved', 'event_espresso'), |
676 | 676 | 'target' => '', |
677 | - 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
677 | + 'class' => $this->menu_class.' ee-toolbar-icon-approved', |
|
678 | 678 | ), |
679 | 679 | ) |
680 | 680 | ); |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | 'meta' => array( |
712 | 712 | 'title' => esc_html__('Pending', 'event_espresso'), |
713 | 713 | 'target' => '', |
714 | - 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
714 | + 'class' => $this->menu_class.' ee-toolbar-icon-pending', |
|
715 | 715 | ), |
716 | 716 | ) |
717 | 717 | ); |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | 'meta' => array( |
749 | 749 | 'title' => esc_html__('Not Approved', 'event_espresso'), |
750 | 750 | 'target' => '', |
751 | - 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
751 | + 'class' => $this->menu_class.' ee-toolbar-icon-not-approved', |
|
752 | 752 | ), |
753 | 753 | ) |
754 | 754 | ); |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | 'meta' => array( |
786 | 786 | 'title' => esc_html__('Cancelled', 'event_espresso'), |
787 | 787 | 'target' => '', |
788 | - 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
788 | + 'class' => $this->menu_class.' ee-toolbar-icon-cancelled', |
|
789 | 789 | ), |
790 | 790 | ) |
791 | 791 | ); |
@@ -22,804 +22,804 @@ |
||
22 | 22 | class AdminToolBar |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var WP_Admin_Bar $admin_bar |
|
27 | - */ |
|
28 | - private $admin_bar; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var EE_Capabilities $capabilities |
|
32 | - */ |
|
33 | - private $capabilities; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string $events_admin_url |
|
37 | - */ |
|
38 | - private $events_admin_url; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var string $menu_class |
|
42 | - */ |
|
43 | - private $menu_class = 'espresso_menu_item_class'; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var string $reg_admin_url |
|
47 | - */ |
|
48 | - private $reg_admin_url; |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * AdminToolBar constructor. |
|
54 | - * |
|
55 | - * @param EE_Capabilities $capabilities |
|
56 | - */ |
|
57 | - public function __construct(EE_Capabilities $capabilities) |
|
58 | - { |
|
59 | - $this->capabilities = $capabilities; |
|
60 | - add_action('admin_bar_menu', array($this, 'espressoToolbarItems'), 100); |
|
61 | - $this->enqueueAssets(); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * espresso_toolbar_items |
|
68 | - * |
|
69 | - * @access public |
|
70 | - * @param WP_Admin_Bar $admin_bar |
|
71 | - * @return void |
|
72 | - */ |
|
73 | - public function espressoToolbarItems(WP_Admin_Bar $admin_bar) |
|
74 | - { |
|
75 | - // if its an AJAX request, or user is NOT an admin, or in full M-Mode |
|
76 | - if ( |
|
77 | - defined('DOING_AJAX') |
|
78 | - || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
79 | - || EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
80 | - ) { |
|
81 | - return; |
|
82 | - } |
|
83 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
84 | - $this->admin_bar = $admin_bar; |
|
85 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
86 | - //because they're only defined in each of their respective constructors |
|
87 | - //and this might be a frontend request, in which case they aren't available |
|
88 | - $this->events_admin_url = admin_url('admin.php?page=espresso_events'); |
|
89 | - $this->reg_admin_url = admin_url('admin.php?page=espresso_registrations'); |
|
90 | - // now let's add all of the menu items |
|
91 | - $this->addTopLevelMenu(); |
|
92 | - $this->addEventsSubMenu(); |
|
93 | - $this->addEventsAddEditHeader(); |
|
94 | - $this->addEventsAddNew(); |
|
95 | - $this->addEventsEditCurrentEvent(); |
|
96 | - $this->addEventsViewHeader(); |
|
97 | - $this->addEventsViewAll(); |
|
98 | - $this->addEventsViewToday(); |
|
99 | - $this->addEventsViewThisMonth(); |
|
100 | - $this->addRegistrationSubMenu(); |
|
101 | - $this->addRegistrationOverviewToday(); |
|
102 | - $this->addRegistrationOverviewTodayApproved(); |
|
103 | - $this->addRegistrationOverviewTodayPendingPayment(); |
|
104 | - $this->addRegistrationOverviewTodayNotApproved(); |
|
105 | - $this->addRegistrationOverviewTodayCancelled(); |
|
106 | - $this->addRegistrationOverviewThisMonth(); |
|
107 | - $this->addRegistrationOverviewThisMonthApproved(); |
|
108 | - $this->addRegistrationOverviewThisMonthPending(); |
|
109 | - $this->addRegistrationOverviewThisMonthNotApproved(); |
|
110 | - $this->addRegistrationOverviewThisMonthCancelled(); |
|
111 | - $this->addExtensionsAndServices(); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - private function enqueueAssets() |
|
120 | - { |
|
121 | - wp_register_style( |
|
122 | - 'espresso-admin-toolbar', |
|
123 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css', |
|
124 | - array('dashicons'), |
|
125 | - EVENT_ESPRESSO_VERSION |
|
126 | - ); |
|
127 | - wp_enqueue_style('espresso-admin-toolbar'); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - private function addTopLevelMenu() |
|
136 | - { |
|
137 | - $this->admin_bar->add_menu( |
|
138 | - array( |
|
139 | - 'id' => 'espresso-toolbar', |
|
140 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
141 | - . esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
142 | - . '</span>', |
|
143 | - 'href' => $this->events_admin_url, |
|
144 | - 'meta' => array( |
|
145 | - 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
146 | - 'class' => $this->menu_class . 'first', |
|
147 | - ), |
|
148 | - ) |
|
149 | - ); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - private function addEventsSubMenu() |
|
158 | - { |
|
159 | - if ( |
|
160 | - $this->capabilities->current_user_can( |
|
161 | - 'ee_read_events', |
|
162 | - 'ee_admin_bar_menu_espresso-toolbar-events' |
|
163 | - ) |
|
164 | - ) { |
|
165 | - $this->admin_bar->add_menu( |
|
166 | - array( |
|
167 | - 'id' => 'espresso-toolbar-events', |
|
168 | - 'parent' => 'espresso-toolbar', |
|
169 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
170 | - . esc_html__('Events', 'event_espresso'), |
|
171 | - 'href' => $this->events_admin_url, |
|
172 | - 'meta' => array( |
|
173 | - 'title' => esc_html__('Events', 'event_espresso'), |
|
174 | - 'target' => '', |
|
175 | - 'class' => $this->menu_class, |
|
176 | - ), |
|
177 | - ) |
|
178 | - ); |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @return void |
|
186 | - */ |
|
187 | - private function addEventsAddEditHeader() |
|
188 | - { |
|
189 | - if ( |
|
190 | - $this->capabilities->current_user_can( |
|
191 | - 'ee_read_events', |
|
192 | - 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
193 | - ) |
|
194 | - ) { |
|
195 | - $this->admin_bar->add_menu( |
|
196 | - array( |
|
197 | - 'id' => 'espresso-toolbar-events-add-edit', |
|
198 | - 'parent' => 'espresso-toolbar-events', |
|
199 | - 'title' => esc_html__('Add / Edit', 'event_espresso'), |
|
200 | - 'href' => '', |
|
201 | - ) |
|
202 | - ); |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - private function addEventsAddNew() |
|
212 | - { |
|
213 | - if ( |
|
214 | - $this->capabilities->current_user_can( |
|
215 | - 'ee_edit_events', |
|
216 | - 'ee_admin_bar_menu_espresso-toolbar-events-new' |
|
217 | - ) |
|
218 | - ) { |
|
219 | - $this->admin_bar->add_menu( |
|
220 | - array( |
|
221 | - 'id' => 'espresso-toolbar-events-new', |
|
222 | - 'parent' => 'espresso-toolbar-events', |
|
223 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
224 | - . esc_html__('Add New', 'event_espresso'), |
|
225 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
226 | - array('action' => 'create_new'), |
|
227 | - $this->events_admin_url |
|
228 | - ), |
|
229 | - 'meta' => array( |
|
230 | - 'title' => esc_html__('Add New', 'event_espresso'), |
|
231 | - 'target' => '', |
|
232 | - 'class' => $this->menu_class, |
|
233 | - ), |
|
234 | - ) |
|
235 | - ); |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @return void |
|
243 | - */ |
|
244 | - private function addEventsEditCurrentEvent() |
|
245 | - { |
|
246 | - if (is_single() && (get_post_type() === 'espresso_events')) { |
|
247 | - //Current post |
|
248 | - global $post; |
|
249 | - if ( |
|
250 | - $this->capabilities->current_user_can( |
|
251 | - 'ee_edit_event', |
|
252 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID |
|
253 | - ) |
|
254 | - ) { |
|
255 | - $this->admin_bar->add_menu( |
|
256 | - array( |
|
257 | - 'id' => 'espresso-toolbar-events-edit', |
|
258 | - 'parent' => 'espresso-toolbar-events', |
|
259 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
260 | - . esc_html__('Edit Event', 'event_espresso'), |
|
261 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
262 | - array( |
|
263 | - 'action' => 'edit', |
|
264 | - 'post' => $post->ID |
|
265 | - ), |
|
266 | - $this->events_admin_url |
|
267 | - ), |
|
268 | - 'meta' => array( |
|
269 | - 'title' => esc_html__('Edit Event', 'event_espresso'), |
|
270 | - 'target' => '', |
|
271 | - 'class' => $this->menu_class, |
|
272 | - ), |
|
273 | - ) |
|
274 | - ); |
|
275 | - } |
|
276 | - } |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * @return void |
|
283 | - */ |
|
284 | - private function addEventsViewHeader() |
|
285 | - { |
|
286 | - if ( |
|
287 | - $this->capabilities->current_user_can( |
|
288 | - 'ee_read_events', |
|
289 | - 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
290 | - ) |
|
291 | - ) { |
|
292 | - $this->admin_bar->add_menu( |
|
293 | - array( |
|
294 | - 'id' => 'espresso-toolbar-events-view', |
|
295 | - 'parent' => 'espresso-toolbar-events', |
|
296 | - 'title' => esc_html__('View', 'event_espresso'), |
|
297 | - 'href' => '', |
|
298 | - ) |
|
299 | - ); |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * @return void |
|
307 | - */ |
|
308 | - private function addEventsViewAll() |
|
309 | - { |
|
310 | - if ( |
|
311 | - $this->capabilities->current_user_can( |
|
312 | - 'ee_read_events', |
|
313 | - 'ee_admin_bar_menu_espresso-toolbar-events-all' |
|
314 | - ) |
|
315 | - ) { |
|
316 | - $this->admin_bar->add_menu( |
|
317 | - array( |
|
318 | - 'id' => 'espresso-toolbar-events-all', |
|
319 | - 'parent' => 'espresso-toolbar-events', |
|
320 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
321 | - . esc_html__('All', 'event_espresso'), |
|
322 | - 'href' => $this->events_admin_url, |
|
323 | - 'meta' => array( |
|
324 | - 'title' => esc_html__('All', 'event_espresso'), |
|
325 | - 'target' => '', |
|
326 | - 'class' => $this->menu_class, |
|
327 | - ), |
|
328 | - ) |
|
329 | - ); |
|
330 | - } |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * @return void |
|
337 | - */ |
|
338 | - private function addEventsViewToday() |
|
339 | - { |
|
340 | - if ( |
|
341 | - $this->capabilities->current_user_can( |
|
342 | - 'ee_read_events', |
|
343 | - 'ee_admin_bar_menu_espresso-toolbar-events-today' |
|
344 | - ) |
|
345 | - ) { |
|
346 | - $this->admin_bar->add_menu( |
|
347 | - array( |
|
348 | - 'id' => 'espresso-toolbar-events-today', |
|
349 | - 'parent' => 'espresso-toolbar-events', |
|
350 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
351 | - . esc_html__('Today', 'event_espresso'), |
|
352 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
353 | - array( |
|
354 | - 'action' => 'default', |
|
355 | - 'status' => 'today' |
|
356 | - ), |
|
357 | - $this->events_admin_url |
|
358 | - ), |
|
359 | - 'meta' => array( |
|
360 | - 'title' => esc_html__('Today', 'event_espresso'), |
|
361 | - 'target' => '', |
|
362 | - 'class' => $this->menu_class, |
|
363 | - ), |
|
364 | - ) |
|
365 | - ); |
|
366 | - } |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * @return void |
|
373 | - */ |
|
374 | - private function addEventsViewThisMonth() |
|
375 | - { |
|
376 | - if ( |
|
377 | - $this->capabilities->current_user_can( |
|
378 | - 'ee_read_events', |
|
379 | - 'ee_admin_bar_menu_espresso-toolbar-events-month' |
|
380 | - ) |
|
381 | - ) { |
|
382 | - $this->admin_bar->add_menu( |
|
383 | - array( |
|
384 | - 'id' => 'espresso-toolbar-events-month', |
|
385 | - 'parent' => 'espresso-toolbar-events', |
|
386 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
387 | - . esc_html__('This Month', 'event_espresso'), |
|
388 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
389 | - array( |
|
390 | - 'action' => 'default', |
|
391 | - 'status' => 'month' |
|
392 | - ), |
|
393 | - $this->events_admin_url |
|
394 | - ), |
|
395 | - 'meta' => array( |
|
396 | - 'title' => esc_html__('This Month', 'event_espresso'), |
|
397 | - 'target' => '', |
|
398 | - 'class' => $this->menu_class, |
|
399 | - ), |
|
400 | - ) |
|
401 | - ); |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * @return void |
|
409 | - */ |
|
410 | - private function addRegistrationSubMenu() |
|
411 | - { |
|
412 | - if ( |
|
413 | - $this->capabilities->current_user_can( |
|
414 | - 'ee_read_registrations', |
|
415 | - 'ee_admin_bar_menu_espresso-toolbar-registrations' |
|
416 | - ) |
|
417 | - ) { |
|
418 | - $this->admin_bar->add_menu( |
|
419 | - array( |
|
420 | - 'id' => 'espresso-toolbar-registrations', |
|
421 | - 'parent' => 'espresso-toolbar', |
|
422 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
423 | - . esc_html__('Registrations', 'event_espresso'), |
|
424 | - 'href' => $this->reg_admin_url, |
|
425 | - 'meta' => array( |
|
426 | - 'title' => esc_html__('Registrations', 'event_espresso'), |
|
427 | - 'target' => '', |
|
428 | - 'class' => $this->menu_class, |
|
429 | - ), |
|
430 | - ) |
|
431 | - ); |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * @return void |
|
439 | - */ |
|
440 | - private function addRegistrationOverviewToday() |
|
441 | - { |
|
442 | - if ( |
|
443 | - $this->capabilities->current_user_can( |
|
444 | - 'ee_read_registrations', |
|
445 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today' |
|
446 | - ) |
|
447 | - ) { |
|
448 | - $this->admin_bar->add_menu( |
|
449 | - array( |
|
450 | - 'id' => 'espresso-toolbar-registrations-today', |
|
451 | - 'parent' => 'espresso-toolbar-registrations', |
|
452 | - 'title' => esc_html__('Today', 'event_espresso'), |
|
453 | - 'href' => '', |
|
454 | - 'meta' => array( |
|
455 | - 'title' => esc_html__('Today', 'event_espresso'), |
|
456 | - 'target' => '', |
|
457 | - 'class' => $this->menu_class, |
|
458 | - ), |
|
459 | - ) |
|
460 | - ); |
|
461 | - } |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * @return void |
|
468 | - */ |
|
469 | - private function addRegistrationOverviewTodayApproved() |
|
470 | - { |
|
471 | - if ( |
|
472 | - $this->capabilities->current_user_can( |
|
473 | - 'ee_read_registrations', |
|
474 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' |
|
475 | - ) |
|
476 | - ) { |
|
477 | - $this->admin_bar->add_menu( |
|
478 | - array( |
|
479 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
480 | - 'parent' => 'espresso-toolbar-registrations', |
|
481 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
482 | - . esc_html__('Approved', 'event_espresso'), |
|
483 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
484 | - array( |
|
485 | - 'action' => 'default', |
|
486 | - 'status' => 'today', |
|
487 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
488 | - ), |
|
489 | - $this->reg_admin_url |
|
490 | - ), |
|
491 | - 'meta' => array( |
|
492 | - 'title' => esc_html__('Approved', 'event_espresso'), |
|
493 | - 'target' => '', |
|
494 | - 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
495 | - ), |
|
496 | - ) |
|
497 | - ); |
|
498 | - } |
|
499 | - } |
|
500 | - |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * @return void |
|
505 | - */ |
|
506 | - private function addRegistrationOverviewTodayPendingPayment() |
|
507 | - { |
|
508 | - if ( |
|
509 | - $this->capabilities->current_user_can( |
|
510 | - 'ee_read_registrations', |
|
511 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' |
|
512 | - ) |
|
513 | - ) { |
|
514 | - $this->admin_bar->add_menu( |
|
515 | - array( |
|
516 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
517 | - 'parent' => 'espresso-toolbar-registrations', |
|
518 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
519 | - . esc_html__('Pending', 'event_espresso'), |
|
520 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
521 | - array( |
|
522 | - 'action' => 'default', |
|
523 | - 'status' => 'today', |
|
524 | - 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
525 | - ), |
|
526 | - $this->reg_admin_url |
|
527 | - ), |
|
528 | - 'meta' => array( |
|
529 | - 'title' => esc_html__('Pending Payment', 'event_espresso'), |
|
530 | - 'target' => '', |
|
531 | - 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
532 | - ), |
|
533 | - ) |
|
534 | - ); |
|
535 | - } |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * @return void |
|
542 | - */ |
|
543 | - private function addRegistrationOverviewTodayNotApproved() |
|
544 | - { |
|
545 | - if ( |
|
546 | - $this->capabilities->current_user_can( |
|
547 | - 'ee_read_registrations', |
|
548 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' |
|
549 | - ) |
|
550 | - ) { |
|
551 | - $this->admin_bar->add_menu( |
|
552 | - array( |
|
553 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
554 | - 'parent' => 'espresso-toolbar-registrations', |
|
555 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
556 | - . esc_html__('Not Approved', 'event_espresso'), |
|
557 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
558 | - array( |
|
559 | - 'action' => 'default', |
|
560 | - 'status' => 'today', |
|
561 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
562 | - ), |
|
563 | - $this->reg_admin_url |
|
564 | - ), |
|
565 | - 'meta' => array( |
|
566 | - 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
567 | - 'target' => '', |
|
568 | - 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
569 | - ), |
|
570 | - ) |
|
571 | - ); |
|
572 | - } |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * @return void |
|
579 | - */ |
|
580 | - private function addRegistrationOverviewTodayCancelled() |
|
581 | - { |
|
582 | - if ( |
|
583 | - $this->capabilities->current_user_can( |
|
584 | - 'ee_read_registrations', |
|
585 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' |
|
586 | - ) |
|
587 | - ) { |
|
588 | - $this->admin_bar->add_menu( |
|
589 | - array( |
|
590 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
591 | - 'parent' => 'espresso-toolbar-registrations', |
|
592 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
593 | - . esc_html__('Cancelled', 'event_espresso'), |
|
594 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
595 | - array( |
|
596 | - 'action' => 'default', |
|
597 | - 'status' => 'today', |
|
598 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
599 | - ), |
|
600 | - $this->reg_admin_url |
|
601 | - ), |
|
602 | - 'meta' => array( |
|
603 | - 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
604 | - 'target' => '', |
|
605 | - 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
606 | - ), |
|
607 | - ) |
|
608 | - ); |
|
609 | - } |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - |
|
614 | - /** |
|
615 | - * @return void |
|
616 | - */ |
|
617 | - private function addRegistrationOverviewThisMonth() |
|
618 | - { |
|
619 | - if ( |
|
620 | - $this->capabilities->current_user_can( |
|
621 | - 'ee_read_registrations', |
|
622 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month' |
|
623 | - ) |
|
624 | - ) { |
|
625 | - $this->admin_bar->add_menu( |
|
626 | - array( |
|
627 | - 'id' => 'espresso-toolbar-registrations-month', |
|
628 | - 'parent' => 'espresso-toolbar-registrations', |
|
629 | - 'title' => esc_html__('This Month', 'event_espresso'), |
|
630 | - 'href' => '', //EEH_URL::add_query_args_and_nonce( |
|
631 | - // array( |
|
632 | - // 'action' => 'default', |
|
633 | - // 'status' => 'month' |
|
634 | - // ), |
|
635 | - // $this->reg_admin_url |
|
636 | - // ), |
|
637 | - 'meta' => array( |
|
638 | - 'title' => esc_html__('This Month', 'event_espresso'), |
|
639 | - 'target' => '', |
|
640 | - 'class' => $this->menu_class, |
|
641 | - ), |
|
642 | - ) |
|
643 | - ); |
|
644 | - } |
|
645 | - } |
|
646 | - |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * @return void |
|
651 | - */ |
|
652 | - private function addRegistrationOverviewThisMonthApproved() |
|
653 | - { |
|
654 | - if ( |
|
655 | - $this->capabilities->current_user_can( |
|
656 | - 'ee_read_registrations', |
|
657 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' |
|
658 | - ) |
|
659 | - ) { |
|
660 | - $this->admin_bar->add_menu( |
|
661 | - array( |
|
662 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
663 | - 'parent' => 'espresso-toolbar-registrations', |
|
664 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
665 | - . esc_html__('Approved', 'event_espresso'), |
|
666 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
667 | - array( |
|
668 | - 'action' => 'default', |
|
669 | - 'status' => 'month', |
|
670 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
671 | - ), |
|
672 | - $this->reg_admin_url |
|
673 | - ), |
|
674 | - 'meta' => array( |
|
675 | - 'title' => esc_html__('Approved', 'event_espresso'), |
|
676 | - 'target' => '', |
|
677 | - 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
678 | - ), |
|
679 | - ) |
|
680 | - ); |
|
681 | - } |
|
682 | - } |
|
683 | - |
|
684 | - |
|
685 | - |
|
686 | - /** |
|
687 | - * @return void |
|
688 | - */ |
|
689 | - private function addRegistrationOverviewThisMonthPending() |
|
690 | - { |
|
691 | - if ( |
|
692 | - $this->capabilities->current_user_can( |
|
693 | - 'ee_read_registrations', |
|
694 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' |
|
695 | - ) |
|
696 | - ) { |
|
697 | - $this->admin_bar->add_menu( |
|
698 | - array( |
|
699 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
700 | - 'parent' => 'espresso-toolbar-registrations', |
|
701 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
702 | - . esc_html__('Pending', 'event_espresso'), |
|
703 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
704 | - array( |
|
705 | - 'action' => 'default', |
|
706 | - 'status' => 'month', |
|
707 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
708 | - ), |
|
709 | - $this->reg_admin_url |
|
710 | - ), |
|
711 | - 'meta' => array( |
|
712 | - 'title' => esc_html__('Pending', 'event_espresso'), |
|
713 | - 'target' => '', |
|
714 | - 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
715 | - ), |
|
716 | - ) |
|
717 | - ); |
|
718 | - } |
|
719 | - } |
|
720 | - |
|
721 | - |
|
722 | - |
|
723 | - /** |
|
724 | - * @return void |
|
725 | - */ |
|
726 | - private function addRegistrationOverviewThisMonthNotApproved() |
|
727 | - { |
|
728 | - if ( |
|
729 | - $this->capabilities->current_user_can( |
|
730 | - 'ee_read_registrations', |
|
731 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' |
|
732 | - ) |
|
733 | - ) { |
|
734 | - $this->admin_bar->add_menu( |
|
735 | - array( |
|
736 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
737 | - 'parent' => 'espresso-toolbar-registrations', |
|
738 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
739 | - . esc_html__('Not Approved', 'event_espresso'), |
|
740 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
741 | - array( |
|
742 | - 'action' => 'default', |
|
743 | - 'status' => 'month', |
|
744 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
745 | - ), |
|
746 | - $this->reg_admin_url |
|
747 | - ), |
|
748 | - 'meta' => array( |
|
749 | - 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
750 | - 'target' => '', |
|
751 | - 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
752 | - ), |
|
753 | - ) |
|
754 | - ); |
|
755 | - } |
|
756 | - } |
|
757 | - |
|
758 | - |
|
759 | - |
|
760 | - /** |
|
761 | - * @return void |
|
762 | - */ |
|
763 | - private function addRegistrationOverviewThisMonthCancelled() |
|
764 | - { |
|
765 | - if ( |
|
766 | - $this->capabilities->current_user_can( |
|
767 | - 'ee_read_registrations', |
|
768 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' |
|
769 | - ) |
|
770 | - ) { |
|
771 | - $this->admin_bar->add_menu( |
|
772 | - array( |
|
773 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
774 | - 'parent' => 'espresso-toolbar-registrations', |
|
775 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
776 | - . esc_html__('Cancelled', 'event_espresso'), |
|
777 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
778 | - array( |
|
779 | - 'action' => 'default', |
|
780 | - 'status' => 'month', |
|
781 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
782 | - ), |
|
783 | - $this->reg_admin_url |
|
784 | - ), |
|
785 | - 'meta' => array( |
|
786 | - 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
787 | - 'target' => '', |
|
788 | - 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
789 | - ), |
|
790 | - ) |
|
791 | - ); |
|
792 | - } |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - |
|
797 | - /** |
|
798 | - * @return void |
|
799 | - */ |
|
800 | - private function addExtensionsAndServices() |
|
801 | - { |
|
802 | - if ( |
|
803 | - $this->capabilities->current_user_can( |
|
804 | - 'ee_read_ee', |
|
805 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' |
|
806 | - ) |
|
807 | - ) { |
|
808 | - $this->admin_bar->add_menu( |
|
809 | - array( |
|
810 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
811 | - 'parent' => 'espresso-toolbar', |
|
812 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
813 | - . esc_html__('Extensions & Services', 'event_espresso'), |
|
814 | - 'href' => admin_url('admin.php?page=espresso_packages'), |
|
815 | - 'meta' => array( |
|
816 | - 'title' => esc_html__('Extensions & Services', 'event_espresso'), |
|
817 | - 'target' => '', |
|
818 | - 'class' => $this->menu_class, |
|
819 | - ), |
|
820 | - ) |
|
821 | - ); |
|
822 | - } |
|
823 | - } |
|
25 | + /** |
|
26 | + * @var WP_Admin_Bar $admin_bar |
|
27 | + */ |
|
28 | + private $admin_bar; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var EE_Capabilities $capabilities |
|
32 | + */ |
|
33 | + private $capabilities; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string $events_admin_url |
|
37 | + */ |
|
38 | + private $events_admin_url; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var string $menu_class |
|
42 | + */ |
|
43 | + private $menu_class = 'espresso_menu_item_class'; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var string $reg_admin_url |
|
47 | + */ |
|
48 | + private $reg_admin_url; |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * AdminToolBar constructor. |
|
54 | + * |
|
55 | + * @param EE_Capabilities $capabilities |
|
56 | + */ |
|
57 | + public function __construct(EE_Capabilities $capabilities) |
|
58 | + { |
|
59 | + $this->capabilities = $capabilities; |
|
60 | + add_action('admin_bar_menu', array($this, 'espressoToolbarItems'), 100); |
|
61 | + $this->enqueueAssets(); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * espresso_toolbar_items |
|
68 | + * |
|
69 | + * @access public |
|
70 | + * @param WP_Admin_Bar $admin_bar |
|
71 | + * @return void |
|
72 | + */ |
|
73 | + public function espressoToolbarItems(WP_Admin_Bar $admin_bar) |
|
74 | + { |
|
75 | + // if its an AJAX request, or user is NOT an admin, or in full M-Mode |
|
76 | + if ( |
|
77 | + defined('DOING_AJAX') |
|
78 | + || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
79 | + || EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
80 | + ) { |
|
81 | + return; |
|
82 | + } |
|
83 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
84 | + $this->admin_bar = $admin_bar; |
|
85 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
86 | + //because they're only defined in each of their respective constructors |
|
87 | + //and this might be a frontend request, in which case they aren't available |
|
88 | + $this->events_admin_url = admin_url('admin.php?page=espresso_events'); |
|
89 | + $this->reg_admin_url = admin_url('admin.php?page=espresso_registrations'); |
|
90 | + // now let's add all of the menu items |
|
91 | + $this->addTopLevelMenu(); |
|
92 | + $this->addEventsSubMenu(); |
|
93 | + $this->addEventsAddEditHeader(); |
|
94 | + $this->addEventsAddNew(); |
|
95 | + $this->addEventsEditCurrentEvent(); |
|
96 | + $this->addEventsViewHeader(); |
|
97 | + $this->addEventsViewAll(); |
|
98 | + $this->addEventsViewToday(); |
|
99 | + $this->addEventsViewThisMonth(); |
|
100 | + $this->addRegistrationSubMenu(); |
|
101 | + $this->addRegistrationOverviewToday(); |
|
102 | + $this->addRegistrationOverviewTodayApproved(); |
|
103 | + $this->addRegistrationOverviewTodayPendingPayment(); |
|
104 | + $this->addRegistrationOverviewTodayNotApproved(); |
|
105 | + $this->addRegistrationOverviewTodayCancelled(); |
|
106 | + $this->addRegistrationOverviewThisMonth(); |
|
107 | + $this->addRegistrationOverviewThisMonthApproved(); |
|
108 | + $this->addRegistrationOverviewThisMonthPending(); |
|
109 | + $this->addRegistrationOverviewThisMonthNotApproved(); |
|
110 | + $this->addRegistrationOverviewThisMonthCancelled(); |
|
111 | + $this->addExtensionsAndServices(); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + private function enqueueAssets() |
|
120 | + { |
|
121 | + wp_register_style( |
|
122 | + 'espresso-admin-toolbar', |
|
123 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css', |
|
124 | + array('dashicons'), |
|
125 | + EVENT_ESPRESSO_VERSION |
|
126 | + ); |
|
127 | + wp_enqueue_style('espresso-admin-toolbar'); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + private function addTopLevelMenu() |
|
136 | + { |
|
137 | + $this->admin_bar->add_menu( |
|
138 | + array( |
|
139 | + 'id' => 'espresso-toolbar', |
|
140 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
141 | + . esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
142 | + . '</span>', |
|
143 | + 'href' => $this->events_admin_url, |
|
144 | + 'meta' => array( |
|
145 | + 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
146 | + 'class' => $this->menu_class . 'first', |
|
147 | + ), |
|
148 | + ) |
|
149 | + ); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + private function addEventsSubMenu() |
|
158 | + { |
|
159 | + if ( |
|
160 | + $this->capabilities->current_user_can( |
|
161 | + 'ee_read_events', |
|
162 | + 'ee_admin_bar_menu_espresso-toolbar-events' |
|
163 | + ) |
|
164 | + ) { |
|
165 | + $this->admin_bar->add_menu( |
|
166 | + array( |
|
167 | + 'id' => 'espresso-toolbar-events', |
|
168 | + 'parent' => 'espresso-toolbar', |
|
169 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
170 | + . esc_html__('Events', 'event_espresso'), |
|
171 | + 'href' => $this->events_admin_url, |
|
172 | + 'meta' => array( |
|
173 | + 'title' => esc_html__('Events', 'event_espresso'), |
|
174 | + 'target' => '', |
|
175 | + 'class' => $this->menu_class, |
|
176 | + ), |
|
177 | + ) |
|
178 | + ); |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @return void |
|
186 | + */ |
|
187 | + private function addEventsAddEditHeader() |
|
188 | + { |
|
189 | + if ( |
|
190 | + $this->capabilities->current_user_can( |
|
191 | + 'ee_read_events', |
|
192 | + 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
193 | + ) |
|
194 | + ) { |
|
195 | + $this->admin_bar->add_menu( |
|
196 | + array( |
|
197 | + 'id' => 'espresso-toolbar-events-add-edit', |
|
198 | + 'parent' => 'espresso-toolbar-events', |
|
199 | + 'title' => esc_html__('Add / Edit', 'event_espresso'), |
|
200 | + 'href' => '', |
|
201 | + ) |
|
202 | + ); |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + private function addEventsAddNew() |
|
212 | + { |
|
213 | + if ( |
|
214 | + $this->capabilities->current_user_can( |
|
215 | + 'ee_edit_events', |
|
216 | + 'ee_admin_bar_menu_espresso-toolbar-events-new' |
|
217 | + ) |
|
218 | + ) { |
|
219 | + $this->admin_bar->add_menu( |
|
220 | + array( |
|
221 | + 'id' => 'espresso-toolbar-events-new', |
|
222 | + 'parent' => 'espresso-toolbar-events', |
|
223 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
224 | + . esc_html__('Add New', 'event_espresso'), |
|
225 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
226 | + array('action' => 'create_new'), |
|
227 | + $this->events_admin_url |
|
228 | + ), |
|
229 | + 'meta' => array( |
|
230 | + 'title' => esc_html__('Add New', 'event_espresso'), |
|
231 | + 'target' => '', |
|
232 | + 'class' => $this->menu_class, |
|
233 | + ), |
|
234 | + ) |
|
235 | + ); |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @return void |
|
243 | + */ |
|
244 | + private function addEventsEditCurrentEvent() |
|
245 | + { |
|
246 | + if (is_single() && (get_post_type() === 'espresso_events')) { |
|
247 | + //Current post |
|
248 | + global $post; |
|
249 | + if ( |
|
250 | + $this->capabilities->current_user_can( |
|
251 | + 'ee_edit_event', |
|
252 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID |
|
253 | + ) |
|
254 | + ) { |
|
255 | + $this->admin_bar->add_menu( |
|
256 | + array( |
|
257 | + 'id' => 'espresso-toolbar-events-edit', |
|
258 | + 'parent' => 'espresso-toolbar-events', |
|
259 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
260 | + . esc_html__('Edit Event', 'event_espresso'), |
|
261 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
262 | + array( |
|
263 | + 'action' => 'edit', |
|
264 | + 'post' => $post->ID |
|
265 | + ), |
|
266 | + $this->events_admin_url |
|
267 | + ), |
|
268 | + 'meta' => array( |
|
269 | + 'title' => esc_html__('Edit Event', 'event_espresso'), |
|
270 | + 'target' => '', |
|
271 | + 'class' => $this->menu_class, |
|
272 | + ), |
|
273 | + ) |
|
274 | + ); |
|
275 | + } |
|
276 | + } |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * @return void |
|
283 | + */ |
|
284 | + private function addEventsViewHeader() |
|
285 | + { |
|
286 | + if ( |
|
287 | + $this->capabilities->current_user_can( |
|
288 | + 'ee_read_events', |
|
289 | + 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
290 | + ) |
|
291 | + ) { |
|
292 | + $this->admin_bar->add_menu( |
|
293 | + array( |
|
294 | + 'id' => 'espresso-toolbar-events-view', |
|
295 | + 'parent' => 'espresso-toolbar-events', |
|
296 | + 'title' => esc_html__('View', 'event_espresso'), |
|
297 | + 'href' => '', |
|
298 | + ) |
|
299 | + ); |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * @return void |
|
307 | + */ |
|
308 | + private function addEventsViewAll() |
|
309 | + { |
|
310 | + if ( |
|
311 | + $this->capabilities->current_user_can( |
|
312 | + 'ee_read_events', |
|
313 | + 'ee_admin_bar_menu_espresso-toolbar-events-all' |
|
314 | + ) |
|
315 | + ) { |
|
316 | + $this->admin_bar->add_menu( |
|
317 | + array( |
|
318 | + 'id' => 'espresso-toolbar-events-all', |
|
319 | + 'parent' => 'espresso-toolbar-events', |
|
320 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
321 | + . esc_html__('All', 'event_espresso'), |
|
322 | + 'href' => $this->events_admin_url, |
|
323 | + 'meta' => array( |
|
324 | + 'title' => esc_html__('All', 'event_espresso'), |
|
325 | + 'target' => '', |
|
326 | + 'class' => $this->menu_class, |
|
327 | + ), |
|
328 | + ) |
|
329 | + ); |
|
330 | + } |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * @return void |
|
337 | + */ |
|
338 | + private function addEventsViewToday() |
|
339 | + { |
|
340 | + if ( |
|
341 | + $this->capabilities->current_user_can( |
|
342 | + 'ee_read_events', |
|
343 | + 'ee_admin_bar_menu_espresso-toolbar-events-today' |
|
344 | + ) |
|
345 | + ) { |
|
346 | + $this->admin_bar->add_menu( |
|
347 | + array( |
|
348 | + 'id' => 'espresso-toolbar-events-today', |
|
349 | + 'parent' => 'espresso-toolbar-events', |
|
350 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
351 | + . esc_html__('Today', 'event_espresso'), |
|
352 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
353 | + array( |
|
354 | + 'action' => 'default', |
|
355 | + 'status' => 'today' |
|
356 | + ), |
|
357 | + $this->events_admin_url |
|
358 | + ), |
|
359 | + 'meta' => array( |
|
360 | + 'title' => esc_html__('Today', 'event_espresso'), |
|
361 | + 'target' => '', |
|
362 | + 'class' => $this->menu_class, |
|
363 | + ), |
|
364 | + ) |
|
365 | + ); |
|
366 | + } |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * @return void |
|
373 | + */ |
|
374 | + private function addEventsViewThisMonth() |
|
375 | + { |
|
376 | + if ( |
|
377 | + $this->capabilities->current_user_can( |
|
378 | + 'ee_read_events', |
|
379 | + 'ee_admin_bar_menu_espresso-toolbar-events-month' |
|
380 | + ) |
|
381 | + ) { |
|
382 | + $this->admin_bar->add_menu( |
|
383 | + array( |
|
384 | + 'id' => 'espresso-toolbar-events-month', |
|
385 | + 'parent' => 'espresso-toolbar-events', |
|
386 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
387 | + . esc_html__('This Month', 'event_espresso'), |
|
388 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
389 | + array( |
|
390 | + 'action' => 'default', |
|
391 | + 'status' => 'month' |
|
392 | + ), |
|
393 | + $this->events_admin_url |
|
394 | + ), |
|
395 | + 'meta' => array( |
|
396 | + 'title' => esc_html__('This Month', 'event_espresso'), |
|
397 | + 'target' => '', |
|
398 | + 'class' => $this->menu_class, |
|
399 | + ), |
|
400 | + ) |
|
401 | + ); |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * @return void |
|
409 | + */ |
|
410 | + private function addRegistrationSubMenu() |
|
411 | + { |
|
412 | + if ( |
|
413 | + $this->capabilities->current_user_can( |
|
414 | + 'ee_read_registrations', |
|
415 | + 'ee_admin_bar_menu_espresso-toolbar-registrations' |
|
416 | + ) |
|
417 | + ) { |
|
418 | + $this->admin_bar->add_menu( |
|
419 | + array( |
|
420 | + 'id' => 'espresso-toolbar-registrations', |
|
421 | + 'parent' => 'espresso-toolbar', |
|
422 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
423 | + . esc_html__('Registrations', 'event_espresso'), |
|
424 | + 'href' => $this->reg_admin_url, |
|
425 | + 'meta' => array( |
|
426 | + 'title' => esc_html__('Registrations', 'event_espresso'), |
|
427 | + 'target' => '', |
|
428 | + 'class' => $this->menu_class, |
|
429 | + ), |
|
430 | + ) |
|
431 | + ); |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * @return void |
|
439 | + */ |
|
440 | + private function addRegistrationOverviewToday() |
|
441 | + { |
|
442 | + if ( |
|
443 | + $this->capabilities->current_user_can( |
|
444 | + 'ee_read_registrations', |
|
445 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today' |
|
446 | + ) |
|
447 | + ) { |
|
448 | + $this->admin_bar->add_menu( |
|
449 | + array( |
|
450 | + 'id' => 'espresso-toolbar-registrations-today', |
|
451 | + 'parent' => 'espresso-toolbar-registrations', |
|
452 | + 'title' => esc_html__('Today', 'event_espresso'), |
|
453 | + 'href' => '', |
|
454 | + 'meta' => array( |
|
455 | + 'title' => esc_html__('Today', 'event_espresso'), |
|
456 | + 'target' => '', |
|
457 | + 'class' => $this->menu_class, |
|
458 | + ), |
|
459 | + ) |
|
460 | + ); |
|
461 | + } |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * @return void |
|
468 | + */ |
|
469 | + private function addRegistrationOverviewTodayApproved() |
|
470 | + { |
|
471 | + if ( |
|
472 | + $this->capabilities->current_user_can( |
|
473 | + 'ee_read_registrations', |
|
474 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' |
|
475 | + ) |
|
476 | + ) { |
|
477 | + $this->admin_bar->add_menu( |
|
478 | + array( |
|
479 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
480 | + 'parent' => 'espresso-toolbar-registrations', |
|
481 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
482 | + . esc_html__('Approved', 'event_espresso'), |
|
483 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
484 | + array( |
|
485 | + 'action' => 'default', |
|
486 | + 'status' => 'today', |
|
487 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
488 | + ), |
|
489 | + $this->reg_admin_url |
|
490 | + ), |
|
491 | + 'meta' => array( |
|
492 | + 'title' => esc_html__('Approved', 'event_espresso'), |
|
493 | + 'target' => '', |
|
494 | + 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
495 | + ), |
|
496 | + ) |
|
497 | + ); |
|
498 | + } |
|
499 | + } |
|
500 | + |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * @return void |
|
505 | + */ |
|
506 | + private function addRegistrationOverviewTodayPendingPayment() |
|
507 | + { |
|
508 | + if ( |
|
509 | + $this->capabilities->current_user_can( |
|
510 | + 'ee_read_registrations', |
|
511 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' |
|
512 | + ) |
|
513 | + ) { |
|
514 | + $this->admin_bar->add_menu( |
|
515 | + array( |
|
516 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
517 | + 'parent' => 'espresso-toolbar-registrations', |
|
518 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
519 | + . esc_html__('Pending', 'event_espresso'), |
|
520 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
521 | + array( |
|
522 | + 'action' => 'default', |
|
523 | + 'status' => 'today', |
|
524 | + 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
525 | + ), |
|
526 | + $this->reg_admin_url |
|
527 | + ), |
|
528 | + 'meta' => array( |
|
529 | + 'title' => esc_html__('Pending Payment', 'event_espresso'), |
|
530 | + 'target' => '', |
|
531 | + 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
532 | + ), |
|
533 | + ) |
|
534 | + ); |
|
535 | + } |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * @return void |
|
542 | + */ |
|
543 | + private function addRegistrationOverviewTodayNotApproved() |
|
544 | + { |
|
545 | + if ( |
|
546 | + $this->capabilities->current_user_can( |
|
547 | + 'ee_read_registrations', |
|
548 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' |
|
549 | + ) |
|
550 | + ) { |
|
551 | + $this->admin_bar->add_menu( |
|
552 | + array( |
|
553 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
554 | + 'parent' => 'espresso-toolbar-registrations', |
|
555 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
556 | + . esc_html__('Not Approved', 'event_espresso'), |
|
557 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
558 | + array( |
|
559 | + 'action' => 'default', |
|
560 | + 'status' => 'today', |
|
561 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
562 | + ), |
|
563 | + $this->reg_admin_url |
|
564 | + ), |
|
565 | + 'meta' => array( |
|
566 | + 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
567 | + 'target' => '', |
|
568 | + 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
569 | + ), |
|
570 | + ) |
|
571 | + ); |
|
572 | + } |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * @return void |
|
579 | + */ |
|
580 | + private function addRegistrationOverviewTodayCancelled() |
|
581 | + { |
|
582 | + if ( |
|
583 | + $this->capabilities->current_user_can( |
|
584 | + 'ee_read_registrations', |
|
585 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' |
|
586 | + ) |
|
587 | + ) { |
|
588 | + $this->admin_bar->add_menu( |
|
589 | + array( |
|
590 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
591 | + 'parent' => 'espresso-toolbar-registrations', |
|
592 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
593 | + . esc_html__('Cancelled', 'event_espresso'), |
|
594 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
595 | + array( |
|
596 | + 'action' => 'default', |
|
597 | + 'status' => 'today', |
|
598 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
599 | + ), |
|
600 | + $this->reg_admin_url |
|
601 | + ), |
|
602 | + 'meta' => array( |
|
603 | + 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
604 | + 'target' => '', |
|
605 | + 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
606 | + ), |
|
607 | + ) |
|
608 | + ); |
|
609 | + } |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + |
|
614 | + /** |
|
615 | + * @return void |
|
616 | + */ |
|
617 | + private function addRegistrationOverviewThisMonth() |
|
618 | + { |
|
619 | + if ( |
|
620 | + $this->capabilities->current_user_can( |
|
621 | + 'ee_read_registrations', |
|
622 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month' |
|
623 | + ) |
|
624 | + ) { |
|
625 | + $this->admin_bar->add_menu( |
|
626 | + array( |
|
627 | + 'id' => 'espresso-toolbar-registrations-month', |
|
628 | + 'parent' => 'espresso-toolbar-registrations', |
|
629 | + 'title' => esc_html__('This Month', 'event_espresso'), |
|
630 | + 'href' => '', //EEH_URL::add_query_args_and_nonce( |
|
631 | + // array( |
|
632 | + // 'action' => 'default', |
|
633 | + // 'status' => 'month' |
|
634 | + // ), |
|
635 | + // $this->reg_admin_url |
|
636 | + // ), |
|
637 | + 'meta' => array( |
|
638 | + 'title' => esc_html__('This Month', 'event_espresso'), |
|
639 | + 'target' => '', |
|
640 | + 'class' => $this->menu_class, |
|
641 | + ), |
|
642 | + ) |
|
643 | + ); |
|
644 | + } |
|
645 | + } |
|
646 | + |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * @return void |
|
651 | + */ |
|
652 | + private function addRegistrationOverviewThisMonthApproved() |
|
653 | + { |
|
654 | + if ( |
|
655 | + $this->capabilities->current_user_can( |
|
656 | + 'ee_read_registrations', |
|
657 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' |
|
658 | + ) |
|
659 | + ) { |
|
660 | + $this->admin_bar->add_menu( |
|
661 | + array( |
|
662 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
663 | + 'parent' => 'espresso-toolbar-registrations', |
|
664 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
665 | + . esc_html__('Approved', 'event_espresso'), |
|
666 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
667 | + array( |
|
668 | + 'action' => 'default', |
|
669 | + 'status' => 'month', |
|
670 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
671 | + ), |
|
672 | + $this->reg_admin_url |
|
673 | + ), |
|
674 | + 'meta' => array( |
|
675 | + 'title' => esc_html__('Approved', 'event_espresso'), |
|
676 | + 'target' => '', |
|
677 | + 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
678 | + ), |
|
679 | + ) |
|
680 | + ); |
|
681 | + } |
|
682 | + } |
|
683 | + |
|
684 | + |
|
685 | + |
|
686 | + /** |
|
687 | + * @return void |
|
688 | + */ |
|
689 | + private function addRegistrationOverviewThisMonthPending() |
|
690 | + { |
|
691 | + if ( |
|
692 | + $this->capabilities->current_user_can( |
|
693 | + 'ee_read_registrations', |
|
694 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' |
|
695 | + ) |
|
696 | + ) { |
|
697 | + $this->admin_bar->add_menu( |
|
698 | + array( |
|
699 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
700 | + 'parent' => 'espresso-toolbar-registrations', |
|
701 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
702 | + . esc_html__('Pending', 'event_espresso'), |
|
703 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
704 | + array( |
|
705 | + 'action' => 'default', |
|
706 | + 'status' => 'month', |
|
707 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
708 | + ), |
|
709 | + $this->reg_admin_url |
|
710 | + ), |
|
711 | + 'meta' => array( |
|
712 | + 'title' => esc_html__('Pending', 'event_espresso'), |
|
713 | + 'target' => '', |
|
714 | + 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
715 | + ), |
|
716 | + ) |
|
717 | + ); |
|
718 | + } |
|
719 | + } |
|
720 | + |
|
721 | + |
|
722 | + |
|
723 | + /** |
|
724 | + * @return void |
|
725 | + */ |
|
726 | + private function addRegistrationOverviewThisMonthNotApproved() |
|
727 | + { |
|
728 | + if ( |
|
729 | + $this->capabilities->current_user_can( |
|
730 | + 'ee_read_registrations', |
|
731 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' |
|
732 | + ) |
|
733 | + ) { |
|
734 | + $this->admin_bar->add_menu( |
|
735 | + array( |
|
736 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
737 | + 'parent' => 'espresso-toolbar-registrations', |
|
738 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
739 | + . esc_html__('Not Approved', 'event_espresso'), |
|
740 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
741 | + array( |
|
742 | + 'action' => 'default', |
|
743 | + 'status' => 'month', |
|
744 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
745 | + ), |
|
746 | + $this->reg_admin_url |
|
747 | + ), |
|
748 | + 'meta' => array( |
|
749 | + 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
750 | + 'target' => '', |
|
751 | + 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
752 | + ), |
|
753 | + ) |
|
754 | + ); |
|
755 | + } |
|
756 | + } |
|
757 | + |
|
758 | + |
|
759 | + |
|
760 | + /** |
|
761 | + * @return void |
|
762 | + */ |
|
763 | + private function addRegistrationOverviewThisMonthCancelled() |
|
764 | + { |
|
765 | + if ( |
|
766 | + $this->capabilities->current_user_can( |
|
767 | + 'ee_read_registrations', |
|
768 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' |
|
769 | + ) |
|
770 | + ) { |
|
771 | + $this->admin_bar->add_menu( |
|
772 | + array( |
|
773 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
774 | + 'parent' => 'espresso-toolbar-registrations', |
|
775 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
776 | + . esc_html__('Cancelled', 'event_espresso'), |
|
777 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
778 | + array( |
|
779 | + 'action' => 'default', |
|
780 | + 'status' => 'month', |
|
781 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
782 | + ), |
|
783 | + $this->reg_admin_url |
|
784 | + ), |
|
785 | + 'meta' => array( |
|
786 | + 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
787 | + 'target' => '', |
|
788 | + 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
789 | + ), |
|
790 | + ) |
|
791 | + ); |
|
792 | + } |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + |
|
797 | + /** |
|
798 | + * @return void |
|
799 | + */ |
|
800 | + private function addExtensionsAndServices() |
|
801 | + { |
|
802 | + if ( |
|
803 | + $this->capabilities->current_user_can( |
|
804 | + 'ee_read_ee', |
|
805 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' |
|
806 | + ) |
|
807 | + ) { |
|
808 | + $this->admin_bar->add_menu( |
|
809 | + array( |
|
810 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
811 | + 'parent' => 'espresso-toolbar', |
|
812 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
813 | + . esc_html__('Extensions & Services', 'event_espresso'), |
|
814 | + 'href' => admin_url('admin.php?page=espresso_packages'), |
|
815 | + 'meta' => array( |
|
816 | + 'title' => esc_html__('Extensions & Services', 'event_espresso'), |
|
817 | + 'target' => '', |
|
818 | + 'class' => $this->menu_class, |
|
819 | + ), |
|
820 | + ) |
|
821 | + ); |
|
822 | + } |
|
823 | + } |
|
824 | 824 | |
825 | 825 | } |
@@ -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 | |
@@ -17,407 +17,407 @@ discard block |
||
17 | 17 | class EE_Payment_Method_Manager |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * instance of the EE_Payment_Method_Manager object |
|
22 | - * |
|
23 | - * @var $_instance |
|
24 | - * @access private |
|
25 | - */ |
|
26 | - private static $_instance; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var array keys are classnames without 'EE_PMT_', values are their filepaths |
|
30 | - */ |
|
31 | - protected $_payment_method_types = array(); |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @singleton method used to instantiate class object |
|
37 | - * @access public |
|
38 | - * @return EE_Payment_Method_Manager instance |
|
39 | - */ |
|
40 | - public static function instance() |
|
41 | - { |
|
42 | - // check if class object is instantiated, and instantiated properly |
|
43 | - if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
44 | - self::$_instance = new self(); |
|
45 | - } |
|
46 | - EE_Registry::instance()->load_lib('PMT_Base'); |
|
47 | - return self::$_instance; |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Resets the instance and returns a new one |
|
54 | - * |
|
55 | - * @return EE_Payment_Method_Manager |
|
56 | - */ |
|
57 | - public static function reset() |
|
58 | - { |
|
59 | - self::$_instance = null; |
|
60 | - return self::instance(); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * If necessary, re-register payment methods |
|
67 | - * |
|
68 | - * @param boolean $force_recheck whether to recheck for payment method types, |
|
69 | - * or just re-use the PMTs we found last time we checked during this request (if |
|
70 | - * we have not yet checked during this request, then we need to check anyways) |
|
71 | - */ |
|
72 | - public function maybe_register_payment_methods($force_recheck = false) |
|
73 | - { |
|
74 | - if ( ! $this->_payment_method_types || $force_recheck) { |
|
75 | - $this->_register_payment_methods(); |
|
76 | - //if in admin lets ensure caps are set. |
|
77 | - if (is_admin()) { |
|
78 | - add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps')); |
|
79 | - EE_Registry::instance()->CAP->init_caps(); |
|
80 | - } |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * register_payment_methods |
|
88 | - * |
|
89 | - * @return array |
|
90 | - */ |
|
91 | - protected function _register_payment_methods() |
|
92 | - { |
|
93 | - // grab list of installed modules |
|
94 | - $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
95 | - // filter list of modules to register |
|
96 | - $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
97 | - $pm_to_register); |
|
98 | - // loop through folders |
|
99 | - foreach ($pm_to_register as $pm_path) { |
|
100 | - $this->register_payment_method($pm_path); |
|
101 | - } |
|
102 | - do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
103 | - // filter list of installed modules |
|
104 | - //keep them organized alphabetically by the payment method type's name |
|
105 | - ksort($this->_payment_method_types); |
|
106 | - return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
107 | - $this->_payment_method_types); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * register_payment_method- makes core aware of this payment method |
|
114 | - * |
|
115 | - * @access public |
|
116 | - * @param string $payment_method_path - full path up to and including payment method folder |
|
117 | - * @return boolean |
|
118 | - */ |
|
119 | - public function register_payment_method($payment_method_path = '') |
|
120 | - { |
|
121 | - do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
122 | - $module_ext = '.pm.php'; |
|
123 | - // make all separators match |
|
124 | - $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
125 | - // grab and sanitize module name |
|
126 | - $module_dir = basename($payment_method_path); |
|
127 | - // create classname from module directory name |
|
128 | - $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
129 | - // add class prefix |
|
130 | - $module_class = 'EE_PMT_' . $module; |
|
131 | - // does the module exist ? |
|
132 | - if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
133 | - $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
134 | - 'event_espresso'), $module); |
|
135 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
136 | - return false; |
|
137 | - } |
|
138 | - if (WP_DEBUG === true) { |
|
139 | - EEH_Debug_Tools::instance()->start_timer(); |
|
140 | - } |
|
141 | - // load the module class file |
|
142 | - require_once($payment_method_path . DS . $module_class . $module_ext); |
|
143 | - if (WP_DEBUG === true) { |
|
144 | - EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); |
|
145 | - } |
|
146 | - // verify that class exists |
|
147 | - if ( ! class_exists($module_class)) { |
|
148 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
149 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
150 | - return false; |
|
151 | - } |
|
152 | - // add to array of registered modules |
|
153 | - $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
154 | - return true; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Checks if a payment method has been registered, and if so includes it |
|
161 | - * |
|
162 | - * @param string $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_') |
|
163 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
164 | - * @return boolean |
|
165 | - */ |
|
166 | - public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
167 | - { |
|
168 | - if ( |
|
169 | - $force_recheck |
|
170 | - || ! is_array($this->_payment_method_types) |
|
171 | - || ! isset($this->_payment_method_types[$payment_method_name]) |
|
172 | - ) { |
|
173 | - $this->maybe_register_payment_methods($force_recheck); |
|
174 | - } |
|
175 | - if (isset($this->_payment_method_types[$payment_method_name])) { |
|
176 | - require_once($this->_payment_method_types[$payment_method_name]); |
|
177 | - return true; |
|
178 | - } else { |
|
179 | - return false; |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Returns all the classnames of the various payment method types |
|
187 | - * |
|
188 | - * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names' |
|
189 | - * (what you'd find in wp_esp_payment_method.PMD_type) |
|
190 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
194 | - { |
|
195 | - $this->maybe_register_payment_methods($force_recheck); |
|
196 | - if ($with_prefixes) { |
|
197 | - $classnames = array_keys($this->_payment_method_types); |
|
198 | - $payment_methods = array(); |
|
199 | - foreach ($classnames as $classname) { |
|
200 | - $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
201 | - } |
|
202 | - return $payment_methods; |
|
203 | - } else { |
|
204 | - return array_keys($this->_payment_method_types); |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Gets an object of each payment method type, none of which are bound to a |
|
212 | - * payment method instance |
|
213 | - * |
|
214 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
215 | - * @return EE_PMT_Base[] |
|
216 | - */ |
|
217 | - public function payment_method_types($force_recheck = false) |
|
218 | - { |
|
219 | - $this->maybe_register_payment_methods($force_recheck); |
|
220 | - $pmt_objs = array(); |
|
221 | - foreach ($this->payment_method_type_names(true) as $classname) { |
|
222 | - $pmt_objs[] = new $classname; |
|
223 | - } |
|
224 | - return $pmt_objs; |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * Changes the payment method's classname into the payment method type's name |
|
231 | - * (as used on the payment method's table's PMD_type field) |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public function payment_method_type_sans_class_prefix($classname) |
|
237 | - { |
|
238 | - return str_replace("EE_PMT_", "", $classname); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Does the opposite of payment-method_type_sans_prefix |
|
245 | - * |
|
246 | - * @param string $type |
|
247 | - * @return string |
|
248 | - */ |
|
249 | - public function payment_method_class_from_type($type) |
|
250 | - { |
|
251 | - $this->maybe_register_payment_methods(); |
|
252 | - return "EE_PMT_" . $type; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * Activates a payment method of the given type. |
|
259 | - * |
|
260 | - * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
261 | - * @return \EE_Payment_Method |
|
262 | - * @throws \EE_Error |
|
263 | - */ |
|
264 | - public function activate_a_payment_method_of_type($payment_method_type) |
|
265 | - { |
|
266 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
267 | - if ( ! $payment_method instanceof EE_Payment_Method) { |
|
268 | - $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
269 | - if (class_exists($pm_type_class)) { |
|
270 | - /** @var $pm_type_obj EE_PMT_Base */ |
|
271 | - $pm_type_obj = new $pm_type_class; |
|
272 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
273 | - if ( ! $payment_method) { |
|
274 | - $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
275 | - } |
|
276 | - $payment_method->set_type($payment_method_type); |
|
277 | - $this->initialize_payment_method($payment_method); |
|
278 | - } else { |
|
279 | - throw new EE_Error( |
|
280 | - sprintf( |
|
281 | - __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
282 | - $pm_type_class) |
|
283 | - ); |
|
284 | - } |
|
285 | - } |
|
286 | - $payment_method->set_active(); |
|
287 | - $payment_method->save(); |
|
288 | - if ($payment_method->type() === 'Invoice') { |
|
289 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
290 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
291 | - $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
292 | - $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
293 | - EE_Error::add_persistent_admin_notice( |
|
294 | - 'invoice_pm_requirements_notice', |
|
295 | - sprintf( |
|
296 | - __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
297 | - 'event_espresso'), |
|
298 | - '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
299 | - '</a>' |
|
300 | - ), |
|
301 | - true |
|
302 | - ); |
|
303 | - } |
|
304 | - return $payment_method; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * Creates a payment method of the specified type. Does not save it. |
|
311 | - * |
|
312 | - * @global WP_User $current_user |
|
313 | - * @param EE_PMT_Base $pm_type_obj |
|
314 | - * @return EE_Payment_Method |
|
315 | - * @throws \EE_Error |
|
316 | - */ |
|
317 | - public function create_payment_method_of_type($pm_type_obj) |
|
318 | - { |
|
319 | - global $current_user; |
|
320 | - $payment_method = EE_Payment_Method::new_instance( |
|
321 | - array( |
|
322 | - 'PMD_type' => $pm_type_obj->system_name(), |
|
323 | - 'PMD_name' => $pm_type_obj->pretty_name(), |
|
324 | - 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
325 | - 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
326 | - 'PMD_wp_user' => $current_user->ID, |
|
327 | - 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
328 | - array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
329 | - ) * 10, |
|
330 | - ) |
|
331 | - ); |
|
332 | - return $payment_method; |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * Sets the initial payment method properties (including extra meta) |
|
339 | - * |
|
340 | - * @param EE_Payment_Method $payment_method |
|
341 | - * @return EE_Payment_Method |
|
342 | - * @throws \EE_Error |
|
343 | - */ |
|
344 | - public function initialize_payment_method($payment_method) |
|
345 | - { |
|
346 | - $pm_type_obj = $payment_method->type_obj(); |
|
347 | - $payment_method->set_description($pm_type_obj->default_description()); |
|
348 | - if ( ! $payment_method->button_url()) { |
|
349 | - $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
350 | - } |
|
351 | - //now add setup its default extra meta properties |
|
352 | - $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
353 | - if ( ! empty($extra_metas)) { |
|
354 | - //verify the payment method has an ID before adding extra meta |
|
355 | - if ( ! $payment_method->ID()) { |
|
356 | - $payment_method->save(); |
|
357 | - } |
|
358 | - foreach ($extra_metas as $meta_name => $input) { |
|
359 | - $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
360 | - } |
|
361 | - } |
|
362 | - return $payment_method; |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * Makes sure the payment method is related to the specified payment method |
|
369 | - * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
370 | - * @param EE_Payment_Method $payment_method |
|
371 | - * @return EE_Payment_Method |
|
372 | - * @throws \EE_Error |
|
373 | - */ |
|
374 | - public function set_usable_currencies_on_payment_method($payment_method) |
|
375 | - { |
|
376 | - EE_Error::doing_it_wrong( |
|
377 | - 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
378 | - esc_html__('We no longer define what currencies are usable by payment methods. Its not used nor efficient.', 'event_espresso'), |
|
379 | - '4.9.40'); |
|
380 | - return $payment_method; |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * Deactivates a payment method of the given payment method slug. |
|
387 | - * |
|
388 | - * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
389 | - * @return int count of rows updated. |
|
390 | - */ |
|
391 | - public function deactivate_payment_method($payment_method_slug) |
|
392 | - { |
|
393 | - EE_Log::instance()->log( |
|
394 | - __FILE__, |
|
395 | - __FUNCTION__, |
|
396 | - sprintf( |
|
397 | - __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'), |
|
398 | - $payment_method_slug |
|
399 | - ), |
|
400 | - 'payment_method_change' |
|
401 | - ); |
|
402 | - $count_updated = EEM_Payment_Method::instance()->update( |
|
403 | - array('PMD_scope' => array()), |
|
404 | - array(array('PMD_slug' => $payment_method_slug)) |
|
405 | - ); |
|
406 | - return $count_updated; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method |
|
413 | - * access caps. |
|
414 | - * |
|
415 | - * @param array $caps capabilities being filtered |
|
416 | - * @return array |
|
417 | - */ |
|
418 | - public function add_payment_method_caps($caps) |
|
419 | - { |
|
420 | - /* add dynamic caps from payment methods |
|
20 | + /** |
|
21 | + * instance of the EE_Payment_Method_Manager object |
|
22 | + * |
|
23 | + * @var $_instance |
|
24 | + * @access private |
|
25 | + */ |
|
26 | + private static $_instance; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var array keys are classnames without 'EE_PMT_', values are their filepaths |
|
30 | + */ |
|
31 | + protected $_payment_method_types = array(); |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @singleton method used to instantiate class object |
|
37 | + * @access public |
|
38 | + * @return EE_Payment_Method_Manager instance |
|
39 | + */ |
|
40 | + public static function instance() |
|
41 | + { |
|
42 | + // check if class object is instantiated, and instantiated properly |
|
43 | + if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
44 | + self::$_instance = new self(); |
|
45 | + } |
|
46 | + EE_Registry::instance()->load_lib('PMT_Base'); |
|
47 | + return self::$_instance; |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Resets the instance and returns a new one |
|
54 | + * |
|
55 | + * @return EE_Payment_Method_Manager |
|
56 | + */ |
|
57 | + public static function reset() |
|
58 | + { |
|
59 | + self::$_instance = null; |
|
60 | + return self::instance(); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * If necessary, re-register payment methods |
|
67 | + * |
|
68 | + * @param boolean $force_recheck whether to recheck for payment method types, |
|
69 | + * or just re-use the PMTs we found last time we checked during this request (if |
|
70 | + * we have not yet checked during this request, then we need to check anyways) |
|
71 | + */ |
|
72 | + public function maybe_register_payment_methods($force_recheck = false) |
|
73 | + { |
|
74 | + if ( ! $this->_payment_method_types || $force_recheck) { |
|
75 | + $this->_register_payment_methods(); |
|
76 | + //if in admin lets ensure caps are set. |
|
77 | + if (is_admin()) { |
|
78 | + add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps')); |
|
79 | + EE_Registry::instance()->CAP->init_caps(); |
|
80 | + } |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * register_payment_methods |
|
88 | + * |
|
89 | + * @return array |
|
90 | + */ |
|
91 | + protected function _register_payment_methods() |
|
92 | + { |
|
93 | + // grab list of installed modules |
|
94 | + $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
95 | + // filter list of modules to register |
|
96 | + $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
97 | + $pm_to_register); |
|
98 | + // loop through folders |
|
99 | + foreach ($pm_to_register as $pm_path) { |
|
100 | + $this->register_payment_method($pm_path); |
|
101 | + } |
|
102 | + do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
103 | + // filter list of installed modules |
|
104 | + //keep them organized alphabetically by the payment method type's name |
|
105 | + ksort($this->_payment_method_types); |
|
106 | + return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
107 | + $this->_payment_method_types); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * register_payment_method- makes core aware of this payment method |
|
114 | + * |
|
115 | + * @access public |
|
116 | + * @param string $payment_method_path - full path up to and including payment method folder |
|
117 | + * @return boolean |
|
118 | + */ |
|
119 | + public function register_payment_method($payment_method_path = '') |
|
120 | + { |
|
121 | + do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
122 | + $module_ext = '.pm.php'; |
|
123 | + // make all separators match |
|
124 | + $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
125 | + // grab and sanitize module name |
|
126 | + $module_dir = basename($payment_method_path); |
|
127 | + // create classname from module directory name |
|
128 | + $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
129 | + // add class prefix |
|
130 | + $module_class = 'EE_PMT_' . $module; |
|
131 | + // does the module exist ? |
|
132 | + if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
133 | + $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
134 | + 'event_espresso'), $module); |
|
135 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
136 | + return false; |
|
137 | + } |
|
138 | + if (WP_DEBUG === true) { |
|
139 | + EEH_Debug_Tools::instance()->start_timer(); |
|
140 | + } |
|
141 | + // load the module class file |
|
142 | + require_once($payment_method_path . DS . $module_class . $module_ext); |
|
143 | + if (WP_DEBUG === true) { |
|
144 | + EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); |
|
145 | + } |
|
146 | + // verify that class exists |
|
147 | + if ( ! class_exists($module_class)) { |
|
148 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
149 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
150 | + return false; |
|
151 | + } |
|
152 | + // add to array of registered modules |
|
153 | + $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
154 | + return true; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Checks if a payment method has been registered, and if so includes it |
|
161 | + * |
|
162 | + * @param string $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_') |
|
163 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
164 | + * @return boolean |
|
165 | + */ |
|
166 | + public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
167 | + { |
|
168 | + if ( |
|
169 | + $force_recheck |
|
170 | + || ! is_array($this->_payment_method_types) |
|
171 | + || ! isset($this->_payment_method_types[$payment_method_name]) |
|
172 | + ) { |
|
173 | + $this->maybe_register_payment_methods($force_recheck); |
|
174 | + } |
|
175 | + if (isset($this->_payment_method_types[$payment_method_name])) { |
|
176 | + require_once($this->_payment_method_types[$payment_method_name]); |
|
177 | + return true; |
|
178 | + } else { |
|
179 | + return false; |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Returns all the classnames of the various payment method types |
|
187 | + * |
|
188 | + * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names' |
|
189 | + * (what you'd find in wp_esp_payment_method.PMD_type) |
|
190 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
194 | + { |
|
195 | + $this->maybe_register_payment_methods($force_recheck); |
|
196 | + if ($with_prefixes) { |
|
197 | + $classnames = array_keys($this->_payment_method_types); |
|
198 | + $payment_methods = array(); |
|
199 | + foreach ($classnames as $classname) { |
|
200 | + $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
201 | + } |
|
202 | + return $payment_methods; |
|
203 | + } else { |
|
204 | + return array_keys($this->_payment_method_types); |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Gets an object of each payment method type, none of which are bound to a |
|
212 | + * payment method instance |
|
213 | + * |
|
214 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
215 | + * @return EE_PMT_Base[] |
|
216 | + */ |
|
217 | + public function payment_method_types($force_recheck = false) |
|
218 | + { |
|
219 | + $this->maybe_register_payment_methods($force_recheck); |
|
220 | + $pmt_objs = array(); |
|
221 | + foreach ($this->payment_method_type_names(true) as $classname) { |
|
222 | + $pmt_objs[] = new $classname; |
|
223 | + } |
|
224 | + return $pmt_objs; |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * Changes the payment method's classname into the payment method type's name |
|
231 | + * (as used on the payment method's table's PMD_type field) |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public function payment_method_type_sans_class_prefix($classname) |
|
237 | + { |
|
238 | + return str_replace("EE_PMT_", "", $classname); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Does the opposite of payment-method_type_sans_prefix |
|
245 | + * |
|
246 | + * @param string $type |
|
247 | + * @return string |
|
248 | + */ |
|
249 | + public function payment_method_class_from_type($type) |
|
250 | + { |
|
251 | + $this->maybe_register_payment_methods(); |
|
252 | + return "EE_PMT_" . $type; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * Activates a payment method of the given type. |
|
259 | + * |
|
260 | + * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
261 | + * @return \EE_Payment_Method |
|
262 | + * @throws \EE_Error |
|
263 | + */ |
|
264 | + public function activate_a_payment_method_of_type($payment_method_type) |
|
265 | + { |
|
266 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
267 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
268 | + $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
269 | + if (class_exists($pm_type_class)) { |
|
270 | + /** @var $pm_type_obj EE_PMT_Base */ |
|
271 | + $pm_type_obj = new $pm_type_class; |
|
272 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
273 | + if ( ! $payment_method) { |
|
274 | + $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
275 | + } |
|
276 | + $payment_method->set_type($payment_method_type); |
|
277 | + $this->initialize_payment_method($payment_method); |
|
278 | + } else { |
|
279 | + throw new EE_Error( |
|
280 | + sprintf( |
|
281 | + __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
282 | + $pm_type_class) |
|
283 | + ); |
|
284 | + } |
|
285 | + } |
|
286 | + $payment_method->set_active(); |
|
287 | + $payment_method->save(); |
|
288 | + if ($payment_method->type() === 'Invoice') { |
|
289 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
290 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
291 | + $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
292 | + $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
293 | + EE_Error::add_persistent_admin_notice( |
|
294 | + 'invoice_pm_requirements_notice', |
|
295 | + sprintf( |
|
296 | + __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
297 | + 'event_espresso'), |
|
298 | + '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
299 | + '</a>' |
|
300 | + ), |
|
301 | + true |
|
302 | + ); |
|
303 | + } |
|
304 | + return $payment_method; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * Creates a payment method of the specified type. Does not save it. |
|
311 | + * |
|
312 | + * @global WP_User $current_user |
|
313 | + * @param EE_PMT_Base $pm_type_obj |
|
314 | + * @return EE_Payment_Method |
|
315 | + * @throws \EE_Error |
|
316 | + */ |
|
317 | + public function create_payment_method_of_type($pm_type_obj) |
|
318 | + { |
|
319 | + global $current_user; |
|
320 | + $payment_method = EE_Payment_Method::new_instance( |
|
321 | + array( |
|
322 | + 'PMD_type' => $pm_type_obj->system_name(), |
|
323 | + 'PMD_name' => $pm_type_obj->pretty_name(), |
|
324 | + 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
325 | + 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
326 | + 'PMD_wp_user' => $current_user->ID, |
|
327 | + 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
328 | + array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
329 | + ) * 10, |
|
330 | + ) |
|
331 | + ); |
|
332 | + return $payment_method; |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * Sets the initial payment method properties (including extra meta) |
|
339 | + * |
|
340 | + * @param EE_Payment_Method $payment_method |
|
341 | + * @return EE_Payment_Method |
|
342 | + * @throws \EE_Error |
|
343 | + */ |
|
344 | + public function initialize_payment_method($payment_method) |
|
345 | + { |
|
346 | + $pm_type_obj = $payment_method->type_obj(); |
|
347 | + $payment_method->set_description($pm_type_obj->default_description()); |
|
348 | + if ( ! $payment_method->button_url()) { |
|
349 | + $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
350 | + } |
|
351 | + //now add setup its default extra meta properties |
|
352 | + $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
353 | + if ( ! empty($extra_metas)) { |
|
354 | + //verify the payment method has an ID before adding extra meta |
|
355 | + if ( ! $payment_method->ID()) { |
|
356 | + $payment_method->save(); |
|
357 | + } |
|
358 | + foreach ($extra_metas as $meta_name => $input) { |
|
359 | + $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
360 | + } |
|
361 | + } |
|
362 | + return $payment_method; |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * Makes sure the payment method is related to the specified payment method |
|
369 | + * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
370 | + * @param EE_Payment_Method $payment_method |
|
371 | + * @return EE_Payment_Method |
|
372 | + * @throws \EE_Error |
|
373 | + */ |
|
374 | + public function set_usable_currencies_on_payment_method($payment_method) |
|
375 | + { |
|
376 | + EE_Error::doing_it_wrong( |
|
377 | + 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
378 | + esc_html__('We no longer define what currencies are usable by payment methods. Its not used nor efficient.', 'event_espresso'), |
|
379 | + '4.9.40'); |
|
380 | + return $payment_method; |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * Deactivates a payment method of the given payment method slug. |
|
387 | + * |
|
388 | + * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
389 | + * @return int count of rows updated. |
|
390 | + */ |
|
391 | + public function deactivate_payment_method($payment_method_slug) |
|
392 | + { |
|
393 | + EE_Log::instance()->log( |
|
394 | + __FILE__, |
|
395 | + __FUNCTION__, |
|
396 | + sprintf( |
|
397 | + __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'), |
|
398 | + $payment_method_slug |
|
399 | + ), |
|
400 | + 'payment_method_change' |
|
401 | + ); |
|
402 | + $count_updated = EEM_Payment_Method::instance()->update( |
|
403 | + array('PMD_scope' => array()), |
|
404 | + array(array('PMD_slug' => $payment_method_slug)) |
|
405 | + ); |
|
406 | + return $count_updated; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method |
|
413 | + * access caps. |
|
414 | + * |
|
415 | + * @param array $caps capabilities being filtered |
|
416 | + * @return array |
|
417 | + */ |
|
418 | + public function add_payment_method_caps($caps) |
|
419 | + { |
|
420 | + /* add dynamic caps from payment methods |
|
421 | 421 | * at the time of writing, october 20 2014, these are the caps added: |
422 | 422 | * ee_payment_method_admin_only |
423 | 423 | * ee_payment_method_aim |
@@ -431,10 +431,10 @@ discard block |
||
431 | 431 | * their related capability automatically added too, so long as they are |
432 | 432 | * registered properly using EE_Register_Payment_Method::register() |
433 | 433 | */ |
434 | - foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
435 | - $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
|
436 | - } |
|
437 | - return $caps; |
|
438 | - } |
|
434 | + foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
435 | + $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
|
436 | + } |
|
437 | + return $caps; |
|
438 | + } |
|
439 | 439 | |
440 | 440 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * @deprecated in 4.9.40 because the currency payment method table has been deprecated |
15 | 15 | * |
16 | 16 | */ |
17 | -class EE_DMS_4_6_0_payment_method_currencies extends EE_Data_Migration_Script_Stage{ |
|
17 | +class EE_DMS_4_6_0_payment_method_currencies extends EE_Data_Migration_Script_Stage { |
|
18 | 18 | protected $_currency_table_name; |
19 | 19 | protected $_currency_payment_method_table_name; |
20 | 20 | protected $_payment_method_table_name; |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | ); |
91 | 91 | public function __construct() { |
92 | 92 | global $wpdb; |
93 | - $this->_pretty_name = __( 'Payment Method Currencies', 'event_espresso' ); |
|
93 | + $this->_pretty_name = __('Payment Method Currencies', 'event_espresso'); |
|
94 | 94 | $this->_payment_method_table_name = $wpdb->prefix.'esp_payment_method'; |
95 | 95 | $this->_currency_payment_method_table_name = $wpdb->prefix.'esp_currency_payment_method'; |
96 | 96 | $this->_currency_table_name = $wpdb->prefix.'esp_currency'; |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | |
100 | 100 | protected function _count_records_to_migrate() { |
101 | 101 | $count = 0; |
102 | - foreach($this->_gateway_currencies as $currencies){ |
|
103 | - if( $currencies == 'all'){ |
|
102 | + foreach ($this->_gateway_currencies as $currencies) { |
|
103 | + if ($currencies == 'all') { |
|
104 | 104 | $currencies = $this->_get_all_currencies(); |
105 | 105 | } |
106 | 106 | $count += count($currencies); |
@@ -110,20 +110,20 @@ discard block |
||
110 | 110 | |
111 | 111 | |
112 | 112 | |
113 | - protected function _migration_step( $num_items_to_migrate = 50 ) { |
|
113 | + protected function _migration_step($num_items_to_migrate = 50) { |
|
114 | 114 | $items_actually_migrated = 0; |
115 | 115 | $relations_to_add_this_step = $this->_gather_relations_to_add($num_items_to_migrate); |
116 | - foreach($relations_to_add_this_step as $pm_slug => $currencies){ |
|
116 | + foreach ($relations_to_add_this_step as $pm_slug => $currencies) { |
|
117 | 117 | |
118 | - $id = $this->get_migration_script()->get_mapping_new_pk( 'EE_Gateway_Config', $pm_slug, $this->_payment_method_table_name ); |
|
119 | - foreach( $currencies as $currency ){ |
|
120 | - if( $id ){ |
|
121 | - $this->_add_currency_relations( $id, $currency ); |
|
118 | + $id = $this->get_migration_script()->get_mapping_new_pk('EE_Gateway_Config', $pm_slug, $this->_payment_method_table_name); |
|
119 | + foreach ($currencies as $currency) { |
|
120 | + if ($id) { |
|
121 | + $this->_add_currency_relations($id, $currency); |
|
122 | 122 | } |
123 | 123 | $items_actually_migrated++; |
124 | 124 | } |
125 | 125 | } |
126 | - if($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()){ |
|
126 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
127 | 127 | $this->set_completed(); |
128 | 128 | } |
129 | 129 | return $items_actually_migrated; |
@@ -133,14 +133,14 @@ discard block |
||
133 | 133 | $relations_to_add_this_step = array(); |
134 | 134 | $migrate_up_to_count = $this->count_records_migrated() + $num_items_to_migrate; |
135 | 135 | $iterator = 0; |
136 | - foreach($this->_gateway_currencies as $pm_slug => $currencies){ |
|
137 | - if( $currencies == 'all' ){ |
|
136 | + foreach ($this->_gateway_currencies as $pm_slug => $currencies) { |
|
137 | + if ($currencies == 'all') { |
|
138 | 138 | $currencies = $this->_get_all_currencies(); |
139 | 139 | } |
140 | - foreach($currencies as $currency_code){ |
|
141 | - if( $this->count_records_migrated() <= $iterator && |
|
142 | - $iterator < $migrate_up_to_count ){ |
|
143 | - $relations_to_add_this_step[ $pm_slug ] [] = $currency_code; |
|
140 | + foreach ($currencies as $currency_code) { |
|
141 | + if ($this->count_records_migrated() <= $iterator && |
|
142 | + $iterator < $migrate_up_to_count) { |
|
143 | + $relations_to_add_this_step[$pm_slug] [] = $currency_code; |
|
144 | 144 | } |
145 | 145 | $iterator++; |
146 | 146 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * Gets all the currency codes in the database |
152 | 152 | * @return array |
153 | 153 | */ |
154 | - private function _get_all_currencies(){ |
|
154 | + private function _get_all_currencies() { |
|
155 | 155 | global $wpdb; |
156 | 156 | $currencies = $wpdb->get_col("SELECT CUR_code FROM {$this->_currency_table_name}"); |
157 | 157 | return $currencies; |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @param int $id |
163 | 163 | * @param string $gateway_slug |
164 | 164 | */ |
165 | - private function _add_currency_relations($pm_id,$currency_code){ |
|
165 | + private function _add_currency_relations($pm_id, $currency_code) { |
|
166 | 166 | global $wpdb; |
167 | 167 | $cur_pm_relation = array( |
168 | 168 | 'CUR_code'=>$currency_code, |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | $success = $wpdb->insert($this->_currency_payment_method_table_name, |
172 | 172 | $cur_pm_relation, |
173 | 173 | array( |
174 | - '%s',//CUR_code |
|
175 | - '%d',//PMD_ID |
|
174 | + '%s', //CUR_code |
|
175 | + '%d', //PMD_ID |
|
176 | 176 | )); |
177 | - if( ! $success ){ |
|
178 | - $this->add_error( sprintf( __( 'Could not add currency relation %s because %s', "event_espresso" ), wp_json_encode( $cur_pm_relation ), $wpdb->last_error ) ); |
|
177 | + if ( ! $success) { |
|
178 | + $this->add_error(sprintf(__('Could not add currency relation %s because %s', "event_espresso"), wp_json_encode($cur_pm_relation), $wpdb->last_error)); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | } |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | $stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*'); |
13 | 13 | $class_to_filepath = array(); |
14 | 14 | foreach ($stages as $filepath) { |
15 | - $matches = array(); |
|
16 | - preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
17 | - $class_to_filepath[$matches[1]] = $filepath; |
|
15 | + $matches = array(); |
|
16 | + preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
17 | + $class_to_filepath[$matches[1]] = $filepath; |
|
18 | 18 | } |
19 | 19 | //give addons a chance to autoload their stages too |
20 | 20 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath); |
@@ -33,68 +33,68 @@ discard block |
||
33 | 33 | class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * return EE_DMS_Core_4_9_0 |
|
38 | - * |
|
39 | - * @param TableManager $table_manager |
|
40 | - * @param TableAnalysis $table_analysis |
|
41 | - */ |
|
42 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
43 | - { |
|
44 | - $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso"); |
|
45 | - $this->_priority = 10; |
|
46 | - $this->_migration_stages = array( |
|
47 | - new EE_DMS_4_9_0_Email_System_Question(), |
|
48 | - new EE_DMS_4_9_0_Answers_With_No_Registration(), |
|
49 | - ); |
|
50 | - parent::__construct($table_manager, $table_analysis); |
|
51 | - } |
|
36 | + /** |
|
37 | + * return EE_DMS_Core_4_9_0 |
|
38 | + * |
|
39 | + * @param TableManager $table_manager |
|
40 | + * @param TableAnalysis $table_analysis |
|
41 | + */ |
|
42 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
43 | + { |
|
44 | + $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso"); |
|
45 | + $this->_priority = 10; |
|
46 | + $this->_migration_stages = array( |
|
47 | + new EE_DMS_4_9_0_Email_System_Question(), |
|
48 | + new EE_DMS_4_9_0_Answers_With_No_Registration(), |
|
49 | + ); |
|
50 | + parent::__construct($table_manager, $table_analysis); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Whether to migrate or not. |
|
57 | - * |
|
58 | - * @param array $version_array |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function can_migrate_from_version($version_array) |
|
62 | - { |
|
63 | - $version_string = $version_array['Core']; |
|
64 | - if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) { |
|
65 | - // echo "$version_string can be migrated from"; |
|
66 | - return true; |
|
67 | - } elseif ( ! $version_string) { |
|
68 | - // echo "no version string provided: $version_string"; |
|
69 | - //no version string provided... this must be pre 4.3 |
|
70 | - return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
71 | - } else { |
|
72 | - // echo "$version_string doesnt apply"; |
|
73 | - return false; |
|
74 | - } |
|
75 | - } |
|
55 | + /** |
|
56 | + * Whether to migrate or not. |
|
57 | + * |
|
58 | + * @param array $version_array |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function can_migrate_from_version($version_array) |
|
62 | + { |
|
63 | + $version_string = $version_array['Core']; |
|
64 | + if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) { |
|
65 | + // echo "$version_string can be migrated from"; |
|
66 | + return true; |
|
67 | + } elseif ( ! $version_string) { |
|
68 | + // echo "no version string provided: $version_string"; |
|
69 | + //no version string provided... this must be pre 4.3 |
|
70 | + return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
71 | + } else { |
|
72 | + // echo "$version_string doesnt apply"; |
|
73 | + return false; |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @return bool |
|
81 | - */ |
|
82 | - public function schema_changes_before_migration() |
|
83 | - { |
|
84 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
85 | - $now_in_mysql = current_time('mysql', true); |
|
86 | - $table_name = 'esp_answer'; |
|
87 | - $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
79 | + /** |
|
80 | + * @return bool |
|
81 | + */ |
|
82 | + public function schema_changes_before_migration() |
|
83 | + { |
|
84 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
85 | + $now_in_mysql = current_time('mysql', true); |
|
86 | + $table_name = 'esp_answer'; |
|
87 | + $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
88 | 88 | REG_ID int(10) unsigned NOT NULL, |
89 | 89 | QST_ID int(10) unsigned NOT NULL, |
90 | 90 | ANS_value text NOT NULL, |
91 | 91 | PRIMARY KEY (ANS_ID), |
92 | 92 | KEY REG_ID (REG_ID), |
93 | 93 | KEY QST_ID (QST_ID)"; |
94 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
95 | - $table_name = 'esp_attendee_meta'; |
|
96 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email'); |
|
97 | - $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
94 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
95 | + $table_name = 'esp_attendee_meta'; |
|
96 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email'); |
|
97 | + $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
98 | 98 | ATT_ID bigint(20) unsigned NOT NULL, |
99 | 99 | ATT_fname varchar(45) NOT NULL, |
100 | 100 | ATT_lname varchar(45) NOT NULL, |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | KEY ATT_email (ATT_email(191)), |
112 | 112 | KEY ATT_lname (ATT_lname), |
113 | 113 | KEY ATT_fname (ATT_fname)"; |
114 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
115 | - $table_name = 'esp_checkin'; |
|
116 | - $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
114 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
115 | + $table_name = 'esp_checkin'; |
|
116 | + $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
117 | 117 | REG_ID int(10) unsigned NOT NULL, |
118 | 118 | DTT_ID int(10) unsigned NOT NULL, |
119 | 119 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | PRIMARY KEY (CHK_ID), |
122 | 122 | KEY REG_ID (REG_ID), |
123 | 123 | KEY DTT_ID (DTT_ID)"; |
124 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
125 | - $table_name = 'esp_country'; |
|
126 | - $sql = "CNT_ISO varchar(2) NOT NULL, |
|
124 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
125 | + $table_name = 'esp_country'; |
|
126 | + $sql = "CNT_ISO varchar(2) NOT NULL, |
|
127 | 127 | CNT_ISO3 varchar(3) NOT NULL, |
128 | 128 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
129 | 129 | CNT_name varchar(45) NOT NULL, |
@@ -139,29 +139,29 @@ discard block |
||
139 | 139 | CNT_is_EU tinyint(1) DEFAULT '0', |
140 | 140 | CNT_active tinyint(1) DEFAULT '0', |
141 | 141 | PRIMARY KEY (CNT_ISO)"; |
142 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
143 | - $table_name = 'esp_currency'; |
|
144 | - $sql = "CUR_code varchar(6) NOT NULL, |
|
142 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
143 | + $table_name = 'esp_currency'; |
|
144 | + $sql = "CUR_code varchar(6) NOT NULL, |
|
145 | 145 | CUR_single varchar(45) DEFAULT 'dollar', |
146 | 146 | CUR_plural varchar(45) DEFAULT 'dollars', |
147 | 147 | CUR_sign varchar(45) DEFAULT '$', |
148 | 148 | CUR_dec_plc varchar(1) NOT NULL DEFAULT '2', |
149 | 149 | CUR_active tinyint(1) DEFAULT '0', |
150 | 150 | PRIMARY KEY (CUR_code)"; |
151 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | - //note: although this table is no longer in use, |
|
153 | - //it hasn't been removed because then queries to the model will have errors. |
|
154 | - //but you should expect this table and its corresponding model to be removed in |
|
155 | - //the next few months |
|
156 | - $table_name = 'esp_currency_payment_method'; |
|
157 | - $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
151 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | + //note: although this table is no longer in use, |
|
153 | + //it hasn't been removed because then queries to the model will have errors. |
|
154 | + //but you should expect this table and its corresponding model to be removed in |
|
155 | + //the next few months |
|
156 | + $table_name = 'esp_currency_payment_method'; |
|
157 | + $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
158 | 158 | CUR_code varchar(6) NOT NULL, |
159 | 159 | PMD_ID int(11) NOT NULL, |
160 | 160 | PRIMARY KEY (CPM_ID), |
161 | 161 | KEY PMD_ID (PMD_ID)"; |
162 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | - $table_name = 'esp_datetime'; |
|
164 | - $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
162 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | + $table_name = 'esp_datetime'; |
|
164 | + $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
165 | 165 | EVT_ID bigint(20) unsigned NOT NULL, |
166 | 166 | DTT_name varchar(255) NOT NULL DEFAULT '', |
167 | 167 | DTT_description text NOT NULL, |
@@ -178,25 +178,25 @@ discard block |
||
178 | 178 | KEY DTT_EVT_start (DTT_EVT_start), |
179 | 179 | KEY EVT_ID (EVT_ID), |
180 | 180 | KEY DTT_is_primary (DTT_is_primary)"; |
181 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | - $table_name = "esp_datetime_ticket"; |
|
183 | - $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
181 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | + $table_name = "esp_datetime_ticket"; |
|
183 | + $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
184 | 184 | DTT_ID int(10) unsigned NOT NULL, |
185 | 185 | TKT_ID int(10) unsigned NOT NULL, |
186 | 186 | PRIMARY KEY (DTK_ID), |
187 | 187 | KEY DTT_ID (DTT_ID), |
188 | 188 | KEY TKT_ID (TKT_ID)"; |
189 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | - $table_name = 'esp_event_message_template'; |
|
191 | - $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
189 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | + $table_name = 'esp_event_message_template'; |
|
191 | + $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
192 | 192 | EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
193 | 193 | GRP_ID int(10) unsigned NOT NULL DEFAULT 0, |
194 | 194 | PRIMARY KEY (EMT_ID), |
195 | 195 | KEY EVT_ID (EVT_ID), |
196 | 196 | KEY GRP_ID (GRP_ID)"; |
197 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | - $table_name = 'esp_event_meta'; |
|
199 | - $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
197 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | + $table_name = 'esp_event_meta'; |
|
199 | + $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
200 | 200 | EVT_ID bigint(20) unsigned NOT NULL, |
201 | 201 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
202 | 202 | EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -211,34 +211,34 @@ discard block |
||
211 | 211 | EVT_donations tinyint(1) NULL, |
212 | 212 | PRIMARY KEY (EVTM_ID), |
213 | 213 | KEY EVT_ID (EVT_ID)"; |
214 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | - $table_name = 'esp_event_question_group'; |
|
216 | - $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
214 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | + $table_name = 'esp_event_question_group'; |
|
216 | + $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
217 | 217 | EVT_ID bigint(20) unsigned NOT NULL, |
218 | 218 | QSG_ID int(10) unsigned NOT NULL, |
219 | 219 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
220 | 220 | PRIMARY KEY (EQG_ID), |
221 | 221 | KEY EVT_ID (EVT_ID), |
222 | 222 | KEY QSG_ID (QSG_ID)"; |
223 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | - $table_name = 'esp_event_venue'; |
|
225 | - $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
223 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | + $table_name = 'esp_event_venue'; |
|
225 | + $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
226 | 226 | EVT_ID bigint(20) unsigned NOT NULL, |
227 | 227 | VNU_ID bigint(20) unsigned NOT NULL, |
228 | 228 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
229 | 229 | PRIMARY KEY (EVV_ID)"; |
230 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
231 | - $table_name = 'esp_extra_meta'; |
|
232 | - $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
230 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
231 | + $table_name = 'esp_extra_meta'; |
|
232 | + $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
233 | 233 | OBJ_ID int(11) DEFAULT NULL, |
234 | 234 | EXM_type varchar(45) DEFAULT NULL, |
235 | 235 | EXM_key varchar(45) DEFAULT NULL, |
236 | 236 | EXM_value text, |
237 | 237 | PRIMARY KEY (EXM_ID), |
238 | 238 | KEY EXM_type (EXM_type,OBJ_ID,EXM_key)"; |
239 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
240 | - $table_name = 'esp_extra_join'; |
|
241 | - $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
239 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
240 | + $table_name = 'esp_extra_join'; |
|
241 | + $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
242 | 242 | EXJ_first_model_id varchar(6) NOT NULL, |
243 | 243 | EXJ_first_model_name varchar(20) NOT NULL, |
244 | 244 | EXJ_second_model_id varchar(6) NOT NULL, |
@@ -246,9 +246,9 @@ discard block |
||
246 | 246 | PRIMARY KEY (EXJ_ID), |
247 | 247 | KEY first_model (EXJ_first_model_name,EXJ_first_model_id), |
248 | 248 | KEY second_model (EXJ_second_model_name,EXJ_second_model_id)"; |
249 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
250 | - $table_name = 'esp_line_item'; |
|
251 | - $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
249 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
250 | + $table_name = 'esp_line_item'; |
|
251 | + $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
252 | 252 | LIN_code varchar(245) NOT NULL DEFAULT '', |
253 | 253 | TXN_ID int(11) DEFAULT NULL, |
254 | 254 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | PRIMARY KEY (LIN_ID), |
268 | 268 | KEY LIN_code (LIN_code(191)), |
269 | 269 | KEY TXN_ID (TXN_ID)"; |
270 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
271 | - $table_name = 'esp_log'; |
|
272 | - $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
270 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
271 | + $table_name = 'esp_log'; |
|
272 | + $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
273 | 273 | LOG_time datetime DEFAULT NULL, |
274 | 274 | OBJ_ID varchar(45) DEFAULT NULL, |
275 | 275 | OBJ_type varchar(45) DEFAULT NULL, |
@@ -280,12 +280,12 @@ discard block |
||
280 | 280 | KEY LOG_time (LOG_time), |
281 | 281 | KEY OBJ (OBJ_type,OBJ_ID), |
282 | 282 | KEY LOG_type (LOG_type)"; |
283 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
284 | - $table_name = 'esp_message'; |
|
285 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
286 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
287 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
288 | - $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
283 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
284 | + $table_name = 'esp_message'; |
|
285 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
286 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
287 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
288 | + $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
289 | 289 | GRP_ID int(10) unsigned NULL, |
290 | 290 | MSG_token varchar(255) NULL, |
291 | 291 | TXN_ID int(10) unsigned NULL, |
@@ -317,18 +317,18 @@ discard block |
||
317 | 317 | KEY STS_ID (STS_ID), |
318 | 318 | KEY MSG_created (MSG_created), |
319 | 319 | KEY MSG_modified (MSG_modified)"; |
320 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
321 | - $table_name = 'esp_message_template'; |
|
322 | - $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
320 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
321 | + $table_name = 'esp_message_template'; |
|
322 | + $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
323 | 323 | GRP_ID int(10) unsigned NOT NULL, |
324 | 324 | MTP_context varchar(50) NOT NULL, |
325 | 325 | MTP_template_field varchar(30) NOT NULL, |
326 | 326 | MTP_content text NOT NULL, |
327 | 327 | PRIMARY KEY (MTP_ID), |
328 | 328 | KEY GRP_ID (GRP_ID)"; |
329 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
330 | - $table_name = 'esp_message_template_group'; |
|
331 | - $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
329 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
330 | + $table_name = 'esp_message_template_group'; |
|
331 | + $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
332 | 332 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
333 | 333 | MTP_name varchar(245) NOT NULL DEFAULT '', |
334 | 334 | MTP_description varchar(245) NOT NULL DEFAULT '', |
@@ -340,9 +340,9 @@ discard block |
||
340 | 340 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
341 | 341 | PRIMARY KEY (GRP_ID), |
342 | 342 | KEY MTP_user_id (MTP_user_id)"; |
343 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
344 | - $table_name = 'esp_payment'; |
|
345 | - $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
343 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
344 | + $table_name = 'esp_payment'; |
|
345 | + $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
346 | 346 | TXN_ID int(10) unsigned DEFAULT NULL, |
347 | 347 | STS_ID varchar(3) DEFAULT NULL, |
348 | 348 | PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -359,9 +359,9 @@ discard block |
||
359 | 359 | PRIMARY KEY (PAY_ID), |
360 | 360 | KEY PAY_timestamp (PAY_timestamp), |
361 | 361 | KEY TXN_ID (TXN_ID)"; |
362 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
363 | - $table_name = 'esp_payment_method'; |
|
364 | - $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
362 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
363 | + $table_name = 'esp_payment_method'; |
|
364 | + $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
365 | 365 | PMD_type varchar(124) DEFAULT NULL, |
366 | 366 | PMD_name varchar(255) DEFAULT NULL, |
367 | 367 | PMD_desc text, |
@@ -377,24 +377,24 @@ discard block |
||
377 | 377 | PRIMARY KEY (PMD_ID), |
378 | 378 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug), |
379 | 379 | KEY PMD_type (PMD_type)"; |
380 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
381 | - $table_name = "esp_ticket_price"; |
|
382 | - $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
380 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
381 | + $table_name = "esp_ticket_price"; |
|
382 | + $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
383 | 383 | TKT_ID int(10) unsigned NOT NULL, |
384 | 384 | PRC_ID int(10) unsigned NOT NULL, |
385 | 385 | PRIMARY KEY (TKP_ID), |
386 | 386 | KEY TKT_ID (TKT_ID), |
387 | 387 | KEY PRC_ID (PRC_ID)"; |
388 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
389 | - $table_name = "esp_ticket_template"; |
|
390 | - $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
388 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
389 | + $table_name = "esp_ticket_template"; |
|
390 | + $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
391 | 391 | TTM_name varchar(45) NOT NULL, |
392 | 392 | TTM_description text, |
393 | 393 | TTM_file varchar(45), |
394 | 394 | PRIMARY KEY (TTM_ID)"; |
395 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
396 | - $table_name = 'esp_question'; |
|
397 | - $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
395 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
396 | + $table_name = 'esp_question'; |
|
397 | + $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
398 | 398 | QST_display_text text NOT NULL, |
399 | 399 | QST_admin_label varchar(255) NOT NULL, |
400 | 400 | QST_system varchar(25) DEFAULT NULL, |
@@ -408,18 +408,18 @@ discard block |
||
408 | 408 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
409 | 409 | PRIMARY KEY (QST_ID), |
410 | 410 | KEY QST_order (QST_order)'; |
411 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
412 | - $table_name = 'esp_question_group_question'; |
|
413 | - $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
411 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
412 | + $table_name = 'esp_question_group_question'; |
|
413 | + $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
414 | 414 | QSG_ID int(10) unsigned NOT NULL, |
415 | 415 | QST_ID int(10) unsigned NOT NULL, |
416 | 416 | QGQ_order int(10) unsigned NOT NULL DEFAULT 0, |
417 | 417 | PRIMARY KEY (QGQ_ID), |
418 | 418 | KEY QST_ID (QST_ID), |
419 | 419 | KEY QSG_ID_order (QSG_ID,QGQ_order)"; |
420 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
421 | - $table_name = 'esp_question_option'; |
|
422 | - $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
420 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
421 | + $table_name = 'esp_question_option'; |
|
422 | + $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
423 | 423 | QSO_value varchar(255) NOT NULL, |
424 | 424 | QSO_desc text NOT NULL, |
425 | 425 | QST_ID int(10) unsigned NOT NULL, |
@@ -429,9 +429,9 @@ discard block |
||
429 | 429 | PRIMARY KEY (QSO_ID), |
430 | 430 | KEY QST_ID (QST_ID), |
431 | 431 | KEY QSO_order (QSO_order)"; |
432 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
433 | - $table_name = 'esp_registration'; |
|
434 | - $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
432 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
433 | + $table_name = 'esp_registration'; |
|
434 | + $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
435 | 435 | EVT_ID bigint(20) unsigned NOT NULL, |
436 | 436 | ATT_ID bigint(20) unsigned NOT NULL, |
437 | 437 | TXN_ID int(10) unsigned NOT NULL, |
@@ -455,18 +455,18 @@ discard block |
||
455 | 455 | KEY TKT_ID (TKT_ID), |
456 | 456 | KEY EVT_ID (EVT_ID), |
457 | 457 | KEY STS_ID (STS_ID)"; |
458 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
459 | - $table_name = 'esp_registration_payment'; |
|
460 | - $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
458 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
459 | + $table_name = 'esp_registration_payment'; |
|
460 | + $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
461 | 461 | REG_ID int(10) unsigned NOT NULL, |
462 | 462 | PAY_ID int(10) unsigned NULL, |
463 | 463 | RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
464 | 464 | PRIMARY KEY (RPY_ID), |
465 | 465 | KEY REG_ID (REG_ID), |
466 | 466 | KEY PAY_ID (PAY_ID)"; |
467 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
468 | - $table_name = 'esp_state'; |
|
469 | - $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
467 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
468 | + $table_name = 'esp_state'; |
|
469 | + $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
470 | 470 | CNT_ISO varchar(2) NOT NULL, |
471 | 471 | STA_abbrev varchar(24) NOT NULL, |
472 | 472 | STA_name varchar(100) NOT NULL, |
@@ -474,9 +474,9 @@ discard block |
||
474 | 474 | PRIMARY KEY (STA_ID), |
475 | 475 | KEY STA_abbrev (STA_abbrev), |
476 | 476 | KEY CNT_ISO (CNT_ISO)"; |
477 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
478 | - $table_name = 'esp_status'; |
|
479 | - $sql = "STS_ID varchar(3) NOT NULL, |
|
477 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
478 | + $table_name = 'esp_status'; |
|
479 | + $sql = "STS_ID varchar(3) NOT NULL, |
|
480 | 480 | STS_code varchar(45) NOT NULL, |
481 | 481 | STS_type varchar(45) NOT NULL, |
482 | 482 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -484,9 +484,9 @@ discard block |
||
484 | 484 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
485 | 485 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
486 | 486 | KEY STS_type (STS_type)"; |
487 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
488 | - $table_name = 'esp_transaction'; |
|
489 | - $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
487 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
488 | + $table_name = 'esp_transaction'; |
|
489 | + $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
490 | 490 | TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
491 | 491 | TXN_total decimal(12,3) DEFAULT '0.00', |
492 | 492 | TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00', |
@@ -498,9 +498,9 @@ discard block |
||
498 | 498 | PRIMARY KEY (TXN_ID), |
499 | 499 | KEY TXN_timestamp (TXN_timestamp), |
500 | 500 | KEY STS_ID (STS_ID)"; |
501 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
502 | - $table_name = 'esp_venue_meta'; |
|
503 | - $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
501 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
502 | + $table_name = 'esp_venue_meta'; |
|
503 | + $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
504 | 504 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
505 | 505 | VNU_address varchar(255) DEFAULT NULL, |
506 | 506 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -519,10 +519,10 @@ discard block |
||
519 | 519 | KEY VNU_ID (VNU_ID), |
520 | 520 | KEY STA_ID (STA_ID), |
521 | 521 | KEY CNT_ISO (CNT_ISO)"; |
522 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
523 | - //modified tables |
|
524 | - $table_name = "esp_price"; |
|
525 | - $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
522 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
523 | + //modified tables |
|
524 | + $table_name = "esp_price"; |
|
525 | + $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
526 | 526 | PRT_ID tinyint(3) unsigned NOT NULL, |
527 | 527 | PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
528 | 528 | PRC_name varchar(245) NOT NULL, |
@@ -535,9 +535,9 @@ discard block |
||
535 | 535 | PRC_parent int(10) unsigned DEFAULT 0, |
536 | 536 | PRIMARY KEY (PRC_ID), |
537 | 537 | KEY PRT_ID (PRT_ID)"; |
538 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
539 | - $table_name = "esp_price_type"; |
|
540 | - $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
538 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
539 | + $table_name = "esp_price_type"; |
|
540 | + $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
541 | 541 | PRT_name varchar(45) NOT NULL, |
542 | 542 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
543 | 543 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -546,9 +546,9 @@ discard block |
||
546 | 546 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
547 | 547 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
548 | 548 | PRIMARY KEY (PRT_ID)"; |
549 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
550 | - $table_name = "esp_ticket"; |
|
551 | - $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
549 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
550 | + $table_name = "esp_ticket"; |
|
551 | + $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
552 | 552 | TTM_ID int(10) unsigned NOT NULL, |
553 | 553 | TKT_name varchar(245) NOT NULL DEFAULT '', |
554 | 554 | TKT_description text NOT NULL, |
@@ -571,9 +571,9 @@ discard block |
||
571 | 571 | TKT_deleted tinyint(1) NOT NULL DEFAULT '0', |
572 | 572 | PRIMARY KEY (TKT_ID), |
573 | 573 | KEY TKT_start_date (TKT_start_date)"; |
574 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
575 | - $table_name = 'esp_question_group'; |
|
576 | - $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
574 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
575 | + $table_name = 'esp_question_group'; |
|
576 | + $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
577 | 577 | QSG_name varchar(255) NOT NULL, |
578 | 578 | QSG_identifier varchar(100) NOT NULL, |
579 | 579 | QSG_desc text NULL, |
@@ -586,138 +586,138 @@ discard block |
||
586 | 586 | PRIMARY KEY (QSG_ID), |
587 | 587 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier), |
588 | 588 | KEY QSG_order (QSG_order)'; |
589 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
590 | - /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
591 | - $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
592 | - //(because many need to convert old string states to foreign keys into the states table) |
|
593 | - $script_4_1_defaults->insert_default_states(); |
|
594 | - $script_4_1_defaults->insert_default_countries(); |
|
595 | - /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
596 | - $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
597 | - $script_4_5_defaults->insert_default_price_types(); |
|
598 | - $script_4_5_defaults->insert_default_prices(); |
|
599 | - $script_4_5_defaults->insert_default_tickets(); |
|
600 | - /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
601 | - $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
602 | - $script_4_6_defaults->add_default_admin_only_payments(); |
|
603 | - $script_4_6_defaults->insert_default_currencies(); |
|
604 | - /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
605 | - $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
606 | - $script_4_8_defaults->verify_new_countries(); |
|
607 | - $script_4_8_defaults->verify_new_currencies(); |
|
608 | - $this->verify_db_collations(); |
|
609 | - $this->verify_db_collations_again(); |
|
610 | - return true; |
|
611 | - } |
|
589 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
590 | + /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
591 | + $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
592 | + //(because many need to convert old string states to foreign keys into the states table) |
|
593 | + $script_4_1_defaults->insert_default_states(); |
|
594 | + $script_4_1_defaults->insert_default_countries(); |
|
595 | + /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
596 | + $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
597 | + $script_4_5_defaults->insert_default_price_types(); |
|
598 | + $script_4_5_defaults->insert_default_prices(); |
|
599 | + $script_4_5_defaults->insert_default_tickets(); |
|
600 | + /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
601 | + $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
602 | + $script_4_6_defaults->add_default_admin_only_payments(); |
|
603 | + $script_4_6_defaults->insert_default_currencies(); |
|
604 | + /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
605 | + $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
606 | + $script_4_8_defaults->verify_new_countries(); |
|
607 | + $script_4_8_defaults->verify_new_currencies(); |
|
608 | + $this->verify_db_collations(); |
|
609 | + $this->verify_db_collations_again(); |
|
610 | + return true; |
|
611 | + } |
|
612 | 612 | |
613 | 613 | |
614 | 614 | |
615 | - /** |
|
616 | - * @return boolean |
|
617 | - */ |
|
618 | - public function schema_changes_after_migration() |
|
619 | - { |
|
620 | - return true; |
|
621 | - } |
|
615 | + /** |
|
616 | + * @return boolean |
|
617 | + */ |
|
618 | + public function schema_changes_after_migration() |
|
619 | + { |
|
620 | + return true; |
|
621 | + } |
|
622 | 622 | |
623 | 623 | |
624 | 624 | |
625 | - public function migration_page_hooks() |
|
626 | - { |
|
627 | - } |
|
625 | + public function migration_page_hooks() |
|
626 | + { |
|
627 | + } |
|
628 | 628 | |
629 | 629 | |
630 | 630 | |
631 | - /** |
|
632 | - * Verify all EE4 models' tables use utf8mb4 collation |
|
633 | - * |
|
634 | - * @return void |
|
635 | - */ |
|
636 | - public function verify_db_collations() |
|
637 | - { |
|
638 | - if (get_option('ee_verified_db_collations', false)) { |
|
639 | - return; |
|
640 | - } |
|
641 | - // grab tables from each model |
|
642 | - $tables_to_check = array(); |
|
643 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
644 | - if (method_exists($model_name, 'instance')) { |
|
645 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
646 | - if ($model_obj instanceof EEM_Base) { |
|
647 | - foreach ($model_obj->get_tables() as $table) { |
|
648 | - if ( |
|
649 | - strpos($table->get_table_name(), 'esp_') |
|
650 | - && (is_main_site()//for main tables, verify global tables |
|
651 | - || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up) |
|
652 | - ) |
|
653 | - && function_exists('maybe_convert_table_to_utf8mb4') |
|
654 | - ) { |
|
655 | - $tables_to_check[] = $table->get_table_name(); |
|
656 | - } |
|
657 | - } |
|
658 | - } |
|
659 | - } |
|
660 | - } |
|
661 | - //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
662 | - //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
663 | - //of hard-coding this |
|
664 | - $addon_tables = array( |
|
665 | - //mailchimp |
|
666 | - 'esp_event_mailchimp_list_group', |
|
667 | - 'esp_event_question_mailchimp_field', |
|
668 | - //multisite |
|
669 | - 'esp_blog_meta', |
|
670 | - //people |
|
671 | - 'esp_people_to_post', |
|
672 | - //promotions |
|
673 | - 'esp_promotion', |
|
674 | - 'esp_promotion_object', |
|
675 | - ); |
|
676 | - foreach ($addon_tables as $table_name) { |
|
677 | - $tables_to_check[] = $table_name; |
|
678 | - } |
|
679 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
680 | - //ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
681 | - add_option('ee_verified_db_collations', true, null, 'no'); |
|
682 | - //seeing how this ran with the fix from 10435, no need to check again |
|
683 | - add_option('ee_verified_db_collations_again',true,null,'no'); |
|
684 | - } |
|
631 | + /** |
|
632 | + * Verify all EE4 models' tables use utf8mb4 collation |
|
633 | + * |
|
634 | + * @return void |
|
635 | + */ |
|
636 | + public function verify_db_collations() |
|
637 | + { |
|
638 | + if (get_option('ee_verified_db_collations', false)) { |
|
639 | + return; |
|
640 | + } |
|
641 | + // grab tables from each model |
|
642 | + $tables_to_check = array(); |
|
643 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
644 | + if (method_exists($model_name, 'instance')) { |
|
645 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
646 | + if ($model_obj instanceof EEM_Base) { |
|
647 | + foreach ($model_obj->get_tables() as $table) { |
|
648 | + if ( |
|
649 | + strpos($table->get_table_name(), 'esp_') |
|
650 | + && (is_main_site()//for main tables, verify global tables |
|
651 | + || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up) |
|
652 | + ) |
|
653 | + && function_exists('maybe_convert_table_to_utf8mb4') |
|
654 | + ) { |
|
655 | + $tables_to_check[] = $table->get_table_name(); |
|
656 | + } |
|
657 | + } |
|
658 | + } |
|
659 | + } |
|
660 | + } |
|
661 | + //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
662 | + //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
663 | + //of hard-coding this |
|
664 | + $addon_tables = array( |
|
665 | + //mailchimp |
|
666 | + 'esp_event_mailchimp_list_group', |
|
667 | + 'esp_event_question_mailchimp_field', |
|
668 | + //multisite |
|
669 | + 'esp_blog_meta', |
|
670 | + //people |
|
671 | + 'esp_people_to_post', |
|
672 | + //promotions |
|
673 | + 'esp_promotion', |
|
674 | + 'esp_promotion_object', |
|
675 | + ); |
|
676 | + foreach ($addon_tables as $table_name) { |
|
677 | + $tables_to_check[] = $table_name; |
|
678 | + } |
|
679 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
680 | + //ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
681 | + add_option('ee_verified_db_collations', true, null, 'no'); |
|
682 | + //seeing how this ran with the fix from 10435, no need to check again |
|
683 | + add_option('ee_verified_db_collations_again',true,null,'no'); |
|
684 | + } |
|
685 | 685 | |
686 | 686 | |
687 | 687 | |
688 | - /** |
|
689 | - * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
690 | - * which meant some DB collations might not have been updated |
|
691 | - * @return void |
|
692 | - */ |
|
693 | - public function verify_db_collations_again(){ |
|
694 | - if (get_option('ee_verified_db_collations_again', false)) { |
|
695 | - return; |
|
696 | - } |
|
697 | - $tables_to_check = array( |
|
698 | - 'esp_attendee_meta', |
|
699 | - 'esp_message' |
|
700 | - ); |
|
701 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
702 | - add_option('ee_verified_db_collations_again',true,null,'no'); |
|
703 | - } |
|
688 | + /** |
|
689 | + * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
690 | + * which meant some DB collations might not have been updated |
|
691 | + * @return void |
|
692 | + */ |
|
693 | + public function verify_db_collations_again(){ |
|
694 | + if (get_option('ee_verified_db_collations_again', false)) { |
|
695 | + return; |
|
696 | + } |
|
697 | + $tables_to_check = array( |
|
698 | + 'esp_attendee_meta', |
|
699 | + 'esp_message' |
|
700 | + ); |
|
701 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
702 | + add_option('ee_verified_db_collations_again',true,null,'no'); |
|
703 | + } |
|
704 | 704 | |
705 | 705 | |
706 | 706 | |
707 | - /** |
|
708 | - * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
709 | - * @param $tables_to_check |
|
710 | - * @return boolean true if logic ran, false if it didn't |
|
711 | - */ |
|
712 | - protected function _verify_db_collations_for_tables($tables_to_check) |
|
713 | - { |
|
714 | - foreach ($tables_to_check as $table_name) { |
|
715 | - $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
716 | - if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name ) |
|
717 | - && $this->_get_table_analysis()->tableExists($table_name) |
|
718 | - ) { |
|
719 | - maybe_convert_table_to_utf8mb4($table_name); |
|
720 | - } |
|
721 | - } |
|
722 | - } |
|
707 | + /** |
|
708 | + * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
709 | + * @param $tables_to_check |
|
710 | + * @return boolean true if logic ran, false if it didn't |
|
711 | + */ |
|
712 | + protected function _verify_db_collations_for_tables($tables_to_check) |
|
713 | + { |
|
714 | + foreach ($tables_to_check as $table_name) { |
|
715 | + $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
716 | + if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name ) |
|
717 | + && $this->_get_table_analysis()->tableExists($table_name) |
|
718 | + ) { |
|
719 | + maybe_convert_table_to_utf8mb4($table_name); |
|
720 | + } |
|
721 | + } |
|
722 | + } |
|
723 | 723 | } |
724 | 724 | \ No newline at end of file |