Premades: the leadership sees the apply button too, others decide on its own applications

Asked for: "füge ein, dass auch admins den bewerbenknopf bei den premaids sehen". Until now the button was
hidden for everyone with premades.manage, since they can put anyone into a premade directly.

- premades.php: the apply row shows for everyone who is not in the premade yet (the lead is), also below the
  list of open applications. A manager's list and the badge on the card leave out the own application.
- premade_action.php: application_accept/_decline refuse the own application - the lead decides, for premades
  without a lead someone else from the leadership.
- premade_applications_badge(): own applications don't count at the menu item "Premades".
- README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Maaxxs 2026-09-27 00:31:08 +02:00
parent 1c0109264a
commit d8ce29efc9
4 changed files with 24 additions and 6 deletions

View file

@ -346,7 +346,9 @@ Platz in der Gruppe, sonst die Reserve; das vergibt der Bot (`premade_members.re
- Beim Einladen einer Premade in einen Raid kommt ihre Reserve auf die Ersatzbank des Raids. - Beim Einladen einer Premade in einen Raid kommt ihre Reserve auf die Ersatzbank des Raids.
- Das Dashboard zeigt alle eigenen Premades (die geleiteten zuerst). - Das Dashboard zeigt alle eigenen Premades (die geleiteten zuerst).
- **Bewerbungen** (`includes/premade_applications.php`): Unter jeder fremden Premade mit freiem Platz (Gruppe oder - **Bewerbungen** (`includes/premade_applications.php`): Unter jeder fremden Premade mit freiem Platz (Gruppe oder
Reserve) steht „Bewerben“ - im Popup der Platz (Gruppe oder Reserve, nur freie wählbar), die Klasse (Main Reserve) steht „Bewerben“, auch für die Leitung - über deren eigene Bewerbung entscheidet der Lead bzw. jemand
anderes aus der Leitung (sie fehlt in ihrer Liste und Zahl, `premade_action.php` lehnt es ab, selbst zu
entscheiden). Im Popup der Platz (Gruppe oder Reserve, nur freie wählbar), die Klasse (Main
vorausgewählt) und eine Nachricht an den Lead (höchstens 500 Zeichen). Gespeichert auf der Website in vorausgewählt) und eine Nachricht an den Lead (höchstens 500 Zeichen). Gespeichert auf der Website in
`premade_applications` (Premade-ID und -Name, Lead zum Zeitpunkt, Bewerber, Klasse, gewünschter Platz, Nachricht, `premade_applications` (Premade-ID und -Name, Lead zum Zeitpunkt, Bewerber, Klasse, gewünschter Platz, Nachricht,
Status open/accepted/declined/withdrawn/closed, Begründung, wer wann entschieden hat). Grenzen: eine offene Status open/accepted/declined/withdrawn/closed, Begründung, wer wann entschieden hat). Grenzen: eine offene

View file

@ -220,7 +220,7 @@ function premade_applications_dissolved(int $premadeId): void
/** /**
* Offene Bewerbungen, ueber die jemand entscheidet: bei Premades, die er leitet - mit premades.manage auch bei Premades * Offene Bewerbungen, ueber die jemand entscheidet: bei Premades, die er leitet - mit premades.manage auch bei Premades
* ohne Lead (Zahl am Menuepunkt "Premades"). * ohne Lead (Zahl am Menuepunkt "Premades"). Die eigenen zaehlen nicht, ueber die entscheiden andere.
*/ */
function premade_applications_badge(?int $discordId, bool $canManage): int function premade_applications_badge(?int $discordId, bool $canManage): int
{ {
@ -236,8 +236,13 @@ function premade_applications_badge(?int $discordId, bool $canManage): int
if (!$conditions) { if (!$conditions) {
return 0; return 0;
} }
$sql = "SELECT COUNT(*) FROM premade_applications WHERE status = 'open' AND (" . implode(' OR ', $conditions) . ')';
if ($discordId !== null && $discordId > 0) {
$sql .= ' AND discord_id <> ?';
$params[] = $discordId;
}
try { try {
$stmt = db()->prepare("SELECT COUNT(*) FROM premade_applications WHERE status = 'open' AND (" . implode(' OR ', $conditions) . ')'); $stmt = db()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
return (int) $stmt->fetchColumn(); return (int) $stmt->fetchColumn();
} catch (PDOException $e) { } catch (PDOException $e) {

View file

@ -484,6 +484,11 @@ try {
redirect('/premades.php#premade-' . $premadeId); redirect('/premades.php#premade-' . $premadeId);
} }
$applicantId = (int) $application['discord_id']; $applicantId = (int) $application['discord_id'];
if ($applicantId === (int) $discordId) {
// Bewirbt sich die Leitung selbst, entscheidet der Lead bzw. jemand anderes aus der Leitung
set_flash('error', 'Über deine eigene Bewerbung entscheidet der Lead – bei Gruppen ohne Lead jemand anderes aus der Legionsleitung.');
redirect('/premades.php#premade-' . $premadeId);
}
$applicantName = premade_applicant_name($application); $applicantName = premade_applicant_name($application);
$decide = db()->prepare("UPDATE premade_applications SET status = ?, reason = ?, decided_by = ?, decided_at = NOW() WHERE id = ? AND status = 'open'"); $decide = db()->prepare("UPDATE premade_applications SET status = ?, reason = ?, decided_by = ?, decided_at = NOW() WHERE id = ? AND status = 'open'");
if ($action === 'application_accept') { if ($action === 'application_accept') {

View file

@ -261,7 +261,10 @@ include __DIR__ . '/includes/header.php';
$reserveFree = $reserveCount < PREMADE_RESERVE_SLOTS; $reserveFree = $reserveCount < PREMADE_RESERVE_SLOTS;
$banner = $banners[$premadeId] ?? null; $banner = $banners[$premadeId] ?? null;
$hasBanner = $banner !== null && $banner['url'] !== null; $hasBanner = $banner !== null && $banner['url'] !== null;
$premadeApplications = $canManageThis ? ($openApplications[$premadeId] ?? []) : []; // Offene Bewerbungen zum Entscheiden - ohne die eigene (bewirbt sich die Leitung selbst, entscheidet der
// Lead bzw. jemand anderes aus der Leitung)
$premadeApplications = $canManageThis ? array_values(array_filter($openApplications[$premadeId] ?? [],
static fn (array $application): bool => (int) $application['discord_id'] !== (int) $discordId)) : [];
$applicationsClosed = isset($closedApplications[$premadeId]); $applicationsClosed = isset($closedApplications[$premadeId]);
?> ?>
<div class="panel premade-panel<?= $hasBanner ? ' has-banner' : '' ?>" id="premade-<?= $premadeId ?>" data-premade-id="<?= $premadeId ?>"> <div class="panel premade-panel<?= $hasBanner ? ' has-banner' : '' ?>" id="premade-<?= $premadeId ?>" data-premade-id="<?= $premadeId ?>">
@ -475,9 +478,12 @@ include __DIR__ . '/includes/header.php';
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
<?php elseif (!$canManageThis && $discordId !== null && !premade_has_user($premade, $discordId)): ?> <?php endif; ?>
<?php if ($discordId !== null && !premade_has_user($premade, $discordId)): ?>
<?php <?php
// Bewerben: bei jeder Premade mit freiem Platz, solange der Lead es nicht abgeschaltet hat // Bewerben: bei jeder Premade mit freiem Platz, solange der Lead es nicht abgeschaltet hat - auch
// fuer die Leitung, die sich sonst nur direkt eintragen koennte
$applyBlocker = premade_application_blocker($premade, $discordId, $myApplications, $applicationsClosed); $applyBlocker = premade_application_blocker($premade, $discordId, $myApplications, $applicationsClosed);
?> ?>
<div class="premade-apply"> <div class="premade-apply">