getQuery(true) ->select('*') ->from($db->quoteName('#__eis_documents')) ->order($db->quoteName('ordering') . ' ASC'); $rows = $db->setQuery($query)->loadAssocList(); // Nach parent_id gruppieren und alphabetisch sortieren $grouped = []; foreach ($rows as $row) { $pid = $row['parent_id'] === null ? null : (int) $row['parent_id']; $grouped[$pid][] = $row; } // Sortieren nach name (case-insensitive) foreach ($grouped as &$group) { usort($group, fn($a, $b) => strcasecmp($a['name'], $b['name'])); } return $grouped; } /** * Hauptfunktion zum Rendern des Baums * - Nutzt title als alternativen Anzeigenamen (Fallback name) * - Fügt für Ordner eine klickbare Label-Zeile hinzu (bessere Tap-Ziele auf iPad) * - Liefert data-* Attribute für spätere Inline-Edits / Preview */ public static function renderTree(array $items, ?int $parentId = null): string { if (!isset($items[$parentId])) { return ''; } $html = ''; return $html; } /** * Zählt alle PDF-Dateien unterhalb eines Ordners rekursiv */ private static function countFilesRecursive(array $items, int $parentId): int { $count = 0; if (!isset($items[$parentId])) { return 0; } foreach ($items[$parentId] as $item) { if ((bool) $item['is_folder']) { $count += self::countFilesRecursive($items, (int) $item['id']); } else { $count++; } } return $count; } /** * Formatierte Dateigröße für Tooltip / Anzeige */ private static function formatFileSize(int $bytes): string { if ($bytes >= 1073741824) { return number_format($bytes / 1073741824, 2) . ' GB'; } elseif ($bytes >= 1048576) { return number_format($bytes / 1048576, 1) . ' MB'; } elseif ($bytes >= 1024) { return number_format($bytes / 1024, 0) . ' KB'; } else { return $bytes . ' B'; } } }