From abc3a2a0a02922112044437c6dce36e2a0ca51a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCnther?= Date: Sat, 23 Mar 2024 00:37:20 +0100 Subject: [PATCH] Base setup for displaying groups and listing members --- assets/wordpress-bdp.css | 8 ++ bdp-kompass.php | 3 + components/partials/telephon-link.php | 9 ++ includes/DatabaseHandler.php | 46 ++++++++++ includes/action_caller.php | 22 ++++- includes/frontend-functions.php | 13 +-- includes/pre_requires.php | 1 + includes/roles.php | 3 + includes/setup.php | 9 +- includes/spl.php | 2 +- .../kompass_stammesgruppen_gruppen.sql | 21 +++++ .../kompass_stammesgruppen_teilis.sql | 48 +++++++++++ .../Gruppen/Controllers/MainController.php | 86 +++++++++++++++++++ modules/Gruppen/Views/GruppenOverview.php | 42 +++++++++ modules/Gruppen/Views/PrintMembers.php | 65 ++++++++++++++ modules/seo/includes/meta.php | 2 +- 16 files changed, 363 insertions(+), 17 deletions(-) create mode 100644 components/partials/telephon-link.php create mode 100644 includes/DatabaseHandler.php create mode 100644 lib/database/kompass_stammesgruppen_gruppen.sql create mode 100644 lib/database/kompass_stammesgruppen_teilis.sql create mode 100644 modules/Gruppen/Controllers/MainController.php create mode 100644 modules/Gruppen/Views/GruppenOverview.php create mode 100644 modules/Gruppen/Views/PrintMembers.php diff --git a/assets/wordpress-bdp.css b/assets/wordpress-bdp.css index 8f5d93a..c3d80b9 100644 --- a/assets/wordpress-bdp.css +++ b/assets/wordpress-bdp.css @@ -198,6 +198,7 @@ ul#adminmenu a.wp-has-current-submenu::after, ul#adminmenu > li.current > a.curr } @media screen and (max-width: 782px) { + #adminmenu > li.menu-top:hover, #adminmenu > li.opensub > a.menu-top, #adminmenu > li > a.menu-top:focus { background-color: #fafafa; color: #1d4899 !important; @@ -234,6 +235,13 @@ ul#adminmenu a.wp-has-current-submenu::after, ul#adminmenu > li.current > a.curr background-color: #fafafa !important; width: 285px !important; } + + #wp-admin-bar-comments { + display: none !important; + } + #wp-admin-bar-kompass_gruppen { + display: block !important; + } } #adminmenu div.wp-menu-name { diff --git a/bdp-kompass.php b/bdp-kompass.php index 99cbdaf..1b59e88 100644 --- a/bdp-kompass.php +++ b/bdp-kompass.php @@ -12,6 +12,7 @@ * Text Domain: bdp-kompass */ +use Bdp\Modules\Gruppen\Controllers\MainController as GruppenMain; use Bdp\Modules\KompassSettings\Controllers\SettingsPage as KomnpassSettings; use Bdp\Modules\LimitLoginAttempts\Controllers\OptionsPage as OptionsPageAlias; use Bdp\Modules\Security\Security; @@ -28,6 +29,7 @@ function bdp_plugin_init() { bdp_kompass_load_plugin_textdomain(); Security::ProhibitBots(); Security::SetPageFilters(); + GruppenMain::setup(); if (null == get_option('kompass_already_installed', null)) { Seo::setup(); @@ -44,6 +46,7 @@ add_action('admin_menu', function () { bdp_kompass_load_plugin_textdomain(); new OptionsPageAlias(); new KomnpassSettings(); + new GruppenMain(); }); diff --git a/components/partials/telephon-link.php b/components/partials/telephon-link.php new file mode 100644 index 0000000..95c1d4d --- /dev/null +++ b/components/partials/telephon-link.php @@ -0,0 +1,9 @@ +' . $telephonnumber . ''; + } \ No newline at end of file diff --git a/includes/DatabaseHandler.php b/includes/DatabaseHandler.php new file mode 100644 index 0000000..6bc2cc3 --- /dev/null +++ b/includes/DatabaseHandler.php @@ -0,0 +1,46 @@ +prefix . $table . $this->parseConditions($conditions); + return $this->getResults( $sql ); + } + + public function readSqlFromDb(string $tableName, string $preparedSql) : array + { + global $wpdb; + $sql = str_replace('%tablename%', $wpdb->prefix . $tableName, $preparedSql ); + return $this->getResults($sql); + } + + public function countSqlRows(string $tableName, array $conditions = []) : int + { + global $wpdb; + $sql = 'SELECT COUNT(*) as count_data FROM ' . $wpdb->prefix . $tableName . $this->parseConditions($conditions); + $res = $this->getResults( $sql ); + $res = $res[0]; + return (int)$res->count_data; + } + + private function getResults(string $sql) : array + { + global $wpdb; + return $wpdb->get_results($sql, OBJECT ); + } + + private function parseConditions(array $conditionArray) : string + { + global $wpdb; + $_tmpArr = []; + foreach ($conditionArray as $key => $value) { + $_tmpArr[] = '`' . $key .'` = "' . $wpdb->_real_escape($value) . '"'; + } + + $returnString = implode(' AND ', $_tmpArr); + return $returnString !== '' ? (' WHERE ' . $returnString) : ''; + } +} \ No newline at end of file diff --git a/includes/action_caller.php b/includes/action_caller.php index 95ce679..c2178a4 100644 --- a/includes/action_caller.php +++ b/includes/action_caller.php @@ -20,6 +20,26 @@ if (isset($_POST['save_kompass_balist_list_type'])) { updateBlockOrAllowList($_POST); } +function add_custom_admin_bar_item() { + global $wp_admin_bar; + // Überprüfen, ob der Benutzer die erforderliche Berechtigung hat + if ( current_user_can( 'show_groups' ) ) { + // Das Array mit den Eigenschaften des benutzerdefinierten Elements + $args = [ + 'id' => 'kompass_gruppen', + 'title' => '' . + '' .__('Groups', BDP_LV_PLUGIN_SLUG) . '', + 'href' => 'admin.php?page=kompass-groups', -add_action('wp_head', 'kompass_seo_add_verfications'); \ No newline at end of file + ]; + + // Das benutzerdefinierte Element zur Admin-Leiste hinzufügen + $wp_admin_bar->add_node( $args ); + } +} + +// Die Funktion aufrufen, um das benutzerdefinierte Element zur Admin-Leiste hinzuzufügen +add_action( 'admin_bar_menu', 'add_custom_admin_bar_item', 50 ); + +add_action('wp_head', 'kompass_seo_add_verifications' ); \ No newline at end of file diff --git a/includes/frontend-functions.php b/includes/frontend-functions.php index 60b858c..f20eadd 100644 --- a/includes/frontend-functions.php +++ b/includes/frontend-functions.php @@ -60,24 +60,17 @@ function bdp_add_menu_mein_lv() { add_menu_page( 'Mein BdP', 'BdP', - 'manage_options', + 'show_bdp', $mainSlug, '', BDP_LV_PLUGIN_URL . '/icon.png', 3 ); - /*add_submenu_page($mainSlug, - 'calendar_settings', - 'Kalender-Einstellungen', - 'manage_options', - $moduleLoad . 'calendar' - );*/ - add_submenu_page($mainSlug, - 'calendar_settings', 'Über', - 'manage_options', + 'Über', + 'show_bdp', $moduleLoad . 'about' ); } diff --git a/includes/pre_requires.php b/includes/pre_requires.php index 6cedbae..e500d62 100644 --- a/includes/pre_requires.php +++ b/includes/pre_requires.php @@ -6,3 +6,4 @@ require_once (ABSPATH . '/wp-includes/pluggable.php'); require_once (ABSPATH . '/wp-includes/capabilities.php'); require_once (ABSPATH . '/wp-admin/includes/template.php'); require_once (ABSPATH . '/wp-admin/includes/file.php'); +require_once( ABSPATH . '/wp-admin/includes/upgrade.php' ); \ No newline at end of file diff --git a/includes/roles.php b/includes/roles.php index dd4dd8b..ed69d1d 100644 --- a/includes/roles.php +++ b/includes/roles.php @@ -43,6 +43,7 @@ function kompass_get_capa_stafue() : array function kompass_get_capa_aktionsleitung() : array { return [ + 'show_bdp' => true, 'create_event_teilis' => true, 'edit_event_teilis' => true, 'delete_event_teilis' => true, @@ -53,6 +54,8 @@ function kompass_get_capa_aktionsleitung() : array function kompass_get_capa_grufue() : array { return [ + 'show_bdp' => true, + 'show_groups' => true, 'create_teilis' => true, 'edit_teilis' => true, 'send_mails' => true diff --git a/includes/setup.php b/includes/setup.php index d0b2a0c..4227595 100644 --- a/includes/setup.php +++ b/includes/setup.php @@ -1,9 +1,7 @@ get_charset_collate(); + $fileReader = new FileAccess(); + foreach ([self::KOMPASS_STAMMESGRUPPEN_GRUPPEN, self::KOMPASS_STAMMESGRUPPEN_TEILIS] as $table) { + $sqlTable = $wpdb->prefix . $table; + $sql = "SHOW TABLES LIKE '$sqlTable'"; + + $result = $wpdb->get_var( $sql ); + if ( $result == $sqlTable ) { + continue; + } + + $sqlSetup = str_replace( + '%tablename%', + $sqlTable, + $fileReader->get_contents( WP_PLUGIN_DIR . '/' . BDP_LV_PLUGIN_SLUG . '/lib/database/' . $table . '.sql' ) ); + + $sqlSetup = str_replace('%charset%', $charset, $sqlSetup); + $sqlSetup = str_replace('%prefix%', $wpdb->prefix, $sqlSetup); + + + + dbDelta( $sqlSetup ); + } + + } + public function __construct() + { + add_submenu_page( + BDP_LV_PLUGIN_DIR . '/modules/index.php', + __('Groups', BDP_LV_PLUGIN_SLUG), + __('Groups', BDP_LV_PLUGIN_SLUG), + 'show_groups', + 'kompass-groups', + [$this, 'router'], + 1); + } + + + public function router() + { + if (isset($_REQUEST['action'])) { + switch ($_REQUEST['action']) { + case 'searchmember': + $this->searchMember(); + break; + + default: + kompass_print_gruppen_overview(); + } + } else { + kompass_print_gruppen_overview(); + } + } + + private function searchMember() + { + global $dbHandler; + $members = $dbHandler->readSqlFromDb(self::KOMPASS_STAMMESGRUPPEN_TEILIS, + 'SELECT * FROM %tablename% WHERE CONCAT(`vorname`, " " , `nachname`) LIKE "%' . $_POST['member_name'] . '%"'); + $this->printMembers($members); + } + + private function printMembers(array $memberList) + { + if (count($memberList) === 0) { + exit; + } + kompass_print_gruppen_members($memberList); + } + +} \ No newline at end of file diff --git a/modules/Gruppen/Views/GruppenOverview.php b/modules/Gruppen/Views/GruppenOverview.php new file mode 100644 index 0000000..617dbf8 --- /dev/null +++ b/modules/Gruppen/Views/GruppenOverview.php @@ -0,0 +1,42 @@ + + +
+

+ + +

+
+ + + + + + + + + + + + readFromDb( GruppenController::KOMPASS_STAMMESGRUPPEN_GRUPPEN) as $currentGruppe) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + ?> + +
' . $currentGruppe->gruppen_name .'' . $dbHandler->countSqlRows(GruppenController::KOMPASS_STAMMESGRUPPEN_TEILIS, ['gruppe_id' => $currentGruppe->id]) .'' . + __('Show Members', BDP_LV_PLUGIN_SLUG) . '
+ +

+ +

+ + + + + + + + + + + + + + + + +
vorname . ' ' . $curMember->nachname ?> +
+ +
+ allergien != '' ? $curMember->allergien : '---'); ?> + +
+ + +
+ + + +
+ + + + + +
+ telefon_1); + if ($curMember->telefon_2 != '') { + echo ' // '; + kompass_print_telephone_link( $curMember->telefon_2 ); + } +} diff --git a/modules/seo/includes/meta.php b/modules/seo/includes/meta.php index 0307483..a2ffdce 100644 --- a/modules/seo/includes/meta.php +++ b/modules/seo/includes/meta.php @@ -1,5 +1,5 @@ ' . "\n";