Members can be awarded contribution points for raids, events and other activities, shown with a golden heart-shaped coin. An award has an occasion, reason, date and points per member; members are picked with search and select all/none, and choosing a raid preselects its participants (signed up in a group and linked to a website account), fills in reason and date and names participants without an account. The + on a member's card awards to that member alone, negative points deduct, and awards can be deleted whole or per member. Balances are always computed from the awards. The ranking shows members as cards with gold/silver/bronze for the top three and the viewer's own balance in the header and sidebar. With only contributions.view it lists the best 25 places plus the viewer's own place; contributions.view_all or contributions.manage show everyone. The history of awards is paginated, using pagination now shared with the warehouse. The sidebar shows the new logo, and the login page and mobile top bar a wordmark cut from it with soft edges. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
243 lines
13 KiB
PHP
243 lines
13 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/bootstrap.php';
|
||
require_once __DIR__ . '/includes/contributions.php';
|
||
require_permission('contributions.view');
|
||
|
||
$canManage = user_has_permission('contributions.manage');
|
||
$canViewAll = $canManage || user_has_permission('contributions.view_all');
|
||
$currentUser = current_user();
|
||
|
||
$balances = contribution_balances();
|
||
$myBalance = contribution_user_balance((int) $currentUser['id']);
|
||
|
||
// Rang: gleiche Punktzahl = gleicher Platz.
|
||
$rank = 0;
|
||
$lastPoints = null;
|
||
foreach ($balances as $index => $member) {
|
||
if ($lastPoints === null || (int) $member['points'] !== $lastPoints) {
|
||
$rank = $index + 1;
|
||
$lastPoints = (int) $member['points'];
|
||
}
|
||
$balances[$index]['rank'] = $rank;
|
||
}
|
||
|
||
// Ohne volle Sicht nur die besten Plaetze - bei Gleichstand an der Grenze alle, die sich den
|
||
// letzten Platz teilen. Der eigene Platz wird trotzdem angezeigt.
|
||
$myEntry = null;
|
||
foreach ($balances as $member) {
|
||
if ((int) $member['id'] === (int) $currentUser['id']) {
|
||
$myEntry = $member;
|
||
}
|
||
}
|
||
$visibleBalances = $canViewAll
|
||
? $balances
|
||
: array_values(array_filter($balances, static fn (array $m): bool => (int) $m['rank'] <= CONTRIBUTION_PUBLIC_RANKS));
|
||
$visibleIds = array_map(static fn (array $m): int => (int) $m['id'], $visibleBalances);
|
||
$showMyEntrySeparately = $myEntry !== null && !in_array((int) $myEntry['id'], $visibleIds, true);
|
||
$hiddenCount = count($balances) - count($visibleBalances);
|
||
|
||
// Verlauf, optional nur fuer ein Mitglied (Klick auf eine Karte).
|
||
$filterUserId = isset($_GET['user']) ? (int) $_GET['user'] : null;
|
||
$filterUser = null;
|
||
// Den Verlauf von Mitgliedern ausserhalb der sichtbaren Plaetze nur mit voller Sicht - sonst
|
||
// liesse sich die Rangliste ueber den Filter doch vollstaendig abfragen.
|
||
if ($filterUserId !== null && !$canViewAll && $filterUserId !== (int) $currentUser['id'] && !in_array($filterUserId, $visibleIds, true)) {
|
||
$filterUserId = null;
|
||
}
|
||
if ($filterUserId !== null) {
|
||
foreach ($balances as $member) {
|
||
if ((int) $member['id'] === $filterUserId) {
|
||
$filterUser = $member;
|
||
}
|
||
}
|
||
if ($filterUser === null) {
|
||
$stmt = db()->prepare("SELECT id, username, display_name, avatar_filename FROM users WHERE id = ?");
|
||
$stmt->execute([$filterUserId]);
|
||
$filterUser = $stmt->fetch() ?: null;
|
||
if ($filterUser) {
|
||
$filterUser['points'] = contribution_user_balance($filterUserId);
|
||
} else {
|
||
$filterUserId = null;
|
||
}
|
||
}
|
||
}
|
||
|
||
$perPage = 20;
|
||
$totalAwards = contribution_award_count($filterUserId);
|
||
$pageCount = max(1, (int) ceil($totalAwards / $perPage));
|
||
$page = min($pageCount, max(1, (int) ($_GET['page'] ?? 1)));
|
||
$awards = contribution_awards($filterUserId, $perPage, ($page - 1) * $perPage);
|
||
|
||
$displayName = static fn (array $u): string => (string) ($u['display_name'] !== '' ? $u['display_name'] : $u['username']);
|
||
|
||
$renderCard = static function (array $member) use ($currentUser, $canManage, $displayName): void {
|
||
?>
|
||
<?php
|
||
$isMe = (int) $member['id'] === (int) $currentUser['id'];
|
||
$rankClass = in_array((int) $member['rank'], [1, 2, 3], true) && (int) $member['points'] > 0 ? ' rank-' . (int) $member['rank'] : '';
|
||
?>
|
||
<div class="contribution-card<?= $isMe ? ' is-me' : '' ?><?= $rankClass ?>" data-name="<?= e(mb_strtolower($displayName($member))) ?>">
|
||
<a class="contribution-card-link" href="/contributions.php?user=<?= (int) $member['id'] ?>#verlauf" title="Verlauf von <?= e($displayName($member)) ?>">
|
||
<span class="contribution-rank">#<?= (int) $member['rank'] ?></span>
|
||
<?= avatar_html($member, 52) ?>
|
||
<span class="contribution-card-name"><?= e($displayName($member)) ?></span>
|
||
<span class="contribution-card-points"><?= contribution_coin(18) ?> <?= contribution_format((int) $member['points']) ?></span>
|
||
</a>
|
||
<?php if ($canManage): ?>
|
||
<a class="icon-button contribution-card-add" href="/contributions_award.php?user=<?= (int) $member['id'] ?>"
|
||
title="Punkte an <?= e($displayName($member)) ?> vergeben" aria-label="Punkte vergeben">+</a>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php
|
||
};
|
||
|
||
$pageTitle = 'Beitragspunkte';
|
||
$containerWide = true;
|
||
include __DIR__ . '/includes/header.php';
|
||
?>
|
||
<div class="panel contribution-hero">
|
||
<img class="contribution-hero-coin" src="/assets/images/beitragspunkt.svg" alt="" width="72" height="72">
|
||
<div class="contribution-hero-text">
|
||
<h1>Beitragspunkte</h1>
|
||
<p class="text-muted">Punkte für Raids, Events und alles, was die Legion voranbringt.</p>
|
||
</div>
|
||
<div class="contribution-hero-balance" title="Dein Punktestand">
|
||
<span class="text-muted">Dein Punktestand</span>
|
||
<strong><?= contribution_coin(26) ?> <?= contribution_format($myBalance) ?></strong>
|
||
</div>
|
||
<?php if ($canManage): ?>
|
||
<a class="button" href="/contributions_award.php">Punkte vergeben</a>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="panel">
|
||
<div class="contribution-head">
|
||
<h2>Rangliste<?= $canViewAll ? '' : ' <span class="contribution-top-label">Top ' . CONTRIBUTION_PUBLIC_RANKS . '</span>' ?></h2>
|
||
<input type="search" id="contribution-search" placeholder="Mitglied suchen …" autocomplete="off">
|
||
</div>
|
||
<?php if (empty($balances)): ?>
|
||
<p class="text-muted">Noch keine Mitglieder.</p>
|
||
<?php else: ?>
|
||
<div class="contribution-grid" id="contribution-ranking">
|
||
<?php foreach ($visibleBalances as $member): ?>
|
||
<?php $renderCard($member); ?>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<p class="text-muted" id="contribution-no-match" hidden>Kein Mitglied passt zur Suche.</p>
|
||
<?php if ($showMyEntrySeparately): ?>
|
||
<div class="contribution-own">
|
||
<h3>Dein Platz</h3>
|
||
<div class="contribution-grid">
|
||
<?php $renderCard($myEntry); ?>
|
||
</div>
|
||
</div>
|
||
<?php endif; ?>
|
||
<?php if ($hiddenCount > 0): ?>
|
||
<p class="text-muted contribution-limit-note">
|
||
Angezeigt werden die besten <?= CONTRIBUTION_PUBLIC_RANKS ?> Plätze. Die vollständige Rangliste
|
||
(<?= count($balances) ?> Mitglieder) ist der Legionsleitung vorbehalten.
|
||
</p>
|
||
<?php endif; ?>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="panel" id="verlauf">
|
||
<div class="contribution-head">
|
||
<h2>
|
||
Verlauf<?= $filterUser ? ': ' . e($displayName($filterUser)) : '' ?>
|
||
<?php if ($filterUser): ?>
|
||
<span class="contribution-filter-balance"><?= contribution_coin(20) ?> <?= contribution_format((int) $filterUser['points']) ?></span>
|
||
<?php endif; ?>
|
||
</h2>
|
||
<?php if ($filterUser): ?>
|
||
<a href="/contributions.php#verlauf">Alle Vergaben anzeigen</a>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<?php if (empty($awards)): ?>
|
||
<p class="text-muted">Noch keine Beitragspunkte vergeben.</p>
|
||
<?php else: ?>
|
||
<div class="contribution-awards">
|
||
<?php foreach ($awards as $award): ?>
|
||
<?php
|
||
$entries = $award['entries'];
|
||
$pointValues = array_unique(array_map(static fn (array $entry): int => (int) $entry['points'], $entries));
|
||
$uniform = count($pointValues) === 1 ? (int) reset($pointValues) : null;
|
||
$mine = null;
|
||
if ($filterUserId !== null) {
|
||
foreach ($entries as $entry) {
|
||
if ((int) $entry['user_id'] === $filterUserId) {
|
||
$mine = (int) $entry['points'];
|
||
}
|
||
}
|
||
}
|
||
$shownPoints = $mine ?? $uniform;
|
||
?>
|
||
<article class="contribution-award">
|
||
<div class="contribution-award-points<?= $shownPoints !== null && $shownPoints < 0 ? ' negative' : '' ?>">
|
||
<?= contribution_coin(22) ?>
|
||
<strong><?= $shownPoints !== null ? contribution_format($shownPoints, true) : 'versch.' ?></strong>
|
||
<?php if ($mine === null && count($entries) > 1): ?>
|
||
<span class="text-muted">je Mitglied</span>
|
||
<?php endif; ?>
|
||
</div>
|
||
<div class="contribution-award-body">
|
||
<div class="contribution-award-title">
|
||
<span class="badge contribution-badge-<?= e((string) $award['category']) ?>"><?= e(contribution_category_label((string) $award['category'])) ?></span>
|
||
<strong><?= e((string) $award['title']) ?></strong>
|
||
</div>
|
||
<?php if (!empty($award['note'])): ?>
|
||
<p class="contribution-award-note"><?= e((string) $award['note']) ?></p>
|
||
<?php endif; ?>
|
||
<div class="contribution-award-meta text-muted">
|
||
<?= e(contribution_format_time($award['awarded_at'])) ?>
|
||
· <?= count($entries) ?> <?= count($entries) === 1 ? 'Mitglied' : 'Mitglieder' ?>
|
||
<?php if (!empty($award['author'])): ?>· vergeben von <?= e((string) $award['author']) ?><?php endif; ?>
|
||
</div>
|
||
<details class="contribution-award-members"<?= count($entries) <= 6 ? ' open' : '' ?>>
|
||
<summary>Mitglieder anzeigen</summary>
|
||
<div class="contribution-chips">
|
||
<?php foreach ($entries as $entry): ?>
|
||
<span class="contribution-chip<?= (int) $entry['user_id'] === $filterUserId ? ' highlight' : '' ?>">
|
||
<a href="/contributions.php?user=<?= (int) $entry['user_id'] ?>#verlauf"><?= e((string) $entry['name']) ?></a>
|
||
<?php if ($uniform === null): ?>
|
||
<span class="text-muted"><?= contribution_format((int) $entry['points'], true) ?></span>
|
||
<?php endif; ?>
|
||
<?php if ($canManage): ?>
|
||
<form class="inline-form" method="post" action="/contributions_action.php"
|
||
onsubmit="return confirm(<?= e(json_encode('„' . $entry['name'] . '“ aus dieser Vergabe entfernen? Die Punkte werden abgezogen.', JSON_UNESCAPED_UNICODE)) ?>);">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="remove_entry">
|
||
<input type="hidden" name="entry_id" value="<?= (int) $entry['id'] ?>">
|
||
<button type="submit" class="contribution-chip-remove" title="Aus der Vergabe entfernen" aria-label="Entfernen">×</button>
|
||
</form>
|
||
<?php endif; ?>
|
||
</span>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
</details>
|
||
</div>
|
||
<?php if ($canManage): ?>
|
||
<form class="contribution-award-delete" method="post" action="/contributions_action.php"
|
||
onsubmit="return confirm(<?= e(json_encode('Vergabe „' . $award['title'] . '“ komplett löschen? Allen ' . count($entries) . ' Mitgliedern werden die Punkte wieder abgezogen.', JSON_UNESCAPED_UNICODE)) ?>);">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="delete_award">
|
||
<input type="hidden" name="award_id" value="<?= (int) $award['id'] ?>">
|
||
<button type="submit" class="icon-button icon-button-danger" title="Vergabe löschen" aria-label="Vergabe löschen"><?= icon('trash') ?></button>
|
||
</form>
|
||
<?php endif; ?>
|
||
</article>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<div class="contribution-pages">
|
||
<span class="text-muted">
|
||
Vergaben <?= ($page - 1) * $perPage + 1 ?>–<?= min($page * $perPage, $totalAwards) ?>
|
||
von <?= number_format($totalAwards, 0, ',', '.') ?>
|
||
</span>
|
||
<?php render_pagination('/contributions.php?' . ($filterUserId !== null ? 'user=' . $filterUserId . '&' : ''), $page, $pageCount, '#verlauf'); ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<script src="/assets/js/contributions.js"></script>
|
||
<?php include __DIR__ . '/includes/footer.php'; ?>
|