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>
160 lines
6.3 KiB
PHP
160 lines
6.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Consilium Elyseum - das Buendnis mit anderen Legionen. Ihre Mitglieder melden sich wie alle ueber Discord an und
|
|
* haben dort die eine Rolle "Consilium Elyseum" (keine Rolle je Legion). Die damit verknuepfte Gruppe gibt
|
|
* consilium.view, aber kein dashboard.view - so sehen sie nur ihre eigene Ansicht (consilium.php) und zaehlen nirgends
|
|
* zur Legion (siehe sql_is_legion_member() in includes/permissions.php).
|
|
*
|
|
* Zu welcher verbuendeten Legion jemand gehoert, steht auf der Website: Die Leitung legt die Legionen an
|
|
* (admin/consilium.php, consilium.manage) und ordnet die Mitglieder zu, jedes Mitglied kann seine Legion auch selbst
|
|
* im Profil waehlen (users.consilium_legion_id).
|
|
*/
|
|
|
|
const CONSILIUM_NAME = 'Consilium Elyseum';
|
|
const CONSILIUM_LEGION_NAME_MAX = 80;
|
|
|
|
/**
|
|
* Die verbuendeten Legionen in ihrer Reihenfolge, mit der Zahl ihrer (aktiven) Mitglieder.
|
|
*
|
|
* @return array<int, array{id: int, name: string, sort_order: int, member_count: int}>
|
|
*/
|
|
function consilium_legions(): array
|
|
{
|
|
try {
|
|
$rows = db()->query(
|
|
"SELECT l.id, l.name, l.sort_order,
|
|
(SELECT COUNT(*) FROM users u WHERE u.consilium_legion_id = l.id AND u.status = 'active'
|
|
AND " . sql_is_consilium_only('u') . ") AS member_count
|
|
FROM consilium_legions l ORDER BY l.sort_order, l.name"
|
|
)->fetchAll();
|
|
} catch (PDOException $e) {
|
|
return []; // Tabelle kommt erst mit dem naechsten Schema-Abgleich
|
|
}
|
|
return array_map(static fn (array $row): array => [
|
|
'id' => (int) $row['id'],
|
|
'name' => (string) $row['name'],
|
|
'sort_order' => (int) $row['sort_order'],
|
|
'member_count' => (int) $row['member_count'],
|
|
], $rows);
|
|
}
|
|
|
|
/**
|
|
* Mitglieder des Consiliums (verbuendete Legionen, nicht die eigene), nach Name - fuer die Mitgliederliste nur aktive,
|
|
* fuer die Verwaltung auch solche, die noch auf die Freischaltung warten.
|
|
*
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
function consilium_members(bool $withPending = false): array
|
|
{
|
|
try {
|
|
return db()->query(
|
|
"SELECT u.id, u.username, u.display_name, u.discord_id, u.discord_username, u.avatar_filename, u.class_name,
|
|
u.classes, u.status, u.consilium_legion_id,
|
|
COALESCE(u.last_seen_at, u.last_login) AS last_active,
|
|
COALESCE(u.discord_joined_at, u.created_at) AS joined_at
|
|
FROM users u
|
|
WHERE u.status " . ($withPending ? "IN ('active', 'pending')" : "= 'active'") . '
|
|
AND ' . sql_is_consilium_only('u') . "
|
|
ORDER BY COALESCE(NULLIF(u.display_name, ''), u.username)"
|
|
)->fetchAll();
|
|
} catch (PDOException $e) {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Ist das Consilium eingerichtet? Erst dann sieht die Legion es in Menue und Mitgliederliste - vorher waere es nur
|
|
* ein leerer Reiter. Eingerichtet heisst: Es gibt eine verbuendete Legion oder eine Gruppe des Consiliums
|
|
* (consilium.view ohne dashboard.view - die Administrator-Gruppe bekommt neue Rechte automatisch und zaehlt nicht).
|
|
*/
|
|
function consilium_enabled(): bool
|
|
{
|
|
static $enabled = null;
|
|
if ($enabled === null) {
|
|
try {
|
|
$enabled = (bool) db()->query('SELECT 1 FROM consilium_legions LIMIT 1')->fetchColumn()
|
|
|| (bool) db()->query(
|
|
"SELECT 1 FROM role_permissions rp JOIN permissions p ON p.id = rp.permission_id
|
|
WHERE p.`key` = 'consilium.view'
|
|
AND NOT EXISTS (SELECT 1 FROM role_permissions rp2 JOIN permissions p2 ON p2.id = rp2.permission_id
|
|
WHERE rp2.role_id = rp.role_id AND p2.`key` = 'dashboard.view')
|
|
LIMIT 1"
|
|
)->fetchColumn();
|
|
} catch (PDOException $e) {
|
|
$enabled = false;
|
|
}
|
|
}
|
|
return $enabled;
|
|
}
|
|
|
|
/**
|
|
* Die naechsten Consilium-Termine aus dem Kalender (freigegeben, ab jetzt) fuer die Startseite.
|
|
*
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
function consilium_upcoming_entries(int $limit = 5): array
|
|
{
|
|
try {
|
|
$stmt = db()->prepare(
|
|
"SELECT e.id, e.title, e.starts_at,
|
|
(SELECT COUNT(*) FROM calendar_participants p JOIN users pu ON pu.id = p.user_id
|
|
WHERE p.entry_id = e.id AND pu.status = 'active') AS people
|
|
FROM calendar_entries e JOIN users u ON u.id = e.user_id
|
|
WHERE e.audience = 'consilium' AND e.status = 'visible' AND u.status = 'active' AND e.starts_at >= ?
|
|
ORDER BY e.starts_at LIMIT " . max(1, $limit)
|
|
);
|
|
$stmt->execute([date('Y-m-d H:i:s', strtotime('-2 hours'))]);
|
|
return $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/** Gibt es diese Legion? */
|
|
function consilium_legion_exists(int $legionId): bool
|
|
{
|
|
$stmt = db()->prepare('SELECT 1 FROM consilium_legions WHERE id = ?');
|
|
$stmt->execute([$legionId]);
|
|
return (bool) $stmt->fetchColumn();
|
|
}
|
|
|
|
/** Name einer Legion oder null. */
|
|
function consilium_legion_name(?int $legionId): ?string
|
|
{
|
|
if ($legionId === null) {
|
|
return null;
|
|
}
|
|
$stmt = db()->prepare('SELECT name FROM consilium_legions WHERE id = ?');
|
|
$stmt->execute([$legionId]);
|
|
$name = $stmt->fetchColumn();
|
|
return $name === false ? null : (string) $name;
|
|
}
|
|
|
|
/** Gehoert das Konto nur zum Consilium (nicht zur Legion)? Fuer andere Konten als das angemeldete. */
|
|
function consilium_is_member_account(int $userId): bool
|
|
{
|
|
$stmt = db()->prepare('SELECT 1 FROM users u WHERE u.id = ? AND ' . sql_is_consilium_only('u'));
|
|
$stmt->execute([$userId]);
|
|
return (bool) $stmt->fetchColumn();
|
|
}
|
|
|
|
/** Legion eines Kontos (users.consilium_legion_id) oder null. */
|
|
function consilium_member_legion_id(int $userId): ?int
|
|
{
|
|
try {
|
|
$stmt = db()->prepare('SELECT consilium_legion_id FROM users WHERE id = ?');
|
|
$stmt->execute([$userId]);
|
|
$legionId = $stmt->fetchColumn();
|
|
} catch (PDOException $e) {
|
|
return null;
|
|
}
|
|
return $legionId === false || $legionId === null ? null : (int) $legionId;
|
|
}
|
|
|
|
/** Ein Mitglied einer verbuendeten Legion zuordnen (null = keiner). */
|
|
function consilium_set_member_legion(int $userId, ?int $legionId): void
|
|
{
|
|
db()->prepare('UPDATE users SET consilium_legion_id = ? WHERE id = ?')->execute([$legionId, $userId]);
|
|
}
|