This commit is contained in:
2025-12-29 02:15:28 +01:00
parent 33482a0291
commit 3ec7c9182b
3 changed files with 68 additions and 12 deletions

20
config/community.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
return [
// Points per action
'points' => [
'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' => '🏆'],
],
];

View File

@@ -32,6 +32,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
} }
$threads = []; $threads = [];
$configCommunity = require __DIR__ . '/../../config/community.php';
$pointsCfg = $configCommunity['points'] ?? [];
$levelsCfg = $configCommunity['levels'] ?? [];
if ($pdo) { if ($pdo) {
$pdo->prepare('CREATE TABLE IF NOT EXISTS forum_posts ( $pdo->prepare('CREATE TABLE IF NOT EXISTS forum_posts (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
@@ -57,23 +60,32 @@ if ($pdo) {
$threads = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC) ?: []; $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']; $uid = (int)$row['uid'];
$threads = (int)($row['user_posts'] ?? 0); $threads = (int)($row['user_posts'] ?? 0);
$answers = (int)($row['answers'] ?? 0); $answers = (int)($row['answers'] ?? 0);
$eventCreated = (int)$pdo->query("SELECT COUNT(*) FROM events WHERE created_by = {$uid}")->fetchColumn(); $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(); $eventParticipants = (float)$pdo->query("SELECT COUNT(*) FROM event_participants WHERE user_id = {$uid}")->fetchColumn();
$invites = 0; $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 { function membership_level(float $points, array $levels): array {
if ($points >= 1000) return 'Daddy of Daddies'; usort($levels, fn($a,$b) => ($b['min'] ?? 0) <=> ($a['min'] ?? 0));
if ($points >= 300) return 'Master Daddy'; foreach ($levels as $lvl) {
if ($points >= 150) return 'Good Daddy'; if ($points >= (float)($lvl['min'] ?? 0)) {
if ($points >= 50) return 'Mini Daddy'; return [
if ($points >= 5) return 'Baby Daddy'; 'label' => $lvl['label'] ?? 'New Daddy',
return 'New Daddy'; 'icon' => $lvl['icon'] ?? '',
];
}
}
$fallback = $levels ? $levels[count($levels)-1] : ['label' => 'New Daddy','icon' => ''];
return ['label' => $fallback['label'], 'icon' => $fallback['icon'] ?? ''];
} }
?> ?>
<main class="section"> <main class="section">
@@ -104,15 +116,15 @@ function membership_level(float $points): string {
<div class="stack gap-12" style="margin-top:20px;"> <div class="stack gap-12" style="margin-top:20px;">
<?php foreach ($threads as $t): ?> <?php foreach ($threads as $t): ?>
<?php <?php
$pts = $pdo ? compute_points($t, $pdo) : 0.0; $pts = $pdo ? compute_points($t, $pdo, $pointsCfg) : 0.0;
$lvl = membership_level($pts); $lvl = membership_level($pts, $levelsCfg);
?> ?>
<article class="card"> <article class="card">
<div class="event__body"> <div class="event__body">
<div class="event__meta"> <div class="event__meta">
<span><?= htmlspecialchars($t['created_at'], ENT_QUOTES) ?></span> <span><?= htmlspecialchars($t['created_at'], ENT_QUOTES) ?></span>
<span><?= htmlspecialchars($t['display_name'] ?: 'Mitglied', ENT_QUOTES) ?></span> <span><?= htmlspecialchars($t['display_name'] ?: 'Mitglied', ENT_QUOTES) ?></span>
<span><?= htmlspecialchars($lvl, ENT_QUOTES) ?> (<?= number_format($pts,1) ?> Punkte)</span> <span><?= htmlspecialchars($lvl['icon'] ?? '', ENT_QUOTES) ?> <?= htmlspecialchars($lvl['label'] ?? '', ENT_QUOTES) ?> (<?= number_format($pts,1) ?> Punkte)</span>
<span>Beiträge: <?= (int)$t['user_posts'] + (int)$t['answers'] ?></span> <span>Beiträge: <?= (int)$t['user_posts'] + (int)$t['answers'] ?></span>
</div> </div>
<h3><a href="/community_thread?id=<?= (int)$t['id'] ?>"><?= htmlspecialchars($t['title'], ENT_QUOTES) ?></a></h3> <h3><a href="/community_thread?id=<?= (int)$t['id'] ?>"><?= htmlspecialchars($t['title'], ENT_QUOTES) ?></a></h3>

View File

@@ -98,6 +98,30 @@ CREATE TABLE event_participants (
CONSTRAINT fk_ep_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE CONSTRAINT fk_ep_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ) 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) -- Session-Handling (neutral, keine sensiblen Inhalte)
CREATE TABLE sessions ( CREATE TABLE sessions (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,