Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Venues_Admin_Page often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Venues_Admin_Page, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | class Venues_Admin_Page extends EE_Admin_Page_CPT { |
||
31 | |||
32 | |||
33 | /** |
||
34 | * _venue |
||
35 | * This will hold the venue object for venue_details screen. |
||
36 | * |
||
37 | * @access protected |
||
38 | * @var object |
||
39 | */ |
||
40 | protected $_venue; |
||
41 | |||
42 | |||
43 | |||
44 | |||
45 | /** |
||
46 | * This will hold the category object for category_details screen. |
||
47 | * @var object |
||
48 | */ |
||
49 | protected $_category; |
||
50 | |||
51 | |||
52 | |||
53 | |||
54 | /** |
||
55 | * This property will hold the venue model instance |
||
56 | * @var object |
||
57 | */ |
||
58 | protected $_venue_model; |
||
59 | |||
60 | |||
61 | |||
62 | |||
63 | |||
64 | protected function _init_page_props() { |
||
65 | require_once( EE_MODELS . 'EEM_Venue.model.php' ); |
||
66 | $this->page_slug = EE_VENUES_PG_SLUG; |
||
67 | $this->_admin_base_url = EE_VENUES_ADMIN_URL; |
||
68 | $this->_admin_base_path = EE_ADMIN_PAGES . 'venues'; |
||
69 | $this->page_label = __('Event Venues', 'event_espresso'); |
||
70 | $this->_cpt_model_names = array( |
||
|
|||
71 | 'create_new' => 'EEM_Venue', |
||
72 | 'edit' => 'EEM_Venue' |
||
73 | ); |
||
74 | $this->_cpt_edit_routes = array( |
||
75 | 'espresso_venues' => 'edit' |
||
76 | ); |
||
77 | $this->_venue_model = EEM_Venue::instance(); |
||
78 | } |
||
79 | |||
80 | |||
81 | |||
82 | |||
83 | protected function _ajax_hooks() { |
||
86 | |||
87 | |||
88 | |||
89 | |||
90 | |||
91 | |||
92 | View Code Duplication | protected function _define_page_props() { |
|
93 | $this->_admin_page_title = $this->page_label; |
||
94 | $this->_labels = array( |
||
95 | 'buttons' => array( |
||
96 | 'add' => __('Add New Venue', 'event_espresso'), |
||
97 | 'edit' => __('Edit Venue', 'event_espresso'), |
||
98 | 'delete' => __('Delete Venue', 'event_espresso'), |
||
99 | 'add_category' => __('Add New Category', 'event_espresso'), |
||
100 | 'edit_category' => __('Edit Category', 'event_espresso'), |
||
101 | 'delete_category' => __('Delete Category', 'event_espresso') |
||
102 | ), |
||
103 | 'editor_title' => array( |
||
104 | 'espresso_venues' => __('Enter Venue name here') |
||
105 | ), |
||
106 | 'publishbox' => array( |
||
107 | 'create_new' => __('Save New Venue', 'event_espresso'), |
||
108 | 'edit' => __('Update Venue', 'event_espresso'), |
||
109 | 'add_category' => __('Save New Category', 'event_espresso'), |
||
110 | 'edit_category' => __('Update Category', 'event_espresso'), |
||
111 | 'google_map_settings' => __( 'Update Settings', 'event_espresso' ) |
||
112 | ) |
||
113 | ); |
||
114 | } |
||
115 | |||
116 | |||
117 | |||
118 | |||
119 | |||
120 | protected function _set_page_routes() { |
||
121 | |||
122 | //load formatter helper |
||
123 | EE_Registry::instance()->load_helper( 'Formatter' ); |
||
124 | //load field generator helper |
||
125 | EE_Registry::instance()->load_helper( 'Form_Fields' ); |
||
126 | |||
127 | //is there a vnu_id in the request? |
||
128 | $vnu_id = ! empty( $this->_req_data['VNU_ID'] ) && ! is_array( $this->_req_data['VNU_ID'] ) ? $this->_req_data['VNU_ID'] : 0; |
||
129 | $vnu_id = ! empty( $this->_req_data['post'] ) ? $this->_req_data['post'] : $vnu_id; |
||
130 | |||
131 | $this->_page_routes = array( |
||
132 | 'default' => array( |
||
133 | 'func' => '_overview_list_table', |
||
134 | 'capability' => 'ee_read_venues' |
||
135 | ), |
||
136 | 'create_new' => array( |
||
137 | 'func' => '_create_new_cpt_item', |
||
138 | 'capability' => 'ee_edit_venues' |
||
139 | ), |
||
140 | 'edit' => array( |
||
141 | 'func' => '_edit_cpt_item', |
||
142 | 'capability' => 'ee_edit_venue', |
||
143 | 'obj_id' => $vnu_id |
||
144 | ), |
||
145 | 'trash_venue' => array( |
||
146 | 'func' => '_trash_or_restore_venue', |
||
147 | 'args' => array( 'venue_status' => 'trash' ), |
||
148 | 'noheader' => TRUE, |
||
149 | 'capability' => 'ee_delete_venue', |
||
150 | 'obj_id' => $vnu_id |
||
151 | ), |
||
152 | 'trash_venues' => array( |
||
153 | 'func' => '_trash_or_restore_venues', |
||
154 | 'args' => array( 'venue_status' => 'trash' ), |
||
155 | 'noheader' => TRUE, |
||
156 | 'capability' => 'ee_delete_venues' |
||
157 | ), |
||
158 | 'restore_venue' => array( |
||
159 | 'func' => '_trash_or_restore_venue', |
||
160 | 'args' => array( 'venue_status' => 'draft' ), |
||
161 | 'noheader' => TRUE, |
||
162 | 'capability' => 'ee_delete_venue', |
||
163 | 'obj_id' => $vnu_id |
||
164 | ), |
||
165 | 'restore_venues' => array( |
||
166 | 'func' => '_trash_or_restore_venues', |
||
167 | 'args' => array( 'venue_status' => 'draft' ), |
||
168 | 'noheader' => TRUE, |
||
169 | 'capability' => 'ee_delete_venues' |
||
170 | ), |
||
171 | 'delete_venues' => array( |
||
172 | 'func' => '_delete_venues', |
||
173 | 'noheader' => TRUE, |
||
174 | 'capability' => 'ee_delete_venues' |
||
175 | ), |
||
176 | 'delete_venue' => array( |
||
177 | 'func' => '_delete_venue', |
||
178 | 'noheader' => TRUE, |
||
179 | 'capability' => 'ee_delete_venue', |
||
180 | 'obj_id' => $vnu_id |
||
181 | ), |
||
182 | //settings related |
||
183 | 'google_map_settings' => array( |
||
184 | 'func' => '_google_map_settings', |
||
185 | 'capability' => 'manage_options' |
||
186 | ), |
||
187 | 'update_google_map_settings' => array( |
||
188 | 'func' => '_update_google_map_settings', |
||
189 | 'capability' => 'manage_options', |
||
190 | 'noheader' => TRUE |
||
191 | ), |
||
192 | //venue category tab related |
||
193 | 'add_category' => array( |
||
194 | 'func' => '_category_details', |
||
195 | 'args' => array('add'), |
||
196 | 'capability' => 'ee_edit_venue_category' |
||
197 | ), |
||
198 | 'edit_category' => array( |
||
199 | 'func' => '_category_details', |
||
200 | 'args' => array('edit'), |
||
201 | 'capability' => 'ee_edit_venue_category' |
||
202 | ), |
||
203 | 'delete_categories' => array( |
||
204 | 'func' => '_delete_categories', |
||
205 | 'noheader' => TRUE, |
||
206 | 'capability' => 'ee_delete_venue_category' |
||
207 | ), |
||
208 | |||
209 | 'delete_category' => array( |
||
210 | 'func' => '_delete_categories', |
||
211 | 'noheader' => TRUE, |
||
212 | 'capability' => 'ee_delete_venue_category' |
||
213 | ), |
||
214 | |||
215 | 'insert_category' => array( |
||
216 | 'func' => '_insert_or_update_category', |
||
217 | 'args' => array('new_category' => TRUE), |
||
218 | 'noheader' => TRUE, |
||
219 | 'capability' => 'ee_edit_venue_category' |
||
220 | ), |
||
221 | |||
222 | 'update_category' => array( |
||
223 | 'func' => '_insert_or_update_category', |
||
224 | 'args' => array('new_category' => FALSE), |
||
225 | 'noheader' => TRUE, |
||
226 | 'capability' => 'ee_edit_venue_category' |
||
227 | ), |
||
228 | 'export_categories' => array( |
||
229 | 'func' => '_categories_export', |
||
230 | 'noheader' => TRUE, |
||
231 | 'capability' => 'export' |
||
232 | ), |
||
233 | 'import_categories' => array( |
||
234 | 'func' => '_import_categories', |
||
235 | 'capability' => 'import' |
||
236 | ), |
||
237 | 'category_list' => array( |
||
238 | 'func' => '_category_list_table', |
||
239 | 'capability' => 'ee_manage_venue_categories' |
||
240 | ) |
||
241 | ); |
||
242 | } |
||
243 | |||
244 | |||
245 | |||
246 | |||
247 | protected function _set_page_config() { |
||
248 | $this->_page_config = array( |
||
249 | 'default' => array( |
||
250 | 'nav' => array( |
||
251 | 'label' => __('Overview', 'event_espresso'), |
||
252 | 'order' => 10 |
||
253 | ), |
||
254 | 'list_table' => 'Venues_Admin_List_Table', |
||
255 | 'help_tabs' => array( |
||
256 | 'venues_overview_help_tab' => array( |
||
257 | 'title' => __('Venues Overview', 'event_espresso'), |
||
258 | 'filename' => 'venues_overview' |
||
259 | ), |
||
260 | 'venues_overview_table_column_headings_help_tab' => array( |
||
261 | 'title' => __('Venues Overview Table Column Headings', 'event_espresso'), |
||
262 | 'filename' => 'venues_overview_table_column_headings' |
||
263 | ), |
||
264 | 'venues_overview_views_bulk_actions_search_help_tab' => array( |
||
265 | 'title' => __('Venues Overview Views & Bulk Actions & Search', 'event_espresso'), |
||
266 | 'filename' => 'venues_overview_views_bulk_actions_search' |
||
267 | ) |
||
268 | ), |
||
269 | 'help_tour' => array( 'Venues_Overview_Help_Tour' ), |
||
270 | 'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'), |
||
271 | 'require_nonce' => FALSE |
||
272 | ), |
||
273 | 'create_new' => array( |
||
274 | 'nav' => array( |
||
275 | 'label' => __('Add Venue', 'event_espresso'), |
||
276 | 'order' => 5, |
||
277 | 'persistent' => FALSE |
||
278 | ), |
||
279 | 'help_tabs' => array( |
||
280 | 'venues_editor_help_tab' => array( |
||
281 | 'title' => __('Venue Editor', 'event_espresso'), |
||
282 | 'filename' => 'venues_editor' |
||
283 | ), |
||
284 | 'venues_editor_title_richtexteditor_help_tab' => array( |
||
285 | 'title' => __('Venue Title & Rich Text Editor', 'event_espresso'), |
||
286 | 'filename' => 'venues_editor_title_richtexteditor' |
||
287 | ), |
||
288 | 'venues_editor_tags_categories_help_tab' => array( |
||
289 | 'title' => __('Venue Tags & Categories', 'event_espresso'), |
||
290 | 'filename' => 'venues_editor_tags_categories' |
||
291 | ), |
||
292 | 'venues_editor_physical_location_google_map_virtual_location_help_tab' => array( |
||
293 | 'title' => __('Venue Editor Physical Location & Google Map & Virtual Location', 'event_espresso'), |
||
294 | 'filename' => 'venues_editor_physical_location_google_map_virtual_location' |
||
295 | ), |
||
296 | 'venues_editor_save_new_venue_help_tab' => array( |
||
297 | 'title' => __('Save New Venue', 'event_espresso'), |
||
298 | 'filename' => 'venues_editor_save_new_venue' |
||
299 | ), |
||
300 | 'venues_editor_other_help_tab' => array( |
||
301 | 'title' => __('Venue Editor Other', 'event_espresso'), |
||
302 | 'filename' => 'venues_editor_other' |
||
303 | ) |
||
304 | ), |
||
305 | 'help_tour' => array( 'Venues_Add_Venue_Help_Tour' ), |
||
306 | 'metaboxes' => array('_venue_editor_metaboxes'), |
||
307 | 'require_nonce' => FALSE |
||
308 | ), |
||
309 | 'edit' => array( |
||
310 | 'nav' => array( |
||
311 | 'label' => __('Edit Venue', 'event_espresso'), |
||
312 | 'order' => 5, |
||
313 | 'persistent' => FALSE, |
||
314 | 'url' => isset($this->_req_data['post']) ? add_query_arg(array('post' => $this->_req_data['post'] ), $this->_current_page_view_url ) : $this->_admin_base_url |
||
315 | ), |
||
316 | 'help_tabs' => array( |
||
317 | 'venues_editor_help_tab' => array( |
||
318 | 'title' => __('Venue Editor', 'event_espresso'), |
||
319 | 'filename' => 'venues_editor' |
||
320 | ), |
||
321 | 'venues_editor_title_richtexteditor_help_tab' => array( |
||
322 | 'title' => __('Venue Title & Rich Text Editor', 'event_espresso'), |
||
323 | 'filename' => 'venues_editor_title_richtexteditor' |
||
324 | ), |
||
325 | 'venues_editor_tags_categories_help_tab' => array( |
||
326 | 'title' => __('Venue Tags & Categories', 'event_espresso'), |
||
327 | 'filename' => 'venues_editor_tags_categories' |
||
328 | ), |
||
329 | 'venues_editor_physical_location_google_map_virtual_location_help_tab' => array( |
||
330 | 'title' => __('Venue Editor Physical Location & Google Map & Virtual Location', 'event_espresso'), |
||
331 | 'filename' => 'venues_editor_physical_location_google_map_virtual_location' |
||
332 | ), |
||
333 | 'venues_editor_save_new_venue_help_tab' => array( |
||
334 | 'title' => __('Save New Venue', 'event_espresso'), |
||
335 | 'filename' => 'venues_editor_save_new_venue' |
||
336 | ), |
||
337 | 'venues_editor_other_help_tab' => array( |
||
338 | 'title' => __('Venue Editor Other', 'event_espresso'), |
||
339 | 'filename' => 'venues_editor_other' |
||
340 | ) |
||
341 | ), |
||
342 | 'help_tour' => array( 'Venues_Edit_Venue_Help_Tour' ), |
||
343 | 'metaboxes' => array('_venue_editor_metaboxes'), |
||
344 | 'require_nonce' => FALSE |
||
345 | ), |
||
346 | 'google_map_settings' => array( |
||
347 | 'nav' => array( |
||
348 | 'label' => __('Google Maps'), |
||
349 | 'order' => 40 |
||
350 | ), |
||
351 | 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box' ) ), |
||
352 | 'help_tabs' => array( |
||
353 | 'general_settings_google_maps_help_tab' => array( |
||
354 | 'title' => __('Google Maps', 'event_espresso'), |
||
355 | 'filename' => 'general_settings_google_maps' |
||
356 | ) |
||
357 | ), |
||
358 | 'help_tour' => array( 'Google_Maps_Help_Tour' ), |
||
359 | 'require_nonce' => FALSE |
||
360 | ), |
||
361 | //venue category stuff |
||
362 | 'add_category' => array( |
||
363 | 'nav' => array( |
||
364 | 'label' => __('Add Category', 'event_espresso'), |
||
365 | 'order' => 15, |
||
366 | 'persistent' => false), |
||
367 | 'metaboxes' => array('_publish_post_box'), |
||
368 | 'help_tabs' => array( |
||
369 | 'venues_add_category_help_tab' => array( |
||
370 | 'title' => __('Add New Venue Category', 'event_espresso'), |
||
371 | 'filename' => 'venues_add_category' |
||
372 | ) |
||
373 | ), |
||
374 | 'help_tour' => array( 'Venues_Add_Category_Help_Tour' ), |
||
375 | 'require_nonce' => FALSE |
||
376 | ), |
||
377 | 'edit_category' => array( |
||
378 | 'nav' => array( |
||
379 | 'label' => __('Edit Category', 'event_espresso'), |
||
380 | 'order' => 15, |
||
381 | 'persistent' => FALSE, |
||
382 | 'url' => isset($this->_req_data['EVT_CAT_ID']) ? add_query_arg(array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID'] ), $this->_current_page_view_url ) : $this->_admin_base_url |
||
383 | ), |
||
384 | 'metaboxes' => array('_publish_post_box'), |
||
385 | 'help_tabs' => array( |
||
386 | 'venues_edit_category_help_tab' => array( |
||
387 | 'title' => __('Edit Venue Category', 'event_espresso'), |
||
388 | 'filename' => 'venues_edit_category' |
||
389 | ) |
||
390 | ), |
||
391 | 'help_tour' => array( 'Venues_Edit_Category_Help_Tour' ), |
||
392 | 'require_nonce' => FALSE |
||
393 | ), |
||
394 | 'category_list' => array( |
||
395 | 'nav' => array( |
||
396 | 'label' => __('Categories', 'event_espresso'), |
||
397 | 'order' => 20 |
||
398 | ), |
||
399 | 'list_table' => 'Venue_Categories_Admin_List_Table', |
||
400 | 'help_tabs' => array( |
||
401 | 'venues_categories_help_tab' => array( |
||
402 | 'title' => __('Venue Categories', 'event_espresso'), |
||
403 | 'filename' => 'venues_categories' |
||
404 | ), |
||
405 | 'venues_categories_table_column_headings_help_tab' => array( |
||
406 | 'title' => __('Venue Categories Table Column Headings', 'event_espresso'), |
||
407 | 'filename' => 'venues_categories_table_column_headings' |
||
408 | ), |
||
409 | 'venues_categories_views_help_tab' => array( |
||
410 | 'title' => __('Venue Categories Views', 'event_espresso'), |
||
411 | 'filename' => 'venues_categories_views' |
||
412 | ), |
||
413 | 'venues_categories_other_help_tab' => array( |
||
414 | 'title' => __('Venue Categories Other', 'event_espresso'), |
||
415 | 'filename' => 'venues_categories_other' |
||
416 | ) |
||
417 | ), |
||
418 | 'help_tour' => array( 'Venues_Categories_Help_Tour' ), |
||
419 | 'metaboxes' => $this->_default_espresso_metaboxes, |
||
420 | 'require_nonce' => FALSE |
||
421 | ) |
||
422 | ); |
||
423 | } |
||
424 | |||
425 | |||
426 | |||
427 | |||
428 | |||
429 | protected function _add_screen_options() { |
||
432 | |||
433 | |||
434 | |||
435 | |||
436 | |||
437 | protected function _add_screen_options_default() { |
||
440 | |||
441 | |||
442 | |||
443 | View Code Duplication | protected function _add_screen_options_category_list() { |
|
444 | $page_title = $this->_admin_page_title; |
||
445 | $this->_admin_page_title = __('Venue Categories', 'event_espresso'); |
||
446 | $this->_per_page_screen_option(); |
||
447 | $this->_admin_page_title = $page_title; |
||
448 | } |
||
449 | |||
450 | |||
451 | |||
452 | |||
453 | |||
454 | |||
455 | //none of the below group are currently used for Event Venues |
||
456 | protected function _add_feature_pointers() {} |
||
460 | |||
461 | |||
462 | |||
463 | |||
464 | |||
465 | |||
466 | public function load_scripts_styles_create_new() { |
||
469 | |||
470 | |||
471 | |||
472 | |||
473 | |||
474 | public function load_scripts_styles() { |
||
478 | |||
479 | |||
480 | |||
481 | public function load_scripts_styles_add_category() { |
||
484 | |||
485 | |||
486 | |||
487 | |||
488 | |||
489 | public function load_scripts_styles_edit_category() {} |
||
490 | |||
491 | |||
492 | |||
493 | |||
494 | |||
495 | public function load_scripts_styles_edit() { |
||
496 | //styles |
||
497 | wp_enqueue_style('espresso-ui-theme'); |
||
498 | wp_register_style( 'espresso_venues', EE_VENUES_ASSETS_URL . 'ee-venues-admin.css', array(), EVENT_ESPRESSO_VERSION ); |
||
499 | wp_enqueue_style('espresso_venues'); |
||
500 | } |
||
501 | |||
502 | |||
503 | |||
504 | |||
505 | |||
506 | |||
507 | protected function _set_list_table_views_default() { |
||
508 | $this->_views = array( |
||
509 | 'all' => array( |
||
510 | 'slug' => 'all', |
||
511 | 'label' => __('View All Venues', 'event_espresso'), |
||
512 | 'count' => 0, |
||
513 | 'bulk_action' => array() |
||
514 | ) |
||
515 | ); |
||
516 | |||
517 | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_venues', 'espresso_venues_trash_venues' ) ) { |
||
518 | $this->_views['all']['bulk_action'] = array( |
||
519 | 'trash_venues' => __('Move to Trash', 'event_espresso') |
||
520 | ); |
||
521 | $this->_views['trash'] = array( |
||
522 | 'slug' => 'trash', |
||
523 | 'label' => __( 'Trash', 'event_espresso' ), |
||
524 | 'count' => 0, |
||
525 | 'bulk_action' => array( |
||
526 | 'restore_venues' => __('Restore from Trash', 'event_espresso'), |
||
527 | 'delete_venues' => __('Delete', 'event_espresso') |
||
528 | ) |
||
529 | ); |
||
530 | } |
||
531 | } |
||
532 | |||
533 | |||
534 | |||
535 | |||
536 | |||
537 | View Code Duplication | protected function _set_list_table_views_category_list() { |
|
538 | $this->_views = array( |
||
539 | 'all' => array( |
||
540 | 'slug' => 'all', |
||
541 | 'label' => __('All', 'event_espresso'), |
||
542 | 'count' => 0, |
||
543 | 'bulk_action' => array( |
||
544 | 'delete_categories' => __('Delete Permanently', 'event_espresso'), |
||
545 | // 'export_categories' => __('Export Categories', 'event_espresso'), |
||
546 | ) |
||
547 | ) |
||
548 | ); |
||
549 | } |
||
550 | |||
551 | |||
552 | |||
553 | |||
554 | |||
555 | protected function _overview_list_table() { |
||
556 | do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
||
557 | $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link( get_post_type_archive_link('espresso_venues'), __("View Venue Archive Page", "event_espresso"), 'button' ); |
||
558 | $this->_admin_page_title .= $this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2'); |
||
559 | $this->_search_btn_label = __('Venues', 'event_espresso'); |
||
560 | $this->display_admin_list_table_page_with_sidebar(); |
||
561 | } |
||
562 | |||
563 | |||
564 | |||
565 | public function extra_misc_actions_publish_box() { |
||
566 | $extra_rows = array( |
||
567 | 'vnu_capacity' => $this->_cpt_model_obj->get_pretty('VNU_capacity', 'input'), |
||
568 | 'vnu_url' => $this->_cpt_model_obj->venue_url(), |
||
569 | 'vnu_phone' => $this->_cpt_model_obj->phone() |
||
570 | ); |
||
571 | $template = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php'; |
||
572 | EEH_Template::display_template( $template, $extra_rows ); |
||
573 | } |
||
574 | |||
575 | |||
576 | |||
577 | /************* Google Maps *************/ |
||
578 | |||
579 | |||
580 | protected function _google_map_settings() { |
||
581 | |||
582 | |||
583 | $this->_template_args['values'] = $this->_yes_no_values; |
||
584 | $default_map_settings = new stdClass(); |
||
585 | $default_map_settings->use_google_maps = TRUE; |
||
586 | // for event details pages (reg page) |
||
587 | $default_map_settings->event_details_map_width = 585; // ee_map_width_single |
||
588 | $default_map_settings->event_details_map_height = 362; // ee_map_height_single |
||
589 | $default_map_settings->event_details_map_zoom = 14; // ee_map_zoom_single |
||
590 | $default_map_settings->event_details_display_nav = TRUE; // ee_map_nav_display_single |
||
591 | $default_map_settings->event_details_nav_size = FALSE; // ee_map_nav_size_single |
||
592 | $default_map_settings->event_details_control_type = 'default'; // ee_map_type_control_single |
||
593 | $default_map_settings->event_details_map_align = 'center'; // ee_map_align_single |
||
594 | // for event list pages |
||
595 | $default_map_settings->event_list_map_width = 300; // ee_map_width |
||
596 | $default_map_settings->event_list_map_height = 185; // ee_map_height |
||
597 | $default_map_settings->event_list_map_zoom = 12; // ee_map_zoom |
||
598 | $default_map_settings->event_list_display_nav = FALSE; // ee_map_nav_display |
||
599 | $default_map_settings->event_list_nav_size = TRUE; // ee_map_nav_size |
||
600 | $default_map_settings->event_list_control_type = 'dropdown'; // ee_map_type_control |
||
601 | $default_map_settings->event_list_map_align = 'center'; // ee_map_align |
||
602 | |||
603 | $this->_template_args['map_settings'] = |
||
604 | isset( EE_Registry::instance()->CFG->map_settings ) && ! empty( EE_Registry::instance()->CFG->map_settings ) |
||
605 | ? (object)array_merge( (array)$default_map_settings, (array)EE_Registry::instance()->CFG->map_settings ) |
||
606 | : $default_map_settings; |
||
607 | |||
608 | $this->_set_add_edit_form_tags( 'update_google_map_settings' ); |
||
609 | $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
||
610 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( EE_VENUES_TEMPLATE_PATH . 'google_map.template.php', $this->_template_args, TRUE ); |
||
611 | $this->display_admin_page_with_sidebar(); |
||
612 | } |
||
613 | |||
614 | protected function _update_google_map_settings() { |
||
698 | |||
699 | |||
700 | |||
701 | protected function _venue_editor_metaboxes() { |
||
702 | $this->verify_cpt_object(); |
||
703 | |||
704 | add_meta_box( 'espresso_venue_address_options', __('Physical Location', 'event_espresso'), array( $this, 'venue_address_metabox'), $this->page_slug, 'side', 'default' ); |
||
705 | add_meta_box( 'espresso_venue_gmap_options', __('Google Map', 'event_espresso'), array( $this, 'venue_gmap_metabox'), $this->page_slug, 'side', 'default' ); |
||
706 | add_meta_box( 'espresso_venue_virtual_loc_options', __('Virtual Location', 'event_espresso'), array( $this, 'venue_virtual_loc_metabox'), $this->page_slug, 'side', 'default' ); |
||
707 | |||
708 | } |
||
709 | |||
710 | |||
711 | |||
712 | public function venue_gmap_metabox() { |
||
713 | $template_args = array( |
||
714 | 'vnu_enable_for_gmap' => EEH_Form_Fields::select_input('vnu_enable_for_gmap', $this->get_yes_no_values(), $this->_cpt_model_obj->enable_for_gmap() ), |
||
715 | 'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(), |
||
716 | ); |
||
717 | $template = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php'; |
||
718 | EEH_Template::display_template( $template, $template_args ); |
||
719 | } |
||
720 | |||
721 | |||
722 | |||
723 | public function venue_address_metabox() { |
||
724 | |||
725 | $template_args['_venue'] =$this->_cpt_model_obj; |
||
726 | |||
727 | $template_args['states_dropdown'] = EEH_Form_Fields::generate_form_input( |
||
728 | $QFI = new EE_Question_Form_Input( |
||
729 | EE_Question::new_instance( array( 'QST_display_text' => 'State', 'QST_system' => 'state' )), |
||
730 | EE_Answer::new_instance( array( 'ANS_value'=> $this->_cpt_model_obj->state_ID() )), |
||
731 | array( |
||
732 | 'input_name' => 'sta_id', |
||
733 | 'input_id' => 'sta_id', |
||
734 | 'input_class' => '', |
||
735 | 'input_prefix' => '', |
||
736 | 'append_qstn_id' => FALSE |
||
737 | ) |
||
738 | ) |
||
739 | ); |
||
740 | $template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input( |
||
741 | $QFI = new EE_Question_Form_Input( |
||
742 | EE_Question::new_instance( array( 'QST_display_text' => 'Country', 'QST_system' => 'country' )), |
||
743 | EE_Answer::new_instance( array( 'ANS_value'=> $this->_cpt_model_obj->country_ID() )), |
||
744 | array( |
||
745 | 'input_name' => 'cnt_iso', |
||
746 | 'input_id' => 'cnt_iso', |
||
747 | 'input_class' => '', |
||
748 | 'input_prefix' => '', |
||
749 | 'append_qstn_id' => FALSE |
||
750 | ) |
||
751 | ) |
||
752 | ); |
||
753 | |||
754 | $template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php'; |
||
755 | EEH_Template::display_template( $template, $template_args ); |
||
756 | } |
||
757 | |||
758 | |||
759 | |||
760 | |||
761 | |||
762 | |||
763 | public function venue_virtual_loc_metabox() { |
||
764 | $template_args = array( |
||
765 | '_venue' => $this->_cpt_model_obj |
||
766 | ); |
||
767 | $template = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php'; |
||
768 | EEH_Template::display_template( $template, $template_args ); |
||
769 | } |
||
770 | |||
771 | |||
772 | |||
773 | protected function _restore_cpt_item($post_id, $revision_id) { |
||
774 | $venue_obj = $this->_venue_model->get_one_by_ID($post_id); |
||
775 | |||
776 | //meta revision restore |
||
777 | $venue_obj->restore_revision($revision_id); |
||
778 | } |
||
779 | |||
780 | |||
781 | |||
782 | |||
783 | |||
784 | |||
785 | /** |
||
786 | * Handles updates for venue cpts |
||
787 | * @param int $post_id ID of Venue CPT |
||
788 | * @param object $post Post object (with "blessed" WP properties) |
||
789 | * @return void |
||
790 | */ |
||
791 | protected function _insert_update_cpt_item( $post_id, $post ) { |
||
792 | |||
793 | if ( $post instanceof WP_Post && $post->post_type !== 'espresso_venues' ) { |
||
794 | return;// get out we're not processing the saving of venues. |
||
795 | } |
||
796 | |||
797 | $wheres = array( $this->_venue_model->primary_key_name() => $post_id ); |
||
798 | |||
799 | $venue_values = array( |
||
800 | 'VNU_address' => !empty( $this->_req_data['vnu_address'] ) ? $this->_req_data['vnu_address'] : NULL, |
||
801 | 'VNU_address2' => !empty( $this->_req_data['vnu_address2'] ) ? $this->_req_data['vnu_address2'] : NULL, |
||
802 | 'VNU_city' => !empty( $this->_req_data['vnu_city'] ) ? $this->_req_data['vnu_city'] : NULL, |
||
803 | 'STA_ID' => !empty( $this->_req_data['sta_id'] ) ? $this->_req_data['sta_id'] : NULL, |
||
804 | 'CNT_ISO' => !empty( $this->_req_data['cnt_iso'] ) ? $this->_req_data['cnt_iso'] : NULL, |
||
805 | 'VNU_zip' => !empty( $this->_req_data['vnu_zip'] ) ? $this->_req_data['vnu_zip'] : NULL, |
||
806 | 'VNU_phone' => !empty( $this->_req_data['vnu_phone'] ) ? $this->_req_data['vnu_phone'] : NULL, |
||
807 | 'VNU_capacity' => !empty( $this->_req_data['vnu_capacity'] ) ? str_replace( ',', '', $this->_req_data['vnu_capacity'] ) : EE_INF, |
||
808 | 'VNU_url' => !empty( $this->_req_data['vnu_url'] ) ? $this->_req_data['vnu_url'] : NULL, |
||
809 | 'VNU_virtual_phone' => !empty( $this->_req_data['vnu_virtual_phone'] ) ? $this->_req_data['vnu_virtual_phone'] : NULL, |
||
810 | 'VNU_virtual_url' => !empty( $this->_req_data['vnu_virtual_url'] ) ? $this->_req_data['vnu_virtual_url'] : NULL, |
||
811 | 'VNU_enable_for_gmap' => !empty( $this->_req_data['vnu_enable_for_gmap'] ) ? TRUE : FALSE, |
||
812 | 'VNU_google_map_link' => !empty( $this->_req_data['vnu_google_map_link'] ) ? $this->_req_data['vnu_google_map_link'] : NULL |
||
813 | ); |
||
814 | |||
815 | //update venue |
||
816 | $success = $this->_venue_model->update( $venue_values, array( $wheres ) ); |
||
817 | |||
818 | //get venue_object for other metaboxes that might be added via the filter... though it would seem to make sense to just use $this->_venue_model->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
||
819 | $get_one_where = array( $this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status ); |
||
820 | $venue = $this->_venue_model->get_one( array( $get_one_where ) ); |
||
821 | |||
822 | //notice we've applied a filter for venue metabox callbacks but we don't actually have any default venue metaboxes in use. So this is just here for addons to more easily hook into venue saves. |
||
823 | $venue_update_callbacks = apply_filters( 'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks', array() ); |
||
824 | |||
825 | $att_success = TRUE; |
||
826 | |||
827 | View Code Duplication | foreach ( $venue_update_callbacks as $v_callback ) { |
|
828 | $_succ = call_user_func_array( $v_callback, array( $venue, $this->_req_data ) ); |
||
829 | $att_success = !$att_success ? $att_success : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
||
830 | } |
||
831 | |||
832 | //any errors? |
||
833 | if ( $success && !$att_success ) { |
||
834 | EE_Error::add_error( __('Venue Details saved successfully but something went wrong with saving attachments.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
||
835 | } else if ( $success === FALSE ) { |
||
836 | EE_Error::add_error( __('Venue Details did not save successfully.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
||
837 | } |
||
838 | } |
||
839 | |||
840 | |||
841 | |||
842 | |||
843 | |||
844 | public function trash_cpt_item( $post_id ) { |
||
848 | |||
849 | |||
850 | |||
851 | |||
852 | |||
853 | |||
854 | public function restore_cpt_item( $post_id ) { |
||
858 | |||
859 | |||
860 | |||
861 | |||
862 | |||
863 | public function delete_cpt_item( $post_id ) { |
||
867 | |||
868 | |||
869 | |||
870 | |||
871 | |||
872 | |||
873 | public function get_venue_object() { |
||
876 | |||
877 | |||
878 | |||
879 | |||
880 | View Code Duplication | protected function _trash_or_restore_venue( $venue_status = 'trash', $redirect_after = TRUE ) { |
|
881 | $VNU_ID = isset( $this->_req_data['VNU_ID'] ) ? absint( $this->_req_data['VNU_ID'] ) : FALSE; |
||
882 | |||
883 | //loop thru venues |
||
884 | if ( $VNU_ID ) { |
||
885 | //clean status |
||
886 | $venue_status = sanitize_key( $venue_status ); |
||
887 | // grab status |
||
888 | if (!empty($venue_status)) { |
||
889 | $success = $this->_change_venue_status($VNU_ID, $venue_status); |
||
890 | } else { |
||
891 | $success = FALSE; |
||
892 | $msg = __('An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.', 'event_espresso'); |
||
893 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
||
894 | } |
||
895 | } else { |
||
896 | $success = FALSE; |
||
897 | $msg = __('An error occurred. The venue could not be moved to the trash because a valid venue ID was not not supplied.', 'event_espresso'); |
||
898 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
||
899 | } |
||
900 | $action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
||
901 | |||
902 | if ( $redirect_after ) |
||
903 | $this->_redirect_after_action($success, 'Venue', $action, array('action' => 'default')); |
||
904 | |||
905 | } |
||
906 | |||
907 | |||
908 | |||
909 | |||
910 | |||
911 | View Code Duplication | protected function _trash_or_restore_venues( $venue_status = 'trash' ) { |
|
912 | // clean status |
||
913 | $venue_status = sanitize_key($venue_status); |
||
914 | // grab status |
||
915 | if (!empty($venue_status)) { |
||
916 | $success = TRUE; |
||
917 | //determine the event id and set to array. |
||
918 | $VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array(); |
||
919 | // loop thru events |
||
920 | foreach ($VNU_IDs as $VNU_ID) { |
||
921 | if ($VNU_ID = absint($VNU_ID)) { |
||
922 | $results = $this->_change_venue_status($VNU_ID, $venue_status); |
||
923 | $success = $results !== FALSE ? $success : FALSE; |
||
924 | } else { |
||
925 | $msg = sprintf(__('An error occurred. Venue #%d could not be moved to the trash because a valid venue ID was not not supplied.', 'event_espresso'), $VNU_ID); |
||
926 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
||
927 | $success = FALSE; |
||
928 | } |
||
929 | } |
||
930 | } else { |
||
931 | $success = FALSE; |
||
932 | $msg = __('An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.', 'event_espresso'); |
||
933 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
||
934 | } |
||
935 | // in order to force a pluralized result message we need to send back a success status greater than 1 |
||
936 | $success = $success ? 2 : FALSE; |
||
937 | $action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
||
938 | $this->_redirect_after_action($success, 'Venues', $action, array('action' => 'default')); |
||
939 | } |
||
940 | |||
941 | |||
942 | |||
943 | |||
944 | |||
945 | /** |
||
946 | * _trash_or_restore_venues |
||
947 | * |
||
948 | * //todo this is pretty much the same as the corresponding change_event_status method in Events_Admin_Page. We should probably abstract this up to the EE_Admin_Page_CPT (or even EE_Admin_Page) and make this a common method accepting a certain number of params. |
||
949 | * |
||
950 | * @access private |
||
951 | * @param int $VNU_ID |
||
952 | * @param string $venue_status |
||
953 | * @return void |
||
954 | */ |
||
955 | View Code Duplication | private function _change_venue_status( $VNU_ID = 0, $venue_status = '' ) { |
|
956 | // grab venue id |
||
957 | if (! $VNU_ID) { |
||
958 | $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso'); |
||
959 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
||
960 | return FALSE; |
||
961 | } |
||
962 | |||
963 | $this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
||
964 | |||
965 | // clean status |
||
966 | $venue_status = sanitize_key($venue_status); |
||
967 | // grab status |
||
968 | if ( ! $venue_status ) { |
||
969 | $msg = __('An error occurred. No Venue Status or an invalid Venue Status was received.', 'event_espresso'); |
||
970 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
||
971 | return FALSE; |
||
972 | } |
||
973 | |||
974 | // was event trashed or restored ? |
||
975 | switch ($venue_status) { |
||
976 | case 'draft' : |
||
977 | $action = 'restored from the trash'; |
||
978 | $hook = 'AHEE_venue_restored_from_trash'; |
||
979 | break; |
||
980 | case 'trash' : |
||
981 | $action = 'moved to the trash'; |
||
982 | $hook = 'AHEE_venue_moved_to_trash'; |
||
983 | break; |
||
984 | default : |
||
985 | $action = 'updated'; |
||
986 | $hook = FALSE; |
||
987 | } |
||
988 | //use class to change status |
||
989 | $this->_cpt_model_obj->set_status( $venue_status ); |
||
990 | $success = $this->_cpt_model_obj->save(); |
||
991 | |||
992 | if ($success === FALSE) { |
||
993 | $msg = sprintf(__('An error occurred. The venue could not be %s.', 'event_espresso'), $action); |
||
994 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
||
995 | return FALSE; |
||
996 | } |
||
997 | if ($hook) { |
||
998 | do_action($hook); |
||
999 | } |
||
1000 | return TRUE; |
||
1001 | } |
||
1002 | |||
1003 | |||
1004 | /** |
||
1005 | * @param bool $redirect_after |
||
1006 | * @return void |
||
1007 | */ |
||
1008 | protected function _delete_venue( $redirect_after = true ) { |
||
1009 | //determine the venue id and set to array. |
||
1010 | $VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : NULL; |
||
1011 | $VNU_ID = isset( $this->_req_data['post'] ) ? absint( $this->_req_data['post'] ) : $VNU_ID; |
||
1012 | |||
1013 | |||
1014 | // loop thru venues |
||
1015 | if ($VNU_ID) { |
||
1016 | $success = $this->_delete_or_trash_venue( $VNU_ID ); |
||
1017 | } else { |
||
1018 | $success = FALSE; |
||
1019 | $msg = __('An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.', 'event_espresso'); |
||
1020 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
||
1021 | } |
||
1022 | if ( $redirect_after ) |
||
1023 | $this->_redirect_after_action($success, 'Venue', 'deleted', array('action' => 'default')); |
||
1024 | } |
||
1025 | |||
1026 | |||
1027 | |||
1028 | protected function _delete_venues() { |
||
1029 | $success = TRUE; |
||
1030 | //determine the event id and set to array. |
||
1031 | $VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array(); |
||
1032 | // loop thru events |
||
1033 | foreach ($VNU_IDs as $VNU_ID) { |
||
1034 | if ($VNU_ID = absint($VNU_ID)) { |
||
1035 | $results = $this->_delete_or_trash_venue($VNU_ID); |
||
1036 | $success = $results !== FALSE ? $success : FALSE; |
||
1037 | } else { |
||
1038 | $success = FALSE; |
||
1039 | $msg = __('An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.', 'event_espresso'); |
||
1040 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
||
1041 | } |
||
1042 | } |
||
1043 | // in order to force a pluralized result message we need to send back a success status greater than 1 |
||
1044 | $success = $success ? 2 : FALSE; |
||
1045 | $this->_redirect_after_action($success, __('Venues', 'event_espresso'), __('deleted', 'event_espresso'), array('action' => 'default')); |
||
1046 | } |
||
1047 | |||
1048 | |||
1049 | |||
1050 | |||
1051 | //todo: put in parent |
||
1052 | private function _delete_or_trash_venue($VNU_ID = FALSE) { |
||
1053 | // grab event id |
||
1054 | if (!$VNU_ID = absint($VNU_ID)) { |
||
1055 | $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso'); |
||
1056 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
||
1057 | return FALSE; |
||
1058 | } |
||
1059 | |||
1060 | |||
1061 | $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
||
1062 | //first need to remove all term relationships |
||
1063 | $venue->_remove_relations('Term_Taxonomy'); |
||
1064 | $success = $venue->delete_permanently(); |
||
1065 | // did it all go as planned ? |
||
1066 | if ($success) { |
||
1067 | $msg = sprintf(__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID); |
||
1068 | EE_Error::add_success($msg); |
||
1069 | } else { |
||
1070 | $msg = sprintf(__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'), $VNU_ID); |
||
1071 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
||
1072 | return FALSE; |
||
1073 | } |
||
1074 | do_action( 'AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted' ); |
||
1075 | return TRUE; |
||
1076 | } |
||
1077 | |||
1078 | |||
1079 | |||
1080 | |||
1081 | /***********/ |
||
1082 | /* QUERIES */ |
||
1083 | |||
1084 | |||
1085 | public function get_venues( $per_page = 10, $count = FALSE ) { |
||
1181 | |||
1182 | |||
1183 | |||
1184 | |||
1185 | /** Venue Category Stuff **/ |
||
1186 | |||
1187 | /** |
||
1188 | * set the _category property with the category object for the loaded page. |
||
1189 | * |
||
1190 | * @access private |
||
1191 | * @return void |
||
1192 | */ |
||
1193 | View Code Duplication | private function _set_category_object() { |
|
1194 | if ( isset( $this->_category->id ) && !empty( $this->_category->id ) ) |
||
1195 | return; //already have the category object so get out. |
||
1196 | |||
1197 | //set default category object |
||
1198 | $this->_set_empty_category_object(); |
||
1199 | |||
1200 | //only set if we've got an id |
||
1201 | if ( !isset($this->_req_data['VEN_CAT_ID'] ) ) { |
||
1202 | return; |
||
1203 | } |
||
1204 | |||
1205 | $category_id = absint($this->_req_data['VEN_CAT_ID']); |
||
1206 | $term = get_term( $category_id, 'espresso_venue_categories' ); |
||
1207 | |||
1208 | |||
1209 | if ( !empty( $term ) ) { |
||
1210 | $this->_category->category_name = $term->name; |
||
1211 | $this->_category->category_identifier = $term->slug; |
||
1212 | $this->_category->category_desc = $term->description; |
||
1213 | $this->_category->id = $term->term_id; |
||
1214 | $this->_category->parent = $term->parent; |
||
1215 | } |
||
1216 | } |
||
1217 | |||
1218 | |||
1219 | |||
1220 | |||
1221 | private function _set_empty_category_object() { |
||
1222 | $this->_category = new stdClass(); |
||
1223 | $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
||
1224 | $this->_category->id = $this->_category->parent = 0; |
||
1225 | } |
||
1226 | |||
1227 | |||
1228 | |||
1229 | View Code Duplication | protected function _category_list_table() { |
|
1230 | do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
||
1231 | $this->_admin_page_title .= $this->get_action_link_or_button('add_category', 'add_category', array(), 'add-new-h2'); |
||
1232 | $this->_search_btn_label = __('Venue Categories', 'event_espresso'); |
||
1233 | $this->display_admin_list_table_page_with_sidebar(); |
||
1234 | } |
||
1235 | |||
1236 | |||
1237 | View Code Duplication | protected function _category_details($view) { |
|
1238 | |||
1239 | //load formatter helper |
||
1240 | EE_Registry::instance()->load_helper( 'Formatter' ); |
||
1241 | //load field generator helper |
||
1242 | EE_Registry::instance()->load_helper( 'Form_Fields' ); |
||
1243 | |||
1244 | $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
||
1245 | $this->_set_add_edit_form_tags($route); |
||
1246 | |||
1247 | $this->_set_category_object(); |
||
1248 | $id = !empty($this->_category->id) ? $this->_category->id : ''; |
||
1249 | |||
1250 | $delete_action = 'delete_category'; |
||
1251 | |||
1252 | $redirect = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'category_list' ), $this->_admin_base_url ); |
||
1253 | |||
1254 | $this->_set_publish_post_box_vars( 'VEN_CAT_ID', $id, $delete_action, $redirect ); |
||
1255 | |||
1256 | //take care of contents |
||
1257 | $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
||
1258 | $this->display_admin_page_with_sidebar(); |
||
1259 | } |
||
1260 | |||
1261 | |||
1262 | |||
1263 | View Code Duplication | protected function _category_details_content() { |
|
1264 | $editor_args['category_desc'] = array( |
||
1265 | 'type' => 'wp_editor', |
||
1266 | 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
||
1267 | 'class' => 'my_editor_custom', |
||
1268 | 'wpeditor_args' => array( 'media_buttons' => FALSE ) |
||
1269 | ); |
||
1270 | $_wp_editor = $this->_generate_admin_form_fields( $editor_args, 'array' ); |
||
1271 | |||
1272 | $all_terms = get_terms( array('espresso_venue_categories' ), array( 'hide_empty' => 0, 'exclude' => array( $this->_category->id ) ) ); |
||
1273 | |||
1274 | //setup category select for term parents. |
||
1275 | $category_select_values[] = array( |
||
1276 | 'text' => __('No Parent', 'event_espresso'), |
||
1277 | 'id' => 0 |
||
1278 | ); |
||
1279 | foreach ( $all_terms as $term ) { |
||
1280 | $category_select_values[] = array( |
||
1281 | 'text' => $term->name, |
||
1282 | 'id' => $term->term_id |
||
1283 | ); |
||
1284 | } |
||
1285 | |||
1286 | $category_select = EEH_Form_Fields::select_input( 'category_parent', $category_select_values, $this->_category->parent ); |
||
1287 | $template_args = array( |
||
1288 | 'category' => $this->_category, |
||
1289 | 'category_select' => $category_select, |
||
1290 | 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
||
1291 | 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
||
1292 | 'disable' => '', |
||
1293 | 'disabled_message' =>FALSE |
||
1294 | ); |
||
1295 | $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
||
1296 | return EEH_Template::display_template($template, $template_args, TRUE ); |
||
1297 | } |
||
1298 | |||
1299 | |||
1300 | View Code Duplication | protected function _delete_categories() { |
|
1301 | $cat_ids = isset( $this->_req_data['VEN_CAT_ID'] ) ? (array) $this->_req_data['VEN_CAT_ID'] : (array) $this->_req_data['category_id']; |
||
1302 | |||
1303 | foreach ( $cat_ids as $cat_id ) { |
||
1304 | $this->_delete_category($cat_id); |
||
1305 | } |
||
1306 | |||
1307 | //doesn't matter what page we're coming from... we're going to the same place after delete. |
||
1308 | $query_args = array( |
||
1309 | 'action' => 'category_list' |
||
1310 | ); |
||
1311 | $this->_redirect_after_action(0,'','',$query_args); |
||
1312 | |||
1313 | } |
||
1314 | |||
1315 | |||
1316 | |||
1317 | |||
1318 | |||
1319 | protected function _delete_category($cat_id) { |
||
1323 | |||
1324 | |||
1325 | |||
1326 | View Code Duplication | protected function _insert_or_update_category($new_category) { |
|
1327 | |||
1328 | $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category( TRUE ); |
||
1329 | $success = 0; //we already have a success message so lets not send another. |
||
1330 | if ( $cat_id ) { |
||
1331 | $query_args = array( |
||
1332 | 'action' => 'edit_category', |
||
1333 | 'VEN_CAT_ID' => $cat_id |
||
1334 | ); |
||
1335 | } else { |
||
1336 | $query_args = array( 'action' => 'add_category' ); |
||
1337 | } |
||
1338 | $this->_redirect_after_action( $success, '','', $query_args, TRUE ); |
||
1339 | |||
1340 | } |
||
1341 | |||
1342 | |||
1343 | |||
1344 | private function _insert_category( $update = FALSE ) { |
||
1345 | $cat_id = $update ? $this->_req_data['VEN_CAT_ID'] : ''; |
||
1346 | $category_name= isset( $this->_req_data['category_name'] ) ? $this->_req_data['category_name'] : ''; |
||
1347 | $category_desc= isset( $this->_req_data['category_desc'] ) ? $this->_req_data['category_desc'] : ''; |
||
1348 | $category_parent = isset( $this->_req_data['category_parent'] ) ? $this->_req_data['category_parent'] : 0; |
||
1349 | |||
1350 | if ( empty( $category_name ) ) { |
||
1351 | $msg = __( 'You must add a name for the category.', 'event_espresso' ); |
||
1352 | EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
||
1353 | return false; |
||
1376 | |||
1377 | |||
1378 | /** |
||
1379 | * TODO handle category exports() |
||
1380 | * @return file export |
||
1381 | */ |
||
1382 | View Code Duplication | protected function _categories_export() { |
|
1401 | |||
1402 | |||
1403 | |||
1404 | |||
1405 | |||
1406 | protected function _import_categories() { |
||
1412 | |||
1413 | |||
1414 | |||
1415 | |||
1416 | View Code Duplication | public function get_categories( $per_page = 10, $current_page = 1, $count = FALSE ) { |
|
1442 | |||
1443 | |||
1444 | /* end category stuff */ |
||
1445 | /**************/ |
||
1446 | |||
1447 | |||
1448 | |||
1449 | } //end Venues_Admin_Page class |
||
1450 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..