LuminaWebsite/admin/role_order_action.php
Maaxxs 0e00f35923 Tag order: the leadership sets the order of the group tags
Until now the tags of a member were sorted by rank group first and then by the internal name, so
"Legionär" came before PvE while "Veteranus" came last. Verwaltung -> Berechtigungsgruppen now has
"Reihenfolge der Tags": move groups by drag & drop (mouse: whole row, finger: grip) or with the
arrows, then save.

- New column roles.tag_order (schema version 56, also in sql/schema.sql), saved by
  admin/role_order_action.php (roles.manage) with before/after in the audit log.
- ROLE_TAG_ORDER_SQL and role_tags_sorted() in includes/permissions.php sort the tags in the member
  list and its group filter, on the profile page, in the dashboard and in the user admin. Groups
  without a position (before the first save, or created later) follow in the old order.
- The rank of a member (sections of the member list) still depends only on roster_order.
- Live updates of the member list react to a new order; README and patch notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:59:25 +02:00

49 lines
1.8 KiB
PHP

<?php
/**
* Speichert die Reihenfolge der Gruppen-Tags (admin/roles.php, "Reihenfolge der Tags"): jede Gruppe bekommt
* ihren Platz in roles.tag_order. Sortiert wird damit ueberall ueber ROLE_TAG_ORDER_SQL (includes/permissions.php).
*/
require_once __DIR__ . '/../includes/bootstrap.php';
require_permission('roles.manage');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/admin/roles.php');
}
verify_csrf();
$pdo = db();
// Bisherige Reihenfolge - Gruppen, die hier fehlen (inzwischen angelegt), behalten dahinter ihren Platz
$labels = [];
foreach ($pdo->query("SELECT r.id, COALESCE(NULLIF(r.display_name, ''), r.name) AS label FROM roles r ORDER BY " . ROLE_TAG_ORDER_SQL) as $row) {
$labels[(int) $row['id']] = (string) $row['label'];
}
$before = array_keys($labels);
$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;
}
}
foreach ($before as $id) {
if (!in_array($id, $order, true)) {
$order[] = $id;
}
}
// Auch unveraendert speichern: danach hat jede Gruppe ihren festen Platz, neue kommen ans Ende
$pdo->beginTransaction();
$update = $pdo->prepare('UPDATE roles SET tag_order = ? WHERE id = ?');
foreach ($order as $position => $id) {
$update->execute([$position + 1, $id]);
}
$pdo->commit();
if ($order !== $before) {
$list = static fn (array $ids): string => mb_strimwidth(implode(', ', array_map(static fn (int $id): string => $labels[$id], $ids)), 0, 500, '…');
admin_log('🏷️ Reihenfolge der Tags geändert', ['Vorher' => $list($before), 'Neu' => $list($order)]);
}
set_flash('success', 'Reihenfolge der Tags gespeichert.');
redirect('/admin/roles.php#tag-order');