1414use App \Models \Album ;
1515use App \Models \BaseAlbumImpl ;
1616use App \Models \Extensions \BaseAlbum ;
17+ use App \Models \PersonAlbum ;
1718use App \Models \TagAlbum ;
1819use App \Repositories \ConfigManager ;
1920use App \SmartAlbums \BaseSmartAlbum ;
@@ -53,6 +54,8 @@ class AlbumFactory
5354 SmartAlbumType::MY_BEST_PICTURES ->value => MyBestPicturesAlbum::class,
5455 ];
5556
57+ private const PHOTOS_RELATIONS = ['photos ' , 'photos.size_variants ' , 'photos.statistics ' , 'photos.palette ' , 'photos.tags ' , 'photos.rating ' ];
58+
5659 public function __construct (
5760 protected readonly ConfigManager $ config_manager ,
5861 ) {
@@ -120,13 +123,15 @@ public function findBaseAlbumOrFail(string $album_id, bool $with_relations = tru
120123 {
121124 $ album_query = Album::query ()->with (['access_permissions ' ]);
122125 $ tag_album_query = TagAlbum::query ()->with (['access_permissions ' ]);
126+ $ person_album_query = PersonAlbum::query ()->with (['access_permissions ' ]);
123127
124128 if ($ with_relations ) {
125- $ album_query ->with (['photos ' , 'children ' , 'children.owner ' , 'photos.size_variants ' , 'photos.statistics ' , 'photos.palette ' , 'photos.tags ' , 'photos.rating ' ]);
126- $ tag_album_query ->with (['tags ' , 'photos ' , 'photos.size_variants ' , 'photos.statistics ' , 'photos.palette ' , 'photos.tags ' , 'photos.rating ' ]);
129+ $ album_query ->with (array_merge (['children ' , 'children.owner ' ], self ::PHOTOS_RELATIONS ));
130+ $ tag_album_query ->with (array_merge (['tags ' ], self ::PHOTOS_RELATIONS ));
131+ $ person_album_query ->with (array_merge (['persons ' ], self ::PHOTOS_RELATIONS ));
127132 }
128133
129- $ ret = $ album_query ->find ($ album_id ) ?? $ tag_album_query ->find ($ album_id );
134+ $ ret = $ album_query ->find ($ album_id ) ?? $ tag_album_query ->find ($ album_id ) ?? $ person_album_query -> find ( $ album_id ) ;
130135 if ($ ret === null ) {
131136 throw (new ModelNotFoundException ())->setModel (BaseAlbumImpl::class, [$ album_id ]);
132137 }
@@ -176,7 +181,7 @@ public function findAbstractAlbumsOrFail(array $album_ids, bool $with_relations
176181 * shall be loaded, too.
177182 * @param bool $albums_only if true, only albums are returned, not tag albums
178183 *
179- * @return ($albums_only is true ? Collection<int,Album> : Collection<int,Album|TagAlbum>) a possibly empty list of {@link BaseAlbum}
184+ * @return ($albums_only is true ? Collection<int,Album> : Collection<int,Album|TagAlbum|PersonAlbum >) a possibly empty list of {@link BaseAlbum}
180185 *
181186 * @throws ModelNotFoundException
182187 */
@@ -188,19 +193,24 @@ public function findBaseAlbumsOrFail(array $album_ids, bool $with_relations = tr
188193 $ album_ids = array_diff (array_unique ($ album_ids ), [null ]);
189194
190195 $ tag_album_query = TagAlbum::query ();
196+ $ person_album_query = PersonAlbum::query ();
191197 $ album_query = Album::query ();
192198
193199 if ($ with_relations ) {
194- $ tag_album_query ->with (['tags ' , 'photos ' , 'photos.size_variants ' , 'photos.statistics ' , 'photos.palette ' , 'photos.tags ' , 'photos.rating ' ]);
195- $ album_query ->with (['photos ' , 'children ' , 'photos.size_variants ' , 'photos.statistics ' , 'photos.palette ' , 'photos.tags ' , 'photos.rating ' ]);
200+ $ tag_album_query ->with (array_merge (['tags ' ], self ::PHOTOS_RELATIONS ));
201+ $ person_album_query ->with (array_merge (['persons ' ], self ::PHOTOS_RELATIONS ));
202+ $ album_query ->with (array_merge (['children ' ], self ::PHOTOS_RELATIONS ));
196203 }
197204
198205 /** @var ($albums_only is true ? array<int,Album> : array<int,TagAlbum>)&array */
199206 $ tag_albums = $ albums_only ? [] : $ tag_album_query ->findMany ($ album_ids )->all (); /** @phpstan-ignore varTag.type */
200207
208+ /** @var array<int,PersonAlbum> $person_albums */
209+ $ person_albums = $ albums_only ? [] : $ person_album_query ->findMany ($ album_ids )->all ();
210+
201211 /** @var array<int,Album> $albums */
202212 $ albums = $ album_query ->findMany ($ album_ids )->all ();
203- $ result = new Collection (array_merge ($ tag_albums , $ albums ));
213+ $ result = new Collection (array_merge ($ tag_albums , $ person_albums , $ albums ));
204214
205215 if ($ result ->count () !== count ($ album_ids )) {
206216 throw (new ModelNotFoundException ())->setModel (BaseAlbumImpl::class, $ album_ids );
0 commit comments