@@ -16,2800 +16,2800 @@ |
||
16 | 16 | class Events_Admin_Page extends EE_Admin_Page_CPT |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * This will hold the event object for event_details screen. |
|
19 | + /** |
|
20 | + * This will hold the event object for event_details screen. |
|
21 | + * |
|
22 | + * @var EE_Event $_event |
|
23 | + */ |
|
24 | + protected $_event; |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * This will hold the category object for category_details screen. |
|
29 | + * |
|
30 | + * @var stdClass $_category |
|
31 | + */ |
|
32 | + protected $_category; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * This will hold the event model instance |
|
37 | + * |
|
38 | + * @var EEM_Event $_event_model |
|
39 | + */ |
|
40 | + protected $_event_model; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @var EE_Event |
|
45 | + */ |
|
46 | + protected $_cpt_model_obj = false; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * @var NodeGroupDao |
|
51 | + */ |
|
52 | + protected $model_obj_node_group_persister; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Initialize page props for this admin page group. |
|
57 | + */ |
|
58 | + protected function _init_page_props() |
|
59 | + { |
|
60 | + $this->page_slug = EVENTS_PG_SLUG; |
|
61 | + $this->page_label = EVENTS_LABEL; |
|
62 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
63 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
64 | + $this->_cpt_model_names = [ |
|
65 | + 'create_new' => 'EEM_Event', |
|
66 | + 'edit' => 'EEM_Event', |
|
67 | + ]; |
|
68 | + $this->_cpt_edit_routes = [ |
|
69 | + 'espresso_events' => 'edit', |
|
70 | + ]; |
|
71 | + add_action( |
|
72 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
73 | + [$this, 'verify_event_edit'], |
|
74 | + 10, |
|
75 | + 2 |
|
76 | + ); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Sets the ajax hooks used for this admin page group. |
|
82 | + */ |
|
83 | + protected function _ajax_hooks() |
|
84 | + { |
|
85 | + add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Sets the page properties for this admin page group. |
|
91 | + */ |
|
92 | + protected function _define_page_props() |
|
93 | + { |
|
94 | + $this->_admin_page_title = EVENTS_LABEL; |
|
95 | + $this->_labels = [ |
|
96 | + 'buttons' => [ |
|
97 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
98 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
99 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
100 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
101 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
102 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
103 | + ], |
|
104 | + 'editor_title' => [ |
|
105 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
106 | + ], |
|
107 | + 'publishbox' => [ |
|
108 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
109 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
110 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
111 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
112 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
113 | + ], |
|
114 | + ]; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * Sets the page routes property for this admin page group. |
|
120 | + */ |
|
121 | + protected function _set_page_routes() |
|
122 | + { |
|
123 | + // load formatter helper |
|
124 | + // load field generator helper |
|
125 | + // is there a evt_id in the request? |
|
126 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
127 | + $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
|
128 | + |
|
129 | + $this->_page_routes = [ |
|
130 | + 'default' => [ |
|
131 | + 'func' => '_events_overview_list_table', |
|
132 | + 'capability' => 'ee_read_events', |
|
133 | + ], |
|
134 | + 'create_new' => [ |
|
135 | + 'func' => '_create_new_cpt_item', |
|
136 | + 'capability' => 'ee_edit_events', |
|
137 | + ], |
|
138 | + 'edit' => [ |
|
139 | + 'func' => '_edit_cpt_item', |
|
140 | + 'capability' => 'ee_edit_event', |
|
141 | + 'obj_id' => $EVT_ID, |
|
142 | + ], |
|
143 | + 'copy_event' => [ |
|
144 | + 'func' => '_copy_events', |
|
145 | + 'capability' => 'ee_edit_event', |
|
146 | + 'obj_id' => $EVT_ID, |
|
147 | + 'noheader' => true, |
|
148 | + ], |
|
149 | + 'trash_event' => [ |
|
150 | + 'func' => '_trash_or_restore_event', |
|
151 | + 'args' => ['event_status' => 'trash'], |
|
152 | + 'capability' => 'ee_delete_event', |
|
153 | + 'obj_id' => $EVT_ID, |
|
154 | + 'noheader' => true, |
|
155 | + ], |
|
156 | + 'trash_events' => [ |
|
157 | + 'func' => '_trash_or_restore_events', |
|
158 | + 'args' => ['event_status' => 'trash'], |
|
159 | + 'capability' => 'ee_delete_events', |
|
160 | + 'noheader' => true, |
|
161 | + ], |
|
162 | + 'restore_event' => [ |
|
163 | + 'func' => '_trash_or_restore_event', |
|
164 | + 'args' => ['event_status' => 'draft'], |
|
165 | + 'capability' => 'ee_delete_event', |
|
166 | + 'obj_id' => $EVT_ID, |
|
167 | + 'noheader' => true, |
|
168 | + ], |
|
169 | + 'restore_events' => [ |
|
170 | + 'func' => '_trash_or_restore_events', |
|
171 | + 'args' => ['event_status' => 'draft'], |
|
172 | + 'capability' => 'ee_delete_events', |
|
173 | + 'noheader' => true, |
|
174 | + ], |
|
175 | + 'delete_event' => [ |
|
176 | + 'func' => '_delete_event', |
|
177 | + 'capability' => 'ee_delete_event', |
|
178 | + 'obj_id' => $EVT_ID, |
|
179 | + 'noheader' => true, |
|
180 | + ], |
|
181 | + 'delete_events' => [ |
|
182 | + 'func' => '_delete_events', |
|
183 | + 'capability' => 'ee_delete_events', |
|
184 | + 'noheader' => true, |
|
185 | + ], |
|
186 | + 'view_report' => [ |
|
187 | + 'func' => '_view_report', |
|
188 | + 'capability' => 'ee_edit_events', |
|
189 | + ], |
|
190 | + 'default_event_settings' => [ |
|
191 | + 'func' => '_default_event_settings', |
|
192 | + 'capability' => 'manage_options', |
|
193 | + ], |
|
194 | + 'update_default_event_settings' => [ |
|
195 | + 'func' => '_update_default_event_settings', |
|
196 | + 'capability' => 'manage_options', |
|
197 | + 'noheader' => true, |
|
198 | + ], |
|
199 | + 'template_settings' => [ |
|
200 | + 'func' => '_template_settings', |
|
201 | + 'capability' => 'manage_options', |
|
202 | + ], |
|
203 | + // event category tab related |
|
204 | + 'add_category' => [ |
|
205 | + 'func' => '_category_details', |
|
206 | + 'capability' => 'ee_edit_event_category', |
|
207 | + 'args' => ['add'], |
|
208 | + ], |
|
209 | + 'edit_category' => [ |
|
210 | + 'func' => '_category_details', |
|
211 | + 'capability' => 'ee_edit_event_category', |
|
212 | + 'args' => ['edit'], |
|
213 | + ], |
|
214 | + 'delete_categories' => [ |
|
215 | + 'func' => '_delete_categories', |
|
216 | + 'capability' => 'ee_delete_event_category', |
|
217 | + 'noheader' => true, |
|
218 | + ], |
|
219 | + 'delete_category' => [ |
|
220 | + 'func' => '_delete_categories', |
|
221 | + 'capability' => 'ee_delete_event_category', |
|
222 | + 'noheader' => true, |
|
223 | + ], |
|
224 | + 'insert_category' => [ |
|
225 | + 'func' => '_insert_or_update_category', |
|
226 | + 'args' => ['new_category' => true], |
|
227 | + 'capability' => 'ee_edit_event_category', |
|
228 | + 'noheader' => true, |
|
229 | + ], |
|
230 | + 'update_category' => [ |
|
231 | + 'func' => '_insert_or_update_category', |
|
232 | + 'args' => ['new_category' => false], |
|
233 | + 'capability' => 'ee_edit_event_category', |
|
234 | + 'noheader' => true, |
|
235 | + ], |
|
236 | + 'category_list' => [ |
|
237 | + 'func' => '_category_list_table', |
|
238 | + 'capability' => 'ee_manage_event_categories', |
|
239 | + ], |
|
240 | + 'preview_deletion' => [ |
|
241 | + 'func' => 'previewDeletion', |
|
242 | + 'capability' => 'ee_delete_events', |
|
243 | + ], |
|
244 | + 'confirm_deletion' => [ |
|
245 | + 'func' => 'confirmDeletion', |
|
246 | + 'capability' => 'ee_delete_events', |
|
247 | + 'noheader' => true, |
|
248 | + ], |
|
249 | + ]; |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * Set the _page_config property for this admin page group. |
|
255 | + */ |
|
256 | + protected function _set_page_config() |
|
257 | + { |
|
258 | + $post_id = $this->request->getRequestParam('post', 0, 'int'); |
|
259 | + $EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
260 | + $this->_page_config = [ |
|
261 | + 'default' => [ |
|
262 | + 'nav' => [ |
|
263 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
264 | + 'order' => 10, |
|
265 | + ], |
|
266 | + 'list_table' => 'Events_Admin_List_Table', |
|
267 | + 'help_tabs' => [ |
|
268 | + 'events_overview_help_tab' => [ |
|
269 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
270 | + 'filename' => 'events_overview', |
|
271 | + ], |
|
272 | + 'events_overview_table_column_headings_help_tab' => [ |
|
273 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
274 | + 'filename' => 'events_overview_table_column_headings', |
|
275 | + ], |
|
276 | + 'events_overview_filters_help_tab' => [ |
|
277 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
278 | + 'filename' => 'events_overview_filters', |
|
279 | + ], |
|
280 | + 'events_overview_view_help_tab' => [ |
|
281 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
282 | + 'filename' => 'events_overview_views', |
|
283 | + ], |
|
284 | + 'events_overview_other_help_tab' => [ |
|
285 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
286 | + 'filename' => 'events_overview_other', |
|
287 | + ], |
|
288 | + ], |
|
289 | + 'qtips' => [ |
|
290 | + 'EE_Event_List_Table_Tips', |
|
291 | + ], |
|
292 | + 'require_nonce' => false, |
|
293 | + ], |
|
294 | + 'create_new' => [ |
|
295 | + 'nav' => [ |
|
296 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
297 | + 'order' => 5, |
|
298 | + 'persistent' => false, |
|
299 | + ], |
|
300 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
301 | + 'help_tabs' => [ |
|
302 | + 'event_editor_help_tab' => [ |
|
303 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
304 | + 'filename' => 'event_editor', |
|
305 | + ], |
|
306 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
307 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
308 | + 'filename' => 'event_editor_title_richtexteditor', |
|
309 | + ], |
|
310 | + 'event_editor_venue_details_help_tab' => [ |
|
311 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
312 | + 'filename' => 'event_editor_venue_details', |
|
313 | + ], |
|
314 | + 'event_editor_event_datetimes_help_tab' => [ |
|
315 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
316 | + 'filename' => 'event_editor_event_datetimes', |
|
317 | + ], |
|
318 | + 'event_editor_event_tickets_help_tab' => [ |
|
319 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
320 | + 'filename' => 'event_editor_event_tickets', |
|
321 | + ], |
|
322 | + 'event_editor_event_registration_options_help_tab' => [ |
|
323 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
324 | + 'filename' => 'event_editor_event_registration_options', |
|
325 | + ], |
|
326 | + 'event_editor_tags_categories_help_tab' => [ |
|
327 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
328 | + 'filename' => 'event_editor_tags_categories', |
|
329 | + ], |
|
330 | + 'event_editor_questions_registrants_help_tab' => [ |
|
331 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
332 | + 'filename' => 'event_editor_questions_registrants', |
|
333 | + ], |
|
334 | + 'event_editor_save_new_event_help_tab' => [ |
|
335 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
336 | + 'filename' => 'event_editor_save_new_event', |
|
337 | + ], |
|
338 | + 'event_editor_other_help_tab' => [ |
|
339 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
340 | + 'filename' => 'event_editor_other', |
|
341 | + ], |
|
342 | + ], |
|
343 | + 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
344 | + 'require_nonce' => false, |
|
345 | + ], |
|
346 | + 'edit' => [ |
|
347 | + 'nav' => [ |
|
348 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
349 | + 'order' => 5, |
|
350 | + 'persistent' => false, |
|
351 | + 'url' => $post_id |
|
352 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
353 | + ['post' => $post_id, 'action' => 'edit'], |
|
354 | + $this->_current_page_view_url |
|
355 | + ) |
|
356 | + : $this->_admin_base_url, |
|
357 | + ], |
|
358 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
359 | + 'help_tabs' => [ |
|
360 | + 'event_editor_help_tab' => [ |
|
361 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
362 | + 'filename' => 'event_editor', |
|
363 | + ], |
|
364 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
365 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
366 | + 'filename' => 'event_editor_title_richtexteditor', |
|
367 | + ], |
|
368 | + 'event_editor_venue_details_help_tab' => [ |
|
369 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
370 | + 'filename' => 'event_editor_venue_details', |
|
371 | + ], |
|
372 | + 'event_editor_event_datetimes_help_tab' => [ |
|
373 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
374 | + 'filename' => 'event_editor_event_datetimes', |
|
375 | + ], |
|
376 | + 'event_editor_event_tickets_help_tab' => [ |
|
377 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
378 | + 'filename' => 'event_editor_event_tickets', |
|
379 | + ], |
|
380 | + 'event_editor_event_registration_options_help_tab' => [ |
|
381 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
382 | + 'filename' => 'event_editor_event_registration_options', |
|
383 | + ], |
|
384 | + 'event_editor_tags_categories_help_tab' => [ |
|
385 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
386 | + 'filename' => 'event_editor_tags_categories', |
|
387 | + ], |
|
388 | + 'event_editor_questions_registrants_help_tab' => [ |
|
389 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
390 | + 'filename' => 'event_editor_questions_registrants', |
|
391 | + ], |
|
392 | + 'event_editor_save_new_event_help_tab' => [ |
|
393 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
394 | + 'filename' => 'event_editor_save_new_event', |
|
395 | + ], |
|
396 | + 'event_editor_other_help_tab' => [ |
|
397 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
398 | + 'filename' => 'event_editor_other', |
|
399 | + ], |
|
400 | + ], |
|
401 | + 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
402 | + 'require_nonce' => false, |
|
403 | + ], |
|
404 | + 'default_event_settings' => [ |
|
405 | + 'nav' => [ |
|
406 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
407 | + 'order' => 40, |
|
408 | + ], |
|
409 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
410 | + 'labels' => [ |
|
411 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
412 | + ], |
|
413 | + 'help_tabs' => [ |
|
414 | + 'default_settings_help_tab' => [ |
|
415 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
416 | + 'filename' => 'events_default_settings', |
|
417 | + ], |
|
418 | + 'default_settings_status_help_tab' => [ |
|
419 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
420 | + 'filename' => 'events_default_settings_status', |
|
421 | + ], |
|
422 | + 'default_maximum_tickets_help_tab' => [ |
|
423 | + 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
424 | + 'filename' => 'events_default_settings_max_tickets', |
|
425 | + ], |
|
426 | + ], |
|
427 | + 'require_nonce' => false, |
|
428 | + ], |
|
429 | + // template settings |
|
430 | + 'template_settings' => [ |
|
431 | + 'nav' => [ |
|
432 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
433 | + 'order' => 30, |
|
434 | + ], |
|
435 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
436 | + 'help_tabs' => [ |
|
437 | + 'general_settings_templates_help_tab' => [ |
|
438 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
439 | + 'filename' => 'general_settings_templates', |
|
440 | + ], |
|
441 | + ], |
|
442 | + 'require_nonce' => false, |
|
443 | + ], |
|
444 | + // event category stuff |
|
445 | + 'add_category' => [ |
|
446 | + 'nav' => [ |
|
447 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
448 | + 'order' => 15, |
|
449 | + 'persistent' => false, |
|
450 | + ], |
|
451 | + 'help_tabs' => [ |
|
452 | + 'add_category_help_tab' => [ |
|
453 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
454 | + 'filename' => 'events_add_category', |
|
455 | + ], |
|
456 | + ], |
|
457 | + 'metaboxes' => ['_publish_post_box'], |
|
458 | + 'require_nonce' => false, |
|
459 | + ], |
|
460 | + 'edit_category' => [ |
|
461 | + 'nav' => [ |
|
462 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
463 | + 'order' => 15, |
|
464 | + 'persistent' => false, |
|
465 | + 'url' => $EVT_CAT_ID |
|
466 | + ? add_query_arg( |
|
467 | + ['EVT_CAT_ID' => $EVT_CAT_ID], |
|
468 | + $this->_current_page_view_url |
|
469 | + ) |
|
470 | + : $this->_admin_base_url, |
|
471 | + ], |
|
472 | + 'help_tabs' => [ |
|
473 | + 'edit_category_help_tab' => [ |
|
474 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
475 | + 'filename' => 'events_edit_category', |
|
476 | + ], |
|
477 | + ], |
|
478 | + 'metaboxes' => ['_publish_post_box'], |
|
479 | + 'require_nonce' => false, |
|
480 | + ], |
|
481 | + 'category_list' => [ |
|
482 | + 'nav' => [ |
|
483 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
484 | + 'order' => 20, |
|
485 | + ], |
|
486 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
487 | + 'help_tabs' => [ |
|
488 | + 'events_categories_help_tab' => [ |
|
489 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
490 | + 'filename' => 'events_categories', |
|
491 | + ], |
|
492 | + 'events_categories_table_column_headings_help_tab' => [ |
|
493 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
494 | + 'filename' => 'events_categories_table_column_headings', |
|
495 | + ], |
|
496 | + 'events_categories_view_help_tab' => [ |
|
497 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
498 | + 'filename' => 'events_categories_views', |
|
499 | + ], |
|
500 | + 'events_categories_other_help_tab' => [ |
|
501 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
502 | + 'filename' => 'events_categories_other', |
|
503 | + ], |
|
504 | + ], |
|
505 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
506 | + 'require_nonce' => false, |
|
507 | + ], |
|
508 | + 'preview_deletion' => [ |
|
509 | + 'nav' => [ |
|
510 | + 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
511 | + 'order' => 15, |
|
512 | + 'persistent' => false, |
|
513 | + 'url' => '', |
|
514 | + ], |
|
515 | + 'require_nonce' => false, |
|
516 | + ], |
|
517 | + ]; |
|
518 | + } |
|
519 | + |
|
520 | + |
|
521 | + /** |
|
522 | + * Used to register any global screen options if necessary for every route in this admin page group. |
|
523 | + */ |
|
524 | + protected function _add_screen_options() |
|
525 | + { |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * Implementing the screen options for the 'default' route. |
|
531 | + */ |
|
532 | + protected function _add_screen_options_default() |
|
533 | + { |
|
534 | + $this->_per_page_screen_option(); |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + /** |
|
539 | + * Implementing screen options for the category list route. |
|
540 | + */ |
|
541 | + protected function _add_screen_options_category_list() |
|
542 | + { |
|
543 | + $page_title = $this->_admin_page_title; |
|
544 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
545 | + $this->_per_page_screen_option(); |
|
546 | + $this->_admin_page_title = $page_title; |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * Used to register any global feature pointers for the admin page group. |
|
552 | + */ |
|
553 | + protected function _add_feature_pointers() |
|
554 | + { |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
560 | + */ |
|
561 | + public function load_scripts_styles() |
|
562 | + { |
|
563 | + wp_register_style( |
|
564 | + 'events-admin-css', |
|
565 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
566 | + [], |
|
567 | + EVENT_ESPRESSO_VERSION |
|
568 | + ); |
|
569 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION); |
|
570 | + wp_enqueue_style('events-admin-css'); |
|
571 | + wp_enqueue_style('ee-cat-admin'); |
|
572 | + // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
573 | + // registers for all views |
|
574 | + // scripts |
|
575 | + wp_register_script( |
|
576 | + 'event_editor_js', |
|
577 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
578 | + ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
579 | + EVENT_ESPRESSO_VERSION, |
|
580 | + true |
|
581 | + ); |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * Enqueuing scripts and styles specific to this view |
|
587 | + */ |
|
588 | + public function load_scripts_styles_create_new() |
|
589 | + { |
|
590 | + $this->load_scripts_styles_edit(); |
|
591 | + } |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * Enqueuing scripts and styles specific to this view |
|
596 | + */ |
|
597 | + public function load_scripts_styles_edit() |
|
598 | + { |
|
599 | + // styles |
|
600 | + wp_enqueue_style('espresso-ui-theme'); |
|
601 | + wp_register_style( |
|
602 | + 'event-editor-css', |
|
603 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
604 | + ['ee-admin-css'], |
|
605 | + EVENT_ESPRESSO_VERSION |
|
606 | + ); |
|
607 | + wp_enqueue_style('event-editor-css'); |
|
608 | + // scripts |
|
609 | + wp_register_script( |
|
610 | + 'event-datetime-metabox', |
|
611 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
612 | + ['event_editor_js', 'ee-datepicker'], |
|
613 | + EVENT_ESPRESSO_VERSION |
|
614 | + ); |
|
615 | + wp_enqueue_script('event-datetime-metabox'); |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * Populating the _views property for the category list table view. |
|
621 | + */ |
|
622 | + protected function _set_list_table_views_category_list() |
|
623 | + { |
|
624 | + $this->_views = [ |
|
625 | + 'all' => [ |
|
626 | + 'slug' => 'all', |
|
627 | + 'label' => esc_html__('All', 'event_espresso'), |
|
628 | + 'count' => 0, |
|
629 | + 'bulk_action' => [ |
|
630 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
631 | + ], |
|
632 | + ], |
|
633 | + ]; |
|
634 | + } |
|
635 | + |
|
636 | + |
|
637 | + /** |
|
638 | + * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
639 | + */ |
|
640 | + public function admin_init() |
|
641 | + { |
|
642 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
643 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
644 | + 'event_espresso' |
|
645 | + ); |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
651 | + * group. |
|
652 | + */ |
|
653 | + public function admin_notices() |
|
654 | + { |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
660 | + * this admin page group. |
|
661 | + */ |
|
662 | + public function admin_footer_scripts() |
|
663 | + { |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + /** |
|
668 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
669 | + * warning (via EE_Error::add_error()); |
|
670 | + * |
|
671 | + * @param EE_Event $event Event object |
|
672 | + * @param string $req_type |
|
673 | + * @return void |
|
674 | + * @throws EE_Error |
|
675 | + * @throws ReflectionException |
|
676 | + */ |
|
677 | + public function verify_event_edit($event = null, $req_type = '') |
|
678 | + { |
|
679 | + // don't need to do this when processing |
|
680 | + if (! empty($req_type)) { |
|
681 | + return; |
|
682 | + } |
|
683 | + // no event? |
|
684 | + if (empty($event)) { |
|
685 | + // set event |
|
686 | + $event = $this->_cpt_model_obj; |
|
687 | + } |
|
688 | + // STILL no event? |
|
689 | + if (! $event instanceof EE_Event) { |
|
690 | + return; |
|
691 | + } |
|
692 | + $orig_status = $event->status(); |
|
693 | + // first check if event is active. |
|
694 | + if ( |
|
695 | + $orig_status === EEM_Event::cancelled |
|
696 | + || $orig_status === EEM_Event::postponed |
|
697 | + || $event->is_expired() |
|
698 | + || $event->is_inactive() |
|
699 | + ) { |
|
700 | + return; |
|
701 | + } |
|
702 | + // made it here so it IS active... next check that any of the tickets are sold. |
|
703 | + if ($event->is_sold_out(true)) { |
|
704 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
705 | + EE_Error::add_attention( |
|
706 | + sprintf( |
|
707 | + esc_html__( |
|
708 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
709 | + 'event_espresso' |
|
710 | + ), |
|
711 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
712 | + ) |
|
713 | + ); |
|
714 | + } |
|
715 | + return; |
|
716 | + } elseif ($orig_status === EEM_Event::sold_out) { |
|
717 | + EE_Error::add_attention( |
|
718 | + sprintf( |
|
719 | + esc_html__( |
|
720 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
721 | + 'event_espresso' |
|
722 | + ), |
|
723 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
724 | + ) |
|
725 | + ); |
|
726 | + } |
|
727 | + // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
728 | + if (! $event->tickets_on_sale()) { |
|
729 | + return; |
|
730 | + } |
|
731 | + // made it here so show warning |
|
732 | + $this->_edit_event_warning(); |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
738 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
739 | + * |
|
740 | + * @access protected |
|
741 | + * @return void |
|
742 | + */ |
|
743 | + protected function _edit_event_warning() |
|
744 | + { |
|
745 | + // we don't want to add warnings during these requests |
|
746 | + if ($this->request->getRequestParam('action') === 'editpost') { |
|
747 | + return; |
|
748 | + } |
|
749 | + EE_Error::add_attention( |
|
750 | + sprintf( |
|
751 | + esc_html__( |
|
752 | + 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
753 | + 'event_espresso' |
|
754 | + ), |
|
755 | + '<a class="espresso-help-tab-lnk">', |
|
756 | + '</a>' |
|
757 | + ) |
|
758 | + ); |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + /** |
|
763 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
764 | + * Otherwise, do the normal logic |
|
765 | + * |
|
766 | + * @return void |
|
767 | + * @throws EE_Error |
|
768 | + */ |
|
769 | + protected function _create_new_cpt_item() |
|
770 | + { |
|
771 | + $has_timezone_string = get_option('timezone_string'); |
|
772 | + // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
773 | + if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
774 | + EE_Error::add_attention( |
|
775 | + sprintf( |
|
776 | + esc_html__( |
|
777 | + 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
778 | + 'event_espresso' |
|
779 | + ), |
|
780 | + '<br>', |
|
781 | + '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
782 | + . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
783 | + . '</select>', |
|
784 | + '<button class="button button-secondary timezone-submit">', |
|
785 | + '</button><span class="spinner"></span>' |
|
786 | + ), |
|
787 | + __FILE__, |
|
788 | + __FUNCTION__, |
|
789 | + __LINE__ |
|
790 | + ); |
|
791 | + } |
|
792 | + parent::_create_new_cpt_item(); |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * Sets the _views property for the default route in this admin page group. |
|
798 | + */ |
|
799 | + protected function _set_list_table_views_default() |
|
800 | + { |
|
801 | + $this->_views = [ |
|
802 | + 'all' => [ |
|
803 | + 'slug' => 'all', |
|
804 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
805 | + 'count' => 0, |
|
806 | + 'bulk_action' => [ |
|
807 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
808 | + ], |
|
809 | + ], |
|
810 | + 'draft' => [ |
|
811 | + 'slug' => 'draft', |
|
812 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
813 | + 'count' => 0, |
|
814 | + 'bulk_action' => [ |
|
815 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
816 | + ], |
|
817 | + ], |
|
818 | + ]; |
|
819 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
820 | + $this->_views['trash'] = [ |
|
821 | + 'slug' => 'trash', |
|
822 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
823 | + 'count' => 0, |
|
824 | + 'bulk_action' => [ |
|
825 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
826 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
827 | + ], |
|
828 | + ]; |
|
829 | + } |
|
830 | + } |
|
831 | + |
|
832 | + |
|
833 | + /** |
|
834 | + * Provides the legend item array for the default list table view. |
|
835 | + * |
|
836 | + * @return array |
|
837 | + * @throws EE_Error |
|
838 | + * @throws EE_Error |
|
839 | + */ |
|
840 | + protected function _event_legend_items() |
|
841 | + { |
|
842 | + $items = [ |
|
843 | + 'view_details' => [ |
|
844 | + 'class' => 'dashicons dashicons-search', |
|
845 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
846 | + ], |
|
847 | + 'edit_event' => [ |
|
848 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
849 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
850 | + ], |
|
851 | + 'view_attendees' => [ |
|
852 | + 'class' => 'dashicons dashicons-groups', |
|
853 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
854 | + ], |
|
855 | + ]; |
|
856 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
857 | + $statuses = [ |
|
858 | + 'sold_out_status' => [ |
|
859 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
860 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
861 | + ], |
|
862 | + 'active_status' => [ |
|
863 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
864 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
865 | + ], |
|
866 | + 'upcoming_status' => [ |
|
867 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
868 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
869 | + ], |
|
870 | + 'postponed_status' => [ |
|
871 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
872 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
873 | + ], |
|
874 | + 'cancelled_status' => [ |
|
875 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
876 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
877 | + ], |
|
878 | + 'expired_status' => [ |
|
879 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
880 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
881 | + ], |
|
882 | + 'inactive_status' => [ |
|
883 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
884 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
885 | + ], |
|
886 | + ]; |
|
887 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
888 | + return array_merge($items, $statuses); |
|
889 | + } |
|
890 | + |
|
891 | + |
|
892 | + /** |
|
893 | + * @return EEM_Event |
|
894 | + * @throws EE_Error |
|
895 | + * @throws ReflectionException |
|
896 | + */ |
|
897 | + private function _event_model() |
|
898 | + { |
|
899 | + if (! $this->_event_model instanceof EEM_Event) { |
|
900 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
901 | + } |
|
902 | + return $this->_event_model; |
|
903 | + } |
|
904 | + |
|
905 | + |
|
906 | + /** |
|
907 | + * Adds extra buttons to the WP CPT permalink field row. |
|
908 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
909 | + * |
|
910 | + * @param string $return the current html |
|
911 | + * @param int $id the post id for the page |
|
912 | + * @param string $new_title What the title is |
|
913 | + * @param string $new_slug what the slug is |
|
914 | + * @return string The new html string for the permalink area |
|
915 | + */ |
|
916 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
917 | + { |
|
918 | + // make sure this is only when editing |
|
919 | + if (! empty($id)) { |
|
920 | + $post = get_post($id); |
|
921 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
922 | + . esc_html__('Shortcode', 'event_espresso') |
|
923 | + . '</a> '; |
|
924 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
925 | + . $post->ID |
|
926 | + . ']">'; |
|
927 | + } |
|
928 | + return $return; |
|
929 | + } |
|
930 | + |
|
931 | + |
|
932 | + /** |
|
933 | + * _events_overview_list_table |
|
934 | + * This contains the logic for showing the events_overview list |
|
935 | + * |
|
936 | + * @access protected |
|
937 | + * @return void |
|
938 | + * @throws EE_Error |
|
939 | + */ |
|
940 | + protected function _events_overview_list_table() |
|
941 | + { |
|
942 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
943 | + $this->_template_args['after_list_table'] = |
|
944 | + ! empty($this->_template_args['after_list_table']) |
|
945 | + ? (array) $this->_template_args['after_list_table'] |
|
946 | + : []; |
|
947 | + $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
948 | + . EEH_Template::get_button_or_link( |
|
949 | + get_post_type_archive_link('espresso_events'), |
|
950 | + esc_html__("View Event Archive Page", "event_espresso"), |
|
951 | + 'button' |
|
952 | + ); |
|
953 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend( |
|
954 | + $this->_event_legend_items() |
|
955 | + ); |
|
956 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
957 | + 'create_new', |
|
958 | + 'add', |
|
959 | + [], |
|
960 | + 'add-new-h2' |
|
961 | + ); |
|
962 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
963 | + } |
|
964 | + |
|
965 | + |
|
966 | + /** |
|
967 | + * this allows for extra misc actions in the default WP publish box |
|
968 | + * |
|
969 | + * @return void |
|
970 | + * @throws EE_Error |
|
971 | + * @throws ReflectionException |
|
972 | + */ |
|
973 | + public function extra_misc_actions_publish_box() |
|
974 | + { |
|
975 | + $this->_generate_publish_box_extra_content(); |
|
976 | + } |
|
977 | + |
|
978 | + |
|
979 | + /** |
|
980 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
981 | + * saved. |
|
982 | + * Typically you would use this to save any additional data. |
|
983 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
984 | + * ALSO very important. When a post transitions from scheduled to published, |
|
985 | + * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
986 | + * other meta saves. So MAKE sure that you handle this accordingly. |
|
987 | + * |
|
988 | + * @access protected |
|
989 | + * @abstract |
|
990 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
991 | + * @param object $post The post object of the cpt that was saved. |
|
992 | + * @return void |
|
993 | + * @throws EE_Error |
|
994 | + * @throws ReflectionException |
|
995 | + */ |
|
996 | + protected function _insert_update_cpt_item($post_id, $post) |
|
997 | + { |
|
998 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
999 | + // get out we're not processing an event save. |
|
1000 | + return; |
|
1001 | + } |
|
1002 | + |
|
1003 | + $event_values = [ |
|
1004 | + 'EVT_display_desc' => $this->request->getRequestParam('display_desc', false, 'bool'), |
|
1005 | + 'EVT_display_ticket_selector' => $this->request->getRequestParam( |
|
1006 | + 'display_ticket_selector', |
|
1007 | + false, |
|
1008 | + 'bool' |
|
1009 | + ), |
|
1010 | + 'EVT_additional_limit' => min( |
|
1011 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
1012 | + $this->request->getRequestParam('additional_limit', null, 'int') |
|
1013 | + ), |
|
1014 | + 'EVT_default_registration_status' => $this->request->getRequestParam( |
|
1015 | + 'EVT_default_registration_status', |
|
1016 | + EE_Registry::instance()->CFG->registration->default_STS_ID |
|
1017 | + ), |
|
1018 | + |
|
1019 | + 'EVT_member_only' => $this->request->getRequestParam('member_only', false, 'bool'), |
|
1020 | + 'EVT_allow_overflow' => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'), |
|
1021 | + 'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'), |
|
1022 | + 'EVT_external_URL' => $this->request->getRequestParam('externalURL'), |
|
1023 | + 'EVT_phone' => $this->request->getRequestParam('event_phone'), |
|
1024 | + ]; |
|
1025 | + // update event |
|
1026 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
1027 | + // get event_object for other metaboxes... |
|
1028 | + // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. |
|
1029 | + // i have to setup where conditions to override the filters in the model |
|
1030 | + // that filter out autodraft and inherit statuses so we GET the inherit id! |
|
1031 | + $event = $this->_event_model()->get_one( |
|
1032 | + [ |
|
1033 | + [ |
|
1034 | + $this->_event_model()->primary_key_name() => $post_id, |
|
1035 | + 'OR' => [ |
|
1036 | + 'status' => $post->post_status, |
|
1037 | + // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
1038 | + // but the returned object here has a status of "publish", so use the original post status as well |
|
1039 | + 'status*1' => $this->request->getRequestParam('original_post_status'), |
|
1040 | + ], |
|
1041 | + ], |
|
1042 | + ] |
|
1043 | + ); |
|
1044 | + // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
1045 | + $event_update_callbacks = apply_filters( |
|
1046 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
1047 | + [ |
|
1048 | + [$this, '_default_venue_update'], |
|
1049 | + [$this, '_default_tickets_update'], |
|
1050 | + ] |
|
1051 | + ); |
|
1052 | + $att_success = true; |
|
1053 | + foreach ($event_update_callbacks as $e_callback) { |
|
1054 | + $_success = is_callable($e_callback) |
|
1055 | + ? call_user_func($e_callback, $event, $this->request->requestParams()) |
|
1056 | + : false; |
|
1057 | + // if ANY of these updates fail then we want the appropriate global error message |
|
1058 | + $att_success = ! $att_success ? $att_success : $_success; |
|
1059 | + } |
|
1060 | + // any errors? |
|
1061 | + if ($success && false === $att_success) { |
|
1062 | + EE_Error::add_error( |
|
1063 | + esc_html__( |
|
1064 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
1065 | + 'event_espresso' |
|
1066 | + ), |
|
1067 | + __FILE__, |
|
1068 | + __FUNCTION__, |
|
1069 | + __LINE__ |
|
1070 | + ); |
|
1071 | + } elseif ($success === false) { |
|
1072 | + EE_Error::add_error( |
|
1073 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
1074 | + __FILE__, |
|
1075 | + __FUNCTION__, |
|
1076 | + __LINE__ |
|
1077 | + ); |
|
1078 | + } |
|
1079 | + } |
|
1080 | + |
|
1081 | + |
|
1082 | + /** |
|
1083 | + * @param int $post_id |
|
1084 | + * @param int $revision_id |
|
1085 | + * @throws EE_Error |
|
1086 | + * @throws EE_Error |
|
1087 | + * @throws ReflectionException |
|
1088 | + * @see parent::restore_item() |
|
1089 | + */ |
|
1090 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
1091 | + { |
|
1092 | + // copy existing event meta to new post |
|
1093 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
1094 | + if ($post_evt instanceof EE_Event) { |
|
1095 | + // meta revision restore |
|
1096 | + $post_evt->restore_revision($revision_id); |
|
1097 | + // related objs restore |
|
1098 | + $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
1099 | + } |
|
1100 | + } |
|
1101 | + |
|
1102 | + |
|
1103 | + /** |
|
1104 | + * Attach the venue to the Event |
|
1105 | + * |
|
1106 | + * @param EE_Event $event Event Object to add the venue to |
|
1107 | + * @param array $data The request data from the form |
|
1108 | + * @return bool Success or fail. |
|
1109 | + * @throws EE_Error |
|
1110 | + * @throws ReflectionException |
|
1111 | + */ |
|
1112 | + protected function _default_venue_update(EE_Event $event, $data) |
|
1113 | + { |
|
1114 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
1115 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
1116 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
1117 | + // very important. If we don't have a venue name... |
|
1118 | + // then we'll get out because not necessary to create empty venue |
|
1119 | + if (empty($data['venue_title'])) { |
|
1120 | + return false; |
|
1121 | + } |
|
1122 | + $venue_array = [ |
|
1123 | + 'VNU_wp_user' => $event->get('EVT_wp_user'), |
|
1124 | + 'VNU_name' => $data['venue_title'], |
|
1125 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
1126 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
1127 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) |
|
1128 | + ? $data['venue_short_description'] |
|
1129 | + : null, |
|
1130 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
1131 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
1132 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
1133 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
1134 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
1135 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
1136 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
1137 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
1138 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
1139 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
1140 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
1141 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
1142 | + 'status' => 'publish', |
|
1143 | + ]; |
|
1144 | + // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
1145 | + if (! empty($venue_id)) { |
|
1146 | + $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
1147 | + $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
1148 | + // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
1149 | + $event->_add_relation_to($venue_id, 'Venue'); |
|
1150 | + return $rows_affected > 0; |
|
1151 | + } |
|
1152 | + // we insert the venue |
|
1153 | + $venue_id = $venue_model->insert($venue_array); |
|
1154 | + $event->_add_relation_to($venue_id, 'Venue'); |
|
1155 | + return ! empty($venue_id); |
|
1156 | + // when we have the ancestor come in it's already been handled by the revision save. |
|
1157 | + } |
|
1158 | + |
|
1159 | + |
|
1160 | + /** |
|
1161 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
1162 | + * |
|
1163 | + * @param EE_Event $event The Event object we're attaching data to |
|
1164 | + * @param array $data The request data from the form |
|
1165 | + * @return array |
|
1166 | + * @throws EE_Error |
|
1167 | + * @throws ReflectionException |
|
1168 | + * @throws Exception |
|
1169 | + */ |
|
1170 | + protected function _default_tickets_update(EE_Event $event, $data) |
|
1171 | + { |
|
1172 | + $datetime = null; |
|
1173 | + $saved_tickets = []; |
|
1174 | + $event_timezone = $event->get_timezone(); |
|
1175 | + $date_formats = ['Y-m-d', 'h:i a']; |
|
1176 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
1177 | + // trim all values to ensure any excess whitespace is removed. |
|
1178 | + $datetime_data = array_map('trim', $datetime_data); |
|
1179 | + $datetime_data['DTT_EVT_end'] = |
|
1180 | + isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end']) |
|
1181 | + ? $datetime_data['DTT_EVT_end'] |
|
1182 | + : $datetime_data['DTT_EVT_start']; |
|
1183 | + $datetime_values = [ |
|
1184 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null, |
|
1185 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
1186 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
1187 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'], |
|
1188 | + 'DTT_order' => $row, |
|
1189 | + ]; |
|
1190 | + // if we have an id then let's get existing object first and then set the new values. |
|
1191 | + // Otherwise we instantiate a new object for save. |
|
1192 | + if (! empty($datetime_data['DTT_ID'])) { |
|
1193 | + $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']); |
|
1194 | + if (! $datetime instanceof EE_Datetime) { |
|
1195 | + throw new RuntimeException( |
|
1196 | + sprintf( |
|
1197 | + esc_html__( |
|
1198 | + 'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d', |
|
1199 | + 'event_espresso' |
|
1200 | + ), |
|
1201 | + $datetime_data['DTT_ID'] |
|
1202 | + ) |
|
1203 | + ); |
|
1204 | + } |
|
1205 | + $datetime->set_date_format($date_formats[0]); |
|
1206 | + $datetime->set_time_format($date_formats[1]); |
|
1207 | + foreach ($datetime_values as $field => $value) { |
|
1208 | + $datetime->set($field, $value); |
|
1209 | + } |
|
1210 | + } else { |
|
1211 | + $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats); |
|
1212 | + } |
|
1213 | + if (! $datetime instanceof EE_Datetime) { |
|
1214 | + throw new RuntimeException( |
|
1215 | + sprintf( |
|
1216 | + esc_html__( |
|
1217 | + 'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s', |
|
1218 | + 'event_espresso' |
|
1219 | + ), |
|
1220 | + print_r($datetime_values, true) |
|
1221 | + ) |
|
1222 | + ); |
|
1223 | + } |
|
1224 | + // before going any further make sure our dates are setup correctly |
|
1225 | + // so that the end date is always equal or greater than the start date. |
|
1226 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
1227 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
1228 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
1229 | + } |
|
1230 | + $datetime->save(); |
|
1231 | + $event->_add_relation_to($datetime, 'Datetime'); |
|
1232 | + } |
|
1233 | + // no datetimes get deleted so we don't do any of that logic here. |
|
1234 | + // update tickets next |
|
1235 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
1236 | + |
|
1237 | + // set up some default start and end dates in case those are not present in the incoming data |
|
1238 | + $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
1239 | + $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]); |
|
1240 | + // use the start date of the first datetime for the end date |
|
1241 | + $first_datetime = $event->first_datetime(); |
|
1242 | + $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]); |
|
1243 | + |
|
1244 | + // now process the incoming data |
|
1245 | + foreach ($data['edit_tickets'] as $row => $ticket_data) { |
|
1246 | + $update_prices = false; |
|
1247 | + $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
1248 | + ? $data['edit_prices'][ $row ][1]['PRC_amount'] |
|
1249 | + : 0; |
|
1250 | + // trim inputs to ensure any excess whitespace is removed. |
|
1251 | + $ticket_data = array_map('trim', $ticket_data); |
|
1252 | + $ticket_values = [ |
|
1253 | + 'TKT_ID' => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null, |
|
1254 | + 'TTM_ID' => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0, |
|
1255 | + 'TKT_name' => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '', |
|
1256 | + 'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '', |
|
1257 | + 'TKT_start_date' => ! empty($ticket_data['TKT_start_date']) |
|
1258 | + ? $ticket_data['TKT_start_date'] |
|
1259 | + : $default_start_date, |
|
1260 | + 'TKT_end_date' => ! empty($ticket_data['TKT_end_date']) |
|
1261 | + ? $ticket_data['TKT_end_date'] |
|
1262 | + : $default_end_date, |
|
1263 | + 'TKT_qty' => ! empty($ticket_data['TKT_qty']) |
|
1264 | + || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0) |
|
1265 | + ? $ticket_data['TKT_qty'] |
|
1266 | + : EE_INF, |
|
1267 | + 'TKT_uses' => ! empty($ticket_data['TKT_uses']) |
|
1268 | + || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0) |
|
1269 | + ? $ticket_data['TKT_uses'] |
|
1270 | + : EE_INF, |
|
1271 | + 'TKT_min' => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0, |
|
1272 | + 'TKT_max' => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF, |
|
1273 | + 'TKT_order' => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row, |
|
1274 | + 'TKT_price' => $ticket_price, |
|
1275 | + 'TKT_row' => $row, |
|
1276 | + ]; |
|
1277 | + // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly, |
|
1278 | + // which means in turn that the prices will become new prices as well. |
|
1279 | + if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) { |
|
1280 | + $ticket_values['TKT_ID'] = 0; |
|
1281 | + $ticket_values['TKT_is_default'] = 0; |
|
1282 | + $update_prices = true; |
|
1283 | + } |
|
1284 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
1285 | + // we actually do our saves ahead of adding any relations because its entirely possible that this |
|
1286 | + // ticket didn't get removed or added to any datetime in the session but DID have it's items modified. |
|
1287 | + // keep in mind that if the ticket has been sold (and we have changed pricing information), |
|
1288 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
1289 | + if (! empty($ticket_data['TKT_ID'])) { |
|
1290 | + $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']); |
|
1291 | + if (! $existing_ticket instanceof EE_Ticket) { |
|
1292 | + throw new RuntimeException( |
|
1293 | + sprintf( |
|
1294 | + esc_html__( |
|
1295 | + 'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d', |
|
1296 | + 'event_espresso' |
|
1297 | + ), |
|
1298 | + $ticket_data['TKT_ID'] |
|
1299 | + ) |
|
1300 | + ); |
|
1301 | + } |
|
1302 | + $ticket_sold = $existing_ticket->count_related( |
|
1303 | + 'Registration', |
|
1304 | + [ |
|
1305 | + [ |
|
1306 | + 'STS_ID' => [ |
|
1307 | + 'NOT IN', |
|
1308 | + [EEM_Registration::status_id_incomplete], |
|
1309 | + ], |
|
1310 | + ], |
|
1311 | + ] |
|
1312 | + ) > 0; |
|
1313 | + // let's just check the total price for the existing ticket and determine if it matches the new total price. |
|
1314 | + // if they are different then we create a new ticket (if $ticket_sold) |
|
1315 | + // if they aren't different then we go ahead and modify existing ticket. |
|
1316 | + $create_new_ticket = $ticket_sold |
|
1317 | + && $ticket_price !== $existing_ticket->price() |
|
1318 | + && ! $existing_ticket->deleted(); |
|
1319 | + $existing_ticket->set_date_format($date_formats[0]); |
|
1320 | + $existing_ticket->set_time_format($date_formats[1]); |
|
1321 | + // set new values |
|
1322 | + foreach ($ticket_values as $field => $value) { |
|
1323 | + if ($field == 'TKT_qty') { |
|
1324 | + $existing_ticket->set_qty($value); |
|
1325 | + } elseif ($field == 'TKT_price') { |
|
1326 | + $existing_ticket->set('TKT_price', $ticket_price); |
|
1327 | + } else { |
|
1328 | + $existing_ticket->set($field, $value); |
|
1329 | + } |
|
1330 | + } |
|
1331 | + $ticket = $existing_ticket; |
|
1332 | + // if $create_new_ticket is false then we can safely update the existing ticket. |
|
1333 | + // Otherwise we have to create a new ticket. |
|
1334 | + if ($create_new_ticket) { |
|
1335 | + // archive the old ticket first |
|
1336 | + $existing_ticket->set('TKT_deleted', 1); |
|
1337 | + $existing_ticket->save(); |
|
1338 | + // make sure this ticket is still recorded in our $saved_tickets |
|
1339 | + // so we don't run it through the regular trash routine. |
|
1340 | + $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket; |
|
1341 | + // create new ticket that's a copy of the existing except, |
|
1342 | + // (a new id of course and not archived) AND has the new TKT_price associated with it. |
|
1343 | + $new_ticket = clone $existing_ticket; |
|
1344 | + $new_ticket->set('TKT_ID', 0); |
|
1345 | + $new_ticket->set('TKT_deleted', 0); |
|
1346 | + $new_ticket->set('TKT_sold', 0); |
|
1347 | + // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
1348 | + $update_prices = true; |
|
1349 | + $ticket = $new_ticket; |
|
1350 | + } |
|
1351 | + } else { |
|
1352 | + // no TKT_id so a new ticket |
|
1353 | + $ticket_values['TKT_price'] = $ticket_price; |
|
1354 | + $ticket = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats); |
|
1355 | + $update_prices = true; |
|
1356 | + } |
|
1357 | + if (! $ticket instanceof EE_Ticket) { |
|
1358 | + throw new RuntimeException( |
|
1359 | + sprintf( |
|
1360 | + esc_html__( |
|
1361 | + 'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s', |
|
1362 | + 'event_espresso' |
|
1363 | + ), |
|
1364 | + print_r($ticket_values, true) |
|
1365 | + ) |
|
1366 | + ); |
|
1367 | + } |
|
1368 | + // cap ticket qty by datetime reg limits |
|
1369 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
1370 | + // update ticket. |
|
1371 | + $ticket->save(); |
|
1372 | + // before going any further make sure our dates are setup correctly |
|
1373 | + // so that the end date is always equal or greater than the start date. |
|
1374 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
1375 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
1376 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
1377 | + $ticket->save(); |
|
1378 | + } |
|
1379 | + // initially let's add the ticket to the datetime |
|
1380 | + $datetime->_add_relation_to($ticket, 'Ticket'); |
|
1381 | + $saved_tickets[ $ticket->ID() ] = $ticket; |
|
1382 | + // add prices to ticket |
|
1383 | + $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices); |
|
1384 | + } |
|
1385 | + // however now we need to handle permanently deleting tickets via the ui. |
|
1386 | + // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
|
1387 | + // However, it does allow for deleting tickets that have no tickets sold, |
|
1388 | + // in which case we want to get rid of permanently because there is no need to save in db. |
|
1389 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets; |
|
1390 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
1391 | + foreach ($tickets_removed as $id) { |
|
1392 | + $id = absint($id); |
|
1393 | + // get the ticket for this id |
|
1394 | + $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
|
1395 | + if (! $ticket_to_remove instanceof EE_Ticket) { |
|
1396 | + continue; |
|
1397 | + } |
|
1398 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
1399 | + // (remember this process can ONLY kick off if there are NO tickets sold) |
|
1400 | + $related_datetimes = $ticket_to_remove->get_many_related('Datetime'); |
|
1401 | + foreach ($related_datetimes as $related_datetime) { |
|
1402 | + $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime'); |
|
1403 | + } |
|
1404 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
1405 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
1406 | + $ticket_to_remove->delete_related_permanently('Price'); |
|
1407 | + // finally let's delete this ticket |
|
1408 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
1409 | + $ticket_to_remove->delete_permanently(); |
|
1410 | + } |
|
1411 | + return [$datetime, $saved_tickets]; |
|
1412 | + } |
|
1413 | + |
|
1414 | + |
|
1415 | + /** |
|
1416 | + * This attaches a list of given prices to a ticket. |
|
1417 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
1418 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
1419 | + * price info and prices are automatically "archived" via the ticket. |
|
1420 | + * |
|
1421 | + * @access private |
|
1422 | + * @param array $prices_data Array of prices from the form. |
|
1423 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
1424 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
1425 | + * @return void |
|
1426 | + * @throws EE_Error |
|
1427 | + * @throws ReflectionException |
|
1428 | + */ |
|
1429 | + private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false) |
|
1430 | + { |
|
1431 | + $timezone = $ticket->get_timezone(); |
|
1432 | + foreach ($prices_data as $row => $price_data) { |
|
1433 | + $price_values = [ |
|
1434 | + 'PRC_ID' => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null, |
|
1435 | + 'PRT_ID' => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null, |
|
1436 | + 'PRC_amount' => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0, |
|
1437 | + 'PRC_name' => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '', |
|
1438 | + 'PRC_desc' => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '', |
|
1439 | + 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
1440 | + 'PRC_order' => $row, |
|
1441 | + ]; |
|
1442 | + if ($new_prices || empty($price_values['PRC_ID'])) { |
|
1443 | + $price_values['PRC_ID'] = 0; |
|
1444 | + $price = EE_Price::new_instance($price_values, $timezone); |
|
1445 | + } else { |
|
1446 | + $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']); |
|
1447 | + // update this price with new values |
|
1448 | + foreach ($price_values as $field => $new_price) { |
|
1449 | + $price->set($field, $new_price); |
|
1450 | + } |
|
1451 | + } |
|
1452 | + if (! $price instanceof EE_Price) { |
|
1453 | + throw new RuntimeException( |
|
1454 | + sprintf( |
|
1455 | + esc_html__( |
|
1456 | + 'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s', |
|
1457 | + 'event_espresso' |
|
1458 | + ), |
|
1459 | + print_r($price_values, true) |
|
1460 | + ) |
|
1461 | + ); |
|
1462 | + } |
|
1463 | + $price->save(); |
|
1464 | + $ticket->_add_relation_to($price, 'Price'); |
|
1465 | + } |
|
1466 | + } |
|
1467 | + |
|
1468 | + |
|
1469 | + /** |
|
1470 | + * Add in our autosave ajax handlers |
|
1471 | + * |
|
1472 | + */ |
|
1473 | + protected function _ee_autosave_create_new() |
|
1474 | + { |
|
1475 | + } |
|
1476 | + |
|
1477 | + |
|
1478 | + /** |
|
1479 | + * More autosave handlers. |
|
1480 | + */ |
|
1481 | + protected function _ee_autosave_edit() |
|
1482 | + { |
|
1483 | + // TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
1484 | + } |
|
1485 | + |
|
1486 | + |
|
1487 | + /** |
|
1488 | + * @throws EE_Error |
|
1489 | + * @throws ReflectionException |
|
1490 | + */ |
|
1491 | + private function _generate_publish_box_extra_content() |
|
1492 | + { |
|
1493 | + // load formatter helper |
|
1494 | + // args for getting related registrations |
|
1495 | + $approved_query_args = [ |
|
1496 | + [ |
|
1497 | + 'REG_deleted' => 0, |
|
1498 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
1499 | + ], |
|
1500 | + ]; |
|
1501 | + $not_approved_query_args = [ |
|
1502 | + [ |
|
1503 | + 'REG_deleted' => 0, |
|
1504 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
1505 | + ], |
|
1506 | + ]; |
|
1507 | + $pending_payment_query_args = [ |
|
1508 | + [ |
|
1509 | + 'REG_deleted' => 0, |
|
1510 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
1511 | + ], |
|
1512 | + ]; |
|
1513 | + // publish box |
|
1514 | + $publish_box_extra_args = [ |
|
1515 | + 'view_approved_reg_url' => add_query_arg( |
|
1516 | + [ |
|
1517 | + 'action' => 'default', |
|
1518 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1519 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1520 | + ], |
|
1521 | + REG_ADMIN_URL |
|
1522 | + ), |
|
1523 | + 'view_not_approved_reg_url' => add_query_arg( |
|
1524 | + [ |
|
1525 | + 'action' => 'default', |
|
1526 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1527 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1528 | + ], |
|
1529 | + REG_ADMIN_URL |
|
1530 | + ), |
|
1531 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
1532 | + [ |
|
1533 | + 'action' => 'default', |
|
1534 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1535 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1536 | + ], |
|
1537 | + REG_ADMIN_URL |
|
1538 | + ), |
|
1539 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
1540 | + 'Registration', |
|
1541 | + $approved_query_args |
|
1542 | + ), |
|
1543 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
1544 | + 'Registration', |
|
1545 | + $not_approved_query_args |
|
1546 | + ), |
|
1547 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
1548 | + 'Registration', |
|
1549 | + $pending_payment_query_args |
|
1550 | + ), |
|
1551 | + 'misc_pub_section_class' => apply_filters( |
|
1552 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
1553 | + 'misc-pub-section' |
|
1554 | + ), |
|
1555 | + ]; |
|
1556 | + ob_start(); |
|
1557 | + do_action( |
|
1558 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
1559 | + $this->_cpt_model_obj |
|
1560 | + ); |
|
1561 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
1562 | + // load template |
|
1563 | + EEH_Template::display_template( |
|
1564 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
1565 | + $publish_box_extra_args |
|
1566 | + ); |
|
1567 | + } |
|
1568 | + |
|
1569 | + |
|
1570 | + /** |
|
1571 | + * @return EE_Event |
|
1572 | + */ |
|
1573 | + public function get_event_object() |
|
1574 | + { |
|
1575 | + return $this->_cpt_model_obj; |
|
1576 | + } |
|
1577 | + |
|
1578 | + |
|
1579 | + |
|
1580 | + |
|
1581 | + /** METABOXES * */ |
|
1582 | + /** |
|
1583 | + * _register_event_editor_meta_boxes |
|
1584 | + * add all metaboxes related to the event_editor |
|
1585 | + * |
|
1586 | + * @return void |
|
1587 | + * @throws EE_Error |
|
1588 | + * @throws ReflectionException |
|
1589 | + */ |
|
1590 | + protected function _register_event_editor_meta_boxes() |
|
1591 | + { |
|
1592 | + $this->verify_cpt_object(); |
|
1593 | + add_meta_box( |
|
1594 | + 'espresso_event_editor_tickets', |
|
1595 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
1596 | + [$this, 'ticket_metabox'], |
|
1597 | + $this->page_slug, |
|
1598 | + 'normal', |
|
1599 | + 'high' |
|
1600 | + ); |
|
1601 | + add_meta_box( |
|
1602 | + 'espresso_event_editor_event_options', |
|
1603 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
1604 | + [$this, 'registration_options_meta_box'], |
|
1605 | + $this->page_slug, |
|
1606 | + 'side' |
|
1607 | + ); |
|
1608 | + // NOTE: if you're looking for other metaboxes in here, |
|
1609 | + // where a metabox has a related management page in the admin |
|
1610 | + // you will find it setup in the related management page's "_Hooks" file. |
|
1611 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
1612 | + } |
|
1613 | + |
|
1614 | + |
|
1615 | + /** |
|
1616 | + * @throws DomainException |
|
1617 | + * @throws EE_Error |
|
1618 | + * @throws ReflectionException |
|
1619 | + */ |
|
1620 | + public function ticket_metabox() |
|
1621 | + { |
|
1622 | + $existing_datetime_ids = $existing_ticket_ids = []; |
|
1623 | + // defaults for template args |
|
1624 | + $template_args = [ |
|
1625 | + 'existing_datetime_ids' => '', |
|
1626 | + 'event_datetime_help_link' => '', |
|
1627 | + 'ticket_options_help_link' => '', |
|
1628 | + 'time' => null, |
|
1629 | + 'ticket_rows' => '', |
|
1630 | + 'existing_ticket_ids' => '', |
|
1631 | + 'total_ticket_rows' => 1, |
|
1632 | + 'ticket_js_structure' => '', |
|
1633 | + 'trash_icon' => 'ee-lock-icon', |
|
1634 | + 'disabled' => '', |
|
1635 | + ]; |
|
1636 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
1637 | + /** |
|
1638 | + * 1. Start with retrieving Datetimes |
|
1639 | + * 2. Fore each datetime get related tickets |
|
1640 | + * 3. For each ticket get related prices |
|
1641 | + */ |
|
1642 | + $times = EEM_Datetime::instance()->get_all_event_dates($event_id); |
|
1643 | + $first_datetime = reset($times); |
|
1644 | + // do we get related tickets? |
|
1645 | + if ( |
|
1646 | + $first_datetime instanceof EE_Datetime |
|
1647 | + && $first_datetime->ID() !== 0 |
|
1648 | + ) { |
|
1649 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
1650 | + $template_args['time'] = $first_datetime; |
|
1651 | + $related_tickets = $first_datetime->tickets( |
|
1652 | + [ |
|
1653 | + ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
1654 | + 'default_where_conditions' => 'none', |
|
1655 | + ] |
|
1656 | + ); |
|
1657 | + if (! empty($related_tickets)) { |
|
1658 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
1659 | + $row = 0; |
|
1660 | + foreach ($related_tickets as $ticket) { |
|
1661 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
1662 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
1663 | + $row++; |
|
1664 | + } |
|
1665 | + } else { |
|
1666 | + $template_args['total_ticket_rows'] = 1; |
|
1667 | + /** @type EE_Ticket $ticket */ |
|
1668 | + $ticket = EEM_Ticket::instance()->create_default_object(); |
|
1669 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
1670 | + } |
|
1671 | + } else { |
|
1672 | + $template_args['time'] = $times[0]; |
|
1673 | + $tickets = EEM_Ticket::instance()->get_all_default_tickets(); |
|
1674 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
|
1675 | + // NOTE: we're just sending the first default row |
|
1676 | + // (decaf can't manage default tickets so this should be sufficient); |
|
1677 | + } |
|
1678 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
1679 | + 'event_editor_event_datetimes_help_tab' |
|
1680 | + ); |
|
1681 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
1682 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1683 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1684 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
1685 | + EEM_Ticket::instance()->create_default_object(), |
|
1686 | + true |
|
1687 | + ); |
|
1688 | + $template = apply_filters( |
|
1689 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
1690 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
1691 | + ); |
|
1692 | + EEH_Template::display_template($template, $template_args); |
|
1693 | + } |
|
1694 | + |
|
1695 | + |
|
1696 | + /** |
|
1697 | + * Setup an individual ticket form for the decaf event editor page |
|
1698 | + * |
|
1699 | + * @access private |
|
1700 | + * @param EE_Ticket $ticket the ticket object |
|
1701 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
1702 | + * @param int $row |
|
1703 | + * @return string generated html for the ticket row. |
|
1704 | + * @throws EE_Error |
|
1705 | + * @throws ReflectionException |
|
1706 | + */ |
|
1707 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
1708 | + { |
|
1709 | + $template_args = [ |
|
1710 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1711 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
1712 | + : '', |
|
1713 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
1714 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
1715 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
1716 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
1717 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
1718 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
1719 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
1720 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1721 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
1722 | + 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1723 | + && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1724 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
1725 | + 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1726 | + : ' disabled=disabled', |
|
1727 | + ]; |
|
1728 | + $price = $ticket->ID() !== 0 |
|
1729 | + ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
1730 | + : null; |
|
1731 | + $price = $price instanceof EE_Price |
|
1732 | + ? $price |
|
1733 | + : EEM_Price::instance()->create_default_object(); |
|
1734 | + $price_args = [ |
|
1735 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1736 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
1737 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
1738 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
1739 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
1740 | + ]; |
|
1741 | + // make sure we have default start and end dates if skeleton |
|
1742 | + // handle rows that should NOT be empty |
|
1743 | + if (empty($template_args['TKT_start_date'])) { |
|
1744 | + // if empty then the start date will be now. |
|
1745 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
1746 | + } |
|
1747 | + if (empty($template_args['TKT_end_date'])) { |
|
1748 | + // get the earliest datetime (if present); |
|
1749 | + $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
1750 | + ? $this->_cpt_model_obj->get_first_related( |
|
1751 | + 'Datetime', |
|
1752 | + ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
1753 | + ) |
|
1754 | + : null; |
|
1755 | + $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime |
|
1756 | + ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a') |
|
1757 | + : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))); |
|
1758 | + } |
|
1759 | + $template_args = array_merge($template_args, $price_args); |
|
1760 | + $template = apply_filters( |
|
1761 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
1762 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
1763 | + $ticket |
|
1764 | + ); |
|
1765 | + return EEH_Template::display_template($template, $template_args, true); |
|
1766 | + } |
|
1767 | + |
|
1768 | + |
|
1769 | + /** |
|
1770 | + * @throws EE_Error |
|
1771 | + * @throws ReflectionException |
|
1772 | + */ |
|
1773 | + public function registration_options_meta_box() |
|
1774 | + { |
|
1775 | + $yes_no_values = [ |
|
1776 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
1777 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
1778 | + ]; |
|
1779 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
1780 | + [ |
|
1781 | + EEM_Registration::status_id_cancelled, |
|
1782 | + EEM_Registration::status_id_declined, |
|
1783 | + EEM_Registration::status_id_incomplete, |
|
1784 | + ], |
|
1785 | + true |
|
1786 | + ); |
|
1787 | + // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
1788 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
1789 | + $template_args['event'] = $this->_cpt_model_obj; |
|
1790 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
1791 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
1792 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
1793 | + 'default_reg_status', |
|
1794 | + $default_reg_status_values, |
|
1795 | + $this->_cpt_model_obj->default_registration_status() |
|
1796 | + ); |
|
1797 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
1798 | + 'display_desc', |
|
1799 | + $yes_no_values, |
|
1800 | + $this->_cpt_model_obj->display_description() |
|
1801 | + ); |
|
1802 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
1803 | + 'display_ticket_selector', |
|
1804 | + $yes_no_values, |
|
1805 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
1806 | + '', |
|
1807 | + '', |
|
1808 | + false |
|
1809 | + ); |
|
1810 | + $template_args['additional_registration_options'] = apply_filters( |
|
1811 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
1812 | + '', |
|
1813 | + $template_args, |
|
1814 | + $yes_no_values, |
|
1815 | + $default_reg_status_values |
|
1816 | + ); |
|
1817 | + EEH_Template::display_template( |
|
1818 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
1819 | + $template_args |
|
1820 | + ); |
|
1821 | + } |
|
1822 | + |
|
1823 | + |
|
1824 | + /** |
|
1825 | + * _get_events() |
|
1826 | + * This method simply returns all the events (for the given _view and paging) |
|
1827 | + * |
|
1828 | + * @access public |
|
1829 | + * @param int $per_page count of items per page (20 default); |
|
1830 | + * @param int $current_page what is the current page being viewed. |
|
1831 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
1832 | + * If FALSE then we return an array of event objects |
|
1833 | + * that match the given _view and paging parameters. |
|
1834 | + * @return array|int an array of event objects or a count of them. |
|
1835 | + * @throws Exception |
|
1836 | + */ |
|
1837 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
1838 | + { |
|
1839 | + $EEM_Event = $this->_event_model(); |
|
1840 | + $offset = ($current_page - 1) * $per_page; |
|
1841 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
1842 | + $orderby = $this->request->getRequestParam('orderby', 'EVT_ID'); |
|
1843 | + $order = $this->request->getRequestParam('order', 'DESC'); |
|
1844 | + $month_range = $this->request->getRequestParam('month_range'); |
|
1845 | + if ($month_range) { |
|
1846 | + $pieces = explode(' ', $month_range, 3); |
|
1847 | + // simulate the FIRST day of the month, that fixes issues for months like February |
|
1848 | + // where PHP doesn't know what to assume for date. |
|
1849 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
1850 | + $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
1851 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
1852 | + } |
|
1853 | + $where = []; |
|
1854 | + $status = $this->request->getRequestParam('status'); |
|
1855 | + // determine what post_status our condition will have for the query. |
|
1856 | + switch ($status) { |
|
1857 | + case 'month': |
|
1858 | + case 'today': |
|
1859 | + case null: |
|
1860 | + case 'all': |
|
1861 | + break; |
|
1862 | + case 'draft': |
|
1863 | + $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
1864 | + break; |
|
1865 | + default: |
|
1866 | + $where['status'] = $status; |
|
1867 | + } |
|
1868 | + // categories? The default for all categories is -1 |
|
1869 | + $category = $this->request->getRequestParam('EVT_CAT', -1, 'int'); |
|
1870 | + if ($category !== -1) { |
|
1871 | + $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
1872 | + $where['Term_Taxonomy.term_id'] = $category; |
|
1873 | + } |
|
1874 | + // date where conditions |
|
1875 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
1876 | + if ($month_range) { |
|
1877 | + $DateTime = new DateTime( |
|
1878 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
1879 | + new DateTimeZone('UTC') |
|
1880 | + ); |
|
1881 | + $start = $DateTime->getTimestamp(); |
|
1882 | + // set the datetime to be the end of the month |
|
1883 | + $DateTime->setDate( |
|
1884 | + $year_r, |
|
1885 | + $month_r, |
|
1886 | + $DateTime->format('t') |
|
1887 | + )->setTime(23, 59, 59); |
|
1888 | + $end = $DateTime->getTimestamp(); |
|
1889 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
1890 | + } elseif ($status === 'today') { |
|
1891 | + $DateTime = |
|
1892 | + new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1893 | + $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
1894 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1895 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
1896 | + } elseif ($status === 'month') { |
|
1897 | + $now = date('Y-m-01'); |
|
1898 | + $DateTime = |
|
1899 | + new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1900 | + $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
1901 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
1902 | + ->setTime(23, 59, 59) |
|
1903 | + ->format(implode(' ', $start_formats)); |
|
1904 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
1905 | + } |
|
1906 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1907 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
1908 | + } else { |
|
1909 | + if (! isset($where['status'])) { |
|
1910 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
1911 | + $where['OR'] = [ |
|
1912 | + 'status*restrict_private' => ['!=', 'private'], |
|
1913 | + 'AND' => [ |
|
1914 | + 'status*inclusive' => ['=', 'private'], |
|
1915 | + 'EVT_wp_user' => get_current_user_id(), |
|
1916 | + ], |
|
1917 | + ]; |
|
1918 | + } |
|
1919 | + } |
|
1920 | + } |
|
1921 | + $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int'); |
|
1922 | + if ( |
|
1923 | + $wp_user |
|
1924 | + && $wp_user !== get_current_user_id() |
|
1925 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
1926 | + ) { |
|
1927 | + $where['EVT_wp_user'] = $wp_user; |
|
1928 | + } |
|
1929 | + // search query handling |
|
1930 | + $search_term = $this->request->getRequestParam('s'); |
|
1931 | + if ($search_term) { |
|
1932 | + $search_term = '%' . $search_term . '%'; |
|
1933 | + $where['OR'] = [ |
|
1934 | + 'EVT_name' => ['LIKE', $search_term], |
|
1935 | + 'EVT_desc' => ['LIKE', $search_term], |
|
1936 | + 'EVT_short_desc' => ['LIKE', $search_term], |
|
1937 | + ]; |
|
1938 | + } |
|
1939 | + // filter events by venue. |
|
1940 | + $venue = $this->request->getRequestParam('venue', 0, 'int'); |
|
1941 | + if ($venue) { |
|
1942 | + $where['Venue.VNU_ID'] = $venue; |
|
1943 | + } |
|
1944 | + $request_params = $this->request->requestParams(); |
|
1945 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params); |
|
1946 | + $query_params = apply_filters( |
|
1947 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
1948 | + [ |
|
1949 | + $where, |
|
1950 | + 'limit' => $limit, |
|
1951 | + 'order_by' => $orderby, |
|
1952 | + 'order' => $order, |
|
1953 | + 'group_by' => 'EVT_ID', |
|
1954 | + ], |
|
1955 | + $request_params |
|
1956 | + ); |
|
1957 | + |
|
1958 | + // let's first check if we have special requests coming in. |
|
1959 | + $active_status = $this->request->getRequestParam('active_status'); |
|
1960 | + if ($active_status) { |
|
1961 | + switch ($active_status) { |
|
1962 | + case 'upcoming': |
|
1963 | + return $EEM_Event->get_upcoming_events($query_params, $count); |
|
1964 | + case 'expired': |
|
1965 | + return $EEM_Event->get_expired_events($query_params, $count); |
|
1966 | + case 'active': |
|
1967 | + return $EEM_Event->get_active_events($query_params, $count); |
|
1968 | + case 'inactive': |
|
1969 | + return $EEM_Event->get_inactive_events($query_params, $count); |
|
1970 | + } |
|
1971 | + } |
|
1972 | + |
|
1973 | + return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params); |
|
1974 | + } |
|
1975 | + |
|
1976 | + |
|
1977 | + /** |
|
1978 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
1979 | + * |
|
1980 | + * @param string $post_id |
|
1981 | + * @throws EE_Error |
|
1982 | + * @throws ReflectionException |
|
1983 | + */ |
|
1984 | + public function trash_cpt_item($post_id) |
|
1985 | + { |
|
1986 | + $this->request->setRequestParam('EVT_ID', $post_id); |
|
1987 | + $this->_trash_or_restore_event('trash', false); |
|
1988 | + } |
|
1989 | + |
|
1990 | + |
|
1991 | + /** |
|
1992 | + * @param string $post_id |
|
1993 | + * @throws EE_Error |
|
1994 | + * @throws ReflectionException |
|
1995 | + */ |
|
1996 | + public function restore_cpt_item($post_id) |
|
1997 | + { |
|
1998 | + $this->request->setRequestParam('EVT_ID', $post_id); |
|
1999 | + $this->_trash_or_restore_event('draft', false); |
|
2000 | + } |
|
2001 | + |
|
2002 | + |
|
2003 | + /** |
|
2004 | + * @param string $post_id |
|
2005 | + * @throws EE_Error |
|
2006 | + * @throws EE_Error |
|
2007 | + */ |
|
2008 | + public function delete_cpt_item($post_id) |
|
2009 | + { |
|
2010 | + throw new EE_Error( |
|
2011 | + esc_html__( |
|
2012 | + 'Please contact Event Espresso support with the details of the steps taken to produce this error.', |
|
2013 | + 'event_espresso' |
|
2014 | + ) |
|
2015 | + ); |
|
2016 | + // $this->request->setRequestParam('EVT_ID', $post_id); |
|
2017 | + // $this->_delete_event(); |
|
2018 | + } |
|
2019 | + |
|
2020 | + |
|
2021 | + /** |
|
2022 | + * _trash_or_restore_event |
|
2023 | + * |
|
2024 | + * @access protected |
|
2025 | + * @param string $event_status |
|
2026 | + * @param bool $redirect_after |
|
2027 | + * @throws EE_Error |
|
2028 | + * @throws EE_Error |
|
2029 | + * @throws ReflectionException |
|
2030 | + */ |
|
2031 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
2032 | + { |
|
2033 | + // determine the event id and set to array. |
|
2034 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
2035 | + // loop thru events |
|
2036 | + if ($EVT_ID) { |
|
2037 | + // clean status |
|
2038 | + $event_status = sanitize_key($event_status); |
|
2039 | + // grab status |
|
2040 | + if (! empty($event_status)) { |
|
2041 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
2042 | + } else { |
|
2043 | + $success = false; |
|
2044 | + $msg = esc_html__( |
|
2045 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2046 | + 'event_espresso' |
|
2047 | + ); |
|
2048 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2049 | + } |
|
2050 | + } else { |
|
2051 | + $success = false; |
|
2052 | + $msg = esc_html__( |
|
2053 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
2054 | + 'event_espresso' |
|
2055 | + ); |
|
2056 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2057 | + } |
|
2058 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2059 | + if ($redirect_after) { |
|
2060 | + $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
2061 | + } |
|
2062 | + } |
|
2063 | + |
|
2064 | + |
|
2065 | + /** |
|
2066 | + * _trash_or_restore_events |
|
2067 | + * |
|
2068 | + * @access protected |
|
2069 | + * @param string $event_status |
|
2070 | + * @return void |
|
2071 | + * @throws EE_Error |
|
2072 | + * @throws EE_Error |
|
2073 | + * @throws ReflectionException |
|
2074 | + */ |
|
2075 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
2076 | + { |
|
2077 | + // clean status |
|
2078 | + $event_status = sanitize_key($event_status); |
|
2079 | + // grab status |
|
2080 | + if (! empty($event_status)) { |
|
2081 | + $success = true; |
|
2082 | + // determine the event id and set to array. |
|
2083 | + $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
2084 | + // loop thru events |
|
2085 | + foreach ($EVT_IDs as $EVT_ID) { |
|
2086 | + if ($EVT_ID = absint($EVT_ID)) { |
|
2087 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
2088 | + $success = $results !== false ? $success : false; |
|
2089 | + } else { |
|
2090 | + $msg = sprintf( |
|
2091 | + esc_html__( |
|
2092 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
2093 | + 'event_espresso' |
|
2094 | + ), |
|
2095 | + $EVT_ID |
|
2096 | + ); |
|
2097 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2098 | + $success = false; |
|
2099 | + } |
|
2100 | + } |
|
2101 | + } else { |
|
2102 | + $success = false; |
|
2103 | + $msg = esc_html__( |
|
2104 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2105 | + 'event_espresso' |
|
2106 | + ); |
|
2107 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2108 | + } |
|
2109 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
2110 | + $success = $success ? 2 : false; |
|
2111 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2112 | + $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
2113 | + } |
|
2114 | + |
|
2115 | + |
|
2116 | + /** |
|
2117 | + * @param int $EVT_ID |
|
2118 | + * @param string $event_status |
|
2119 | + * @return bool |
|
2120 | + * @throws EE_Error |
|
2121 | + * @throws ReflectionException |
|
2122 | + */ |
|
2123 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
2124 | + { |
|
2125 | + // grab event id |
|
2126 | + if (! $EVT_ID) { |
|
2127 | + $msg = esc_html__( |
|
2128 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2129 | + 'event_espresso' |
|
2130 | + ); |
|
2131 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2132 | + return false; |
|
2133 | + } |
|
2134 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2135 | + // clean status |
|
2136 | + $event_status = sanitize_key($event_status); |
|
2137 | + // grab status |
|
2138 | + if (empty($event_status)) { |
|
2139 | + $msg = esc_html__( |
|
2140 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
2141 | + 'event_espresso' |
|
2142 | + ); |
|
2143 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2144 | + return false; |
|
2145 | + } |
|
2146 | + // was event trashed or restored ? |
|
2147 | + switch ($event_status) { |
|
2148 | + case 'draft': |
|
2149 | + $action = 'restored from the trash'; |
|
2150 | + $hook = 'AHEE_event_restored_from_trash'; |
|
2151 | + break; |
|
2152 | + case 'trash': |
|
2153 | + $action = 'moved to the trash'; |
|
2154 | + $hook = 'AHEE_event_moved_to_trash'; |
|
2155 | + break; |
|
2156 | + default: |
|
2157 | + $action = 'updated'; |
|
2158 | + $hook = false; |
|
2159 | + } |
|
2160 | + // use class to change status |
|
2161 | + $this->_cpt_model_obj->set_status($event_status); |
|
2162 | + $success = $this->_cpt_model_obj->save(); |
|
2163 | + if (! $success) { |
|
2164 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
2165 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2166 | + return false; |
|
2167 | + } |
|
2168 | + if ($hook) { |
|
2169 | + do_action($hook); |
|
2170 | + } |
|
2171 | + return true; |
|
2172 | + } |
|
2173 | + |
|
2174 | + |
|
2175 | + /** |
|
2176 | + * @param array $event_ids |
|
2177 | + * @return array |
|
2178 | + * @since 4.10.23.p |
|
2179 | + */ |
|
2180 | + private function cleanEventIds(array $event_ids) |
|
2181 | + { |
|
2182 | + return array_map('absint', $event_ids); |
|
2183 | + } |
|
2184 | + |
|
2185 | + |
|
2186 | + /** |
|
2187 | + * @return array |
|
2188 | + * @since 4.10.23.p |
|
2189 | + */ |
|
2190 | + private function getEventIdsFromRequest() |
|
2191 | + { |
|
2192 | + if ($this->request->requestParamIsSet('EVT_IDs')) { |
|
2193 | + return $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
2194 | + } else { |
|
2195 | + return $this->request->getRequestParam('EVT_ID', [], 'int', true); |
|
2196 | + } |
|
2197 | + } |
|
2198 | + |
|
2199 | + |
|
2200 | + /** |
|
2201 | + * @param bool $preview_delete |
|
2202 | + * @throws EE_Error |
|
2203 | + */ |
|
2204 | + protected function _delete_event($preview_delete = true) |
|
2205 | + { |
|
2206 | + $this->_delete_events($preview_delete); |
|
2207 | + } |
|
2208 | + |
|
2209 | + |
|
2210 | + /** |
|
2211 | + * Gets the tree traversal batch persister. |
|
2212 | + * |
|
2213 | + * @return NodeGroupDao |
|
2214 | + * @throws InvalidArgumentException |
|
2215 | + * @throws InvalidDataTypeException |
|
2216 | + * @throws InvalidInterfaceException |
|
2217 | + * @since 4.10.12.p |
|
2218 | + */ |
|
2219 | + protected function getModelObjNodeGroupPersister() |
|
2220 | + { |
|
2221 | + if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
2222 | + $this->model_obj_node_group_persister = |
|
2223 | + $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
2224 | + } |
|
2225 | + return $this->model_obj_node_group_persister; |
|
2226 | + } |
|
2227 | + |
|
2228 | + |
|
2229 | + /** |
|
2230 | + * @param bool $preview_delete |
|
2231 | + * @return void |
|
2232 | + * @throws EE_Error |
|
2233 | + */ |
|
2234 | + protected function _delete_events($preview_delete = true) |
|
2235 | + { |
|
2236 | + $event_ids = $this->getEventIdsFromRequest(); |
|
2237 | + if ($preview_delete) { |
|
2238 | + $this->generateDeletionPreview($event_ids); |
|
2239 | + } else { |
|
2240 | + EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]); |
|
2241 | + } |
|
2242 | + } |
|
2243 | + |
|
2244 | + |
|
2245 | + /** |
|
2246 | + * @param array $event_ids |
|
2247 | + */ |
|
2248 | + protected function generateDeletionPreview(array $event_ids) |
|
2249 | + { |
|
2250 | + $event_ids = $this->cleanEventIds($event_ids); |
|
2251 | + // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
2252 | + $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
2253 | + $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
2254 | + [ |
|
2255 | + 'action' => 'preview_deletion', |
|
2256 | + 'deletion_job_code' => $deletion_job_code, |
|
2257 | + ], |
|
2258 | + $this->_admin_base_url |
|
2259 | + ); |
|
2260 | + EEH_URL::safeRedirectAndExit( |
|
2261 | + EE_Admin_Page::add_query_args_and_nonce( |
|
2262 | + [ |
|
2263 | + 'page' => 'espresso_batch', |
|
2264 | + 'batch' => EED_Batch::batch_job, |
|
2265 | + 'EVT_IDs' => $event_ids, |
|
2266 | + 'deletion_job_code' => $deletion_job_code, |
|
2267 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
2268 | + 'return_url' => urlencode($return_url), |
|
2269 | + ], |
|
2270 | + admin_url() |
|
2271 | + ) |
|
2272 | + ); |
|
2273 | + } |
|
2274 | + |
|
2275 | + |
|
2276 | + /** |
|
2277 | + * Checks for a POST submission |
|
2278 | + * |
|
2279 | + * @since 4.10.12.p |
|
2280 | + */ |
|
2281 | + protected function confirmDeletion() |
|
2282 | + { |
|
2283 | + $deletion_redirect_logic = |
|
2284 | + $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'); |
|
2285 | + $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
2286 | + } |
|
2287 | + |
|
2288 | + |
|
2289 | + /** |
|
2290 | + * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
2291 | + * |
|
2292 | + * @throws EE_Error |
|
2293 | + * @since 4.10.12.p |
|
2294 | + */ |
|
2295 | + protected function previewDeletion() |
|
2296 | + { |
|
2297 | + $preview_deletion_logic = |
|
2298 | + $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'); |
|
2299 | + $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
2300 | + $this->display_admin_page_with_no_sidebar(); |
|
2301 | + } |
|
2302 | + |
|
2303 | + |
|
2304 | + /** |
|
2305 | + * get total number of events |
|
2306 | + * |
|
2307 | + * @access public |
|
2308 | + * @return int |
|
2309 | + * @throws EE_Error |
|
2310 | + * @throws EE_Error |
|
2311 | + */ |
|
2312 | + public function total_events() |
|
2313 | + { |
|
2314 | + return EEM_Event::instance()->count( |
|
2315 | + ['caps' => 'read_admin'], |
|
2316 | + 'EVT_ID', |
|
2317 | + true |
|
2318 | + ); |
|
2319 | + } |
|
2320 | + |
|
2321 | + |
|
2322 | + /** |
|
2323 | + * get total number of draft events |
|
2324 | + * |
|
2325 | + * @access public |
|
2326 | + * @return int |
|
2327 | + * @throws EE_Error |
|
2328 | + * @throws EE_Error |
|
2329 | + */ |
|
2330 | + public function total_events_draft() |
|
2331 | + { |
|
2332 | + return EEM_Event::instance()->count( |
|
2333 | + [ |
|
2334 | + ['status' => ['IN', ['draft', 'auto-draft']]], |
|
2335 | + 'caps' => 'read_admin', |
|
2336 | + ], |
|
2337 | + 'EVT_ID', |
|
2338 | + true |
|
2339 | + ); |
|
2340 | + } |
|
2341 | + |
|
2342 | + |
|
2343 | + /** |
|
2344 | + * get total number of trashed events |
|
2345 | + * |
|
2346 | + * @access public |
|
2347 | + * @return int |
|
2348 | + * @throws EE_Error |
|
2349 | + * @throws EE_Error |
|
2350 | + */ |
|
2351 | + public function total_trashed_events() |
|
2352 | + { |
|
2353 | + return EEM_Event::instance()->count( |
|
2354 | + [ |
|
2355 | + ['status' => 'trash'], |
|
2356 | + 'caps' => 'read_admin', |
|
2357 | + ], |
|
2358 | + 'EVT_ID', |
|
2359 | + true |
|
2360 | + ); |
|
2361 | + } |
|
2362 | + |
|
2363 | + |
|
2364 | + /** |
|
2365 | + * _default_event_settings |
|
2366 | + * This generates the Default Settings Tab |
|
2367 | + * |
|
2368 | + * @return void |
|
2369 | + * @throws EE_Error |
|
2370 | + */ |
|
2371 | + protected function _default_event_settings() |
|
2372 | + { |
|
2373 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
2374 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
2375 | + $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
2376 | + $this->display_admin_page_with_sidebar(); |
|
2377 | + } |
|
2378 | + |
|
2379 | + |
|
2380 | + /** |
|
2381 | + * Return the form for event settings. |
|
2382 | + * |
|
2383 | + * @return EE_Form_Section_Proper |
|
2384 | + * @throws EE_Error |
|
2385 | + */ |
|
2386 | + protected function _default_event_settings_form() |
|
2387 | + { |
|
2388 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
2389 | + $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
2390 | + // exclude |
|
2391 | + [ |
|
2392 | + EEM_Registration::status_id_cancelled, |
|
2393 | + EEM_Registration::status_id_declined, |
|
2394 | + EEM_Registration::status_id_incomplete, |
|
2395 | + EEM_Registration::status_id_wait_list, |
|
2396 | + ], |
|
2397 | + true |
|
2398 | + ); |
|
2399 | + return new EE_Form_Section_Proper( |
|
2400 | + [ |
|
2401 | + 'name' => 'update_default_event_settings', |
|
2402 | + 'html_id' => 'update_default_event_settings', |
|
2403 | + 'html_class' => 'form-table', |
|
2404 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
2405 | + 'subsections' => apply_filters( |
|
2406 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
2407 | + [ |
|
2408 | + 'default_reg_status' => new EE_Select_Input( |
|
2409 | + $registration_stati_for_selection, |
|
2410 | + [ |
|
2411 | + 'default' => isset($registration_config->default_STS_ID) |
|
2412 | + && array_key_exists( |
|
2413 | + $registration_config->default_STS_ID, |
|
2414 | + $registration_stati_for_selection |
|
2415 | + ) |
|
2416 | + ? sanitize_text_field($registration_config->default_STS_ID) |
|
2417 | + : EEM_Registration::status_id_pending_payment, |
|
2418 | + 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
2419 | + . EEH_Template::get_help_tab_link( |
|
2420 | + 'default_settings_status_help_tab' |
|
2421 | + ), |
|
2422 | + 'html_help_text' => esc_html__( |
|
2423 | + 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
2424 | + 'event_espresso' |
|
2425 | + ), |
|
2426 | + ] |
|
2427 | + ), |
|
2428 | + 'default_max_tickets' => new EE_Integer_Input( |
|
2429 | + [ |
|
2430 | + 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
2431 | + ? $registration_config->default_maximum_number_of_tickets |
|
2432 | + : EEM_Event::get_default_additional_limit(), |
|
2433 | + 'html_label_text' => esc_html__( |
|
2434 | + 'Default Maximum Tickets Allowed Per Order:', |
|
2435 | + 'event_espresso' |
|
2436 | + ) |
|
2437 | + . EEH_Template::get_help_tab_link( |
|
2438 | + 'default_maximum_tickets_help_tab"' |
|
2439 | + ), |
|
2440 | + 'html_help_text' => esc_html__( |
|
2441 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
2442 | + 'event_espresso' |
|
2443 | + ), |
|
2444 | + ] |
|
2445 | + ), |
|
2446 | + ] |
|
2447 | + ), |
|
2448 | + ] |
|
2449 | + ); |
|
2450 | + } |
|
2451 | + |
|
2452 | + |
|
2453 | + /** |
|
2454 | + * _update_default_event_settings |
|
2455 | + * |
|
2456 | + * @access protected |
|
2457 | + * @return void |
|
2458 | + * @throws EE_Error |
|
2459 | + */ |
|
2460 | + protected function _update_default_event_settings() |
|
2461 | + { |
|
2462 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
2463 | + $form = $this->_default_event_settings_form(); |
|
2464 | + if ($form->was_submitted()) { |
|
2465 | + $form->receive_form_submission(); |
|
2466 | + if ($form->is_valid()) { |
|
2467 | + $valid_data = $form->valid_data(); |
|
2468 | + if (isset($valid_data['default_reg_status'])) { |
|
2469 | + $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
2470 | + } |
|
2471 | + if (isset($valid_data['default_max_tickets'])) { |
|
2472 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
2473 | + } |
|
2474 | + // update because data was valid! |
|
2475 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
2476 | + EE_Error::overwrite_success(); |
|
2477 | + EE_Error::add_success( |
|
2478 | + esc_html__('Default Event Settings were updated', 'event_espresso') |
|
2479 | + ); |
|
2480 | + } |
|
2481 | + } |
|
2482 | + $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
2483 | + } |
|
2484 | + |
|
2485 | + |
|
2486 | + /************* Templates ************* |
|
21 | 2487 | * |
22 | - * @var EE_Event $_event |
|
23 | - */ |
|
24 | - protected $_event; |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * This will hold the category object for category_details screen. |
|
29 | - * |
|
30 | - * @var stdClass $_category |
|
31 | - */ |
|
32 | - protected $_category; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * This will hold the event model instance |
|
37 | - * |
|
38 | - * @var EEM_Event $_event_model |
|
39 | - */ |
|
40 | - protected $_event_model; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @var EE_Event |
|
45 | - */ |
|
46 | - protected $_cpt_model_obj = false; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * @var NodeGroupDao |
|
51 | - */ |
|
52 | - protected $model_obj_node_group_persister; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Initialize page props for this admin page group. |
|
57 | - */ |
|
58 | - protected function _init_page_props() |
|
59 | - { |
|
60 | - $this->page_slug = EVENTS_PG_SLUG; |
|
61 | - $this->page_label = EVENTS_LABEL; |
|
62 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
63 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
64 | - $this->_cpt_model_names = [ |
|
65 | - 'create_new' => 'EEM_Event', |
|
66 | - 'edit' => 'EEM_Event', |
|
67 | - ]; |
|
68 | - $this->_cpt_edit_routes = [ |
|
69 | - 'espresso_events' => 'edit', |
|
70 | - ]; |
|
71 | - add_action( |
|
72 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
73 | - [$this, 'verify_event_edit'], |
|
74 | - 10, |
|
75 | - 2 |
|
76 | - ); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Sets the ajax hooks used for this admin page group. |
|
82 | - */ |
|
83 | - protected function _ajax_hooks() |
|
84 | - { |
|
85 | - add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Sets the page properties for this admin page group. |
|
91 | - */ |
|
92 | - protected function _define_page_props() |
|
93 | - { |
|
94 | - $this->_admin_page_title = EVENTS_LABEL; |
|
95 | - $this->_labels = [ |
|
96 | - 'buttons' => [ |
|
97 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
98 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
99 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
100 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
101 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
102 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
103 | - ], |
|
104 | - 'editor_title' => [ |
|
105 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
106 | - ], |
|
107 | - 'publishbox' => [ |
|
108 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
109 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
110 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
111 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
112 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
113 | - ], |
|
114 | - ]; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * Sets the page routes property for this admin page group. |
|
120 | - */ |
|
121 | - protected function _set_page_routes() |
|
122 | - { |
|
123 | - // load formatter helper |
|
124 | - // load field generator helper |
|
125 | - // is there a evt_id in the request? |
|
126 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
127 | - $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
|
128 | - |
|
129 | - $this->_page_routes = [ |
|
130 | - 'default' => [ |
|
131 | - 'func' => '_events_overview_list_table', |
|
132 | - 'capability' => 'ee_read_events', |
|
133 | - ], |
|
134 | - 'create_new' => [ |
|
135 | - 'func' => '_create_new_cpt_item', |
|
136 | - 'capability' => 'ee_edit_events', |
|
137 | - ], |
|
138 | - 'edit' => [ |
|
139 | - 'func' => '_edit_cpt_item', |
|
140 | - 'capability' => 'ee_edit_event', |
|
141 | - 'obj_id' => $EVT_ID, |
|
142 | - ], |
|
143 | - 'copy_event' => [ |
|
144 | - 'func' => '_copy_events', |
|
145 | - 'capability' => 'ee_edit_event', |
|
146 | - 'obj_id' => $EVT_ID, |
|
147 | - 'noheader' => true, |
|
148 | - ], |
|
149 | - 'trash_event' => [ |
|
150 | - 'func' => '_trash_or_restore_event', |
|
151 | - 'args' => ['event_status' => 'trash'], |
|
152 | - 'capability' => 'ee_delete_event', |
|
153 | - 'obj_id' => $EVT_ID, |
|
154 | - 'noheader' => true, |
|
155 | - ], |
|
156 | - 'trash_events' => [ |
|
157 | - 'func' => '_trash_or_restore_events', |
|
158 | - 'args' => ['event_status' => 'trash'], |
|
159 | - 'capability' => 'ee_delete_events', |
|
160 | - 'noheader' => true, |
|
161 | - ], |
|
162 | - 'restore_event' => [ |
|
163 | - 'func' => '_trash_or_restore_event', |
|
164 | - 'args' => ['event_status' => 'draft'], |
|
165 | - 'capability' => 'ee_delete_event', |
|
166 | - 'obj_id' => $EVT_ID, |
|
167 | - 'noheader' => true, |
|
168 | - ], |
|
169 | - 'restore_events' => [ |
|
170 | - 'func' => '_trash_or_restore_events', |
|
171 | - 'args' => ['event_status' => 'draft'], |
|
172 | - 'capability' => 'ee_delete_events', |
|
173 | - 'noheader' => true, |
|
174 | - ], |
|
175 | - 'delete_event' => [ |
|
176 | - 'func' => '_delete_event', |
|
177 | - 'capability' => 'ee_delete_event', |
|
178 | - 'obj_id' => $EVT_ID, |
|
179 | - 'noheader' => true, |
|
180 | - ], |
|
181 | - 'delete_events' => [ |
|
182 | - 'func' => '_delete_events', |
|
183 | - 'capability' => 'ee_delete_events', |
|
184 | - 'noheader' => true, |
|
185 | - ], |
|
186 | - 'view_report' => [ |
|
187 | - 'func' => '_view_report', |
|
188 | - 'capability' => 'ee_edit_events', |
|
189 | - ], |
|
190 | - 'default_event_settings' => [ |
|
191 | - 'func' => '_default_event_settings', |
|
192 | - 'capability' => 'manage_options', |
|
193 | - ], |
|
194 | - 'update_default_event_settings' => [ |
|
195 | - 'func' => '_update_default_event_settings', |
|
196 | - 'capability' => 'manage_options', |
|
197 | - 'noheader' => true, |
|
198 | - ], |
|
199 | - 'template_settings' => [ |
|
200 | - 'func' => '_template_settings', |
|
201 | - 'capability' => 'manage_options', |
|
202 | - ], |
|
203 | - // event category tab related |
|
204 | - 'add_category' => [ |
|
205 | - 'func' => '_category_details', |
|
206 | - 'capability' => 'ee_edit_event_category', |
|
207 | - 'args' => ['add'], |
|
208 | - ], |
|
209 | - 'edit_category' => [ |
|
210 | - 'func' => '_category_details', |
|
211 | - 'capability' => 'ee_edit_event_category', |
|
212 | - 'args' => ['edit'], |
|
213 | - ], |
|
214 | - 'delete_categories' => [ |
|
215 | - 'func' => '_delete_categories', |
|
216 | - 'capability' => 'ee_delete_event_category', |
|
217 | - 'noheader' => true, |
|
218 | - ], |
|
219 | - 'delete_category' => [ |
|
220 | - 'func' => '_delete_categories', |
|
221 | - 'capability' => 'ee_delete_event_category', |
|
222 | - 'noheader' => true, |
|
223 | - ], |
|
224 | - 'insert_category' => [ |
|
225 | - 'func' => '_insert_or_update_category', |
|
226 | - 'args' => ['new_category' => true], |
|
227 | - 'capability' => 'ee_edit_event_category', |
|
228 | - 'noheader' => true, |
|
229 | - ], |
|
230 | - 'update_category' => [ |
|
231 | - 'func' => '_insert_or_update_category', |
|
232 | - 'args' => ['new_category' => false], |
|
233 | - 'capability' => 'ee_edit_event_category', |
|
234 | - 'noheader' => true, |
|
235 | - ], |
|
236 | - 'category_list' => [ |
|
237 | - 'func' => '_category_list_table', |
|
238 | - 'capability' => 'ee_manage_event_categories', |
|
239 | - ], |
|
240 | - 'preview_deletion' => [ |
|
241 | - 'func' => 'previewDeletion', |
|
242 | - 'capability' => 'ee_delete_events', |
|
243 | - ], |
|
244 | - 'confirm_deletion' => [ |
|
245 | - 'func' => 'confirmDeletion', |
|
246 | - 'capability' => 'ee_delete_events', |
|
247 | - 'noheader' => true, |
|
248 | - ], |
|
249 | - ]; |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * Set the _page_config property for this admin page group. |
|
255 | - */ |
|
256 | - protected function _set_page_config() |
|
257 | - { |
|
258 | - $post_id = $this->request->getRequestParam('post', 0, 'int'); |
|
259 | - $EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
260 | - $this->_page_config = [ |
|
261 | - 'default' => [ |
|
262 | - 'nav' => [ |
|
263 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
264 | - 'order' => 10, |
|
265 | - ], |
|
266 | - 'list_table' => 'Events_Admin_List_Table', |
|
267 | - 'help_tabs' => [ |
|
268 | - 'events_overview_help_tab' => [ |
|
269 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
270 | - 'filename' => 'events_overview', |
|
271 | - ], |
|
272 | - 'events_overview_table_column_headings_help_tab' => [ |
|
273 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
274 | - 'filename' => 'events_overview_table_column_headings', |
|
275 | - ], |
|
276 | - 'events_overview_filters_help_tab' => [ |
|
277 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
278 | - 'filename' => 'events_overview_filters', |
|
279 | - ], |
|
280 | - 'events_overview_view_help_tab' => [ |
|
281 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
282 | - 'filename' => 'events_overview_views', |
|
283 | - ], |
|
284 | - 'events_overview_other_help_tab' => [ |
|
285 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
286 | - 'filename' => 'events_overview_other', |
|
287 | - ], |
|
288 | - ], |
|
289 | - 'qtips' => [ |
|
290 | - 'EE_Event_List_Table_Tips', |
|
291 | - ], |
|
292 | - 'require_nonce' => false, |
|
293 | - ], |
|
294 | - 'create_new' => [ |
|
295 | - 'nav' => [ |
|
296 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
297 | - 'order' => 5, |
|
298 | - 'persistent' => false, |
|
299 | - ], |
|
300 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
301 | - 'help_tabs' => [ |
|
302 | - 'event_editor_help_tab' => [ |
|
303 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
304 | - 'filename' => 'event_editor', |
|
305 | - ], |
|
306 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
307 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
308 | - 'filename' => 'event_editor_title_richtexteditor', |
|
309 | - ], |
|
310 | - 'event_editor_venue_details_help_tab' => [ |
|
311 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
312 | - 'filename' => 'event_editor_venue_details', |
|
313 | - ], |
|
314 | - 'event_editor_event_datetimes_help_tab' => [ |
|
315 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
316 | - 'filename' => 'event_editor_event_datetimes', |
|
317 | - ], |
|
318 | - 'event_editor_event_tickets_help_tab' => [ |
|
319 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
320 | - 'filename' => 'event_editor_event_tickets', |
|
321 | - ], |
|
322 | - 'event_editor_event_registration_options_help_tab' => [ |
|
323 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
324 | - 'filename' => 'event_editor_event_registration_options', |
|
325 | - ], |
|
326 | - 'event_editor_tags_categories_help_tab' => [ |
|
327 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
328 | - 'filename' => 'event_editor_tags_categories', |
|
329 | - ], |
|
330 | - 'event_editor_questions_registrants_help_tab' => [ |
|
331 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
332 | - 'filename' => 'event_editor_questions_registrants', |
|
333 | - ], |
|
334 | - 'event_editor_save_new_event_help_tab' => [ |
|
335 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
336 | - 'filename' => 'event_editor_save_new_event', |
|
337 | - ], |
|
338 | - 'event_editor_other_help_tab' => [ |
|
339 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
340 | - 'filename' => 'event_editor_other', |
|
341 | - ], |
|
342 | - ], |
|
343 | - 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
344 | - 'require_nonce' => false, |
|
345 | - ], |
|
346 | - 'edit' => [ |
|
347 | - 'nav' => [ |
|
348 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
349 | - 'order' => 5, |
|
350 | - 'persistent' => false, |
|
351 | - 'url' => $post_id |
|
352 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
353 | - ['post' => $post_id, 'action' => 'edit'], |
|
354 | - $this->_current_page_view_url |
|
355 | - ) |
|
356 | - : $this->_admin_base_url, |
|
357 | - ], |
|
358 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
359 | - 'help_tabs' => [ |
|
360 | - 'event_editor_help_tab' => [ |
|
361 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
362 | - 'filename' => 'event_editor', |
|
363 | - ], |
|
364 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
365 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
366 | - 'filename' => 'event_editor_title_richtexteditor', |
|
367 | - ], |
|
368 | - 'event_editor_venue_details_help_tab' => [ |
|
369 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
370 | - 'filename' => 'event_editor_venue_details', |
|
371 | - ], |
|
372 | - 'event_editor_event_datetimes_help_tab' => [ |
|
373 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
374 | - 'filename' => 'event_editor_event_datetimes', |
|
375 | - ], |
|
376 | - 'event_editor_event_tickets_help_tab' => [ |
|
377 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
378 | - 'filename' => 'event_editor_event_tickets', |
|
379 | - ], |
|
380 | - 'event_editor_event_registration_options_help_tab' => [ |
|
381 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
382 | - 'filename' => 'event_editor_event_registration_options', |
|
383 | - ], |
|
384 | - 'event_editor_tags_categories_help_tab' => [ |
|
385 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
386 | - 'filename' => 'event_editor_tags_categories', |
|
387 | - ], |
|
388 | - 'event_editor_questions_registrants_help_tab' => [ |
|
389 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
390 | - 'filename' => 'event_editor_questions_registrants', |
|
391 | - ], |
|
392 | - 'event_editor_save_new_event_help_tab' => [ |
|
393 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
394 | - 'filename' => 'event_editor_save_new_event', |
|
395 | - ], |
|
396 | - 'event_editor_other_help_tab' => [ |
|
397 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
398 | - 'filename' => 'event_editor_other', |
|
399 | - ], |
|
400 | - ], |
|
401 | - 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
402 | - 'require_nonce' => false, |
|
403 | - ], |
|
404 | - 'default_event_settings' => [ |
|
405 | - 'nav' => [ |
|
406 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
407 | - 'order' => 40, |
|
408 | - ], |
|
409 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
410 | - 'labels' => [ |
|
411 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
412 | - ], |
|
413 | - 'help_tabs' => [ |
|
414 | - 'default_settings_help_tab' => [ |
|
415 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
416 | - 'filename' => 'events_default_settings', |
|
417 | - ], |
|
418 | - 'default_settings_status_help_tab' => [ |
|
419 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
420 | - 'filename' => 'events_default_settings_status', |
|
421 | - ], |
|
422 | - 'default_maximum_tickets_help_tab' => [ |
|
423 | - 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
424 | - 'filename' => 'events_default_settings_max_tickets', |
|
425 | - ], |
|
426 | - ], |
|
427 | - 'require_nonce' => false, |
|
428 | - ], |
|
429 | - // template settings |
|
430 | - 'template_settings' => [ |
|
431 | - 'nav' => [ |
|
432 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
433 | - 'order' => 30, |
|
434 | - ], |
|
435 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
436 | - 'help_tabs' => [ |
|
437 | - 'general_settings_templates_help_tab' => [ |
|
438 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
439 | - 'filename' => 'general_settings_templates', |
|
440 | - ], |
|
441 | - ], |
|
442 | - 'require_nonce' => false, |
|
443 | - ], |
|
444 | - // event category stuff |
|
445 | - 'add_category' => [ |
|
446 | - 'nav' => [ |
|
447 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
448 | - 'order' => 15, |
|
449 | - 'persistent' => false, |
|
450 | - ], |
|
451 | - 'help_tabs' => [ |
|
452 | - 'add_category_help_tab' => [ |
|
453 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
454 | - 'filename' => 'events_add_category', |
|
455 | - ], |
|
456 | - ], |
|
457 | - 'metaboxes' => ['_publish_post_box'], |
|
458 | - 'require_nonce' => false, |
|
459 | - ], |
|
460 | - 'edit_category' => [ |
|
461 | - 'nav' => [ |
|
462 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
463 | - 'order' => 15, |
|
464 | - 'persistent' => false, |
|
465 | - 'url' => $EVT_CAT_ID |
|
466 | - ? add_query_arg( |
|
467 | - ['EVT_CAT_ID' => $EVT_CAT_ID], |
|
468 | - $this->_current_page_view_url |
|
469 | - ) |
|
470 | - : $this->_admin_base_url, |
|
471 | - ], |
|
472 | - 'help_tabs' => [ |
|
473 | - 'edit_category_help_tab' => [ |
|
474 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
475 | - 'filename' => 'events_edit_category', |
|
476 | - ], |
|
477 | - ], |
|
478 | - 'metaboxes' => ['_publish_post_box'], |
|
479 | - 'require_nonce' => false, |
|
480 | - ], |
|
481 | - 'category_list' => [ |
|
482 | - 'nav' => [ |
|
483 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
484 | - 'order' => 20, |
|
485 | - ], |
|
486 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
487 | - 'help_tabs' => [ |
|
488 | - 'events_categories_help_tab' => [ |
|
489 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
490 | - 'filename' => 'events_categories', |
|
491 | - ], |
|
492 | - 'events_categories_table_column_headings_help_tab' => [ |
|
493 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
494 | - 'filename' => 'events_categories_table_column_headings', |
|
495 | - ], |
|
496 | - 'events_categories_view_help_tab' => [ |
|
497 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
498 | - 'filename' => 'events_categories_views', |
|
499 | - ], |
|
500 | - 'events_categories_other_help_tab' => [ |
|
501 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
502 | - 'filename' => 'events_categories_other', |
|
503 | - ], |
|
504 | - ], |
|
505 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
506 | - 'require_nonce' => false, |
|
507 | - ], |
|
508 | - 'preview_deletion' => [ |
|
509 | - 'nav' => [ |
|
510 | - 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
511 | - 'order' => 15, |
|
512 | - 'persistent' => false, |
|
513 | - 'url' => '', |
|
514 | - ], |
|
515 | - 'require_nonce' => false, |
|
516 | - ], |
|
517 | - ]; |
|
518 | - } |
|
519 | - |
|
520 | - |
|
521 | - /** |
|
522 | - * Used to register any global screen options if necessary for every route in this admin page group. |
|
523 | - */ |
|
524 | - protected function _add_screen_options() |
|
525 | - { |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * Implementing the screen options for the 'default' route. |
|
531 | - */ |
|
532 | - protected function _add_screen_options_default() |
|
533 | - { |
|
534 | - $this->_per_page_screen_option(); |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - /** |
|
539 | - * Implementing screen options for the category list route. |
|
540 | - */ |
|
541 | - protected function _add_screen_options_category_list() |
|
542 | - { |
|
543 | - $page_title = $this->_admin_page_title; |
|
544 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
545 | - $this->_per_page_screen_option(); |
|
546 | - $this->_admin_page_title = $page_title; |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * Used to register any global feature pointers for the admin page group. |
|
552 | - */ |
|
553 | - protected function _add_feature_pointers() |
|
554 | - { |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
560 | - */ |
|
561 | - public function load_scripts_styles() |
|
562 | - { |
|
563 | - wp_register_style( |
|
564 | - 'events-admin-css', |
|
565 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
566 | - [], |
|
567 | - EVENT_ESPRESSO_VERSION |
|
568 | - ); |
|
569 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION); |
|
570 | - wp_enqueue_style('events-admin-css'); |
|
571 | - wp_enqueue_style('ee-cat-admin'); |
|
572 | - // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
573 | - // registers for all views |
|
574 | - // scripts |
|
575 | - wp_register_script( |
|
576 | - 'event_editor_js', |
|
577 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
578 | - ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
579 | - EVENT_ESPRESSO_VERSION, |
|
580 | - true |
|
581 | - ); |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * Enqueuing scripts and styles specific to this view |
|
587 | - */ |
|
588 | - public function load_scripts_styles_create_new() |
|
589 | - { |
|
590 | - $this->load_scripts_styles_edit(); |
|
591 | - } |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * Enqueuing scripts and styles specific to this view |
|
596 | - */ |
|
597 | - public function load_scripts_styles_edit() |
|
598 | - { |
|
599 | - // styles |
|
600 | - wp_enqueue_style('espresso-ui-theme'); |
|
601 | - wp_register_style( |
|
602 | - 'event-editor-css', |
|
603 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
604 | - ['ee-admin-css'], |
|
605 | - EVENT_ESPRESSO_VERSION |
|
606 | - ); |
|
607 | - wp_enqueue_style('event-editor-css'); |
|
608 | - // scripts |
|
609 | - wp_register_script( |
|
610 | - 'event-datetime-metabox', |
|
611 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
612 | - ['event_editor_js', 'ee-datepicker'], |
|
613 | - EVENT_ESPRESSO_VERSION |
|
614 | - ); |
|
615 | - wp_enqueue_script('event-datetime-metabox'); |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * Populating the _views property for the category list table view. |
|
621 | - */ |
|
622 | - protected function _set_list_table_views_category_list() |
|
623 | - { |
|
624 | - $this->_views = [ |
|
625 | - 'all' => [ |
|
626 | - 'slug' => 'all', |
|
627 | - 'label' => esc_html__('All', 'event_espresso'), |
|
628 | - 'count' => 0, |
|
629 | - 'bulk_action' => [ |
|
630 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
631 | - ], |
|
632 | - ], |
|
633 | - ]; |
|
634 | - } |
|
635 | - |
|
636 | - |
|
637 | - /** |
|
638 | - * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
639 | - */ |
|
640 | - public function admin_init() |
|
641 | - { |
|
642 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
643 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
644 | - 'event_espresso' |
|
645 | - ); |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
651 | - * group. |
|
652 | - */ |
|
653 | - public function admin_notices() |
|
654 | - { |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
660 | - * this admin page group. |
|
661 | - */ |
|
662 | - public function admin_footer_scripts() |
|
663 | - { |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - /** |
|
668 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
669 | - * warning (via EE_Error::add_error()); |
|
670 | - * |
|
671 | - * @param EE_Event $event Event object |
|
672 | - * @param string $req_type |
|
673 | - * @return void |
|
674 | - * @throws EE_Error |
|
675 | - * @throws ReflectionException |
|
676 | - */ |
|
677 | - public function verify_event_edit($event = null, $req_type = '') |
|
678 | - { |
|
679 | - // don't need to do this when processing |
|
680 | - if (! empty($req_type)) { |
|
681 | - return; |
|
682 | - } |
|
683 | - // no event? |
|
684 | - if (empty($event)) { |
|
685 | - // set event |
|
686 | - $event = $this->_cpt_model_obj; |
|
687 | - } |
|
688 | - // STILL no event? |
|
689 | - if (! $event instanceof EE_Event) { |
|
690 | - return; |
|
691 | - } |
|
692 | - $orig_status = $event->status(); |
|
693 | - // first check if event is active. |
|
694 | - if ( |
|
695 | - $orig_status === EEM_Event::cancelled |
|
696 | - || $orig_status === EEM_Event::postponed |
|
697 | - || $event->is_expired() |
|
698 | - || $event->is_inactive() |
|
699 | - ) { |
|
700 | - return; |
|
701 | - } |
|
702 | - // made it here so it IS active... next check that any of the tickets are sold. |
|
703 | - if ($event->is_sold_out(true)) { |
|
704 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
705 | - EE_Error::add_attention( |
|
706 | - sprintf( |
|
707 | - esc_html__( |
|
708 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
709 | - 'event_espresso' |
|
710 | - ), |
|
711 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
712 | - ) |
|
713 | - ); |
|
714 | - } |
|
715 | - return; |
|
716 | - } elseif ($orig_status === EEM_Event::sold_out) { |
|
717 | - EE_Error::add_attention( |
|
718 | - sprintf( |
|
719 | - esc_html__( |
|
720 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
721 | - 'event_espresso' |
|
722 | - ), |
|
723 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
724 | - ) |
|
725 | - ); |
|
726 | - } |
|
727 | - // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
728 | - if (! $event->tickets_on_sale()) { |
|
729 | - return; |
|
730 | - } |
|
731 | - // made it here so show warning |
|
732 | - $this->_edit_event_warning(); |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
738 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
739 | - * |
|
740 | - * @access protected |
|
741 | - * @return void |
|
742 | - */ |
|
743 | - protected function _edit_event_warning() |
|
744 | - { |
|
745 | - // we don't want to add warnings during these requests |
|
746 | - if ($this->request->getRequestParam('action') === 'editpost') { |
|
747 | - return; |
|
748 | - } |
|
749 | - EE_Error::add_attention( |
|
750 | - sprintf( |
|
751 | - esc_html__( |
|
752 | - 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
753 | - 'event_espresso' |
|
754 | - ), |
|
755 | - '<a class="espresso-help-tab-lnk">', |
|
756 | - '</a>' |
|
757 | - ) |
|
758 | - ); |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - /** |
|
763 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
764 | - * Otherwise, do the normal logic |
|
765 | - * |
|
766 | - * @return void |
|
767 | - * @throws EE_Error |
|
768 | - */ |
|
769 | - protected function _create_new_cpt_item() |
|
770 | - { |
|
771 | - $has_timezone_string = get_option('timezone_string'); |
|
772 | - // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
773 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
774 | - EE_Error::add_attention( |
|
775 | - sprintf( |
|
776 | - esc_html__( |
|
777 | - 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
778 | - 'event_espresso' |
|
779 | - ), |
|
780 | - '<br>', |
|
781 | - '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
782 | - . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
783 | - . '</select>', |
|
784 | - '<button class="button button-secondary timezone-submit">', |
|
785 | - '</button><span class="spinner"></span>' |
|
786 | - ), |
|
787 | - __FILE__, |
|
788 | - __FUNCTION__, |
|
789 | - __LINE__ |
|
790 | - ); |
|
791 | - } |
|
792 | - parent::_create_new_cpt_item(); |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * Sets the _views property for the default route in this admin page group. |
|
798 | - */ |
|
799 | - protected function _set_list_table_views_default() |
|
800 | - { |
|
801 | - $this->_views = [ |
|
802 | - 'all' => [ |
|
803 | - 'slug' => 'all', |
|
804 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
805 | - 'count' => 0, |
|
806 | - 'bulk_action' => [ |
|
807 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
808 | - ], |
|
809 | - ], |
|
810 | - 'draft' => [ |
|
811 | - 'slug' => 'draft', |
|
812 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
813 | - 'count' => 0, |
|
814 | - 'bulk_action' => [ |
|
815 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
816 | - ], |
|
817 | - ], |
|
818 | - ]; |
|
819 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
820 | - $this->_views['trash'] = [ |
|
821 | - 'slug' => 'trash', |
|
822 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
823 | - 'count' => 0, |
|
824 | - 'bulk_action' => [ |
|
825 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
826 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
827 | - ], |
|
828 | - ]; |
|
829 | - } |
|
830 | - } |
|
831 | - |
|
832 | - |
|
833 | - /** |
|
834 | - * Provides the legend item array for the default list table view. |
|
835 | - * |
|
836 | - * @return array |
|
837 | - * @throws EE_Error |
|
838 | - * @throws EE_Error |
|
839 | - */ |
|
840 | - protected function _event_legend_items() |
|
841 | - { |
|
842 | - $items = [ |
|
843 | - 'view_details' => [ |
|
844 | - 'class' => 'dashicons dashicons-search', |
|
845 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
846 | - ], |
|
847 | - 'edit_event' => [ |
|
848 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
849 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
850 | - ], |
|
851 | - 'view_attendees' => [ |
|
852 | - 'class' => 'dashicons dashicons-groups', |
|
853 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
854 | - ], |
|
855 | - ]; |
|
856 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
857 | - $statuses = [ |
|
858 | - 'sold_out_status' => [ |
|
859 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
860 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
861 | - ], |
|
862 | - 'active_status' => [ |
|
863 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
864 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
865 | - ], |
|
866 | - 'upcoming_status' => [ |
|
867 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
868 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
869 | - ], |
|
870 | - 'postponed_status' => [ |
|
871 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
872 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
873 | - ], |
|
874 | - 'cancelled_status' => [ |
|
875 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
876 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
877 | - ], |
|
878 | - 'expired_status' => [ |
|
879 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
880 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
881 | - ], |
|
882 | - 'inactive_status' => [ |
|
883 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
884 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
885 | - ], |
|
886 | - ]; |
|
887 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
888 | - return array_merge($items, $statuses); |
|
889 | - } |
|
890 | - |
|
891 | - |
|
892 | - /** |
|
893 | - * @return EEM_Event |
|
894 | - * @throws EE_Error |
|
895 | - * @throws ReflectionException |
|
896 | - */ |
|
897 | - private function _event_model() |
|
898 | - { |
|
899 | - if (! $this->_event_model instanceof EEM_Event) { |
|
900 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
901 | - } |
|
902 | - return $this->_event_model; |
|
903 | - } |
|
904 | - |
|
905 | - |
|
906 | - /** |
|
907 | - * Adds extra buttons to the WP CPT permalink field row. |
|
908 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
909 | - * |
|
910 | - * @param string $return the current html |
|
911 | - * @param int $id the post id for the page |
|
912 | - * @param string $new_title What the title is |
|
913 | - * @param string $new_slug what the slug is |
|
914 | - * @return string The new html string for the permalink area |
|
915 | - */ |
|
916 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
917 | - { |
|
918 | - // make sure this is only when editing |
|
919 | - if (! empty($id)) { |
|
920 | - $post = get_post($id); |
|
921 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
922 | - . esc_html__('Shortcode', 'event_espresso') |
|
923 | - . '</a> '; |
|
924 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
925 | - . $post->ID |
|
926 | - . ']">'; |
|
927 | - } |
|
928 | - return $return; |
|
929 | - } |
|
930 | - |
|
931 | - |
|
932 | - /** |
|
933 | - * _events_overview_list_table |
|
934 | - * This contains the logic for showing the events_overview list |
|
935 | - * |
|
936 | - * @access protected |
|
937 | - * @return void |
|
938 | - * @throws EE_Error |
|
939 | - */ |
|
940 | - protected function _events_overview_list_table() |
|
941 | - { |
|
942 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
943 | - $this->_template_args['after_list_table'] = |
|
944 | - ! empty($this->_template_args['after_list_table']) |
|
945 | - ? (array) $this->_template_args['after_list_table'] |
|
946 | - : []; |
|
947 | - $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
948 | - . EEH_Template::get_button_or_link( |
|
949 | - get_post_type_archive_link('espresso_events'), |
|
950 | - esc_html__("View Event Archive Page", "event_espresso"), |
|
951 | - 'button' |
|
952 | - ); |
|
953 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend( |
|
954 | - $this->_event_legend_items() |
|
955 | - ); |
|
956 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
957 | - 'create_new', |
|
958 | - 'add', |
|
959 | - [], |
|
960 | - 'add-new-h2' |
|
961 | - ); |
|
962 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
963 | - } |
|
964 | - |
|
965 | - |
|
966 | - /** |
|
967 | - * this allows for extra misc actions in the default WP publish box |
|
968 | - * |
|
969 | - * @return void |
|
970 | - * @throws EE_Error |
|
971 | - * @throws ReflectionException |
|
972 | - */ |
|
973 | - public function extra_misc_actions_publish_box() |
|
974 | - { |
|
975 | - $this->_generate_publish_box_extra_content(); |
|
976 | - } |
|
977 | - |
|
978 | - |
|
979 | - /** |
|
980 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
981 | - * saved. |
|
982 | - * Typically you would use this to save any additional data. |
|
983 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
984 | - * ALSO very important. When a post transitions from scheduled to published, |
|
985 | - * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
986 | - * other meta saves. So MAKE sure that you handle this accordingly. |
|
987 | - * |
|
988 | - * @access protected |
|
989 | - * @abstract |
|
990 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
991 | - * @param object $post The post object of the cpt that was saved. |
|
992 | - * @return void |
|
993 | - * @throws EE_Error |
|
994 | - * @throws ReflectionException |
|
995 | - */ |
|
996 | - protected function _insert_update_cpt_item($post_id, $post) |
|
997 | - { |
|
998 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
999 | - // get out we're not processing an event save. |
|
1000 | - return; |
|
1001 | - } |
|
1002 | - |
|
1003 | - $event_values = [ |
|
1004 | - 'EVT_display_desc' => $this->request->getRequestParam('display_desc', false, 'bool'), |
|
1005 | - 'EVT_display_ticket_selector' => $this->request->getRequestParam( |
|
1006 | - 'display_ticket_selector', |
|
1007 | - false, |
|
1008 | - 'bool' |
|
1009 | - ), |
|
1010 | - 'EVT_additional_limit' => min( |
|
1011 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
1012 | - $this->request->getRequestParam('additional_limit', null, 'int') |
|
1013 | - ), |
|
1014 | - 'EVT_default_registration_status' => $this->request->getRequestParam( |
|
1015 | - 'EVT_default_registration_status', |
|
1016 | - EE_Registry::instance()->CFG->registration->default_STS_ID |
|
1017 | - ), |
|
1018 | - |
|
1019 | - 'EVT_member_only' => $this->request->getRequestParam('member_only', false, 'bool'), |
|
1020 | - 'EVT_allow_overflow' => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'), |
|
1021 | - 'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'), |
|
1022 | - 'EVT_external_URL' => $this->request->getRequestParam('externalURL'), |
|
1023 | - 'EVT_phone' => $this->request->getRequestParam('event_phone'), |
|
1024 | - ]; |
|
1025 | - // update event |
|
1026 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
1027 | - // get event_object for other metaboxes... |
|
1028 | - // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. |
|
1029 | - // i have to setup where conditions to override the filters in the model |
|
1030 | - // that filter out autodraft and inherit statuses so we GET the inherit id! |
|
1031 | - $event = $this->_event_model()->get_one( |
|
1032 | - [ |
|
1033 | - [ |
|
1034 | - $this->_event_model()->primary_key_name() => $post_id, |
|
1035 | - 'OR' => [ |
|
1036 | - 'status' => $post->post_status, |
|
1037 | - // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
1038 | - // but the returned object here has a status of "publish", so use the original post status as well |
|
1039 | - 'status*1' => $this->request->getRequestParam('original_post_status'), |
|
1040 | - ], |
|
1041 | - ], |
|
1042 | - ] |
|
1043 | - ); |
|
1044 | - // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
1045 | - $event_update_callbacks = apply_filters( |
|
1046 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
1047 | - [ |
|
1048 | - [$this, '_default_venue_update'], |
|
1049 | - [$this, '_default_tickets_update'], |
|
1050 | - ] |
|
1051 | - ); |
|
1052 | - $att_success = true; |
|
1053 | - foreach ($event_update_callbacks as $e_callback) { |
|
1054 | - $_success = is_callable($e_callback) |
|
1055 | - ? call_user_func($e_callback, $event, $this->request->requestParams()) |
|
1056 | - : false; |
|
1057 | - // if ANY of these updates fail then we want the appropriate global error message |
|
1058 | - $att_success = ! $att_success ? $att_success : $_success; |
|
1059 | - } |
|
1060 | - // any errors? |
|
1061 | - if ($success && false === $att_success) { |
|
1062 | - EE_Error::add_error( |
|
1063 | - esc_html__( |
|
1064 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
1065 | - 'event_espresso' |
|
1066 | - ), |
|
1067 | - __FILE__, |
|
1068 | - __FUNCTION__, |
|
1069 | - __LINE__ |
|
1070 | - ); |
|
1071 | - } elseif ($success === false) { |
|
1072 | - EE_Error::add_error( |
|
1073 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
1074 | - __FILE__, |
|
1075 | - __FUNCTION__, |
|
1076 | - __LINE__ |
|
1077 | - ); |
|
1078 | - } |
|
1079 | - } |
|
1080 | - |
|
1081 | - |
|
1082 | - /** |
|
1083 | - * @param int $post_id |
|
1084 | - * @param int $revision_id |
|
1085 | - * @throws EE_Error |
|
1086 | - * @throws EE_Error |
|
1087 | - * @throws ReflectionException |
|
1088 | - * @see parent::restore_item() |
|
1089 | - */ |
|
1090 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
1091 | - { |
|
1092 | - // copy existing event meta to new post |
|
1093 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
1094 | - if ($post_evt instanceof EE_Event) { |
|
1095 | - // meta revision restore |
|
1096 | - $post_evt->restore_revision($revision_id); |
|
1097 | - // related objs restore |
|
1098 | - $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
1099 | - } |
|
1100 | - } |
|
1101 | - |
|
1102 | - |
|
1103 | - /** |
|
1104 | - * Attach the venue to the Event |
|
1105 | - * |
|
1106 | - * @param EE_Event $event Event Object to add the venue to |
|
1107 | - * @param array $data The request data from the form |
|
1108 | - * @return bool Success or fail. |
|
1109 | - * @throws EE_Error |
|
1110 | - * @throws ReflectionException |
|
1111 | - */ |
|
1112 | - protected function _default_venue_update(EE_Event $event, $data) |
|
1113 | - { |
|
1114 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
1115 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
1116 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
1117 | - // very important. If we don't have a venue name... |
|
1118 | - // then we'll get out because not necessary to create empty venue |
|
1119 | - if (empty($data['venue_title'])) { |
|
1120 | - return false; |
|
1121 | - } |
|
1122 | - $venue_array = [ |
|
1123 | - 'VNU_wp_user' => $event->get('EVT_wp_user'), |
|
1124 | - 'VNU_name' => $data['venue_title'], |
|
1125 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
1126 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
1127 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) |
|
1128 | - ? $data['venue_short_description'] |
|
1129 | - : null, |
|
1130 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
1131 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
1132 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
1133 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
1134 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
1135 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
1136 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
1137 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
1138 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
1139 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
1140 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
1141 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
1142 | - 'status' => 'publish', |
|
1143 | - ]; |
|
1144 | - // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
1145 | - if (! empty($venue_id)) { |
|
1146 | - $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
1147 | - $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
1148 | - // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
1149 | - $event->_add_relation_to($venue_id, 'Venue'); |
|
1150 | - return $rows_affected > 0; |
|
1151 | - } |
|
1152 | - // we insert the venue |
|
1153 | - $venue_id = $venue_model->insert($venue_array); |
|
1154 | - $event->_add_relation_to($venue_id, 'Venue'); |
|
1155 | - return ! empty($venue_id); |
|
1156 | - // when we have the ancestor come in it's already been handled by the revision save. |
|
1157 | - } |
|
1158 | - |
|
1159 | - |
|
1160 | - /** |
|
1161 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
1162 | - * |
|
1163 | - * @param EE_Event $event The Event object we're attaching data to |
|
1164 | - * @param array $data The request data from the form |
|
1165 | - * @return array |
|
1166 | - * @throws EE_Error |
|
1167 | - * @throws ReflectionException |
|
1168 | - * @throws Exception |
|
1169 | - */ |
|
1170 | - protected function _default_tickets_update(EE_Event $event, $data) |
|
1171 | - { |
|
1172 | - $datetime = null; |
|
1173 | - $saved_tickets = []; |
|
1174 | - $event_timezone = $event->get_timezone(); |
|
1175 | - $date_formats = ['Y-m-d', 'h:i a']; |
|
1176 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
1177 | - // trim all values to ensure any excess whitespace is removed. |
|
1178 | - $datetime_data = array_map('trim', $datetime_data); |
|
1179 | - $datetime_data['DTT_EVT_end'] = |
|
1180 | - isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end']) |
|
1181 | - ? $datetime_data['DTT_EVT_end'] |
|
1182 | - : $datetime_data['DTT_EVT_start']; |
|
1183 | - $datetime_values = [ |
|
1184 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null, |
|
1185 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
1186 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
1187 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'], |
|
1188 | - 'DTT_order' => $row, |
|
1189 | - ]; |
|
1190 | - // if we have an id then let's get existing object first and then set the new values. |
|
1191 | - // Otherwise we instantiate a new object for save. |
|
1192 | - if (! empty($datetime_data['DTT_ID'])) { |
|
1193 | - $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']); |
|
1194 | - if (! $datetime instanceof EE_Datetime) { |
|
1195 | - throw new RuntimeException( |
|
1196 | - sprintf( |
|
1197 | - esc_html__( |
|
1198 | - 'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d', |
|
1199 | - 'event_espresso' |
|
1200 | - ), |
|
1201 | - $datetime_data['DTT_ID'] |
|
1202 | - ) |
|
1203 | - ); |
|
1204 | - } |
|
1205 | - $datetime->set_date_format($date_formats[0]); |
|
1206 | - $datetime->set_time_format($date_formats[1]); |
|
1207 | - foreach ($datetime_values as $field => $value) { |
|
1208 | - $datetime->set($field, $value); |
|
1209 | - } |
|
1210 | - } else { |
|
1211 | - $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats); |
|
1212 | - } |
|
1213 | - if (! $datetime instanceof EE_Datetime) { |
|
1214 | - throw new RuntimeException( |
|
1215 | - sprintf( |
|
1216 | - esc_html__( |
|
1217 | - 'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s', |
|
1218 | - 'event_espresso' |
|
1219 | - ), |
|
1220 | - print_r($datetime_values, true) |
|
1221 | - ) |
|
1222 | - ); |
|
1223 | - } |
|
1224 | - // before going any further make sure our dates are setup correctly |
|
1225 | - // so that the end date is always equal or greater than the start date. |
|
1226 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
1227 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
1228 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
1229 | - } |
|
1230 | - $datetime->save(); |
|
1231 | - $event->_add_relation_to($datetime, 'Datetime'); |
|
1232 | - } |
|
1233 | - // no datetimes get deleted so we don't do any of that logic here. |
|
1234 | - // update tickets next |
|
1235 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
1236 | - |
|
1237 | - // set up some default start and end dates in case those are not present in the incoming data |
|
1238 | - $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
1239 | - $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]); |
|
1240 | - // use the start date of the first datetime for the end date |
|
1241 | - $first_datetime = $event->first_datetime(); |
|
1242 | - $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]); |
|
1243 | - |
|
1244 | - // now process the incoming data |
|
1245 | - foreach ($data['edit_tickets'] as $row => $ticket_data) { |
|
1246 | - $update_prices = false; |
|
1247 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
1248 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] |
|
1249 | - : 0; |
|
1250 | - // trim inputs to ensure any excess whitespace is removed. |
|
1251 | - $ticket_data = array_map('trim', $ticket_data); |
|
1252 | - $ticket_values = [ |
|
1253 | - 'TKT_ID' => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null, |
|
1254 | - 'TTM_ID' => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0, |
|
1255 | - 'TKT_name' => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '', |
|
1256 | - 'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '', |
|
1257 | - 'TKT_start_date' => ! empty($ticket_data['TKT_start_date']) |
|
1258 | - ? $ticket_data['TKT_start_date'] |
|
1259 | - : $default_start_date, |
|
1260 | - 'TKT_end_date' => ! empty($ticket_data['TKT_end_date']) |
|
1261 | - ? $ticket_data['TKT_end_date'] |
|
1262 | - : $default_end_date, |
|
1263 | - 'TKT_qty' => ! empty($ticket_data['TKT_qty']) |
|
1264 | - || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0) |
|
1265 | - ? $ticket_data['TKT_qty'] |
|
1266 | - : EE_INF, |
|
1267 | - 'TKT_uses' => ! empty($ticket_data['TKT_uses']) |
|
1268 | - || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0) |
|
1269 | - ? $ticket_data['TKT_uses'] |
|
1270 | - : EE_INF, |
|
1271 | - 'TKT_min' => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0, |
|
1272 | - 'TKT_max' => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF, |
|
1273 | - 'TKT_order' => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row, |
|
1274 | - 'TKT_price' => $ticket_price, |
|
1275 | - 'TKT_row' => $row, |
|
1276 | - ]; |
|
1277 | - // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly, |
|
1278 | - // which means in turn that the prices will become new prices as well. |
|
1279 | - if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) { |
|
1280 | - $ticket_values['TKT_ID'] = 0; |
|
1281 | - $ticket_values['TKT_is_default'] = 0; |
|
1282 | - $update_prices = true; |
|
1283 | - } |
|
1284 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
1285 | - // we actually do our saves ahead of adding any relations because its entirely possible that this |
|
1286 | - // ticket didn't get removed or added to any datetime in the session but DID have it's items modified. |
|
1287 | - // keep in mind that if the ticket has been sold (and we have changed pricing information), |
|
1288 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
1289 | - if (! empty($ticket_data['TKT_ID'])) { |
|
1290 | - $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']); |
|
1291 | - if (! $existing_ticket instanceof EE_Ticket) { |
|
1292 | - throw new RuntimeException( |
|
1293 | - sprintf( |
|
1294 | - esc_html__( |
|
1295 | - 'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d', |
|
1296 | - 'event_espresso' |
|
1297 | - ), |
|
1298 | - $ticket_data['TKT_ID'] |
|
1299 | - ) |
|
1300 | - ); |
|
1301 | - } |
|
1302 | - $ticket_sold = $existing_ticket->count_related( |
|
1303 | - 'Registration', |
|
1304 | - [ |
|
1305 | - [ |
|
1306 | - 'STS_ID' => [ |
|
1307 | - 'NOT IN', |
|
1308 | - [EEM_Registration::status_id_incomplete], |
|
1309 | - ], |
|
1310 | - ], |
|
1311 | - ] |
|
1312 | - ) > 0; |
|
1313 | - // let's just check the total price for the existing ticket and determine if it matches the new total price. |
|
1314 | - // if they are different then we create a new ticket (if $ticket_sold) |
|
1315 | - // if they aren't different then we go ahead and modify existing ticket. |
|
1316 | - $create_new_ticket = $ticket_sold |
|
1317 | - && $ticket_price !== $existing_ticket->price() |
|
1318 | - && ! $existing_ticket->deleted(); |
|
1319 | - $existing_ticket->set_date_format($date_formats[0]); |
|
1320 | - $existing_ticket->set_time_format($date_formats[1]); |
|
1321 | - // set new values |
|
1322 | - foreach ($ticket_values as $field => $value) { |
|
1323 | - if ($field == 'TKT_qty') { |
|
1324 | - $existing_ticket->set_qty($value); |
|
1325 | - } elseif ($field == 'TKT_price') { |
|
1326 | - $existing_ticket->set('TKT_price', $ticket_price); |
|
1327 | - } else { |
|
1328 | - $existing_ticket->set($field, $value); |
|
1329 | - } |
|
1330 | - } |
|
1331 | - $ticket = $existing_ticket; |
|
1332 | - // if $create_new_ticket is false then we can safely update the existing ticket. |
|
1333 | - // Otherwise we have to create a new ticket. |
|
1334 | - if ($create_new_ticket) { |
|
1335 | - // archive the old ticket first |
|
1336 | - $existing_ticket->set('TKT_deleted', 1); |
|
1337 | - $existing_ticket->save(); |
|
1338 | - // make sure this ticket is still recorded in our $saved_tickets |
|
1339 | - // so we don't run it through the regular trash routine. |
|
1340 | - $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket; |
|
1341 | - // create new ticket that's a copy of the existing except, |
|
1342 | - // (a new id of course and not archived) AND has the new TKT_price associated with it. |
|
1343 | - $new_ticket = clone $existing_ticket; |
|
1344 | - $new_ticket->set('TKT_ID', 0); |
|
1345 | - $new_ticket->set('TKT_deleted', 0); |
|
1346 | - $new_ticket->set('TKT_sold', 0); |
|
1347 | - // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
1348 | - $update_prices = true; |
|
1349 | - $ticket = $new_ticket; |
|
1350 | - } |
|
1351 | - } else { |
|
1352 | - // no TKT_id so a new ticket |
|
1353 | - $ticket_values['TKT_price'] = $ticket_price; |
|
1354 | - $ticket = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats); |
|
1355 | - $update_prices = true; |
|
1356 | - } |
|
1357 | - if (! $ticket instanceof EE_Ticket) { |
|
1358 | - throw new RuntimeException( |
|
1359 | - sprintf( |
|
1360 | - esc_html__( |
|
1361 | - 'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s', |
|
1362 | - 'event_espresso' |
|
1363 | - ), |
|
1364 | - print_r($ticket_values, true) |
|
1365 | - ) |
|
1366 | - ); |
|
1367 | - } |
|
1368 | - // cap ticket qty by datetime reg limits |
|
1369 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
1370 | - // update ticket. |
|
1371 | - $ticket->save(); |
|
1372 | - // before going any further make sure our dates are setup correctly |
|
1373 | - // so that the end date is always equal or greater than the start date. |
|
1374 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
1375 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
1376 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
1377 | - $ticket->save(); |
|
1378 | - } |
|
1379 | - // initially let's add the ticket to the datetime |
|
1380 | - $datetime->_add_relation_to($ticket, 'Ticket'); |
|
1381 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
1382 | - // add prices to ticket |
|
1383 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices); |
|
1384 | - } |
|
1385 | - // however now we need to handle permanently deleting tickets via the ui. |
|
1386 | - // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
|
1387 | - // However, it does allow for deleting tickets that have no tickets sold, |
|
1388 | - // in which case we want to get rid of permanently because there is no need to save in db. |
|
1389 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets; |
|
1390 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
1391 | - foreach ($tickets_removed as $id) { |
|
1392 | - $id = absint($id); |
|
1393 | - // get the ticket for this id |
|
1394 | - $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
|
1395 | - if (! $ticket_to_remove instanceof EE_Ticket) { |
|
1396 | - continue; |
|
1397 | - } |
|
1398 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
1399 | - // (remember this process can ONLY kick off if there are NO tickets sold) |
|
1400 | - $related_datetimes = $ticket_to_remove->get_many_related('Datetime'); |
|
1401 | - foreach ($related_datetimes as $related_datetime) { |
|
1402 | - $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime'); |
|
1403 | - } |
|
1404 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
1405 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
1406 | - $ticket_to_remove->delete_related_permanently('Price'); |
|
1407 | - // finally let's delete this ticket |
|
1408 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
1409 | - $ticket_to_remove->delete_permanently(); |
|
1410 | - } |
|
1411 | - return [$datetime, $saved_tickets]; |
|
1412 | - } |
|
1413 | - |
|
1414 | - |
|
1415 | - /** |
|
1416 | - * This attaches a list of given prices to a ticket. |
|
1417 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
1418 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
1419 | - * price info and prices are automatically "archived" via the ticket. |
|
1420 | - * |
|
1421 | - * @access private |
|
1422 | - * @param array $prices_data Array of prices from the form. |
|
1423 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
1424 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
1425 | - * @return void |
|
1426 | - * @throws EE_Error |
|
1427 | - * @throws ReflectionException |
|
1428 | - */ |
|
1429 | - private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false) |
|
1430 | - { |
|
1431 | - $timezone = $ticket->get_timezone(); |
|
1432 | - foreach ($prices_data as $row => $price_data) { |
|
1433 | - $price_values = [ |
|
1434 | - 'PRC_ID' => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null, |
|
1435 | - 'PRT_ID' => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null, |
|
1436 | - 'PRC_amount' => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0, |
|
1437 | - 'PRC_name' => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '', |
|
1438 | - 'PRC_desc' => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '', |
|
1439 | - 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
1440 | - 'PRC_order' => $row, |
|
1441 | - ]; |
|
1442 | - if ($new_prices || empty($price_values['PRC_ID'])) { |
|
1443 | - $price_values['PRC_ID'] = 0; |
|
1444 | - $price = EE_Price::new_instance($price_values, $timezone); |
|
1445 | - } else { |
|
1446 | - $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']); |
|
1447 | - // update this price with new values |
|
1448 | - foreach ($price_values as $field => $new_price) { |
|
1449 | - $price->set($field, $new_price); |
|
1450 | - } |
|
1451 | - } |
|
1452 | - if (! $price instanceof EE_Price) { |
|
1453 | - throw new RuntimeException( |
|
1454 | - sprintf( |
|
1455 | - esc_html__( |
|
1456 | - 'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s', |
|
1457 | - 'event_espresso' |
|
1458 | - ), |
|
1459 | - print_r($price_values, true) |
|
1460 | - ) |
|
1461 | - ); |
|
1462 | - } |
|
1463 | - $price->save(); |
|
1464 | - $ticket->_add_relation_to($price, 'Price'); |
|
1465 | - } |
|
1466 | - } |
|
1467 | - |
|
1468 | - |
|
1469 | - /** |
|
1470 | - * Add in our autosave ajax handlers |
|
1471 | - * |
|
1472 | - */ |
|
1473 | - protected function _ee_autosave_create_new() |
|
1474 | - { |
|
1475 | - } |
|
1476 | - |
|
1477 | - |
|
1478 | - /** |
|
1479 | - * More autosave handlers. |
|
1480 | - */ |
|
1481 | - protected function _ee_autosave_edit() |
|
1482 | - { |
|
1483 | - // TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
1484 | - } |
|
1485 | - |
|
1486 | - |
|
1487 | - /** |
|
1488 | - * @throws EE_Error |
|
1489 | - * @throws ReflectionException |
|
1490 | - */ |
|
1491 | - private function _generate_publish_box_extra_content() |
|
1492 | - { |
|
1493 | - // load formatter helper |
|
1494 | - // args for getting related registrations |
|
1495 | - $approved_query_args = [ |
|
1496 | - [ |
|
1497 | - 'REG_deleted' => 0, |
|
1498 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
1499 | - ], |
|
1500 | - ]; |
|
1501 | - $not_approved_query_args = [ |
|
1502 | - [ |
|
1503 | - 'REG_deleted' => 0, |
|
1504 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
1505 | - ], |
|
1506 | - ]; |
|
1507 | - $pending_payment_query_args = [ |
|
1508 | - [ |
|
1509 | - 'REG_deleted' => 0, |
|
1510 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
1511 | - ], |
|
1512 | - ]; |
|
1513 | - // publish box |
|
1514 | - $publish_box_extra_args = [ |
|
1515 | - 'view_approved_reg_url' => add_query_arg( |
|
1516 | - [ |
|
1517 | - 'action' => 'default', |
|
1518 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1519 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1520 | - ], |
|
1521 | - REG_ADMIN_URL |
|
1522 | - ), |
|
1523 | - 'view_not_approved_reg_url' => add_query_arg( |
|
1524 | - [ |
|
1525 | - 'action' => 'default', |
|
1526 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1527 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1528 | - ], |
|
1529 | - REG_ADMIN_URL |
|
1530 | - ), |
|
1531 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
1532 | - [ |
|
1533 | - 'action' => 'default', |
|
1534 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1535 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1536 | - ], |
|
1537 | - REG_ADMIN_URL |
|
1538 | - ), |
|
1539 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
1540 | - 'Registration', |
|
1541 | - $approved_query_args |
|
1542 | - ), |
|
1543 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
1544 | - 'Registration', |
|
1545 | - $not_approved_query_args |
|
1546 | - ), |
|
1547 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
1548 | - 'Registration', |
|
1549 | - $pending_payment_query_args |
|
1550 | - ), |
|
1551 | - 'misc_pub_section_class' => apply_filters( |
|
1552 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
1553 | - 'misc-pub-section' |
|
1554 | - ), |
|
1555 | - ]; |
|
1556 | - ob_start(); |
|
1557 | - do_action( |
|
1558 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
1559 | - $this->_cpt_model_obj |
|
1560 | - ); |
|
1561 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
1562 | - // load template |
|
1563 | - EEH_Template::display_template( |
|
1564 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
1565 | - $publish_box_extra_args |
|
1566 | - ); |
|
1567 | - } |
|
1568 | - |
|
1569 | - |
|
1570 | - /** |
|
1571 | - * @return EE_Event |
|
1572 | - */ |
|
1573 | - public function get_event_object() |
|
1574 | - { |
|
1575 | - return $this->_cpt_model_obj; |
|
1576 | - } |
|
1577 | - |
|
1578 | - |
|
1579 | - |
|
1580 | - |
|
1581 | - /** METABOXES * */ |
|
1582 | - /** |
|
1583 | - * _register_event_editor_meta_boxes |
|
1584 | - * add all metaboxes related to the event_editor |
|
1585 | - * |
|
1586 | - * @return void |
|
1587 | - * @throws EE_Error |
|
1588 | - * @throws ReflectionException |
|
1589 | - */ |
|
1590 | - protected function _register_event_editor_meta_boxes() |
|
1591 | - { |
|
1592 | - $this->verify_cpt_object(); |
|
1593 | - add_meta_box( |
|
1594 | - 'espresso_event_editor_tickets', |
|
1595 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
1596 | - [$this, 'ticket_metabox'], |
|
1597 | - $this->page_slug, |
|
1598 | - 'normal', |
|
1599 | - 'high' |
|
1600 | - ); |
|
1601 | - add_meta_box( |
|
1602 | - 'espresso_event_editor_event_options', |
|
1603 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
1604 | - [$this, 'registration_options_meta_box'], |
|
1605 | - $this->page_slug, |
|
1606 | - 'side' |
|
1607 | - ); |
|
1608 | - // NOTE: if you're looking for other metaboxes in here, |
|
1609 | - // where a metabox has a related management page in the admin |
|
1610 | - // you will find it setup in the related management page's "_Hooks" file. |
|
1611 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
1612 | - } |
|
1613 | - |
|
1614 | - |
|
1615 | - /** |
|
1616 | - * @throws DomainException |
|
1617 | - * @throws EE_Error |
|
1618 | - * @throws ReflectionException |
|
1619 | - */ |
|
1620 | - public function ticket_metabox() |
|
1621 | - { |
|
1622 | - $existing_datetime_ids = $existing_ticket_ids = []; |
|
1623 | - // defaults for template args |
|
1624 | - $template_args = [ |
|
1625 | - 'existing_datetime_ids' => '', |
|
1626 | - 'event_datetime_help_link' => '', |
|
1627 | - 'ticket_options_help_link' => '', |
|
1628 | - 'time' => null, |
|
1629 | - 'ticket_rows' => '', |
|
1630 | - 'existing_ticket_ids' => '', |
|
1631 | - 'total_ticket_rows' => 1, |
|
1632 | - 'ticket_js_structure' => '', |
|
1633 | - 'trash_icon' => 'ee-lock-icon', |
|
1634 | - 'disabled' => '', |
|
1635 | - ]; |
|
1636 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
1637 | - /** |
|
1638 | - * 1. Start with retrieving Datetimes |
|
1639 | - * 2. Fore each datetime get related tickets |
|
1640 | - * 3. For each ticket get related prices |
|
1641 | - */ |
|
1642 | - $times = EEM_Datetime::instance()->get_all_event_dates($event_id); |
|
1643 | - $first_datetime = reset($times); |
|
1644 | - // do we get related tickets? |
|
1645 | - if ( |
|
1646 | - $first_datetime instanceof EE_Datetime |
|
1647 | - && $first_datetime->ID() !== 0 |
|
1648 | - ) { |
|
1649 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
1650 | - $template_args['time'] = $first_datetime; |
|
1651 | - $related_tickets = $first_datetime->tickets( |
|
1652 | - [ |
|
1653 | - ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
1654 | - 'default_where_conditions' => 'none', |
|
1655 | - ] |
|
1656 | - ); |
|
1657 | - if (! empty($related_tickets)) { |
|
1658 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
1659 | - $row = 0; |
|
1660 | - foreach ($related_tickets as $ticket) { |
|
1661 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
1662 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
1663 | - $row++; |
|
1664 | - } |
|
1665 | - } else { |
|
1666 | - $template_args['total_ticket_rows'] = 1; |
|
1667 | - /** @type EE_Ticket $ticket */ |
|
1668 | - $ticket = EEM_Ticket::instance()->create_default_object(); |
|
1669 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
1670 | - } |
|
1671 | - } else { |
|
1672 | - $template_args['time'] = $times[0]; |
|
1673 | - $tickets = EEM_Ticket::instance()->get_all_default_tickets(); |
|
1674 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
|
1675 | - // NOTE: we're just sending the first default row |
|
1676 | - // (decaf can't manage default tickets so this should be sufficient); |
|
1677 | - } |
|
1678 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
1679 | - 'event_editor_event_datetimes_help_tab' |
|
1680 | - ); |
|
1681 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
1682 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1683 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1684 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
1685 | - EEM_Ticket::instance()->create_default_object(), |
|
1686 | - true |
|
1687 | - ); |
|
1688 | - $template = apply_filters( |
|
1689 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
1690 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
1691 | - ); |
|
1692 | - EEH_Template::display_template($template, $template_args); |
|
1693 | - } |
|
1694 | - |
|
1695 | - |
|
1696 | - /** |
|
1697 | - * Setup an individual ticket form for the decaf event editor page |
|
1698 | - * |
|
1699 | - * @access private |
|
1700 | - * @param EE_Ticket $ticket the ticket object |
|
1701 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
1702 | - * @param int $row |
|
1703 | - * @return string generated html for the ticket row. |
|
1704 | - * @throws EE_Error |
|
1705 | - * @throws ReflectionException |
|
1706 | - */ |
|
1707 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
1708 | - { |
|
1709 | - $template_args = [ |
|
1710 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1711 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
1712 | - : '', |
|
1713 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
1714 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
1715 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
1716 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
1717 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
1718 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
1719 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
1720 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1721 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
1722 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1723 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1724 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
1725 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1726 | - : ' disabled=disabled', |
|
1727 | - ]; |
|
1728 | - $price = $ticket->ID() !== 0 |
|
1729 | - ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
1730 | - : null; |
|
1731 | - $price = $price instanceof EE_Price |
|
1732 | - ? $price |
|
1733 | - : EEM_Price::instance()->create_default_object(); |
|
1734 | - $price_args = [ |
|
1735 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1736 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
1737 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
1738 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
1739 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
1740 | - ]; |
|
1741 | - // make sure we have default start and end dates if skeleton |
|
1742 | - // handle rows that should NOT be empty |
|
1743 | - if (empty($template_args['TKT_start_date'])) { |
|
1744 | - // if empty then the start date will be now. |
|
1745 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
1746 | - } |
|
1747 | - if (empty($template_args['TKT_end_date'])) { |
|
1748 | - // get the earliest datetime (if present); |
|
1749 | - $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
1750 | - ? $this->_cpt_model_obj->get_first_related( |
|
1751 | - 'Datetime', |
|
1752 | - ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
1753 | - ) |
|
1754 | - : null; |
|
1755 | - $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime |
|
1756 | - ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a') |
|
1757 | - : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))); |
|
1758 | - } |
|
1759 | - $template_args = array_merge($template_args, $price_args); |
|
1760 | - $template = apply_filters( |
|
1761 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
1762 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
1763 | - $ticket |
|
1764 | - ); |
|
1765 | - return EEH_Template::display_template($template, $template_args, true); |
|
1766 | - } |
|
1767 | - |
|
1768 | - |
|
1769 | - /** |
|
1770 | - * @throws EE_Error |
|
1771 | - * @throws ReflectionException |
|
1772 | - */ |
|
1773 | - public function registration_options_meta_box() |
|
1774 | - { |
|
1775 | - $yes_no_values = [ |
|
1776 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
1777 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
1778 | - ]; |
|
1779 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
1780 | - [ |
|
1781 | - EEM_Registration::status_id_cancelled, |
|
1782 | - EEM_Registration::status_id_declined, |
|
1783 | - EEM_Registration::status_id_incomplete, |
|
1784 | - ], |
|
1785 | - true |
|
1786 | - ); |
|
1787 | - // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
1788 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
1789 | - $template_args['event'] = $this->_cpt_model_obj; |
|
1790 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
1791 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
1792 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
1793 | - 'default_reg_status', |
|
1794 | - $default_reg_status_values, |
|
1795 | - $this->_cpt_model_obj->default_registration_status() |
|
1796 | - ); |
|
1797 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
1798 | - 'display_desc', |
|
1799 | - $yes_no_values, |
|
1800 | - $this->_cpt_model_obj->display_description() |
|
1801 | - ); |
|
1802 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
1803 | - 'display_ticket_selector', |
|
1804 | - $yes_no_values, |
|
1805 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
1806 | - '', |
|
1807 | - '', |
|
1808 | - false |
|
1809 | - ); |
|
1810 | - $template_args['additional_registration_options'] = apply_filters( |
|
1811 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
1812 | - '', |
|
1813 | - $template_args, |
|
1814 | - $yes_no_values, |
|
1815 | - $default_reg_status_values |
|
1816 | - ); |
|
1817 | - EEH_Template::display_template( |
|
1818 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
1819 | - $template_args |
|
1820 | - ); |
|
1821 | - } |
|
1822 | - |
|
1823 | - |
|
1824 | - /** |
|
1825 | - * _get_events() |
|
1826 | - * This method simply returns all the events (for the given _view and paging) |
|
1827 | - * |
|
1828 | - * @access public |
|
1829 | - * @param int $per_page count of items per page (20 default); |
|
1830 | - * @param int $current_page what is the current page being viewed. |
|
1831 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
1832 | - * If FALSE then we return an array of event objects |
|
1833 | - * that match the given _view and paging parameters. |
|
1834 | - * @return array|int an array of event objects or a count of them. |
|
1835 | - * @throws Exception |
|
1836 | - */ |
|
1837 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
1838 | - { |
|
1839 | - $EEM_Event = $this->_event_model(); |
|
1840 | - $offset = ($current_page - 1) * $per_page; |
|
1841 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
1842 | - $orderby = $this->request->getRequestParam('orderby', 'EVT_ID'); |
|
1843 | - $order = $this->request->getRequestParam('order', 'DESC'); |
|
1844 | - $month_range = $this->request->getRequestParam('month_range'); |
|
1845 | - if ($month_range) { |
|
1846 | - $pieces = explode(' ', $month_range, 3); |
|
1847 | - // simulate the FIRST day of the month, that fixes issues for months like February |
|
1848 | - // where PHP doesn't know what to assume for date. |
|
1849 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
1850 | - $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
1851 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
1852 | - } |
|
1853 | - $where = []; |
|
1854 | - $status = $this->request->getRequestParam('status'); |
|
1855 | - // determine what post_status our condition will have for the query. |
|
1856 | - switch ($status) { |
|
1857 | - case 'month': |
|
1858 | - case 'today': |
|
1859 | - case null: |
|
1860 | - case 'all': |
|
1861 | - break; |
|
1862 | - case 'draft': |
|
1863 | - $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
1864 | - break; |
|
1865 | - default: |
|
1866 | - $where['status'] = $status; |
|
1867 | - } |
|
1868 | - // categories? The default for all categories is -1 |
|
1869 | - $category = $this->request->getRequestParam('EVT_CAT', -1, 'int'); |
|
1870 | - if ($category !== -1) { |
|
1871 | - $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
1872 | - $where['Term_Taxonomy.term_id'] = $category; |
|
1873 | - } |
|
1874 | - // date where conditions |
|
1875 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
1876 | - if ($month_range) { |
|
1877 | - $DateTime = new DateTime( |
|
1878 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
1879 | - new DateTimeZone('UTC') |
|
1880 | - ); |
|
1881 | - $start = $DateTime->getTimestamp(); |
|
1882 | - // set the datetime to be the end of the month |
|
1883 | - $DateTime->setDate( |
|
1884 | - $year_r, |
|
1885 | - $month_r, |
|
1886 | - $DateTime->format('t') |
|
1887 | - )->setTime(23, 59, 59); |
|
1888 | - $end = $DateTime->getTimestamp(); |
|
1889 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
1890 | - } elseif ($status === 'today') { |
|
1891 | - $DateTime = |
|
1892 | - new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1893 | - $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
1894 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1895 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
1896 | - } elseif ($status === 'month') { |
|
1897 | - $now = date('Y-m-01'); |
|
1898 | - $DateTime = |
|
1899 | - new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1900 | - $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
1901 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
1902 | - ->setTime(23, 59, 59) |
|
1903 | - ->format(implode(' ', $start_formats)); |
|
1904 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
1905 | - } |
|
1906 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1907 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
1908 | - } else { |
|
1909 | - if (! isset($where['status'])) { |
|
1910 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
1911 | - $where['OR'] = [ |
|
1912 | - 'status*restrict_private' => ['!=', 'private'], |
|
1913 | - 'AND' => [ |
|
1914 | - 'status*inclusive' => ['=', 'private'], |
|
1915 | - 'EVT_wp_user' => get_current_user_id(), |
|
1916 | - ], |
|
1917 | - ]; |
|
1918 | - } |
|
1919 | - } |
|
1920 | - } |
|
1921 | - $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int'); |
|
1922 | - if ( |
|
1923 | - $wp_user |
|
1924 | - && $wp_user !== get_current_user_id() |
|
1925 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
1926 | - ) { |
|
1927 | - $where['EVT_wp_user'] = $wp_user; |
|
1928 | - } |
|
1929 | - // search query handling |
|
1930 | - $search_term = $this->request->getRequestParam('s'); |
|
1931 | - if ($search_term) { |
|
1932 | - $search_term = '%' . $search_term . '%'; |
|
1933 | - $where['OR'] = [ |
|
1934 | - 'EVT_name' => ['LIKE', $search_term], |
|
1935 | - 'EVT_desc' => ['LIKE', $search_term], |
|
1936 | - 'EVT_short_desc' => ['LIKE', $search_term], |
|
1937 | - ]; |
|
1938 | - } |
|
1939 | - // filter events by venue. |
|
1940 | - $venue = $this->request->getRequestParam('venue', 0, 'int'); |
|
1941 | - if ($venue) { |
|
1942 | - $where['Venue.VNU_ID'] = $venue; |
|
1943 | - } |
|
1944 | - $request_params = $this->request->requestParams(); |
|
1945 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params); |
|
1946 | - $query_params = apply_filters( |
|
1947 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
1948 | - [ |
|
1949 | - $where, |
|
1950 | - 'limit' => $limit, |
|
1951 | - 'order_by' => $orderby, |
|
1952 | - 'order' => $order, |
|
1953 | - 'group_by' => 'EVT_ID', |
|
1954 | - ], |
|
1955 | - $request_params |
|
1956 | - ); |
|
1957 | - |
|
1958 | - // let's first check if we have special requests coming in. |
|
1959 | - $active_status = $this->request->getRequestParam('active_status'); |
|
1960 | - if ($active_status) { |
|
1961 | - switch ($active_status) { |
|
1962 | - case 'upcoming': |
|
1963 | - return $EEM_Event->get_upcoming_events($query_params, $count); |
|
1964 | - case 'expired': |
|
1965 | - return $EEM_Event->get_expired_events($query_params, $count); |
|
1966 | - case 'active': |
|
1967 | - return $EEM_Event->get_active_events($query_params, $count); |
|
1968 | - case 'inactive': |
|
1969 | - return $EEM_Event->get_inactive_events($query_params, $count); |
|
1970 | - } |
|
1971 | - } |
|
1972 | - |
|
1973 | - return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params); |
|
1974 | - } |
|
1975 | - |
|
1976 | - |
|
1977 | - /** |
|
1978 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
1979 | - * |
|
1980 | - * @param string $post_id |
|
1981 | - * @throws EE_Error |
|
1982 | - * @throws ReflectionException |
|
1983 | - */ |
|
1984 | - public function trash_cpt_item($post_id) |
|
1985 | - { |
|
1986 | - $this->request->setRequestParam('EVT_ID', $post_id); |
|
1987 | - $this->_trash_or_restore_event('trash', false); |
|
1988 | - } |
|
1989 | - |
|
1990 | - |
|
1991 | - /** |
|
1992 | - * @param string $post_id |
|
1993 | - * @throws EE_Error |
|
1994 | - * @throws ReflectionException |
|
1995 | - */ |
|
1996 | - public function restore_cpt_item($post_id) |
|
1997 | - { |
|
1998 | - $this->request->setRequestParam('EVT_ID', $post_id); |
|
1999 | - $this->_trash_or_restore_event('draft', false); |
|
2000 | - } |
|
2001 | - |
|
2002 | - |
|
2003 | - /** |
|
2004 | - * @param string $post_id |
|
2005 | - * @throws EE_Error |
|
2006 | - * @throws EE_Error |
|
2007 | - */ |
|
2008 | - public function delete_cpt_item($post_id) |
|
2009 | - { |
|
2010 | - throw new EE_Error( |
|
2011 | - esc_html__( |
|
2012 | - 'Please contact Event Espresso support with the details of the steps taken to produce this error.', |
|
2013 | - 'event_espresso' |
|
2014 | - ) |
|
2015 | - ); |
|
2016 | - // $this->request->setRequestParam('EVT_ID', $post_id); |
|
2017 | - // $this->_delete_event(); |
|
2018 | - } |
|
2019 | - |
|
2020 | - |
|
2021 | - /** |
|
2022 | - * _trash_or_restore_event |
|
2023 | - * |
|
2024 | - * @access protected |
|
2025 | - * @param string $event_status |
|
2026 | - * @param bool $redirect_after |
|
2027 | - * @throws EE_Error |
|
2028 | - * @throws EE_Error |
|
2029 | - * @throws ReflectionException |
|
2030 | - */ |
|
2031 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
2032 | - { |
|
2033 | - // determine the event id and set to array. |
|
2034 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
2035 | - // loop thru events |
|
2036 | - if ($EVT_ID) { |
|
2037 | - // clean status |
|
2038 | - $event_status = sanitize_key($event_status); |
|
2039 | - // grab status |
|
2040 | - if (! empty($event_status)) { |
|
2041 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
2042 | - } else { |
|
2043 | - $success = false; |
|
2044 | - $msg = esc_html__( |
|
2045 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2046 | - 'event_espresso' |
|
2047 | - ); |
|
2048 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2049 | - } |
|
2050 | - } else { |
|
2051 | - $success = false; |
|
2052 | - $msg = esc_html__( |
|
2053 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
2054 | - 'event_espresso' |
|
2055 | - ); |
|
2056 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2057 | - } |
|
2058 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2059 | - if ($redirect_after) { |
|
2060 | - $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
2061 | - } |
|
2062 | - } |
|
2063 | - |
|
2064 | - |
|
2065 | - /** |
|
2066 | - * _trash_or_restore_events |
|
2067 | - * |
|
2068 | - * @access protected |
|
2069 | - * @param string $event_status |
|
2070 | - * @return void |
|
2071 | - * @throws EE_Error |
|
2072 | - * @throws EE_Error |
|
2073 | - * @throws ReflectionException |
|
2074 | - */ |
|
2075 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
2076 | - { |
|
2077 | - // clean status |
|
2078 | - $event_status = sanitize_key($event_status); |
|
2079 | - // grab status |
|
2080 | - if (! empty($event_status)) { |
|
2081 | - $success = true; |
|
2082 | - // determine the event id and set to array. |
|
2083 | - $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
2084 | - // loop thru events |
|
2085 | - foreach ($EVT_IDs as $EVT_ID) { |
|
2086 | - if ($EVT_ID = absint($EVT_ID)) { |
|
2087 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
2088 | - $success = $results !== false ? $success : false; |
|
2089 | - } else { |
|
2090 | - $msg = sprintf( |
|
2091 | - esc_html__( |
|
2092 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
2093 | - 'event_espresso' |
|
2094 | - ), |
|
2095 | - $EVT_ID |
|
2096 | - ); |
|
2097 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2098 | - $success = false; |
|
2099 | - } |
|
2100 | - } |
|
2101 | - } else { |
|
2102 | - $success = false; |
|
2103 | - $msg = esc_html__( |
|
2104 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2105 | - 'event_espresso' |
|
2106 | - ); |
|
2107 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2108 | - } |
|
2109 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
2110 | - $success = $success ? 2 : false; |
|
2111 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2112 | - $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
2113 | - } |
|
2114 | - |
|
2115 | - |
|
2116 | - /** |
|
2117 | - * @param int $EVT_ID |
|
2118 | - * @param string $event_status |
|
2119 | - * @return bool |
|
2120 | - * @throws EE_Error |
|
2121 | - * @throws ReflectionException |
|
2122 | - */ |
|
2123 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
2124 | - { |
|
2125 | - // grab event id |
|
2126 | - if (! $EVT_ID) { |
|
2127 | - $msg = esc_html__( |
|
2128 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2129 | - 'event_espresso' |
|
2130 | - ); |
|
2131 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2132 | - return false; |
|
2133 | - } |
|
2134 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2135 | - // clean status |
|
2136 | - $event_status = sanitize_key($event_status); |
|
2137 | - // grab status |
|
2138 | - if (empty($event_status)) { |
|
2139 | - $msg = esc_html__( |
|
2140 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
2141 | - 'event_espresso' |
|
2142 | - ); |
|
2143 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2144 | - return false; |
|
2145 | - } |
|
2146 | - // was event trashed or restored ? |
|
2147 | - switch ($event_status) { |
|
2148 | - case 'draft': |
|
2149 | - $action = 'restored from the trash'; |
|
2150 | - $hook = 'AHEE_event_restored_from_trash'; |
|
2151 | - break; |
|
2152 | - case 'trash': |
|
2153 | - $action = 'moved to the trash'; |
|
2154 | - $hook = 'AHEE_event_moved_to_trash'; |
|
2155 | - break; |
|
2156 | - default: |
|
2157 | - $action = 'updated'; |
|
2158 | - $hook = false; |
|
2159 | - } |
|
2160 | - // use class to change status |
|
2161 | - $this->_cpt_model_obj->set_status($event_status); |
|
2162 | - $success = $this->_cpt_model_obj->save(); |
|
2163 | - if (! $success) { |
|
2164 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
2165 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2166 | - return false; |
|
2167 | - } |
|
2168 | - if ($hook) { |
|
2169 | - do_action($hook); |
|
2170 | - } |
|
2171 | - return true; |
|
2172 | - } |
|
2173 | - |
|
2174 | - |
|
2175 | - /** |
|
2176 | - * @param array $event_ids |
|
2177 | - * @return array |
|
2178 | - * @since 4.10.23.p |
|
2179 | - */ |
|
2180 | - private function cleanEventIds(array $event_ids) |
|
2181 | - { |
|
2182 | - return array_map('absint', $event_ids); |
|
2183 | - } |
|
2184 | - |
|
2185 | - |
|
2186 | - /** |
|
2187 | - * @return array |
|
2188 | - * @since 4.10.23.p |
|
2189 | - */ |
|
2190 | - private function getEventIdsFromRequest() |
|
2191 | - { |
|
2192 | - if ($this->request->requestParamIsSet('EVT_IDs')) { |
|
2193 | - return $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
2194 | - } else { |
|
2195 | - return $this->request->getRequestParam('EVT_ID', [], 'int', true); |
|
2196 | - } |
|
2197 | - } |
|
2198 | - |
|
2199 | - |
|
2200 | - /** |
|
2201 | - * @param bool $preview_delete |
|
2202 | - * @throws EE_Error |
|
2203 | - */ |
|
2204 | - protected function _delete_event($preview_delete = true) |
|
2205 | - { |
|
2206 | - $this->_delete_events($preview_delete); |
|
2207 | - } |
|
2208 | - |
|
2209 | - |
|
2210 | - /** |
|
2211 | - * Gets the tree traversal batch persister. |
|
2212 | - * |
|
2213 | - * @return NodeGroupDao |
|
2214 | - * @throws InvalidArgumentException |
|
2215 | - * @throws InvalidDataTypeException |
|
2216 | - * @throws InvalidInterfaceException |
|
2217 | - * @since 4.10.12.p |
|
2218 | - */ |
|
2219 | - protected function getModelObjNodeGroupPersister() |
|
2220 | - { |
|
2221 | - if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
2222 | - $this->model_obj_node_group_persister = |
|
2223 | - $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
2224 | - } |
|
2225 | - return $this->model_obj_node_group_persister; |
|
2226 | - } |
|
2227 | - |
|
2228 | - |
|
2229 | - /** |
|
2230 | - * @param bool $preview_delete |
|
2231 | - * @return void |
|
2232 | - * @throws EE_Error |
|
2233 | - */ |
|
2234 | - protected function _delete_events($preview_delete = true) |
|
2235 | - { |
|
2236 | - $event_ids = $this->getEventIdsFromRequest(); |
|
2237 | - if ($preview_delete) { |
|
2238 | - $this->generateDeletionPreview($event_ids); |
|
2239 | - } else { |
|
2240 | - EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]); |
|
2241 | - } |
|
2242 | - } |
|
2243 | - |
|
2244 | - |
|
2245 | - /** |
|
2246 | - * @param array $event_ids |
|
2247 | - */ |
|
2248 | - protected function generateDeletionPreview(array $event_ids) |
|
2249 | - { |
|
2250 | - $event_ids = $this->cleanEventIds($event_ids); |
|
2251 | - // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
2252 | - $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
2253 | - $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
2254 | - [ |
|
2255 | - 'action' => 'preview_deletion', |
|
2256 | - 'deletion_job_code' => $deletion_job_code, |
|
2257 | - ], |
|
2258 | - $this->_admin_base_url |
|
2259 | - ); |
|
2260 | - EEH_URL::safeRedirectAndExit( |
|
2261 | - EE_Admin_Page::add_query_args_and_nonce( |
|
2262 | - [ |
|
2263 | - 'page' => 'espresso_batch', |
|
2264 | - 'batch' => EED_Batch::batch_job, |
|
2265 | - 'EVT_IDs' => $event_ids, |
|
2266 | - 'deletion_job_code' => $deletion_job_code, |
|
2267 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
2268 | - 'return_url' => urlencode($return_url), |
|
2269 | - ], |
|
2270 | - admin_url() |
|
2271 | - ) |
|
2272 | - ); |
|
2273 | - } |
|
2274 | - |
|
2275 | - |
|
2276 | - /** |
|
2277 | - * Checks for a POST submission |
|
2278 | - * |
|
2279 | - * @since 4.10.12.p |
|
2280 | - */ |
|
2281 | - protected function confirmDeletion() |
|
2282 | - { |
|
2283 | - $deletion_redirect_logic = |
|
2284 | - $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'); |
|
2285 | - $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
2286 | - } |
|
2287 | - |
|
2288 | - |
|
2289 | - /** |
|
2290 | - * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
2291 | - * |
|
2292 | - * @throws EE_Error |
|
2293 | - * @since 4.10.12.p |
|
2294 | - */ |
|
2295 | - protected function previewDeletion() |
|
2296 | - { |
|
2297 | - $preview_deletion_logic = |
|
2298 | - $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'); |
|
2299 | - $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
2300 | - $this->display_admin_page_with_no_sidebar(); |
|
2301 | - } |
|
2302 | - |
|
2303 | - |
|
2304 | - /** |
|
2305 | - * get total number of events |
|
2306 | - * |
|
2307 | - * @access public |
|
2308 | - * @return int |
|
2309 | - * @throws EE_Error |
|
2310 | - * @throws EE_Error |
|
2311 | - */ |
|
2312 | - public function total_events() |
|
2313 | - { |
|
2314 | - return EEM_Event::instance()->count( |
|
2315 | - ['caps' => 'read_admin'], |
|
2316 | - 'EVT_ID', |
|
2317 | - true |
|
2318 | - ); |
|
2319 | - } |
|
2320 | - |
|
2321 | - |
|
2322 | - /** |
|
2323 | - * get total number of draft events |
|
2324 | - * |
|
2325 | - * @access public |
|
2326 | - * @return int |
|
2327 | - * @throws EE_Error |
|
2328 | - * @throws EE_Error |
|
2329 | - */ |
|
2330 | - public function total_events_draft() |
|
2331 | - { |
|
2332 | - return EEM_Event::instance()->count( |
|
2333 | - [ |
|
2334 | - ['status' => ['IN', ['draft', 'auto-draft']]], |
|
2335 | - 'caps' => 'read_admin', |
|
2336 | - ], |
|
2337 | - 'EVT_ID', |
|
2338 | - true |
|
2339 | - ); |
|
2340 | - } |
|
2341 | - |
|
2342 | - |
|
2343 | - /** |
|
2344 | - * get total number of trashed events |
|
2345 | - * |
|
2346 | - * @access public |
|
2347 | - * @return int |
|
2348 | - * @throws EE_Error |
|
2349 | - * @throws EE_Error |
|
2350 | - */ |
|
2351 | - public function total_trashed_events() |
|
2352 | - { |
|
2353 | - return EEM_Event::instance()->count( |
|
2354 | - [ |
|
2355 | - ['status' => 'trash'], |
|
2356 | - 'caps' => 'read_admin', |
|
2357 | - ], |
|
2358 | - 'EVT_ID', |
|
2359 | - true |
|
2360 | - ); |
|
2361 | - } |
|
2362 | - |
|
2363 | - |
|
2364 | - /** |
|
2365 | - * _default_event_settings |
|
2366 | - * This generates the Default Settings Tab |
|
2367 | - * |
|
2368 | - * @return void |
|
2369 | - * @throws EE_Error |
|
2370 | - */ |
|
2371 | - protected function _default_event_settings() |
|
2372 | - { |
|
2373 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
2374 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
2375 | - $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
2376 | - $this->display_admin_page_with_sidebar(); |
|
2377 | - } |
|
2378 | - |
|
2379 | - |
|
2380 | - /** |
|
2381 | - * Return the form for event settings. |
|
2382 | - * |
|
2383 | - * @return EE_Form_Section_Proper |
|
2384 | - * @throws EE_Error |
|
2385 | - */ |
|
2386 | - protected function _default_event_settings_form() |
|
2387 | - { |
|
2388 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
2389 | - $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
2390 | - // exclude |
|
2391 | - [ |
|
2392 | - EEM_Registration::status_id_cancelled, |
|
2393 | - EEM_Registration::status_id_declined, |
|
2394 | - EEM_Registration::status_id_incomplete, |
|
2395 | - EEM_Registration::status_id_wait_list, |
|
2396 | - ], |
|
2397 | - true |
|
2398 | - ); |
|
2399 | - return new EE_Form_Section_Proper( |
|
2400 | - [ |
|
2401 | - 'name' => 'update_default_event_settings', |
|
2402 | - 'html_id' => 'update_default_event_settings', |
|
2403 | - 'html_class' => 'form-table', |
|
2404 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
2405 | - 'subsections' => apply_filters( |
|
2406 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
2407 | - [ |
|
2408 | - 'default_reg_status' => new EE_Select_Input( |
|
2409 | - $registration_stati_for_selection, |
|
2410 | - [ |
|
2411 | - 'default' => isset($registration_config->default_STS_ID) |
|
2412 | - && array_key_exists( |
|
2413 | - $registration_config->default_STS_ID, |
|
2414 | - $registration_stati_for_selection |
|
2415 | - ) |
|
2416 | - ? sanitize_text_field($registration_config->default_STS_ID) |
|
2417 | - : EEM_Registration::status_id_pending_payment, |
|
2418 | - 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
2419 | - . EEH_Template::get_help_tab_link( |
|
2420 | - 'default_settings_status_help_tab' |
|
2421 | - ), |
|
2422 | - 'html_help_text' => esc_html__( |
|
2423 | - 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
2424 | - 'event_espresso' |
|
2425 | - ), |
|
2426 | - ] |
|
2427 | - ), |
|
2428 | - 'default_max_tickets' => new EE_Integer_Input( |
|
2429 | - [ |
|
2430 | - 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
2431 | - ? $registration_config->default_maximum_number_of_tickets |
|
2432 | - : EEM_Event::get_default_additional_limit(), |
|
2433 | - 'html_label_text' => esc_html__( |
|
2434 | - 'Default Maximum Tickets Allowed Per Order:', |
|
2435 | - 'event_espresso' |
|
2436 | - ) |
|
2437 | - . EEH_Template::get_help_tab_link( |
|
2438 | - 'default_maximum_tickets_help_tab"' |
|
2439 | - ), |
|
2440 | - 'html_help_text' => esc_html__( |
|
2441 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
2442 | - 'event_espresso' |
|
2443 | - ), |
|
2444 | - ] |
|
2445 | - ), |
|
2446 | - ] |
|
2447 | - ), |
|
2448 | - ] |
|
2449 | - ); |
|
2450 | - } |
|
2451 | - |
|
2452 | - |
|
2453 | - /** |
|
2454 | - * _update_default_event_settings |
|
2455 | - * |
|
2456 | - * @access protected |
|
2457 | - * @return void |
|
2458 | - * @throws EE_Error |
|
2459 | - */ |
|
2460 | - protected function _update_default_event_settings() |
|
2461 | - { |
|
2462 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
2463 | - $form = $this->_default_event_settings_form(); |
|
2464 | - if ($form->was_submitted()) { |
|
2465 | - $form->receive_form_submission(); |
|
2466 | - if ($form->is_valid()) { |
|
2467 | - $valid_data = $form->valid_data(); |
|
2468 | - if (isset($valid_data['default_reg_status'])) { |
|
2469 | - $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
2470 | - } |
|
2471 | - if (isset($valid_data['default_max_tickets'])) { |
|
2472 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
2473 | - } |
|
2474 | - // update because data was valid! |
|
2475 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
2476 | - EE_Error::overwrite_success(); |
|
2477 | - EE_Error::add_success( |
|
2478 | - esc_html__('Default Event Settings were updated', 'event_espresso') |
|
2479 | - ); |
|
2480 | - } |
|
2481 | - } |
|
2482 | - $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
2483 | - } |
|
2484 | - |
|
2485 | - |
|
2486 | - /************* Templates ************* |
|
2487 | - * |
|
2488 | - * @throws EE_Error |
|
2489 | - */ |
|
2490 | - protected function _template_settings() |
|
2491 | - { |
|
2492 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
2493 | - $this->_template_args['preview_img'] = '<img src="' |
|
2494 | - . EVENTS_ASSETS_URL |
|
2495 | - . '/images/' |
|
2496 | - . 'caffeinated_template_features.jpg" alt="' |
|
2497 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
2498 | - . '" />'; |
|
2499 | - $this->_template_args['preview_text'] = '<strong>' |
|
2500 | - . esc_html__( |
|
2501 | - 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
2502 | - 'event_espresso' |
|
2503 | - ) . '</strong>'; |
|
2504 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
2505 | - } |
|
2506 | - |
|
2507 | - |
|
2508 | - /** Event Category Stuff **/ |
|
2509 | - /** |
|
2510 | - * set the _category property with the category object for the loaded page. |
|
2511 | - * |
|
2512 | - * @access private |
|
2513 | - * @return void |
|
2514 | - */ |
|
2515 | - private function _set_category_object() |
|
2516 | - { |
|
2517 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
2518 | - return; |
|
2519 | - } //already have the category object so get out. |
|
2520 | - // set default category object |
|
2521 | - $this->_set_empty_category_object(); |
|
2522 | - // only set if we've got an id |
|
2523 | - $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
2524 | - if (! $category_ID) { |
|
2525 | - return; |
|
2526 | - } |
|
2527 | - $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2528 | - if (! empty($term)) { |
|
2529 | - $this->_category->category_name = $term->name; |
|
2530 | - $this->_category->category_identifier = $term->slug; |
|
2531 | - $this->_category->category_desc = $term->description; |
|
2532 | - $this->_category->id = $term->term_id; |
|
2533 | - $this->_category->parent = $term->parent; |
|
2534 | - } |
|
2535 | - } |
|
2536 | - |
|
2537 | - |
|
2538 | - /** |
|
2539 | - * Clears out category properties. |
|
2540 | - */ |
|
2541 | - private function _set_empty_category_object() |
|
2542 | - { |
|
2543 | - $this->_category = new stdClass(); |
|
2544 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2545 | - $this->_category->id = $this->_category->parent = 0; |
|
2546 | - } |
|
2547 | - |
|
2548 | - |
|
2549 | - /** |
|
2550 | - * @throws EE_Error |
|
2551 | - */ |
|
2552 | - protected function _category_list_table() |
|
2553 | - { |
|
2554 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2555 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
2556 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
2557 | - 'add_category', |
|
2558 | - 'add_category', |
|
2559 | - [], |
|
2560 | - 'add-new-h2' |
|
2561 | - ); |
|
2562 | - $this->display_admin_list_table_page_with_sidebar(); |
|
2563 | - } |
|
2564 | - |
|
2565 | - |
|
2566 | - /** |
|
2567 | - * Output category details view. |
|
2568 | - * |
|
2569 | - * @throws EE_Error |
|
2570 | - * @throws EE_Error |
|
2571 | - */ |
|
2572 | - protected function _category_details($view) |
|
2573 | - { |
|
2574 | - // load formatter helper |
|
2575 | - // load field generator helper |
|
2576 | - $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
2577 | - $this->_set_add_edit_form_tags($route); |
|
2578 | - $this->_set_category_object(); |
|
2579 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
2580 | - $delete_action = 'delete_category'; |
|
2581 | - // custom redirect |
|
2582 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
2583 | - ['action' => 'category_list'], |
|
2584 | - $this->_admin_base_url |
|
2585 | - ); |
|
2586 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
2587 | - // take care of contents |
|
2588 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
2589 | - $this->display_admin_page_with_sidebar(); |
|
2590 | - } |
|
2591 | - |
|
2592 | - |
|
2593 | - /** |
|
2594 | - * Output category details content. |
|
2595 | - */ |
|
2596 | - protected function _category_details_content() |
|
2597 | - { |
|
2598 | - $editor_args['category_desc'] = [ |
|
2599 | - 'type' => 'wp_editor', |
|
2600 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
2601 | - 'class' => 'my_editor_custom', |
|
2602 | - 'wpeditor_args' => ['media_buttons' => false], |
|
2603 | - ]; |
|
2604 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
2605 | - $all_terms = get_terms( |
|
2606 | - [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
2607 | - ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
2608 | - ); |
|
2609 | - // setup category select for term parents. |
|
2610 | - $category_select_values[] = [ |
|
2611 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
2612 | - 'id' => 0, |
|
2613 | - ]; |
|
2614 | - foreach ($all_terms as $term) { |
|
2615 | - $category_select_values[] = [ |
|
2616 | - 'text' => $term->name, |
|
2617 | - 'id' => $term->term_id, |
|
2618 | - ]; |
|
2619 | - } |
|
2620 | - $category_select = EEH_Form_Fields::select_input( |
|
2621 | - 'category_parent', |
|
2622 | - $category_select_values, |
|
2623 | - $this->_category->parent |
|
2624 | - ); |
|
2625 | - $template_args = [ |
|
2626 | - 'category' => $this->_category, |
|
2627 | - 'category_select' => $category_select, |
|
2628 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
2629 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
2630 | - 'disable' => '', |
|
2631 | - 'disabled_message' => false, |
|
2632 | - ]; |
|
2633 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2634 | - return EEH_Template::display_template($template, $template_args, true); |
|
2635 | - } |
|
2636 | - |
|
2637 | - |
|
2638 | - /** |
|
2639 | - * Handles deleting categories. |
|
2640 | - * |
|
2641 | - * @throws EE_Error |
|
2642 | - */ |
|
2643 | - protected function _delete_categories() |
|
2644 | - { |
|
2645 | - $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true); |
|
2646 | - foreach ($category_IDs as $category_ID) { |
|
2647 | - $this->_delete_category($category_ID); |
|
2648 | - } |
|
2649 | - // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
2650 | - $query_args = [ |
|
2651 | - 'action' => 'category_list', |
|
2652 | - ]; |
|
2653 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
2654 | - } |
|
2655 | - |
|
2656 | - |
|
2657 | - /** |
|
2658 | - * Handles deleting specific category. |
|
2659 | - * |
|
2660 | - * @param int $cat_id |
|
2661 | - */ |
|
2662 | - protected function _delete_category($cat_id) |
|
2663 | - { |
|
2664 | - $cat_id = absint($cat_id); |
|
2665 | - wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2666 | - } |
|
2667 | - |
|
2668 | - |
|
2669 | - /** |
|
2670 | - * Handles triggering the update or insertion of a new category. |
|
2671 | - * |
|
2672 | - * @param bool $new_category true means we're triggering the insert of a new category. |
|
2673 | - * @throws EE_Error |
|
2674 | - * @throws EE_Error |
|
2675 | - */ |
|
2676 | - protected function _insert_or_update_category($new_category) |
|
2677 | - { |
|
2678 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
2679 | - $success = 0; // we already have a success message so lets not send another. |
|
2680 | - if ($cat_id) { |
|
2681 | - $query_args = [ |
|
2682 | - 'action' => 'edit_category', |
|
2683 | - 'EVT_CAT_ID' => $cat_id, |
|
2684 | - ]; |
|
2685 | - } else { |
|
2686 | - $query_args = ['action' => 'add_category']; |
|
2687 | - } |
|
2688 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
2689 | - } |
|
2690 | - |
|
2691 | - |
|
2692 | - /** |
|
2693 | - * Inserts or updates category |
|
2694 | - * |
|
2695 | - * @param bool $update (true indicates we're updating a category). |
|
2696 | - * @return bool|mixed|string |
|
2697 | - */ |
|
2698 | - private function _insert_category($update = false) |
|
2699 | - { |
|
2700 | - $category_ID = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0; |
|
2701 | - $category_name = $this->request->getRequestParam('category_name', ''); |
|
2702 | - $category_desc = $this->request->getRequestParam('category_desc', ''); |
|
2703 | - $category_parent = $this->request->getRequestParam('category_parent', 0, 'int'); |
|
2704 | - $category_identifier = $this->request->getRequestParam('category_identifier', ''); |
|
2705 | - |
|
2706 | - if (empty($category_name)) { |
|
2707 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
2708 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2709 | - return false; |
|
2710 | - } |
|
2711 | - $term_args = [ |
|
2712 | - 'name' => $category_name, |
|
2713 | - 'description' => $category_desc, |
|
2714 | - 'parent' => $category_parent, |
|
2715 | - ]; |
|
2716 | - // was the category_identifier input disabled? |
|
2717 | - if ($category_identifier) { |
|
2718 | - $term_args['slug'] = $category_identifier; |
|
2719 | - } |
|
2720 | - $insert_ids = $update |
|
2721 | - ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
2722 | - : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
2723 | - if (! is_array($insert_ids)) { |
|
2724 | - $msg = esc_html__( |
|
2725 | - 'An error occurred and the category has not been saved to the database.', |
|
2726 | - 'event_espresso' |
|
2727 | - ); |
|
2728 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2729 | - } else { |
|
2730 | - $category_ID = $insert_ids['term_id']; |
|
2731 | - $msg = |
|
2732 | - sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
2733 | - EE_Error::add_success($msg); |
|
2734 | - } |
|
2735 | - return $category_ID; |
|
2736 | - } |
|
2737 | - |
|
2738 | - |
|
2739 | - /** |
|
2740 | - * Gets categories or count of categories matching the arguments in the request. |
|
2741 | - * |
|
2742 | - * @param int $per_page |
|
2743 | - * @param int $current_page |
|
2744 | - * @param bool $count |
|
2745 | - * @return EE_Term_Taxonomy[]|int |
|
2746 | - * @throws EE_Error |
|
2747 | - * @throws EE_Error |
|
2748 | - */ |
|
2749 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
2750 | - { |
|
2751 | - // testing term stuff |
|
2752 | - $orderby = $this->request->getRequestParam('orderby', 'Term.term_id'); |
|
2753 | - $order = $this->request->getRequestParam('order', 'DESC'); |
|
2754 | - $limit = ($current_page - 1) * $per_page; |
|
2755 | - $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
2756 | - $search_term = $this->request->getRequestParam('s'); |
|
2757 | - if ($search_term) { |
|
2758 | - $search_term = '%' . $search_term . '%'; |
|
2759 | - $where['OR'] = [ |
|
2760 | - 'Term.name' => ['LIKE', $search_term], |
|
2761 | - 'description' => ['LIKE', $search_term], |
|
2762 | - ]; |
|
2763 | - } |
|
2764 | - $query_params = [ |
|
2765 | - $where, |
|
2766 | - 'order_by' => [$orderby => $order], |
|
2767 | - 'limit' => $limit . ',' . $per_page, |
|
2768 | - 'force_join' => ['Term'], |
|
2769 | - ]; |
|
2770 | - return $count |
|
2771 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
2772 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
2773 | - } |
|
2774 | - |
|
2775 | - /* end category stuff */ |
|
2776 | - /**************/ |
|
2777 | - |
|
2778 | - |
|
2779 | - /** |
|
2780 | - * Callback for the `ee_save_timezone_setting` ajax action. |
|
2781 | - * |
|
2782 | - * @throws EE_Error |
|
2783 | - */ |
|
2784 | - public function saveTimezoneString() |
|
2785 | - { |
|
2786 | - $timezone_string = $this->request->getRequestParam('timezone_selected'); |
|
2787 | - if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
2788 | - EE_Error::add_error( |
|
2789 | - esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
2790 | - __FILE__, |
|
2791 | - __FUNCTION__, |
|
2792 | - __LINE__ |
|
2793 | - ); |
|
2794 | - $this->_template_args['error'] = true; |
|
2795 | - $this->_return_json(); |
|
2796 | - } |
|
2797 | - |
|
2798 | - update_option('timezone_string', $timezone_string); |
|
2799 | - EE_Error::add_success( |
|
2800 | - esc_html__('Your timezone string was updated.', 'event_espresso') |
|
2801 | - ); |
|
2802 | - $this->_template_args['success'] = true; |
|
2803 | - $this->_return_json(true, ['action' => 'create_new']); |
|
2804 | - } |
|
2805 | - |
|
2806 | - |
|
2807 | - /** |
|
2808 | 2488 | * @throws EE_Error |
2809 | - * @deprecated 4.10.25.p |
|
2810 | 2489 | */ |
2811 | - public function save_timezonestring_setting() |
|
2812 | - { |
|
2813 | - $this->saveTimezoneString(); |
|
2814 | - } |
|
2490 | + protected function _template_settings() |
|
2491 | + { |
|
2492 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
2493 | + $this->_template_args['preview_img'] = '<img src="' |
|
2494 | + . EVENTS_ASSETS_URL |
|
2495 | + . '/images/' |
|
2496 | + . 'caffeinated_template_features.jpg" alt="' |
|
2497 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
2498 | + . '" />'; |
|
2499 | + $this->_template_args['preview_text'] = '<strong>' |
|
2500 | + . esc_html__( |
|
2501 | + 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
2502 | + 'event_espresso' |
|
2503 | + ) . '</strong>'; |
|
2504 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
2505 | + } |
|
2506 | + |
|
2507 | + |
|
2508 | + /** Event Category Stuff **/ |
|
2509 | + /** |
|
2510 | + * set the _category property with the category object for the loaded page. |
|
2511 | + * |
|
2512 | + * @access private |
|
2513 | + * @return void |
|
2514 | + */ |
|
2515 | + private function _set_category_object() |
|
2516 | + { |
|
2517 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
2518 | + return; |
|
2519 | + } //already have the category object so get out. |
|
2520 | + // set default category object |
|
2521 | + $this->_set_empty_category_object(); |
|
2522 | + // only set if we've got an id |
|
2523 | + $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
2524 | + if (! $category_ID) { |
|
2525 | + return; |
|
2526 | + } |
|
2527 | + $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2528 | + if (! empty($term)) { |
|
2529 | + $this->_category->category_name = $term->name; |
|
2530 | + $this->_category->category_identifier = $term->slug; |
|
2531 | + $this->_category->category_desc = $term->description; |
|
2532 | + $this->_category->id = $term->term_id; |
|
2533 | + $this->_category->parent = $term->parent; |
|
2534 | + } |
|
2535 | + } |
|
2536 | + |
|
2537 | + |
|
2538 | + /** |
|
2539 | + * Clears out category properties. |
|
2540 | + */ |
|
2541 | + private function _set_empty_category_object() |
|
2542 | + { |
|
2543 | + $this->_category = new stdClass(); |
|
2544 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2545 | + $this->_category->id = $this->_category->parent = 0; |
|
2546 | + } |
|
2547 | + |
|
2548 | + |
|
2549 | + /** |
|
2550 | + * @throws EE_Error |
|
2551 | + */ |
|
2552 | + protected function _category_list_table() |
|
2553 | + { |
|
2554 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2555 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
2556 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
2557 | + 'add_category', |
|
2558 | + 'add_category', |
|
2559 | + [], |
|
2560 | + 'add-new-h2' |
|
2561 | + ); |
|
2562 | + $this->display_admin_list_table_page_with_sidebar(); |
|
2563 | + } |
|
2564 | + |
|
2565 | + |
|
2566 | + /** |
|
2567 | + * Output category details view. |
|
2568 | + * |
|
2569 | + * @throws EE_Error |
|
2570 | + * @throws EE_Error |
|
2571 | + */ |
|
2572 | + protected function _category_details($view) |
|
2573 | + { |
|
2574 | + // load formatter helper |
|
2575 | + // load field generator helper |
|
2576 | + $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
2577 | + $this->_set_add_edit_form_tags($route); |
|
2578 | + $this->_set_category_object(); |
|
2579 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
2580 | + $delete_action = 'delete_category'; |
|
2581 | + // custom redirect |
|
2582 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
2583 | + ['action' => 'category_list'], |
|
2584 | + $this->_admin_base_url |
|
2585 | + ); |
|
2586 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
2587 | + // take care of contents |
|
2588 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
2589 | + $this->display_admin_page_with_sidebar(); |
|
2590 | + } |
|
2591 | + |
|
2592 | + |
|
2593 | + /** |
|
2594 | + * Output category details content. |
|
2595 | + */ |
|
2596 | + protected function _category_details_content() |
|
2597 | + { |
|
2598 | + $editor_args['category_desc'] = [ |
|
2599 | + 'type' => 'wp_editor', |
|
2600 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
2601 | + 'class' => 'my_editor_custom', |
|
2602 | + 'wpeditor_args' => ['media_buttons' => false], |
|
2603 | + ]; |
|
2604 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
2605 | + $all_terms = get_terms( |
|
2606 | + [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
2607 | + ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
2608 | + ); |
|
2609 | + // setup category select for term parents. |
|
2610 | + $category_select_values[] = [ |
|
2611 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
2612 | + 'id' => 0, |
|
2613 | + ]; |
|
2614 | + foreach ($all_terms as $term) { |
|
2615 | + $category_select_values[] = [ |
|
2616 | + 'text' => $term->name, |
|
2617 | + 'id' => $term->term_id, |
|
2618 | + ]; |
|
2619 | + } |
|
2620 | + $category_select = EEH_Form_Fields::select_input( |
|
2621 | + 'category_parent', |
|
2622 | + $category_select_values, |
|
2623 | + $this->_category->parent |
|
2624 | + ); |
|
2625 | + $template_args = [ |
|
2626 | + 'category' => $this->_category, |
|
2627 | + 'category_select' => $category_select, |
|
2628 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
2629 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
2630 | + 'disable' => '', |
|
2631 | + 'disabled_message' => false, |
|
2632 | + ]; |
|
2633 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2634 | + return EEH_Template::display_template($template, $template_args, true); |
|
2635 | + } |
|
2636 | + |
|
2637 | + |
|
2638 | + /** |
|
2639 | + * Handles deleting categories. |
|
2640 | + * |
|
2641 | + * @throws EE_Error |
|
2642 | + */ |
|
2643 | + protected function _delete_categories() |
|
2644 | + { |
|
2645 | + $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true); |
|
2646 | + foreach ($category_IDs as $category_ID) { |
|
2647 | + $this->_delete_category($category_ID); |
|
2648 | + } |
|
2649 | + // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
2650 | + $query_args = [ |
|
2651 | + 'action' => 'category_list', |
|
2652 | + ]; |
|
2653 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
2654 | + } |
|
2655 | + |
|
2656 | + |
|
2657 | + /** |
|
2658 | + * Handles deleting specific category. |
|
2659 | + * |
|
2660 | + * @param int $cat_id |
|
2661 | + */ |
|
2662 | + protected function _delete_category($cat_id) |
|
2663 | + { |
|
2664 | + $cat_id = absint($cat_id); |
|
2665 | + wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2666 | + } |
|
2667 | + |
|
2668 | + |
|
2669 | + /** |
|
2670 | + * Handles triggering the update or insertion of a new category. |
|
2671 | + * |
|
2672 | + * @param bool $new_category true means we're triggering the insert of a new category. |
|
2673 | + * @throws EE_Error |
|
2674 | + * @throws EE_Error |
|
2675 | + */ |
|
2676 | + protected function _insert_or_update_category($new_category) |
|
2677 | + { |
|
2678 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
2679 | + $success = 0; // we already have a success message so lets not send another. |
|
2680 | + if ($cat_id) { |
|
2681 | + $query_args = [ |
|
2682 | + 'action' => 'edit_category', |
|
2683 | + 'EVT_CAT_ID' => $cat_id, |
|
2684 | + ]; |
|
2685 | + } else { |
|
2686 | + $query_args = ['action' => 'add_category']; |
|
2687 | + } |
|
2688 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
2689 | + } |
|
2690 | + |
|
2691 | + |
|
2692 | + /** |
|
2693 | + * Inserts or updates category |
|
2694 | + * |
|
2695 | + * @param bool $update (true indicates we're updating a category). |
|
2696 | + * @return bool|mixed|string |
|
2697 | + */ |
|
2698 | + private function _insert_category($update = false) |
|
2699 | + { |
|
2700 | + $category_ID = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0; |
|
2701 | + $category_name = $this->request->getRequestParam('category_name', ''); |
|
2702 | + $category_desc = $this->request->getRequestParam('category_desc', ''); |
|
2703 | + $category_parent = $this->request->getRequestParam('category_parent', 0, 'int'); |
|
2704 | + $category_identifier = $this->request->getRequestParam('category_identifier', ''); |
|
2705 | + |
|
2706 | + if (empty($category_name)) { |
|
2707 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
2708 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2709 | + return false; |
|
2710 | + } |
|
2711 | + $term_args = [ |
|
2712 | + 'name' => $category_name, |
|
2713 | + 'description' => $category_desc, |
|
2714 | + 'parent' => $category_parent, |
|
2715 | + ]; |
|
2716 | + // was the category_identifier input disabled? |
|
2717 | + if ($category_identifier) { |
|
2718 | + $term_args['slug'] = $category_identifier; |
|
2719 | + } |
|
2720 | + $insert_ids = $update |
|
2721 | + ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
2722 | + : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
2723 | + if (! is_array($insert_ids)) { |
|
2724 | + $msg = esc_html__( |
|
2725 | + 'An error occurred and the category has not been saved to the database.', |
|
2726 | + 'event_espresso' |
|
2727 | + ); |
|
2728 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2729 | + } else { |
|
2730 | + $category_ID = $insert_ids['term_id']; |
|
2731 | + $msg = |
|
2732 | + sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
2733 | + EE_Error::add_success($msg); |
|
2734 | + } |
|
2735 | + return $category_ID; |
|
2736 | + } |
|
2737 | + |
|
2738 | + |
|
2739 | + /** |
|
2740 | + * Gets categories or count of categories matching the arguments in the request. |
|
2741 | + * |
|
2742 | + * @param int $per_page |
|
2743 | + * @param int $current_page |
|
2744 | + * @param bool $count |
|
2745 | + * @return EE_Term_Taxonomy[]|int |
|
2746 | + * @throws EE_Error |
|
2747 | + * @throws EE_Error |
|
2748 | + */ |
|
2749 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
2750 | + { |
|
2751 | + // testing term stuff |
|
2752 | + $orderby = $this->request->getRequestParam('orderby', 'Term.term_id'); |
|
2753 | + $order = $this->request->getRequestParam('order', 'DESC'); |
|
2754 | + $limit = ($current_page - 1) * $per_page; |
|
2755 | + $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
2756 | + $search_term = $this->request->getRequestParam('s'); |
|
2757 | + if ($search_term) { |
|
2758 | + $search_term = '%' . $search_term . '%'; |
|
2759 | + $where['OR'] = [ |
|
2760 | + 'Term.name' => ['LIKE', $search_term], |
|
2761 | + 'description' => ['LIKE', $search_term], |
|
2762 | + ]; |
|
2763 | + } |
|
2764 | + $query_params = [ |
|
2765 | + $where, |
|
2766 | + 'order_by' => [$orderby => $order], |
|
2767 | + 'limit' => $limit . ',' . $per_page, |
|
2768 | + 'force_join' => ['Term'], |
|
2769 | + ]; |
|
2770 | + return $count |
|
2771 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
2772 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
2773 | + } |
|
2774 | + |
|
2775 | + /* end category stuff */ |
|
2776 | + /**************/ |
|
2777 | + |
|
2778 | + |
|
2779 | + /** |
|
2780 | + * Callback for the `ee_save_timezone_setting` ajax action. |
|
2781 | + * |
|
2782 | + * @throws EE_Error |
|
2783 | + */ |
|
2784 | + public function saveTimezoneString() |
|
2785 | + { |
|
2786 | + $timezone_string = $this->request->getRequestParam('timezone_selected'); |
|
2787 | + if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
2788 | + EE_Error::add_error( |
|
2789 | + esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
2790 | + __FILE__, |
|
2791 | + __FUNCTION__, |
|
2792 | + __LINE__ |
|
2793 | + ); |
|
2794 | + $this->_template_args['error'] = true; |
|
2795 | + $this->_return_json(); |
|
2796 | + } |
|
2797 | + |
|
2798 | + update_option('timezone_string', $timezone_string); |
|
2799 | + EE_Error::add_success( |
|
2800 | + esc_html__('Your timezone string was updated.', 'event_espresso') |
|
2801 | + ); |
|
2802 | + $this->_template_args['success'] = true; |
|
2803 | + $this->_return_json(true, ['action' => 'create_new']); |
|
2804 | + } |
|
2805 | + |
|
2806 | + |
|
2807 | + /** |
|
2808 | + * @throws EE_Error |
|
2809 | + * @deprecated 4.10.25.p |
|
2810 | + */ |
|
2811 | + public function save_timezonestring_setting() |
|
2812 | + { |
|
2813 | + $this->saveTimezoneString(); |
|
2814 | + } |
|
2815 | 2815 | } |
@@ -5,7 +5,7 @@ |
||
5 | 5 | <p> |
6 | 6 | <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong><br /> |
7 | 7 | <?php esc_html_e( |
8 | - 'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.', |
|
9 | - 'event_espresso' |
|
10 | - ); ?> |
|
8 | + 'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.', |
|
9 | + 'event_espresso' |
|
10 | + ); ?> |
|
11 | 11 | </p> |
12 | 12 | \ No newline at end of file |
@@ -1,21 +1,21 @@ |
||
1 | 1 | <p><strong><?php esc_html_e('Event Categories', 'event_espresso'); ?></strong></p> |
2 | 2 | <p> |
3 | 3 | <?php esc_html_e( |
4 | - 'This page shows all event categories that have been created with Event Espresso.', |
|
5 | - 'event_espresso' |
|
6 | - ); ?> |
|
4 | + 'This page shows all event categories that have been created with Event Espresso.', |
|
5 | + 'event_espresso' |
|
6 | + ); ?> |
|
7 | 7 | </p> |
8 | 8 | <p> |
9 | 9 | <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong><br /> |
10 | 10 | <?php esc_html_e( |
11 | - 'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.', |
|
12 | - 'event_espresso' |
|
13 | - ); ?> |
|
11 | + 'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.', |
|
12 | + 'event_espresso' |
|
13 | + ); ?> |
|
14 | 14 | </p> |
15 | 15 | <p> |
16 | 16 | <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong><br /> |
17 | 17 | <?php esc_html_e( |
18 | - 'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content and even adjust the pagination for event categories.', |
|
19 | - 'event_espresso' |
|
20 | - ); ?> |
|
18 | + 'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content and even adjust the pagination for event categories.', |
|
19 | + 'event_espresso' |
|
20 | + ); ?> |
|
21 | 21 | </p> |
22 | 22 | \ No newline at end of file |
@@ -14,15 +14,15 @@ |
||
14 | 14 | <li> |
15 | 15 | <strong><?php esc_html_e('Category Description', 'event_espresso'); ?></strong><br /> |
16 | 16 | <?php esc_html_e( |
17 | - 'The rich text editor can be used to create a description for your event category.', |
|
18 | - 'event_espresso' |
|
19 | - ); ?> |
|
17 | + 'The rich text editor can be used to create a description for your event category.', |
|
18 | + 'event_espresso' |
|
19 | + ); ?> |
|
20 | 20 | </li> |
21 | 21 | </ul> |
22 | 22 | <p> |
23 | 23 | <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong><br /> |
24 | 24 | <?php esc_html_e( |
25 | - 'You can customize the information that is shown on this page by toggling the screen options tab. Then you can add or remove checkmarks to hide or show certain content.', |
|
26 | - 'event_espresso' |
|
27 | - ); ?> |
|
25 | + 'You can customize the information that is shown on this page by toggling the screen options tab. Then you can add or remove checkmarks to hide or show certain content.', |
|
26 | + 'event_espresso' |
|
27 | + ); ?> |
|
28 | 28 | </p> |
@@ -15,25 +15,25 @@ discard block |
||
15 | 15 | <li> |
16 | 16 | <strong><?php esc_html_e('Display Status Banner', 'event_espresso'); ?></strong><br /> |
17 | 17 | <?php esc_html_e( |
18 | - 'Specify whether event status banners should be shown next to the title on the single event page. Notice: Some themes do not use the_title() tag correctly and this may cause things to appear broken (stray html). You can use this option to test your theme.', |
|
19 | - 'event_espresso' |
|
20 | - ); ?> |
|
18 | + 'Specify whether event status banners should be shown next to the title on the single event page. Notice: Some themes do not use the_title() tag correctly and this may cause things to appear broken (stray html). You can use this option to test your theme.', |
|
19 | + 'event_espresso' |
|
20 | + ); ?> |
|
21 | 21 | </li> |
22 | 22 | </ul> |
23 | 23 | <ul> |
24 | 24 | <li> |
25 | 25 | <strong><?php esc_html_e('Display Venue Details', 'event_espresso'); ?></strong><br /> |
26 | 26 | <?php esc_html_e( |
27 | - 'Whether Venue information, such as the address and Google Map should be shown on the Single Event pages.', |
|
28 | - 'event_espresso' |
|
29 | - ); ?> |
|
27 | + 'Whether Venue information, such as the address and Google Map should be shown on the Single Event pages.', |
|
28 | + 'event_espresso' |
|
29 | + ); ?> |
|
30 | 30 | </li> |
31 | 31 | <li> |
32 | 32 | <strong><?php esc_html_e('Display Order', 'event_espresso'); ?></strong><br /> |
33 | 33 | <?php esc_html_e( |
34 | - 'This setting controls the order of the event elements on the single event page. For example, if you want the venue details to appear above the ticket selector on the single event pages, just set the "Venue Display Order" setting to "1", and set the "Tickets Display Order" setting to "2". The lower the number, the further down the page the venue details will appear.', |
|
35 | - 'event_espresso' |
|
36 | - ); ?> |
|
34 | + 'This setting controls the order of the event elements on the single event page. For example, if you want the venue details to appear above the ticket selector on the single event pages, just set the "Venue Display Order" setting to "1", and set the "Tickets Display Order" setting to "2". The lower the number, the further down the page the venue details will appear.', |
|
35 | + 'event_espresso' |
|
36 | + ); ?> |
|
37 | 37 | </li> |
38 | 38 | </ul> |
39 | 39 | <p><strong> |
@@ -47,27 +47,27 @@ discard block |
||
47 | 47 | <li> |
48 | 48 | <strong><?php esc_html_e('Display Status Banner', 'event_espresso'); ?></strong><br /> |
49 | 49 | <?php esc_html_e( |
50 | - 'Specify whether event status banners should be shown next to the title on the event list page. Notice: Some themes do not use the_title() tag correctly and this may cause things to appear broken (stray html). You can use this option to test your theme.', |
|
51 | - 'event_espresso' |
|
52 | - ); ?> |
|
50 | + 'Specify whether event status banners should be shown next to the title on the event list page. Notice: Some themes do not use the_title() tag correctly and this may cause things to appear broken (stray html). You can use this option to test your theme.', |
|
51 | + 'event_espresso' |
|
52 | + ); ?> |
|
53 | 53 | </li> |
54 | 54 | <li> |
55 | 55 | <strong><?php esc_html_e('Display Descriptions', 'event_espresso'); ?></strong><br /> |
56 | 56 | <?php printf( |
57 | - esc_html__( |
|
58 | - 'Whether descriptions should be shown on the event list page.%1$sSelecting "none" will NOT display any of the text content you entered into the main text editor on the event admin page.%1$sSelecting "excerpt" will display the text you entered into the "Excerpt" textarea on the event admin page, OR, any text in the main text editor above the %2$s tag.%1$sSelecting "full description" will display ALL of the text content you entered into the main text editor on the event admin page.', |
|
59 | - 'event_espresso' |
|
60 | - ), |
|
61 | - '<br/>', |
|
62 | - htmlentities('<!--more-->') |
|
63 | - ); ?> |
|
57 | + esc_html__( |
|
58 | + 'Whether descriptions should be shown on the event list page.%1$sSelecting "none" will NOT display any of the text content you entered into the main text editor on the event admin page.%1$sSelecting "excerpt" will display the text you entered into the "Excerpt" textarea on the event admin page, OR, any text in the main text editor above the %2$s tag.%1$sSelecting "full description" will display ALL of the text content you entered into the main text editor on the event admin page.', |
|
59 | + 'event_espresso' |
|
60 | + ), |
|
61 | + '<br/>', |
|
62 | + htmlentities('<!--more-->') |
|
63 | + ); ?> |
|
64 | 64 | </li> |
65 | 65 | <li> |
66 | 66 | <strong><?php esc_html_e('Display Ticket Selector', 'event_espresso'); ?></strong><br /> |
67 | 67 | <?php esc_html_e( |
68 | - 'Whether the ticket options table (Ticket Selector) should be shown on the event list page.', |
|
69 | - 'event_espresso' |
|
70 | - ); ?> |
|
68 | + 'Whether the ticket options table (Ticket Selector) should be shown on the event list page.', |
|
69 | + 'event_espresso' |
|
70 | + ); ?> |
|
71 | 71 | </li> |
72 | 72 | <li> |
73 | 73 | <strong><?php esc_html_e('Display Datetimes', 'event_espresso'); ?></strong><br /> |
@@ -89,14 +89,14 @@ discard block |
||
89 | 89 | <p> |
90 | 90 | <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong><br /> |
91 | 91 | <?php esc_html_e( |
92 | - 'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.', |
|
93 | - 'event_espresso' |
|
94 | - ); ?> |
|
92 | + 'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.', |
|
93 | + 'event_espresso' |
|
94 | + ); ?> |
|
95 | 95 | </p> |
96 | 96 | <p> |
97 | 97 | <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong><br /> |
98 | 98 | <?php esc_html_e( |
99 | - 'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.', |
|
100 | - 'event_espresso' |
|
101 | - ); ?> |
|
99 | + 'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.', |
|
100 | + 'event_espresso' |
|
101 | + ); ?> |
|
102 | 102 | </p> |
103 | 103 | \ No newline at end of file |
@@ -8,14 +8,14 @@ |
||
8 | 8 | <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong> |
9 | 9 | <br /> |
10 | 10 | <?php esc_html_e( |
11 | - 'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.', |
|
12 | - 'event_espresso' |
|
13 | - ); ?> |
|
11 | + 'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.', |
|
12 | + 'event_espresso' |
|
13 | + ); ?> |
|
14 | 14 | </p> |
15 | 15 | <p> |
16 | 16 | <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong><br /> |
17 | 17 | <?php esc_html_e( |
18 | - 'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content and even adjust the pagination for events.', |
|
19 | - 'event_espresso' |
|
20 | - ); ?> |
|
18 | + 'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content and even adjust the pagination for events.', |
|
19 | + 'event_espresso' |
|
20 | + ); ?> |
|
21 | 21 | </p> |
22 | 22 | \ No newline at end of file |
@@ -5,14 +5,14 @@ |
||
5 | 5 | <p> |
6 | 6 | <strong><?php esc_html_e('Sample Import File', 'event_espresso'); ?></strong><br /> |
7 | 7 | <?php esc_html_e( |
8 | - 'Save time by downloading a sample import file. Then customize that file and import it back into Event Espresso.', |
|
9 | - 'event_espresso' |
|
10 | - ); ?> |
|
8 | + 'Save time by downloading a sample import file. Then customize that file and import it back into Event Espresso.', |
|
9 | + 'event_espresso' |
|
10 | + ); ?> |
|
11 | 11 | </p> |
12 | 12 | <p> |
13 | 13 | <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong><br /> |
14 | 14 | <?php esc_html_e( |
15 | - 'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.', |
|
16 | - 'event_espresso' |
|
17 | - ); ?> |
|
15 | + 'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.', |
|
16 | + 'event_espresso' |
|
17 | + ); ?> |
|
18 | 18 | </p> |
19 | 19 | \ No newline at end of file |
@@ -14,1306 +14,1306 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * Extend_Events_Admin_Page constructor. |
|
19 | - * |
|
20 | - * @param bool $routing |
|
21 | - * @throws EE_Error |
|
22 | - * @throws ReflectionException |
|
23 | - */ |
|
24 | - public function __construct($routing = true) |
|
25 | - { |
|
26 | - parent::__construct($routing); |
|
27 | - if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
28 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
29 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
30 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
31 | - } |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * Sets routes. |
|
37 | - * |
|
38 | - * @throws EE_Error |
|
39 | - */ |
|
40 | - protected function _extend_page_config() |
|
41 | - { |
|
42 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
43 | - // is there a evt_id in the request? |
|
44 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
45 | - $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
|
46 | - $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
|
47 | - $new_page_routes = [ |
|
48 | - 'duplicate_event' => [ |
|
49 | - 'func' => '_duplicate_event', |
|
50 | - 'capability' => 'ee_edit_event', |
|
51 | - 'obj_id' => $EVT_ID, |
|
52 | - 'noheader' => true, |
|
53 | - ], |
|
54 | - 'ticket_list_table' => [ |
|
55 | - 'func' => '_tickets_overview_list_table', |
|
56 | - 'capability' => 'ee_read_default_tickets', |
|
57 | - ], |
|
58 | - 'trash_ticket' => [ |
|
59 | - 'func' => '_trash_or_restore_ticket', |
|
60 | - 'capability' => 'ee_delete_default_ticket', |
|
61 | - 'obj_id' => $TKT_ID, |
|
62 | - 'noheader' => true, |
|
63 | - 'args' => ['trash' => true], |
|
64 | - ], |
|
65 | - 'trash_tickets' => [ |
|
66 | - 'func' => '_trash_or_restore_ticket', |
|
67 | - 'capability' => 'ee_delete_default_tickets', |
|
68 | - 'noheader' => true, |
|
69 | - 'args' => ['trash' => true], |
|
70 | - ], |
|
71 | - 'restore_ticket' => [ |
|
72 | - 'func' => '_trash_or_restore_ticket', |
|
73 | - 'capability' => 'ee_delete_default_ticket', |
|
74 | - 'obj_id' => $TKT_ID, |
|
75 | - 'noheader' => true, |
|
76 | - ], |
|
77 | - 'restore_tickets' => [ |
|
78 | - 'func' => '_trash_or_restore_ticket', |
|
79 | - 'capability' => 'ee_delete_default_tickets', |
|
80 | - 'noheader' => true, |
|
81 | - ], |
|
82 | - 'delete_ticket' => [ |
|
83 | - 'func' => '_delete_ticket', |
|
84 | - 'capability' => 'ee_delete_default_ticket', |
|
85 | - 'obj_id' => $TKT_ID, |
|
86 | - 'noheader' => true, |
|
87 | - ], |
|
88 | - 'delete_tickets' => [ |
|
89 | - 'func' => '_delete_ticket', |
|
90 | - 'capability' => 'ee_delete_default_tickets', |
|
91 | - 'noheader' => true, |
|
92 | - ], |
|
93 | - 'import_page' => [ |
|
94 | - 'func' => '_import_page', |
|
95 | - 'capability' => 'import', |
|
96 | - ], |
|
97 | - 'import' => [ |
|
98 | - 'func' => '_import_events', |
|
99 | - 'capability' => 'import', |
|
100 | - 'noheader' => true, |
|
101 | - ], |
|
102 | - 'import_events' => [ |
|
103 | - 'func' => '_import_events', |
|
104 | - 'capability' => 'import', |
|
105 | - 'noheader' => true, |
|
106 | - ], |
|
107 | - 'export_events' => [ |
|
108 | - 'func' => '_events_export', |
|
109 | - 'capability' => 'export', |
|
110 | - 'noheader' => true, |
|
111 | - ], |
|
112 | - 'export_categories' => [ |
|
113 | - 'func' => '_categories_export', |
|
114 | - 'capability' => 'export', |
|
115 | - 'noheader' => true, |
|
116 | - ], |
|
117 | - 'sample_export_file' => [ |
|
118 | - 'func' => '_sample_export_file', |
|
119 | - 'capability' => 'export', |
|
120 | - 'noheader' => true, |
|
121 | - ], |
|
122 | - 'update_template_settings' => [ |
|
123 | - 'func' => '_update_template_settings', |
|
124 | - 'capability' => 'manage_options', |
|
125 | - 'noheader' => true, |
|
126 | - ], |
|
127 | - ]; |
|
128 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
129 | - // partial route/config override |
|
130 | - $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
131 | - $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
132 | - $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
133 | - $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
134 | - $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
135 | - $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
136 | - // add tickets tab but only if there are more than one default ticket! |
|
137 | - $ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
138 | - [['TKT_is_default' => 1]], |
|
139 | - 'TKT_ID', |
|
140 | - true |
|
141 | - ); |
|
142 | - if ($ticket_count > 1) { |
|
143 | - $new_page_config = [ |
|
144 | - 'ticket_list_table' => [ |
|
145 | - 'nav' => [ |
|
146 | - 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
147 | - 'order' => 60, |
|
148 | - ], |
|
149 | - 'list_table' => 'Tickets_List_Table', |
|
150 | - 'require_nonce' => false, |
|
151 | - ], |
|
152 | - ]; |
|
153 | - } |
|
154 | - // template settings |
|
155 | - $new_page_config['template_settings'] = [ |
|
156 | - 'nav' => [ |
|
157 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
158 | - 'order' => 30, |
|
159 | - ], |
|
160 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
161 | - 'help_tabs' => [ |
|
162 | - 'general_settings_templates_help_tab' => [ |
|
163 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
164 | - 'filename' => 'general_settings_templates', |
|
165 | - ], |
|
166 | - ], |
|
167 | - 'require_nonce' => false, |
|
168 | - ]; |
|
169 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
170 | - // add filters and actions |
|
171 | - // modifying _views |
|
172 | - add_filter( |
|
173 | - 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
174 | - [$this, 'add_additional_datetime_button'], |
|
175 | - 10, |
|
176 | - 2 |
|
177 | - ); |
|
178 | - add_filter( |
|
179 | - 'FHEE_event_datetime_metabox_clone_button_template', |
|
180 | - [$this, 'add_datetime_clone_button'], |
|
181 | - 10, |
|
182 | - 2 |
|
183 | - ); |
|
184 | - add_filter( |
|
185 | - 'FHEE_event_datetime_metabox_timezones_template', |
|
186 | - [$this, 'datetime_timezones_template'], |
|
187 | - 10, |
|
188 | - 2 |
|
189 | - ); |
|
190 | - // filters for event list table |
|
191 | - add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2); |
|
192 | - add_filter( |
|
193 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
194 | - [$this, 'extra_list_table_actions'], |
|
195 | - 10, |
|
196 | - 2 |
|
197 | - ); |
|
198 | - // legend item |
|
199 | - add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']); |
|
200 | - add_action('admin_init', [$this, 'admin_init']); |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * admin_init |
|
206 | - */ |
|
207 | - public function admin_init() |
|
208 | - { |
|
209 | - EE_Registry::$i18n_js_strings = array_merge( |
|
210 | - EE_Registry::$i18n_js_strings, |
|
211 | - [ |
|
212 | - 'image_confirm' => esc_html__( |
|
213 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
214 | - 'event_espresso' |
|
215 | - ), |
|
216 | - 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
217 | - 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
218 | - 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
219 | - 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
220 | - 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
221 | - ] |
|
222 | - ); |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * Add per page screen options to the default ticket list table view. |
|
228 | - */ |
|
229 | - protected function _add_screen_options_ticket_list_table() |
|
230 | - { |
|
231 | - $this->_per_page_screen_option(); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @param string $return |
|
237 | - * @param int $id |
|
238 | - * @param string $new_title |
|
239 | - * @param string $new_slug |
|
240 | - * @return string |
|
241 | - */ |
|
242 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
243 | - { |
|
244 | - $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
245 | - // make sure this is only when editing |
|
246 | - if (! empty($id)) { |
|
247 | - $href = EE_Admin_Page::add_query_args_and_nonce( |
|
248 | - ['action' => 'duplicate_event', 'EVT_ID' => $id], |
|
249 | - $this->_admin_base_url |
|
250 | - ); |
|
251 | - $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
252 | - $return .= '<a href="' |
|
253 | - . $href |
|
254 | - . '" title="' |
|
255 | - . $title |
|
256 | - . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
257 | - . $title |
|
258 | - . '</a>'; |
|
259 | - } |
|
260 | - return $return; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * Set the list table views for the default ticket list table view. |
|
266 | - */ |
|
267 | - public function _set_list_table_views_ticket_list_table() |
|
268 | - { |
|
269 | - $this->_views = [ |
|
270 | - 'all' => [ |
|
271 | - 'slug' => 'all', |
|
272 | - 'label' => esc_html__('All', 'event_espresso'), |
|
273 | - 'count' => 0, |
|
274 | - 'bulk_action' => [ |
|
275 | - 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
276 | - ], |
|
277 | - ], |
|
278 | - 'trashed' => [ |
|
279 | - 'slug' => 'trashed', |
|
280 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
281 | - 'count' => 0, |
|
282 | - 'bulk_action' => [ |
|
283 | - 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
284 | - 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
285 | - ], |
|
286 | - ], |
|
287 | - ]; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * Enqueue scripts and styles for the event editor. |
|
293 | - */ |
|
294 | - public function load_scripts_styles_edit() |
|
295 | - { |
|
296 | - wp_register_script( |
|
297 | - 'ee-event-editor-heartbeat', |
|
298 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
299 | - ['ee_admin_js', 'heartbeat'], |
|
300 | - EVENT_ESPRESSO_VERSION, |
|
301 | - true |
|
302 | - ); |
|
303 | - wp_enqueue_script('ee-accounting'); |
|
304 | - // styles |
|
305 | - wp_enqueue_style('espresso-ui-theme'); |
|
306 | - wp_enqueue_script('event_editor_js'); |
|
307 | - wp_enqueue_script('ee-event-editor-heartbeat'); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * Returns template for the additional datetime. |
|
313 | - * |
|
314 | - * @param string $template |
|
315 | - * @param array $template_args |
|
316 | - * @return string |
|
317 | - * @throws DomainException |
|
318 | - */ |
|
319 | - public function add_additional_datetime_button($template, $template_args) |
|
320 | - { |
|
321 | - return EEH_Template::display_template( |
|
322 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
323 | - $template_args, |
|
324 | - true |
|
325 | - ); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Returns the template for cloning a datetime. |
|
331 | - * |
|
332 | - * @param $template |
|
333 | - * @param $template_args |
|
334 | - * @return string |
|
335 | - * @throws DomainException |
|
336 | - */ |
|
337 | - public function add_datetime_clone_button($template, $template_args) |
|
338 | - { |
|
339 | - return EEH_Template::display_template( |
|
340 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
341 | - $template_args, |
|
342 | - true |
|
343 | - ); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Returns the template for datetime timezones. |
|
349 | - * |
|
350 | - * @param $template |
|
351 | - * @param $template_args |
|
352 | - * @return string |
|
353 | - * @throws DomainException |
|
354 | - */ |
|
355 | - public function datetime_timezones_template($template, $template_args) |
|
356 | - { |
|
357 | - return EEH_Template::display_template( |
|
358 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
359 | - $template_args, |
|
360 | - true |
|
361 | - ); |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * Sets the views for the default list table view. |
|
367 | - * |
|
368 | - * @throws EE_Error |
|
369 | - */ |
|
370 | - protected function _set_list_table_views_default() |
|
371 | - { |
|
372 | - parent::_set_list_table_views_default(); |
|
373 | - $new_views = [ |
|
374 | - 'today' => [ |
|
375 | - 'slug' => 'today', |
|
376 | - 'label' => esc_html__('Today', 'event_espresso'), |
|
377 | - 'count' => $this->total_events_today(), |
|
378 | - 'bulk_action' => [ |
|
379 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
380 | - ], |
|
381 | - ], |
|
382 | - 'month' => [ |
|
383 | - 'slug' => 'month', |
|
384 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
385 | - 'count' => $this->total_events_this_month(), |
|
386 | - 'bulk_action' => [ |
|
387 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
388 | - ], |
|
389 | - ], |
|
390 | - ]; |
|
391 | - $this->_views = array_merge($this->_views, $new_views); |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - /** |
|
396 | - * Returns the extra action links for the default list table view. |
|
397 | - * |
|
398 | - * @param array $action_links |
|
399 | - * @param EE_Event $event |
|
400 | - * @return array |
|
401 | - * @throws EE_Error |
|
402 | - * @throws ReflectionException |
|
403 | - */ |
|
404 | - public function extra_list_table_actions(array $action_links, EE_Event $event) |
|
405 | - { |
|
406 | - if ( |
|
407 | - EE_Registry::instance()->CAP->current_user_can( |
|
408 | - 'ee_read_registrations', |
|
409 | - 'espresso_registrations_reports', |
|
410 | - $event->ID() |
|
411 | - ) |
|
412 | - ) { |
|
413 | - $reports_query_args = [ |
|
414 | - 'action' => 'reports', |
|
415 | - 'EVT_ID' => $event->ID(), |
|
416 | - ]; |
|
417 | - $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
418 | - $action_links[] = '<a href="' |
|
419 | - . $reports_link |
|
420 | - . '" title="' |
|
421 | - . esc_attr__('View Report', 'event_espresso') |
|
422 | - . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
423 | - . "\n\t"; |
|
424 | - } |
|
425 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
426 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
427 | - $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
428 | - 'see_notifications_for', |
|
429 | - null, |
|
430 | - ['EVT_ID' => $event->ID()] |
|
431 | - ); |
|
432 | - } |
|
433 | - return $action_links; |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * @param $items |
|
439 | - * @return mixed |
|
440 | - */ |
|
441 | - public function additional_legend_items($items) |
|
442 | - { |
|
443 | - if ( |
|
444 | - EE_Registry::instance()->CAP->current_user_can( |
|
445 | - 'ee_read_registrations', |
|
446 | - 'espresso_registrations_reports' |
|
447 | - ) |
|
448 | - ) { |
|
449 | - $items['reports'] = [ |
|
450 | - 'class' => 'dashicons dashicons-chart-bar', |
|
451 | - 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
452 | - ]; |
|
453 | - } |
|
454 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
455 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
456 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
457 | - $items['view_related_messages'] = [ |
|
458 | - 'class' => $related_for_icon['css_class'], |
|
459 | - 'desc' => $related_for_icon['label'], |
|
460 | - ]; |
|
461 | - } |
|
462 | - } |
|
463 | - return $items; |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * This is the callback method for the duplicate event route |
|
469 | - * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
470 | - * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
471 | - * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
472 | - * After duplication the redirect is to the new event edit page. |
|
473 | - * |
|
474 | - * @return void |
|
475 | - * @throws EE_Error If EE_Event is not available with given ID |
|
476 | - * @throws ReflectionException |
|
477 | - * @access protected |
|
478 | - */ |
|
479 | - protected function _duplicate_event() |
|
480 | - { |
|
481 | - // first make sure the ID for the event is in the request. |
|
482 | - // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
483 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
484 | - if (! $EVT_ID) { |
|
485 | - EE_Error::add_error( |
|
486 | - esc_html__( |
|
487 | - 'In order to duplicate an event an Event ID is required. None was given.', |
|
488 | - 'event_espresso' |
|
489 | - ), |
|
490 | - __FILE__, |
|
491 | - __FUNCTION__, |
|
492 | - __LINE__ |
|
493 | - ); |
|
494 | - $this->_redirect_after_action(false, '', '', [], true); |
|
495 | - return; |
|
496 | - } |
|
497 | - // k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
498 | - $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
499 | - if (! $orig_event instanceof EE_Event) { |
|
500 | - throw new EE_Error( |
|
501 | - sprintf( |
|
502 | - esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
503 | - $EVT_ID |
|
504 | - ) |
|
505 | - ); |
|
506 | - } |
|
507 | - // k now let's clone the $orig_event before getting relations |
|
508 | - $new_event = clone $orig_event; |
|
509 | - // original datetimes |
|
510 | - $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
511 | - // other original relations |
|
512 | - $orig_ven = $orig_event->get_many_related('Venue'); |
|
513 | - // reset the ID and modify other details to make it clear this is a dupe |
|
514 | - $new_event->set('EVT_ID', 0); |
|
515 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
516 | - $new_event->set('EVT_name', $new_name); |
|
517 | - $new_event->set( |
|
518 | - 'EVT_slug', |
|
519 | - wp_unique_post_slug( |
|
520 | - sanitize_title($orig_event->name()), |
|
521 | - 0, |
|
522 | - 'publish', |
|
523 | - 'espresso_events', |
|
524 | - 0 |
|
525 | - ) |
|
526 | - ); |
|
527 | - $new_event->set('status', 'draft'); |
|
528 | - // duplicate discussion settings |
|
529 | - $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
530 | - $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
531 | - // save the new event |
|
532 | - $new_event->save(); |
|
533 | - // venues |
|
534 | - foreach ($orig_ven as $ven) { |
|
535 | - $new_event->_add_relation_to($ven, 'Venue'); |
|
536 | - } |
|
537 | - $new_event->save(); |
|
538 | - // now we need to get the question group relations and handle that |
|
539 | - // first primary question groups |
|
540 | - $orig_primary_qgs = $orig_event->get_many_related( |
|
541 | - 'Question_Group', |
|
542 | - [['Event_Question_Group.EQG_primary' => true]] |
|
543 | - ); |
|
544 | - if (! empty($orig_primary_qgs)) { |
|
545 | - foreach ($orig_primary_qgs as $obj) { |
|
546 | - if ($obj instanceof EE_Question_Group) { |
|
547 | - $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]); |
|
548 | - } |
|
549 | - } |
|
550 | - } |
|
551 | - // next additional attendee question groups |
|
552 | - $orig_additional_qgs = $orig_event->get_many_related( |
|
553 | - 'Question_Group', |
|
554 | - [['Event_Question_Group.EQG_additional' => true]] |
|
555 | - ); |
|
556 | - if (! empty($orig_additional_qgs)) { |
|
557 | - foreach ($orig_additional_qgs as $obj) { |
|
558 | - if ($obj instanceof EE_Question_Group) { |
|
559 | - $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]); |
|
560 | - } |
|
561 | - } |
|
562 | - } |
|
563 | - |
|
564 | - $new_event->save(); |
|
565 | - |
|
566 | - // k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
567 | - $cloned_tickets = []; |
|
568 | - foreach ($orig_datetimes as $orig_dtt) { |
|
569 | - if (! $orig_dtt instanceof EE_Datetime) { |
|
570 | - continue; |
|
571 | - } |
|
572 | - $new_dtt = clone $orig_dtt; |
|
573 | - $orig_tickets = $orig_dtt->tickets(); |
|
574 | - // save new dtt then add to event |
|
575 | - $new_dtt->set('DTT_ID', 0); |
|
576 | - $new_dtt->set('DTT_sold', 0); |
|
577 | - $new_dtt->set_reserved(0); |
|
578 | - $new_dtt->save(); |
|
579 | - $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
580 | - $new_event->save(); |
|
581 | - // now let's get the ticket relations setup. |
|
582 | - foreach ((array) $orig_tickets as $orig_ticket) { |
|
583 | - // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
584 | - if (! $orig_ticket instanceof EE_Ticket) { |
|
585 | - continue; |
|
586 | - } |
|
587 | - // is this ticket archived? If it is then let's skip |
|
588 | - if ($orig_ticket->get('TKT_deleted')) { |
|
589 | - continue; |
|
590 | - } |
|
591 | - // does this original ticket already exist in the clone_tickets cache? |
|
592 | - // If so we'll just use the new ticket from it. |
|
593 | - if (isset($cloned_tickets[ $orig_ticket->ID() ])) { |
|
594 | - $new_ticket = $cloned_tickets[ $orig_ticket->ID() ]; |
|
595 | - } else { |
|
596 | - $new_ticket = clone $orig_ticket; |
|
597 | - // get relations on the $orig_ticket that we need to setup. |
|
598 | - $orig_prices = $orig_ticket->prices(); |
|
599 | - $new_ticket->set('TKT_ID', 0); |
|
600 | - $new_ticket->set('TKT_sold', 0); |
|
601 | - $new_ticket->set('TKT_reserved', 0); |
|
602 | - $new_ticket->save(); // make sure new ticket has ID. |
|
603 | - // price relations on new ticket need to be setup. |
|
604 | - foreach ($orig_prices as $orig_price) { |
|
605 | - $new_price = clone $orig_price; |
|
606 | - $new_price->set('PRC_ID', 0); |
|
607 | - $new_price->save(); |
|
608 | - $new_ticket->_add_relation_to($new_price, 'Price'); |
|
609 | - $new_ticket->save(); |
|
610 | - } |
|
611 | - |
|
612 | - do_action( |
|
613 | - 'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after', |
|
614 | - $orig_ticket, |
|
615 | - $new_ticket, |
|
616 | - $orig_prices, |
|
617 | - $orig_event, |
|
618 | - $orig_dtt, |
|
619 | - $new_dtt |
|
620 | - ); |
|
621 | - } |
|
622 | - // k now we can add the new ticket as a relation to the new datetime |
|
623 | - // and make sure its added to our cached $cloned_tickets array |
|
624 | - // for use with later datetimes that have the same ticket. |
|
625 | - $new_dtt->_add_relation_to($new_ticket, 'Ticket'); |
|
626 | - $new_dtt->save(); |
|
627 | - $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket; |
|
628 | - } |
|
629 | - } |
|
630 | - // clone taxonomy information |
|
631 | - $taxonomies_to_clone_with = apply_filters( |
|
632 | - 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
633 | - ['espresso_event_categories', 'espresso_event_type', 'post_tag'] |
|
634 | - ); |
|
635 | - // get terms for original event (notice) |
|
636 | - $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
637 | - // loop through terms and add them to new event. |
|
638 | - foreach ($orig_terms as $term) { |
|
639 | - wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
640 | - } |
|
641 | - |
|
642 | - // duplicate other core WP_Post items for this event. |
|
643 | - // post thumbnail (feature image). |
|
644 | - $feature_image_id = get_post_thumbnail_id($orig_event->ID()); |
|
645 | - if ($feature_image_id) { |
|
646 | - update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id); |
|
647 | - } |
|
648 | - |
|
649 | - // duplicate page_template setting |
|
650 | - $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true); |
|
651 | - if ($page_template) { |
|
652 | - update_post_meta($new_event->ID(), '_wp_page_template', $page_template); |
|
653 | - } |
|
654 | - |
|
655 | - do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
656 | - // now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
657 | - if ($new_event->ID()) { |
|
658 | - $redirect_args = [ |
|
659 | - 'post' => $new_event->ID(), |
|
660 | - 'action' => 'edit', |
|
661 | - ]; |
|
662 | - EE_Error::add_success( |
|
663 | - esc_html__( |
|
664 | - 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
665 | - 'event_espresso' |
|
666 | - ) |
|
667 | - ); |
|
668 | - } else { |
|
669 | - $redirect_args = [ |
|
670 | - 'action' => 'default', |
|
671 | - ]; |
|
672 | - EE_Error::add_error( |
|
673 | - esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
674 | - __FILE__, |
|
675 | - __FUNCTION__, |
|
676 | - __LINE__ |
|
677 | - ); |
|
678 | - } |
|
679 | - $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * Generates output for the import page. |
|
685 | - * |
|
686 | - * @throws EE_Error |
|
687 | - */ |
|
688 | - protected function _import_page() |
|
689 | - { |
|
690 | - $title = esc_html__('Import', 'event_espresso'); |
|
691 | - $intro = esc_html__( |
|
692 | - 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
693 | - 'event_espresso' |
|
694 | - ); |
|
695 | - |
|
696 | - $form_url = EVENTS_ADMIN_URL; |
|
697 | - $action = 'import_events'; |
|
698 | - $type = 'csv'; |
|
699 | - |
|
700 | - $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
701 | - $title, |
|
702 | - $intro, |
|
703 | - $form_url, |
|
704 | - $action, |
|
705 | - $type |
|
706 | - ); |
|
707 | - |
|
708 | - $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
709 | - ['action' => 'sample_export_file'], |
|
710 | - $this->_admin_base_url |
|
711 | - ); |
|
712 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
713 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
714 | - $this->_template_args, |
|
715 | - true |
|
716 | - ); |
|
717 | - $this->display_admin_page_with_sidebar(); |
|
718 | - } |
|
719 | - |
|
720 | - |
|
721 | - /** |
|
722 | - * _import_events |
|
723 | - * This handles displaying the screen and running imports for importing events. |
|
724 | - * |
|
725 | - * @return void |
|
726 | - * @throws EE_Error |
|
727 | - */ |
|
728 | - protected function _import_events() |
|
729 | - { |
|
730 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
731 | - $success = EE_Import::instance()->import(); |
|
732 | - $this->_redirect_after_action( |
|
733 | - $success, |
|
734 | - esc_html__('Import File', 'event_espresso'), |
|
735 | - 'ran', |
|
736 | - ['action' => 'import_page'], |
|
737 | - true |
|
738 | - ); |
|
739 | - } |
|
740 | - |
|
741 | - |
|
742 | - /** |
|
743 | - * _events_export |
|
744 | - * Will export all (or just the given event) to a Excel compatible file. |
|
745 | - * |
|
746 | - * @access protected |
|
747 | - * @return void |
|
748 | - */ |
|
749 | - protected function _events_export() |
|
750 | - { |
|
751 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
752 | - $EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int'); |
|
753 | - $this->request->mergeRequestParams( |
|
754 | - [ |
|
755 | - 'export' => 'report', |
|
756 | - 'action' => 'all_event_data', |
|
757 | - 'EVT_ID' => $EVT_ID, |
|
758 | - ] |
|
759 | - ); |
|
760 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
761 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
762 | - $EE_Export = EE_Export::instance($this->request->requestParams()); |
|
763 | - $EE_Export->export(); |
|
764 | - } |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * handle category exports() |
|
770 | - * |
|
771 | - * @return void |
|
772 | - */ |
|
773 | - protected function _categories_export() |
|
774 | - { |
|
775 | - $EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
776 | - $this->request->mergeRequestParams( |
|
777 | - [ |
|
778 | - 'export' => 'report', |
|
779 | - 'action' => 'categories', |
|
780 | - 'EVT_ID' => $EVT_ID, |
|
781 | - ] |
|
782 | - ); |
|
783 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
784 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
785 | - $EE_Export = EE_Export::instance($this->request->requestParams()); |
|
786 | - $EE_Export->export(); |
|
787 | - } |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - /** |
|
792 | - * Creates a sample CSV file for importing |
|
793 | - */ |
|
794 | - protected function _sample_export_file() |
|
795 | - { |
|
796 | - // require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
797 | - EE_Export::instance()->export_sample(); |
|
798 | - } |
|
799 | - |
|
800 | - |
|
801 | - /************* Template Settings *************/ |
|
802 | - /** |
|
803 | - * Generates template settings page output |
|
804 | - * |
|
805 | - * @throws DomainException |
|
806 | - * @throws EE_Error |
|
807 | - */ |
|
808 | - protected function _template_settings() |
|
809 | - { |
|
810 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
811 | - /** |
|
812 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
813 | - * from General_Settings_Admin_Page to here. |
|
814 | - */ |
|
815 | - $this->_template_args = apply_filters( |
|
816 | - 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
817 | - $this->_template_args |
|
818 | - ); |
|
819 | - $this->_set_add_edit_form_tags('update_template_settings'); |
|
820 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
821 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
822 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
823 | - $this->_template_args, |
|
824 | - true |
|
825 | - ); |
|
826 | - $this->display_admin_page_with_sidebar(); |
|
827 | - } |
|
828 | - |
|
829 | - |
|
830 | - /** |
|
831 | - * Handler for updating template settings. |
|
832 | - * |
|
833 | - * @throws EE_Error |
|
834 | - */ |
|
835 | - protected function _update_template_settings() |
|
836 | - { |
|
837 | - /** |
|
838 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
839 | - * from General_Settings_Admin_Page to here. |
|
840 | - */ |
|
841 | - EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
842 | - 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
843 | - EE_Registry::instance()->CFG->template_settings, |
|
844 | - $this->request->requestParams() |
|
845 | - ); |
|
846 | - // update custom post type slugs and detect if we need to flush rewrite rules |
|
847 | - $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
848 | - |
|
849 | - $event_cpt_slug = $this->request->getRequestParam('event_cpt_slug'); |
|
850 | - |
|
851 | - EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug |
|
852 | - ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
853 | - : EEH_URL::slugify($event_cpt_slug, 'events'); |
|
854 | - |
|
855 | - $what = esc_html__('Template Settings', 'event_espresso'); |
|
856 | - $success = $this->_update_espresso_configuration( |
|
857 | - $what, |
|
858 | - EE_Registry::instance()->CFG->template_settings, |
|
859 | - __FILE__, |
|
860 | - __FUNCTION__, |
|
861 | - __LINE__ |
|
862 | - ); |
|
863 | - if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
864 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
865 | - $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
866 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
867 | - ); |
|
868 | - $rewrite_rules->flush(); |
|
869 | - } |
|
870 | - $this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']); |
|
871 | - } |
|
872 | - |
|
873 | - |
|
874 | - /** |
|
875 | - * _premium_event_editor_meta_boxes |
|
876 | - * add all metaboxes related to the event_editor |
|
877 | - * |
|
878 | - * @access protected |
|
879 | - * @return void |
|
880 | - * @throws EE_Error |
|
881 | - * @throws ReflectionException |
|
882 | - */ |
|
883 | - protected function _premium_event_editor_meta_boxes() |
|
884 | - { |
|
885 | - $this->verify_cpt_object(); |
|
886 | - add_meta_box( |
|
887 | - 'espresso_event_editor_event_options', |
|
888 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
889 | - [$this, 'registration_options_meta_box'], |
|
890 | - $this->page_slug, |
|
891 | - 'side', |
|
892 | - 'core' |
|
893 | - ); |
|
894 | - } |
|
895 | - |
|
896 | - |
|
897 | - /** |
|
898 | - * override caf metabox |
|
899 | - * |
|
900 | - * @return void |
|
901 | - * @throws EE_Error |
|
902 | - * @throws ReflectionException |
|
903 | - */ |
|
904 | - public function registration_options_meta_box() |
|
905 | - { |
|
906 | - $yes_no_values = [ |
|
907 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
908 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
909 | - ]; |
|
910 | - |
|
911 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
912 | - [ |
|
913 | - EEM_Registration::status_id_cancelled, |
|
914 | - EEM_Registration::status_id_declined, |
|
915 | - EEM_Registration::status_id_incomplete, |
|
916 | - EEM_Registration::status_id_wait_list, |
|
917 | - ], |
|
918 | - true |
|
919 | - ); |
|
920 | - |
|
921 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
922 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
923 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
924 | - |
|
925 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
926 | - 'default_reg_status', |
|
927 | - $default_reg_status_values, |
|
928 | - $this->_cpt_model_obj->default_registration_status() |
|
929 | - ); |
|
930 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
931 | - 'display_desc', |
|
932 | - $yes_no_values, |
|
933 | - $this->_cpt_model_obj->display_description() |
|
934 | - ); |
|
935 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
936 | - 'display_ticket_selector', |
|
937 | - $yes_no_values, |
|
938 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
939 | - '', |
|
940 | - '', |
|
941 | - false |
|
942 | - ); |
|
943 | - $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
944 | - 'EVT_default_registration_status', |
|
945 | - $default_reg_status_values, |
|
946 | - $this->_cpt_model_obj->default_registration_status() |
|
947 | - ); |
|
948 | - $template_args['additional_registration_options'] = apply_filters( |
|
949 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
950 | - '', |
|
951 | - $template_args, |
|
952 | - $yes_no_values, |
|
953 | - $default_reg_status_values |
|
954 | - ); |
|
955 | - EEH_Template::display_template( |
|
956 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
957 | - $template_args |
|
958 | - ); |
|
959 | - } |
|
960 | - |
|
961 | - |
|
962 | - |
|
963 | - /** |
|
964 | - * wp_list_table_mods for caf |
|
965 | - * ============================ |
|
966 | - */ |
|
967 | - /** |
|
968 | - * hook into list table filters and provide filters for caffeinated list table |
|
969 | - * |
|
970 | - * @param array $old_filters any existing filters present |
|
971 | - * @param array $list_table_obj the list table object |
|
972 | - * @return array new filters |
|
973 | - * @throws EE_Error |
|
974 | - * @throws ReflectionException |
|
975 | - */ |
|
976 | - public function list_table_filters($old_filters, $list_table_obj) |
|
977 | - { |
|
978 | - $filters = []; |
|
979 | - // first month/year filters |
|
980 | - $filters[] = $this->espresso_event_months_dropdown(); |
|
981 | - $status = $this->request->getRequestParam('status'); |
|
982 | - // active status dropdown |
|
983 | - if ($status !== 'draft') { |
|
984 | - $filters[] = $this->active_status_dropdown($this->request->getRequestParam('active_status')); |
|
985 | - $filters[] = $this->venuesDropdown($this->request->getRequestParam('venue')); |
|
986 | - } |
|
987 | - // category filter |
|
988 | - $filters[] = $this->category_dropdown(); |
|
989 | - return array_merge($old_filters, $filters); |
|
990 | - } |
|
991 | - |
|
992 | - |
|
993 | - /** |
|
994 | - * espresso_event_months_dropdown |
|
995 | - * |
|
996 | - * @access public |
|
997 | - * @return string dropdown listing month/year selections for events. |
|
998 | - * @throws EE_Error |
|
999 | - */ |
|
1000 | - public function espresso_event_months_dropdown() |
|
1001 | - { |
|
1002 | - // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
1003 | - // Note we need to include any other filters that are set! |
|
1004 | - return EEH_Form_Fields::generate_event_months_dropdown( |
|
1005 | - $this->request->getRequestParam('month_range'), |
|
1006 | - $this->request->getRequestParam('status'), |
|
1007 | - $this->request->getRequestParam('EVT_CAT', 0, 'int'), |
|
1008 | - $this->request->getRequestParam('active_status') |
|
1009 | - ); |
|
1010 | - } |
|
1011 | - |
|
1012 | - |
|
1013 | - /** |
|
1014 | - * returns a list of "active" statuses on the event |
|
1015 | - * |
|
1016 | - * @param string $current_value whatever the current active status is |
|
1017 | - * @return string |
|
1018 | - */ |
|
1019 | - public function active_status_dropdown($current_value = '') |
|
1020 | - { |
|
1021 | - $select_name = 'active_status'; |
|
1022 | - $values = [ |
|
1023 | - 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
1024 | - 'active' => esc_html__('Active', 'event_espresso'), |
|
1025 | - 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
1026 | - 'expired' => esc_html__('Expired', 'event_espresso'), |
|
1027 | - 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
1028 | - ]; |
|
1029 | - |
|
1030 | - return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide'); |
|
1031 | - } |
|
1032 | - |
|
1033 | - |
|
1034 | - /** |
|
1035 | - * returns a list of "venues" |
|
1036 | - * |
|
1037 | - * @param string $current_value whatever the current active status is |
|
1038 | - * @return string |
|
1039 | - * @throws EE_Error |
|
1040 | - * @throws ReflectionException |
|
1041 | - */ |
|
1042 | - protected function venuesDropdown($current_value = '') |
|
1043 | - { |
|
1044 | - $values = [ |
|
1045 | - '' => esc_html__('All Venues', 'event_espresso'), |
|
1046 | - ]; |
|
1047 | - // populate the list of venues. |
|
1048 | - $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]); |
|
1049 | - |
|
1050 | - foreach ($venues as $venue) { |
|
1051 | - $values[ $venue->ID() ] = $venue->name(); |
|
1052 | - } |
|
1053 | - |
|
1054 | - return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide'); |
|
1055 | - } |
|
1056 | - |
|
1057 | - |
|
1058 | - /** |
|
1059 | - * output a dropdown of the categories for the category filter on the event admin list table |
|
1060 | - * |
|
1061 | - * @access public |
|
1062 | - * @return string html |
|
1063 | - * @throws EE_Error |
|
1064 | - * @throws ReflectionException |
|
1065 | - */ |
|
1066 | - public function category_dropdown() |
|
1067 | - { |
|
1068 | - return EEH_Form_Fields::generate_event_category_dropdown( |
|
1069 | - $this->request->getRequestParam('EVT_CAT', -1, 'int') |
|
1070 | - ); |
|
1071 | - } |
|
1072 | - |
|
1073 | - |
|
1074 | - /** |
|
1075 | - * get total number of events today |
|
1076 | - * |
|
1077 | - * @access public |
|
1078 | - * @return int |
|
1079 | - * @throws EE_Error |
|
1080 | - */ |
|
1081 | - public function total_events_today() |
|
1082 | - { |
|
1083 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1084 | - 'DTT_EVT_start', |
|
1085 | - date('Y-m-d') . ' 00:00:00', |
|
1086 | - 'Y-m-d H:i:s', |
|
1087 | - 'UTC' |
|
1088 | - ); |
|
1089 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1090 | - 'DTT_EVT_start', |
|
1091 | - date('Y-m-d') . ' 23:59:59', |
|
1092 | - 'Y-m-d H:i:s', |
|
1093 | - 'UTC' |
|
1094 | - ); |
|
1095 | - $where = [ |
|
1096 | - 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
|
1097 | - ]; |
|
1098 | - return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
1099 | - } |
|
1100 | - |
|
1101 | - |
|
1102 | - /** |
|
1103 | - * get total number of events this month |
|
1104 | - * |
|
1105 | - * @access public |
|
1106 | - * @return int |
|
1107 | - * @throws EE_Error |
|
1108 | - */ |
|
1109 | - public function total_events_this_month() |
|
1110 | - { |
|
1111 | - // Dates |
|
1112 | - $this_year_r = date('Y'); |
|
1113 | - $this_month_r = date('m'); |
|
1114 | - $days_this_month = date('t'); |
|
1115 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1116 | - 'DTT_EVT_start', |
|
1117 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
1118 | - 'Y-m-d H:i:s', |
|
1119 | - 'UTC' |
|
1120 | - ); |
|
1121 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1122 | - 'DTT_EVT_start', |
|
1123 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
1124 | - 'Y-m-d H:i:s', |
|
1125 | - 'UTC' |
|
1126 | - ); |
|
1127 | - $where = [ |
|
1128 | - 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
|
1129 | - ]; |
|
1130 | - return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
1131 | - } |
|
1132 | - |
|
1133 | - |
|
1134 | - /** DEFAULT TICKETS STUFF **/ |
|
1135 | - |
|
1136 | - /** |
|
1137 | - * Output default tickets list table view. |
|
1138 | - * |
|
1139 | - * @throws EE_Error |
|
1140 | - */ |
|
1141 | - public function _tickets_overview_list_table() |
|
1142 | - { |
|
1143 | - $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
1144 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
1145 | - } |
|
1146 | - |
|
1147 | - |
|
1148 | - /** |
|
1149 | - * @param int $per_page |
|
1150 | - * @param bool $count |
|
1151 | - * @param bool $trashed |
|
1152 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
1153 | - * @throws EE_Error |
|
1154 | - */ |
|
1155 | - public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
1156 | - { |
|
1157 | - $orderby = $this->request->getRequestParam('orderby', 'TKT_name'); |
|
1158 | - $order = $this->request->getRequestParam('order', 'ASC'); |
|
1159 | - switch ($orderby) { |
|
1160 | - case 'TKT_name': |
|
1161 | - $orderby = ['TKT_name' => $order]; |
|
1162 | - break; |
|
1163 | - case 'TKT_price': |
|
1164 | - $orderby = ['TKT_price' => $order]; |
|
1165 | - break; |
|
1166 | - case 'TKT_uses': |
|
1167 | - $orderby = ['TKT_uses' => $order]; |
|
1168 | - break; |
|
1169 | - case 'TKT_min': |
|
1170 | - $orderby = ['TKT_min' => $order]; |
|
1171 | - break; |
|
1172 | - case 'TKT_max': |
|
1173 | - $orderby = ['TKT_max' => $order]; |
|
1174 | - break; |
|
1175 | - case 'TKT_qty': |
|
1176 | - $orderby = ['TKT_qty' => $order]; |
|
1177 | - break; |
|
1178 | - } |
|
1179 | - |
|
1180 | - $current_page = $this->request->getRequestParam('paged', 1, 'int'); |
|
1181 | - $per_page = $this->request->getRequestParam('perpage', $per_page, 'int'); |
|
1182 | - $offset = ($current_page - 1) * $per_page; |
|
1183 | - |
|
1184 | - $where = [ |
|
1185 | - 'TKT_is_default' => 1, |
|
1186 | - 'TKT_deleted' => $trashed, |
|
1187 | - ]; |
|
1188 | - |
|
1189 | - $search_term = $this->request->getRequestParam('s'); |
|
1190 | - if ($search_term) { |
|
1191 | - $search_term = '%' . $search_term . '%'; |
|
1192 | - $where['OR'] = [ |
|
1193 | - 'TKT_name' => ['LIKE', $search_term], |
|
1194 | - 'TKT_description' => ['LIKE', $search_term], |
|
1195 | - ]; |
|
1196 | - } |
|
1197 | - |
|
1198 | - return $count |
|
1199 | - ? EEM_Ticket::instance()->count_deleted_and_undeleted([$where]) |
|
1200 | - : EEM_Ticket::instance()->get_all_deleted_and_undeleted( |
|
1201 | - [ |
|
1202 | - $where, |
|
1203 | - 'order_by' => $orderby, |
|
1204 | - 'limit' => [$offset, $per_page], |
|
1205 | - 'group_by' => 'TKT_ID', |
|
1206 | - ] |
|
1207 | - ); |
|
1208 | - } |
|
1209 | - |
|
1210 | - |
|
1211 | - /** |
|
1212 | - * @param bool $trash |
|
1213 | - * @throws EE_Error |
|
1214 | - */ |
|
1215 | - protected function _trash_or_restore_ticket($trash = false) |
|
1216 | - { |
|
1217 | - $success = 1; |
|
1218 | - $TKT = EEM_Ticket::instance(); |
|
1219 | - // checkboxes? |
|
1220 | - $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); |
|
1221 | - if (! empty($checkboxes)) { |
|
1222 | - // if array has more than one element then success message should be plural |
|
1223 | - $success = count($checkboxes) > 1 ? 2 : 1; |
|
1224 | - // cycle thru the boxes |
|
1225 | - while (list($TKT_ID, $value) = each($checkboxes)) { |
|
1226 | - if ($trash) { |
|
1227 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1228 | - $success = 0; |
|
1229 | - } |
|
1230 | - } else { |
|
1231 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1232 | - $success = 0; |
|
1233 | - } |
|
1234 | - } |
|
1235 | - } |
|
1236 | - } else { |
|
1237 | - // grab single id and trash |
|
1238 | - $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
|
1239 | - if ($trash) { |
|
1240 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1241 | - $success = 0; |
|
1242 | - } |
|
1243 | - } else { |
|
1244 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1245 | - $success = 0; |
|
1246 | - } |
|
1247 | - } |
|
1248 | - } |
|
1249 | - $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
1250 | - $query_args = [ |
|
1251 | - 'action' => 'ticket_list_table', |
|
1252 | - 'status' => $trash ? '' : 'trashed', |
|
1253 | - ]; |
|
1254 | - $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args); |
|
1255 | - } |
|
1256 | - |
|
1257 | - |
|
1258 | - /** |
|
1259 | - * Handles trashing default ticket. |
|
1260 | - * |
|
1261 | - * @throws EE_Error |
|
1262 | - * @throws ReflectionException |
|
1263 | - */ |
|
1264 | - protected function _delete_ticket() |
|
1265 | - { |
|
1266 | - $success = 1; |
|
1267 | - // checkboxes? |
|
1268 | - $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); |
|
1269 | - if (! empty($checkboxes)) { |
|
1270 | - // if array has more than one element then success message should be plural |
|
1271 | - $success = count($checkboxes) > 1 ? 2 : 1; |
|
1272 | - // cycle thru the boxes |
|
1273 | - while (list($TKT_ID, $value) = each($checkboxes)) { |
|
1274 | - // delete |
|
1275 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1276 | - $success = 0; |
|
1277 | - } |
|
1278 | - } |
|
1279 | - } else { |
|
1280 | - // grab single id and trash |
|
1281 | - $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
|
1282 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1283 | - $success = 0; |
|
1284 | - } |
|
1285 | - } |
|
1286 | - $action_desc = 'deleted'; |
|
1287 | - $query_args = [ |
|
1288 | - 'action' => 'ticket_list_table', |
|
1289 | - 'status' => 'trashed', |
|
1290 | - ]; |
|
1291 | - // fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
1292 | - if ( |
|
1293 | - EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
1294 | - [['TKT_is_default' => 1]], |
|
1295 | - 'TKT_ID', |
|
1296 | - true |
|
1297 | - ) |
|
1298 | - ) { |
|
1299 | - $query_args = []; |
|
1300 | - } |
|
1301 | - $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args); |
|
1302 | - } |
|
1303 | - |
|
1304 | - |
|
1305 | - /** |
|
1306 | - * @param int $TKT_ID |
|
1307 | - * @return bool|int |
|
1308 | - * @throws EE_Error |
|
1309 | - * @throws ReflectionException |
|
1310 | - */ |
|
1311 | - protected function _delete_the_ticket($TKT_ID) |
|
1312 | - { |
|
1313 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
1314 | - $ticket->_remove_relations('Datetime'); |
|
1315 | - // delete all related prices first |
|
1316 | - $ticket->delete_related_permanently('Price'); |
|
1317 | - return $ticket->delete_permanently(); |
|
1318 | - } |
|
17 | + /** |
|
18 | + * Extend_Events_Admin_Page constructor. |
|
19 | + * |
|
20 | + * @param bool $routing |
|
21 | + * @throws EE_Error |
|
22 | + * @throws ReflectionException |
|
23 | + */ |
|
24 | + public function __construct($routing = true) |
|
25 | + { |
|
26 | + parent::__construct($routing); |
|
27 | + if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
28 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
29 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
30 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
31 | + } |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * Sets routes. |
|
37 | + * |
|
38 | + * @throws EE_Error |
|
39 | + */ |
|
40 | + protected function _extend_page_config() |
|
41 | + { |
|
42 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
43 | + // is there a evt_id in the request? |
|
44 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
45 | + $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
|
46 | + $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
|
47 | + $new_page_routes = [ |
|
48 | + 'duplicate_event' => [ |
|
49 | + 'func' => '_duplicate_event', |
|
50 | + 'capability' => 'ee_edit_event', |
|
51 | + 'obj_id' => $EVT_ID, |
|
52 | + 'noheader' => true, |
|
53 | + ], |
|
54 | + 'ticket_list_table' => [ |
|
55 | + 'func' => '_tickets_overview_list_table', |
|
56 | + 'capability' => 'ee_read_default_tickets', |
|
57 | + ], |
|
58 | + 'trash_ticket' => [ |
|
59 | + 'func' => '_trash_or_restore_ticket', |
|
60 | + 'capability' => 'ee_delete_default_ticket', |
|
61 | + 'obj_id' => $TKT_ID, |
|
62 | + 'noheader' => true, |
|
63 | + 'args' => ['trash' => true], |
|
64 | + ], |
|
65 | + 'trash_tickets' => [ |
|
66 | + 'func' => '_trash_or_restore_ticket', |
|
67 | + 'capability' => 'ee_delete_default_tickets', |
|
68 | + 'noheader' => true, |
|
69 | + 'args' => ['trash' => true], |
|
70 | + ], |
|
71 | + 'restore_ticket' => [ |
|
72 | + 'func' => '_trash_or_restore_ticket', |
|
73 | + 'capability' => 'ee_delete_default_ticket', |
|
74 | + 'obj_id' => $TKT_ID, |
|
75 | + 'noheader' => true, |
|
76 | + ], |
|
77 | + 'restore_tickets' => [ |
|
78 | + 'func' => '_trash_or_restore_ticket', |
|
79 | + 'capability' => 'ee_delete_default_tickets', |
|
80 | + 'noheader' => true, |
|
81 | + ], |
|
82 | + 'delete_ticket' => [ |
|
83 | + 'func' => '_delete_ticket', |
|
84 | + 'capability' => 'ee_delete_default_ticket', |
|
85 | + 'obj_id' => $TKT_ID, |
|
86 | + 'noheader' => true, |
|
87 | + ], |
|
88 | + 'delete_tickets' => [ |
|
89 | + 'func' => '_delete_ticket', |
|
90 | + 'capability' => 'ee_delete_default_tickets', |
|
91 | + 'noheader' => true, |
|
92 | + ], |
|
93 | + 'import_page' => [ |
|
94 | + 'func' => '_import_page', |
|
95 | + 'capability' => 'import', |
|
96 | + ], |
|
97 | + 'import' => [ |
|
98 | + 'func' => '_import_events', |
|
99 | + 'capability' => 'import', |
|
100 | + 'noheader' => true, |
|
101 | + ], |
|
102 | + 'import_events' => [ |
|
103 | + 'func' => '_import_events', |
|
104 | + 'capability' => 'import', |
|
105 | + 'noheader' => true, |
|
106 | + ], |
|
107 | + 'export_events' => [ |
|
108 | + 'func' => '_events_export', |
|
109 | + 'capability' => 'export', |
|
110 | + 'noheader' => true, |
|
111 | + ], |
|
112 | + 'export_categories' => [ |
|
113 | + 'func' => '_categories_export', |
|
114 | + 'capability' => 'export', |
|
115 | + 'noheader' => true, |
|
116 | + ], |
|
117 | + 'sample_export_file' => [ |
|
118 | + 'func' => '_sample_export_file', |
|
119 | + 'capability' => 'export', |
|
120 | + 'noheader' => true, |
|
121 | + ], |
|
122 | + 'update_template_settings' => [ |
|
123 | + 'func' => '_update_template_settings', |
|
124 | + 'capability' => 'manage_options', |
|
125 | + 'noheader' => true, |
|
126 | + ], |
|
127 | + ]; |
|
128 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
129 | + // partial route/config override |
|
130 | + $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
131 | + $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
132 | + $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
133 | + $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
134 | + $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
135 | + $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
136 | + // add tickets tab but only if there are more than one default ticket! |
|
137 | + $ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
138 | + [['TKT_is_default' => 1]], |
|
139 | + 'TKT_ID', |
|
140 | + true |
|
141 | + ); |
|
142 | + if ($ticket_count > 1) { |
|
143 | + $new_page_config = [ |
|
144 | + 'ticket_list_table' => [ |
|
145 | + 'nav' => [ |
|
146 | + 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
147 | + 'order' => 60, |
|
148 | + ], |
|
149 | + 'list_table' => 'Tickets_List_Table', |
|
150 | + 'require_nonce' => false, |
|
151 | + ], |
|
152 | + ]; |
|
153 | + } |
|
154 | + // template settings |
|
155 | + $new_page_config['template_settings'] = [ |
|
156 | + 'nav' => [ |
|
157 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
158 | + 'order' => 30, |
|
159 | + ], |
|
160 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
161 | + 'help_tabs' => [ |
|
162 | + 'general_settings_templates_help_tab' => [ |
|
163 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
164 | + 'filename' => 'general_settings_templates', |
|
165 | + ], |
|
166 | + ], |
|
167 | + 'require_nonce' => false, |
|
168 | + ]; |
|
169 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
170 | + // add filters and actions |
|
171 | + // modifying _views |
|
172 | + add_filter( |
|
173 | + 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
174 | + [$this, 'add_additional_datetime_button'], |
|
175 | + 10, |
|
176 | + 2 |
|
177 | + ); |
|
178 | + add_filter( |
|
179 | + 'FHEE_event_datetime_metabox_clone_button_template', |
|
180 | + [$this, 'add_datetime_clone_button'], |
|
181 | + 10, |
|
182 | + 2 |
|
183 | + ); |
|
184 | + add_filter( |
|
185 | + 'FHEE_event_datetime_metabox_timezones_template', |
|
186 | + [$this, 'datetime_timezones_template'], |
|
187 | + 10, |
|
188 | + 2 |
|
189 | + ); |
|
190 | + // filters for event list table |
|
191 | + add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2); |
|
192 | + add_filter( |
|
193 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
194 | + [$this, 'extra_list_table_actions'], |
|
195 | + 10, |
|
196 | + 2 |
|
197 | + ); |
|
198 | + // legend item |
|
199 | + add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']); |
|
200 | + add_action('admin_init', [$this, 'admin_init']); |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * admin_init |
|
206 | + */ |
|
207 | + public function admin_init() |
|
208 | + { |
|
209 | + EE_Registry::$i18n_js_strings = array_merge( |
|
210 | + EE_Registry::$i18n_js_strings, |
|
211 | + [ |
|
212 | + 'image_confirm' => esc_html__( |
|
213 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
214 | + 'event_espresso' |
|
215 | + ), |
|
216 | + 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
217 | + 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
218 | + 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
219 | + 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
220 | + 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
221 | + ] |
|
222 | + ); |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * Add per page screen options to the default ticket list table view. |
|
228 | + */ |
|
229 | + protected function _add_screen_options_ticket_list_table() |
|
230 | + { |
|
231 | + $this->_per_page_screen_option(); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * @param string $return |
|
237 | + * @param int $id |
|
238 | + * @param string $new_title |
|
239 | + * @param string $new_slug |
|
240 | + * @return string |
|
241 | + */ |
|
242 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
243 | + { |
|
244 | + $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
245 | + // make sure this is only when editing |
|
246 | + if (! empty($id)) { |
|
247 | + $href = EE_Admin_Page::add_query_args_and_nonce( |
|
248 | + ['action' => 'duplicate_event', 'EVT_ID' => $id], |
|
249 | + $this->_admin_base_url |
|
250 | + ); |
|
251 | + $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
252 | + $return .= '<a href="' |
|
253 | + . $href |
|
254 | + . '" title="' |
|
255 | + . $title |
|
256 | + . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
257 | + . $title |
|
258 | + . '</a>'; |
|
259 | + } |
|
260 | + return $return; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * Set the list table views for the default ticket list table view. |
|
266 | + */ |
|
267 | + public function _set_list_table_views_ticket_list_table() |
|
268 | + { |
|
269 | + $this->_views = [ |
|
270 | + 'all' => [ |
|
271 | + 'slug' => 'all', |
|
272 | + 'label' => esc_html__('All', 'event_espresso'), |
|
273 | + 'count' => 0, |
|
274 | + 'bulk_action' => [ |
|
275 | + 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
276 | + ], |
|
277 | + ], |
|
278 | + 'trashed' => [ |
|
279 | + 'slug' => 'trashed', |
|
280 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
281 | + 'count' => 0, |
|
282 | + 'bulk_action' => [ |
|
283 | + 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
284 | + 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
285 | + ], |
|
286 | + ], |
|
287 | + ]; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * Enqueue scripts and styles for the event editor. |
|
293 | + */ |
|
294 | + public function load_scripts_styles_edit() |
|
295 | + { |
|
296 | + wp_register_script( |
|
297 | + 'ee-event-editor-heartbeat', |
|
298 | + EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
299 | + ['ee_admin_js', 'heartbeat'], |
|
300 | + EVENT_ESPRESSO_VERSION, |
|
301 | + true |
|
302 | + ); |
|
303 | + wp_enqueue_script('ee-accounting'); |
|
304 | + // styles |
|
305 | + wp_enqueue_style('espresso-ui-theme'); |
|
306 | + wp_enqueue_script('event_editor_js'); |
|
307 | + wp_enqueue_script('ee-event-editor-heartbeat'); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * Returns template for the additional datetime. |
|
313 | + * |
|
314 | + * @param string $template |
|
315 | + * @param array $template_args |
|
316 | + * @return string |
|
317 | + * @throws DomainException |
|
318 | + */ |
|
319 | + public function add_additional_datetime_button($template, $template_args) |
|
320 | + { |
|
321 | + return EEH_Template::display_template( |
|
322 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
323 | + $template_args, |
|
324 | + true |
|
325 | + ); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Returns the template for cloning a datetime. |
|
331 | + * |
|
332 | + * @param $template |
|
333 | + * @param $template_args |
|
334 | + * @return string |
|
335 | + * @throws DomainException |
|
336 | + */ |
|
337 | + public function add_datetime_clone_button($template, $template_args) |
|
338 | + { |
|
339 | + return EEH_Template::display_template( |
|
340 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
341 | + $template_args, |
|
342 | + true |
|
343 | + ); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Returns the template for datetime timezones. |
|
349 | + * |
|
350 | + * @param $template |
|
351 | + * @param $template_args |
|
352 | + * @return string |
|
353 | + * @throws DomainException |
|
354 | + */ |
|
355 | + public function datetime_timezones_template($template, $template_args) |
|
356 | + { |
|
357 | + return EEH_Template::display_template( |
|
358 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
359 | + $template_args, |
|
360 | + true |
|
361 | + ); |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * Sets the views for the default list table view. |
|
367 | + * |
|
368 | + * @throws EE_Error |
|
369 | + */ |
|
370 | + protected function _set_list_table_views_default() |
|
371 | + { |
|
372 | + parent::_set_list_table_views_default(); |
|
373 | + $new_views = [ |
|
374 | + 'today' => [ |
|
375 | + 'slug' => 'today', |
|
376 | + 'label' => esc_html__('Today', 'event_espresso'), |
|
377 | + 'count' => $this->total_events_today(), |
|
378 | + 'bulk_action' => [ |
|
379 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
380 | + ], |
|
381 | + ], |
|
382 | + 'month' => [ |
|
383 | + 'slug' => 'month', |
|
384 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
385 | + 'count' => $this->total_events_this_month(), |
|
386 | + 'bulk_action' => [ |
|
387 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
388 | + ], |
|
389 | + ], |
|
390 | + ]; |
|
391 | + $this->_views = array_merge($this->_views, $new_views); |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + /** |
|
396 | + * Returns the extra action links for the default list table view. |
|
397 | + * |
|
398 | + * @param array $action_links |
|
399 | + * @param EE_Event $event |
|
400 | + * @return array |
|
401 | + * @throws EE_Error |
|
402 | + * @throws ReflectionException |
|
403 | + */ |
|
404 | + public function extra_list_table_actions(array $action_links, EE_Event $event) |
|
405 | + { |
|
406 | + if ( |
|
407 | + EE_Registry::instance()->CAP->current_user_can( |
|
408 | + 'ee_read_registrations', |
|
409 | + 'espresso_registrations_reports', |
|
410 | + $event->ID() |
|
411 | + ) |
|
412 | + ) { |
|
413 | + $reports_query_args = [ |
|
414 | + 'action' => 'reports', |
|
415 | + 'EVT_ID' => $event->ID(), |
|
416 | + ]; |
|
417 | + $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
418 | + $action_links[] = '<a href="' |
|
419 | + . $reports_link |
|
420 | + . '" title="' |
|
421 | + . esc_attr__('View Report', 'event_espresso') |
|
422 | + . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
423 | + . "\n\t"; |
|
424 | + } |
|
425 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
426 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
427 | + $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
428 | + 'see_notifications_for', |
|
429 | + null, |
|
430 | + ['EVT_ID' => $event->ID()] |
|
431 | + ); |
|
432 | + } |
|
433 | + return $action_links; |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * @param $items |
|
439 | + * @return mixed |
|
440 | + */ |
|
441 | + public function additional_legend_items($items) |
|
442 | + { |
|
443 | + if ( |
|
444 | + EE_Registry::instance()->CAP->current_user_can( |
|
445 | + 'ee_read_registrations', |
|
446 | + 'espresso_registrations_reports' |
|
447 | + ) |
|
448 | + ) { |
|
449 | + $items['reports'] = [ |
|
450 | + 'class' => 'dashicons dashicons-chart-bar', |
|
451 | + 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
452 | + ]; |
|
453 | + } |
|
454 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
455 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
456 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
457 | + $items['view_related_messages'] = [ |
|
458 | + 'class' => $related_for_icon['css_class'], |
|
459 | + 'desc' => $related_for_icon['label'], |
|
460 | + ]; |
|
461 | + } |
|
462 | + } |
|
463 | + return $items; |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * This is the callback method for the duplicate event route |
|
469 | + * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
470 | + * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
471 | + * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
472 | + * After duplication the redirect is to the new event edit page. |
|
473 | + * |
|
474 | + * @return void |
|
475 | + * @throws EE_Error If EE_Event is not available with given ID |
|
476 | + * @throws ReflectionException |
|
477 | + * @access protected |
|
478 | + */ |
|
479 | + protected function _duplicate_event() |
|
480 | + { |
|
481 | + // first make sure the ID for the event is in the request. |
|
482 | + // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
483 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
484 | + if (! $EVT_ID) { |
|
485 | + EE_Error::add_error( |
|
486 | + esc_html__( |
|
487 | + 'In order to duplicate an event an Event ID is required. None was given.', |
|
488 | + 'event_espresso' |
|
489 | + ), |
|
490 | + __FILE__, |
|
491 | + __FUNCTION__, |
|
492 | + __LINE__ |
|
493 | + ); |
|
494 | + $this->_redirect_after_action(false, '', '', [], true); |
|
495 | + return; |
|
496 | + } |
|
497 | + // k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
498 | + $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
499 | + if (! $orig_event instanceof EE_Event) { |
|
500 | + throw new EE_Error( |
|
501 | + sprintf( |
|
502 | + esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
503 | + $EVT_ID |
|
504 | + ) |
|
505 | + ); |
|
506 | + } |
|
507 | + // k now let's clone the $orig_event before getting relations |
|
508 | + $new_event = clone $orig_event; |
|
509 | + // original datetimes |
|
510 | + $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
511 | + // other original relations |
|
512 | + $orig_ven = $orig_event->get_many_related('Venue'); |
|
513 | + // reset the ID and modify other details to make it clear this is a dupe |
|
514 | + $new_event->set('EVT_ID', 0); |
|
515 | + $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
516 | + $new_event->set('EVT_name', $new_name); |
|
517 | + $new_event->set( |
|
518 | + 'EVT_slug', |
|
519 | + wp_unique_post_slug( |
|
520 | + sanitize_title($orig_event->name()), |
|
521 | + 0, |
|
522 | + 'publish', |
|
523 | + 'espresso_events', |
|
524 | + 0 |
|
525 | + ) |
|
526 | + ); |
|
527 | + $new_event->set('status', 'draft'); |
|
528 | + // duplicate discussion settings |
|
529 | + $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
530 | + $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
531 | + // save the new event |
|
532 | + $new_event->save(); |
|
533 | + // venues |
|
534 | + foreach ($orig_ven as $ven) { |
|
535 | + $new_event->_add_relation_to($ven, 'Venue'); |
|
536 | + } |
|
537 | + $new_event->save(); |
|
538 | + // now we need to get the question group relations and handle that |
|
539 | + // first primary question groups |
|
540 | + $orig_primary_qgs = $orig_event->get_many_related( |
|
541 | + 'Question_Group', |
|
542 | + [['Event_Question_Group.EQG_primary' => true]] |
|
543 | + ); |
|
544 | + if (! empty($orig_primary_qgs)) { |
|
545 | + foreach ($orig_primary_qgs as $obj) { |
|
546 | + if ($obj instanceof EE_Question_Group) { |
|
547 | + $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]); |
|
548 | + } |
|
549 | + } |
|
550 | + } |
|
551 | + // next additional attendee question groups |
|
552 | + $orig_additional_qgs = $orig_event->get_many_related( |
|
553 | + 'Question_Group', |
|
554 | + [['Event_Question_Group.EQG_additional' => true]] |
|
555 | + ); |
|
556 | + if (! empty($orig_additional_qgs)) { |
|
557 | + foreach ($orig_additional_qgs as $obj) { |
|
558 | + if ($obj instanceof EE_Question_Group) { |
|
559 | + $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]); |
|
560 | + } |
|
561 | + } |
|
562 | + } |
|
563 | + |
|
564 | + $new_event->save(); |
|
565 | + |
|
566 | + // k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
567 | + $cloned_tickets = []; |
|
568 | + foreach ($orig_datetimes as $orig_dtt) { |
|
569 | + if (! $orig_dtt instanceof EE_Datetime) { |
|
570 | + continue; |
|
571 | + } |
|
572 | + $new_dtt = clone $orig_dtt; |
|
573 | + $orig_tickets = $orig_dtt->tickets(); |
|
574 | + // save new dtt then add to event |
|
575 | + $new_dtt->set('DTT_ID', 0); |
|
576 | + $new_dtt->set('DTT_sold', 0); |
|
577 | + $new_dtt->set_reserved(0); |
|
578 | + $new_dtt->save(); |
|
579 | + $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
580 | + $new_event->save(); |
|
581 | + // now let's get the ticket relations setup. |
|
582 | + foreach ((array) $orig_tickets as $orig_ticket) { |
|
583 | + // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
584 | + if (! $orig_ticket instanceof EE_Ticket) { |
|
585 | + continue; |
|
586 | + } |
|
587 | + // is this ticket archived? If it is then let's skip |
|
588 | + if ($orig_ticket->get('TKT_deleted')) { |
|
589 | + continue; |
|
590 | + } |
|
591 | + // does this original ticket already exist in the clone_tickets cache? |
|
592 | + // If so we'll just use the new ticket from it. |
|
593 | + if (isset($cloned_tickets[ $orig_ticket->ID() ])) { |
|
594 | + $new_ticket = $cloned_tickets[ $orig_ticket->ID() ]; |
|
595 | + } else { |
|
596 | + $new_ticket = clone $orig_ticket; |
|
597 | + // get relations on the $orig_ticket that we need to setup. |
|
598 | + $orig_prices = $orig_ticket->prices(); |
|
599 | + $new_ticket->set('TKT_ID', 0); |
|
600 | + $new_ticket->set('TKT_sold', 0); |
|
601 | + $new_ticket->set('TKT_reserved', 0); |
|
602 | + $new_ticket->save(); // make sure new ticket has ID. |
|
603 | + // price relations on new ticket need to be setup. |
|
604 | + foreach ($orig_prices as $orig_price) { |
|
605 | + $new_price = clone $orig_price; |
|
606 | + $new_price->set('PRC_ID', 0); |
|
607 | + $new_price->save(); |
|
608 | + $new_ticket->_add_relation_to($new_price, 'Price'); |
|
609 | + $new_ticket->save(); |
|
610 | + } |
|
611 | + |
|
612 | + do_action( |
|
613 | + 'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after', |
|
614 | + $orig_ticket, |
|
615 | + $new_ticket, |
|
616 | + $orig_prices, |
|
617 | + $orig_event, |
|
618 | + $orig_dtt, |
|
619 | + $new_dtt |
|
620 | + ); |
|
621 | + } |
|
622 | + // k now we can add the new ticket as a relation to the new datetime |
|
623 | + // and make sure its added to our cached $cloned_tickets array |
|
624 | + // for use with later datetimes that have the same ticket. |
|
625 | + $new_dtt->_add_relation_to($new_ticket, 'Ticket'); |
|
626 | + $new_dtt->save(); |
|
627 | + $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket; |
|
628 | + } |
|
629 | + } |
|
630 | + // clone taxonomy information |
|
631 | + $taxonomies_to_clone_with = apply_filters( |
|
632 | + 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
633 | + ['espresso_event_categories', 'espresso_event_type', 'post_tag'] |
|
634 | + ); |
|
635 | + // get terms for original event (notice) |
|
636 | + $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
637 | + // loop through terms and add them to new event. |
|
638 | + foreach ($orig_terms as $term) { |
|
639 | + wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
640 | + } |
|
641 | + |
|
642 | + // duplicate other core WP_Post items for this event. |
|
643 | + // post thumbnail (feature image). |
|
644 | + $feature_image_id = get_post_thumbnail_id($orig_event->ID()); |
|
645 | + if ($feature_image_id) { |
|
646 | + update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id); |
|
647 | + } |
|
648 | + |
|
649 | + // duplicate page_template setting |
|
650 | + $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true); |
|
651 | + if ($page_template) { |
|
652 | + update_post_meta($new_event->ID(), '_wp_page_template', $page_template); |
|
653 | + } |
|
654 | + |
|
655 | + do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
656 | + // now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
657 | + if ($new_event->ID()) { |
|
658 | + $redirect_args = [ |
|
659 | + 'post' => $new_event->ID(), |
|
660 | + 'action' => 'edit', |
|
661 | + ]; |
|
662 | + EE_Error::add_success( |
|
663 | + esc_html__( |
|
664 | + 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
665 | + 'event_espresso' |
|
666 | + ) |
|
667 | + ); |
|
668 | + } else { |
|
669 | + $redirect_args = [ |
|
670 | + 'action' => 'default', |
|
671 | + ]; |
|
672 | + EE_Error::add_error( |
|
673 | + esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
674 | + __FILE__, |
|
675 | + __FUNCTION__, |
|
676 | + __LINE__ |
|
677 | + ); |
|
678 | + } |
|
679 | + $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * Generates output for the import page. |
|
685 | + * |
|
686 | + * @throws EE_Error |
|
687 | + */ |
|
688 | + protected function _import_page() |
|
689 | + { |
|
690 | + $title = esc_html__('Import', 'event_espresso'); |
|
691 | + $intro = esc_html__( |
|
692 | + 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
693 | + 'event_espresso' |
|
694 | + ); |
|
695 | + |
|
696 | + $form_url = EVENTS_ADMIN_URL; |
|
697 | + $action = 'import_events'; |
|
698 | + $type = 'csv'; |
|
699 | + |
|
700 | + $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
701 | + $title, |
|
702 | + $intro, |
|
703 | + $form_url, |
|
704 | + $action, |
|
705 | + $type |
|
706 | + ); |
|
707 | + |
|
708 | + $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
709 | + ['action' => 'sample_export_file'], |
|
710 | + $this->_admin_base_url |
|
711 | + ); |
|
712 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
713 | + EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
714 | + $this->_template_args, |
|
715 | + true |
|
716 | + ); |
|
717 | + $this->display_admin_page_with_sidebar(); |
|
718 | + } |
|
719 | + |
|
720 | + |
|
721 | + /** |
|
722 | + * _import_events |
|
723 | + * This handles displaying the screen and running imports for importing events. |
|
724 | + * |
|
725 | + * @return void |
|
726 | + * @throws EE_Error |
|
727 | + */ |
|
728 | + protected function _import_events() |
|
729 | + { |
|
730 | + require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
731 | + $success = EE_Import::instance()->import(); |
|
732 | + $this->_redirect_after_action( |
|
733 | + $success, |
|
734 | + esc_html__('Import File', 'event_espresso'), |
|
735 | + 'ran', |
|
736 | + ['action' => 'import_page'], |
|
737 | + true |
|
738 | + ); |
|
739 | + } |
|
740 | + |
|
741 | + |
|
742 | + /** |
|
743 | + * _events_export |
|
744 | + * Will export all (or just the given event) to a Excel compatible file. |
|
745 | + * |
|
746 | + * @access protected |
|
747 | + * @return void |
|
748 | + */ |
|
749 | + protected function _events_export() |
|
750 | + { |
|
751 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
752 | + $EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int'); |
|
753 | + $this->request->mergeRequestParams( |
|
754 | + [ |
|
755 | + 'export' => 'report', |
|
756 | + 'action' => 'all_event_data', |
|
757 | + 'EVT_ID' => $EVT_ID, |
|
758 | + ] |
|
759 | + ); |
|
760 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
761 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
762 | + $EE_Export = EE_Export::instance($this->request->requestParams()); |
|
763 | + $EE_Export->export(); |
|
764 | + } |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * handle category exports() |
|
770 | + * |
|
771 | + * @return void |
|
772 | + */ |
|
773 | + protected function _categories_export() |
|
774 | + { |
|
775 | + $EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
776 | + $this->request->mergeRequestParams( |
|
777 | + [ |
|
778 | + 'export' => 'report', |
|
779 | + 'action' => 'categories', |
|
780 | + 'EVT_ID' => $EVT_ID, |
|
781 | + ] |
|
782 | + ); |
|
783 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
784 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
785 | + $EE_Export = EE_Export::instance($this->request->requestParams()); |
|
786 | + $EE_Export->export(); |
|
787 | + } |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + /** |
|
792 | + * Creates a sample CSV file for importing |
|
793 | + */ |
|
794 | + protected function _sample_export_file() |
|
795 | + { |
|
796 | + // require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
797 | + EE_Export::instance()->export_sample(); |
|
798 | + } |
|
799 | + |
|
800 | + |
|
801 | + /************* Template Settings *************/ |
|
802 | + /** |
|
803 | + * Generates template settings page output |
|
804 | + * |
|
805 | + * @throws DomainException |
|
806 | + * @throws EE_Error |
|
807 | + */ |
|
808 | + protected function _template_settings() |
|
809 | + { |
|
810 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
811 | + /** |
|
812 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
813 | + * from General_Settings_Admin_Page to here. |
|
814 | + */ |
|
815 | + $this->_template_args = apply_filters( |
|
816 | + 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
817 | + $this->_template_args |
|
818 | + ); |
|
819 | + $this->_set_add_edit_form_tags('update_template_settings'); |
|
820 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
821 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
822 | + EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
823 | + $this->_template_args, |
|
824 | + true |
|
825 | + ); |
|
826 | + $this->display_admin_page_with_sidebar(); |
|
827 | + } |
|
828 | + |
|
829 | + |
|
830 | + /** |
|
831 | + * Handler for updating template settings. |
|
832 | + * |
|
833 | + * @throws EE_Error |
|
834 | + */ |
|
835 | + protected function _update_template_settings() |
|
836 | + { |
|
837 | + /** |
|
838 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
839 | + * from General_Settings_Admin_Page to here. |
|
840 | + */ |
|
841 | + EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
842 | + 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
843 | + EE_Registry::instance()->CFG->template_settings, |
|
844 | + $this->request->requestParams() |
|
845 | + ); |
|
846 | + // update custom post type slugs and detect if we need to flush rewrite rules |
|
847 | + $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
848 | + |
|
849 | + $event_cpt_slug = $this->request->getRequestParam('event_cpt_slug'); |
|
850 | + |
|
851 | + EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug |
|
852 | + ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
853 | + : EEH_URL::slugify($event_cpt_slug, 'events'); |
|
854 | + |
|
855 | + $what = esc_html__('Template Settings', 'event_espresso'); |
|
856 | + $success = $this->_update_espresso_configuration( |
|
857 | + $what, |
|
858 | + EE_Registry::instance()->CFG->template_settings, |
|
859 | + __FILE__, |
|
860 | + __FUNCTION__, |
|
861 | + __LINE__ |
|
862 | + ); |
|
863 | + if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
864 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
865 | + $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
866 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
867 | + ); |
|
868 | + $rewrite_rules->flush(); |
|
869 | + } |
|
870 | + $this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']); |
|
871 | + } |
|
872 | + |
|
873 | + |
|
874 | + /** |
|
875 | + * _premium_event_editor_meta_boxes |
|
876 | + * add all metaboxes related to the event_editor |
|
877 | + * |
|
878 | + * @access protected |
|
879 | + * @return void |
|
880 | + * @throws EE_Error |
|
881 | + * @throws ReflectionException |
|
882 | + */ |
|
883 | + protected function _premium_event_editor_meta_boxes() |
|
884 | + { |
|
885 | + $this->verify_cpt_object(); |
|
886 | + add_meta_box( |
|
887 | + 'espresso_event_editor_event_options', |
|
888 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
889 | + [$this, 'registration_options_meta_box'], |
|
890 | + $this->page_slug, |
|
891 | + 'side', |
|
892 | + 'core' |
|
893 | + ); |
|
894 | + } |
|
895 | + |
|
896 | + |
|
897 | + /** |
|
898 | + * override caf metabox |
|
899 | + * |
|
900 | + * @return void |
|
901 | + * @throws EE_Error |
|
902 | + * @throws ReflectionException |
|
903 | + */ |
|
904 | + public function registration_options_meta_box() |
|
905 | + { |
|
906 | + $yes_no_values = [ |
|
907 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
908 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
909 | + ]; |
|
910 | + |
|
911 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
912 | + [ |
|
913 | + EEM_Registration::status_id_cancelled, |
|
914 | + EEM_Registration::status_id_declined, |
|
915 | + EEM_Registration::status_id_incomplete, |
|
916 | + EEM_Registration::status_id_wait_list, |
|
917 | + ], |
|
918 | + true |
|
919 | + ); |
|
920 | + |
|
921 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
922 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
923 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
924 | + |
|
925 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
926 | + 'default_reg_status', |
|
927 | + $default_reg_status_values, |
|
928 | + $this->_cpt_model_obj->default_registration_status() |
|
929 | + ); |
|
930 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
931 | + 'display_desc', |
|
932 | + $yes_no_values, |
|
933 | + $this->_cpt_model_obj->display_description() |
|
934 | + ); |
|
935 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
936 | + 'display_ticket_selector', |
|
937 | + $yes_no_values, |
|
938 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
939 | + '', |
|
940 | + '', |
|
941 | + false |
|
942 | + ); |
|
943 | + $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
944 | + 'EVT_default_registration_status', |
|
945 | + $default_reg_status_values, |
|
946 | + $this->_cpt_model_obj->default_registration_status() |
|
947 | + ); |
|
948 | + $template_args['additional_registration_options'] = apply_filters( |
|
949 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
950 | + '', |
|
951 | + $template_args, |
|
952 | + $yes_no_values, |
|
953 | + $default_reg_status_values |
|
954 | + ); |
|
955 | + EEH_Template::display_template( |
|
956 | + EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
957 | + $template_args |
|
958 | + ); |
|
959 | + } |
|
960 | + |
|
961 | + |
|
962 | + |
|
963 | + /** |
|
964 | + * wp_list_table_mods for caf |
|
965 | + * ============================ |
|
966 | + */ |
|
967 | + /** |
|
968 | + * hook into list table filters and provide filters for caffeinated list table |
|
969 | + * |
|
970 | + * @param array $old_filters any existing filters present |
|
971 | + * @param array $list_table_obj the list table object |
|
972 | + * @return array new filters |
|
973 | + * @throws EE_Error |
|
974 | + * @throws ReflectionException |
|
975 | + */ |
|
976 | + public function list_table_filters($old_filters, $list_table_obj) |
|
977 | + { |
|
978 | + $filters = []; |
|
979 | + // first month/year filters |
|
980 | + $filters[] = $this->espresso_event_months_dropdown(); |
|
981 | + $status = $this->request->getRequestParam('status'); |
|
982 | + // active status dropdown |
|
983 | + if ($status !== 'draft') { |
|
984 | + $filters[] = $this->active_status_dropdown($this->request->getRequestParam('active_status')); |
|
985 | + $filters[] = $this->venuesDropdown($this->request->getRequestParam('venue')); |
|
986 | + } |
|
987 | + // category filter |
|
988 | + $filters[] = $this->category_dropdown(); |
|
989 | + return array_merge($old_filters, $filters); |
|
990 | + } |
|
991 | + |
|
992 | + |
|
993 | + /** |
|
994 | + * espresso_event_months_dropdown |
|
995 | + * |
|
996 | + * @access public |
|
997 | + * @return string dropdown listing month/year selections for events. |
|
998 | + * @throws EE_Error |
|
999 | + */ |
|
1000 | + public function espresso_event_months_dropdown() |
|
1001 | + { |
|
1002 | + // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
1003 | + // Note we need to include any other filters that are set! |
|
1004 | + return EEH_Form_Fields::generate_event_months_dropdown( |
|
1005 | + $this->request->getRequestParam('month_range'), |
|
1006 | + $this->request->getRequestParam('status'), |
|
1007 | + $this->request->getRequestParam('EVT_CAT', 0, 'int'), |
|
1008 | + $this->request->getRequestParam('active_status') |
|
1009 | + ); |
|
1010 | + } |
|
1011 | + |
|
1012 | + |
|
1013 | + /** |
|
1014 | + * returns a list of "active" statuses on the event |
|
1015 | + * |
|
1016 | + * @param string $current_value whatever the current active status is |
|
1017 | + * @return string |
|
1018 | + */ |
|
1019 | + public function active_status_dropdown($current_value = '') |
|
1020 | + { |
|
1021 | + $select_name = 'active_status'; |
|
1022 | + $values = [ |
|
1023 | + 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
1024 | + 'active' => esc_html__('Active', 'event_espresso'), |
|
1025 | + 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
1026 | + 'expired' => esc_html__('Expired', 'event_espresso'), |
|
1027 | + 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
1028 | + ]; |
|
1029 | + |
|
1030 | + return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide'); |
|
1031 | + } |
|
1032 | + |
|
1033 | + |
|
1034 | + /** |
|
1035 | + * returns a list of "venues" |
|
1036 | + * |
|
1037 | + * @param string $current_value whatever the current active status is |
|
1038 | + * @return string |
|
1039 | + * @throws EE_Error |
|
1040 | + * @throws ReflectionException |
|
1041 | + */ |
|
1042 | + protected function venuesDropdown($current_value = '') |
|
1043 | + { |
|
1044 | + $values = [ |
|
1045 | + '' => esc_html__('All Venues', 'event_espresso'), |
|
1046 | + ]; |
|
1047 | + // populate the list of venues. |
|
1048 | + $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]); |
|
1049 | + |
|
1050 | + foreach ($venues as $venue) { |
|
1051 | + $values[ $venue->ID() ] = $venue->name(); |
|
1052 | + } |
|
1053 | + |
|
1054 | + return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide'); |
|
1055 | + } |
|
1056 | + |
|
1057 | + |
|
1058 | + /** |
|
1059 | + * output a dropdown of the categories for the category filter on the event admin list table |
|
1060 | + * |
|
1061 | + * @access public |
|
1062 | + * @return string html |
|
1063 | + * @throws EE_Error |
|
1064 | + * @throws ReflectionException |
|
1065 | + */ |
|
1066 | + public function category_dropdown() |
|
1067 | + { |
|
1068 | + return EEH_Form_Fields::generate_event_category_dropdown( |
|
1069 | + $this->request->getRequestParam('EVT_CAT', -1, 'int') |
|
1070 | + ); |
|
1071 | + } |
|
1072 | + |
|
1073 | + |
|
1074 | + /** |
|
1075 | + * get total number of events today |
|
1076 | + * |
|
1077 | + * @access public |
|
1078 | + * @return int |
|
1079 | + * @throws EE_Error |
|
1080 | + */ |
|
1081 | + public function total_events_today() |
|
1082 | + { |
|
1083 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1084 | + 'DTT_EVT_start', |
|
1085 | + date('Y-m-d') . ' 00:00:00', |
|
1086 | + 'Y-m-d H:i:s', |
|
1087 | + 'UTC' |
|
1088 | + ); |
|
1089 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1090 | + 'DTT_EVT_start', |
|
1091 | + date('Y-m-d') . ' 23:59:59', |
|
1092 | + 'Y-m-d H:i:s', |
|
1093 | + 'UTC' |
|
1094 | + ); |
|
1095 | + $where = [ |
|
1096 | + 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
|
1097 | + ]; |
|
1098 | + return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
1099 | + } |
|
1100 | + |
|
1101 | + |
|
1102 | + /** |
|
1103 | + * get total number of events this month |
|
1104 | + * |
|
1105 | + * @access public |
|
1106 | + * @return int |
|
1107 | + * @throws EE_Error |
|
1108 | + */ |
|
1109 | + public function total_events_this_month() |
|
1110 | + { |
|
1111 | + // Dates |
|
1112 | + $this_year_r = date('Y'); |
|
1113 | + $this_month_r = date('m'); |
|
1114 | + $days_this_month = date('t'); |
|
1115 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1116 | + 'DTT_EVT_start', |
|
1117 | + $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
1118 | + 'Y-m-d H:i:s', |
|
1119 | + 'UTC' |
|
1120 | + ); |
|
1121 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1122 | + 'DTT_EVT_start', |
|
1123 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
1124 | + 'Y-m-d H:i:s', |
|
1125 | + 'UTC' |
|
1126 | + ); |
|
1127 | + $where = [ |
|
1128 | + 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
|
1129 | + ]; |
|
1130 | + return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
1131 | + } |
|
1132 | + |
|
1133 | + |
|
1134 | + /** DEFAULT TICKETS STUFF **/ |
|
1135 | + |
|
1136 | + /** |
|
1137 | + * Output default tickets list table view. |
|
1138 | + * |
|
1139 | + * @throws EE_Error |
|
1140 | + */ |
|
1141 | + public function _tickets_overview_list_table() |
|
1142 | + { |
|
1143 | + $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
1144 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
1145 | + } |
|
1146 | + |
|
1147 | + |
|
1148 | + /** |
|
1149 | + * @param int $per_page |
|
1150 | + * @param bool $count |
|
1151 | + * @param bool $trashed |
|
1152 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
1153 | + * @throws EE_Error |
|
1154 | + */ |
|
1155 | + public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
1156 | + { |
|
1157 | + $orderby = $this->request->getRequestParam('orderby', 'TKT_name'); |
|
1158 | + $order = $this->request->getRequestParam('order', 'ASC'); |
|
1159 | + switch ($orderby) { |
|
1160 | + case 'TKT_name': |
|
1161 | + $orderby = ['TKT_name' => $order]; |
|
1162 | + break; |
|
1163 | + case 'TKT_price': |
|
1164 | + $orderby = ['TKT_price' => $order]; |
|
1165 | + break; |
|
1166 | + case 'TKT_uses': |
|
1167 | + $orderby = ['TKT_uses' => $order]; |
|
1168 | + break; |
|
1169 | + case 'TKT_min': |
|
1170 | + $orderby = ['TKT_min' => $order]; |
|
1171 | + break; |
|
1172 | + case 'TKT_max': |
|
1173 | + $orderby = ['TKT_max' => $order]; |
|
1174 | + break; |
|
1175 | + case 'TKT_qty': |
|
1176 | + $orderby = ['TKT_qty' => $order]; |
|
1177 | + break; |
|
1178 | + } |
|
1179 | + |
|
1180 | + $current_page = $this->request->getRequestParam('paged', 1, 'int'); |
|
1181 | + $per_page = $this->request->getRequestParam('perpage', $per_page, 'int'); |
|
1182 | + $offset = ($current_page - 1) * $per_page; |
|
1183 | + |
|
1184 | + $where = [ |
|
1185 | + 'TKT_is_default' => 1, |
|
1186 | + 'TKT_deleted' => $trashed, |
|
1187 | + ]; |
|
1188 | + |
|
1189 | + $search_term = $this->request->getRequestParam('s'); |
|
1190 | + if ($search_term) { |
|
1191 | + $search_term = '%' . $search_term . '%'; |
|
1192 | + $where['OR'] = [ |
|
1193 | + 'TKT_name' => ['LIKE', $search_term], |
|
1194 | + 'TKT_description' => ['LIKE', $search_term], |
|
1195 | + ]; |
|
1196 | + } |
|
1197 | + |
|
1198 | + return $count |
|
1199 | + ? EEM_Ticket::instance()->count_deleted_and_undeleted([$where]) |
|
1200 | + : EEM_Ticket::instance()->get_all_deleted_and_undeleted( |
|
1201 | + [ |
|
1202 | + $where, |
|
1203 | + 'order_by' => $orderby, |
|
1204 | + 'limit' => [$offset, $per_page], |
|
1205 | + 'group_by' => 'TKT_ID', |
|
1206 | + ] |
|
1207 | + ); |
|
1208 | + } |
|
1209 | + |
|
1210 | + |
|
1211 | + /** |
|
1212 | + * @param bool $trash |
|
1213 | + * @throws EE_Error |
|
1214 | + */ |
|
1215 | + protected function _trash_or_restore_ticket($trash = false) |
|
1216 | + { |
|
1217 | + $success = 1; |
|
1218 | + $TKT = EEM_Ticket::instance(); |
|
1219 | + // checkboxes? |
|
1220 | + $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); |
|
1221 | + if (! empty($checkboxes)) { |
|
1222 | + // if array has more than one element then success message should be plural |
|
1223 | + $success = count($checkboxes) > 1 ? 2 : 1; |
|
1224 | + // cycle thru the boxes |
|
1225 | + while (list($TKT_ID, $value) = each($checkboxes)) { |
|
1226 | + if ($trash) { |
|
1227 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1228 | + $success = 0; |
|
1229 | + } |
|
1230 | + } else { |
|
1231 | + if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1232 | + $success = 0; |
|
1233 | + } |
|
1234 | + } |
|
1235 | + } |
|
1236 | + } else { |
|
1237 | + // grab single id and trash |
|
1238 | + $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
|
1239 | + if ($trash) { |
|
1240 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1241 | + $success = 0; |
|
1242 | + } |
|
1243 | + } else { |
|
1244 | + if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1245 | + $success = 0; |
|
1246 | + } |
|
1247 | + } |
|
1248 | + } |
|
1249 | + $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
1250 | + $query_args = [ |
|
1251 | + 'action' => 'ticket_list_table', |
|
1252 | + 'status' => $trash ? '' : 'trashed', |
|
1253 | + ]; |
|
1254 | + $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args); |
|
1255 | + } |
|
1256 | + |
|
1257 | + |
|
1258 | + /** |
|
1259 | + * Handles trashing default ticket. |
|
1260 | + * |
|
1261 | + * @throws EE_Error |
|
1262 | + * @throws ReflectionException |
|
1263 | + */ |
|
1264 | + protected function _delete_ticket() |
|
1265 | + { |
|
1266 | + $success = 1; |
|
1267 | + // checkboxes? |
|
1268 | + $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); |
|
1269 | + if (! empty($checkboxes)) { |
|
1270 | + // if array has more than one element then success message should be plural |
|
1271 | + $success = count($checkboxes) > 1 ? 2 : 1; |
|
1272 | + // cycle thru the boxes |
|
1273 | + while (list($TKT_ID, $value) = each($checkboxes)) { |
|
1274 | + // delete |
|
1275 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1276 | + $success = 0; |
|
1277 | + } |
|
1278 | + } |
|
1279 | + } else { |
|
1280 | + // grab single id and trash |
|
1281 | + $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
|
1282 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1283 | + $success = 0; |
|
1284 | + } |
|
1285 | + } |
|
1286 | + $action_desc = 'deleted'; |
|
1287 | + $query_args = [ |
|
1288 | + 'action' => 'ticket_list_table', |
|
1289 | + 'status' => 'trashed', |
|
1290 | + ]; |
|
1291 | + // fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
1292 | + if ( |
|
1293 | + EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
1294 | + [['TKT_is_default' => 1]], |
|
1295 | + 'TKT_ID', |
|
1296 | + true |
|
1297 | + ) |
|
1298 | + ) { |
|
1299 | + $query_args = []; |
|
1300 | + } |
|
1301 | + $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args); |
|
1302 | + } |
|
1303 | + |
|
1304 | + |
|
1305 | + /** |
|
1306 | + * @param int $TKT_ID |
|
1307 | + * @return bool|int |
|
1308 | + * @throws EE_Error |
|
1309 | + * @throws ReflectionException |
|
1310 | + */ |
|
1311 | + protected function _delete_the_ticket($TKT_ID) |
|
1312 | + { |
|
1313 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
1314 | + $ticket->_remove_relations('Datetime'); |
|
1315 | + // delete all related prices first |
|
1316 | + $ticket->delete_related_permanently('Price'); |
|
1317 | + return $ticket->delete_permanently(); |
|
1318 | + } |
|
1319 | 1319 | } |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | public function __construct($routing = true) |
25 | 25 | { |
26 | 26 | parent::__construct($routing); |
27 | - if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
28 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
29 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
30 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
27 | + if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
28 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/'); |
|
29 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/'); |
|
30 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/'); |
|
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | protected function _extend_page_config() |
41 | 41 | { |
42 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
42 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events'; |
|
43 | 43 | // is there a evt_id in the request? |
44 | 44 | $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
45 | 45 | $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | ], |
167 | 167 | 'require_nonce' => false, |
168 | 168 | ]; |
169 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
169 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
170 | 170 | // add filters and actions |
171 | 171 | // modifying _views |
172 | 172 | add_filter( |
@@ -243,12 +243,12 @@ discard block |
||
243 | 243 | { |
244 | 244 | $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
245 | 245 | // make sure this is only when editing |
246 | - if (! empty($id)) { |
|
247 | - $href = EE_Admin_Page::add_query_args_and_nonce( |
|
246 | + if ( ! empty($id)) { |
|
247 | + $href = EE_Admin_Page::add_query_args_and_nonce( |
|
248 | 248 | ['action' => 'duplicate_event', 'EVT_ID' => $id], |
249 | 249 | $this->_admin_base_url |
250 | 250 | ); |
251 | - $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
251 | + $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
252 | 252 | $return .= '<a href="' |
253 | 253 | . $href |
254 | 254 | . '" title="' |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | { |
296 | 296 | wp_register_script( |
297 | 297 | 'ee-event-editor-heartbeat', |
298 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
298 | + EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js', |
|
299 | 299 | ['ee_admin_js', 'heartbeat'], |
300 | 300 | EVENT_ESPRESSO_VERSION, |
301 | 301 | true |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | public function add_additional_datetime_button($template, $template_args) |
320 | 320 | { |
321 | 321 | return EEH_Template::display_template( |
322 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
322 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php', |
|
323 | 323 | $template_args, |
324 | 324 | true |
325 | 325 | ); |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | public function add_datetime_clone_button($template, $template_args) |
338 | 338 | { |
339 | 339 | return EEH_Template::display_template( |
340 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
340 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php', |
|
341 | 341 | $template_args, |
342 | 342 | true |
343 | 343 | ); |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | public function datetime_timezones_template($template, $template_args) |
356 | 356 | { |
357 | 357 | return EEH_Template::display_template( |
358 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
358 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php', |
|
359 | 359 | $template_args, |
360 | 360 | true |
361 | 361 | ); |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | protected function _set_list_table_views_default() |
371 | 371 | { |
372 | 372 | parent::_set_list_table_views_default(); |
373 | - $new_views = [ |
|
373 | + $new_views = [ |
|
374 | 374 | 'today' => [ |
375 | 375 | 'slug' => 'today', |
376 | 376 | 'label' => esc_html__('Today', 'event_espresso'), |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | // first make sure the ID for the event is in the request. |
482 | 482 | // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
483 | 483 | $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
484 | - if (! $EVT_ID) { |
|
484 | + if ( ! $EVT_ID) { |
|
485 | 485 | EE_Error::add_error( |
486 | 486 | esc_html__( |
487 | 487 | 'In order to duplicate an event an Event ID is required. None was given.', |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | } |
497 | 497 | // k we've got EVT_ID so let's use that to get the event we'll duplicate |
498 | 498 | $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
499 | - if (! $orig_event instanceof EE_Event) { |
|
499 | + if ( ! $orig_event instanceof EE_Event) { |
|
500 | 500 | throw new EE_Error( |
501 | 501 | sprintf( |
502 | 502 | esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | $orig_ven = $orig_event->get_many_related('Venue'); |
513 | 513 | // reset the ID and modify other details to make it clear this is a dupe |
514 | 514 | $new_event->set('EVT_ID', 0); |
515 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
515 | + $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso'); |
|
516 | 516 | $new_event->set('EVT_name', $new_name); |
517 | 517 | $new_event->set( |
518 | 518 | 'EVT_slug', |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | 'Question_Group', |
542 | 542 | [['Event_Question_Group.EQG_primary' => true]] |
543 | 543 | ); |
544 | - if (! empty($orig_primary_qgs)) { |
|
544 | + if ( ! empty($orig_primary_qgs)) { |
|
545 | 545 | foreach ($orig_primary_qgs as $obj) { |
546 | 546 | if ($obj instanceof EE_Question_Group) { |
547 | 547 | $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]); |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | 'Question_Group', |
554 | 554 | [['Event_Question_Group.EQG_additional' => true]] |
555 | 555 | ); |
556 | - if (! empty($orig_additional_qgs)) { |
|
556 | + if ( ! empty($orig_additional_qgs)) { |
|
557 | 557 | foreach ($orig_additional_qgs as $obj) { |
558 | 558 | if ($obj instanceof EE_Question_Group) { |
559 | 559 | $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]); |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | // k now that we have the new event saved we can loop through the datetimes and start adding relations. |
567 | 567 | $cloned_tickets = []; |
568 | 568 | foreach ($orig_datetimes as $orig_dtt) { |
569 | - if (! $orig_dtt instanceof EE_Datetime) { |
|
569 | + if ( ! $orig_dtt instanceof EE_Datetime) { |
|
570 | 570 | continue; |
571 | 571 | } |
572 | 572 | $new_dtt = clone $orig_dtt; |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | // now let's get the ticket relations setup. |
582 | 582 | foreach ((array) $orig_tickets as $orig_ticket) { |
583 | 583 | // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
584 | - if (! $orig_ticket instanceof EE_Ticket) { |
|
584 | + if ( ! $orig_ticket instanceof EE_Ticket) { |
|
585 | 585 | continue; |
586 | 586 | } |
587 | 587 | // is this ticket archived? If it is then let's skip |
@@ -590,8 +590,8 @@ discard block |
||
590 | 590 | } |
591 | 591 | // does this original ticket already exist in the clone_tickets cache? |
592 | 592 | // If so we'll just use the new ticket from it. |
593 | - if (isset($cloned_tickets[ $orig_ticket->ID() ])) { |
|
594 | - $new_ticket = $cloned_tickets[ $orig_ticket->ID() ]; |
|
593 | + if (isset($cloned_tickets[$orig_ticket->ID()])) { |
|
594 | + $new_ticket = $cloned_tickets[$orig_ticket->ID()]; |
|
595 | 595 | } else { |
596 | 596 | $new_ticket = clone $orig_ticket; |
597 | 597 | // get relations on the $orig_ticket that we need to setup. |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | // for use with later datetimes that have the same ticket. |
625 | 625 | $new_dtt->_add_relation_to($new_ticket, 'Ticket'); |
626 | 626 | $new_dtt->save(); |
627 | - $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket; |
|
627 | + $cloned_tickets[$orig_ticket->ID()] = $new_ticket; |
|
628 | 628 | } |
629 | 629 | } |
630 | 630 | // clone taxonomy information |
@@ -705,12 +705,12 @@ discard block |
||
705 | 705 | $type |
706 | 706 | ); |
707 | 707 | |
708 | - $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
708 | + $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
709 | 709 | ['action' => 'sample_export_file'], |
710 | 710 | $this->_admin_base_url |
711 | 711 | ); |
712 | 712 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
713 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
713 | + EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php', |
|
714 | 714 | $this->_template_args, |
715 | 715 | true |
716 | 716 | ); |
@@ -727,7 +727,7 @@ discard block |
||
727 | 727 | */ |
728 | 728 | protected function _import_events() |
729 | 729 | { |
730 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
730 | + require_once(EE_CLASSES.'EE_Import.class.php'); |
|
731 | 731 | $success = EE_Import::instance()->import(); |
732 | 732 | $this->_redirect_after_action( |
733 | 733 | $success, |
@@ -757,8 +757,8 @@ discard block |
||
757 | 757 | 'EVT_ID' => $EVT_ID, |
758 | 758 | ] |
759 | 759 | ); |
760 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
761 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
760 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
761 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
762 | 762 | $EE_Export = EE_Export::instance($this->request->requestParams()); |
763 | 763 | $EE_Export->export(); |
764 | 764 | } |
@@ -780,8 +780,8 @@ discard block |
||
780 | 780 | 'EVT_ID' => $EVT_ID, |
781 | 781 | ] |
782 | 782 | ); |
783 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
784 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
783 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
784 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
785 | 785 | $EE_Export = EE_Export::instance($this->request->requestParams()); |
786 | 786 | $EE_Export->export(); |
787 | 787 | } |
@@ -819,7 +819,7 @@ discard block |
||
819 | 819 | $this->_set_add_edit_form_tags('update_template_settings'); |
820 | 820 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
821 | 821 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
822 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
822 | + EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php', |
|
823 | 823 | $this->_template_args, |
824 | 824 | true |
825 | 825 | ); |
@@ -922,17 +922,17 @@ discard block |
||
922 | 922 | $template_args['_event'] = $this->_cpt_model_obj; |
923 | 923 | $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
924 | 924 | |
925 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
925 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
926 | 926 | 'default_reg_status', |
927 | 927 | $default_reg_status_values, |
928 | 928 | $this->_cpt_model_obj->default_registration_status() |
929 | 929 | ); |
930 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
930 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
931 | 931 | 'display_desc', |
932 | 932 | $yes_no_values, |
933 | 933 | $this->_cpt_model_obj->display_description() |
934 | 934 | ); |
935 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
935 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
936 | 936 | 'display_ticket_selector', |
937 | 937 | $yes_no_values, |
938 | 938 | $this->_cpt_model_obj->display_ticket_selector(), |
@@ -953,7 +953,7 @@ discard block |
||
953 | 953 | $default_reg_status_values |
954 | 954 | ); |
955 | 955 | EEH_Template::display_template( |
956 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
956 | + EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php', |
|
957 | 957 | $template_args |
958 | 958 | ); |
959 | 959 | } |
@@ -1048,7 +1048,7 @@ discard block |
||
1048 | 1048 | $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]); |
1049 | 1049 | |
1050 | 1050 | foreach ($venues as $venue) { |
1051 | - $values[ $venue->ID() ] = $venue->name(); |
|
1051 | + $values[$venue->ID()] = $venue->name(); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide'); |
@@ -1082,13 +1082,13 @@ discard block |
||
1082 | 1082 | { |
1083 | 1083 | $start = EEM_Datetime::instance()->convert_datetime_for_query( |
1084 | 1084 | 'DTT_EVT_start', |
1085 | - date('Y-m-d') . ' 00:00:00', |
|
1085 | + date('Y-m-d').' 00:00:00', |
|
1086 | 1086 | 'Y-m-d H:i:s', |
1087 | 1087 | 'UTC' |
1088 | 1088 | ); |
1089 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1089 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1090 | 1090 | 'DTT_EVT_start', |
1091 | - date('Y-m-d') . ' 23:59:59', |
|
1091 | + date('Y-m-d').' 23:59:59', |
|
1092 | 1092 | 'Y-m-d H:i:s', |
1093 | 1093 | 'UTC' |
1094 | 1094 | ); |
@@ -1114,17 +1114,17 @@ discard block |
||
1114 | 1114 | $days_this_month = date('t'); |
1115 | 1115 | $start = EEM_Datetime::instance()->convert_datetime_for_query( |
1116 | 1116 | 'DTT_EVT_start', |
1117 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
1117 | + $this_year_r.'-'.$this_month_r.'-01 00:00:00', |
|
1118 | 1118 | 'Y-m-d H:i:s', |
1119 | 1119 | 'UTC' |
1120 | 1120 | ); |
1121 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1121 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1122 | 1122 | 'DTT_EVT_start', |
1123 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
1123 | + $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59', |
|
1124 | 1124 | 'Y-m-d H:i:s', |
1125 | 1125 | 'UTC' |
1126 | 1126 | ); |
1127 | - $where = [ |
|
1127 | + $where = [ |
|
1128 | 1128 | 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
1129 | 1129 | ]; |
1130 | 1130 | return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
@@ -1188,7 +1188,7 @@ discard block |
||
1188 | 1188 | |
1189 | 1189 | $search_term = $this->request->getRequestParam('s'); |
1190 | 1190 | if ($search_term) { |
1191 | - $search_term = '%' . $search_term . '%'; |
|
1191 | + $search_term = '%'.$search_term.'%'; |
|
1192 | 1192 | $where['OR'] = [ |
1193 | 1193 | 'TKT_name' => ['LIKE', $search_term], |
1194 | 1194 | 'TKT_description' => ['LIKE', $search_term], |
@@ -1218,17 +1218,17 @@ discard block |
||
1218 | 1218 | $TKT = EEM_Ticket::instance(); |
1219 | 1219 | // checkboxes? |
1220 | 1220 | $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); |
1221 | - if (! empty($checkboxes)) { |
|
1221 | + if ( ! empty($checkboxes)) { |
|
1222 | 1222 | // if array has more than one element then success message should be plural |
1223 | 1223 | $success = count($checkboxes) > 1 ? 2 : 1; |
1224 | 1224 | // cycle thru the boxes |
1225 | 1225 | while (list($TKT_ID, $value) = each($checkboxes)) { |
1226 | 1226 | if ($trash) { |
1227 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1227 | + if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
1228 | 1228 | $success = 0; |
1229 | 1229 | } |
1230 | 1230 | } else { |
1231 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1231 | + if ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
1232 | 1232 | $success = 0; |
1233 | 1233 | } |
1234 | 1234 | } |
@@ -1237,11 +1237,11 @@ discard block |
||
1237 | 1237 | // grab single id and trash |
1238 | 1238 | $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
1239 | 1239 | if ($trash) { |
1240 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1240 | + if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
1241 | 1241 | $success = 0; |
1242 | 1242 | } |
1243 | 1243 | } else { |
1244 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1244 | + if ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
1245 | 1245 | $success = 0; |
1246 | 1246 | } |
1247 | 1247 | } |
@@ -1266,20 +1266,20 @@ discard block |
||
1266 | 1266 | $success = 1; |
1267 | 1267 | // checkboxes? |
1268 | 1268 | $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); |
1269 | - if (! empty($checkboxes)) { |
|
1269 | + if ( ! empty($checkboxes)) { |
|
1270 | 1270 | // if array has more than one element then success message should be plural |
1271 | 1271 | $success = count($checkboxes) > 1 ? 2 : 1; |
1272 | 1272 | // cycle thru the boxes |
1273 | 1273 | while (list($TKT_ID, $value) = each($checkboxes)) { |
1274 | 1274 | // delete |
1275 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1275 | + if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
1276 | 1276 | $success = 0; |
1277 | 1277 | } |
1278 | 1278 | } |
1279 | 1279 | } else { |
1280 | 1280 | // grab single id and trash |
1281 | 1281 | $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
1282 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1282 | + if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
1283 | 1283 | $success = 0; |
1284 | 1284 | } |
1285 | 1285 | } |
@@ -16,1274 +16,1274 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * This is used to hold the reports template data which is setup early in the request. |
|
21 | - * |
|
22 | - * @type array |
|
23 | - */ |
|
24 | - protected $_reports_template_data = array(); |
|
19 | + /** |
|
20 | + * This is used to hold the reports template data which is setup early in the request. |
|
21 | + * |
|
22 | + * @type array |
|
23 | + */ |
|
24 | + protected $_reports_template_data = array(); |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * Extend_Registrations_Admin_Page constructor. |
|
29 | - * |
|
30 | - * @param bool $routing |
|
31 | - */ |
|
32 | - public function __construct($routing = true) |
|
33 | - { |
|
34 | - parent::__construct($routing); |
|
35 | - if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
36 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
37 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
38 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
39 | - } |
|
40 | - } |
|
27 | + /** |
|
28 | + * Extend_Registrations_Admin_Page constructor. |
|
29 | + * |
|
30 | + * @param bool $routing |
|
31 | + */ |
|
32 | + public function __construct($routing = true) |
|
33 | + { |
|
34 | + parent::__construct($routing); |
|
35 | + if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
36 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
37 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
38 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * Extending page configuration. |
|
45 | - */ |
|
46 | - protected function _extend_page_config() |
|
47 | - { |
|
48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
49 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
50 | - ? $this->_req_data['_REG_ID'] |
|
51 | - : 0; |
|
52 | - $new_page_routes = array( |
|
53 | - 'reports' => array( |
|
54 | - 'func' => '_registration_reports', |
|
55 | - 'capability' => 'ee_read_registrations', |
|
56 | - ), |
|
57 | - 'registration_checkins' => array( |
|
58 | - 'func' => '_registration_checkin_list_table', |
|
59 | - 'capability' => 'ee_read_checkins', |
|
60 | - ), |
|
61 | - 'newsletter_selected_send' => array( |
|
62 | - 'func' => '_newsletter_selected_send', |
|
63 | - 'noheader' => true, |
|
64 | - 'capability' => 'ee_send_message', |
|
65 | - ), |
|
66 | - 'delete_checkin_rows' => array( |
|
67 | - 'func' => '_delete_checkin_rows', |
|
68 | - 'noheader' => true, |
|
69 | - 'capability' => 'ee_delete_checkins', |
|
70 | - ), |
|
71 | - 'delete_checkin_row' => array( |
|
72 | - 'func' => '_delete_checkin_row', |
|
73 | - 'noheader' => true, |
|
74 | - 'capability' => 'ee_delete_checkin', |
|
75 | - 'obj_id' => $reg_id, |
|
76 | - ), |
|
77 | - 'toggle_checkin_status' => array( |
|
78 | - 'func' => '_toggle_checkin_status', |
|
79 | - 'noheader' => true, |
|
80 | - 'capability' => 'ee_edit_checkin', |
|
81 | - 'obj_id' => $reg_id, |
|
82 | - ), |
|
83 | - 'toggle_checkin_status_bulk' => array( |
|
84 | - 'func' => '_toggle_checkin_status', |
|
85 | - 'noheader' => true, |
|
86 | - 'capability' => 'ee_edit_checkins', |
|
87 | - ), |
|
88 | - 'event_registrations' => array( |
|
89 | - 'func' => '_event_registrations_list_table', |
|
90 | - 'capability' => 'ee_read_checkins', |
|
91 | - ), |
|
92 | - 'registrations_checkin_report' => array( |
|
93 | - 'func' => '_registrations_checkin_report', |
|
94 | - 'noheader' => true, |
|
95 | - 'capability' => 'ee_read_registrations', |
|
96 | - ), |
|
97 | - ); |
|
98 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
99 | - $new_page_config = array( |
|
100 | - 'reports' => array( |
|
101 | - 'nav' => array( |
|
102 | - 'label' => esc_html__('Reports', 'event_espresso'), |
|
103 | - 'order' => 30, |
|
104 | - ), |
|
105 | - 'help_tabs' => array( |
|
106 | - 'registrations_reports_help_tab' => array( |
|
107 | - 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
108 | - 'filename' => 'registrations_reports', |
|
109 | - ), |
|
110 | - ), |
|
111 | - 'require_nonce' => false, |
|
112 | - ), |
|
113 | - 'event_registrations' => array( |
|
114 | - 'nav' => array( |
|
115 | - 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
116 | - 'order' => 10, |
|
117 | - 'persistent' => true, |
|
118 | - ), |
|
119 | - 'help_tabs' => array( |
|
120 | - 'registrations_event_checkin_help_tab' => array( |
|
121 | - 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
122 | - 'filename' => 'registrations_event_checkin', |
|
123 | - ), |
|
124 | - 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
125 | - 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
126 | - 'filename' => 'registrations_event_checkin_table_column_headings', |
|
127 | - ), |
|
128 | - 'registrations_event_checkin_filters_help_tab' => array( |
|
129 | - 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
130 | - 'filename' => 'registrations_event_checkin_filters', |
|
131 | - ), |
|
132 | - 'registrations_event_checkin_views_help_tab' => array( |
|
133 | - 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
134 | - 'filename' => 'registrations_event_checkin_views', |
|
135 | - ), |
|
136 | - 'registrations_event_checkin_other_help_tab' => array( |
|
137 | - 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
138 | - 'filename' => 'registrations_event_checkin_other', |
|
139 | - ), |
|
140 | - ), |
|
141 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
142 | - 'list_table' => 'EE_Event_Registrations_List_Table', |
|
143 | - 'metaboxes' => array(), |
|
144 | - 'require_nonce' => false, |
|
145 | - ), |
|
146 | - 'registration_checkins' => array( |
|
147 | - 'nav' => array( |
|
148 | - 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
149 | - 'order' => 15, |
|
150 | - 'persistent' => false, |
|
151 | - 'url' => '', |
|
152 | - ), |
|
153 | - 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
154 | - 'metaboxes' => array(), |
|
155 | - 'require_nonce' => false, |
|
156 | - ), |
|
157 | - ); |
|
158 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
159 | - $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
160 | - $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
161 | - } |
|
43 | + /** |
|
44 | + * Extending page configuration. |
|
45 | + */ |
|
46 | + protected function _extend_page_config() |
|
47 | + { |
|
48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
49 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
50 | + ? $this->_req_data['_REG_ID'] |
|
51 | + : 0; |
|
52 | + $new_page_routes = array( |
|
53 | + 'reports' => array( |
|
54 | + 'func' => '_registration_reports', |
|
55 | + 'capability' => 'ee_read_registrations', |
|
56 | + ), |
|
57 | + 'registration_checkins' => array( |
|
58 | + 'func' => '_registration_checkin_list_table', |
|
59 | + 'capability' => 'ee_read_checkins', |
|
60 | + ), |
|
61 | + 'newsletter_selected_send' => array( |
|
62 | + 'func' => '_newsletter_selected_send', |
|
63 | + 'noheader' => true, |
|
64 | + 'capability' => 'ee_send_message', |
|
65 | + ), |
|
66 | + 'delete_checkin_rows' => array( |
|
67 | + 'func' => '_delete_checkin_rows', |
|
68 | + 'noheader' => true, |
|
69 | + 'capability' => 'ee_delete_checkins', |
|
70 | + ), |
|
71 | + 'delete_checkin_row' => array( |
|
72 | + 'func' => '_delete_checkin_row', |
|
73 | + 'noheader' => true, |
|
74 | + 'capability' => 'ee_delete_checkin', |
|
75 | + 'obj_id' => $reg_id, |
|
76 | + ), |
|
77 | + 'toggle_checkin_status' => array( |
|
78 | + 'func' => '_toggle_checkin_status', |
|
79 | + 'noheader' => true, |
|
80 | + 'capability' => 'ee_edit_checkin', |
|
81 | + 'obj_id' => $reg_id, |
|
82 | + ), |
|
83 | + 'toggle_checkin_status_bulk' => array( |
|
84 | + 'func' => '_toggle_checkin_status', |
|
85 | + 'noheader' => true, |
|
86 | + 'capability' => 'ee_edit_checkins', |
|
87 | + ), |
|
88 | + 'event_registrations' => array( |
|
89 | + 'func' => '_event_registrations_list_table', |
|
90 | + 'capability' => 'ee_read_checkins', |
|
91 | + ), |
|
92 | + 'registrations_checkin_report' => array( |
|
93 | + 'func' => '_registrations_checkin_report', |
|
94 | + 'noheader' => true, |
|
95 | + 'capability' => 'ee_read_registrations', |
|
96 | + ), |
|
97 | + ); |
|
98 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
99 | + $new_page_config = array( |
|
100 | + 'reports' => array( |
|
101 | + 'nav' => array( |
|
102 | + 'label' => esc_html__('Reports', 'event_espresso'), |
|
103 | + 'order' => 30, |
|
104 | + ), |
|
105 | + 'help_tabs' => array( |
|
106 | + 'registrations_reports_help_tab' => array( |
|
107 | + 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
108 | + 'filename' => 'registrations_reports', |
|
109 | + ), |
|
110 | + ), |
|
111 | + 'require_nonce' => false, |
|
112 | + ), |
|
113 | + 'event_registrations' => array( |
|
114 | + 'nav' => array( |
|
115 | + 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
116 | + 'order' => 10, |
|
117 | + 'persistent' => true, |
|
118 | + ), |
|
119 | + 'help_tabs' => array( |
|
120 | + 'registrations_event_checkin_help_tab' => array( |
|
121 | + 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
122 | + 'filename' => 'registrations_event_checkin', |
|
123 | + ), |
|
124 | + 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
125 | + 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
126 | + 'filename' => 'registrations_event_checkin_table_column_headings', |
|
127 | + ), |
|
128 | + 'registrations_event_checkin_filters_help_tab' => array( |
|
129 | + 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
130 | + 'filename' => 'registrations_event_checkin_filters', |
|
131 | + ), |
|
132 | + 'registrations_event_checkin_views_help_tab' => array( |
|
133 | + 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
134 | + 'filename' => 'registrations_event_checkin_views', |
|
135 | + ), |
|
136 | + 'registrations_event_checkin_other_help_tab' => array( |
|
137 | + 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
138 | + 'filename' => 'registrations_event_checkin_other', |
|
139 | + ), |
|
140 | + ), |
|
141 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
142 | + 'list_table' => 'EE_Event_Registrations_List_Table', |
|
143 | + 'metaboxes' => array(), |
|
144 | + 'require_nonce' => false, |
|
145 | + ), |
|
146 | + 'registration_checkins' => array( |
|
147 | + 'nav' => array( |
|
148 | + 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
149 | + 'order' => 15, |
|
150 | + 'persistent' => false, |
|
151 | + 'url' => '', |
|
152 | + ), |
|
153 | + 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
154 | + 'metaboxes' => array(), |
|
155 | + 'require_nonce' => false, |
|
156 | + ), |
|
157 | + ); |
|
158 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
159 | + $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
160 | + $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
161 | + } |
|
162 | 162 | |
163 | 163 | |
164 | - /** |
|
165 | - * Ajax hooks for all routes in this page. |
|
166 | - */ |
|
167 | - protected function _ajax_hooks() |
|
168 | - { |
|
169 | - parent::_ajax_hooks(); |
|
170 | - add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
171 | - } |
|
164 | + /** |
|
165 | + * Ajax hooks for all routes in this page. |
|
166 | + */ |
|
167 | + protected function _ajax_hooks() |
|
168 | + { |
|
169 | + parent::_ajax_hooks(); |
|
170 | + add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
171 | + } |
|
172 | 172 | |
173 | 173 | |
174 | - /** |
|
175 | - * Global scripts for all routes in this page. |
|
176 | - */ |
|
177 | - public function load_scripts_styles() |
|
178 | - { |
|
179 | - parent::load_scripts_styles(); |
|
180 | - // if newsletter message type is active then let's add filter and load js for it. |
|
181 | - if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
182 | - // enqueue newsletter js |
|
183 | - wp_enqueue_script( |
|
184 | - 'ee-newsletter-trigger', |
|
185 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
186 | - array('ee-dialog'), |
|
187 | - EVENT_ESPRESSO_VERSION, |
|
188 | - true |
|
189 | - ); |
|
190 | - wp_enqueue_style( |
|
191 | - 'ee-newsletter-trigger-css', |
|
192 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
193 | - array(), |
|
194 | - EVENT_ESPRESSO_VERSION |
|
195 | - ); |
|
196 | - // hook in buttons for newsletter message type trigger. |
|
197 | - add_action( |
|
198 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
199 | - array($this, 'add_newsletter_action_buttons'), |
|
200 | - 10 |
|
201 | - ); |
|
202 | - } |
|
203 | - } |
|
174 | + /** |
|
175 | + * Global scripts for all routes in this page. |
|
176 | + */ |
|
177 | + public function load_scripts_styles() |
|
178 | + { |
|
179 | + parent::load_scripts_styles(); |
|
180 | + // if newsletter message type is active then let's add filter and load js for it. |
|
181 | + if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
182 | + // enqueue newsletter js |
|
183 | + wp_enqueue_script( |
|
184 | + 'ee-newsletter-trigger', |
|
185 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
186 | + array('ee-dialog'), |
|
187 | + EVENT_ESPRESSO_VERSION, |
|
188 | + true |
|
189 | + ); |
|
190 | + wp_enqueue_style( |
|
191 | + 'ee-newsletter-trigger-css', |
|
192 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
193 | + array(), |
|
194 | + EVENT_ESPRESSO_VERSION |
|
195 | + ); |
|
196 | + // hook in buttons for newsletter message type trigger. |
|
197 | + add_action( |
|
198 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
199 | + array($this, 'add_newsletter_action_buttons'), |
|
200 | + 10 |
|
201 | + ); |
|
202 | + } |
|
203 | + } |
|
204 | 204 | |
205 | 205 | |
206 | - /** |
|
207 | - * Scripts and styles for just the reports route. |
|
208 | - */ |
|
209 | - public function load_scripts_styles_reports() |
|
210 | - { |
|
211 | - wp_register_script( |
|
212 | - 'ee-reg-reports-js', |
|
213 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
214 | - array('google-charts'), |
|
215 | - EVENT_ESPRESSO_VERSION, |
|
216 | - true |
|
217 | - ); |
|
218 | - wp_enqueue_script('ee-reg-reports-js'); |
|
219 | - $this->_registration_reports_js_setup(); |
|
220 | - } |
|
206 | + /** |
|
207 | + * Scripts and styles for just the reports route. |
|
208 | + */ |
|
209 | + public function load_scripts_styles_reports() |
|
210 | + { |
|
211 | + wp_register_script( |
|
212 | + 'ee-reg-reports-js', |
|
213 | + REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
214 | + array('google-charts'), |
|
215 | + EVENT_ESPRESSO_VERSION, |
|
216 | + true |
|
217 | + ); |
|
218 | + wp_enqueue_script('ee-reg-reports-js'); |
|
219 | + $this->_registration_reports_js_setup(); |
|
220 | + } |
|
221 | 221 | |
222 | 222 | |
223 | - /** |
|
224 | - * Register screen options for event_registrations route. |
|
225 | - */ |
|
226 | - protected function _add_screen_options_event_registrations() |
|
227 | - { |
|
228 | - $this->_per_page_screen_option(); |
|
229 | - } |
|
223 | + /** |
|
224 | + * Register screen options for event_registrations route. |
|
225 | + */ |
|
226 | + protected function _add_screen_options_event_registrations() |
|
227 | + { |
|
228 | + $this->_per_page_screen_option(); |
|
229 | + } |
|
230 | 230 | |
231 | 231 | |
232 | - /** |
|
233 | - * Register screen options for registration_checkins route |
|
234 | - */ |
|
235 | - protected function _add_screen_options_registration_checkins() |
|
236 | - { |
|
237 | - $page_title = $this->_admin_page_title; |
|
238 | - $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
239 | - $this->_per_page_screen_option(); |
|
240 | - $this->_admin_page_title = $page_title; |
|
241 | - } |
|
232 | + /** |
|
233 | + * Register screen options for registration_checkins route |
|
234 | + */ |
|
235 | + protected function _add_screen_options_registration_checkins() |
|
236 | + { |
|
237 | + $page_title = $this->_admin_page_title; |
|
238 | + $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
239 | + $this->_per_page_screen_option(); |
|
240 | + $this->_admin_page_title = $page_title; |
|
241 | + } |
|
242 | 242 | |
243 | 243 | |
244 | - /** |
|
245 | - * Set views property for event_registrations route. |
|
246 | - */ |
|
247 | - protected function _set_list_table_views_event_registrations() |
|
248 | - { |
|
249 | - $this->_views = array( |
|
250 | - 'all' => array( |
|
251 | - 'slug' => 'all', |
|
252 | - 'label' => esc_html__('All', 'event_espresso'), |
|
253 | - 'count' => 0, |
|
254 | - 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
255 | - ? array() |
|
256 | - : array( |
|
257 | - 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
258 | - ), |
|
259 | - ), |
|
260 | - ); |
|
261 | - } |
|
244 | + /** |
|
245 | + * Set views property for event_registrations route. |
|
246 | + */ |
|
247 | + protected function _set_list_table_views_event_registrations() |
|
248 | + { |
|
249 | + $this->_views = array( |
|
250 | + 'all' => array( |
|
251 | + 'slug' => 'all', |
|
252 | + 'label' => esc_html__('All', 'event_espresso'), |
|
253 | + 'count' => 0, |
|
254 | + 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
255 | + ? array() |
|
256 | + : array( |
|
257 | + 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
258 | + ), |
|
259 | + ), |
|
260 | + ); |
|
261 | + } |
|
262 | 262 | |
263 | 263 | |
264 | - /** |
|
265 | - * Set views property for registration_checkins route. |
|
266 | - */ |
|
267 | - protected function _set_list_table_views_registration_checkins() |
|
268 | - { |
|
269 | - $this->_views = array( |
|
270 | - 'all' => array( |
|
271 | - 'slug' => 'all', |
|
272 | - 'label' => esc_html__('All', 'event_espresso'), |
|
273 | - 'count' => 0, |
|
274 | - 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
275 | - ), |
|
276 | - ); |
|
277 | - } |
|
264 | + /** |
|
265 | + * Set views property for registration_checkins route. |
|
266 | + */ |
|
267 | + protected function _set_list_table_views_registration_checkins() |
|
268 | + { |
|
269 | + $this->_views = array( |
|
270 | + 'all' => array( |
|
271 | + 'slug' => 'all', |
|
272 | + 'label' => esc_html__('All', 'event_espresso'), |
|
273 | + 'count' => 0, |
|
274 | + 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
275 | + ), |
|
276 | + ); |
|
277 | + } |
|
278 | 278 | |
279 | 279 | |
280 | - /** |
|
281 | - * callback for ajax action. |
|
282 | - * |
|
283 | - * @since 4.3.0 |
|
284 | - * @return void (JSON) |
|
285 | - * @throws EE_Error |
|
286 | - * @throws InvalidArgumentException |
|
287 | - * @throws InvalidDataTypeException |
|
288 | - * @throws InvalidInterfaceException |
|
289 | - */ |
|
290 | - public function get_newsletter_form_content() |
|
291 | - { |
|
292 | - // do a nonce check cause we're not coming in from an normal route here. |
|
293 | - $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
294 | - $this->_req_data['get_newsletter_form_content_nonce'] |
|
295 | - ) : ''; |
|
296 | - $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
297 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
298 | - // let's get the mtp for the incoming MTP_ ID |
|
299 | - if (! isset($this->_req_data['GRP_ID'])) { |
|
300 | - EE_Error::add_error( |
|
301 | - esc_html__( |
|
302 | - 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
303 | - 'event_espresso' |
|
304 | - ), |
|
305 | - __FILE__, |
|
306 | - __FUNCTION__, |
|
307 | - __LINE__ |
|
308 | - ); |
|
309 | - $this->_template_args['success'] = false; |
|
310 | - $this->_template_args['error'] = true; |
|
311 | - $this->_return_json(); |
|
312 | - } |
|
313 | - $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
314 | - if (! $MTPG instanceof EE_Message_Template_Group) { |
|
315 | - EE_Error::add_error( |
|
316 | - sprintf( |
|
317 | - esc_html__( |
|
318 | - 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
319 | - 'event_espresso' |
|
320 | - ), |
|
321 | - $this->_req_data['GRP_ID'] |
|
322 | - ), |
|
323 | - __FILE__, |
|
324 | - __FUNCTION__, |
|
325 | - __LINE__ |
|
326 | - ); |
|
327 | - $this->_template_args['success'] = false; |
|
328 | - $this->_template_args['error'] = true; |
|
329 | - $this->_return_json(); |
|
330 | - } |
|
331 | - $MTPs = $MTPG->context_templates(); |
|
332 | - $MTPs = $MTPs['attendee']; |
|
333 | - $template_fields = array(); |
|
334 | - /** @var EE_Message_Template $MTP */ |
|
335 | - foreach ($MTPs as $MTP) { |
|
336 | - $field = $MTP->get('MTP_template_field'); |
|
337 | - if ($field === 'content') { |
|
338 | - $content = $MTP->get('MTP_content'); |
|
339 | - if (! empty($content['newsletter_content'])) { |
|
340 | - $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
341 | - } |
|
342 | - continue; |
|
343 | - } |
|
344 | - $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
345 | - } |
|
346 | - $this->_template_args['success'] = true; |
|
347 | - $this->_template_args['error'] = false; |
|
348 | - $this->_template_args['data'] = array( |
|
349 | - 'batch_message_from' => isset($template_fields['from']) |
|
350 | - ? $template_fields['from'] |
|
351 | - : '', |
|
352 | - 'batch_message_subject' => isset($template_fields['subject']) |
|
353 | - ? $template_fields['subject'] |
|
354 | - : '', |
|
355 | - 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
356 | - ? $template_fields['newsletter_content'] |
|
357 | - : '', |
|
358 | - ); |
|
359 | - $this->_return_json(); |
|
360 | - } |
|
280 | + /** |
|
281 | + * callback for ajax action. |
|
282 | + * |
|
283 | + * @since 4.3.0 |
|
284 | + * @return void (JSON) |
|
285 | + * @throws EE_Error |
|
286 | + * @throws InvalidArgumentException |
|
287 | + * @throws InvalidDataTypeException |
|
288 | + * @throws InvalidInterfaceException |
|
289 | + */ |
|
290 | + public function get_newsletter_form_content() |
|
291 | + { |
|
292 | + // do a nonce check cause we're not coming in from an normal route here. |
|
293 | + $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
294 | + $this->_req_data['get_newsletter_form_content_nonce'] |
|
295 | + ) : ''; |
|
296 | + $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
297 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
298 | + // let's get the mtp for the incoming MTP_ ID |
|
299 | + if (! isset($this->_req_data['GRP_ID'])) { |
|
300 | + EE_Error::add_error( |
|
301 | + esc_html__( |
|
302 | + 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
303 | + 'event_espresso' |
|
304 | + ), |
|
305 | + __FILE__, |
|
306 | + __FUNCTION__, |
|
307 | + __LINE__ |
|
308 | + ); |
|
309 | + $this->_template_args['success'] = false; |
|
310 | + $this->_template_args['error'] = true; |
|
311 | + $this->_return_json(); |
|
312 | + } |
|
313 | + $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
314 | + if (! $MTPG instanceof EE_Message_Template_Group) { |
|
315 | + EE_Error::add_error( |
|
316 | + sprintf( |
|
317 | + esc_html__( |
|
318 | + 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
319 | + 'event_espresso' |
|
320 | + ), |
|
321 | + $this->_req_data['GRP_ID'] |
|
322 | + ), |
|
323 | + __FILE__, |
|
324 | + __FUNCTION__, |
|
325 | + __LINE__ |
|
326 | + ); |
|
327 | + $this->_template_args['success'] = false; |
|
328 | + $this->_template_args['error'] = true; |
|
329 | + $this->_return_json(); |
|
330 | + } |
|
331 | + $MTPs = $MTPG->context_templates(); |
|
332 | + $MTPs = $MTPs['attendee']; |
|
333 | + $template_fields = array(); |
|
334 | + /** @var EE_Message_Template $MTP */ |
|
335 | + foreach ($MTPs as $MTP) { |
|
336 | + $field = $MTP->get('MTP_template_field'); |
|
337 | + if ($field === 'content') { |
|
338 | + $content = $MTP->get('MTP_content'); |
|
339 | + if (! empty($content['newsletter_content'])) { |
|
340 | + $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
341 | + } |
|
342 | + continue; |
|
343 | + } |
|
344 | + $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
345 | + } |
|
346 | + $this->_template_args['success'] = true; |
|
347 | + $this->_template_args['error'] = false; |
|
348 | + $this->_template_args['data'] = array( |
|
349 | + 'batch_message_from' => isset($template_fields['from']) |
|
350 | + ? $template_fields['from'] |
|
351 | + : '', |
|
352 | + 'batch_message_subject' => isset($template_fields['subject']) |
|
353 | + ? $template_fields['subject'] |
|
354 | + : '', |
|
355 | + 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
356 | + ? $template_fields['newsletter_content'] |
|
357 | + : '', |
|
358 | + ); |
|
359 | + $this->_return_json(); |
|
360 | + } |
|
361 | 361 | |
362 | 362 | |
363 | - /** |
|
364 | - * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
365 | - * |
|
366 | - * @since 4.3.0 |
|
367 | - * @param EE_Admin_List_Table $list_table |
|
368 | - * @return void |
|
369 | - * @throws InvalidArgumentException |
|
370 | - * @throws InvalidDataTypeException |
|
371 | - * @throws InvalidInterfaceException |
|
372 | - */ |
|
373 | - public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
374 | - { |
|
375 | - if ( |
|
376 | - ! EE_Registry::instance()->CAP->current_user_can( |
|
377 | - 'ee_send_message', |
|
378 | - 'espresso_registrations_newsletter_selected_send' |
|
379 | - ) |
|
380 | - ) { |
|
381 | - return; |
|
382 | - } |
|
383 | - $routes_to_add_to = array( |
|
384 | - 'contact_list', |
|
385 | - 'event_registrations', |
|
386 | - 'default', |
|
387 | - ); |
|
388 | - if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
389 | - if ( |
|
390 | - ($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
391 | - || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
392 | - ) { |
|
393 | - echo ''; |
|
394 | - } else { |
|
395 | - $button_text = sprintf( |
|
396 | - esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
397 | - '<span class="send-selected-newsletter-count">0</span>' |
|
398 | - ); |
|
399 | - echo '<button id="selected-batch-send-trigger" class="button secondary-button">' |
|
400 | - . '<span class="dashicons dashicons-email "></span>' |
|
401 | - . $button_text |
|
402 | - . '</button>'; |
|
403 | - add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
404 | - } |
|
405 | - } |
|
406 | - } |
|
363 | + /** |
|
364 | + * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
365 | + * |
|
366 | + * @since 4.3.0 |
|
367 | + * @param EE_Admin_List_Table $list_table |
|
368 | + * @return void |
|
369 | + * @throws InvalidArgumentException |
|
370 | + * @throws InvalidDataTypeException |
|
371 | + * @throws InvalidInterfaceException |
|
372 | + */ |
|
373 | + public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
374 | + { |
|
375 | + if ( |
|
376 | + ! EE_Registry::instance()->CAP->current_user_can( |
|
377 | + 'ee_send_message', |
|
378 | + 'espresso_registrations_newsletter_selected_send' |
|
379 | + ) |
|
380 | + ) { |
|
381 | + return; |
|
382 | + } |
|
383 | + $routes_to_add_to = array( |
|
384 | + 'contact_list', |
|
385 | + 'event_registrations', |
|
386 | + 'default', |
|
387 | + ); |
|
388 | + if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
389 | + if ( |
|
390 | + ($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
391 | + || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
392 | + ) { |
|
393 | + echo ''; |
|
394 | + } else { |
|
395 | + $button_text = sprintf( |
|
396 | + esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
397 | + '<span class="send-selected-newsletter-count">0</span>' |
|
398 | + ); |
|
399 | + echo '<button id="selected-batch-send-trigger" class="button secondary-button">' |
|
400 | + . '<span class="dashicons dashicons-email "></span>' |
|
401 | + . $button_text |
|
402 | + . '</button>'; |
|
403 | + add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
404 | + } |
|
405 | + } |
|
406 | + } |
|
407 | 407 | |
408 | 408 | |
409 | - /** |
|
410 | - * @throws DomainException |
|
411 | - * @throws EE_Error |
|
412 | - * @throws InvalidArgumentException |
|
413 | - * @throws InvalidDataTypeException |
|
414 | - * @throws InvalidInterfaceException |
|
415 | - */ |
|
416 | - public function newsletter_send_form_skeleton() |
|
417 | - { |
|
418 | - $list_table = $this->_list_table_object; |
|
419 | - $codes = array(); |
|
420 | - // need to templates for the newsletter message type for the template selector. |
|
421 | - $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
422 | - $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
423 | - array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
424 | - ); |
|
425 | - foreach ($mtps as $mtp) { |
|
426 | - $name = $mtp->name(); |
|
427 | - $values[] = array( |
|
428 | - 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
429 | - 'id' => $mtp->ID(), |
|
430 | - ); |
|
431 | - } |
|
432 | - // need to get a list of shortcodes that are available for the newsletter message type. |
|
433 | - $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
434 | - 'newsletter', |
|
435 | - 'email', |
|
436 | - array(), |
|
437 | - 'attendee', |
|
438 | - false |
|
439 | - ); |
|
440 | - foreach ($shortcodes as $field => $shortcode_array) { |
|
441 | - $available_shortcodes = array(); |
|
442 | - foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
443 | - $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
444 | - ? 'content' |
|
445 | - : $field; |
|
446 | - $field_id = 'batch-message-' . strtolower($field_id); |
|
447 | - $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
448 | - . $shortcode |
|
449 | - . '" data-linked-input-id="' . $field_id . '">' |
|
450 | - . $shortcode |
|
451 | - . '</span>'; |
|
452 | - } |
|
453 | - $codes[ $field ] = implode(', ', $available_shortcodes); |
|
454 | - } |
|
455 | - $shortcodes = $codes; |
|
456 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
457 | - $form_template_args = array( |
|
458 | - 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
459 | - 'form_route' => 'newsletter_selected_send', |
|
460 | - 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
461 | - 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
462 | - 'redirect_back_to' => $this->_req_action, |
|
463 | - 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
464 | - 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
465 | - 'shortcodes' => $shortcodes, |
|
466 | - 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
467 | - ); |
|
468 | - EEH_Template::display_template($form_template, $form_template_args); |
|
469 | - } |
|
409 | + /** |
|
410 | + * @throws DomainException |
|
411 | + * @throws EE_Error |
|
412 | + * @throws InvalidArgumentException |
|
413 | + * @throws InvalidDataTypeException |
|
414 | + * @throws InvalidInterfaceException |
|
415 | + */ |
|
416 | + public function newsletter_send_form_skeleton() |
|
417 | + { |
|
418 | + $list_table = $this->_list_table_object; |
|
419 | + $codes = array(); |
|
420 | + // need to templates for the newsletter message type for the template selector. |
|
421 | + $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
422 | + $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
423 | + array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
424 | + ); |
|
425 | + foreach ($mtps as $mtp) { |
|
426 | + $name = $mtp->name(); |
|
427 | + $values[] = array( |
|
428 | + 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
429 | + 'id' => $mtp->ID(), |
|
430 | + ); |
|
431 | + } |
|
432 | + // need to get a list of shortcodes that are available for the newsletter message type. |
|
433 | + $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
434 | + 'newsletter', |
|
435 | + 'email', |
|
436 | + array(), |
|
437 | + 'attendee', |
|
438 | + false |
|
439 | + ); |
|
440 | + foreach ($shortcodes as $field => $shortcode_array) { |
|
441 | + $available_shortcodes = array(); |
|
442 | + foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
443 | + $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
444 | + ? 'content' |
|
445 | + : $field; |
|
446 | + $field_id = 'batch-message-' . strtolower($field_id); |
|
447 | + $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
448 | + . $shortcode |
|
449 | + . '" data-linked-input-id="' . $field_id . '">' |
|
450 | + . $shortcode |
|
451 | + . '</span>'; |
|
452 | + } |
|
453 | + $codes[ $field ] = implode(', ', $available_shortcodes); |
|
454 | + } |
|
455 | + $shortcodes = $codes; |
|
456 | + $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
457 | + $form_template_args = array( |
|
458 | + 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
459 | + 'form_route' => 'newsletter_selected_send', |
|
460 | + 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
461 | + 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
462 | + 'redirect_back_to' => $this->_req_action, |
|
463 | + 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
464 | + 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
465 | + 'shortcodes' => $shortcodes, |
|
466 | + 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
467 | + ); |
|
468 | + EEH_Template::display_template($form_template, $form_template_args); |
|
469 | + } |
|
470 | 470 | |
471 | 471 | |
472 | - /** |
|
473 | - * Handles sending selected registrations/contacts a newsletter. |
|
474 | - * |
|
475 | - * @since 4.3.0 |
|
476 | - * @return void |
|
477 | - * @throws EE_Error |
|
478 | - * @throws InvalidArgumentException |
|
479 | - * @throws InvalidDataTypeException |
|
480 | - * @throws InvalidInterfaceException |
|
481 | - */ |
|
482 | - protected function _newsletter_selected_send() |
|
483 | - { |
|
484 | - $success = true; |
|
485 | - // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
486 | - if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
487 | - EE_Error::add_error( |
|
488 | - esc_html__( |
|
489 | - 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
490 | - 'event_espresso' |
|
491 | - ), |
|
492 | - __FILE__, |
|
493 | - __FUNCTION__, |
|
494 | - __LINE__ |
|
495 | - ); |
|
496 | - $success = false; |
|
497 | - } |
|
498 | - if ($success) { |
|
499 | - // update Message template in case there are any changes |
|
500 | - $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
501 | - $this->_req_data['newsletter_mtp_selected'] |
|
502 | - ); |
|
503 | - $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
504 | - ? $Message_Template_Group->context_templates() |
|
505 | - : array(); |
|
506 | - if (empty($Message_Templates)) { |
|
507 | - EE_Error::add_error( |
|
508 | - esc_html__( |
|
509 | - 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
510 | - 'event_espresso' |
|
511 | - ), |
|
512 | - __FILE__, |
|
513 | - __FUNCTION__, |
|
514 | - __LINE__ |
|
515 | - ); |
|
516 | - } |
|
517 | - // let's just update the specific fields |
|
518 | - foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
519 | - if ($Message_Template instanceof EE_Message_Template) { |
|
520 | - $field = $Message_Template->get('MTP_template_field'); |
|
521 | - $content = $Message_Template->get('MTP_content'); |
|
522 | - $new_content = $content; |
|
523 | - switch ($field) { |
|
524 | - case 'from': |
|
525 | - $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
526 | - ? $this->_req_data['batch_message']['from'] |
|
527 | - : $content; |
|
528 | - break; |
|
529 | - case 'subject': |
|
530 | - $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
531 | - ? $this->_req_data['batch_message']['subject'] |
|
532 | - : $content; |
|
533 | - break; |
|
534 | - case 'content': |
|
535 | - $new_content = $content; |
|
536 | - $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
537 | - ? $this->_req_data['batch_message']['content'] |
|
538 | - : $content['newsletter_content']; |
|
539 | - break; |
|
540 | - default: |
|
541 | - // continue the foreach loop, we don't want to set $new_content nor save. |
|
542 | - continue 2; |
|
543 | - } |
|
544 | - $Message_Template->set('MTP_content', $new_content); |
|
545 | - $Message_Template->save(); |
|
546 | - } |
|
547 | - } |
|
548 | - // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
549 | - $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
550 | - ? $this->_req_data['batch_message']['id_type'] |
|
551 | - : 'registration'; |
|
552 | - // id_type will affect how we assemble the ids. |
|
553 | - $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
554 | - ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
555 | - : array(); |
|
556 | - $registrations_used_for_contact_data = array(); |
|
557 | - // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
558 | - switch ($id_type) { |
|
559 | - case 'registration': |
|
560 | - $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
561 | - array( |
|
562 | - array( |
|
563 | - 'REG_ID' => array('IN', $ids), |
|
564 | - ), |
|
565 | - ) |
|
566 | - ); |
|
567 | - break; |
|
568 | - case 'contact': |
|
569 | - $registrations_used_for_contact_data = EEM_Registration::instance() |
|
570 | - ->get_latest_registration_for_each_of_given_contacts( |
|
571 | - $ids |
|
572 | - ); |
|
573 | - break; |
|
574 | - } |
|
575 | - do_action_ref_array( |
|
576 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
577 | - array( |
|
578 | - $registrations_used_for_contact_data, |
|
579 | - $Message_Template_Group->ID(), |
|
580 | - ) |
|
581 | - ); |
|
582 | - // kept for backward compat, internally we no longer use this action. |
|
583 | - // @deprecated 4.8.36.rc.002 |
|
584 | - $contacts = $id_type === 'registration' |
|
585 | - ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
586 | - : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
587 | - do_action_ref_array( |
|
588 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
589 | - array( |
|
590 | - $contacts, |
|
591 | - $Message_Template_Group->ID(), |
|
592 | - ) |
|
593 | - ); |
|
594 | - } |
|
595 | - $query_args = array( |
|
596 | - 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
597 | - ? $this->_req_data['redirect_back_to'] |
|
598 | - : 'default', |
|
599 | - ); |
|
600 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
601 | - } |
|
472 | + /** |
|
473 | + * Handles sending selected registrations/contacts a newsletter. |
|
474 | + * |
|
475 | + * @since 4.3.0 |
|
476 | + * @return void |
|
477 | + * @throws EE_Error |
|
478 | + * @throws InvalidArgumentException |
|
479 | + * @throws InvalidDataTypeException |
|
480 | + * @throws InvalidInterfaceException |
|
481 | + */ |
|
482 | + protected function _newsletter_selected_send() |
|
483 | + { |
|
484 | + $success = true; |
|
485 | + // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
486 | + if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
487 | + EE_Error::add_error( |
|
488 | + esc_html__( |
|
489 | + 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
490 | + 'event_espresso' |
|
491 | + ), |
|
492 | + __FILE__, |
|
493 | + __FUNCTION__, |
|
494 | + __LINE__ |
|
495 | + ); |
|
496 | + $success = false; |
|
497 | + } |
|
498 | + if ($success) { |
|
499 | + // update Message template in case there are any changes |
|
500 | + $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
501 | + $this->_req_data['newsletter_mtp_selected'] |
|
502 | + ); |
|
503 | + $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
504 | + ? $Message_Template_Group->context_templates() |
|
505 | + : array(); |
|
506 | + if (empty($Message_Templates)) { |
|
507 | + EE_Error::add_error( |
|
508 | + esc_html__( |
|
509 | + 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
510 | + 'event_espresso' |
|
511 | + ), |
|
512 | + __FILE__, |
|
513 | + __FUNCTION__, |
|
514 | + __LINE__ |
|
515 | + ); |
|
516 | + } |
|
517 | + // let's just update the specific fields |
|
518 | + foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
519 | + if ($Message_Template instanceof EE_Message_Template) { |
|
520 | + $field = $Message_Template->get('MTP_template_field'); |
|
521 | + $content = $Message_Template->get('MTP_content'); |
|
522 | + $new_content = $content; |
|
523 | + switch ($field) { |
|
524 | + case 'from': |
|
525 | + $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
526 | + ? $this->_req_data['batch_message']['from'] |
|
527 | + : $content; |
|
528 | + break; |
|
529 | + case 'subject': |
|
530 | + $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
531 | + ? $this->_req_data['batch_message']['subject'] |
|
532 | + : $content; |
|
533 | + break; |
|
534 | + case 'content': |
|
535 | + $new_content = $content; |
|
536 | + $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
537 | + ? $this->_req_data['batch_message']['content'] |
|
538 | + : $content['newsletter_content']; |
|
539 | + break; |
|
540 | + default: |
|
541 | + // continue the foreach loop, we don't want to set $new_content nor save. |
|
542 | + continue 2; |
|
543 | + } |
|
544 | + $Message_Template->set('MTP_content', $new_content); |
|
545 | + $Message_Template->save(); |
|
546 | + } |
|
547 | + } |
|
548 | + // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
549 | + $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
550 | + ? $this->_req_data['batch_message']['id_type'] |
|
551 | + : 'registration'; |
|
552 | + // id_type will affect how we assemble the ids. |
|
553 | + $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
554 | + ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
555 | + : array(); |
|
556 | + $registrations_used_for_contact_data = array(); |
|
557 | + // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
558 | + switch ($id_type) { |
|
559 | + case 'registration': |
|
560 | + $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
561 | + array( |
|
562 | + array( |
|
563 | + 'REG_ID' => array('IN', $ids), |
|
564 | + ), |
|
565 | + ) |
|
566 | + ); |
|
567 | + break; |
|
568 | + case 'contact': |
|
569 | + $registrations_used_for_contact_data = EEM_Registration::instance() |
|
570 | + ->get_latest_registration_for_each_of_given_contacts( |
|
571 | + $ids |
|
572 | + ); |
|
573 | + break; |
|
574 | + } |
|
575 | + do_action_ref_array( |
|
576 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
577 | + array( |
|
578 | + $registrations_used_for_contact_data, |
|
579 | + $Message_Template_Group->ID(), |
|
580 | + ) |
|
581 | + ); |
|
582 | + // kept for backward compat, internally we no longer use this action. |
|
583 | + // @deprecated 4.8.36.rc.002 |
|
584 | + $contacts = $id_type === 'registration' |
|
585 | + ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
586 | + : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
587 | + do_action_ref_array( |
|
588 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
589 | + array( |
|
590 | + $contacts, |
|
591 | + $Message_Template_Group->ID(), |
|
592 | + ) |
|
593 | + ); |
|
594 | + } |
|
595 | + $query_args = array( |
|
596 | + 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
597 | + ? $this->_req_data['redirect_back_to'] |
|
598 | + : 'default', |
|
599 | + ); |
|
600 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
601 | + } |
|
602 | 602 | |
603 | 603 | |
604 | - /** |
|
605 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
606 | - * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
607 | - */ |
|
608 | - protected function _registration_reports_js_setup() |
|
609 | - { |
|
610 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
611 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
612 | - } |
|
604 | + /** |
|
605 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
606 | + * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
607 | + */ |
|
608 | + protected function _registration_reports_js_setup() |
|
609 | + { |
|
610 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
611 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
612 | + } |
|
613 | 613 | |
614 | 614 | |
615 | - /** |
|
616 | - * generates Business Reports regarding Registrations |
|
617 | - * |
|
618 | - * @access protected |
|
619 | - * @return void |
|
620 | - * @throws DomainException |
|
621 | - */ |
|
622 | - protected function _registration_reports() |
|
623 | - { |
|
624 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
625 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
626 | - $template_path, |
|
627 | - $this->_reports_template_data, |
|
628 | - true |
|
629 | - ); |
|
630 | - // the final template wrapper |
|
631 | - $this->display_admin_page_with_no_sidebar(); |
|
632 | - } |
|
615 | + /** |
|
616 | + * generates Business Reports regarding Registrations |
|
617 | + * |
|
618 | + * @access protected |
|
619 | + * @return void |
|
620 | + * @throws DomainException |
|
621 | + */ |
|
622 | + protected function _registration_reports() |
|
623 | + { |
|
624 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
625 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
626 | + $template_path, |
|
627 | + $this->_reports_template_data, |
|
628 | + true |
|
629 | + ); |
|
630 | + // the final template wrapper |
|
631 | + $this->display_admin_page_with_no_sidebar(); |
|
632 | + } |
|
633 | 633 | |
634 | 634 | |
635 | - /** |
|
636 | - * Generates Business Report showing total registrations per day. |
|
637 | - * |
|
638 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
639 | - * @return string |
|
640 | - * @throws EE_Error |
|
641 | - * @throws InvalidArgumentException |
|
642 | - * @throws InvalidDataTypeException |
|
643 | - * @throws InvalidInterfaceException |
|
644 | - */ |
|
645 | - private function _registrations_per_day_report($period = '-1 month') |
|
646 | - { |
|
647 | - $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
648 | - $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
649 | - $results = (array) $results; |
|
650 | - $regs = array(); |
|
651 | - $subtitle = ''; |
|
652 | - if ($results) { |
|
653 | - $column_titles = array(); |
|
654 | - $tracker = 0; |
|
655 | - foreach ($results as $result) { |
|
656 | - $report_column_values = array(); |
|
657 | - foreach ($result as $property_name => $property_value) { |
|
658 | - $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
659 | - : (int) $property_value; |
|
660 | - $report_column_values[] = $property_value; |
|
661 | - if ($tracker === 0) { |
|
662 | - if ($property_name === 'Registration_REG_date') { |
|
663 | - $column_titles[] = esc_html__( |
|
664 | - 'Date (only days with registrations are shown)', |
|
665 | - 'event_espresso' |
|
666 | - ); |
|
667 | - } else { |
|
668 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
669 | - } |
|
670 | - } |
|
671 | - } |
|
672 | - $tracker++; |
|
673 | - $regs[] = $report_column_values; |
|
674 | - } |
|
675 | - // make sure the column_titles is pushed to the beginning of the array |
|
676 | - array_unshift($regs, $column_titles); |
|
677 | - // setup the date range. |
|
678 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
679 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
680 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
681 | - $subtitle = sprintf( |
|
682 | - wp_strip_all_tags( |
|
683 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso') |
|
684 | - ), |
|
685 | - $beginning_date->format('Y-m-d'), |
|
686 | - $ending_date->format('Y-m-d') |
|
687 | - ); |
|
688 | - } |
|
689 | - $report_title = wp_strip_all_tags(__('Total Registrations per Day', 'event_espresso')); |
|
690 | - $report_params = array( |
|
691 | - 'title' => $report_title, |
|
692 | - 'subtitle' => $subtitle, |
|
693 | - 'id' => $report_ID, |
|
694 | - 'regs' => $regs, |
|
695 | - 'noResults' => empty($regs), |
|
696 | - 'noRegsMsg' => sprintf( |
|
697 | - wp_strip_all_tags( |
|
698 | - __( |
|
699 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
700 | - 'event_espresso' |
|
701 | - ) |
|
702 | - ), |
|
703 | - '<h2>' . $report_title . '</h2><p>', |
|
704 | - '</p>' |
|
705 | - ), |
|
706 | - ); |
|
707 | - wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
708 | - return $report_ID; |
|
709 | - } |
|
635 | + /** |
|
636 | + * Generates Business Report showing total registrations per day. |
|
637 | + * |
|
638 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
639 | + * @return string |
|
640 | + * @throws EE_Error |
|
641 | + * @throws InvalidArgumentException |
|
642 | + * @throws InvalidDataTypeException |
|
643 | + * @throws InvalidInterfaceException |
|
644 | + */ |
|
645 | + private function _registrations_per_day_report($period = '-1 month') |
|
646 | + { |
|
647 | + $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
648 | + $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
649 | + $results = (array) $results; |
|
650 | + $regs = array(); |
|
651 | + $subtitle = ''; |
|
652 | + if ($results) { |
|
653 | + $column_titles = array(); |
|
654 | + $tracker = 0; |
|
655 | + foreach ($results as $result) { |
|
656 | + $report_column_values = array(); |
|
657 | + foreach ($result as $property_name => $property_value) { |
|
658 | + $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
659 | + : (int) $property_value; |
|
660 | + $report_column_values[] = $property_value; |
|
661 | + if ($tracker === 0) { |
|
662 | + if ($property_name === 'Registration_REG_date') { |
|
663 | + $column_titles[] = esc_html__( |
|
664 | + 'Date (only days with registrations are shown)', |
|
665 | + 'event_espresso' |
|
666 | + ); |
|
667 | + } else { |
|
668 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
669 | + } |
|
670 | + } |
|
671 | + } |
|
672 | + $tracker++; |
|
673 | + $regs[] = $report_column_values; |
|
674 | + } |
|
675 | + // make sure the column_titles is pushed to the beginning of the array |
|
676 | + array_unshift($regs, $column_titles); |
|
677 | + // setup the date range. |
|
678 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
679 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
680 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
681 | + $subtitle = sprintf( |
|
682 | + wp_strip_all_tags( |
|
683 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso') |
|
684 | + ), |
|
685 | + $beginning_date->format('Y-m-d'), |
|
686 | + $ending_date->format('Y-m-d') |
|
687 | + ); |
|
688 | + } |
|
689 | + $report_title = wp_strip_all_tags(__('Total Registrations per Day', 'event_espresso')); |
|
690 | + $report_params = array( |
|
691 | + 'title' => $report_title, |
|
692 | + 'subtitle' => $subtitle, |
|
693 | + 'id' => $report_ID, |
|
694 | + 'regs' => $regs, |
|
695 | + 'noResults' => empty($regs), |
|
696 | + 'noRegsMsg' => sprintf( |
|
697 | + wp_strip_all_tags( |
|
698 | + __( |
|
699 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
700 | + 'event_espresso' |
|
701 | + ) |
|
702 | + ), |
|
703 | + '<h2>' . $report_title . '</h2><p>', |
|
704 | + '</p>' |
|
705 | + ), |
|
706 | + ); |
|
707 | + wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
708 | + return $report_ID; |
|
709 | + } |
|
710 | 710 | |
711 | 711 | |
712 | - /** |
|
713 | - * Generates Business Report showing total registrations per event. |
|
714 | - * |
|
715 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
716 | - * @return string |
|
717 | - * @throws EE_Error |
|
718 | - * @throws InvalidArgumentException |
|
719 | - * @throws InvalidDataTypeException |
|
720 | - * @throws InvalidInterfaceException |
|
721 | - */ |
|
722 | - private function _registrations_per_event_report($period = '-1 month') |
|
723 | - { |
|
724 | - $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
725 | - $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
726 | - $results = (array) $results; |
|
727 | - $regs = array(); |
|
728 | - $subtitle = ''; |
|
729 | - if ($results) { |
|
730 | - $column_titles = array(); |
|
731 | - $tracker = 0; |
|
732 | - foreach ($results as $result) { |
|
733 | - $report_column_values = array(); |
|
734 | - foreach ($result as $property_name => $property_value) { |
|
735 | - $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
736 | - $property_value, |
|
737 | - 4, |
|
738 | - '...' |
|
739 | - ) : (int) $property_value; |
|
740 | - $report_column_values[] = $property_value; |
|
741 | - if ($tracker === 0) { |
|
742 | - if ($property_name === 'Registration_Event') { |
|
743 | - $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
744 | - } else { |
|
745 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
746 | - } |
|
747 | - } |
|
748 | - } |
|
749 | - $tracker++; |
|
750 | - $regs[] = $report_column_values; |
|
751 | - } |
|
752 | - // make sure the column_titles is pushed to the beginning of the array |
|
753 | - array_unshift($regs, $column_titles); |
|
754 | - // setup the date range. |
|
755 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
756 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
757 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
758 | - $subtitle = sprintf( |
|
759 | - wp_strip_all_tags( |
|
760 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso') |
|
761 | - ), |
|
762 | - $beginning_date->format('Y-m-d'), |
|
763 | - $ending_date->format('Y-m-d') |
|
764 | - ); |
|
765 | - } |
|
766 | - $report_title = wp_strip_all_tags(__('Total Registrations per Event', 'event_espresso')); |
|
767 | - $report_params = array( |
|
768 | - 'title' => $report_title, |
|
769 | - 'subtitle' => $subtitle, |
|
770 | - 'id' => $report_ID, |
|
771 | - 'regs' => $regs, |
|
772 | - 'noResults' => empty($regs), |
|
773 | - 'noRegsMsg' => sprintf( |
|
774 | - wp_strip_all_tags( |
|
775 | - __( |
|
776 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
777 | - 'event_espresso' |
|
778 | - ) |
|
779 | - ), |
|
780 | - '<h2>' . $report_title . '</h2><p>', |
|
781 | - '</p>' |
|
782 | - ), |
|
783 | - ); |
|
784 | - wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
785 | - return $report_ID; |
|
786 | - } |
|
712 | + /** |
|
713 | + * Generates Business Report showing total registrations per event. |
|
714 | + * |
|
715 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
716 | + * @return string |
|
717 | + * @throws EE_Error |
|
718 | + * @throws InvalidArgumentException |
|
719 | + * @throws InvalidDataTypeException |
|
720 | + * @throws InvalidInterfaceException |
|
721 | + */ |
|
722 | + private function _registrations_per_event_report($period = '-1 month') |
|
723 | + { |
|
724 | + $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
725 | + $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
726 | + $results = (array) $results; |
|
727 | + $regs = array(); |
|
728 | + $subtitle = ''; |
|
729 | + if ($results) { |
|
730 | + $column_titles = array(); |
|
731 | + $tracker = 0; |
|
732 | + foreach ($results as $result) { |
|
733 | + $report_column_values = array(); |
|
734 | + foreach ($result as $property_name => $property_value) { |
|
735 | + $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
736 | + $property_value, |
|
737 | + 4, |
|
738 | + '...' |
|
739 | + ) : (int) $property_value; |
|
740 | + $report_column_values[] = $property_value; |
|
741 | + if ($tracker === 0) { |
|
742 | + if ($property_name === 'Registration_Event') { |
|
743 | + $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
744 | + } else { |
|
745 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
746 | + } |
|
747 | + } |
|
748 | + } |
|
749 | + $tracker++; |
|
750 | + $regs[] = $report_column_values; |
|
751 | + } |
|
752 | + // make sure the column_titles is pushed to the beginning of the array |
|
753 | + array_unshift($regs, $column_titles); |
|
754 | + // setup the date range. |
|
755 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
756 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
757 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
758 | + $subtitle = sprintf( |
|
759 | + wp_strip_all_tags( |
|
760 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso') |
|
761 | + ), |
|
762 | + $beginning_date->format('Y-m-d'), |
|
763 | + $ending_date->format('Y-m-d') |
|
764 | + ); |
|
765 | + } |
|
766 | + $report_title = wp_strip_all_tags(__('Total Registrations per Event', 'event_espresso')); |
|
767 | + $report_params = array( |
|
768 | + 'title' => $report_title, |
|
769 | + 'subtitle' => $subtitle, |
|
770 | + 'id' => $report_ID, |
|
771 | + 'regs' => $regs, |
|
772 | + 'noResults' => empty($regs), |
|
773 | + 'noRegsMsg' => sprintf( |
|
774 | + wp_strip_all_tags( |
|
775 | + __( |
|
776 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
777 | + 'event_espresso' |
|
778 | + ) |
|
779 | + ), |
|
780 | + '<h2>' . $report_title . '</h2><p>', |
|
781 | + '</p>' |
|
782 | + ), |
|
783 | + ); |
|
784 | + wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
785 | + return $report_ID; |
|
786 | + } |
|
787 | 787 | |
788 | 788 | |
789 | - /** |
|
790 | - * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
791 | - * |
|
792 | - * @access protected |
|
793 | - * @return void |
|
794 | - * @throws EE_Error |
|
795 | - * @throws InvalidArgumentException |
|
796 | - * @throws InvalidDataTypeException |
|
797 | - * @throws InvalidInterfaceException |
|
798 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
799 | - */ |
|
800 | - protected function _registration_checkin_list_table() |
|
801 | - { |
|
802 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
803 | - $reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null; |
|
804 | - /** @var EE_Registration $registration */ |
|
805 | - $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
806 | - if (! $registration instanceof EE_Registration) { |
|
807 | - throw new EE_Error( |
|
808 | - sprintf( |
|
809 | - esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'), |
|
810 | - $reg_id |
|
811 | - ) |
|
812 | - ); |
|
813 | - } |
|
814 | - $attendee = $registration->attendee(); |
|
815 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
816 | - 'new_registration', |
|
817 | - 'add-registrant', |
|
818 | - array('event_id' => $registration->event_ID()), |
|
819 | - 'add-new-h2' |
|
820 | - ); |
|
821 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
822 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
823 | - $legend_items = array( |
|
824 | - 'checkin' => array( |
|
825 | - 'class' => $checked_in->cssClasses(), |
|
826 | - 'desc' => $checked_in->legendLabel(), |
|
827 | - ), |
|
828 | - 'checkout' => array( |
|
829 | - 'class' => $checked_out->cssClasses(), |
|
830 | - 'desc' => $checked_out->legendLabel(), |
|
831 | - ), |
|
832 | - ); |
|
833 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
834 | - $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
835 | - /** @var EE_Datetime $datetime */ |
|
836 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
837 | - $datetime_label = ''; |
|
838 | - if ($datetime instanceof EE_Datetime) { |
|
839 | - $datetime_label = $datetime->get_dtt_display_name(true); |
|
840 | - $datetime_label .= ! empty($datetime_label) |
|
841 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
842 | - : $datetime->get_dtt_display_name(); |
|
843 | - } |
|
844 | - $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
845 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
846 | - array( |
|
847 | - 'action' => 'event_registrations', |
|
848 | - 'event_id' => $registration->event_ID(), |
|
849 | - 'DTT_ID' => $dtt_id, |
|
850 | - ), |
|
851 | - $this->_admin_base_url |
|
852 | - ) |
|
853 | - : ''; |
|
854 | - $datetime_link = ! empty($datetime_link) |
|
855 | - ? '<a href="' . $datetime_link . '">' |
|
856 | - . '<span id="checkin-dtt">' |
|
857 | - . $datetime_label |
|
858 | - . '</span></a>' |
|
859 | - : $datetime_label; |
|
860 | - $attendee_name = $attendee instanceof EE_Attendee |
|
861 | - ? $attendee->full_name() |
|
862 | - : ''; |
|
863 | - $attendee_link = $attendee instanceof EE_Attendee |
|
864 | - ? $attendee->get_admin_details_link() |
|
865 | - : ''; |
|
866 | - $attendee_link = ! empty($attendee_link) |
|
867 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
868 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
869 | - . '<span id="checkin-attendee-name">' |
|
870 | - . $attendee_name |
|
871 | - . '</span></a>' |
|
872 | - : ''; |
|
873 | - $event_link = $registration->event() instanceof EE_Event |
|
874 | - ? $registration->event()->get_admin_details_link() |
|
875 | - : ''; |
|
876 | - $event_link = ! empty($event_link) |
|
877 | - ? '<a href="' . $event_link . '"' |
|
878 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
879 | - . '<span id="checkin-event-name">' |
|
880 | - . $registration->event_name() |
|
881 | - . '</span>' |
|
882 | - . '</a>' |
|
883 | - : ''; |
|
884 | - $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
885 | - ? '<h2>' . sprintf( |
|
886 | - esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
887 | - $attendee_link, |
|
888 | - $datetime_link, |
|
889 | - $event_link |
|
890 | - ) . '</h2>' |
|
891 | - : ''; |
|
892 | - $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
893 | - ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
894 | - $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
895 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
896 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
897 | - } |
|
789 | + /** |
|
790 | + * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
791 | + * |
|
792 | + * @access protected |
|
793 | + * @return void |
|
794 | + * @throws EE_Error |
|
795 | + * @throws InvalidArgumentException |
|
796 | + * @throws InvalidDataTypeException |
|
797 | + * @throws InvalidInterfaceException |
|
798 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
799 | + */ |
|
800 | + protected function _registration_checkin_list_table() |
|
801 | + { |
|
802 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
803 | + $reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null; |
|
804 | + /** @var EE_Registration $registration */ |
|
805 | + $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
806 | + if (! $registration instanceof EE_Registration) { |
|
807 | + throw new EE_Error( |
|
808 | + sprintf( |
|
809 | + esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'), |
|
810 | + $reg_id |
|
811 | + ) |
|
812 | + ); |
|
813 | + } |
|
814 | + $attendee = $registration->attendee(); |
|
815 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
816 | + 'new_registration', |
|
817 | + 'add-registrant', |
|
818 | + array('event_id' => $registration->event_ID()), |
|
819 | + 'add-new-h2' |
|
820 | + ); |
|
821 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
822 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
823 | + $legend_items = array( |
|
824 | + 'checkin' => array( |
|
825 | + 'class' => $checked_in->cssClasses(), |
|
826 | + 'desc' => $checked_in->legendLabel(), |
|
827 | + ), |
|
828 | + 'checkout' => array( |
|
829 | + 'class' => $checked_out->cssClasses(), |
|
830 | + 'desc' => $checked_out->legendLabel(), |
|
831 | + ), |
|
832 | + ); |
|
833 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
834 | + $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
835 | + /** @var EE_Datetime $datetime */ |
|
836 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
837 | + $datetime_label = ''; |
|
838 | + if ($datetime instanceof EE_Datetime) { |
|
839 | + $datetime_label = $datetime->get_dtt_display_name(true); |
|
840 | + $datetime_label .= ! empty($datetime_label) |
|
841 | + ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
842 | + : $datetime->get_dtt_display_name(); |
|
843 | + } |
|
844 | + $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
845 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
846 | + array( |
|
847 | + 'action' => 'event_registrations', |
|
848 | + 'event_id' => $registration->event_ID(), |
|
849 | + 'DTT_ID' => $dtt_id, |
|
850 | + ), |
|
851 | + $this->_admin_base_url |
|
852 | + ) |
|
853 | + : ''; |
|
854 | + $datetime_link = ! empty($datetime_link) |
|
855 | + ? '<a href="' . $datetime_link . '">' |
|
856 | + . '<span id="checkin-dtt">' |
|
857 | + . $datetime_label |
|
858 | + . '</span></a>' |
|
859 | + : $datetime_label; |
|
860 | + $attendee_name = $attendee instanceof EE_Attendee |
|
861 | + ? $attendee->full_name() |
|
862 | + : ''; |
|
863 | + $attendee_link = $attendee instanceof EE_Attendee |
|
864 | + ? $attendee->get_admin_details_link() |
|
865 | + : ''; |
|
866 | + $attendee_link = ! empty($attendee_link) |
|
867 | + ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
868 | + . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
869 | + . '<span id="checkin-attendee-name">' |
|
870 | + . $attendee_name |
|
871 | + . '</span></a>' |
|
872 | + : ''; |
|
873 | + $event_link = $registration->event() instanceof EE_Event |
|
874 | + ? $registration->event()->get_admin_details_link() |
|
875 | + : ''; |
|
876 | + $event_link = ! empty($event_link) |
|
877 | + ? '<a href="' . $event_link . '"' |
|
878 | + . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
879 | + . '<span id="checkin-event-name">' |
|
880 | + . $registration->event_name() |
|
881 | + . '</span>' |
|
882 | + . '</a>' |
|
883 | + : ''; |
|
884 | + $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
885 | + ? '<h2>' . sprintf( |
|
886 | + esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
887 | + $attendee_link, |
|
888 | + $datetime_link, |
|
889 | + $event_link |
|
890 | + ) . '</h2>' |
|
891 | + : ''; |
|
892 | + $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
893 | + ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
894 | + $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
895 | + ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
896 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
897 | + } |
|
898 | 898 | |
899 | 899 | |
900 | - /** |
|
901 | - * toggle the Check-in status for the given registration (coming from ajax) |
|
902 | - * |
|
903 | - * @return void (JSON) |
|
904 | - * @throws EE_Error |
|
905 | - * @throws InvalidArgumentException |
|
906 | - * @throws InvalidDataTypeException |
|
907 | - * @throws InvalidInterfaceException |
|
908 | - */ |
|
909 | - public function toggle_checkin_status() |
|
910 | - { |
|
911 | - // first make sure we have the necessary data |
|
912 | - if (! isset($this->_req_data['_regid'])) { |
|
913 | - EE_Error::add_error( |
|
914 | - esc_html__( |
|
915 | - 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
916 | - 'event_espresso' |
|
917 | - ), |
|
918 | - __FILE__, |
|
919 | - __FUNCTION__, |
|
920 | - __LINE__ |
|
921 | - ); |
|
922 | - $this->_template_args['success'] = false; |
|
923 | - $this->_template_args['error'] = true; |
|
924 | - $this->_return_json(); |
|
925 | - }; |
|
926 | - // do a nonce check cause we're not coming in from an normal route here. |
|
927 | - $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
928 | - : ''; |
|
929 | - $nonce_ref = 'checkin_nonce'; |
|
930 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
931 | - // beautiful! Made it this far so let's get the status. |
|
932 | - $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
933 | - // setup new class to return via ajax |
|
934 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
935 | - $this->_template_args['success'] = true; |
|
936 | - $this->_return_json(); |
|
937 | - } |
|
900 | + /** |
|
901 | + * toggle the Check-in status for the given registration (coming from ajax) |
|
902 | + * |
|
903 | + * @return void (JSON) |
|
904 | + * @throws EE_Error |
|
905 | + * @throws InvalidArgumentException |
|
906 | + * @throws InvalidDataTypeException |
|
907 | + * @throws InvalidInterfaceException |
|
908 | + */ |
|
909 | + public function toggle_checkin_status() |
|
910 | + { |
|
911 | + // first make sure we have the necessary data |
|
912 | + if (! isset($this->_req_data['_regid'])) { |
|
913 | + EE_Error::add_error( |
|
914 | + esc_html__( |
|
915 | + 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
916 | + 'event_espresso' |
|
917 | + ), |
|
918 | + __FILE__, |
|
919 | + __FUNCTION__, |
|
920 | + __LINE__ |
|
921 | + ); |
|
922 | + $this->_template_args['success'] = false; |
|
923 | + $this->_template_args['error'] = true; |
|
924 | + $this->_return_json(); |
|
925 | + }; |
|
926 | + // do a nonce check cause we're not coming in from an normal route here. |
|
927 | + $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
928 | + : ''; |
|
929 | + $nonce_ref = 'checkin_nonce'; |
|
930 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
931 | + // beautiful! Made it this far so let's get the status. |
|
932 | + $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
933 | + // setup new class to return via ajax |
|
934 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
935 | + $this->_template_args['success'] = true; |
|
936 | + $this->_return_json(); |
|
937 | + } |
|
938 | 938 | |
939 | 939 | |
940 | - /** |
|
941 | - * handles toggling the checkin status for the registration, |
|
942 | - * |
|
943 | - * @access protected |
|
944 | - * @return int|void |
|
945 | - * @throws EE_Error |
|
946 | - * @throws InvalidArgumentException |
|
947 | - * @throws InvalidDataTypeException |
|
948 | - * @throws InvalidInterfaceException |
|
949 | - */ |
|
950 | - protected function _toggle_checkin_status() |
|
951 | - { |
|
952 | - // first let's get the query args out of the way for the redirect |
|
953 | - $query_args = array( |
|
954 | - 'action' => 'event_registrations', |
|
955 | - 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
956 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
957 | - ); |
|
958 | - $new_status = false; |
|
959 | - // bulk action check in toggle |
|
960 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
961 | - // cycle thru checkboxes |
|
962 | - while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
963 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
964 | - $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
965 | - } |
|
966 | - } elseif (isset($this->_req_data['_regid'])) { |
|
967 | - // coming from ajax request |
|
968 | - $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
969 | - $query_args['DTT_ID'] = $DTT_ID; |
|
970 | - $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
971 | - } else { |
|
972 | - EE_Error::add_error( |
|
973 | - esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
974 | - __FILE__, |
|
975 | - __FUNCTION__, |
|
976 | - __LINE__ |
|
977 | - ); |
|
978 | - } |
|
979 | - if (defined('DOING_AJAX')) { |
|
980 | - return $new_status; |
|
981 | - } |
|
982 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
983 | - } |
|
940 | + /** |
|
941 | + * handles toggling the checkin status for the registration, |
|
942 | + * |
|
943 | + * @access protected |
|
944 | + * @return int|void |
|
945 | + * @throws EE_Error |
|
946 | + * @throws InvalidArgumentException |
|
947 | + * @throws InvalidDataTypeException |
|
948 | + * @throws InvalidInterfaceException |
|
949 | + */ |
|
950 | + protected function _toggle_checkin_status() |
|
951 | + { |
|
952 | + // first let's get the query args out of the way for the redirect |
|
953 | + $query_args = array( |
|
954 | + 'action' => 'event_registrations', |
|
955 | + 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
956 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
957 | + ); |
|
958 | + $new_status = false; |
|
959 | + // bulk action check in toggle |
|
960 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
961 | + // cycle thru checkboxes |
|
962 | + while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
963 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
964 | + $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
965 | + } |
|
966 | + } elseif (isset($this->_req_data['_regid'])) { |
|
967 | + // coming from ajax request |
|
968 | + $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
969 | + $query_args['DTT_ID'] = $DTT_ID; |
|
970 | + $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
971 | + } else { |
|
972 | + EE_Error::add_error( |
|
973 | + esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
974 | + __FILE__, |
|
975 | + __FUNCTION__, |
|
976 | + __LINE__ |
|
977 | + ); |
|
978 | + } |
|
979 | + if (defined('DOING_AJAX')) { |
|
980 | + return $new_status; |
|
981 | + } |
|
982 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
983 | + } |
|
984 | 984 | |
985 | 985 | |
986 | - /** |
|
987 | - * This is toggles a single Check-in for the given registration and datetime. |
|
988 | - * |
|
989 | - * @param int $REG_ID The registration we're toggling |
|
990 | - * @param int $DTT_ID The datetime we're toggling |
|
991 | - * @return int The new status toggled to. |
|
992 | - * @throws EE_Error |
|
993 | - * @throws InvalidArgumentException |
|
994 | - * @throws InvalidDataTypeException |
|
995 | - * @throws InvalidInterfaceException |
|
996 | - */ |
|
997 | - private function _toggle_checkin($REG_ID, $DTT_ID) |
|
998 | - { |
|
999 | - /** @var EE_Registration $REG */ |
|
1000 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
1001 | - $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
1002 | - if ($new_status !== false) { |
|
1003 | - EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
1004 | - } else { |
|
1005 | - EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
1006 | - $new_status = false; |
|
1007 | - } |
|
1008 | - return $new_status; |
|
1009 | - } |
|
986 | + /** |
|
987 | + * This is toggles a single Check-in for the given registration and datetime. |
|
988 | + * |
|
989 | + * @param int $REG_ID The registration we're toggling |
|
990 | + * @param int $DTT_ID The datetime we're toggling |
|
991 | + * @return int The new status toggled to. |
|
992 | + * @throws EE_Error |
|
993 | + * @throws InvalidArgumentException |
|
994 | + * @throws InvalidDataTypeException |
|
995 | + * @throws InvalidInterfaceException |
|
996 | + */ |
|
997 | + private function _toggle_checkin($REG_ID, $DTT_ID) |
|
998 | + { |
|
999 | + /** @var EE_Registration $REG */ |
|
1000 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
1001 | + $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
1002 | + if ($new_status !== false) { |
|
1003 | + EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
1004 | + } else { |
|
1005 | + EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
1006 | + $new_status = false; |
|
1007 | + } |
|
1008 | + return $new_status; |
|
1009 | + } |
|
1010 | 1010 | |
1011 | 1011 | |
1012 | - /** |
|
1013 | - * Takes care of deleting multiple EE_Checkin table rows |
|
1014 | - * |
|
1015 | - * @access protected |
|
1016 | - * @return void |
|
1017 | - * @throws EE_Error |
|
1018 | - * @throws InvalidArgumentException |
|
1019 | - * @throws InvalidDataTypeException |
|
1020 | - * @throws InvalidInterfaceException |
|
1021 | - */ |
|
1022 | - protected function _delete_checkin_rows() |
|
1023 | - { |
|
1024 | - $query_args = array( |
|
1025 | - 'action' => 'registration_checkins', |
|
1026 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
1027 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
1028 | - ); |
|
1029 | - $errors = 0; |
|
1030 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1031 | - while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1032 | - if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
1033 | - $errors++; |
|
1034 | - } |
|
1035 | - } |
|
1036 | - } else { |
|
1037 | - EE_Error::add_error( |
|
1038 | - esc_html__( |
|
1039 | - 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
1040 | - 'event_espresso' |
|
1041 | - ), |
|
1042 | - __FILE__, |
|
1043 | - __FUNCTION__, |
|
1044 | - __LINE__ |
|
1045 | - ); |
|
1046 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1047 | - } |
|
1048 | - if ($errors > 0) { |
|
1049 | - EE_Error::add_error( |
|
1050 | - sprintf(esc_html__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
1051 | - __FILE__, |
|
1052 | - __FUNCTION__, |
|
1053 | - __LINE__ |
|
1054 | - ); |
|
1055 | - } else { |
|
1056 | - EE_Error::add_success(esc_html__('Records were successfully deleted', 'event_espresso')); |
|
1057 | - } |
|
1058 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1059 | - } |
|
1012 | + /** |
|
1013 | + * Takes care of deleting multiple EE_Checkin table rows |
|
1014 | + * |
|
1015 | + * @access protected |
|
1016 | + * @return void |
|
1017 | + * @throws EE_Error |
|
1018 | + * @throws InvalidArgumentException |
|
1019 | + * @throws InvalidDataTypeException |
|
1020 | + * @throws InvalidInterfaceException |
|
1021 | + */ |
|
1022 | + protected function _delete_checkin_rows() |
|
1023 | + { |
|
1024 | + $query_args = array( |
|
1025 | + 'action' => 'registration_checkins', |
|
1026 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
1027 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
1028 | + ); |
|
1029 | + $errors = 0; |
|
1030 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1031 | + while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1032 | + if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
1033 | + $errors++; |
|
1034 | + } |
|
1035 | + } |
|
1036 | + } else { |
|
1037 | + EE_Error::add_error( |
|
1038 | + esc_html__( |
|
1039 | + 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
1040 | + 'event_espresso' |
|
1041 | + ), |
|
1042 | + __FILE__, |
|
1043 | + __FUNCTION__, |
|
1044 | + __LINE__ |
|
1045 | + ); |
|
1046 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1047 | + } |
|
1048 | + if ($errors > 0) { |
|
1049 | + EE_Error::add_error( |
|
1050 | + sprintf(esc_html__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
1051 | + __FILE__, |
|
1052 | + __FUNCTION__, |
|
1053 | + __LINE__ |
|
1054 | + ); |
|
1055 | + } else { |
|
1056 | + EE_Error::add_success(esc_html__('Records were successfully deleted', 'event_espresso')); |
|
1057 | + } |
|
1058 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1059 | + } |
|
1060 | 1060 | |
1061 | 1061 | |
1062 | - /** |
|
1063 | - * Deletes a single EE_Checkin row |
|
1064 | - * |
|
1065 | - * @return void |
|
1066 | - * @throws EE_Error |
|
1067 | - * @throws InvalidArgumentException |
|
1068 | - * @throws InvalidDataTypeException |
|
1069 | - * @throws InvalidInterfaceException |
|
1070 | - */ |
|
1071 | - protected function _delete_checkin_row() |
|
1072 | - { |
|
1073 | - $query_args = array( |
|
1074 | - 'action' => 'registration_checkins', |
|
1075 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
1076 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
1077 | - ); |
|
1078 | - if (! empty($this->_req_data['CHK_ID'])) { |
|
1079 | - if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
1080 | - EE_Error::add_error( |
|
1081 | - esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
1082 | - __FILE__, |
|
1083 | - __FUNCTION__, |
|
1084 | - __LINE__ |
|
1085 | - ); |
|
1086 | - } else { |
|
1087 | - EE_Error::add_success(esc_html__('Check-In record successfully deleted', 'event_espresso')); |
|
1088 | - } |
|
1089 | - } else { |
|
1090 | - EE_Error::add_error( |
|
1091 | - esc_html__( |
|
1092 | - 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
1093 | - 'event_espresso' |
|
1094 | - ), |
|
1095 | - __FILE__, |
|
1096 | - __FUNCTION__, |
|
1097 | - __LINE__ |
|
1098 | - ); |
|
1099 | - } |
|
1100 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1101 | - } |
|
1062 | + /** |
|
1063 | + * Deletes a single EE_Checkin row |
|
1064 | + * |
|
1065 | + * @return void |
|
1066 | + * @throws EE_Error |
|
1067 | + * @throws InvalidArgumentException |
|
1068 | + * @throws InvalidDataTypeException |
|
1069 | + * @throws InvalidInterfaceException |
|
1070 | + */ |
|
1071 | + protected function _delete_checkin_row() |
|
1072 | + { |
|
1073 | + $query_args = array( |
|
1074 | + 'action' => 'registration_checkins', |
|
1075 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
1076 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
1077 | + ); |
|
1078 | + if (! empty($this->_req_data['CHK_ID'])) { |
|
1079 | + if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
1080 | + EE_Error::add_error( |
|
1081 | + esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
1082 | + __FILE__, |
|
1083 | + __FUNCTION__, |
|
1084 | + __LINE__ |
|
1085 | + ); |
|
1086 | + } else { |
|
1087 | + EE_Error::add_success(esc_html__('Check-In record successfully deleted', 'event_espresso')); |
|
1088 | + } |
|
1089 | + } else { |
|
1090 | + EE_Error::add_error( |
|
1091 | + esc_html__( |
|
1092 | + 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
1093 | + 'event_espresso' |
|
1094 | + ), |
|
1095 | + __FILE__, |
|
1096 | + __FUNCTION__, |
|
1097 | + __LINE__ |
|
1098 | + ); |
|
1099 | + } |
|
1100 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1101 | + } |
|
1102 | 1102 | |
1103 | 1103 | |
1104 | - /** |
|
1105 | - * generates HTML for the Event Registrations List Table |
|
1106 | - * |
|
1107 | - * @access protected |
|
1108 | - * @return void |
|
1109 | - * @throws EE_Error |
|
1110 | - * @throws InvalidArgumentException |
|
1111 | - * @throws InvalidDataTypeException |
|
1112 | - * @throws InvalidInterfaceException |
|
1113 | - */ |
|
1114 | - protected function _event_registrations_list_table() |
|
1115 | - { |
|
1116 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1117 | - $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
1118 | - ? $this->get_action_link_or_button( |
|
1119 | - 'new_registration', |
|
1120 | - 'add-registrant', |
|
1121 | - array('event_id' => $this->_req_data['event_id']), |
|
1122 | - 'add-new-h2', |
|
1123 | - '', |
|
1124 | - false |
|
1125 | - ) |
|
1126 | - : ''; |
|
1127 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
1128 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
1129 | - $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
1130 | - $legend_items = array( |
|
1131 | - 'star-icon' => array( |
|
1132 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
1133 | - 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
1134 | - ), |
|
1135 | - 'checkin' => array( |
|
1136 | - 'class' => $checked_in->cssClasses(), |
|
1137 | - 'desc' => $checked_in->legendLabel(), |
|
1138 | - ), |
|
1139 | - 'checkout' => array( |
|
1140 | - 'class' => $checked_out->cssClasses(), |
|
1141 | - 'desc' => $checked_out->legendLabel(), |
|
1142 | - ), |
|
1143 | - 'nocheckinrecord' => array( |
|
1144 | - 'class' => $checked_never->cssClasses(), |
|
1145 | - 'desc' => $checked_never->legendLabel(), |
|
1146 | - ), |
|
1147 | - 'approved_status' => array( |
|
1148 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1149 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
1150 | - ), |
|
1151 | - 'cancelled_status' => array( |
|
1152 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1153 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
1154 | - ), |
|
1155 | - 'declined_status' => array( |
|
1156 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1157 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
1158 | - ), |
|
1159 | - 'not_approved' => array( |
|
1160 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1161 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
1162 | - ), |
|
1163 | - 'pending_status' => array( |
|
1164 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1165 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
1166 | - ), |
|
1167 | - 'wait_list' => array( |
|
1168 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1169 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
1170 | - ), |
|
1171 | - ); |
|
1172 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
1173 | - $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
1174 | - /** @var EE_Event $event */ |
|
1175 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
1176 | - $this->_template_args['before_list_table'] = $event instanceof EE_Event |
|
1177 | - ? '<h2>' . sprintf( |
|
1178 | - esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
1179 | - EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
1180 | - ) . '</h2>' |
|
1181 | - : ''; |
|
1182 | - // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
1183 | - // the event. |
|
1184 | - $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
1185 | - $datetime = null; |
|
1186 | - if ($event instanceof EE_Event) { |
|
1187 | - $datetimes_on_event = $event->datetimes(); |
|
1188 | - if (count($datetimes_on_event) === 1) { |
|
1189 | - $datetime = reset($datetimes_on_event); |
|
1190 | - } |
|
1191 | - } |
|
1192 | - $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1193 | - if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
1194 | - $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
1195 | - $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
1196 | - $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1197 | - $this->_template_args['before_list_table'] .= $datetime->name(); |
|
1198 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1199 | - $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
1200 | - } |
|
1201 | - // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
1202 | - // column represents |
|
1203 | - if (! $datetime instanceof EE_Datetime) { |
|
1204 | - $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
1205 | - . esc_html__( |
|
1206 | - 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
1207 | - 'event_espresso' |
|
1208 | - ) |
|
1209 | - . '</p>'; |
|
1210 | - } |
|
1211 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
1212 | - } |
|
1104 | + /** |
|
1105 | + * generates HTML for the Event Registrations List Table |
|
1106 | + * |
|
1107 | + * @access protected |
|
1108 | + * @return void |
|
1109 | + * @throws EE_Error |
|
1110 | + * @throws InvalidArgumentException |
|
1111 | + * @throws InvalidDataTypeException |
|
1112 | + * @throws InvalidInterfaceException |
|
1113 | + */ |
|
1114 | + protected function _event_registrations_list_table() |
|
1115 | + { |
|
1116 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1117 | + $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
1118 | + ? $this->get_action_link_or_button( |
|
1119 | + 'new_registration', |
|
1120 | + 'add-registrant', |
|
1121 | + array('event_id' => $this->_req_data['event_id']), |
|
1122 | + 'add-new-h2', |
|
1123 | + '', |
|
1124 | + false |
|
1125 | + ) |
|
1126 | + : ''; |
|
1127 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
1128 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
1129 | + $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
1130 | + $legend_items = array( |
|
1131 | + 'star-icon' => array( |
|
1132 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
1133 | + 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
1134 | + ), |
|
1135 | + 'checkin' => array( |
|
1136 | + 'class' => $checked_in->cssClasses(), |
|
1137 | + 'desc' => $checked_in->legendLabel(), |
|
1138 | + ), |
|
1139 | + 'checkout' => array( |
|
1140 | + 'class' => $checked_out->cssClasses(), |
|
1141 | + 'desc' => $checked_out->legendLabel(), |
|
1142 | + ), |
|
1143 | + 'nocheckinrecord' => array( |
|
1144 | + 'class' => $checked_never->cssClasses(), |
|
1145 | + 'desc' => $checked_never->legendLabel(), |
|
1146 | + ), |
|
1147 | + 'approved_status' => array( |
|
1148 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1149 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
1150 | + ), |
|
1151 | + 'cancelled_status' => array( |
|
1152 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1153 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
1154 | + ), |
|
1155 | + 'declined_status' => array( |
|
1156 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1157 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
1158 | + ), |
|
1159 | + 'not_approved' => array( |
|
1160 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1161 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
1162 | + ), |
|
1163 | + 'pending_status' => array( |
|
1164 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1165 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
1166 | + ), |
|
1167 | + 'wait_list' => array( |
|
1168 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1169 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
1170 | + ), |
|
1171 | + ); |
|
1172 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
1173 | + $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
1174 | + /** @var EE_Event $event */ |
|
1175 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
1176 | + $this->_template_args['before_list_table'] = $event instanceof EE_Event |
|
1177 | + ? '<h2>' . sprintf( |
|
1178 | + esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
1179 | + EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
1180 | + ) . '</h2>' |
|
1181 | + : ''; |
|
1182 | + // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
1183 | + // the event. |
|
1184 | + $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
1185 | + $datetime = null; |
|
1186 | + if ($event instanceof EE_Event) { |
|
1187 | + $datetimes_on_event = $event->datetimes(); |
|
1188 | + if (count($datetimes_on_event) === 1) { |
|
1189 | + $datetime = reset($datetimes_on_event); |
|
1190 | + } |
|
1191 | + } |
|
1192 | + $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1193 | + if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
1194 | + $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
1195 | + $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
1196 | + $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1197 | + $this->_template_args['before_list_table'] .= $datetime->name(); |
|
1198 | + $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1199 | + $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
1200 | + } |
|
1201 | + // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
1202 | + // column represents |
|
1203 | + if (! $datetime instanceof EE_Datetime) { |
|
1204 | + $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
1205 | + . esc_html__( |
|
1206 | + 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
1207 | + 'event_espresso' |
|
1208 | + ) |
|
1209 | + . '</p>'; |
|
1210 | + } |
|
1211 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
1212 | + } |
|
1213 | 1213 | |
1214 | - /** |
|
1215 | - * Download the registrations check-in report (same as the normal registration report, but with different where |
|
1216 | - * conditions) |
|
1217 | - * |
|
1218 | - * @return void ends the request by a redirect or download |
|
1219 | - */ |
|
1220 | - public function _registrations_checkin_report() |
|
1221 | - { |
|
1222 | - $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
1223 | - } |
|
1214 | + /** |
|
1215 | + * Download the registrations check-in report (same as the normal registration report, but with different where |
|
1216 | + * conditions) |
|
1217 | + * |
|
1218 | + * @return void ends the request by a redirect or download |
|
1219 | + */ |
|
1220 | + public function _registrations_checkin_report() |
|
1221 | + { |
|
1222 | + $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
1223 | + } |
|
1224 | 1224 | |
1225 | - /** |
|
1226 | - * Gets the query params from the request, plus adds a where condition for the registration status, |
|
1227 | - * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
1228 | - * |
|
1229 | - * @param array $request |
|
1230 | - * @param int $per_page |
|
1231 | - * @param bool $count |
|
1232 | - * @return array |
|
1233 | - * @throws EE_Error |
|
1234 | - */ |
|
1235 | - protected function _get_checkin_query_params_from_request( |
|
1236 | - $request, |
|
1237 | - $per_page = 10, |
|
1238 | - $count = false |
|
1239 | - ) { |
|
1240 | - $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
1241 | - // unlike the regular registrations list table, |
|
1242 | - $status_ids_array = apply_filters( |
|
1243 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
1244 | - array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
1245 | - ); |
|
1246 | - $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
1247 | - return $query_params; |
|
1248 | - } |
|
1225 | + /** |
|
1226 | + * Gets the query params from the request, plus adds a where condition for the registration status, |
|
1227 | + * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
1228 | + * |
|
1229 | + * @param array $request |
|
1230 | + * @param int $per_page |
|
1231 | + * @param bool $count |
|
1232 | + * @return array |
|
1233 | + * @throws EE_Error |
|
1234 | + */ |
|
1235 | + protected function _get_checkin_query_params_from_request( |
|
1236 | + $request, |
|
1237 | + $per_page = 10, |
|
1238 | + $count = false |
|
1239 | + ) { |
|
1240 | + $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
1241 | + // unlike the regular registrations list table, |
|
1242 | + $status_ids_array = apply_filters( |
|
1243 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
1244 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
1245 | + ); |
|
1246 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
1247 | + return $query_params; |
|
1248 | + } |
|
1249 | 1249 | |
1250 | 1250 | |
1251 | - /** |
|
1252 | - * Gets registrations for an event |
|
1253 | - * |
|
1254 | - * @param int $per_page |
|
1255 | - * @param bool $count whether to return count or data. |
|
1256 | - * @param bool $trash |
|
1257 | - * @param string $orderby |
|
1258 | - * @return EE_Registration[]|int |
|
1259 | - * @throws EE_Error |
|
1260 | - * @throws InvalidArgumentException |
|
1261 | - * @throws InvalidDataTypeException |
|
1262 | - * @throws InvalidInterfaceException |
|
1263 | - */ |
|
1264 | - public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
1265 | - { |
|
1266 | - // normalize some request params that get setup by the parent `get_registrations` method. |
|
1267 | - $request = $this->_req_data; |
|
1268 | - $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
1269 | - $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1270 | - if ($trash) { |
|
1271 | - $request['status'] = 'trash'; |
|
1272 | - } |
|
1273 | - $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
1274 | - /** |
|
1275 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1276 | - * |
|
1277 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1278 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1279 | - * or if you have the development copy of EE you can view this at the path: |
|
1280 | - * /docs/G--Model-System/model-query-params.md |
|
1281 | - */ |
|
1282 | - $query_params['group_by'] = ''; |
|
1251 | + /** |
|
1252 | + * Gets registrations for an event |
|
1253 | + * |
|
1254 | + * @param int $per_page |
|
1255 | + * @param bool $count whether to return count or data. |
|
1256 | + * @param bool $trash |
|
1257 | + * @param string $orderby |
|
1258 | + * @return EE_Registration[]|int |
|
1259 | + * @throws EE_Error |
|
1260 | + * @throws InvalidArgumentException |
|
1261 | + * @throws InvalidDataTypeException |
|
1262 | + * @throws InvalidInterfaceException |
|
1263 | + */ |
|
1264 | + public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
1265 | + { |
|
1266 | + // normalize some request params that get setup by the parent `get_registrations` method. |
|
1267 | + $request = $this->_req_data; |
|
1268 | + $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
1269 | + $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1270 | + if ($trash) { |
|
1271 | + $request['status'] = 'trash'; |
|
1272 | + } |
|
1273 | + $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
1274 | + /** |
|
1275 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1276 | + * |
|
1277 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1278 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1279 | + * or if you have the development copy of EE you can view this at the path: |
|
1280 | + * /docs/G--Model-System/model-query-params.md |
|
1281 | + */ |
|
1282 | + $query_params['group_by'] = ''; |
|
1283 | 1283 | |
1284 | - return $count |
|
1285 | - ? EEM_Registration::instance()->count($query_params) |
|
1286 | - /** @type EE_Registration[] */ |
|
1287 | - : EEM_Registration::instance()->get_all($query_params); |
|
1288 | - } |
|
1284 | + return $count |
|
1285 | + ? EEM_Registration::instance()->count($query_params) |
|
1286 | + /** @type EE_Registration[] */ |
|
1287 | + : EEM_Registration::instance()->get_all($query_params); |
|
1288 | + } |
|
1289 | 1289 | } |