diff --git a/dashboard.php b/dashboard.php
index f6c41bc..f733fe9 100644
--- a/dashboard.php
+++ b/dashboard.php
@@ -7,7 +7,8 @@ $user = current_user();
$canViewUsers = user_has_permission('users.view');
$canManageRoles = user_has_permission('roles.manage');
$canViewRaids = user_has_permission('raids.view');
-$discordId = $user['discord_id'] ?? null;
+$canViewPremades = user_has_permission('premades.view');
+$discordId = $user['discord_id'] ? (int) $user['discord_id'] : null;
$roleStmt = db()->prepare(
"SELECT COALESCE(NULLIF(r.display_name, ''), r.name) AS name
@@ -44,6 +45,39 @@ $nextRaids = array_slice($upcomingRaids, 0, 3);
$memberCount = $canViewUsers ? (int) db()->query("SELECT COUNT(*) FROM users WHERE status = 'active'")->fetchColumn() : null;
$roleCount = $canManageRoles ? (int) db()->query('SELECT COUNT(*) FROM roles')->fetchColumn() : null;
+// Eigene Premade fuer die Dashboard-Kurzuebersicht laden (nur Anzeige, keine Verwaltung -
+// dafuer verweist das Widget auf /premades.php). Faellt bei Bot-Ausfall o.ae. still weg,
+// das restliche Dashboard soll trotzdem laden.
+$myPremade = null;
+$myPremadeNamesByDiscordId = [];
+$myPremadeLinkedUsersByDiscordId = [];
+if ($canViewPremades && $discordId) {
+ try {
+ $myRelation = find_my_premade(fetch_premades(), $discordId);
+ if ($myRelation !== null) {
+ $myPremade = $myRelation['premade'];
+
+ $premadeDiscordIds = [(int) ($myPremade['owner_id'] ?? 0)];
+ foreach ($myPremade['members'] ?? [] as $m) {
+ $premadeDiscordIds[] = (int) ($m['user_id'] ?? 0);
+ }
+ $premadeDiscordIds = array_values(array_unique(array_filter($premadeDiscordIds)));
+ if (!empty($premadeDiscordIds)) {
+ $placeholders = implode(',', array_fill(0, count($premadeDiscordIds), '?'));
+ $stmt = db()->prepare("SELECT id, discord_id, discord_username, display_name, avatar_filename FROM users WHERE discord_id IN ($placeholders)");
+ $stmt->execute($premadeDiscordIds);
+ foreach ($stmt->fetchAll() as $row) {
+ $name = $row['display_name'] !== '' ? $row['display_name'] : $row['discord_username'];
+ $myPremadeNamesByDiscordId[(int) $row['discord_id']] = $name;
+ $myPremadeLinkedUsersByDiscordId[(int) $row['discord_id']] = $row;
+ }
+ }
+ }
+ } catch (Throwable $e) {
+ $myPremade = null;
+ }
+}
+
$pageTitle = 'Dashboard';
include __DIR__ . '/includes/header.php';
?>
@@ -157,4 +191,48 @@ include __DIR__ . '/includes/header.php';
+
+
+
+
+
+
+
+
+
+
+
+ = avatar_html($slotUser, 40) ?>
+
+
= $slot['type'] === 'pending' ? '⏳ ' : '' ?>= e($slot['name']) ?>
+
+
Einladung offen
+
+
+
+
+
+
+ = e($slot['class']) ?>
+
+
+
+
+
= icon('crown') ?>
+
+
+
+
+
+
+
+
+
diff --git a/includes/raids_api.php b/includes/raids_api.php
index 90351fb..8345c12 100644
--- a/includes/raids_api.php
+++ b/includes/raids_api.php
@@ -390,6 +390,61 @@ function find_my_pending_invites(array $premades, int $discordId): array
return $result;
}
+// Bevorzugt den von der Bot-API aufgeloesten Discord-Anzeigenamen (die API kennt Discord direkt,
+// die Website nicht); faellt auf den verknuepften Website-Account und zuletzt auf die rohe
+// Discord-ID zurueck, falls beides fehlt (z.B. Bot offline beim API-Aufruf).
+// Wird sowohl von premades.php als auch vom Dashboard-Widget genutzt.
+function premade_name_for(int $discordId, array $namesByDiscordId, ?string $apiName = null): string
+{
+ if ($apiName !== null && $apiName !== '') {
+ return $apiName;
+ }
+ return $namesByDiscordId[$discordId] ?? ('Discord-Nutzer ' . $discordId);
+}
+
+// Baut ein fuer avatar_html() nutzbares Nutzer-Array: das echte, hochgeladene Profilbild,
+// falls die Discord-ID zu einem verknuepften Website-Account gehoert, sonst ein Platzhalter
+// mit dem Anfangsbuchstaben des (von der API aufgeloesten) Namens.
+function premade_avatar_user(int $discordId, array $linkedUsersByDiscordId, string $displayName): array
+{
+ if (isset($linkedUsersByDiscordId[$discordId])) {
+ return $linkedUsersByDiscordId[$discordId];
+ }
+ return ['id' => $discordId, 'display_name' => $displayName, 'username' => $displayName, 'avatar_filename' => null];
+}
+
+/**
+ * Baut die feste 5er-Slot-Darstellung einer Premade (Lead + bis zu 4 weitere,
+ * mit ausgegrauten Platzhaltern aufgefuellt) - genutzt sowohl von premades.php
+ * als auch vom "Meine Premade"-Widget im Dashboard.
+ *
+ * @param array $premade
+ * @param array $namesByDiscordId
+ * @return array>
+ */
+function build_premade_slots(array $premade, array $namesByDiscordId): array
+{
+ $ownerId = (int) ($premade['owner_id'] ?? 0);
+ $members = is_array($premade['members'] ?? null) ? $premade['members'] : [];
+ $accepted = array_filter($members, fn ($m) => ($m['status'] ?? '') === 'accepted' && (int) ($m['user_id'] ?? 0) !== $ownerId);
+ $pending = array_filter($members, fn ($m) => ($m['status'] ?? '') === 'pending');
+
+ $ownerName = premade_name_for($ownerId, $namesByDiscordId, $premade['owner_name'] ?? null);
+ $slots = [['type' => 'lead', 'id' => $ownerId, 'name' => $ownerName, 'class' => $premade['owner_class'] ?? null]];
+ foreach ($accepted as $member) {
+ $mid = (int) ($member['user_id'] ?? 0);
+ $slots[] = ['type' => 'accepted', 'id' => $mid, 'name' => premade_name_for($mid, $namesByDiscordId, $member['name'] ?? null), 'class' => $member['class'] ?? null];
+ }
+ foreach ($pending as $member) {
+ $mid = (int) ($member['user_id'] ?? 0);
+ $slots[] = ['type' => 'pending', 'id' => $mid, 'name' => premade_name_for($mid, $namesByDiscordId, $member['name'] ?? null), 'class' => $member['class'] ?? null];
+ }
+ while (count($slots) < 5) {
+ $slots[] = ['type' => 'empty'];
+ }
+ return $slots;
+}
+
/**
* Sucht einen einzelnen Raid (inkl. aktueller Signups) anhand seiner ID.
*
diff --git a/premades.php b/premades.php
index 24a0a14..619ff3a 100644
--- a/premades.php
+++ b/premades.php
@@ -39,28 +39,6 @@ if (!empty($allDiscordIds)) {
}
}
-// Bevorzugt den von der Bot-API aufgeloesten Discord-Anzeigenamen (die API kennt Discord direkt,
-// die Website nicht); faellt auf den verknuepften Website-Account und zuletzt auf die rohe
-// Discord-ID zurueck, falls beides fehlt (z.B. Bot offline beim API-Aufruf).
-function premade_name_for(int $discordId, array $namesByDiscordId, ?string $apiName = null): string
-{
- if ($apiName !== null && $apiName !== '') {
- return $apiName;
- }
- return $namesByDiscordId[$discordId] ?? ('Discord-Nutzer ' . $discordId);
-}
-
-// Baut ein fuer avatar_html() nutzbares Nutzer-Array: das echte, hochgeladene Profilbild,
-// falls die Discord-ID zu einem verknuepften Website-Account gehoert, sonst ein Platzhalter
-// mit dem Anfangsbuchstaben des (von der API aufgeloesten) Namens.
-function premade_avatar_user(int $discordId, array $linkedUsersByDiscordId, string $displayName): array
-{
- if (isset($linkedUsersByDiscordId[$discordId])) {
- return $linkedUsersByDiscordId[$discordId];
- }
- return ['id' => $discordId, 'display_name' => $displayName, 'username' => $displayName, 'avatar_filename' => null];
-}
-
$myRelation = $discordId ? find_my_premade($premades, $discordId) : null;
$myPendingInvites = $discordId ? find_my_pending_invites($premades, $discordId) : [];
@@ -180,19 +158,7 @@ include __DIR__ . '/includes/header.php';
'lead', 'id' => $ownerId, 'name' => $ownerName, 'class' => $premade['owner_class'] ?? null]];
- foreach ($accepted as $member) {
- $mid = (int) ($member['user_id'] ?? 0);
- $slots[] = ['type' => 'accepted', 'id' => $mid, 'name' => premade_name_for($mid, $namesByDiscordId, $member['name'] ?? null), 'class' => $member['class'] ?? null];
- }
- foreach ($pending as $member) {
- $mid = (int) ($member['user_id'] ?? 0);
- $slots[] = ['type' => 'pending', 'id' => $mid, 'name' => premade_name_for($mid, $namesByDiscordId, $member['name'] ?? null), 'class' => $member['class'] ?? null];
- }
- while (count($slots) < 5) {
- $slots[] = ['type' => 'empty'];
- }
+ $slots = build_premade_slots($premade, $namesByDiscordId);
$isMemberHere = false;
$myClass = null;
?>