From 3ec7c9182bf3b37620a068798d87f6d5a1343b11 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Mon, 29 Dec 2025 02:15:28 +0100 Subject: [PATCH] adasd --- config/community.php | 20 ++++++++++++++++++++ public/page/community.php | 36 ++++++++++++++++++++++++------------ schema.sql | 24 ++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 config/community.php diff --git a/config/community.php b/config/community.php new file mode 100644 index 0000000..3b4c0e6 --- /dev/null +++ b/config/community.php @@ -0,0 +1,20 @@ + [ + 'event_participation' => 0.1, + 'event_create' => 1.0, + 'forum_question' => 0.5, + 'forum_answer' => 1.0, + 'invite' => 0.5, + ], + // Levels with thresholds and optional icons + 'levels' => [ + ['min' => 0, 'label' => 'New Daddy', 'icon' => '🍼'], + ['min' => 5, 'label' => 'Baby Daddy', 'icon' => '👶'], + ['min' => 50, 'label' => 'Mini Daddy', 'icon' => '🧒'], + ['min' => 150, 'label' => 'Good Daddy', 'icon' => '🧔'], + ['min' => 300, 'label' => 'Master Daddy', 'icon' => '🛡️'], + ['min' => 1000, 'label' => 'Daddy of Daddies','icon' => '🏆'], + ], +]; diff --git a/public/page/community.php b/public/page/community.php index e51433c..0415666 100644 --- a/public/page/community.php +++ b/public/page/community.php @@ -32,6 +32,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' } $threads = []; +$configCommunity = require __DIR__ . '/../../config/community.php'; +$pointsCfg = $configCommunity['points'] ?? []; +$levelsCfg = $configCommunity['levels'] ?? []; if ($pdo) { $pdo->prepare('CREATE TABLE IF NOT EXISTS forum_posts ( id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, @@ -57,23 +60,32 @@ if ($pdo) { $threads = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC) ?: []; } -function compute_points(array $row, \PDO $pdo): float { +function compute_points(array $row, \PDO $pdo, array $pointsCfg): float { $uid = (int)$row['uid']; $threads = (int)($row['user_posts'] ?? 0); $answers = (int)($row['answers'] ?? 0); $eventCreated = (int)$pdo->query("SELECT COUNT(*) FROM events WHERE created_by = {$uid}")->fetchColumn(); $eventParticipants = (float)$pdo->query("SELECT COUNT(*) FROM event_participants WHERE user_id = {$uid}")->fetchColumn(); $invites = 0; - return $threads * 0.5 + $answers * 1 + $eventCreated * 1 + $eventParticipants * 0.1 + $invites * 0.5; + return $threads * ($pointsCfg['forum_question'] ?? 0.5) + + $answers * ($pointsCfg['forum_answer'] ?? 1.0) + + $eventCreated * ($pointsCfg['event_create'] ?? 1.0) + + $eventParticipants * ($pointsCfg['event_participation'] ?? 0.1) + + $invites * ($pointsCfg['invite'] ?? 0.5); } -function membership_level(float $points): string { - if ($points >= 1000) return 'Daddy of Daddies'; - if ($points >= 300) return 'Master Daddy'; - if ($points >= 150) return 'Good Daddy'; - if ($points >= 50) return 'Mini Daddy'; - if ($points >= 5) return 'Baby Daddy'; - return 'New Daddy'; +function membership_level(float $points, array $levels): array { + usort($levels, fn($a,$b) => ($b['min'] ?? 0) <=> ($a['min'] ?? 0)); + foreach ($levels as $lvl) { + if ($points >= (float)($lvl['min'] ?? 0)) { + return [ + 'label' => $lvl['label'] ?? 'New Daddy', + 'icon' => $lvl['icon'] ?? '', + ]; + } + } + $fallback = $levels ? $levels[count($levels)-1] : ['label' => 'New Daddy','icon' => '']; + return ['label' => $fallback['label'], 'icon' => $fallback['icon'] ?? '']; } ?>
@@ -104,15 +116,15 @@ function membership_level(float $points): string {
- ( Punkte) + ( Punkte) Beiträge:

diff --git a/schema.sql b/schema.sql index 706a2a3..8ed8022 100644 --- a/schema.sql +++ b/schema.sql @@ -98,6 +98,30 @@ CREATE TABLE event_participants ( CONSTRAINT fk_ep_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +-- Community / Forum +CREATE TABLE forum_threads ( + id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, + user_id BIGINT UNSIGNED NOT NULL, + title VARCHAR(200) NOT NULL, + body TEXT NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT fk_ft_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + INDEX idx_ft_created (created_at) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE forum_posts ( + id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, + thread_id BIGINT UNSIGNED NOT NULL, + user_id BIGINT UNSIGNED NOT NULL, + body TEXT NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT fk_fp_thread FOREIGN KEY (thread_id) REFERENCES forum_threads(id) ON DELETE CASCADE, + CONSTRAINT fk_fp_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + INDEX idx_fp_thread (thread_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + -- Session-Handling (neutral, keine sensiblen Inhalte) CREATE TABLE sessions ( id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,