Asked for: alliances ("Consilium Elyseum") with their own view, a member-list tab with the allied legions and their
members, an own raid area, a calendar that shows them only alliance entries, and live map sessions the legion can
share with them - watching only, or drawing only with an extra permission. There is one Discord role "Consilium
Elyseum" for all allies, so which legion each ally belongs to is stored on the website.
- Permissions consilium.view / consilium.draw / consilium.manage. An account with consilium.view but without
dashboard.view is a guest of the Consilium (consilium_only(), sql_is_consilium_only()) and sees only the alliance
area; raids, calendar and map stay restricted even with extra rights like raids.view or map.view.
- includes/consilium.php; consilium.php is the allies' start page instead of the dashboard (next raids and entries,
legions, running shared map sessions); admin/consilium.php: setup hints, allied legions, member assignment.
users.consilium_legion_id, table consilium_legions (schema 69); allies pick their legion under Mein Profil.
- Members: new tab "Consilium Elyseum" (legions with their members), the only tab allies see. Legion-only lists
(dues, Lumipunkte, member pickers, raid and activity points) leave allies out.
- Raids: two areas, legion and Consilium, told apart by the Discord channel ("Consilium-Raids" under Verwaltung ->
Discord-Bot, settings.consilium_raid_channel; the bot API returns channel_id). Allies only see and sign up for
Consilium raids, which give no Lumipunkte; raids created in the Consilium area are posted to its channel.
- Calendar: audience "Consilium Elyseum". Allies see only those entries and the Consilium raids (also in their iCal
subscription), their own entries are always Consilium entries; the public calendar shows no Consilium raids; the
legion sees them marked with 🤝.
- Map: whoever may edit a public tactic shares its running live session with the Consilium (consilium_share, logged).
The share lives in the bot's live relay and only for that session: it ends with "Freigabe beenden" or 60 s after
the last legion member left; making the tactic private or deleting it ends it as well. Allies see only running
shared sessions under Karte (and on their start page), join and watch; with consilium.draw they add strokes,
areas, points and text - no figures, nothing moved, erased or undone, no tactics, steps, copies or history.
Enforced in tactics_api.php (guest branch: shared tactics only, only live_token and shape_create) and in the relay
(guest tickets, event whitelist, guests are disconnected when the share ends). Needs the bot update (api.py,
database/db.py, live_tactics.py).
- Navigation, privacy page, patch note, README.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
216 lines
8.1 KiB
PHP
216 lines
8.1 KiB
PHP
<?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',
|
||
];
|
||
|
||
// Anlaesse, die nur das System anlegt (nicht im Formular waehlbar). Vergaben dieser Art
|
||
// lassen sich nicht auf der Lumipunkte-Seite loeschen, sondern nur dort, wo sie entstanden sind.
|
||
const CONTRIBUTION_SYSTEM_CATEGORIES = [
|
||
'shop' => 'Lumishop',
|
||
];
|
||
|
||
// Anlaesse, die automatisch entstehen (nicht im Formular waehlbar), sich aber wie normale
|
||
// Vergaben auf der Lumipunkte-Seite loeschen lassen.
|
||
const CONTRIBUTION_AUTO_CATEGORIES = [
|
||
'activity' => 'Aktivitätscheck',
|
||
'daily' => 'Tägliche Belohnung',
|
||
];
|
||
|
||
// Taegliche Belohnung: so viele Punkte beim ersten Besuch der Website an einem Tag
|
||
const CONTRIBUTION_DAILY_POINTS = 5;
|
||
|
||
// So viele Plaetze zeigt die Rangliste. Mit contributions.view sieht man nur diese, mit
|
||
// contributions.view_all (oder contributions.manage) laesst sich der Rest aufklappen und durchsuchen.
|
||
const CONTRIBUTION_PUBLIC_RANKS = 24;
|
||
|
||
// 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] ?? CONTRIBUTION_SYSTEM_CATEGORIES[$key] ?? CONTRIBUTION_AUTO_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 der Legion (auch 0), hoechster zuerst - Verbuendete aus dem Consilium sammeln
|
||
* keine Lumipunkte.
|
||
*
|
||
* @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' AND " . sql_is_legion_member('u') . "
|
||
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) : '-';
|
||
}
|
||
|
||
/**
|
||
* Taegliche Belohnung: beim ersten Seitenaufruf eines Tages CONTRIBUTION_DAILY_POINTS Punkte.
|
||
* Pro Tag gibt es eine gemeinsame Vergabe ("Tägliche Belohnung"), an die jedes Mitglied beim
|
||
* ersten Besuch angehaengt wird - so bleibt der Verlauf uebersichtlich. Der eindeutige Schluessel
|
||
* (award_id, user_id) verhindert doppelte Punkte, auch bei mehreren Tabs oder Geraeten.
|
||
*
|
||
* @return bool true = gerade gutgeschrieben (fuer die Meldung)
|
||
*/
|
||
function contribution_daily_reward(int $userId): bool
|
||
{
|
||
$today = date('Y-m-d');
|
||
// Pro Sitzung nur einmal am Tag nachsehen
|
||
if (($_SESSION['daily_reward_checked'] ?? '') === $today . ':' . $userId) {
|
||
return false;
|
||
}
|
||
$_SESSION['daily_reward_checked'] = $today . ':' . $userId;
|
||
|
||
$pdo = db();
|
||
try {
|
||
$find = $pdo->prepare("SELECT id FROM contribution_awards WHERE category = 'daily' AND awarded_at = ? ORDER BY id LIMIT 1");
|
||
$find->execute([$today . ' 00:00:00']);
|
||
$awardId = (int) $find->fetchColumn();
|
||
if ($awardId === 0) {
|
||
// Gleichzeitige erste Besuche des Tages duerfen die Vergabe nicht doppelt anlegen
|
||
$pdo->query("SELECT GET_LOCK('lumina_daily_reward', 5)");
|
||
$find->execute([$today . ' 00:00:00']);
|
||
$awardId = (int) $find->fetchColumn();
|
||
if ($awardId === 0) {
|
||
$pdo->prepare(
|
||
"INSERT INTO contribution_awards (category, title, note, awarded_at, created_by) VALUES ('daily', ?, ?, ?, NULL)"
|
||
)->execute([
|
||
'Tägliche Belohnung ' . date('d.m.Y'),
|
||
'Automatisch beim ersten Besuch der Website an diesem Tag',
|
||
$today . ' 00:00:00',
|
||
]);
|
||
$awardId = (int) $pdo->lastInsertId();
|
||
}
|
||
$pdo->query("SELECT RELEASE_LOCK('lumina_daily_reward')");
|
||
}
|
||
$insert = $pdo->prepare('INSERT IGNORE INTO contribution_entries (award_id, user_id, points) VALUES (?, ?, ?)');
|
||
$insert->execute([$awardId, $userId, CONTRIBUTION_DAILY_POINTS]);
|
||
return $insert->rowCount() > 0;
|
||
} catch (PDOException $e) {
|
||
return false;
|
||
}
|
||
}
|