|
@@ -245,34 +245,18 @@ class FolderController extends Controller
|
|
|
|
|
|
$folderObjectType->modelBuilderAllowed()->findOrFail($objectId);
|
|
|
|
|
|
- $foldsCount = Folder::query()
|
|
|
- ->where('parent_id',0)
|
|
|
- ->where('object_type',$objectType)
|
|
|
- ->whereIn("object_id", $folderId)
|
|
|
- ->selectRaw("count(*) as cut, object_id")
|
|
|
- ->groupBy("object_id")
|
|
|
- ->pluck("cut", "object_id");
|
|
|
-
|
|
|
- $fileCount = File::query()
|
|
|
- ->where('object_type',$objectType)
|
|
|
- ->whereIn('object_id',$folderId)
|
|
|
- ->where("is_latest_version", 1)
|
|
|
- ->selectRaw("count(*) as cut, object_id")
|
|
|
- ->groupBy("object_id")
|
|
|
- ->pluck("cut", "object_id");
|
|
|
-
|
|
|
|
|
|
$objectWhere = ['object_type' => $objectType, 'object_id' => $objectId,];
|
|
|
$folders = Folder::query()
|
|
|
->where($objectWhere)
|
|
|
->when($folderId, fn($query) => $query->where("parent_id", $folderId))
|
|
|
->when(! $folderId, fn($query) => $query->where("parent_id", 0))
|
|
|
- ->get(['id', 'name']);
|
|
|
+ ->get(['id', 'name'])->each(function ($folders)use ($folderId){
|
|
|
+ $folderCount=Folder::query()->where('parent_id',$folders->id)->count();
|
|
|
+ $filesCount=File::query()->where('folder_id',$folderId>0?$folders->id:$folderId)->where("is_latest_version", 1)->count();
|
|
|
+ $folders->itemCount=$folderCount+$filesCount;
|
|
|
+ });
|
|
|
|
|
|
- $folders = $folders->map(function (Folder $folder) use ($foldsCount,$fileCount) {
|
|
|
- $folder->itemCount =$foldsCount->get($folder->id, 0)+$fileCount->get($folder->id, 0);
|
|
|
- return $folder;
|
|
|
- });
|
|
|
|
|
|
$files = File::query()->where($objectWhere)
|
|
|
->where("folder_id", $folderId)
|