From 608efc1f017247fdddb38ec291c30c0ec1e0a164 Mon Sep 17 00:00:00 2001 From: Nicolas Roudaire Date: Fri, 4 Mar 2022 10:55:24 +0100 Subject: [PATCH] Replace category by album (the same for plural forms) Cope with #65 --- config/routes/album.yaml | 16 +- config/routes/picture.yaml | 2 +- features/web/admin/album.feature | 20 +- src/Controller/Admin/AdminAlbumController.php | 4 +- .../Admin/AdminAlbumsController.php | 2 +- src/Controller/AlbumController.php | 49 ++-- src/Controller/DefaultController.php | 5 +- src/Controller/MenubarController.php | 1 - src/Controller/PictureController.php | 45 ++-- src/DataMapper/AlbumMapper.php | 223 ++++++++++-------- src/DataMapper/ImageMapper.php | 63 +++-- tools/phpstan-doctrine-orm-bootstrap.php | 4 +- 12 files changed, 252 insertions(+), 182 deletions(-) diff --git a/config/routes/album.yaml b/config/routes/album.yaml index b3d1a7caa..7967feb9a 100644 --- a/config/routes/album.yaml +++ b/config/routes/album.yaml @@ -1,5 +1,5 @@ albums_flat__start: - path: /categories/flat/start-{start} + path: /albums/flat/start-{start} controller: App\Controller\AlbumController::albumsFlat defaults: start: 0 @@ -7,25 +7,25 @@ albums_flat__start: start: \d+ albums_flat: - path: /categories/flat + path: /albums/flat controller: App\Controller\AlbumController::albumsFlat defaults: start: 0 albums__start: - path: /categories/start-{start} + path: /albums/start-{start} controller: App\Controller\AlbumController::albums requirements: start: \d+ albums: - path: /categories + path: /albums controller: App\Controller\AlbumController::albums defaults: start: 0 album__start: - path: /category/{category_id}/start-{start} + path: /album/{album_id}/start-{start} controller: App\Controller\AlbumController::album defaults: start: 0 @@ -33,13 +33,13 @@ album__start: start: \d+ album: - path: /category/{category_id} + path: /album/{album_id} controller: App\Controller\AlbumController::album defaults: start: 0 album_flat__start: - path: /category/{category_id}/flat/start-{start} + path: /album/{album_id}/flat/start-{start} controller: App\Controller\AlbumController::albumFlat defaults: start: 0 @@ -48,7 +48,7 @@ album_flat__start: start: \d+ album_flat: - path: /category/{category_id}/flat + path: /album/{album_id}/flat controller: App\Controller\AlbumController::albumFlat defaults: start: 0 diff --git a/config/routes/picture.yaml b/config/routes/picture.yaml index 5d51221e1..7431628f3 100644 --- a/config/routes/picture.yaml +++ b/config/routes/picture.yaml @@ -20,7 +20,7 @@ picture: controller: App\Controller\PictureController::picture requirements: element_id: .+ - type: category|list|tags|search|favorites|most_visited|best_rated|recent_pics|recent_cats|file|from_calendar + type: album|list|tags|search|favorites|most_visited|best_rated|recent_pics|recent_cats|file|from_calendar picture_rate: path: /rate diff --git a/features/web/admin/album.feature b/features/web/admin/album.feature index 0d917eb4b..fe3151528 100644 --- a/features/web/admin/album.feature +++ b/features/web/admin/album.feature @@ -9,14 +9,14 @@ Feature: Album | user1 | pass1 | webmaster | And some albums: - | name | parent | comment | status | - | album 1 | | album 1 description | public | - | album 2 | | album 2 description | public | + | name | parent | comment | status | + | album 1 | | album 1 description | public | + | album 2 | | album 2 description | public | And some images: - | name | album | - | photo 1 | album 1 | - | photo 2 | album 2 | + | name | album | + | photo 1 | album 1 | + | photo 2 | album 2 | Scenario: Move album in sub-album Given I am logged in as "user1" with password "pass1" @@ -25,10 +25,10 @@ Feature: Album When I go to "admin/albums/move" Then the select "Virtual albums to move" should contain: - """ - album 1 - album 2 - """ + """ + album 1 + album 2 + """ When I select "album 2" from "Virtual albums to move" And I select "album 1" from "New parent album" And I press "Submit" diff --git a/src/Controller/Admin/AdminAlbumController.php b/src/Controller/Admin/AdminAlbumController.php index afc7ff071..860db17da 100644 --- a/src/Controller/Admin/AdminAlbumController.php +++ b/src/Controller/Admin/AdminAlbumController.php @@ -135,7 +135,7 @@ public function properties( $tpl_params['CAT_NAME'] = $album->getName(); $tpl_params['CAT_COMMENT'] = $album->getComment(); $tpl_params['CAT_LOCK'] = $album->isVisible() ? 'false': 'true'; - $tpl_params['U_JUMPTO'] = $this->generateUrl('album', ['category_id' => $album_id]); + $tpl_params['U_JUMPTO'] = $this->generateUrl('album', ['album_id' => $album_id]); $tpl_params['U_ADD_PHOTOS_ALBUM'] = $this->generateUrl('admin_photos_add', ['album_id' => $album_id]); $tpl_params['U_CHILDREN'] = $this->generateUrl('admin_albums', ['parent_id' => $album_id]); $tpl_params['ws'] = $this->generateUrl('ws'); @@ -549,7 +549,7 @@ public function notification( 'derivative' => $derivative->getUrlType(), 'image_extension' => $element->getExtension() ]); - $img_url = 'generateUrl('picture', ['image_id' => $element->getId(), 'type' => 'album', 'element_id' => $album_id], UrlGeneratorInterface::ABSOLUTE_URL); $img_url .= '">X'; } } diff --git a/src/Controller/Admin/AdminAlbumsController.php b/src/Controller/Admin/AdminAlbumsController.php index 9bf8414ac..67abe88ee 100644 --- a/src/Controller/Admin/AdminAlbumsController.php +++ b/src/Controller/Admin/AdminAlbumsController.php @@ -109,7 +109,7 @@ public function list( 'NB_SUB_ALBUMS' => $subcats_of[$album->getId()] ?? 0, 'ID' => $album->getId(), 'RANK' => $album->getRank() * 10, - 'U_JUMPTO' => $this->generateUrl('album', ['category_id' => $album->getId()]), + 'U_JUMPTO' => $this->generateUrl('album', ['album_id' => $album->getId()]), 'U_CHILDREN' => $this->generateUrl('admin_albums', ['parent_id' => $album->getId()]), 'U_EDIT' => $this->generateUrl('admin_album', ['album_id' => $album->getId(), 'parent_id' => $parent_id]), 'IS_VIRTUAL' => $album->isVirtual(), diff --git a/src/Controller/AlbumController.php b/src/Controller/AlbumController.php index c21e16794..fc25a787c 100644 --- a/src/Controller/AlbumController.php +++ b/src/Controller/AlbumController.php @@ -20,6 +20,7 @@ use App\Repository\UserCacheAlbumRepository; use App\Security\AppUserService; use Phyxo\Functions\Utils; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Security; @@ -39,8 +40,8 @@ public function album( AppUserService $appUserService, RouterInterface $router, int $start = 0, - int $category_id = 0 - ) { + int $album_id = 0 + ): Response { $tpl_params = []; $this->image_std_params = $image_std_params; @@ -48,9 +49,9 @@ public function album( $tpl_params['category_view'] = $request->cookies->get('category_view'); } - $album = $albumMapper->getRepository()->find($category_id); + $album = $albumMapper->getRepository()->find($album_id); - if (in_array($category_id, $appUserService->getUser()->getUserInfos()->getForbiddenCategories())) { + if (in_array($album_id, $appUserService->getUser()->getUserInfos()->getForbiddenCategories())) { throw new AccessDeniedHttpException("Access denied to that album"); } @@ -86,7 +87,7 @@ public function album( if ($order[2] === true) { $tpl_params['image_orders'][] = [ 'DISPLAY' => $order[0], - 'URL' => $this->generateUrl('album', ['category_id' => $album->getId(), 'start' => $start, 'order' => $order_id]), + 'URL' => $this->generateUrl('album', ['album_id' => $album->getId(), 'start' => $start, 'order' => $order_id]), 'SELECTED' => false ]; } @@ -103,7 +104,7 @@ public function album( list($is_child_date_last, $albums, $image_ids, $user_representative_updates_for) = $albumMapper->getAlbumThumbnails( $appUserService->getUser(), - $albumMapper->getRepository()->findByParentId($category_id, $appUserService->getUser()->getId()) + $albumMapper->getRepository()->findByParentId($album_id, $appUserService->getUser()->getId()) ); if (count($albums) > 0) { @@ -137,7 +138,7 @@ public function album( 'representative' => $representative_infos, 'TN_ALT' => $currentAlbum->getName(), 'TN_TITLE' => $imageMapper->getThumbnailTitle(['rating_score' => '', 'nb_comments' => ''], $currentAlbum->getName(), $currentAlbum->getComment()), - 'URL' => $this->generateUrl('album', ['category_id' => $currentAlbum->getId(), 'start' => $start]), + 'URL' => $this->generateUrl('album', ['album_id' => $currentAlbum->getId(), 'start' => $start]), 'CAPTION_NB_IMAGES' => $albumMapper->getDisplayImagesCount( $userCacheAlbum->getNbImages(), $userCacheAlbum->getCountImages(), @@ -202,7 +203,7 @@ public function album( $tpl_params['thumb_navbar'] = Utils::createNavigationBar( $router, 'album', - ['category_id' => $category_id], + ['album_id' => $album_id], count($tpl_params['items']), $start, $nb_image_page, @@ -213,9 +214,9 @@ public function album( $tpl_params = array_merge( $tpl_params, $imageMapper->getPicturesFromSelection( - $category_id, + $album_id, array_slice($tpl_params['items'], $start, $nb_image_page), - 'category', + 'album', $start ) ); @@ -224,8 +225,8 @@ public function album( $tpl_params = array_merge($this->addThemeParams($conf), $tpl_params); $tpl_params['SHOW_THUMBNAIL_CAPTION'] = $conf['show_thumbnail_caption']; - $tpl_params['U_MODE_POSTED'] = $this->generateUrl('calendar', ['date_type' => 'posted', 'category_id' => $category_id]); - $tpl_params['U_MODE_CREATED'] = $this->generateUrl('calendar', ['date_type' => 'created', 'category_id' => $category_id]); + $tpl_params['U_MODE_POSTED'] = $this->generateUrl('calendar', ['date_type' => 'posted', 'album_id' => $album_id]); + $tpl_params['U_MODE_CREATED'] = $this->generateUrl('calendar', ['date_type' => 'created', 'album_id' => $album_id]); $tpl_params['START_ID'] = $start; $tpl_params = array_merge($tpl_params, $this->loadThemeConf($request->getSession()->get('_theme'), $conf)); @@ -238,12 +239,12 @@ public function albumFlat( ImageStandardParams $image_std_params, AlbumMapper $albumMapper, ImageMapper $imageMapper, - int $category_id, + int $album_id, TranslatorInterface $translator, RouterInterface $router, AppUserService $appUserService, int $start = 0 - ) { + ): Response { $tpl_params = []; $this->image_std_params = $image_std_params; @@ -251,7 +252,7 @@ public function albumFlat( $tpl_params['category_view'] = $request->cookies->get('category_view'); } - $album = $albumMapper->getRepository()->find($category_id); + $album = $albumMapper->getRepository()->find($album_id); $subcat_ids[] = $album->getId(); foreach ($albumMapper->getRepository()->findAllowedSubAlbums($album->getUppercats(), $appUserService->getUser()->getUserInfos()->getForbiddenCategories()) as $sub_album) { $subcat_ids[] = $sub_album->getId(); @@ -269,7 +270,7 @@ public function albumFlat( $tpl_params['thumb_navbar'] = Utils::createNavigationBar( $router, 'album_flat', - ['category_id' => $category_id], + ['album_id' => $album_id], count($tpl_params['items']), $start, $nb_image_page, @@ -280,9 +281,9 @@ public function albumFlat( $tpl_params = array_merge( $tpl_params, $imageMapper->getPicturesFromSelection( - $category_id, + $album_id, array_slice($tpl_params['items'], $start, $nb_image_page), - 'category', + 'album', $start ) ); @@ -307,7 +308,7 @@ public function albumsFlat( RouterInterface $router, AppUserService $appUserService, int $start = 0 - ) { + ): Response { $tpl_params = []; $this->image_std_params = $image_std_params; @@ -342,7 +343,7 @@ public function albumsFlat( $imageMapper->getPicturesFromSelection( 'flat', array_slice($tpl_params['items'], $start, $nb_image_page), - 'categories', + 'albums', $start ) ); @@ -367,7 +368,7 @@ public function albums( RouterInterface $router, AppUserService $appUserService, int $start = 0 - ) { + ): Response { $tpl_params = []; $this->image_std_params = $image_std_params; @@ -419,7 +420,7 @@ public function albums( 'representative' => $representative_infos, 'TN_ALT' => $album->getName(), 'TN_TITLE' => $imageMapper->getThumbnailTitle(['rating_score' => '', 'nb_comments' => ''], $album->getName(), $album->getComment()), - 'URL' => $this->generateUrl('album', ['category_id' => $album->getId(), 'start' => $start]), + 'URL' => $this->generateUrl('album', ['album_id' => $album->getId(), 'start' => $start]), 'CAPTION_NB_IMAGES' => $albumMapper->getDisplayImagesCount( $userCacheAlbum->getNbImages(), $userCacheAlbum->getCountImages(), @@ -492,7 +493,7 @@ public function recentCats( RouterInterface $router, AppUserService $appUserService, int $start = 0 - ) { + ): Response { $tpl_params = []; $this->image_std_params = $image_std_params; @@ -542,7 +543,7 @@ public function recentCats( 'representative' => $representative_infos, 'TN_ALT' => $album->getName(), 'TN_TITLE' => $imageMapper->getThumbnailTitle(['rating_score' => '', 'nb_comments' => ''], $album->getName(), $album->getComment()), - 'URL' => $this->generateUrl('album', ['category_id' => $album->getId(), 'start' => $start]), + 'URL' => $this->generateUrl('album', ['album_id' => $album->getId(), 'start' => $start]), 'CAPTION_NB_IMAGES' => $albumMapper->getDisplayImagesCount( $userCacheAlbum->getNbImages(), $userCacheAlbum->getCountImages(), diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index 1cd883c94..0f22f47e1 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -17,10 +17,11 @@ use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException; use Phyxo\Image\DerivativeImage; use Phyxo\Image\ImageStandardParams; +use Symfony\Component\HttpFoundation\Response; class DefaultController extends CommonController { - public function home() + public function home(): Response { return $this->forward('App\Controller\AlbumController::albums'); } @@ -32,7 +33,7 @@ public function download( AppUserService $appUserService, ImageStandardParams $image_std_params, string $rootProjectDir - ) { + ): Response { $image = $imageMapper->getRepository()->find($image_id); if (!$albumMapper->getRepository()->hasAccessToImage($image_id, $appUserService->getUser()->getUserInfos()->getForbiddenCategories())) { diff --git a/src/Controller/MenubarController.php b/src/Controller/MenubarController.php index 8e58c47cd..56f19627a 100644 --- a/src/Controller/MenubarController.php +++ b/src/Controller/MenubarController.php @@ -13,7 +13,6 @@ use Phyxo\Conf; use Phyxo\MenuBar; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; diff --git a/src/Controller/PictureController.php b/src/Controller/PictureController.php index 0fded9431..50ce1152e 100644 --- a/src/Controller/PictureController.php +++ b/src/Controller/PictureController.php @@ -25,6 +25,7 @@ use App\DataMapper\RateMapper; use App\Entity\Comment; use App\Entity\History; +use App\Entity\Image; use App\Entity\User; use App\Events\HistoryEvent; use App\Form\DeleteCommentType; @@ -36,17 +37,23 @@ use App\Repository\ImageAlbumRepository; use App\Security\AppUserService; use App\Security\TagVoter; +use DateTimeInterface; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException; use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Symfony\Contracts\Translation\TranslatorInterface; class PictureController extends CommonController { - private $userMapper, $translator; + private UserMapper $userMapper; + private TranslatorInterface $translator; + /** + * @param array{current_day?: DateTimeInterface, date_type?: string, year?: int, month?: int, day?: int } $extra + */ public function picture( Request $request, int $image_id, @@ -68,7 +75,7 @@ public function picture( AppUserService $appUserService, CommentRepository $commentRepository, array $extra = [] - ) { + ): Response { $this->translator = $translator; $tpl_params = []; $this->conf = $conf; @@ -198,7 +205,7 @@ public function picture( if ($type === 'list') { $tpl_params['U_UP'] = $this->generateUrl('random_list', ['list' => $element_id]); } else { - $tpl_params['U_UP'] = $this->generateUrl('album', ['category_id' => (int) $element_id]); + $tpl_params['U_UP'] = $this->generateUrl('album', ['album_id' => (int) $element_id]); } $deriv_type = $request->cookies->has('picture_deriv') ? $request->cookies->get('picture_deriv') : $conf['derivative_default_size']; $tpl_params['current']['selected_derivative'] = $tpl_params['current']['derivatives'][$deriv_type]; @@ -276,7 +283,7 @@ public function picture( } $tpl_params['U_CADDIE'] = $this->generateUrl('picture', ['image_id' => $image_id, 'type' => $type, 'element_id' => $element_id, 'action' => 'add_to_caddie']); - $tpl_params['U_PHOTO_ADMIN'] = $this->generateUrl('admin_photo', ['image_id' => $image_id, 'category_id' => (int) $element_id]); + $tpl_params['U_PHOTO_ADMIN'] = $this->generateUrl('admin_photo', ['image_id' => $image_id, 'album_id' => (int) $element_id]); $tpl_params['available_permission_levels'] = Utils::getPrivacyLevelOptions($translator, $conf['available_permission_levels']); } @@ -324,7 +331,7 @@ public function picture( } if ($conf['rate']) { - $tpl_params = array_merge($tpl_params, $this->addRateInfos($rateRepository, $picture, $request, $appUserService->getUser())); + $tpl_params = array_merge($tpl_params, $this->addRateInfos($rateRepository, $image, $request, $appUserService->getUser())); } if (($conf['show_exif'] || $conf['show_iptc'])) { @@ -346,7 +353,7 @@ public function picture( [ 'image_id' => $comment->getImage()->getId(), 'element_id' => $comment->getImage()->getImageAlbums()->first()->getAlbum()->getId(), - 'type' => 'category' + 'type' => 'album' ] ) @@ -508,19 +515,19 @@ function($tag) { return $this->render('picture.html.twig', $tpl_params); } - public function picturesByTypes($image_id, $type) + public function picturesByTypes(int $image_id, string $type): Response { return $this->forward( 'App\Controller\PictureController::picture', [ 'image_id' => $image_id, - 'type' => 'category', + 'type' => 'album', 'element_id' => 'n/a' ] ); } - public function pictureBySearch($image_id, $search_id) + public function pictureBySearch(int $image_id, int $search_id): Response { return $this->forward( 'App\Controller\PictureController::picture', @@ -532,7 +539,7 @@ public function pictureBySearch($image_id, $search_id) ); } - public function pictureFromCalendar(int $image_id, int $year, int $month, int $day, string $date_type) + public function pictureFromCalendar(int $image_id, int $year, int $month, int $day, string $date_type): Response { $current_day = new \DateTime(sprintf('%d-%02d-%02d', $year, $month, $day)); @@ -547,13 +554,14 @@ public function pictureFromCalendar(int $image_id, int $year, int $month, int $d ); } - protected function addRateInfos(RateRepository $rateRepository, array $picture, Request $request, ?User $user): array + /** @phpstan-ignore-next-line */ // @FIX: define return type + protected function addRateInfos(RateRepository $rateRepository, Image $image, Request $request, ?User $user): array { $tpl_params = []; - $rate_summary = ['count' => 0, 'score' => $picture['rating_score'], 'average' => null]; + $rate_summary = ['count' => 0, 'score' => $image->getRatingScore(), 'average' => null]; if (!is_null($rate_summary['score'])) { - $calculated_rate = $rateRepository->calculateRateSummary($picture['id']); + $calculated_rate = $rateRepository->calculateRateSummary($image->getId()); $rate_summary['count'] = $calculated_rate['count']; $rate_summary['average'] = round($calculated_rate['average'], 2); } @@ -569,7 +577,7 @@ protected function addRateInfos(RateRepository $rateRepository, array $picture, $rate = $rateRepository->findOneBy([ 'user' => $user->getId(), - 'image' => $picture['id'], + 'image' => $image->getId(), 'anonymous_id' => $anonymous_id ]); if (!is_null($rate)) { @@ -579,7 +587,7 @@ protected function addRateInfos(RateRepository $rateRepository, array $picture, $tpl_params['rating'] = [ 'F_ACTION' => $this->generateUrl('picture_rate'), - 'image_id' => $picture['id'], + 'image_id' => $image->getId(), 'USER_RATE' => $user_rate, 'marks' => $this->conf['rate_items'] ]; @@ -588,13 +596,13 @@ protected function addRateInfos(RateRepository $rateRepository, array $picture, return $tpl_params; } - public function rate(Request $request, ImageMapper $imageMapper, Conf $conf, RateMapper $rateMapper, AppUserService $appUserService) + public function rate(Request $request, ImageMapper $imageMapper, Conf $conf, RateMapper $rateMapper, AppUserService $appUserService): Response { $result['score'] = null; if ($request->isMethod('POST')) { if (!$imageMapper->getRepository()->isAuthorizedToUser($request->request->get('image_id'), $appUserService->getUser()->getUserInfos()->getForbiddenCategories())) { - return new AccessDeniedException("Cannot rate that image"); + throw new AccessDeniedException("Cannot rate that image"); } if (!$appUserService->isGuest() || $this->conf['rate_anonymous']) { @@ -607,7 +615,7 @@ public function rate(Request $request, ImageMapper $imageMapper, Conf $conf, Rat } if (is_null($result['score'])) { - return new AccessDeniedException('Forbidden or rate not in ' . implode(',', $conf['rate_items'])); + throw new AccessDeniedException('Forbidden or rate not in ' . implode(',', $conf['rate_items'])); } } @@ -625,6 +633,7 @@ public function rate(Request $request, ImageMapper $imageMapper, Conf $conf, Rat return $response; } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function addMetadataInfos(Metadata $metadata, string $path): array { $tpl_params = []; diff --git a/src/DataMapper/AlbumMapper.php b/src/DataMapper/AlbumMapper.php index 81237780b..9ac78373b 100644 --- a/src/DataMapper/AlbumMapper.php +++ b/src/DataMapper/AlbumMapper.php @@ -26,7 +26,19 @@ class AlbumMapper { - private $conf, $albumRepository, $router, $cache = [], $albums_retrieved = false, $translator, $userRepository, $userCacheAlbumRepository, $imageAlbumRepository, $imageRepository; + /** + * @var array $cache + */ + private array $cache; + private Conf $conf; + private AlbumRepository $albumRepository; + private RouterInterface $router; + private bool $albums_retrieved = false; + private TranslatorInterface $translator; + private UserRepository $userRepository; + private UserCacheAlbumRepository $userCacheAlbumRepository; + private ImageAlbumRepository $imageAlbumRepository; + private ImageRepository $imageRepository; public function __construct( Conf $conf, @@ -55,24 +67,26 @@ public function getRepository(): AlbumRepository /** * Returns template vars for main albums menu. - * + * @param array{id?: int, id_uppercat?: int} $selected_album */ - public function getRecursiveAlbumsMenu(User $user, array $selected_category = []): array + /** @phpstan-ignore-next-line */ // @FIX: define return type + public function getRecursiveAlbumsMenu(User $user, array $selected_album = []): array { - $flat_categories = $this->getAlbumsMenu($user, $selected_category); + $flat_albums = $this->getAlbumsMenu($user, $selected_album); - $categories = []; - foreach ($flat_categories as $category) { - if ($category['uppercats'] == $category['id']) { - $categories[$category['id']] = $category; + $albums = []; + foreach ($flat_albums as $album) { + if ($album['uppercats'] == $album['id']) { + $albums[$album['id']] = $album; } else { - $this->insertAlbumInTree($categories, $category, $category['uppercats']); + $this->insertAlbumInTree($albums, $album, $album['uppercats']); } } - return $categories; + return $albums; } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function insertAlbumInTree(&$categories, $category, $uppercats) { if ($category['id'] != $uppercats) { @@ -89,9 +103,10 @@ protected function insertAlbumInTree(&$categories, $category, $uppercats) /** * Returns template vars for main albums menu. - * + * @param array{id?: int, id_uppercat?: int} $selected_album */ - protected function getAlbumsMenu(User $user, array $selected_category = []): array + /** @phpstan-ignore-next-line */ // @FIX: define return type + protected function getAlbumsMenu(User $user, array $selected_album = []): array { $albums = []; foreach ($this->getRepository()->getAlbumsForMenu($user->getId(), $user->getUserInfos()->getForbiddenCategories()) as $album) { @@ -106,10 +121,10 @@ protected function getAlbumsMenu(User $user, array $selected_category = []): arr false, ' / ' ), - 'URL' => $this->router->generate('album', ['category_id' => $album->getId()]), + 'URL' => $this->router->generate('album', ['album_id' => $album->getId()]), 'LEVEL' => substr_count($album->getGlobalRank(), '.') + 1, - 'SELECTED' => isset($selected_category['id']) && $selected_category['id'] === $album->getId() ? true : false, - 'IS_UPPERCAT' => isset($selected_category['id_uppercat']) && $selected_category['id_uppercat'] === $album->getId() ? true : false, + 'SELECTED' => isset($selected_album['id']) && $selected_album['id'] === $album->getId() ? true : false, + 'IS_UPPERCAT' => isset($selected_album['id_uppercat']) && $selected_album['id_uppercat'] === $album->getId() ? true : false, 'count_images' => $album->getUserCacheAlbums()->first()->getCountImages(), 'icon_ts' => '' ] @@ -128,6 +143,7 @@ protected function getAlbumsMenu(User $user, array $selected_category = []): arr * Get computed array of albums, that means cache data of all albums * available for the current user (count_categories, count_images, etc.). */ + /** @phpstan-ignore-next-line */ // @FIX: define return type public function getComputedAlbums(int $level, array $forbidden_categories = []) { $albums = []; @@ -179,6 +195,7 @@ public function getComputedAlbums(int $level, array $forbidden_categories = []) /** * Removes an album from computed array of albums and updates counters. */ + /** @phpstan-ignore-next-line */ // @FIX: define return type public function removeComputedAlbum(array $albums, $album): array { if (isset($albums[$album['id_uppercat']])) { @@ -202,18 +219,15 @@ public function removeComputedAlbum(array $albums, $album): array } /** - * Generates breadcrumb from categories list. - * Categories string returned contains categories as given in the input - * array $cat_informations. $cat_informations array must be an array - * of array( id=>?, name=>?). If url input parameter is null, - * returns only the categories name without links. + * Generates breadcrumb from albums list. */ - public function getAlbumDisplayName(array $cat_informations, string $url = ''): string + /** @phpstan-ignore-next-line */ + public function getAlbumDisplayName(array $album_informations, string $url = ''): string { $output = ''; $is_first = true; - foreach ($cat_informations as $cat) { + foreach ($album_informations as $album) { if ($is_first) { $is_first = false; } else { @@ -221,33 +235,35 @@ public function getAlbumDisplayName(array $cat_informations, string $url = ''): } if (empty($url)) { - $output .= $cat['name']; + $output .= $album['name']; } elseif ($url == '') { - $output .= ''; - $output .= $cat['name'] . ''; + $output .= ''; + $output .= $album['name'] . ''; } else { - $output .= ''; - $output .= $cat['name'] . ''; + $output .= ''; + $output .= $album['name'] . ''; } } return $output; } + /** @phpstan-ignore-next-line */ public function getAlbumsDisplayName(string $uppercats, string $route_name, array $params = []): array { $names = []; - foreach (explode(',', $uppercats) as $category_id) { + foreach (explode(',', $uppercats) as $album_id) { $names[] = [ - 'name' => $this->getCacheAlbums()[$category_id]->getName(), - 'url' => $this->router->generate($route_name, array_merge($params, ['album_id' => $this->getCacheAlbums()[$category_id]->getId()])) + 'name' => $this->getCacheAlbums()[(int) $album_id]->getName(), + 'url' => $this->router->generate($route_name, array_merge($params, ['album_id' => $this->getCacheAlbums()[(int) $album_id]->getId()])) ]; } return $names; } + /** @phpstan-ignore-next-line */ // @FIX: define return type public function getBreadcrumb(Album $album): array { $breadcumb = []; @@ -265,14 +281,14 @@ public function getBreadcrumb(Album $album): array foreach ($upper_ids as $album_id) { $upper_names[] = [ 'id' => $album_id, - 'name' => $this->getCacheAlbums()[$album_id]->getName(), + 'name' => $this->getCacheAlbums()[(int) $album_id]->getName(), ]; } } foreach ($upper_names as $album) { $breadcumb[] = [ - 'url' => $this->router->generate('album', ['category_id' => $album['id']]), + 'url' => $this->router->generate('album', ['album_id' => $album['id']]), 'label' => $album['name'] ]; } @@ -289,7 +305,7 @@ public function getAlbumsDisplayNameCache(string $uppercats, string $url = '', b $all_albums = explode(',', $uppercats); $output = ''; if ($single_link) { - $single_url = $this->router->generate('album', ['category_id' => $all_albums[count($all_albums) - 1]]); + $single_url = $this->router->generate('album', ['album_id' => $all_albums[count($all_albums) - 1]]); $output .= 'getCacheAlbums()[$album_id]; + $album = $this->getCacheAlbums()[(int) $album_id]; if ($is_first) { $is_first = false; @@ -311,7 +327,7 @@ public function getAlbumsDisplayNameCache(string $uppercats, string $url = '', b if ($url === '' || $single_link) { $output .= $album->getName(); } else { - $output .= '' . $album->getName() . ''; + $output .= '' . $album->getName() . ''; } } @@ -322,7 +338,8 @@ public function getAlbumsDisplayNameCache(string $uppercats, string $url = '', b return $output; } - public function displaySelectAlbums(array $albums, array $selecteds, string $blockname, bool $fullname = true) + /** @phpstan-ignore-next-line */ // @FIX: define return type + public function displaySelectAlbums(array $albums, array $selecteds, string $blockname, bool $fullname = true): array { $tpl_cats = []; foreach ($albums as $album) { @@ -346,6 +363,7 @@ public function displaySelectAlbums(array $albums, array $selecteds, string $blo * Same as displaySelectAlbums but albums are ordered by rank * @see displaySelectAlbums() */ + /** @phpstan-ignore-next-line */ // @FIX: define return type public function displaySelectAlbumsWrapper(array $albums, array $selecteds, string $blockname, bool $fullname = true): array { usort($albums, [$this, 'globalRankCompare']); @@ -355,8 +373,9 @@ public function displaySelectAlbumsWrapper(array $albums, array $selecteds, stri /** * Change the parent album of the given albums. The albums are supposed virtual. + * @param int[] $ids */ - public function moveAlbums(array $ids, int $new_parent = null) + public function moveAlbums(array $ids, int $new_parent = null): void { if (count($ids) === 0) { return; @@ -407,7 +426,7 @@ public function moveAlbums(array $ids, int $new_parent = null) /** * Updates albums uppercats field based on albums id + albums id_uppercat */ - public function updateUppercats() + public function updateUppercats(): void { foreach ($this->getCacheAlbums() as $id => $album) { $upper_list = []; @@ -428,8 +447,9 @@ public function updateUppercats() /** * Change the **status** property on a set of albums : private or public. + * @param int[] $album_ids */ - public function setAlbumsStatus(array $album_ids, string $status) + public function setAlbumsStatus(array $album_ids, string $status): void { if (!in_array($status, [Album::STATUS_PUBLIC, Album::STATUS_PRIVATE])) { throw new \Exception("AlbumMapper::setAlbumsStatus invalid param $status"); @@ -480,7 +500,7 @@ public function setAlbumsStatus(array $album_ids, string $status) $top_albums = []; $parent_ids = []; $all_albums = []; - foreach ($this->albumRepository->findById($album_ids) as $album) { + foreach ($this->albumRepository->findBy(['id' => $album_ids]) as $album) { $all_albums[] = $album; } usort($all_albums, [$this, 'globalRankCompare']); @@ -512,7 +532,7 @@ public function setAlbumsStatus(array $album_ids, string $status) $parent_albums = []; if (count($parent_ids) > 0) { - foreach ($this->albumRepository->findById($parent_ids) as $album) { + foreach ($this->albumRepository->findBy(['id' => $parent_ids]) as $album) { $parent_albums[] = $album->getId(); } } @@ -548,7 +568,9 @@ public function setAlbumsStatus(array $album_ids, string $status) /** * Returns all uppercats Album ids of the given Album ids. + * @param int[] $ids */ + /** @phpstan-ignore-next-line */ // @FIX: define return type public function getUppercatIds(array $ids): array { if (count($ids) < 1) { @@ -565,8 +587,10 @@ public function getUppercatIds(array $ids): array /** * Grant access to a list of categories for a list of users. + * @param int[] $album_ids + * @param int[] $user_ids */ - public function addPermissionOnAlbum(array $album_ids, array $user_ids, bool $apply_on_sub = false) + public function addPermissionOnAlbum(array $album_ids, array $user_ids, bool $apply_on_sub = false): void { // check for emptiness if (count($album_ids) === 0 || count($user_ids) === 0) { @@ -593,12 +617,8 @@ public function addPermissionOnAlbum(array $album_ids, array $user_ids, bool $ap /** * Create an album. * - * @param array $options - * - boolean commentable - * - boolean visible - * - string status - * - string comment - * - boolean inherit + * @param int[] $admin_ids + * @param array{commentable?: bool, visible?: bool, status?: string, comment?: string, inherit?: bool} $options */ public function createAlbum(string $name, ?Album $parent = null, int $user_id, array $admin_ids = [], array $options = []): Album { @@ -651,8 +671,8 @@ public function createAlbum(string $name, ?Album $parent = null, int $user_id, a if (!is_null($parent)) { $album->setUppercats($parent->getUppercats() . ',' . $album_id); } else { - $album->setUppercats($album_id); - $album->setGlobalRank($album_id); + $album->setUppercats((string) $album_id); + $album->setGlobalRank((string) $album_id); } $album_id = $this->albumRepository->addOrUpdateAlbum($album); @@ -684,11 +704,14 @@ public function createAlbum(string $name, ?Album $parent = null, int $user_id, a /** * Callback used for sorting by global_rank */ - public function globalRankCompare(Album $a, Album $b) + public function globalRankCompare(Album $a, Album $b): int { return strnatcasecmp($a->getGlobalRank(), $b->getGlobalRank()); } + /** + * @return array + */ protected function getCacheAlbums() { if (!$this->albums_retrieved) { @@ -704,8 +727,10 @@ protected function getCacheAlbums() /** * Change the **visible** property on a set of albums. + * + * @param int[] $ids */ - public function setAlbumsVisibility(array $ids, bool $visible, $unlock_child = false) + public function setAlbumsVisibility(array $ids, bool $visible, bool $unlock_child = false): void { // unlocking a category => all its parent categories become unlocked if ($visible) { @@ -724,7 +749,7 @@ public function setAlbumsVisibility(array $ids, bool $visible, $unlock_child = f * Orders albums (update albums.rank and global_rank database fields) * so that rank field are consecutive integers starting at 1 for each child. */ - public function updateGlobalRank() + public function updateGlobalRank(): void { $albums = []; $current_rank = 0; @@ -749,11 +774,8 @@ public function updateGlobalRank() }; foreach ($albums as $id => $album) { - $new_global_rank = preg_replace_callback( - '/(\d+)/', - $map_callback, - str_replace(',', '.', $album['uppercats']) - ); + /** @phpstan-ignore-next-line */ + $new_global_rank = preg_replace_callback('/(\d+)/', $map_callback, str_replace(',', '.', $album['uppercats'])); if ($album['rank_changed'] || $new_global_rank !== $album['global_rank']) { $album_to_update = $this->getCacheAlbums()[$id]; @@ -766,6 +788,10 @@ public function updateGlobalRank() unset($albums); } + /** + * @param int[] $ids + */ + /** @phpstan-ignore-next-line */ // @FIX: define return type public function getAlbumsRefDate(array $ids, string $field = 'date_available', string $minmax = 'max') { // we need to work on the whole tree under each category, even if we don't want to sort sub categories @@ -779,16 +805,16 @@ public function getAlbumsRefDate(array $ids, string $field = 'date_available', s // then iterate on all albums (having a ref_date or not) to find the reference_date, with a search on sub-albums $uppercats_of = []; - foreach ($this->albumRepository->findById($album_ids) as $album) { + foreach ($this->albumRepository->findBy(['id' => $album_ids]) as $album) { $uppercats_of[$album->getId()] = $album; } - foreach ($uppercats_of as $album_id) { + foreach (array_keys($uppercats_of) as $album_id) { // find the subcats $subcat_ids = []; - foreach ($uppercats_of as $id => $uppercats) { - if (preg_match('/(^|,)' . $album_id . '(,|$)/', $uppercats)) { + foreach ($uppercats_of as $id => $album) { + if (preg_match('/(^|,)' . $album_id . '(,|$)/', $album->getUppercats())) { $subcat_ids[] = $id; } } @@ -818,8 +844,9 @@ public function getAlbumsRefDate(array $ids, string $field = 'date_available', s /** * Set a new random representant to the albums. + * @param int[] $album_ids */ - public function setRandomRepresentant(array $album_ids) + public function setRandomRepresentant(array $album_ids): void { foreach ($album_ids as $album_id) { $representative = $this->imageAlbumRepository->findRandomRepresentant($album_id); @@ -831,35 +858,32 @@ public function setRandomRepresentant(array $album_ids) /** * Returns display text for images counter of album - * - * @param int $cat_nb_images nb images directly in album - * @param int $cat_count_images nb images in album (including subcats) - * @param int $cat_count_categories nb subcats - * @param bool $short_message if true append " in this album" - * @param string $separator - * @return string + * $album_nb_images nb images directly in album + * $album_count_images nb images in album (including sub-albums) + * $album_count_albums nb sub-albums + * $short_message if true append " in this album" */ - public function getDisplayImagesCount($cat_nb_images, $cat_count_images, $cat_count_categories, $short_message = true, $separator = '\n') + public function getDisplayImagesCount(int $album_nb_images, int $album_count_images, int $album_count_albums, bool $short_message = true, string $separator = "\n"): string { $display_text = ''; - if ($cat_count_images > 0) { - if ($cat_nb_images > 0 and $cat_nb_images < $cat_count_images) { - $display_text .= $this->getDisplayImagesCount($cat_nb_images, $cat_nb_images, 0, $short_message, $separator) . $separator; - $cat_count_images -= $cat_nb_images; - $cat_nb_images = 0; + if ($album_count_images > 0) { + if ($album_nb_images > 0 && $album_nb_images < $album_count_images) { + $display_text .= $this->getDisplayImagesCount($album_nb_images, $album_nb_images, 0, $short_message, $separator) . $separator; + $album_count_images -= $album_nb_images; + $album_nb_images = 0; } //at least one image direct or indirect - $display_text .= $this->translator->trans('number_of_photos', ['count' => $cat_count_images]); + $display_text .= $this->translator->trans('number_of_photos', ['count' => $album_count_images]); - if ($cat_count_categories === 0 || $cat_nb_images === $cat_count_images) { + if ($album_count_albums === 0 || $album_nb_images === $album_count_images) { //no descendant categories or descendants do not contain images if (!$short_message) { $display_text .= ' ' . $this->translator->trans('in this album'); } } else { - $display_text .= ' ' . $this->translator->trans('number_of_photos_in_sub_albums', ['count' => $cat_count_categories]); + $display_text .= ' ' . $this->translator->trans('number_of_photos_in_sub_albums', ['count' => $album_count_albums]); } } @@ -871,8 +895,10 @@ public function getDisplayImagesCount($cat_nb_images, $cat_count_images, $cat_co /** * Verifies that the representative picture really exists in the db and * picks up a random representative if possible and based on config. + * + * @param int[] $ids */ - public function updateAlbums(array $ids = []) + public function updateAlbums(array $ids = []): void { // find all albums where the setted representative is not possible : the picture does not exist $wrong_representants = $this->getRepository()->findWrongRepresentant($ids); @@ -902,8 +928,10 @@ public function updateAlbums(array $ids = []) * - all the elements physically linked to the album (with ImageMapper::deleteElements) * - all the links between elements and this album * - all the restrictions linked to the album + * + * @param int[] $ids */ - public function deleteAlbums(array $ids = []) + public function deleteAlbums(array $ids = []): void { if (count($ids) === 0) { return; @@ -928,8 +956,11 @@ public function deleteAlbums(array $ids = []) /** * Associate a list of images to a list of albums. * The function will not duplicate links and will preserve ranks. + * + * @param int[] $image_ids + * @param int[] $album_ids */ - public function associateImagesToAlbums(array $image_ids, array $album_ids) + public function associateImagesToAlbums(array $image_ids, array $album_ids): void { // get max rank of each albums $current_rank_of = $this->imageAlbumRepository->findMaxRankForEachAlbums($album_ids); @@ -957,11 +988,13 @@ public function associateImagesToAlbums(array $image_ids, array $album_ids) * Dissociate images from all old albums except their storage album and * associate to new albums. * This methods will preserve ranks. + * @param int[] $image_ids + * @param int[] $album_ids */ - public function moveImagesToAlbums(array $image_ids = [], array $album_ids = []) + public function moveImagesToAlbums(array $image_ids = [], array $album_ids = []): void { if (count($image_ids) === 0) { - return false; + return; } $new_album_ids = []; @@ -982,22 +1015,23 @@ public function moveImagesToAlbums(array $image_ids = [], array $album_ids = []) * * The list of ordered albums id is supposed to be in the same parent album */ - public function saveAlbumsOrder(array $categories) + /** @phpstan-ignore-next-line */ // @FIX: albums + public function saveAlbumsOrder(array $albums): void { $current_rank_for_id_uppercat = []; $current_rank = 0; - foreach ($categories as $category) { - if (is_array($category)) { - $id = $category['id']; - $id_uppercat = $category['id_uppercat']; + foreach ($albums as $album) { + if (is_array($album)) { + $id = $album['id']; + $id_uppercat = $album['id_uppercat']; if (!isset($current_rank_for_id_uppercat[$id_uppercat])) { $current_rank_for_id_uppercat[$id_uppercat] = 0; } $current_rank = ++$current_rank_for_id_uppercat[$id_uppercat]; } else { - $id = $category; + $id = $album; $current_rank++; } @@ -1009,9 +1043,10 @@ public function saveAlbumsOrder(array $categories) } /** - * param $albums resource (array or null) return by method repository + * @param Album[] $albums */ - public function getAlbumThumbnails(User $user, $albums) + /** @phpstan-ignore-next-line */ // @FIX: return type + public function getAlbumThumbnails(User $user, array $albums): array { $album_thumbnails = []; $user_representative_updates_for = []; @@ -1060,6 +1095,10 @@ public function getAlbumThumbnails(User $user, $albums) return [$is_child_date_last, $album_thumbnails, $image_ids, $user_representative_updates_for]; } + /** + * @param Album[] $albums + */ + /** @phpstan-ignore-next-line */ // @FIX: define return type public function getInfosOfImages(User $user, array $albums, array $image_ids, ImageMapper $imageMapper) { $infos_of_images = []; diff --git a/src/DataMapper/ImageMapper.php b/src/DataMapper/ImageMapper.php index 27b29085b..257cec904 100644 --- a/src/DataMapper/ImageMapper.php +++ b/src/DataMapper/ImageMapper.php @@ -22,7 +22,7 @@ use App\Repository\ImageRepository; use App\Repository\RateRepository; use App\Services\DerivativeService; -use Phyxo\Functions\URL; +use DateTimeInterface; use Phyxo\Functions\Utils; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Filesystem\Filesystem; @@ -30,8 +30,21 @@ class ImageMapper { - private $router, $conf, $userMapper, $image_std_params, $albumMapper, $imageRepository, $imageTagRepository, $historyRepository; - private $translator, $imageAlbumRepository, $commentRepository, $caddieRepository, $favoriteRepository, $rateRepository, $derivativeService; + private RouterInterface $router; + private Conf $conf; + private UserMapper $userMapper; + private ImageStandardParams $image_std_params; + private AlbumMapper $albumMapper; + private ImageRepository $imageRepository; + private ImageTagRepository $imageTagRepository; + private HistoryRepository $historyRepository; + private TranslatorInterface $translator; + private ImageAlbumRepository $imageAlbumRepository; + private CommentRepository $commentRepository; + private CaddieRepository $caddieRepository; + private FavoriteRepository $favoriteRepository; + private RateRepository $rateRepository; + private DerivativeService $derivativeService; public function __construct( RouterInterface $router, @@ -72,7 +85,12 @@ public function getRepository(): ImageRepository return $this->imageRepository; } - public function getPicturesFromSelection($element_id, array $selection = [], string $section = '', int $start_id = 0, array $extra = []): array + /** + * @param array{current_day?: DateTimeInterface, date_type?: string, year?: int, month?: int, day?: int } $extra + * @param int[] $selection + */ + /** @phpstan-ignore-next-line */ // @FIX: define return type + public function getPicturesFromSelection(int $element_id, array $selection = [], string $section = '', int $start_id = 0, array $extra = []): array { $tpl_params = []; @@ -94,8 +112,8 @@ public function getPicturesFromSelection($element_id, array $selection = [], str unset($rank_of); // temporary fix - if ($section === 'categories') { - $section = 'category'; + if ($section === 'albums') { + $section = 'album'; } if (count($pictures) > 0) { @@ -107,12 +125,12 @@ public function getPicturesFromSelection($element_id, array $selection = [], str } } - foreach ($pictures as $row) { - if (in_array($section, ['category', 'list', 'tags', 'search'])) { + foreach ($pictures as $picture) { + if (in_array($section, ['album', 'list', 'tags', 'search'])) { $url = $this->router->generate( 'picture', [ - 'image_id' => $row['id'], + 'image_id' => $picture['image']->getId(), 'type' => $section, 'element_id' => $element_id, ] @@ -121,7 +139,7 @@ public function getPicturesFromSelection($element_id, array $selection = [], str $url = $this->router->generate( 'picture_categories_from_calendar', [ - 'image_id' => $row['id'], + 'image_id' => $picture['image']->getId(), 'start_id' => $start_id !== 0 ? 'start-' . $start_id : '', 'extra' => 'extr', ] @@ -130,7 +148,7 @@ public function getPicturesFromSelection($element_id, array $selection = [], str $url = $this->router->generate( 'picture_from_calendar', [ - 'image_id' => $row['id'], + 'image_id' => $picture['image']->getId(), 'date_type' => $extra['date_type'], 'year' => $extra['year'], 'month' => sprintf('%02d', $extra['month']), 'day' => sprintf('%02d', $extra['day']), 'start_id' => $start_id !== 0 ? 'start-' . $start_id : '', @@ -140,23 +158,23 @@ public function getPicturesFromSelection($element_id, array $selection = [], str $url = $this->router->generate( 'picture_by_type', [ - 'image_id' => $row['id'], + 'image_id' => $picture['image']->getId(), 'type' => $section, 'start_id' => $start_id !== 0 ? 'start-' . $start_id : '' ] ); } - if (isset($nb_comments_of, $nb_comments_of[$row['id']])) { - $row['NB_COMMENTS'] = $row['nb_comments'] = (int) $nb_comments_of[$row['id']]; + if (isset($nb_comments_of, $nb_comments_of[$picture['image']->getId()])) { + $picture['NB_COMMENTS'] = $picture['nb_comments'] = (int) $nb_comments_of[$picture['image']->getId()]; } - $name = Utils::render_element_name($row); - $desc = Utils::render_element_description($row, 'main_page_element_description'); + $name = Utils::render_element_name($picture); + $desc = Utils::render_element_description($picture, 'main_page_element_description'); - $tpl_var = array_merge($row, [ + $tpl_var = array_merge($picture, [ 'TN_ALT' => htmlspecialchars(strip_tags($name)), - 'TN_TITLE' => $this->getThumbnailTitle($row, $name, $desc), + 'TN_TITLE' => $this->getThumbnailTitle($picture, $name, $desc), 'URL' => $url, 'DESCRIPTION' => $desc, 'icon_ts' => '', @@ -167,14 +185,14 @@ public function getPicturesFromSelection($element_id, array $selection = [], str } if ($this->userMapper->getUser()->getUserInfos()->getShowNbHits()) { - $tpl_var['NB_HITS'] = $row['hit']; + $tpl_var['NB_HITS'] = $picture['image']->getHit(); } if ($section === 'best_rated') { - $name = '(' . $row['rating_score'] . ') ' . $name; + $name = '(' . $picture['image']->getRatingScore() . ') ' . $name; } elseif ($section === 'most_visited') { if (!$this->userMapper->getUser()->getUserInfos()->getShowNbHits()) { - $name = '(' . $row['hit'] . ') ' . $name; + $name = '(' . $picture['image']->getHit() . ') ' . $name; } } @@ -200,7 +218,7 @@ public function getPicturesFromSelection($element_id, array $selection = [], str * @param bool $physical_deletion * @return int number of deleted elements */ - public function deleteElements(array $ids, bool $physical_deletion = false) + public function deleteElements(array $ids, bool $physical_deletion = false): int { if (count($ids) == 0) { return 0; @@ -301,6 +319,7 @@ public function deleteElementFiles(array $ids = []) * @param string $comment * @return string */ + /** @phpstan-ignore-next-line */ // @FIX: define return type public function getThumbnailTitle($info, $title, $comment = ''): string { $details = []; diff --git a/tools/phpstan-doctrine-orm-bootstrap.php b/tools/phpstan-doctrine-orm-bootstrap.php index 522705889..cae201ac8 100644 --- a/tools/phpstan-doctrine-orm-bootstrap.php +++ b/tools/phpstan-doctrine-orm-bootstrap.php @@ -14,7 +14,9 @@ use App\Kernel; use Symfony\Component\Dotenv\Dotenv; -(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env'); +require __DIR__ . '/../vendor/autoload.php'; + +(new Dotenv())->bootEnv(__DIR__ . '/../.env'); $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); $kernel->boot();