From 138b3859aa2972ea75bbb6a77da95ab4bc6b7acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCnther?= Date: Sat, 10 Aug 2024 22:13:57 +0200 Subject: [PATCH] Update routines --- .../Controllers/class-main.php | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/modules/event-participants/Controllers/class-main.php b/modules/event-participants/Controllers/class-main.php index a22f1a4..c668719 100644 --- a/modules/event-participants/Controllers/class-main.php +++ b/modules/event-participants/Controllers/class-main.php @@ -40,54 +40,51 @@ class MainController } public function __construct() { - global $dbHandler, $wpdb; + global $dbHandler, $wpdb; - $show_menu = false; + $no_events = true; - foreach ([self::KOMPASS_EVENTS_EVENTS] as $table) { - $sqlTable = $wpdb->prefix . $table; - $sql = "SHOW TABLES LIKE '$sqlTable'"; + foreach ( [ self::KOMPASS_EVENTS_EVENTS ] as $table ) { + $sqlTable = $wpdb->prefix . $table; + $sql = "SHOW TABLES LIKE '$sqlTable'"; - $result = $wpdb->get_var( $sql ); - if ( $result == $sqlTable ) { - $show_menu = true; - } - } + $result = $wpdb->get_var( $sql ); + if ( $result == $sqlTable ) { - if (!$show_menu) { - return; - } + $no_events = 0 === $dbHandler->countSqlRows( self::KOMPASS_EVENTS_EVENTS, [ 'archived' => false ] ); + } + } - add_menu_page( - __('Events (legacy)', BDP_LV_PLUGIN_SLUG), - __('Events (legacy)', BDP_LV_PLUGIN_SLUG), - 'send_mails', - 'kompass-events', - [$this, 'router'], - 'dashicons-tickets-alt', - 3 - ); - foreach ($dbHandler->readFromDb( self::KOMPASS_EVENTS_EVENTS, ['archived' => false]) as $currentEvent) { - add_submenu_page( - 'kompass-events', - $currentEvent->event_name, - $currentEvent->event_name, - 'show_groups', - 'kompass-events&action=show-event&event-id=' . $currentEvent->id, - [ $this, 'router' ]); - } + if ( !$no_events ) { - add_submenu_page( - 'kompass-events', - __('New Event', BDP_LV_PLUGIN_SLUG), - __('New Event', BDP_LV_PLUGIN_SLUG), - 'show_groups', - 'kompass-events&action=new-event', - [ $this, 'router' ]); + + + add_menu_page( + __( 'Events (legacy)', BDP_LV_PLUGIN_SLUG ), + __( 'Events (legacy)', BDP_LV_PLUGIN_SLUG ), + 'send_mails', + 'kompass-events', + [ $this, 'router' ], + 'dashicons-tickets-alt', + 3 + ); + + foreach ( $dbHandler->readFromDb( self::KOMPASS_EVENTS_EVENTS, [ 'archived' => false ] ) as $currentEvent ) { + add_submenu_page( + 'kompass-events', + $currentEvent->event_name, + $currentEvent->event_name, + 'show_groups', + 'kompass-events&action=show-event&event-id=' . $currentEvent->id, + [ $this, 'router' ] ); + } + + } } + public function router() { if (isset($_REQUEST['action'])) {