LuminaWebsite/includes/premade_order.php
Maaxxs f02b980a97 Legion dues: the bot reminds open members by DM; premades open in the leadership's order
Asked for: "bei den Legionsbeiträgen soll der bot auch die leute drauf erinnern dass ihr beitrag fällig ist ...
die nachricht ist frei definierbar über die website (mit markierungen und erwähnungen) ... eine standardnachricht,
welche zur Legion passt" and "es soll wenn man die seite aufruft standardmäßig die von uns definierte reihenfolge
angezeigt werden".

Dues reminders (includes/dues_reminders.php, admin/dues.php "Erinnerungen per Discord"):
- Who: everyone still open in the running cycle with a linked Discord - not who paid, is exempt or sits in a
  suspended cycle. Automatic (switch, off by default) at the start of the cycle and/or N days before its end, at
  a set hour (settings dues_remind_*); a missed moment is caught up for 24 hours at most, so switching it on in the
  middle of a cycle sends nothing. "Jetzt erinnern" for everyone open right now and "Testnachricht an mich" with
  the text from the form, saved or not.
- The text is free: Discord formatting, placeholders {name}, {erwähnung}, {betrag}, {zyklus}, {bis}, mentions of
  members and channels (channel list from the bot API), toolbar and live preview with the own values
  (assets/js/dues-remind.js). The default text greets with "Arieluma" and is stored empty so improvements arrive.
- Flow: the bot (new cogs/dues_reminders.py, already deployed) asks bot_api.php?action=dues_reminders every minute;
  the website queues due reminders in dues_reminders (at most once per member, cycle and kind) and hands out the
  waiting ones with the finished text, the bot sends them without pings and reports back via
  action=dues_reminders_done, then logs to the log channel. The text is dropped after sending, the log stays 90
  days. The section lists the runs of the running cycle with delivered and not deliverable (with reason).
- Schema version 64 (table also in sql/schema.sql); privacy policy (what is stored, the bot, retention), data export
  section, account deletion, data reset, audit log; patch notes and README.

Premades:
- The page opens in the order the leadership set: own premades are no longer pulled to the top. A chosen sort only
  lives in the address (?sort=) - it survives a reload, not a new visit; the former browser entry
  lumina_premades_sort is removed (and left the privacy policy). Patch notes of the sort and order entries adjusted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 01:32:43 +02:00

57 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
/**
* Standard-Reihenfolge der Premades (premades.php): Die Legionsleitung (premades.manage) legt sie per Drag & Drop
* fest (premade_action.php, Aktion "order"), gespeichert als premade_options.sort_order je Premade-ID. Premades
* ohne Platz (neu gegruendet) stehen dahinter, in der Reihenfolge ihrer Gruendung. So sieht jeder die Seite beim
* Aufruf; eine Sortierung, die man oben waehlt, gilt nur bis zum naechsten Aufruf.
*/
/** Plaetze der Standard-Reihenfolge: [premade_id => Platz ab 1]. */
function premade_order_positions(): array
{
try {
$rows = db()->query('SELECT premade_id, sort_order FROM premade_options WHERE sort_order IS NOT NULL')->fetchAll(PDO::FETCH_KEY_PAIR);
} catch (PDOException $e) {
return []; // Spalte kommt erst mit dem naechsten Schema-Abgleich
}
return array_map('intval', $rows);
}
/**
* Premades in der Standard-Reihenfolge: festgelegte nach ihrem Platz, danach die uebrigen nach der Gruendung (ID).
*
* @param array<int, array<string, mixed>> $premades
* @param array<int, int> $positions premade_order_positions()
* @return array<int, array<string, mixed>>
*/
function premade_order_sort(array $premades, array $positions): array
{
usort($premades, static function (array $a, array $b) use ($positions): int {
$idA = (int) ($a['id'] ?? 0);
$idB = (int) ($b['id'] ?? 0);
return [$positions[$idA] ?? PHP_INT_MAX, $idA] <=> [$positions[$idB] ?? PHP_INT_MAX, $idB];
});
return $premades;
}
/**
* Neue Standard-Reihenfolge speichern: jede Premade aus $premadeIds bekommt ihren Platz (ab 1) - danach hat jede
* ihren festen Platz, neu gegruendete kommen ans Ende.
*
* @param int[] $premadeIds
*/
function premade_order_save(array $premadeIds, int $userId): void
{
$pdo = db();
$pdo->beginTransaction();
$stmt = $pdo->prepare(
'INSERT INTO premade_options (premade_id, sort_order, updated_by) VALUES (?, ?, ?)
ON DUPLICATE KEY UPDATE sort_order = VALUES(sort_order), updated_by = VALUES(updated_by)'
);
foreach (array_values($premadeIds) as $index => $premadeId) {
$stmt->execute([(int) $premadeId, $index + 1, $userId]);
}
$pdo->commit();
}