LuminaWebsite/includes/contributions.php
Maaxxs 5f25e20900 Kina in the warehouse, Lumipunkte, new logo, versioned assets
Warehouse: Kina (the game currency) can be paid in and out, shown in its own
box with the in-game coin icon (Icon_Currency_Coin_GoldNonbinding from the
game client via aion2.app, since the wiki has none). It is a catalog item in
the new "Währung" category, kept out of the item cards and totals, and
allows up to a trillion per entry; warehouse_movements.quantity becomes
BIGINT for that. A leftover "Kinah" entry is merged into "Kina".

Beitragspunkte are renamed to Lumipunkte in every visible text, the coin is
now lumipunkt.svg, and the schema sync also updates the descriptions of
existing core permissions so the new name reaches the role editor.

The sidebar, login page and mobile top bar show the new Lumina Ascendens
logo, cropped and with its dark background made transparent.

Scripts and the stylesheet are included with a ?v=<mtime> query
(asset_url()), so browsers pick up new versions after an upload instead of
running stale JavaScript - the cause of raid points not being saved.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 10:25:28 +02:00

152 lines
5.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
/**
* Lumipunkte: Punkte, die Mitglieder fuer Raids und andere Aktivitaeten bekommen.
*
* Eine Vergabe (contribution_awards) ist ein Anlass mit Grund und Datum, an dem ein oder
* mehrere Mitglieder beteiligt sind (contribution_entries, je Mitglied die Punkte). Der
* Punktestand wird nicht gespeichert, sondern aus der Summe berechnet - so kann er nie von
* der Historie abweichen, und spaeter lassen sich Punkte auch ausgeben (negative Eintraege).
*/
const CONTRIBUTION_CATEGORIES = [
'raid' => 'Raid',
'event' => 'Event',
'other' => 'Sonstiges',
];
// So viele Plaetze der Rangliste sieht jeder mit contributions.view - den Rest nur mit
// contributions.view_all (oder contributions.manage).
const CONTRIBUTION_PUBLIC_RANKS = 25;
// Obergrenze pro Mitglied und Vergabe - schuetzt vor Tippfehlern wie 10000 statt 100.
const CONTRIBUTION_MAX_POINTS = 10000;
function contribution_category_label(string $key): string
{
return CONTRIBUTION_CATEGORIES[$key] ?? $key;
}
/** Das Muenz-Symbol der Lumipunkte. */
function contribution_coin(int $size = 20): string
{
return '<img class="contribution-coin" src="/assets/images/lumipunkt.svg" alt="Lumipunkte" '
. 'width="' . $size . '" height="' . $size . '">';
}
/** Punkte mit Tausenderpunkt, Abzuege mit echtem Minuszeichen. */
function contribution_format(int $points, bool $withSign = false): string
{
$formatted = number_format(abs($points), 0, ',', '.');
if ($points < 0) {
return '−' . $formatted;
}
return ($withSign && $points > 0 ? '+' : '') . $formatted;
}
/**
* Punktestand aller aktiven Mitglieder (auch 0), hoechster zuerst.
*
* @return array<int, array<string, mixed>>
*/
function contribution_balances(): array
{
return db()->query(
"SELECT u.id, u.username, u.display_name, u.avatar_filename,
COALESCE(SUM(e.points), 0) AS points,
COUNT(e.id) AS award_count
FROM users u
LEFT JOIN contribution_entries e ON e.user_id = u.id
WHERE u.status = 'active'
GROUP BY u.id
ORDER BY points DESC, COALESCE(NULLIF(u.display_name, ''), u.username)"
)->fetchAll();
}
function contribution_user_balance(int $userId): int
{
$stmt = db()->prepare('SELECT COALESCE(SUM(points), 0) FROM contribution_entries WHERE user_id = ?');
$stmt->execute([$userId]);
return (int) $stmt->fetchColumn();
}
function contribution_award_count(?int $userId): int
{
if ($userId === null) {
return (int) db()->query('SELECT COUNT(*) FROM contribution_awards')->fetchColumn();
}
$stmt = db()->prepare('SELECT COUNT(*) FROM contribution_entries WHERE user_id = ?');
$stmt->execute([$userId]);
return (int) $stmt->fetchColumn();
}
/**
* Vergaben mit ihren Empfaengern, neueste zuerst. Mit $userId nur die Vergaben, an denen
* dieses Mitglied beteiligt war.
*
* @return array<int, array<string, mixed>>
*/
function contribution_awards(?int $userId, int $limit, int $offset): array
{
$join = $userId !== null ? 'JOIN contribution_entries mine ON mine.award_id = a.id AND mine.user_id = ?' : '';
$stmt = db()->prepare(
"SELECT a.id, a.category, a.title, a.note, a.raid_id, a.awarded_at,
COALESCE(NULLIF(cu.display_name, ''), cu.username) AS author
FROM contribution_awards a
$join
LEFT JOIN users cu ON cu.id = a.created_by
ORDER BY a.awarded_at DESC, a.id DESC
LIMIT " . (int) $limit . ' OFFSET ' . (int) $offset
);
$stmt->execute($userId !== null ? [$userId] : []);
$awards = [];
foreach ($stmt->fetchAll() as $row) {
$row['entries'] = [];
$awards[(int) $row['id']] = $row;
}
if (empty($awards)) {
return [];
}
$ids = array_keys($awards);
$placeholders = implode(',', array_fill(0, count($ids), '?'));
$entryStmt = db()->prepare(
"SELECT e.id, e.award_id, e.user_id, e.points,
COALESCE(NULLIF(u.display_name, ''), u.username) AS name
FROM contribution_entries e
JOIN users u ON u.id = e.user_id
WHERE e.award_id IN ($placeholders)
ORDER BY name"
);
$entryStmt->execute($ids);
foreach ($entryStmt->fetchAll() as $entry) {
$awards[(int) $entry['award_id']]['entries'][] = $entry;
}
return array_values($awards);
}
/** Jetzt in deutscher Zeit fuer ein datetime-local-Feld. */
function contribution_now_input(): string
{
return (new DateTimeImmutable('now', new DateTimeZone('Europe/Berlin')))->format('Y-m-d\TH:i');
}
/** Zeitpunkt aus einem datetime-local-Feld, null bei ungueltiger Eingabe oder weit in der Zukunft. */
function contribution_parse_time(string $value): ?string
{
$tz = new DateTimeZone('Europe/Berlin');
$time = DateTimeImmutable::createFromFormat('Y-m-d\TH:i', trim($value), $tz);
if ($time === false || $time > new DateTimeImmutable('+1 day', $tz)) {
return null;
}
return $time->format('Y-m-d H:i:s');
}
function contribution_format_time(?string $value): string
{
$time = $value ? strtotime($value) : false;
return $time ? date('d.m.Y H:i', $time) : '-';
}