|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
4
|
|
|
use EventEspresso\core\exceptions\InvalidInterfaceException; |
|
5
|
|
|
use EventEspresso\core\services\loaders\LoaderFactory; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Extend_Events_Admin_Page |
|
9
|
|
|
* This is the Events Caffeinated admin page. |
|
10
|
|
|
* |
|
11
|
|
|
* @package Extend_Events_Admin_Page |
|
12
|
|
|
* @subpackage includes/core/admin/Extend_Events_Admin_Page.core.php |
|
13
|
|
|
* @author Darren Ethier |
|
14
|
|
|
*/ |
|
15
|
|
|
class Extend_Events_Admin_Page extends Events_Admin_Page |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Extend_Events_Admin_Page constructor. |
|
21
|
|
|
* |
|
22
|
|
|
* @param bool $routing |
|
23
|
|
|
*/ |
|
24
|
|
View Code Duplication |
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
|
|
|
protected function _extend_page_config() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
41
|
|
|
// is there a evt_id in the request? |
|
42
|
|
|
$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
43
|
|
|
? $this->_req_data['EVT_ID'] |
|
44
|
|
|
: 0; |
|
45
|
|
|
$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
46
|
|
|
// tkt_id? |
|
47
|
|
|
$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
48
|
|
|
? $this->_req_data['TKT_ID'] |
|
49
|
|
|
: 0; |
|
50
|
|
|
$new_page_routes = array( |
|
51
|
|
|
'duplicate_event' => array( |
|
52
|
|
|
'func' => '_duplicate_event', |
|
53
|
|
|
'capability' => 'ee_edit_event', |
|
54
|
|
|
'obj_id' => $evt_id, |
|
55
|
|
|
'noheader' => true, |
|
56
|
|
|
), |
|
57
|
|
|
'ticket_list_table' => array( |
|
58
|
|
|
'func' => '_tickets_overview_list_table', |
|
59
|
|
|
'capability' => 'ee_read_default_tickets', |
|
60
|
|
|
), |
|
61
|
|
|
'trash_ticket' => array( |
|
62
|
|
|
'func' => '_trash_or_restore_ticket', |
|
63
|
|
|
'capability' => 'ee_delete_default_ticket', |
|
64
|
|
|
'obj_id' => $tkt_id, |
|
65
|
|
|
'noheader' => true, |
|
66
|
|
|
'args' => array('trash' => true), |
|
67
|
|
|
), |
|
68
|
|
|
'trash_tickets' => array( |
|
69
|
|
|
'func' => '_trash_or_restore_ticket', |
|
70
|
|
|
'capability' => 'ee_delete_default_tickets', |
|
71
|
|
|
'noheader' => true, |
|
72
|
|
|
'args' => array('trash' => true), |
|
73
|
|
|
), |
|
74
|
|
|
'restore_ticket' => array( |
|
75
|
|
|
'func' => '_trash_or_restore_ticket', |
|
76
|
|
|
'capability' => 'ee_delete_default_ticket', |
|
77
|
|
|
'obj_id' => $tkt_id, |
|
78
|
|
|
'noheader' => true, |
|
79
|
|
|
), |
|
80
|
|
|
'restore_tickets' => array( |
|
81
|
|
|
'func' => '_trash_or_restore_ticket', |
|
82
|
|
|
'capability' => 'ee_delete_default_tickets', |
|
83
|
|
|
'noheader' => true, |
|
84
|
|
|
), |
|
85
|
|
|
'delete_ticket' => array( |
|
86
|
|
|
'func' => '_delete_ticket', |
|
87
|
|
|
'capability' => 'ee_delete_default_ticket', |
|
88
|
|
|
'obj_id' => $tkt_id, |
|
89
|
|
|
'noheader' => true, |
|
90
|
|
|
), |
|
91
|
|
|
'delete_tickets' => array( |
|
92
|
|
|
'func' => '_delete_ticket', |
|
93
|
|
|
'capability' => 'ee_delete_default_tickets', |
|
94
|
|
|
'noheader' => true, |
|
95
|
|
|
), |
|
96
|
|
|
'import_page' => array( |
|
97
|
|
|
'func' => '_import_page', |
|
98
|
|
|
'capability' => 'import', |
|
99
|
|
|
), |
|
100
|
|
|
'import' => array( |
|
101
|
|
|
'func' => '_import_events', |
|
102
|
|
|
'capability' => 'import', |
|
103
|
|
|
'noheader' => true, |
|
104
|
|
|
), |
|
105
|
|
|
'import_events' => array( |
|
106
|
|
|
'func' => '_import_events', |
|
107
|
|
|
'capability' => 'import', |
|
108
|
|
|
'noheader' => true, |
|
109
|
|
|
), |
|
110
|
|
|
'export_events' => array( |
|
111
|
|
|
'func' => '_events_export', |
|
112
|
|
|
'capability' => 'export', |
|
113
|
|
|
'noheader' => true, |
|
114
|
|
|
), |
|
115
|
|
|
'export_categories' => array( |
|
116
|
|
|
'func' => '_categories_export', |
|
117
|
|
|
'capability' => 'export', |
|
118
|
|
|
'noheader' => true, |
|
119
|
|
|
), |
|
120
|
|
|
'sample_export_file' => array( |
|
121
|
|
|
'func' => '_sample_export_file', |
|
122
|
|
|
'capability' => 'export', |
|
123
|
|
|
'noheader' => true, |
|
124
|
|
|
), |
|
125
|
|
|
'update_template_settings' => array( |
|
126
|
|
|
'func' => '_update_template_settings', |
|
127
|
|
|
'capability' => 'manage_options', |
|
128
|
|
|
'noheader' => true, |
|
129
|
|
|
), |
|
130
|
|
|
); |
|
131
|
|
|
$this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
132
|
|
|
// partial route/config override |
|
133
|
|
|
$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
134
|
|
|
$this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
135
|
|
|
$this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
136
|
|
|
$this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
137
|
|
|
$this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
138
|
|
|
$this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
139
|
|
|
// add tickets tab but only if there are more than one default ticket! |
|
140
|
|
|
$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
141
|
|
|
array(array('TKT_is_default' => 1)), |
|
142
|
|
|
'TKT_ID', |
|
143
|
|
|
true |
|
144
|
|
|
); |
|
145
|
|
|
if ($tkt_count > 1) { |
|
146
|
|
|
$new_page_config = array( |
|
147
|
|
|
'ticket_list_table' => array( |
|
148
|
|
|
'nav' => array( |
|
149
|
|
|
'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
150
|
|
|
'order' => 60, |
|
151
|
|
|
), |
|
152
|
|
|
'list_table' => 'Tickets_List_Table', |
|
153
|
|
|
'require_nonce' => false, |
|
154
|
|
|
), |
|
155
|
|
|
); |
|
156
|
|
|
} |
|
157
|
|
|
// template settings |
|
158
|
|
|
$new_page_config['template_settings'] = array( |
|
159
|
|
|
'nav' => array( |
|
160
|
|
|
'label' => esc_html__('Templates', 'event_espresso'), |
|
161
|
|
|
'order' => 30, |
|
162
|
|
|
), |
|
163
|
|
|
'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
164
|
|
|
'help_tabs' => array( |
|
165
|
|
|
'general_settings_templates_help_tab' => array( |
|
166
|
|
|
'title' => esc_html__('Templates', 'event_espresso'), |
|
167
|
|
|
'filename' => 'general_settings_templates', |
|
168
|
|
|
), |
|
169
|
|
|
), |
|
170
|
|
|
'help_tour' => array('Templates_Help_Tour'), |
|
171
|
|
|
'require_nonce' => false, |
|
172
|
|
|
); |
|
173
|
|
|
$this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
174
|
|
|
// add filters and actions |
|
175
|
|
|
// modifying _views |
|
176
|
|
|
add_filter( |
|
177
|
|
|
'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
178
|
|
|
array($this, 'add_additional_datetime_button'), |
|
179
|
|
|
10, |
|
180
|
|
|
2 |
|
181
|
|
|
); |
|
182
|
|
|
add_filter( |
|
183
|
|
|
'FHEE_event_datetime_metabox_clone_button_template', |
|
184
|
|
|
array($this, 'add_datetime_clone_button'), |
|
185
|
|
|
10, |
|
186
|
|
|
2 |
|
187
|
|
|
); |
|
188
|
|
|
add_filter( |
|
189
|
|
|
'FHEE_event_datetime_metabox_timezones_template', |
|
190
|
|
|
array($this, 'datetime_timezones_template'), |
|
191
|
|
|
10, |
|
192
|
|
|
2 |
|
193
|
|
|
); |
|
194
|
|
|
// filters for event list table |
|
195
|
|
|
add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2); |
|
196
|
|
|
add_filter( |
|
197
|
|
|
'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
198
|
|
|
array($this, 'extra_list_table_actions'), |
|
199
|
|
|
10, |
|
200
|
|
|
2 |
|
201
|
|
|
); |
|
202
|
|
|
// legend item |
|
203
|
|
|
add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items')); |
|
204
|
|
|
add_action('admin_init', array($this, 'admin_init')); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* admin_init |
|
210
|
|
|
*/ |
|
211
|
|
|
public function admin_init() |
|
212
|
|
|
{ |
|
213
|
|
|
EE_Registry::$i18n_js_strings = array_merge( |
|
214
|
|
|
EE_Registry::$i18n_js_strings, |
|
215
|
|
|
array( |
|
216
|
|
|
'image_confirm' => esc_html__( |
|
217
|
|
|
'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
218
|
|
|
'event_espresso' |
|
219
|
|
|
), |
|
220
|
|
|
'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
221
|
|
|
'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
222
|
|
|
'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
223
|
|
|
'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
224
|
|
|
'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
225
|
|
|
) |
|
226
|
|
|
); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Add per page screen options to the default ticket list table view. |
|
232
|
|
|
*/ |
|
233
|
|
|
protected function _add_screen_options_ticket_list_table() |
|
234
|
|
|
{ |
|
235
|
|
|
$this->_per_page_screen_option(); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* @param string $return |
|
241
|
|
|
* @param int $id |
|
242
|
|
|
* @param string $new_title |
|
243
|
|
|
* @param string $new_slug |
|
244
|
|
|
* @return string |
|
245
|
|
|
*/ |
|
246
|
|
|
public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
247
|
|
|
{ |
|
248
|
|
|
$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
249
|
|
|
// make sure this is only when editing |
|
250
|
|
|
if (! empty($id)) { |
|
251
|
|
|
$href = EE_Admin_Page::add_query_args_and_nonce( |
|
252
|
|
|
array('action' => 'duplicate_event', 'EVT_ID' => $id), |
|
253
|
|
|
$this->_admin_base_url |
|
254
|
|
|
); |
|
255
|
|
|
$title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
256
|
|
|
$return .= '<a href="' |
|
257
|
|
|
. $href |
|
258
|
|
|
. '" title="' |
|
259
|
|
|
. $title |
|
260
|
|
|
. '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
261
|
|
|
. $title |
|
262
|
|
|
. '</a>'; |
|
263
|
|
|
} |
|
264
|
|
|
return $return; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* Set the list table views for the default ticket list table view. |
|
270
|
|
|
*/ |
|
271
|
|
View Code Duplication |
public function _set_list_table_views_ticket_list_table() |
|
272
|
|
|
{ |
|
273
|
|
|
$this->_views = array( |
|
274
|
|
|
'all' => array( |
|
275
|
|
|
'slug' => 'all', |
|
276
|
|
|
'label' => esc_html__('All', 'event_espresso'), |
|
277
|
|
|
'count' => 0, |
|
278
|
|
|
'bulk_action' => array( |
|
279
|
|
|
'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
280
|
|
|
), |
|
281
|
|
|
), |
|
282
|
|
|
'trashed' => array( |
|
283
|
|
|
'slug' => 'trashed', |
|
284
|
|
|
'label' => esc_html__('Trash', 'event_espresso'), |
|
285
|
|
|
'count' => 0, |
|
286
|
|
|
'bulk_action' => array( |
|
287
|
|
|
'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
288
|
|
|
'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
289
|
|
|
), |
|
290
|
|
|
), |
|
291
|
|
|
); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
|
|
295
|
|
|
/** |
|
296
|
|
|
* Enqueue scripts and styles for the event editor. |
|
297
|
|
|
*/ |
|
298
|
|
View Code Duplication |
public function load_scripts_styles_edit() |
|
299
|
|
|
{ |
|
300
|
|
|
wp_register_script( |
|
301
|
|
|
'ee-event-editor-heartbeat', |
|
302
|
|
|
EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
303
|
|
|
array('ee_admin_js', 'heartbeat'), |
|
304
|
|
|
EVENT_ESPRESSO_VERSION, |
|
305
|
|
|
true |
|
306
|
|
|
); |
|
307
|
|
|
wp_enqueue_script('ee-accounting'); |
|
308
|
|
|
// styles |
|
309
|
|
|
wp_enqueue_style('espresso-ui-theme'); |
|
310
|
|
|
wp_enqueue_script('event_editor_js'); |
|
311
|
|
|
wp_enqueue_script('ee-event-editor-heartbeat'); |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* Returns template for the additional datetime. |
|
317
|
|
|
* |
|
318
|
|
|
* @param $template |
|
319
|
|
|
* @param $template_args |
|
320
|
|
|
* @return mixed |
|
321
|
|
|
* @throws DomainException |
|
322
|
|
|
*/ |
|
323
|
|
|
public function add_additional_datetime_button($template, $template_args) |
|
324
|
|
|
{ |
|
325
|
|
|
return EEH_Template::display_template( |
|
326
|
|
|
EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
327
|
|
|
$template_args, |
|
328
|
|
|
true |
|
329
|
|
|
); |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
|
|
333
|
|
|
/** |
|
334
|
|
|
* Returns the template for cloning a datetime. |
|
335
|
|
|
* |
|
336
|
|
|
* @param $template |
|
337
|
|
|
* @param $template_args |
|
338
|
|
|
* @return mixed |
|
339
|
|
|
* @throws DomainException |
|
340
|
|
|
*/ |
|
341
|
|
|
public function add_datetime_clone_button($template, $template_args) |
|
342
|
|
|
{ |
|
343
|
|
|
return EEH_Template::display_template( |
|
344
|
|
|
EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
345
|
|
|
$template_args, |
|
346
|
|
|
true |
|
347
|
|
|
); |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* Returns the template for datetime timezones. |
|
353
|
|
|
* |
|
354
|
|
|
* @param $template |
|
355
|
|
|
* @param $template_args |
|
356
|
|
|
* @return mixed |
|
357
|
|
|
* @throws DomainException |
|
358
|
|
|
*/ |
|
359
|
|
|
public function datetime_timezones_template($template, $template_args) |
|
360
|
|
|
{ |
|
361
|
|
|
return EEH_Template::display_template( |
|
362
|
|
|
EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
363
|
|
|
$template_args, |
|
364
|
|
|
true |
|
365
|
|
|
); |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
|
|
369
|
|
|
/** |
|
370
|
|
|
* Sets the views for the default list table view. |
|
371
|
|
|
*/ |
|
372
|
|
|
protected function _set_list_table_views_default() |
|
373
|
|
|
{ |
|
374
|
|
|
parent::_set_list_table_views_default(); |
|
375
|
|
|
$new_views = array( |
|
376
|
|
|
'today' => array( |
|
377
|
|
|
'slug' => 'today', |
|
378
|
|
|
'label' => esc_html__('Today', 'event_espresso'), |
|
379
|
|
|
'count' => $this->total_events_today(), |
|
380
|
|
|
'bulk_action' => array( |
|
381
|
|
|
'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
382
|
|
|
), |
|
383
|
|
|
), |
|
384
|
|
|
'month' => array( |
|
385
|
|
|
'slug' => 'month', |
|
386
|
|
|
'label' => esc_html__('This Month', 'event_espresso'), |
|
387
|
|
|
'count' => $this->total_events_this_month(), |
|
388
|
|
|
'bulk_action' => array( |
|
389
|
|
|
'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
390
|
|
|
), |
|
391
|
|
|
), |
|
392
|
|
|
); |
|
393
|
|
|
$this->_views = array_merge($this->_views, $new_views); |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
|
|
397
|
|
|
/** |
|
398
|
|
|
* Returns the extra action links for the default list table view. |
|
399
|
|
|
* |
|
400
|
|
|
* @param array $action_links |
|
401
|
|
|
* @param \EE_Event $event |
|
402
|
|
|
* @return array |
|
403
|
|
|
* @throws EE_Error |
|
404
|
|
|
*/ |
|
405
|
|
|
public function extra_list_table_actions(array $action_links, \EE_Event $event) |
|
406
|
|
|
{ |
|
407
|
|
|
if (EE_Registry::instance()->CAP->current_user_can( |
|
408
|
|
|
'ee_read_registrations', |
|
409
|
|
|
'espresso_registrations_reports', |
|
410
|
|
|
$event->ID() |
|
411
|
|
|
) |
|
412
|
|
|
) { |
|
413
|
|
|
$reports_query_args = array( |
|
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
|
|
|
array('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 (EE_Registry::instance()->CAP->current_user_can( |
|
444
|
|
|
'ee_read_registrations', |
|
445
|
|
|
'espresso_registrations_reports' |
|
446
|
|
|
) |
|
447
|
|
|
) { |
|
448
|
|
|
$items['reports'] = array( |
|
449
|
|
|
'class' => 'dashicons dashicons-chart-bar', |
|
450
|
|
|
'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
451
|
|
|
); |
|
452
|
|
|
} |
|
453
|
|
View Code Duplication |
if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
454
|
|
|
$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
455
|
|
|
if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
456
|
|
|
$items['view_related_messages'] = array( |
|
457
|
|
|
'class' => $related_for_icon['css_class'], |
|
458
|
|
|
'desc' => $related_for_icon['label'], |
|
459
|
|
|
); |
|
460
|
|
|
} |
|
461
|
|
|
} |
|
462
|
|
|
return $items; |
|
463
|
|
|
} |
|
464
|
|
|
|
|
465
|
|
|
|
|
466
|
|
|
/** |
|
467
|
|
|
* This is the callback method for the duplicate event route |
|
468
|
|
|
* Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
469
|
|
|
* into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
470
|
|
|
* action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
471
|
|
|
* After duplication the redirect is to the new event edit page. |
|
472
|
|
|
* |
|
473
|
|
|
* @return void |
|
474
|
|
|
* @access protected |
|
475
|
|
|
* @throws EE_Error If EE_Event is not available with given ID |
|
476
|
|
|
*/ |
|
477
|
|
|
protected function _duplicate_event() |
|
478
|
|
|
{ |
|
479
|
|
|
// first make sure the ID for the event is in the request. |
|
480
|
|
|
// If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
481
|
|
View Code Duplication |
if (! isset($this->_req_data['EVT_ID'])) { |
|
482
|
|
|
EE_Error::add_error( |
|
483
|
|
|
esc_html__( |
|
484
|
|
|
'In order to duplicate an event an Event ID is required. None was given.', |
|
485
|
|
|
'event_espresso' |
|
486
|
|
|
), |
|
487
|
|
|
__FILE__, |
|
488
|
|
|
__FUNCTION__, |
|
489
|
|
|
__LINE__ |
|
490
|
|
|
); |
|
491
|
|
|
$this->_redirect_after_action(false, '', '', array(), true); |
|
492
|
|
|
return; |
|
493
|
|
|
} |
|
494
|
|
|
// k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
495
|
|
|
$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
496
|
|
|
if (! $orig_event instanceof EE_Event) { |
|
497
|
|
|
throw new EE_Error( |
|
498
|
|
|
sprintf( |
|
499
|
|
|
esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
500
|
|
|
$this->_req_data['EVT_ID'] |
|
501
|
|
|
) |
|
502
|
|
|
); |
|
503
|
|
|
} |
|
504
|
|
|
// k now let's clone the $orig_event before getting relations |
|
505
|
|
|
$new_event = clone $orig_event; |
|
506
|
|
|
// original datetimes |
|
507
|
|
|
$orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
508
|
|
|
// other original relations |
|
509
|
|
|
$orig_ven = $orig_event->get_many_related('Venue'); |
|
510
|
|
|
// reset the ID and modify other details to make it clear this is a dupe |
|
511
|
|
|
$new_event->set('EVT_ID', 0); |
|
512
|
|
|
$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
513
|
|
|
$new_event->set('EVT_name', $new_name); |
|
514
|
|
|
$new_event->set( |
|
515
|
|
|
'EVT_slug', |
|
516
|
|
|
wp_unique_post_slug( |
|
517
|
|
|
sanitize_title($orig_event->name()), |
|
518
|
|
|
0, |
|
519
|
|
|
'publish', |
|
520
|
|
|
'espresso_events', |
|
521
|
|
|
0 |
|
522
|
|
|
) |
|
523
|
|
|
); |
|
524
|
|
|
$new_event->set('status', 'draft'); |
|
525
|
|
|
// duplicate discussion settings |
|
526
|
|
|
$new_event->set('comment_status', $orig_event->get('comment_status')); |
|
527
|
|
|
$new_event->set('ping_status', $orig_event->get('ping_status')); |
|
528
|
|
|
// save the new event |
|
529
|
|
|
$new_event->save(); |
|
530
|
|
|
// venues |
|
531
|
|
|
foreach ($orig_ven as $ven) { |
|
532
|
|
|
$new_event->_add_relation_to($ven, 'Venue'); |
|
533
|
|
|
} |
|
534
|
|
|
$new_event->save(); |
|
535
|
|
|
// now we need to get the question group relations and handle that |
|
536
|
|
|
// first primary question groups |
|
537
|
|
|
$orig_primary_qgs = $orig_event->get_many_related( |
|
538
|
|
|
'Question_Group', |
|
539
|
|
|
[['Event_Question_Group.EQG_primary' => true]] |
|
540
|
|
|
); |
|
541
|
|
View Code Duplication |
if (! empty($orig_primary_qgs)) { |
|
542
|
|
|
foreach ($orig_primary_qgs as $id => $obj) { |
|
543
|
|
|
if ($obj instanceof EE_Question_Group) { |
|
544
|
|
|
$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]); |
|
545
|
|
|
} |
|
546
|
|
|
} |
|
547
|
|
|
} |
|
548
|
|
|
// next additional attendee question groups |
|
549
|
|
|
$orig_additional_qgs = $orig_event->get_many_related( |
|
550
|
|
|
'Question_Group', |
|
551
|
|
|
[['Event_Question_Group.EQG_additional' => true]] |
|
552
|
|
|
); |
|
553
|
|
View Code Duplication |
if (! empty($orig_additional_qgs)) { |
|
554
|
|
|
foreach ($orig_additional_qgs as $id => $obj) { |
|
555
|
|
|
if ($obj instanceof EE_Question_Group) { |
|
556
|
|
|
$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]); |
|
557
|
|
|
} |
|
558
|
|
|
} |
|
559
|
|
|
} |
|
560
|
|
|
|
|
561
|
|
|
$new_event->save(); |
|
562
|
|
|
|
|
563
|
|
|
// k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
564
|
|
|
$cloned_tickets = array(); |
|
565
|
|
|
foreach ($orig_datetimes as $orig_dtt) { |
|
566
|
|
|
if (! $orig_dtt instanceof EE_Datetime) { |
|
567
|
|
|
continue; |
|
568
|
|
|
} |
|
569
|
|
|
$new_dtt = clone $orig_dtt; |
|
570
|
|
|
$orig_tkts = $orig_dtt->tickets(); |
|
571
|
|
|
// save new dtt then add to event |
|
572
|
|
|
$new_dtt->set('DTT_ID', 0); |
|
573
|
|
|
$new_dtt->set('DTT_sold', 0); |
|
574
|
|
|
$new_dtt->set_reserved(0); |
|
575
|
|
|
$new_dtt->save(); |
|
576
|
|
|
$new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
577
|
|
|
$new_event->save(); |
|
578
|
|
|
// now let's get the ticket relations setup. |
|
579
|
|
|
foreach ((array) $orig_tkts as $orig_tkt) { |
|
580
|
|
|
// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
581
|
|
|
if (! $orig_tkt instanceof EE_Ticket) { |
|
582
|
|
|
continue; |
|
583
|
|
|
} |
|
584
|
|
|
// is this ticket archived? If it is then let's skip |
|
585
|
|
|
if ($orig_tkt->get('TKT_deleted')) { |
|
586
|
|
|
continue; |
|
587
|
|
|
} |
|
588
|
|
|
// does this original ticket already exist in the clone_tickets cache? |
|
589
|
|
|
// If so we'll just use the new ticket from it. |
|
590
|
|
|
if (isset($cloned_tickets[ $orig_tkt->ID() ])) { |
|
591
|
|
|
$new_tkt = $cloned_tickets[ $orig_tkt->ID() ]; |
|
592
|
|
|
} else { |
|
593
|
|
|
$new_tkt = clone $orig_tkt; |
|
594
|
|
|
// get relations on the $orig_tkt that we need to setup. |
|
595
|
|
|
$orig_prices = $orig_tkt->prices(); |
|
596
|
|
|
$new_tkt->set('TKT_ID', 0); |
|
597
|
|
|
$new_tkt->set('TKT_sold', 0); |
|
598
|
|
|
$new_tkt->set('TKT_reserved', 0); |
|
599
|
|
|
$new_tkt->save(); // make sure new ticket has ID. |
|
600
|
|
|
// price relations on new ticket need to be setup. |
|
601
|
|
|
foreach ($orig_prices as $orig_price) { |
|
602
|
|
|
$new_price = clone $orig_price; |
|
603
|
|
|
$new_price->set('PRC_ID', 0); |
|
604
|
|
|
$new_price->save(); |
|
605
|
|
|
$new_tkt->_add_relation_to($new_price, 'Price'); |
|
606
|
|
|
$new_tkt->save(); |
|
607
|
|
|
} |
|
608
|
|
|
|
|
609
|
|
|
do_action( |
|
610
|
|
|
'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after', |
|
611
|
|
|
$orig_tkt, |
|
612
|
|
|
$new_tkt, |
|
613
|
|
|
$orig_prices, |
|
614
|
|
|
$orig_event, |
|
615
|
|
|
$orig_dtt, |
|
616
|
|
|
$new_dtt |
|
617
|
|
|
); |
|
618
|
|
|
} |
|
619
|
|
|
// k now we can add the new ticket as a relation to the new datetime |
|
620
|
|
|
// and make sure its added to our cached $cloned_tickets array |
|
621
|
|
|
// for use with later datetimes that have the same ticket. |
|
622
|
|
|
$new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
623
|
|
|
$new_dtt->save(); |
|
624
|
|
|
$cloned_tickets[ $orig_tkt->ID() ] = $new_tkt; |
|
625
|
|
|
} |
|
626
|
|
|
} |
|
627
|
|
|
// clone taxonomy information |
|
628
|
|
|
$taxonomies_to_clone_with = apply_filters( |
|
629
|
|
|
'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
630
|
|
|
array('espresso_event_categories', 'espresso_event_type', 'post_tag') |
|
631
|
|
|
); |
|
632
|
|
|
// get terms for original event (notice) |
|
633
|
|
|
$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
634
|
|
|
// loop through terms and add them to new event. |
|
635
|
|
|
foreach ($orig_terms as $term) { |
|
636
|
|
|
wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
637
|
|
|
} |
|
638
|
|
|
|
|
639
|
|
|
// duplicate other core WP_Post items for this event. |
|
640
|
|
|
// post thumbnail (feature image). |
|
641
|
|
|
$feature_image_id = get_post_thumbnail_id($orig_event->ID()); |
|
642
|
|
|
if ($feature_image_id) { |
|
643
|
|
|
update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id); |
|
644
|
|
|
} |
|
645
|
|
|
|
|
646
|
|
|
// duplicate page_template setting |
|
647
|
|
|
$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true); |
|
648
|
|
|
if ($page_template) { |
|
649
|
|
|
update_post_meta($new_event->ID(), '_wp_page_template', $page_template); |
|
650
|
|
|
} |
|
651
|
|
|
|
|
652
|
|
|
do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
653
|
|
|
// now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
654
|
|
|
if ($new_event->ID()) { |
|
655
|
|
|
$redirect_args = array( |
|
656
|
|
|
'post' => $new_event->ID(), |
|
657
|
|
|
'action' => 'edit', |
|
658
|
|
|
); |
|
659
|
|
|
EE_Error::add_success( |
|
660
|
|
|
esc_html__( |
|
661
|
|
|
'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
662
|
|
|
'event_espresso' |
|
663
|
|
|
) |
|
664
|
|
|
); |
|
665
|
|
|
} else { |
|
666
|
|
|
$redirect_args = array( |
|
667
|
|
|
'action' => 'default', |
|
668
|
|
|
); |
|
669
|
|
|
EE_Error::add_error( |
|
670
|
|
|
esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
671
|
|
|
__FILE__, |
|
672
|
|
|
__FUNCTION__, |
|
673
|
|
|
__LINE__ |
|
674
|
|
|
); |
|
675
|
|
|
} |
|
676
|
|
|
$this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
677
|
|
|
} |
|
678
|
|
|
|
|
679
|
|
|
|
|
680
|
|
|
/** |
|
681
|
|
|
* Generates output for the import page. |
|
682
|
|
|
* |
|
683
|
|
|
* @throws DomainException |
|
684
|
|
|
*/ |
|
685
|
|
|
protected function _import_page() |
|
686
|
|
|
{ |
|
687
|
|
|
$title = esc_html__('Import', 'event_espresso'); |
|
688
|
|
|
$intro = esc_html__( |
|
689
|
|
|
'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
690
|
|
|
'event_espresso' |
|
691
|
|
|
); |
|
692
|
|
|
$form_url = EVENTS_ADMIN_URL; |
|
693
|
|
|
$action = 'import_events'; |
|
694
|
|
|
$type = 'csv'; |
|
695
|
|
|
$this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
696
|
|
|
$title, |
|
697
|
|
|
$intro, |
|
698
|
|
|
$form_url, |
|
699
|
|
|
$action, |
|
700
|
|
|
$type |
|
701
|
|
|
); |
|
702
|
|
|
$this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
703
|
|
|
array('action' => 'sample_export_file'), |
|
704
|
|
|
$this->_admin_base_url |
|
705
|
|
|
); |
|
706
|
|
|
$content = EEH_Template::display_template( |
|
707
|
|
|
EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
708
|
|
|
$this->_template_args, |
|
709
|
|
|
true |
|
710
|
|
|
); |
|
711
|
|
|
$this->_template_args['admin_page_content'] = $content; |
|
712
|
|
|
$this->display_admin_page_with_sidebar(); |
|
713
|
|
|
} |
|
714
|
|
|
|
|
715
|
|
|
|
|
716
|
|
|
/** |
|
717
|
|
|
* _import_events |
|
718
|
|
|
* This handles displaying the screen and running imports for importing events. |
|
719
|
|
|
* |
|
720
|
|
|
* @return void |
|
721
|
|
|
*/ |
|
722
|
|
|
protected function _import_events() |
|
723
|
|
|
{ |
|
724
|
|
|
require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
725
|
|
|
$success = EE_Import::instance()->import(); |
|
726
|
|
|
$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
|
727
|
|
|
} |
|
728
|
|
|
|
|
729
|
|
|
|
|
730
|
|
|
/** |
|
731
|
|
|
* _events_export |
|
732
|
|
|
* Will export all (or just the given event) to a Excel compatible file. |
|
733
|
|
|
* |
|
734
|
|
|
* @access protected |
|
735
|
|
|
* @return void |
|
736
|
|
|
*/ |
|
737
|
|
|
protected function _events_export() |
|
738
|
|
|
{ |
|
739
|
|
|
if (isset($this->_req_data['EVT_ID'])) { |
|
740
|
|
|
$event_ids = $this->_req_data['EVT_ID']; |
|
741
|
|
|
} elseif (isset($this->_req_data['EVT_IDs'])) { |
|
742
|
|
|
$event_ids = $this->_req_data['EVT_IDs']; |
|
743
|
|
|
} else { |
|
744
|
|
|
$event_ids = null; |
|
745
|
|
|
} |
|
746
|
|
|
// todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
747
|
|
|
$new_request_args = array( |
|
748
|
|
|
'export' => 'report', |
|
749
|
|
|
'action' => 'all_event_data', |
|
750
|
|
|
'EVT_ID' => $event_ids, |
|
751
|
|
|
); |
|
752
|
|
|
$this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
753
|
|
|
if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
754
|
|
|
require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
755
|
|
|
$EE_Export = EE_Export::instance($this->_req_data); |
|
756
|
|
|
$EE_Export->export(); |
|
757
|
|
|
} |
|
758
|
|
|
} |
|
759
|
|
|
|
|
760
|
|
|
|
|
761
|
|
|
/** |
|
762
|
|
|
* handle category exports() |
|
763
|
|
|
* |
|
764
|
|
|
* @return void |
|
765
|
|
|
*/ |
|
766
|
|
View Code Duplication |
protected function _categories_export() |
|
767
|
|
|
{ |
|
768
|
|
|
// todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
769
|
|
|
$new_request_args = array( |
|
770
|
|
|
'export' => 'report', |
|
771
|
|
|
'action' => 'categories', |
|
772
|
|
|
'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
773
|
|
|
); |
|
774
|
|
|
$this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
775
|
|
|
if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
776
|
|
|
require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
777
|
|
|
$EE_Export = EE_Export::instance($this->_req_data); |
|
778
|
|
|
$EE_Export->export(); |
|
779
|
|
|
} |
|
780
|
|
|
} |
|
781
|
|
|
|
|
782
|
|
|
|
|
783
|
|
|
/** |
|
784
|
|
|
* Creates a sample CSV file for importing |
|
785
|
|
|
*/ |
|
786
|
|
|
protected function _sample_export_file() |
|
787
|
|
|
{ |
|
788
|
|
|
// require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
789
|
|
|
EE_Export::instance()->export_sample(); |
|
790
|
|
|
} |
|
791
|
|
|
|
|
792
|
|
|
|
|
793
|
|
|
/************* Template Settings *************/ |
|
794
|
|
|
/** |
|
795
|
|
|
* Generates template settings page output |
|
796
|
|
|
* |
|
797
|
|
|
* @throws DomainException |
|
798
|
|
|
* @throws EE_Error |
|
799
|
|
|
*/ |
|
800
|
|
|
protected function _template_settings() |
|
801
|
|
|
{ |
|
802
|
|
|
$this->_template_args['values'] = $this->_yes_no_values; |
|
803
|
|
|
/** |
|
804
|
|
|
* Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
805
|
|
|
* from General_Settings_Admin_Page to here. |
|
806
|
|
|
*/ |
|
807
|
|
|
$this->_template_args = apply_filters( |
|
808
|
|
|
'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
809
|
|
|
$this->_template_args |
|
810
|
|
|
); |
|
811
|
|
|
$this->_set_add_edit_form_tags('update_template_settings'); |
|
812
|
|
|
$this->_set_publish_post_box_vars(null, false, false, null, false); |
|
813
|
|
|
$this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
814
|
|
|
EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
815
|
|
|
$this->_template_args, |
|
816
|
|
|
true |
|
817
|
|
|
); |
|
818
|
|
|
$this->display_admin_page_with_sidebar(); |
|
819
|
|
|
} |
|
820
|
|
|
|
|
821
|
|
|
|
|
822
|
|
|
/** |
|
823
|
|
|
* Handler for updating template settings. |
|
824
|
|
|
* |
|
825
|
|
|
* @throws InvalidInterfaceException |
|
826
|
|
|
* @throws InvalidDataTypeException |
|
827
|
|
|
* @throws InvalidArgumentException |
|
828
|
|
|
*/ |
|
829
|
|
|
protected function _update_template_settings() |
|
830
|
|
|
{ |
|
831
|
|
|
/** |
|
832
|
|
|
* Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
833
|
|
|
* from General_Settings_Admin_Page to here. |
|
834
|
|
|
*/ |
|
835
|
|
|
EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
836
|
|
|
'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
837
|
|
|
EE_Registry::instance()->CFG->template_settings, |
|
838
|
|
|
$this->_req_data |
|
839
|
|
|
); |
|
840
|
|
|
// update custom post type slugs and detect if we need to flush rewrite rules |
|
841
|
|
|
$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
842
|
|
|
EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
843
|
|
|
? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
844
|
|
|
: EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events'); |
|
845
|
|
|
$what = 'Template Settings'; |
|
846
|
|
|
$success = $this->_update_espresso_configuration( |
|
847
|
|
|
$what, |
|
848
|
|
|
EE_Registry::instance()->CFG->template_settings, |
|
849
|
|
|
__FILE__, |
|
850
|
|
|
__FUNCTION__, |
|
851
|
|
|
__LINE__ |
|
852
|
|
|
); |
|
853
|
|
|
if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
854
|
|
|
/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
855
|
|
|
$rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
856
|
|
|
'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
857
|
|
|
); |
|
858
|
|
|
$rewrite_rules->flush(); |
|
859
|
|
|
} |
|
860
|
|
|
$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings')); |
|
861
|
|
|
} |
|
862
|
|
|
|
|
863
|
|
|
|
|
864
|
|
|
/** |
|
865
|
|
|
* _premium_event_editor_meta_boxes |
|
866
|
|
|
* add all metaboxes related to the event_editor |
|
867
|
|
|
* |
|
868
|
|
|
* @access protected |
|
869
|
|
|
* @return void |
|
870
|
|
|
* @throws EE_Error |
|
871
|
|
|
*/ |
|
872
|
|
|
protected function _premium_event_editor_meta_boxes() |
|
873
|
|
|
{ |
|
874
|
|
|
$this->verify_cpt_object(); |
|
875
|
|
|
add_meta_box( |
|
876
|
|
|
'espresso_event_editor_event_options', |
|
877
|
|
|
esc_html__('Event Registration Options', 'event_espresso'), |
|
878
|
|
|
array($this, 'registration_options_meta_box'), |
|
879
|
|
|
$this->page_slug, |
|
880
|
|
|
'side', |
|
881
|
|
|
'core' |
|
882
|
|
|
); |
|
883
|
|
|
} |
|
884
|
|
|
|
|
885
|
|
|
|
|
886
|
|
|
/** |
|
887
|
|
|
* override caf metabox |
|
888
|
|
|
* |
|
889
|
|
|
* @return void |
|
890
|
|
|
* @throws DomainException |
|
891
|
|
|
*/ |
|
892
|
|
|
public function registration_options_meta_box() |
|
893
|
|
|
{ |
|
894
|
|
|
$yes_no_values = array( |
|
895
|
|
|
array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
896
|
|
|
array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
897
|
|
|
); |
|
898
|
|
|
$default_reg_status_values = EEM_Registration::reg_status_array( |
|
899
|
|
|
array( |
|
900
|
|
|
EEM_Registration::status_id_cancelled, |
|
901
|
|
|
EEM_Registration::status_id_declined, |
|
902
|
|
|
EEM_Registration::status_id_incomplete, |
|
903
|
|
|
EEM_Registration::status_id_wait_list, |
|
904
|
|
|
), |
|
905
|
|
|
true |
|
906
|
|
|
); |
|
907
|
|
|
$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
|
|
|
|
|
908
|
|
|
$template_args['_event'] = $this->_cpt_model_obj; |
|
909
|
|
|
$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
910
|
|
|
$template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
911
|
|
|
'default_reg_status', |
|
912
|
|
|
$default_reg_status_values, |
|
913
|
|
|
$this->_cpt_model_obj->default_registration_status() |
|
|
|
|
|
|
914
|
|
|
); |
|
915
|
|
|
$template_args['display_description'] = EEH_Form_Fields::select_input( |
|
916
|
|
|
'display_desc', |
|
917
|
|
|
$yes_no_values, |
|
918
|
|
|
$this->_cpt_model_obj->display_description() |
|
919
|
|
|
); |
|
920
|
|
|
$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
921
|
|
|
'display_ticket_selector', |
|
922
|
|
|
$yes_no_values, |
|
923
|
|
|
$this->_cpt_model_obj->display_ticket_selector(), |
|
924
|
|
|
'', |
|
925
|
|
|
'', |
|
926
|
|
|
false |
|
927
|
|
|
); |
|
928
|
|
|
$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
929
|
|
|
'EVT_default_registration_status', |
|
930
|
|
|
$default_reg_status_values, |
|
931
|
|
|
$this->_cpt_model_obj->default_registration_status() |
|
|
|
|
|
|
932
|
|
|
); |
|
933
|
|
|
$template_args['additional_registration_options'] = apply_filters( |
|
934
|
|
|
'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
935
|
|
|
'', |
|
936
|
|
|
$template_args, |
|
937
|
|
|
$yes_no_values, |
|
938
|
|
|
$default_reg_status_values |
|
939
|
|
|
); |
|
940
|
|
|
EEH_Template::display_template( |
|
941
|
|
|
EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
942
|
|
|
$template_args |
|
943
|
|
|
); |
|
944
|
|
|
} |
|
945
|
|
|
|
|
946
|
|
|
|
|
947
|
|
|
|
|
948
|
|
|
/** |
|
949
|
|
|
* wp_list_table_mods for caf |
|
950
|
|
|
* ============================ |
|
951
|
|
|
*/ |
|
952
|
|
|
/** |
|
953
|
|
|
* hook into list table filters and provide filters for caffeinated list table |
|
954
|
|
|
* |
|
955
|
|
|
* @param array $old_filters any existing filters present |
|
956
|
|
|
* @param array $list_table_obj the list table object |
|
957
|
|
|
* @return array new filters |
|
958
|
|
|
*/ |
|
959
|
|
|
public function list_table_filters($old_filters, $list_table_obj) |
|
960
|
|
|
{ |
|
961
|
|
|
$filters = array(); |
|
962
|
|
|
// first month/year filters |
|
963
|
|
|
$filters[] = $this->espresso_event_months_dropdown(); |
|
964
|
|
|
$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
965
|
|
|
// active status dropdown |
|
966
|
|
|
if ($status !== 'draft') { |
|
967
|
|
|
$filters[] = $this->active_status_dropdown( |
|
968
|
|
|
isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
969
|
|
|
); |
|
970
|
|
|
$filters[] = $this->venuesDropdown( |
|
971
|
|
|
isset($this->_req_data['venue']) ? $this->_req_data['venue'] : '' |
|
972
|
|
|
); |
|
973
|
|
|
} |
|
974
|
|
|
// category filter |
|
975
|
|
|
$filters[] = $this->category_dropdown(); |
|
976
|
|
|
return array_merge($old_filters, $filters); |
|
977
|
|
|
} |
|
978
|
|
|
|
|
979
|
|
|
|
|
980
|
|
|
/** |
|
981
|
|
|
* espresso_event_months_dropdown |
|
982
|
|
|
* |
|
983
|
|
|
* @access public |
|
984
|
|
|
* @return string dropdown listing month/year selections for events. |
|
985
|
|
|
*/ |
|
986
|
|
|
public function espresso_event_months_dropdown() |
|
987
|
|
|
{ |
|
988
|
|
|
// what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
989
|
|
|
// Note we need to include any other filters that are set! |
|
990
|
|
|
$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
991
|
|
|
// categories? |
|
992
|
|
|
$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
993
|
|
|
? $this->_req_data['EVT_CAT'] |
|
994
|
|
|
: null; |
|
995
|
|
|
// active status? |
|
996
|
|
|
$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
997
|
|
|
$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
998
|
|
|
return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
999
|
|
|
} |
|
1000
|
|
|
|
|
1001
|
|
|
|
|
1002
|
|
|
/** |
|
1003
|
|
|
* returns a list of "active" statuses on the event |
|
1004
|
|
|
* |
|
1005
|
|
|
* @param string $current_value whatever the current active status is |
|
1006
|
|
|
* @return string |
|
1007
|
|
|
*/ |
|
1008
|
|
|
public function active_status_dropdown($current_value = '') |
|
1009
|
|
|
{ |
|
1010
|
|
|
$select_name = 'active_status'; |
|
1011
|
|
|
$values = array( |
|
1012
|
|
|
'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
1013
|
|
|
'active' => esc_html__('Active', 'event_espresso'), |
|
1014
|
|
|
'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
1015
|
|
|
'expired' => esc_html__('Expired', 'event_espresso'), |
|
1016
|
|
|
'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
1017
|
|
|
); |
|
1018
|
|
|
|
|
1019
|
|
|
return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide'); |
|
1020
|
|
|
} |
|
1021
|
|
|
|
|
1022
|
|
|
/** |
|
1023
|
|
|
* returns a list of "venues" |
|
1024
|
|
|
* |
|
1025
|
|
|
* @param string $current_value whatever the current active status is |
|
1026
|
|
|
* @return string |
|
1027
|
|
|
*/ |
|
1028
|
|
|
protected function venuesDropdown($current_value = '') |
|
1029
|
|
|
{ |
|
1030
|
|
|
$select_name = 'venue'; |
|
1031
|
|
|
$values = array( |
|
1032
|
|
|
'' => esc_html__('All Venues', 'event_espresso'), |
|
1033
|
|
|
); |
|
1034
|
|
|
// populate the list of venues. |
|
1035
|
|
|
$venue_model = EE_Registry::instance()->load_model('Venue'); |
|
1036
|
|
|
$venues = $venue_model->get_all(array('order_by' => array('VNU_name' => 'ASC'))); |
|
1037
|
|
|
|
|
1038
|
|
|
foreach ($venues as $venue) { |
|
1039
|
|
|
$values[ $venue->ID() ] = $venue->name(); |
|
1040
|
|
|
} |
|
1041
|
|
|
|
|
1042
|
|
|
return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide'); |
|
1043
|
|
|
} |
|
1044
|
|
|
|
|
1045
|
|
|
|
|
1046
|
|
|
/** |
|
1047
|
|
|
* output a dropdown of the categories for the category filter on the event admin list table |
|
1048
|
|
|
* |
|
1049
|
|
|
* @access public |
|
1050
|
|
|
* @return string html |
|
1051
|
|
|
*/ |
|
1052
|
|
|
public function category_dropdown() |
|
1053
|
|
|
{ |
|
1054
|
|
|
$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
1055
|
|
|
return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
1056
|
|
|
} |
|
1057
|
|
|
|
|
1058
|
|
|
|
|
1059
|
|
|
/** |
|
1060
|
|
|
* get total number of events today |
|
1061
|
|
|
* |
|
1062
|
|
|
* @access public |
|
1063
|
|
|
* @return int |
|
1064
|
|
|
* @throws EE_Error |
|
1065
|
|
|
*/ |
|
1066
|
|
|
public function total_events_today() |
|
1067
|
|
|
{ |
|
1068
|
|
|
$start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1069
|
|
|
'DTT_EVT_start', |
|
1070
|
|
|
date('Y-m-d') . ' 00:00:00', |
|
1071
|
|
|
'Y-m-d H:i:s', |
|
1072
|
|
|
'UTC' |
|
1073
|
|
|
); |
|
1074
|
|
|
$end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1075
|
|
|
'DTT_EVT_start', |
|
1076
|
|
|
date('Y-m-d') . ' 23:59:59', |
|
1077
|
|
|
'Y-m-d H:i:s', |
|
1078
|
|
|
'UTC' |
|
1079
|
|
|
); |
|
1080
|
|
|
$where = array( |
|
1081
|
|
|
'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1082
|
|
|
); |
|
1083
|
|
|
$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1084
|
|
|
return $count; |
|
1085
|
|
|
} |
|
1086
|
|
|
|
|
1087
|
|
|
|
|
1088
|
|
|
/** |
|
1089
|
|
|
* get total number of events this month |
|
1090
|
|
|
* |
|
1091
|
|
|
* @access public |
|
1092
|
|
|
* @return int |
|
1093
|
|
|
* @throws EE_Error |
|
1094
|
|
|
*/ |
|
1095
|
|
|
public function total_events_this_month() |
|
1096
|
|
|
{ |
|
1097
|
|
|
// Dates |
|
1098
|
|
|
$this_year_r = date('Y'); |
|
1099
|
|
|
$this_month_r = date('m'); |
|
1100
|
|
|
$days_this_month = date('t'); |
|
1101
|
|
|
$start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1102
|
|
|
'DTT_EVT_start', |
|
1103
|
|
|
$this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
1104
|
|
|
'Y-m-d H:i:s', |
|
1105
|
|
|
'UTC' |
|
1106
|
|
|
); |
|
1107
|
|
|
$end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1108
|
|
|
'DTT_EVT_start', |
|
1109
|
|
|
$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
1110
|
|
|
'Y-m-d H:i:s', |
|
1111
|
|
|
'UTC' |
|
1112
|
|
|
); |
|
1113
|
|
|
$where = array( |
|
1114
|
|
|
'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1115
|
|
|
); |
|
1116
|
|
|
$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1117
|
|
|
return $count; |
|
1118
|
|
|
} |
|
1119
|
|
|
|
|
1120
|
|
|
|
|
1121
|
|
|
/** DEFAULT TICKETS STUFF **/ |
|
1122
|
|
|
|
|
1123
|
|
|
/** |
|
1124
|
|
|
* Output default tickets list table view. |
|
1125
|
|
|
*/ |
|
1126
|
|
|
public function _tickets_overview_list_table() |
|
1127
|
|
|
{ |
|
1128
|
|
|
$this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
1129
|
|
|
$this->display_admin_list_table_page_with_no_sidebar(); |
|
1130
|
|
|
} |
|
1131
|
|
|
|
|
1132
|
|
|
|
|
1133
|
|
|
/** |
|
1134
|
|
|
* @param int $per_page |
|
1135
|
|
|
* @param bool $count |
|
1136
|
|
|
* @param bool $trashed |
|
1137
|
|
|
* @return \EE_Soft_Delete_Base_Class[]|int |
|
1138
|
|
|
*/ |
|
1139
|
|
View Code Duplication |
public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
1140
|
|
|
{ |
|
1141
|
|
|
$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
1142
|
|
|
$order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
1143
|
|
|
switch ($orderby) { |
|
1144
|
|
|
case 'TKT_name': |
|
1145
|
|
|
$orderby = array('TKT_name' => $order); |
|
1146
|
|
|
break; |
|
1147
|
|
|
case 'TKT_price': |
|
1148
|
|
|
$orderby = array('TKT_price' => $order); |
|
1149
|
|
|
break; |
|
1150
|
|
|
case 'TKT_uses': |
|
1151
|
|
|
$orderby = array('TKT_uses' => $order); |
|
1152
|
|
|
break; |
|
1153
|
|
|
case 'TKT_min': |
|
1154
|
|
|
$orderby = array('TKT_min' => $order); |
|
1155
|
|
|
break; |
|
1156
|
|
|
case 'TKT_max': |
|
1157
|
|
|
$orderby = array('TKT_max' => $order); |
|
1158
|
|
|
break; |
|
1159
|
|
|
case 'TKT_qty': |
|
1160
|
|
|
$orderby = array('TKT_qty' => $order); |
|
1161
|
|
|
break; |
|
1162
|
|
|
} |
|
1163
|
|
|
$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
1164
|
|
|
? $this->_req_data['paged'] |
|
1165
|
|
|
: 1; |
|
1166
|
|
|
$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
1167
|
|
|
? $this->_req_data['perpage'] |
|
1168
|
|
|
: $per_page; |
|
1169
|
|
|
$_where = array( |
|
1170
|
|
|
'TKT_is_default' => 1, |
|
1171
|
|
|
'TKT_deleted' => $trashed, |
|
1172
|
|
|
); |
|
1173
|
|
|
$offset = ($current_page - 1) * $per_page; |
|
1174
|
|
|
$limit = array($offset, $per_page); |
|
1175
|
|
|
if (isset($this->_req_data['s'])) { |
|
1176
|
|
|
$sstr = '%' . $this->_req_data['s'] . '%'; |
|
1177
|
|
|
$_where['OR'] = array( |
|
1178
|
|
|
'TKT_name' => array('LIKE', $sstr), |
|
1179
|
|
|
'TKT_description' => array('LIKE', $sstr), |
|
1180
|
|
|
); |
|
1181
|
|
|
} |
|
1182
|
|
|
$query_params = array( |
|
1183
|
|
|
$_where, |
|
1184
|
|
|
'order_by' => $orderby, |
|
1185
|
|
|
'limit' => $limit, |
|
1186
|
|
|
'group_by' => 'TKT_ID', |
|
1187
|
|
|
); |
|
1188
|
|
|
if ($count) { |
|
1189
|
|
|
return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where)); |
|
1190
|
|
|
} else { |
|
1191
|
|
|
return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
1192
|
|
|
} |
|
1193
|
|
|
} |
|
1194
|
|
|
|
|
1195
|
|
|
|
|
1196
|
|
|
/** |
|
1197
|
|
|
* @param bool $trash |
|
1198
|
|
|
* @throws EE_Error |
|
1199
|
|
|
*/ |
|
1200
|
|
|
protected function _trash_or_restore_ticket($trash = false) |
|
1201
|
|
|
{ |
|
1202
|
|
|
$success = 1; |
|
1203
|
|
|
$TKT = EEM_Ticket::instance(); |
|
1204
|
|
|
// checkboxes? |
|
1205
|
|
View Code Duplication |
if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1206
|
|
|
// if array has more than one element then success message should be plural |
|
1207
|
|
|
$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1208
|
|
|
// cycle thru the boxes |
|
1209
|
|
|
while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
|
|
|
|
|
1210
|
|
|
if ($trash) { |
|
1211
|
|
|
if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1212
|
|
|
$success = 0; |
|
1213
|
|
|
} |
|
1214
|
|
|
} else { |
|
1215
|
|
|
if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1216
|
|
|
$success = 0; |
|
1217
|
|
|
} |
|
1218
|
|
|
} |
|
1219
|
|
|
} |
|
1220
|
|
|
} else { |
|
1221
|
|
|
// grab single id and trash |
|
1222
|
|
|
$TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1223
|
|
|
if ($trash) { |
|
1224
|
|
|
if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1225
|
|
|
$success = 0; |
|
1226
|
|
|
} |
|
1227
|
|
|
} else { |
|
1228
|
|
|
if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1229
|
|
|
$success = 0; |
|
1230
|
|
|
} |
|
1231
|
|
|
} |
|
1232
|
|
|
} |
|
1233
|
|
|
$action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
1234
|
|
|
$query_args = array( |
|
1235
|
|
|
'action' => 'ticket_list_table', |
|
1236
|
|
|
'status' => $trash ? '' : 'trashed', |
|
1237
|
|
|
); |
|
1238
|
|
|
$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1239
|
|
|
} |
|
1240
|
|
|
|
|
1241
|
|
|
|
|
1242
|
|
|
/** |
|
1243
|
|
|
* Handles trashing default ticket. |
|
1244
|
|
|
*/ |
|
1245
|
|
|
protected function _delete_ticket() |
|
1246
|
|
|
{ |
|
1247
|
|
|
$success = 1; |
|
1248
|
|
|
// checkboxes? |
|
1249
|
|
View Code Duplication |
if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1250
|
|
|
// if array has more than one element then success message should be plural |
|
1251
|
|
|
$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1252
|
|
|
// cycle thru the boxes |
|
1253
|
|
|
while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
|
|
|
|
|
1254
|
|
|
// delete |
|
1255
|
|
|
if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1256
|
|
|
$success = 0; |
|
1257
|
|
|
} |
|
1258
|
|
|
} |
|
1259
|
|
|
} else { |
|
1260
|
|
|
// grab single id and trash |
|
1261
|
|
|
$TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1262
|
|
|
if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1263
|
|
|
$success = 0; |
|
1264
|
|
|
} |
|
1265
|
|
|
} |
|
1266
|
|
|
$action_desc = 'deleted'; |
|
1267
|
|
|
$query_args = array( |
|
1268
|
|
|
'action' => 'ticket_list_table', |
|
1269
|
|
|
'status' => 'trashed', |
|
1270
|
|
|
); |
|
1271
|
|
|
// fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
1272
|
|
|
if (EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
1273
|
|
|
array(array('TKT_is_default' => 1)), |
|
1274
|
|
|
'TKT_ID', |
|
1275
|
|
|
true |
|
1276
|
|
|
) |
|
1277
|
|
|
) { |
|
1278
|
|
|
$query_args = array(); |
|
1279
|
|
|
} |
|
1280
|
|
|
$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1281
|
|
|
} |
|
1282
|
|
|
|
|
1283
|
|
|
|
|
1284
|
|
|
/** |
|
1285
|
|
|
* @param int $TKT_ID |
|
1286
|
|
|
* @return bool|int |
|
1287
|
|
|
* @throws EE_Error |
|
1288
|
|
|
*/ |
|
1289
|
|
|
protected function _delete_the_ticket($TKT_ID) |
|
1290
|
|
|
{ |
|
1291
|
|
|
$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
1292
|
|
|
$tkt->_remove_relations('Datetime'); |
|
1293
|
|
|
// delete all related prices first |
|
1294
|
|
|
$tkt->delete_related_permanently('Price'); |
|
1295
|
|
|
return $tkt->delete_permanently(); |
|
1296
|
|
|
} |
|
1297
|
|
|
} |
|
1298
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.