Files
citrus-cms/resources/views/admin-ajax/get-document-folders-simple.blade.php
2026-04-28 21:15:09 +03:00

43 lines
1.1 KiB
PHP

<?php
/**
* @api-readonly
* Returns simple list of document folders
*/
// resources/views/admin-ajax/get-document-folders-simple.blade.php
$basePath = base_path('storage/documents');
function scanFolders($path, $relativePath = '') {
$items = [];
if (!is_dir($path)) {
return $items;
}
foreach (scandir($path) as $item) {
if ($item === '.' || $item === '..') continue;
$fullPath = $path . DIRECTORY_SEPARATOR . $item;
$itemRelativePath = $relativePath ? $relativePath . '/' . $item : $item;
if (is_dir($fullPath)) {
$pdfCount = count(glob($fullPath . '/*.pdf'));
$items[] = [
'text' => $item,
'path' => $itemRelativePath,
'pdf_count' => $pdfCount,
'children' => scanFolders($fullPath, $itemRelativePath)
];
}
}
usort($items, fn($a, $b) => strcmp($a['text'], $b['text']));
return $items;
}
echo json_encode([
'success' => true,
'folders' => scanFolders($basePath)
]);