> */ function member_picker_rows(): array { return db()->query( "SELECT u.id, u.discord_id, COALESCE(NULLIF(u.display_name, ''), u.username) AS name, u.avatar_filename, u.class_name, (SELECT COALESCE(NULLIF(r.display_name, ''), r.name) FROM user_roles ur JOIN roles r ON r.id = ur.role_id WHERE ur.user_id = u.id ORDER BY COALESCE(r.roster_order, 999), r.name LIMIT 1) AS top_role FROM users u WHERE u.status = 'active' AND " . sql_is_legion_member('u') . ' ORDER BY name' )->fetchAll(); } /** * Ein Eintrag fuer die Liste. $idField: welche Spalte als Wert gesendet wird (id oder discord_id). * * @return array{id: string, name: string, category: string, icon: ?string, qty: null} */ function member_picker_item(array $row, string $idField = 'id'): array { return [ 'id' => (string) ($row[$idField] ?? ''), 'name' => (string) ($row['name'] ?? ''), 'category' => trim((($row['top_role'] ?? '') ?: 'Mitglied') . (!empty($row['class_name']) ? ' · ' . $row['class_name'] : '')), 'icon' => !empty($row['avatar_filename']) ? '/assets/uploads/avatars/' . rawurlencode((string) $row['avatar_filename']) : null, 'qty' => null, ]; } /** * HTML fuer das Auswahlfeld. * * @param array>|null $items aus member_picker_item(); null = Liste mit dieser ID * steht schon auf der Seite (mehrere Felder teilen sich eine Liste) * @param array{selected?: string, placeholder?: string, required?: bool, input_id?: string, empty?: string} $options */ function member_picker(string $name, string $listId, ?array $items, array $options = []): string { $required = !empty($options['required']); $inputId = $options['input_id'] ?? $listId . '-search'; return '
' . '' . '' . '
' . ($items === null ? '' : ''); }