adasd
This commit is contained in:
@@ -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'] ?? ''];
|
||||
}
|
||||
?>
|
||||
<main class="section">
|
||||
@@ -104,15 +116,15 @@ function membership_level(float $points): string {
|
||||
<div class="stack gap-12" style="margin-top:20px;">
|
||||
<?php foreach ($threads as $t): ?>
|
||||
<?php
|
||||
$pts = $pdo ? compute_points($t, $pdo) : 0.0;
|
||||
$lvl = membership_level($pts);
|
||||
$pts = $pdo ? compute_points($t, $pdo, $pointsCfg) : 0.0;
|
||||
$lvl = membership_level($pts, $levelsCfg);
|
||||
?>
|
||||
<article class="card">
|
||||
<div class="event__body">
|
||||
<div class="event__meta">
|
||||
<span><?= htmlspecialchars($t['created_at'], 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>
|
||||
</div>
|
||||
<h3><a href="/community_thread?id=<?= (int)$t['id'] ?>"><?= htmlspecialchars($t['title'], ENT_QUOTES) ?></a></h3>
|
||||
|
||||
Reference in New Issue
Block a user