LuminaWebsite/admin/role_rank_action.php
Maaxxs 6f2f44d960 Members: the list is sorted by rank within its sections, the rank order is configurable
Asked for: the Lumina Ascendens are divided into ranks (Veteranus, Legionär, Rekrut) and should be lined
up accordingly; the rank order should be adjustable.

- New column roles.rank_order (schema version 58, also in sql/schema.sql): 1 = highest rank, NULL = no
  rank. The upgrade fills it once with the groups that have "Veteranus", "Legionär" or "Rekrut" as a
  word of their own in the name (so not "Rekrutierung").
- Member list, sort "Rang": section first, then the member's highest rank (data-tier), then the name;
  members without a rank come after the ranked ones.
- Berechtigungsgruppen: new panel "Rangordnung" below "Reihenfolge der Tags" - move ranks by drag &
  drop or arrows, remove them with x, add groups from a select (groups with their own section are not
  offered). Saved by admin/role_rank_action.php (roles.manage, audit log). tag-order.js now handles
  both lists, including add/remove; the list rows share role_order_item().
- User administration sorts by rank after the section as well.
- Live updates of the member list include rank_order; README and patch notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 01:23:48 +02:00

50 lines
1.7 KiB
PHP

<?php
/**
* Speichert die Rangordnung (admin/roles.php, "Rangordnung"): die Gruppen in order[] bekommen ihren Platz in
* roles.rank_order (1 = hoechster Rang), alle anderen keinen. Danach sortieren die Mitgliederliste (in ihren
* Abschnitten) und die Benutzerverwaltung.
*/
require_once __DIR__ . '/../includes/bootstrap.php';
require_permission('roles.manage');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/admin/roles.php');
}
verify_csrf();
$pdo = db();
$labels = [];
$before = [];
foreach ($pdo->query("SELECT r.id, COALESCE(NULLIF(r.display_name, ''), r.name) AS label, r.rank_order FROM roles r
ORDER BY r.rank_order IS NULL, r.rank_order, r.name") as $row) {
$labels[(int) $row['id']] = (string) $row['label'];
if ($row['rank_order'] !== null) {
$before[] = (int) $row['id'];
}
}
$order = [];
foreach ((array) ($_POST['order'] ?? []) as $id) {
$id = (int) $id;
if (isset($labels[$id]) && !in_array($id, $order, true)) { // inzwischen geloeschte Gruppen fallen weg
$order[] = $id;
}
}
$pdo->beginTransaction();
$pdo->exec('UPDATE roles SET rank_order = NULL');
$update = $pdo->prepare('UPDATE roles SET rank_order = ? WHERE id = ?');
foreach ($order as $position => $id) {
$update->execute([$position + 1, $id]);
}
$pdo->commit();
if ($order !== $before) {
$list = static fn (array $ids): string => $ids
? mb_strimwidth(implode(', ', array_map(static fn (int $id): string => $labels[$id], $ids)), 0, 500, '…')
: 'keine';
admin_log('🎖️ Rangordnung geändert', ['Vorher' => $list($before), 'Neu' => $list($order)]);
}
set_flash('success', 'Rangordnung gespeichert.');
redirect('/admin/roles.php#rank-order');