1313use App \Actions \Album \Transfer ;
1414use App \Actions \Search \Strategies \Album \AlbumFieldLikeStrategy ;
1515use App \DTO \Search \SearchToken ;
16- use App \Enum \AspectRatioType ;
1716use App \Enum \ColumnSortingAlbumType ;
1817use App \Enum \ColumnSortingPhotoType ;
1918use App \Enum \LicenseType ;
2019use App \Enum \OrderSortingType ;
21- use App \Enum \PhotoLayoutType ;
22- use App \Enum \TimelineAlbumGranularity ;
23- use App \Enum \TimelinePhotoGranularity ;
2420use App \Http \Requests \Admin \BulkAlbumEdit \DeleteBulkAlbumRequest ;
2521use App \Http \Requests \Admin \BulkAlbumEdit \IdsBulkAlbumRequest ;
2622use App \Http \Requests \Admin \BulkAlbumEdit \IndexBulkAlbumRequest ;
3026use App \Http \Resources \Admin \BulkAlbumResource ;
3127use App \Http \Resources \Admin \PaginatedBulkAlbumResource ;
3228use App \Models \Album ;
33- use Carbon \Carbon ;
3429use Illuminate \Routing \Controller ;
3530use Illuminate \Support \Facades \DB ;
3631
@@ -54,49 +49,16 @@ public function index(IndexBulkAlbumRequest $request): PaginatedBulkAlbumResourc
5449 $ per_page = (int ) $ request ->validated ('per_page ' , 50 );
5550 $ page = (int ) $ request ->validated ('page ' , 1 );
5651
57- $ query = DB ::table ('albums ' )
58- ->join ('base_albums ' , 'base_albums.id ' , '= ' , 'albums.id ' )
59- ->join ('users ' , 'users.id ' , '= ' , 'base_albums.owner_id ' )
60- ->leftJoin ('access_permissions as ap ' , function ($ join ): void {
61- $ join ->on ('ap.base_album_id ' , '= ' , 'base_albums.id ' )
62- ->whereNull ('ap.user_id ' )
63- ->whereNull ('ap.user_group_id ' );
64- })
65- ->select ([
66- 'albums.id ' ,
67- 'base_albums.title ' ,
68- 'base_albums.owner_id ' ,
69- DB ::raw ('COALESCE(users.display_name, users.username) as owner_name ' ),
70- 'base_albums.description ' ,
71- 'base_albums.copyright ' ,
72- 'albums.license ' ,
73- 'base_albums.photo_layout ' ,
74- 'base_albums.sorting_col as photo_sorting_col ' ,
75- 'base_albums.sorting_order as photo_sorting_order ' ,
76- 'albums.album_sorting_col ' ,
77- 'albums.album_sorting_order ' ,
78- 'albums.album_thumb_aspect_ratio ' ,
79- 'albums.album_timeline ' ,
80- 'base_albums.photo_timeline ' ,
81- 'base_albums.is_nsfw ' ,
82- 'albums._lft ' ,
83- 'albums._rgt ' ,
84- 'base_albums.created_at ' ,
85- // Visibility from public access_permissions row
86- DB ::raw ('CASE WHEN ap.id IS NOT NULL THEN 1 ELSE 0 END as is_public ' ),
87- DB ::raw ('COALESCE(ap.is_link_required, 0) as is_link_required ' ),
88- DB ::raw ('COALESCE(ap.grants_full_photo_access, 0) as grants_full_photo_access ' ),
89- DB ::raw ('COALESCE(ap.grants_download, 0) as grants_download ' ),
90- DB ::raw ('COALESCE(ap.grants_upload, 0) as grants_upload ' ),
91- ])
92- ->orderBy ('albums._lft ' , 'asc ' );
52+ $ query = Album::query ()->without (
53+ ['cover ' , 'cover.size_variants ' , 'min_privilege_cover ' , 'min_privilege_cover.size_variants ' , 'max_privilege_cover ' , 'max_privilege_cover.size_variants ' , 'thumb ' ]
54+ )->orderBy ('albums._lft ' , 'asc ' );
9355
9456 if ($ search !== null && $ search !== '' ) {
9557 $ strategy = new AlbumFieldLikeStrategy ('title ' );
9658 $ strategy ->apply ($ query , new SearchToken (null , null , null , value: $ search , is_prefix: false ));
9759 }
9860
99- /** @var \Illuminate\Pagination\LengthAwarePaginator<int,object > $paginated */
61+ /** @var \Illuminate\Pagination\LengthAwarePaginator<int,Album > $paginated */
10062 $ paginated = $ query ->paginate (perPage: $ per_page , page: $ page );
10163
10264 $ resource_collection = $ paginated ->getCollection ()->map (fn ($ row ) => $ this ->rowToResource ($ row ));
@@ -191,35 +153,35 @@ public function destroy(DeleteBulkAlbumRequest $request): void
191153 /**
192154 * Map a raw DB row object to a BulkAlbumResource.
193155 *
194- * @param object $row
156+ * @param Album $row
195157 */
196- private function rowToResource (object $ row ): BulkAlbumResource
158+ private function rowToResource (Album $ row ): BulkAlbumResource
197159 {
198160 return new BulkAlbumResource (
199161 id: $ row ->id ,
200162 title: $ row ->title ,
201- owner_id: ( int ) $ row ->owner_id ,
202- owner_name: $ row ->owner_name ,
163+ owner_id: $ row ->owner_id ,
164+ owner_name: $ row ->owner -> name ,
203165 description: $ row ->description ,
204166 copyright: $ row ->copyright ,
205- license: LicenseType:: tryFrom ( $ row ->license ?? '' ) ?? LicenseType::NONE ,
206- photo_layout: PhotoLayoutType:: tryFrom ( $ row ->photo_layout ?? '' ) ,
207- photo_sorting_col: ColumnSortingPhotoType::tryFrom ($ row ->photo_sorting_col ?? '' ),
208- photo_sorting_order: OrderSortingType::tryFrom ($ row ->photo_sorting_order ?? '' ),
209- album_sorting_col: ColumnSortingAlbumType::tryFrom ($ row ->album_sorting_col ?? '' ),
210- album_sorting_order: OrderSortingType::tryFrom ($ row ->album_sorting_order ?? '' ),
211- album_thumb_aspect_ratio: AspectRatioType:: tryFrom ( $ row ->album_thumb_aspect_ratio ?? '' ) ,
212- album_timeline: TimelineAlbumGranularity:: tryFrom ( $ row ->album_timeline ?? '' ) ,
213- photo_timeline: TimelinePhotoGranularity:: tryFrom ( $ row ->photo_timeline ?? '' ) ,
214- is_nsfw: boolval ( $ row ->is_nsfw ) ,
215- _lft: ( int ) $ row ->_lft ,
216- _rgt: ( int ) $ row ->_rgt ,
217- is_public: boolval ( $ row ->is_public ) ,
218- is_link_required: boolval ( $ row ->is_link_required ) ,
219- grants_full_photo_access: boolval ( $ row ->grants_full_photo_access ) ,
220- grants_download: boolval ( $ row ->grants_download ) ,
221- grants_upload: boolval ( $ row ->grants_upload ) ,
222- created_at: Carbon:: parse ( $ row ->created_at ) ,
167+ license: $ row ->license ?? LicenseType::NONE ,
168+ photo_layout: $ row ->photo_layout ,
169+ photo_sorting_col: ColumnSortingPhotoType::tryFrom ($ row ->sorting_col ),
170+ photo_sorting_order: OrderSortingType::tryFrom ($ row ->sorting_order ),
171+ album_sorting_col: ColumnSortingAlbumType::tryFrom ($ row ->album_sorting_col ),
172+ album_sorting_order: OrderSortingType::tryFrom ($ row ->album_sorting_order ),
173+ album_thumb_aspect_ratio: $ row ->album_thumb_aspect_ratio ,
174+ album_timeline: $ row ->album_timeline ,
175+ photo_timeline: $ row ->photo_timeline ,
176+ is_nsfw: $ row ->is_nsfw ,
177+ _lft: $ row ->_lft ,
178+ _rgt: $ row ->_rgt ,
179+ is_public: $ row ->public_permissions () !== null ,
180+ is_link_required: $ row ->public_permissions ()?->is_link_required === true ,
181+ grants_full_photo_access: $ row ->public_permissions ()?->grants_full_photo_access === true ,
182+ grants_download: $ row ->public_permissions ()?->grants_download === true ,
183+ grants_upload: $ row ->public_permissions ()?->grants_upload === true ,
184+ created_at: $ row ->created_at ,
223185 );
224186 }
225187}
0 commit comments