Signup is now a single "Anmelden" button that opens a class-icon
picker + optional group choice. A new raid_wish_is_sensible() mirrors
the bot's exact role-cap algorithm (Tank/Heal 1, DPS 3 per 5-player
group, ROLE_MAPPING copied from teamplaner.py) to decide server-side
whether the requested group is honored or the request falls back to
the bot's own auto-assignment - with a message telling the member to
ping the raid lead if they wanted something specific. Verified the
cap logic with 7 synthetic cases (own-signup exclusion, full group,
role caps, bench always allowed) before wiring it up.
Admins get a per-raid edit-mode toggle (pencil icon) that reveals:
inline raid editing (title/date/requirements/gearscore/groups/slots/
group locks) via PATCH, a premade-invite mini-form via the new
premades endpoint, and native HTML5 drag-and-drop to move a signup
between groups/bench via PATCH .../signup/{user_id}.
New pieces: includes/raids_api.php gained move_signup(), update_raid(),
invite_premade(), fetch_premades(), fetch_raid_by_id() and the wish-
sensibility check; four new JSON action endpoints (raid_signup_action,
raid_move_action, raid_edit_action, raid_premade_invite_action) reusing
the session CSRF token via a new verify_csrf_token()/read_json_body()/
json_response() trio in functions.php; assets/js/raids.js drives the
modal, edit-mode, and drag-and-drop with plain fetch() (no framework).
Read-heavy parts (page render, class icons, signup-wish logic) verified
against real data/live API. Edit, move and premade-invite are NOT
tested against the live API yet since they'd mutate the real raid or
send real Discord DMs to guild members - flagging this for a
supervised live check before considering it fully verified.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
73 lines
2.8 KiB
PHP
73 lines
2.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/bootstrap.php';
|
|
require_once __DIR__ . '/includes/raids_api.php';
|
|
require_permission('raids.view');
|
|
|
|
$input = read_json_body();
|
|
verify_csrf_token($input['csrf_token'] ?? '');
|
|
|
|
$user = current_user();
|
|
if (empty($user['discord_id'])) {
|
|
json_response(false, 'Bitte verknüpfe zuerst deinen Discord-Account in "Mein Profil".');
|
|
}
|
|
|
|
$raidId = (int) ($input['raid_id'] ?? 0);
|
|
$class = trim((string) ($input['class'] ?? ''));
|
|
$groupRaw = $input['group'] ?? null; // null/"auto" = automatische Zuteilung, sonst gewuenschte Gruppe (0 = Bank)
|
|
|
|
if ($raidId <= 0 || $class === '') {
|
|
json_response(false, 'Bitte eine Klasse auswählen.');
|
|
}
|
|
|
|
try {
|
|
$raid = fetch_raid_by_id($raidId);
|
|
if (!$raid) {
|
|
json_response(false, 'Raid wurde nicht gefunden.');
|
|
}
|
|
if (!empty($raid['archived'])) {
|
|
json_response(false, 'Dieser Raid ist archiviert. Anmeldungen sind geschlossen.');
|
|
}
|
|
|
|
$maxGroups = count(array_filter(array_map('trim', explode(',', (string) ($raid['groups'] ?? '')))));
|
|
$signups = is_array($raid['signups'] ?? null) ? $raid['signups'] : [];
|
|
$discordId = (int) $user['discord_id'];
|
|
|
|
$wantsAuto = $groupRaw === null || $groupRaw === '' || $groupRaw === 'auto';
|
|
$matchedWish = true;
|
|
$requestGroup = null;
|
|
|
|
if (!$wantsAuto) {
|
|
$desiredGroup = (int) $groupRaw;
|
|
if ($desiredGroup < 0 || $desiredGroup > $maxGroups) {
|
|
json_response(false, 'Ungültige Gruppe ausgewählt.');
|
|
}
|
|
|
|
if (raid_wish_is_sensible($signups, $discordId, $class, $desiredGroup)) {
|
|
$requestGroup = $desiredGroup;
|
|
} else {
|
|
$requestGroup = null; // Bot automatisch zuteilen lassen
|
|
$matchedWish = false;
|
|
}
|
|
}
|
|
|
|
$assigned = raid_signup($raidId, $discordId, (string) $user['discord_username'], $class, $requestGroup);
|
|
$assignedGroup = (int) ($assigned['group'] ?? 0);
|
|
|
|
$groupNames = array_values(array_filter(array_map('trim', explode(',', (string) ($raid['groups'] ?? '')))));
|
|
$assignedGroupLabel = $assignedGroup === 0 ? 'Ersatzbank' : ($groupNames[$assignedGroup - 1] ?? ('Gruppe ' . $assignedGroup));
|
|
|
|
if ($matchedWish) {
|
|
json_response(true, 'Du bist angemeldet: ' . $class . ' in ' . $assignedGroupLabel . '.', [
|
|
'group' => $assignedGroup,
|
|
'matched_wish' => true,
|
|
]);
|
|
} else {
|
|
json_response(true, 'Deine Wunschgruppe war schon voll besetzt für diese Rolle, daher wurdest du automatisch zugeteilt: '
|
|
. $assignedGroupLabel . '. Melde dich gerne beim Raid-Lead, falls du eine Anpassung möchtest.', [
|
|
'group' => $assignedGroup,
|
|
'matched_wish' => false,
|
|
]);
|
|
}
|
|
} catch (Throwable $e) {
|
|
json_response(false, 'Anmeldung fehlgeschlagen: ' . $e->getMessage());
|
|
}
|