From a91178b8f5f8e0a55a871ff7014ef32374540f05 Mon Sep 17 00:00:00 2001 From: Tom Udding Date: Fri, 27 Oct 2023 22:57:28 +0200 Subject: [PATCH] Remove `Photo` thumbnails and switch admin viewer to PhotoSwipe --- module/Photo/config/module.config.php | 66 +-- .../src/Controller/AlbumAdminController.php | 74 +-- module/Photo/src/Controller/ApiController.php | 22 +- .../Factory/AlbumAdminControllerFactory.php | 4 + .../Factory/ApiControllerFactory.php | 1 + .../Factory/Plugin/AlbumPluginFactory.php | 27 -- .../src/Controller/PhotoAdminController.php | 26 -- .../Plugin/AlbumPaginatorAdapter.php | 69 --- .../src/Controller/Plugin/AlbumPlugin.php | 163 ------- module/Photo/src/Mapper/Photo.php | 58 --- module/Photo/src/Model/Photo.php | 52 +-- module/Photo/src/Service/Admin.php | 18 - module/Photo/src/Service/AlbumCover.php | 2 +- module/Photo/src/Service/Photo.php | 96 ---- module/Photo/view/partial/albums.phtml | 48 ++ module/Photo/view/partial/years.phtml | 62 +++ module/Photo/view/photo/album-admin/add.phtml | 5 +- .../Photo/view/photo/album-admin/edit.phtml | 8 + .../Photo/view/photo/album-admin/index.phtml | 292 +----------- .../Photo/view/photo/album-admin/view.phtml | 439 ++++++++++++++++++ .../Photo/view/photo/album-admin/year.phtml | 29 ++ .../Photo/view/photo/photo-admin/index.phtml | 168 ------- module/Photo/view/photo/photo/index.phtml | 61 +-- psalm/psalm-baseline.xml | 5 - public/js/photo-admin.js | 136 +----- 25 files changed, 697 insertions(+), 1234 deletions(-) delete mode 100644 module/Photo/src/Controller/Factory/Plugin/AlbumPluginFactory.php delete mode 100644 module/Photo/src/Controller/Plugin/AlbumPaginatorAdapter.php delete mode 100644 module/Photo/src/Controller/Plugin/AlbumPlugin.php create mode 100644 module/Photo/view/partial/albums.phtml create mode 100644 module/Photo/view/partial/years.phtml create mode 100644 module/Photo/view/photo/album-admin/view.phtml create mode 100644 module/Photo/view/photo/album-admin/year.phtml delete mode 100644 module/Photo/view/photo/photo-admin/index.phtml diff --git a/module/Photo/config/module.config.php b/module/Photo/config/module.config.php index 86141eb7eb..0bce46832f 100644 --- a/module/Photo/config/module.config.php +++ b/module/Photo/config/module.config.php @@ -16,11 +16,9 @@ use Photo\Controller\Factory\ApiControllerFactory; use Photo\Controller\Factory\PhotoAdminControllerFactory; use Photo\Controller\Factory\PhotoControllerFactory; -use Photo\Controller\Factory\Plugin\AlbumPluginFactory; use Photo\Controller\Factory\TagControllerFactory; use Photo\Controller\PhotoAdminController; use Photo\Controller\PhotoController; -use Photo\Controller\Plugin\AlbumPlugin; use Photo\Controller\TagController; return [ @@ -178,50 +176,43 @@ ], 'may_terminate' => true, 'child_routes' => [ - 'default' => [ - 'type' => Segment::class, - 'options' => [ - 'route' => '/index', - ], - ], 'album' => [ - 'type' => Literal::class, + 'type' => Segment::class, 'options' => [ - 'route' => '/album', + 'route' => '/album/:album_id', 'defaults' => [ - 'action' => 'index', + 'action' => 'view', + ], + 'constraints' => [ + 'album_id' => '[0-9]+', ], ], ], - 'album_index' => [ + 'album_year' => [ 'type' => Segment::class, 'options' => [ - 'route' => '/album[/:album_id]', + 'route' => '/albums/:year', 'defaults' => [ - 'action' => 'page', + 'action' => 'year', ], 'constraints' => [ - 'album_id' => '[0-9]+', + 'year' => '[0-9]+', ], ], ], - 'album_page' => [ - 'type' => Segment::class, + 'album_unpublished' => [ + 'type' => Literal::class, 'options' => [ - 'route' => '/album[/:album_id][/:page]', + 'route' => '/albums/unpublished', 'defaults' => [ - 'action' => 'page', - ], - 'constraints' => [ - 'album_id' => '[0-9]+', - 'page' => '[0-9]+', + 'action' => 'unpublished', ], ], ], 'album_edit' => [ 'type' => Segment::class, 'options' => [ - 'route' => '/album[/:album_id]/edit', + 'route' => '/album/:album_id/edit', 'defaults' => [ 'action' => 'edit', ], @@ -257,7 +248,7 @@ 'album_upload' => [ 'type' => Segment::class, 'options' => [ - 'route' => '/album[/:album_id]/upload', + 'route' => '/album/:album_id/upload', 'defaults' => [ 'action' => 'upload', ], @@ -281,7 +272,7 @@ 'album_delete' => [ 'type' => Segment::class, 'options' => [ - 'route' => '/album[/:album_id]/delete', + 'route' => '/album/:album_id/delete', 'defaults' => [ 'action' => 'delete', ], @@ -293,7 +284,7 @@ 'album_cover' => [ 'type' => Segment::class, 'options' => [ - 'route' => '/album[/:album_id]/cover', + 'route' => '/album/:album_id/cover', 'defaults' => [ 'action' => 'cover', ], @@ -302,19 +293,6 @@ ], ], ], - 'photo_index' => [ - 'type' => Segment::class, - 'options' => [ - 'route' => '/photo[/:photo_id]', - 'defaults' => [ - 'controller' => PhotoAdminController::class, - 'action' => 'index', - ], - 'constraints' => [ - 'photo_id' => '[0-9]+', - ], - ], - ], 'photo_move' => [ 'type' => Segment::class, 'options' => [ @@ -394,14 +372,6 @@ TagController::class => TagControllerFactory::class, ], ], - 'controller_plugins' => [ - 'aliases' => [ - 'AlbumPlugin' => AlbumPlugin::class, - ], - 'factories' => [ - AlbumPlugin::class => AlbumPluginFactory::class, - ], - ], 'view_manager' => [ 'template_path_stack' => [ 'photo' => __DIR__ . '/../view/', diff --git a/module/Photo/src/Controller/AlbumAdminController.php b/module/Photo/src/Controller/AlbumAdminController.php index 08cd75bc10..022666b248 100644 --- a/module/Photo/src/Controller/AlbumAdminController.php +++ b/module/Photo/src/Controller/AlbumAdminController.php @@ -7,8 +7,10 @@ use Laminas\Http\Request; use Laminas\Http\Response; use Laminas\Mvc\Controller\AbstractActionController; +use Laminas\Mvc\I18n\Translator; use Laminas\View\Model\JsonModel; use Laminas\View\Model\ViewModel; +use Photo\Service\AclService; use Photo\Service\Admin as AdminService; use Photo\Service\Album as AlbumService; use Throwable; @@ -18,8 +20,11 @@ class AlbumAdminController extends AbstractActionController { public function __construct( + private readonly AclService $aclService, + private readonly Translator $translator, private readonly AdminService $adminService, private readonly AlbumService $albumService, + private readonly array $photoConfig, ) { } @@ -28,22 +33,55 @@ public function __construct( */ public function indexAction(): ViewModel { + // TODO: Add ACL $years = $this->albumService->getAlbumYears(); - $albumsByYear = []; - foreach ($years as $year) { - $albumsByYear[$year] = $this->albumService->getAlbumsByYear($year); - } - - $albumsWithoutDate = $this->albumService->getAlbumsWithoutDate(); return new ViewModel( [ - 'albumsByYear' => array_reverse($albumsByYear, true), - 'albumsWithoutDate' => $albumsWithoutDate, + 'years' => $years, ], ); } + /** + * Show a specific album. + */ + public function viewAction(): ViewModel + { + // TODO: Add ACL + $albumId = (int) $this->params()->fromRoute('album_id'); + $album = $this->albumService->getAlbum($albumId); + + if (null === $album) { + return $this->notFoundAction(); + } + + $years = $this->albumService->getAlbumYears(); + + return new ViewModel([ + 'album' => $album, + 'config' => $this->photoConfig, + 'years' => $years, + 'year' => $this->albumService->getAssociationYear($album->getStartDateTime()), + ]); + } + + /** + * Show all albums in a specific year. + */ + public function yearAction(): ViewModel + { + // TODO: Add ACL + $year = (int) $this->params()->fromRoute('year'); + $years = $this->albumService->getAlbumYears(); + + return new ViewModel([ + 'albums' => $this->albumService->getAlbumsByYear($year), + 'years' => $years, + 'year' => $year, + ]); + } + /** * Retrieves the album creation form and saves data if needed. */ @@ -72,25 +110,6 @@ public function createAction(): Response|ViewModel ); } - /** - * Retrieves photos on a certain page. - */ - public function pageAction(): JsonModel|ViewModel - { - $albumId = (int) $this->params()->fromRoute('album_id'); - $activePage = (int) $this->params()->fromRoute('page'); - - if (0 !== $albumId) { - $albumPage = $this->plugin('AlbumPlugin')->getAlbumPageAsArray($albumId, $activePage); - - if (null !== $albumPage) { - return new JsonModel($albumPage); - } - } - - return $this->notFoundAction(); - } - /** * Retrieves the album editing form and saves changes. */ @@ -115,6 +134,7 @@ public function editAction(): Response|ViewModel return new ViewModel( [ 'form' => $form, + 'album' => $form->getObject(), ], ); } diff --git a/module/Photo/src/Controller/ApiController.php b/module/Photo/src/Controller/ApiController.php index 024c40c0a4..c8c8d0e9ef 100644 --- a/module/Photo/src/Controller/ApiController.php +++ b/module/Photo/src/Controller/ApiController.php @@ -11,6 +11,7 @@ use Photo\Mapper\Tag as TagMapper; use Photo\Mapper\Vote as VoteMapper; use Photo\Service\AclService; +use Photo\Service\Album as AlbumService; use User\Permissions\NotAllowedException; class ApiController extends AbstractActionController @@ -20,25 +21,38 @@ public function __construct( private readonly Translator $translator, private readonly TagMapper $tagMapper, private readonly VoteMapper $voteMapper, + private readonly AlbumService $albumService, ) { } /** - * Retrieve a list of all photo's in an album. + * Retrieve a list of all photos in an album. * * This API call is intended for external scripts. Like the AViCo TV screen - * that needs a list of all photo's. + * that needs a list of all photos. */ public function listAction(): JsonModel|ViewModel { $albumId = (int) $this->params()->fromRoute('album_id'); - $album = $this->plugin('AlbumPlugin')->getAlbumAsArray($albumId); + $album = $this->albumService->getAlbum($albumId); if (null === $album) { return $this->notFoundAction(); } - return new JsonModel($album); + $albumArray = $album->toArrayWithChildren(); + + $photos = $albumArray['photos']; + $albums = $albumArray['children']; + + $albumArray['photos'] = []; + $albumArray['children'] = []; + + return new JsonModel([ + 'album' => $albumArray, + 'photos' => $photos, + 'albums' => $albums, + ]); } public function detailsAction(): JsonModel diff --git a/module/Photo/src/Controller/Factory/AlbumAdminControllerFactory.php b/module/Photo/src/Controller/Factory/AlbumAdminControllerFactory.php index 11c8217684..4599915123 100644 --- a/module/Photo/src/Controller/Factory/AlbumAdminControllerFactory.php +++ b/module/Photo/src/Controller/Factory/AlbumAdminControllerFactory.php @@ -4,6 +4,7 @@ namespace Photo\Controller\Factory; +use Laminas\Mvc\I18n\Translator as MvcTranslator; use Laminas\ServiceManager\Factory\FactoryInterface; use Photo\Controller\AlbumAdminController; use Psr\Container\ContainerInterface; @@ -19,8 +20,11 @@ public function __invoke( ?array $options = null, ): AlbumAdminController { return new AlbumAdminController( + $container->get('photo_service_acl'), + $container->get(MvcTranslator::class), $container->get('photo_service_admin'), $container->get('photo_service_album'), + $container->get('config')['photo'], ); } } diff --git a/module/Photo/src/Controller/Factory/ApiControllerFactory.php b/module/Photo/src/Controller/Factory/ApiControllerFactory.php index 547b7c4a4c..a97668d5a2 100644 --- a/module/Photo/src/Controller/Factory/ApiControllerFactory.php +++ b/module/Photo/src/Controller/Factory/ApiControllerFactory.php @@ -24,6 +24,7 @@ public function __invoke( $container->get(MvcTranslator::class), $container->get('photo_mapper_tag'), $container->get('photo_mapper_vote'), + $container->get('photo_service_album'), ); } } diff --git a/module/Photo/src/Controller/Factory/Plugin/AlbumPluginFactory.php b/module/Photo/src/Controller/Factory/Plugin/AlbumPluginFactory.php deleted file mode 100644 index 1ac8044e22..0000000000 --- a/module/Photo/src/Controller/Factory/Plugin/AlbumPluginFactory.php +++ /dev/null @@ -1,27 +0,0 @@ -get('photo_service_album'), - $container->get('photo_service_photo'), - $container->get('config')['photo'], - ); - } -} diff --git a/module/Photo/src/Controller/PhotoAdminController.php b/module/Photo/src/Controller/PhotoAdminController.php index 4e08f007c8..e49529537b 100644 --- a/module/Photo/src/Controller/PhotoAdminController.php +++ b/module/Photo/src/Controller/PhotoAdminController.php @@ -7,11 +7,9 @@ use Laminas\Http\Request; use Laminas\Mvc\Controller\AbstractActionController; use Laminas\View\Model\JsonModel; -use Laminas\View\Model\ViewModel; use Photo\Service\Album as AlbumService; use Photo\Service\Photo as PhotoService; -use function array_merge; use function intval; class PhotoAdminController extends AbstractActionController @@ -22,30 +20,6 @@ public function __construct( ) { } - /** - * Shows an admin page for the specified photo. - * - * TODO: Potentially remove, as the admin interface can already move/delete images from the global view. - */ - public function indexAction(): ViewModel - { - $photoId = (int) $this->params()->fromRoute('photo_id'); - $data = $this->photoService->getPhotoData($photoId); - - if (null === $data) { - return $this->notFoundAction(); - } - - $path = []; //The path to use in the breadcrumb navigation bar - $parent = $data['photo']->getAlbum(); - while (null !== $parent) { - $path[] = $parent; - $parent = $parent->getParent(); - } - - return new ViewModel(array_merge($data, ['path' => $path])); - } - /** * Places a photo in another album. */ diff --git a/module/Photo/src/Controller/Plugin/AlbumPaginatorAdapter.php b/module/Photo/src/Controller/Plugin/AlbumPaginatorAdapter.php deleted file mode 100644 index 91ba75e8dc..0000000000 --- a/module/Photo/src/Controller/Plugin/AlbumPaginatorAdapter.php +++ /dev/null @@ -1,69 +0,0 @@ - - */ -class AlbumPaginatorAdapter implements AdapterInterface -{ - /** - * Item count. - */ - protected ?int $count = null; - - public function __construct( - private readonly PhotoService $photoService, - private readonly AlbumService $albumService, - private readonly ?AlbumModel $album = null, - ) { - $this->count = $album->getAlbumCount() + $album->getPhotoCount(false); - } - - /** - * Returns an array of items for a page. - * - * @param int $offset Page offset - * @param int $itemCountPerPage Number of items per page - * - * @return array - */ - public function getItems( - $offset, - $itemCountPerPage, - ): array { - $albums = $this->albumService->getAlbums( - $this->album, - $offset, - $itemCountPerPage, - ); - - $photoCount = $itemCountPerPage - count($albums); - $photoStart = max($offset - $this->album->getAlbumCount(), 0); - $photos = $this->photoService->getPhotos($this->album, $photoStart, $photoCount); - - return array_merge($albums, $photos); - } - - /** - * Returns the total number of rows in the array. - */ - public function count(): int - { - return $this->count; - } -} diff --git a/module/Photo/src/Controller/Plugin/AlbumPlugin.php b/module/Photo/src/Controller/Plugin/AlbumPlugin.php deleted file mode 100644 index c2d2d4e3fc..0000000000 --- a/module/Photo/src/Controller/Plugin/AlbumPlugin.php +++ /dev/null @@ -1,163 +0,0 @@ -albumService->getAlbum($albumId); - - if (null === $album) { - return null; - } - - $albumArray = $album->toArrayWithChildren(); - - $photos = $albumArray['photos']; - $albums = $albumArray['children']; - - $albumArray['photos'] = []; - $albumArray['children'] = []; - - return [ - 'album' => $albumArray, - 'basedir' => $this->photoService->getBaseDirectory(), - 'photos' => $photos, - 'albums' => $albums, - ]; - } - - /** - * Gets an album page, but returns all objects as assoc arrays. - * - * @param int $albumId the id of the album - * @param int $activePage the page of the album - * - * @return ?array{ - * album: ImportedAlbumArrayType, - * basedir: string, - * pages: ImportedPagesType, - * photos: ImportedPhotoArrayType[], - * albums: ImportedAlbumArrayType[], - * } - * - * @throws Exception - */ - public function getAlbumPageAsArray( - int $albumId, - int $activePage, - ): ?array { - $page = $this->getAlbumPage($albumId, $activePage); - - if (null === $page) { - return null; - } - - $paginator = $page['paginator']; - $photos = []; - $albums = []; - - foreach ($paginator as $item) { - if ('album' === $item->getResourceId()) { - $albums[] = $item->toArray(); - } else { - $photos[] = $item->toArray(); - } - } - - return [ - 'album' => $page['album']->toArray(), - 'basedir' => $page['basedir'], - 'pages' => $paginator->getPages(), - 'photos' => $photos, - 'albums' => $albums, - ]; - } - - /** - * Retrieves all data needed to display a page of an album. - * - * @param int $albumId the id of the album - * @param int $activePage the page of the album - * @param string $type "album"|"member"|"year" - * - * @return ?array{ - * album: Album, - * basedir: string, - * paginator: Paginator\Paginator, - * } - * - * @throws Exception - */ - public function getAlbumPage( - int $albumId, - int $activePage, - string $type = 'album', - ): ?array { - $album = $this->albumService->getAlbum($albumId, $type); - - if (null === $album) { - return null; - } - - $paginator = new Paginator\Paginator( - new AlbumPaginatorAdapter( - $this->photoService, - $this->albumService, - $album, - ), - ); - - $paginator->setCurrentPageNumber($activePage); - $paginator->setItemCountPerPage($this->photoConfig['max_photos_page']); - $basedir = $this->photoService->getBaseDirectory(); - - return [ - 'album' => $album, - 'basedir' => $basedir, - 'paginator' => $paginator, - ]; - } -} diff --git a/module/Photo/src/Mapper/Photo.php b/module/Photo/src/Mapper/Photo.php index 4cd3b33fc4..5cbf29cfc0 100644 --- a/module/Photo/src/Mapper/Photo.php +++ b/module/Photo/src/Mapper/Photo.php @@ -75,64 +75,6 @@ public function getRandomPhotosFromAlbums( return $qb->getQuery()->getResult(); } - /** - * Returns the next photo in the album to display. - * - * @return PhotoModel|null Photo if there is a next photo, null otherwise - */ - public function getNextPhoto( - PhotoModel $photo, - AlbumModel $album, - ): ?PhotoModel { - $qb = $this->getRepository()->createQueryBuilder('p'); - - if ($album instanceof MemberAlbumModel) { - $qb->innerJoin('p.tags', 't') - ->where('t.member = ?1 AND p.dateTime > ?2') - ->setParameter(1, $album->getMember()) - ->setParameter(2, $photo->getDateTime()); - } else { - $qb->where('p.dateTime > ?1 AND p.album = ?2') - ->setParameter(1, $photo->getDateTime()) - ->setParameter(2, $photo->getAlbum()); - } - - $qb->orderBy('p.dateTime', 'ASC') - ->setMaxResults(1); - $res = $qb->getQuery()->getResult(); - - return empty($res) ? null : $res[0]; - } - - /** - * Returns the previous photo in the album to display. - * - * @return PhotoModel|null Photo if there is a previous photo, null otherwise - */ - public function getPreviousPhoto( - PhotoModel $photo, - AlbumModel $album, - ): ?PhotoModel { - $qb = $this->getRepository()->createQueryBuilder('p'); - - if ($album instanceof MemberAlbumModel) { - $qb->innerJoin('p.tags', 't') - ->where('t.member = ?1 AND p.dateTime < ?2') - ->setParameter(1, $album->getMember()) - ->setParameter(2, $photo->getDateTime()); - } else { - $qb->where('p.dateTime < ?1 AND p.album = ?2') - ->setParameter(1, $photo->getDateTime()) - ->setParameter(2, $photo->getAlbum()); - } - - $qb->orderBy('p.dateTime', 'DESC') - ->setMaxResults(1); - $res = $qb->getQuery()->getResult(); - - return empty($res) ? null : $res[0]; - } - /** * Checks if the specified photo exists in the database already and returns it if it does. * diff --git a/module/Photo/src/Model/Photo.php b/module/Photo/src/Model/Photo.php index 519fc35f3a..6ea3b72eff 100644 --- a/module/Photo/src/Model/Photo.php +++ b/module/Photo/src/Model/Photo.php @@ -37,8 +37,6 @@ * iso: ?int, * album: ImportedAlbumArrayType, * path: string, - * smallThumbPath: string, - * largeThumbPath: string, * longitude: ?float, * latitude: ?float, * } @@ -147,20 +145,6 @@ class Photo implements ResourceInterface #[Column(type: 'string')] protected string $path; - /** - * The path where the small thumbnail of the photo is located relative to - * the storage directory. - */ - #[Column(type: 'string')] - protected string $smallThumbPath; - - /** - * The path where the large thumbnail of the photo is located relative to - * the storage directory. - */ - #[Column(type: 'string')] - protected string $largeThumbPath; - /** * The GPS longitude of the location where the photo was taken. */ @@ -330,22 +314,6 @@ public function getPath(): string return $this->path; } - /** - * Get the path where the large thumbnail is stored. - */ - public function getLargeThumbPath(): string - { - return $this->largeThumbPath; - } - - /** - * Get the path where the large thumbnail is stored. - */ - public function getSmallThumbPath(): string - { - return $this->smallThumbPath; - } - /** * Get the GPS longitude of the location where the photo was taken. */ @@ -397,7 +365,7 @@ public function getAspectRatio(): ?float #[PrePersist] public function calculateAspectRatio(): void { - [$width, $height] = getimagesize('public/data/' . $this->getSmallThumbPath()); + [$width, $height] = getimagesize('public/data/' . $this->getPath()); $this->aspectRatio = $height / $width; } @@ -489,22 +457,6 @@ public function setPath(string $path): void $this->path = $path; } - /** - * Set the path where the large thumbnail is stored. - */ - public function setLargeThumbPath(string $path): void - { - $this->largeThumbPath = $path; - } - - /** - * Set the path where the small thumbnail is stored. - */ - public function setSmallThumbPath(string $path): void - { - $this->smallThumbPath = $path; - } - /** * Set the GPS longitude of the location where the photo was taken. */ @@ -606,8 +558,6 @@ public function toArray(): array 'iso' => $this->getIso(), 'album' => $this->getAlbum()->toArray(), 'path' => $this->getPath(), - 'smallThumbPath' => $this->getSmallThumbPath(), - 'largeThumbPath' => $this->getLargeThumbPath(), 'longitude' => $this->getLongitude(), 'latitude' => $this->getLatitude(), ]; diff --git a/module/Photo/src/Service/Admin.php b/module/Photo/src/Service/Admin.php index 61d56ecc26..55a4f076b6 100644 --- a/module/Photo/src/Service/Admin.php +++ b/module/Photo/src/Service/Admin.php @@ -80,24 +80,6 @@ public function storeUploadedPhoto( $mapper = $this->photoMapper; $mapper->getConnection()->beginTransaction(); try { - /* - * Create and set the storage paths for thumbnails. - */ - $photo->setLargeThumbPath( - $this->createThumbnail( - $path, - $config['large_thumb_size']['width'], - $config['large_thumb_size']['height'], - ), - ); - $photo->setSmallThumbPath( - $this->createThumbnail( - $path, - $config['small_thumb_size']['width'], - $config['small_thumb_size']['height'], - ), - ); - if ($move) { unlink($path); } diff --git a/module/Photo/src/Service/AlbumCover.php b/module/Photo/src/Service/AlbumCover.php index d95eaf6bf2..13b065220d 100644 --- a/module/Photo/src/Service/AlbumCover.php +++ b/module/Photo/src/Service/AlbumCover.php @@ -126,7 +126,7 @@ protected function getImages( //convert the photo objects to Imagick objects $images = []; foreach ($photos as $photo) { - $imagePath = $this->storageConfig['storage_dir'] . '/' . $photo->getSmallThumbPath(); + $imagePath = $this->storageConfig['storage_dir'] . '/' . $photo->getPath(); $images[] = new Imagick($imagePath); } diff --git a/module/Photo/src/Service/Photo.php b/module/Photo/src/Service/Photo.php index d1ed96f9d8..3f34029022 100644 --- a/module/Photo/src/Service/Photo.php +++ b/module/Photo/src/Service/Photo.php @@ -135,100 +135,6 @@ public function getPhotoFileName(PhotoModel $photo): string return $albumName . '-' . $photo->getDateTime()->format('Y') . '-' . $photo->getId() . $extension; } - /** - * Get the photo data belonging to a certain photo. - * - * @param int $photoId the id of the photo to retrieve - * - * @return ?array{ - * photo: PhotoModel, - * next: ?PhotoModel, - * previous: ?PhotoModel, - * isTagged: bool, - * isProfilePhoto: bool, - * isExplicitProfilePhoto: bool, - * } - * - * @throws Exception - */ - public function getPhotoData( - int $photoId, - ?AlbumModel $album = null, - ): ?array { - if (!$this->aclService->isAllowed('view', 'photo')) { - throw new NotAllowedException($this->translator->translate('Not allowed to view photos')); - } - - $photo = $this->getPhoto($photoId); - - // photo does not exist - if (null === $photo) { - return null; - } - - if (null === $album) { - // Default type for albums is Album. - $album = new AlbumModel(); - } - - $next = $this->getNextPhoto($photo, $album); - $previous = $this->getPreviousPhoto($photo, $album); - - $lidnr = $this->aclService->getUserIdentityOrThrowException()->getLidnr(); - $isTagged = $this->isTaggedIn($photoId, $lidnr); - $profilePhoto = $this->getStoredProfilePhoto($lidnr); - $isProfilePhoto = false; - $isExplicitProfilePhoto = false; - - if (null !== $profilePhoto) { - $isExplicitProfilePhoto = $profilePhoto->isExplicit(); - if ($photoId === $profilePhoto->getPhoto()->getId()) { - $isProfilePhoto = true; - } - } - - return [ - 'photo' => $photo, - 'next' => $next, - 'previous' => $previous, - 'isTagged' => $isTagged, - 'isProfilePhoto' => $isProfilePhoto, - 'isExplicitProfilePhoto' => $isExplicitProfilePhoto, - ]; - } - - /** - * Returns the next photo in the album to display. - * - * @return PhotoModel|null the next photo - */ - public function getNextPhoto( - PhotoModel $photo, - AlbumModel $album, - ): ?PhotoModel { - if (!$this->aclService->isAllowed('view', 'photo')) { - throw new NotAllowedException($this->translator->translate('Not allowed to view photos')); - } - - return $this->photoMapper->getNextPhoto($photo, $album); - } - - /** - * Returns the previous photo in the album to display. - * - * @return PhotoModel|null the next photo - */ - public function getPreviousPhoto( - PhotoModel $photo, - AlbumModel $album, - ): ?PhotoModel { - if (!$this->aclService->isAllowed('view', 'photo')) { - throw new NotAllowedException($this->translator->translate('Not allowed to view photos')); - } - - return $this->photoMapper->getPreviousPhoto($photo, $album); - } - /** * Removes a photo from the database and deletes its files, including thumbs * from the server. @@ -262,8 +168,6 @@ public function deletePhoto(int $photoId): bool public function deletePhotoFiles(PhotoModel $photo): void { $this->deletePhotoFile($photo->getPath()); - $this->deletePhotoFile($photo->getLargeThumbPath()); - $this->deletePhotoFile($photo->getSmallThumbPath()); } /** diff --git a/module/Photo/view/partial/albums.phtml b/module/Photo/view/partial/albums.phtml new file mode 100644 index 0000000000..6b8bba7bd4 --- /dev/null +++ b/module/Photo/view/partial/albums.phtml @@ -0,0 +1,48 @@ + +sub(new DateInterval('P7D')); ?> + + getPhotoCount() > 0): ?> + + + diff --git a/module/Photo/view/partial/years.phtml b/module/Photo/view/partial/years.phtml new file mode 100644 index 0000000000..5fdf0eb662 --- /dev/null +++ b/module/Photo/view/partial/years.phtml @@ -0,0 +1,62 @@ + +
+
+ +
+
+
diff --git a/module/Photo/view/photo/album-admin/add.phtml b/module/Photo/view/photo/album-admin/add.phtml index 9705752c69..192ee4f432 100644 --- a/module/Photo/view/photo/album-admin/add.phtml +++ b/module/Photo/view/photo/album-admin/add.phtml @@ -32,10 +32,9 @@ $this->headLink()->appendStylesheet($this->basepath('css/dropzone.css')); $this->breadcrumbs() ->addBreadcrumb($this->translate('Photos'), true, $this->url('admin_photo')) ->addBreadcrumb($album->getName(), true, $this->url( - 'admin_photo', - [], + 'admin_photo/album', [ - 'fragment' => $album->getId(), + 'album_id' => $album->getId(), ], )) ->addBreadcrumb($this->translate('Upload Photos')); diff --git a/module/Photo/view/photo/album-admin/edit.phtml b/module/Photo/view/photo/album-admin/edit.phtml index 091c1110e7..7723443d9f 100644 --- a/module/Photo/view/photo/album-admin/edit.phtml +++ b/module/Photo/view/photo/album-admin/edit.phtml @@ -5,14 +5,22 @@ declare(strict_types=1); use Application\View\HelperTrait; use Laminas\View\Renderer\PhpRenderer; use Photo\Form\EditAlbum as EditAlbumForm; +use Photo\Model\Album as AlbumModel; /** * @var PhpRenderer|HelperTrait $this + * @var AlbumModel $album * @var EditAlbumForm $form */ $this->breadcrumbs() ->addBreadcrumb($this->translate('Photos'), true, $this->url('admin_photo')) + ->addBreadcrumb($this->escapeHtml($album->getName()), true, $this->url( + 'admin_photo/album', + [ + 'album_id' => $album->getId(), + ], + )) ->addBreadcrumb($this->translate('Edit Album')); $form->prepare(); diff --git a/module/Photo/view/photo/album-admin/index.phtml b/module/Photo/view/photo/album-admin/index.phtml index 032d241aeb..2fc7dc1dc1 100644 --- a/module/Photo/view/photo/album-admin/index.phtml +++ b/module/Photo/view/photo/album-admin/index.phtml @@ -7,295 +7,19 @@ use Laminas\View\Renderer\PhpRenderer; /** * @var PhpRenderer|HelperTrait $this - * @var array $albumsByYear + * @var int[] $years */ -$this->headScript() - ->appendFile( - $this->basepath('js/photo.js'), - 'text/javascript', - ['nonce' => NONCE_REPLACEMENT_STRING], - ) - ->appendFile( - $this->basepath('js/photo-admin.js'), - 'text/javascript', - ['nonce' => NONCE_REPLACEMENT_STRING], - ) - ->appendFile( - $this->basepath('js/tree.js'), - 'text/javascript', - ['nonce' => NONCE_REPLACEMENT_STRING], - ); -$this->headLink() - ->appendStylesheet($this->basepath('css/tree.css')); - $this->breadcrumbs() ->addBreadcrumb($this->translate('Photos')); - -$this->scriptUrl()->requireUrl('admin_photo/album_page', ['album_id', 'page']) - ->requireUrls( - [ - 'admin_photo/album_edit', - 'admin_photo/album_delete', - 'admin_photo/album_add', - 'admin_photo/album_create', - 'admin_photo/album_move', - 'admin_photo/album_delete', - 'admin_photo/album_cover', - 'admin_photo/album_index' - ], - ['album_id'] - ) - ->requireUrls( - ['admin_photo/photo_index', 'admin_photo/photo_delete', 'admin_photo/photo_move'], - ['photo_id'] - ) - ->requireUrl('home'); ?> -

translate('Photo admin') ?>

-
+partial('partial/years', ['years' => $years, 'admin' => true]) ?>
-
-
-
-
    - -
  • - - escapeHtml($album->getName()) ?> - - getChildren(); - if (!$children->isEmpty()): - ?> -
      - -
    - -
  • - $albums): - if (!empty($albums)): - $nextYear = $year + 1; - ?> -
  • - -
      - -
    -
  • - -
  • - translate('Other albums'); ?> -
      - -
    -
  • - -
-
-
-
-
- - -  translate('Create new album') ?> -
-
- -  translate('Edit album') ?> - -  translate('Add photos') ?> - - - -

- - -
-
- - -
-
-
- - - - - - - - - - - - - - -