Skip to content

Commit

Permalink
Remove Photo thumbnails and switch admin viewer to PhotoSwipe
Browse files Browse the repository at this point in the history
  • Loading branch information
tomudding committed Nov 21, 2023
1 parent 212bc9c commit a91178b
Show file tree
Hide file tree
Showing 25 changed files with 697 additions and 1,234 deletions.
66 changes: 18 additions & 48 deletions module/Photo/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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',
],
Expand Down Expand Up @@ -257,7 +248,7 @@
'album_upload' => [
'type' => Segment::class,
'options' => [
'route' => '/album[/:album_id]/upload',
'route' => '/album/:album_id/upload',
'defaults' => [
'action' => 'upload',
],
Expand All @@ -281,7 +272,7 @@
'album_delete' => [
'type' => Segment::class,
'options' => [
'route' => '/album[/:album_id]/delete',
'route' => '/album/:album_id/delete',
'defaults' => [
'action' => 'delete',
],
Expand All @@ -293,7 +284,7 @@
'album_cover' => [
'type' => Segment::class,
'options' => [
'route' => '/album[/:album_id]/cover',
'route' => '/album/:album_id/cover',
'defaults' => [
'action' => 'cover',
],
Expand All @@ -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' => [
Expand Down Expand Up @@ -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/',
Expand Down
74 changes: 47 additions & 27 deletions module/Photo/src/Controller/AlbumAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,8 +20,11 @@
class AlbumAdminController extends AbstractActionController
{
public function __construct(

Check failure on line 22 in module/Photo/src/Controller/AlbumAdminController.php

View workflow job for this annotation

GitHub Actions / php-codesniffer / PHP_CodeSniffer (8.2)

Method \Photo\Controller\AlbumAdminController::__construct() does not have @param annotation for its traversable parameter $photoConfig.
private readonly AclService $aclService,

Check failure on line 23 in module/Photo/src/Controller/AlbumAdminController.php

View workflow job for this annotation

GitHub Actions / PHPStan

Property Photo\Controller\AlbumAdminController::$aclService is never read, only written.
private readonly Translator $translator,

Check failure on line 24 in module/Photo/src/Controller/AlbumAdminController.php

View workflow job for this annotation

GitHub Actions / PHPStan

Property Photo\Controller\AlbumAdminController::$translator is never read, only written.
private readonly AdminService $adminService,
private readonly AlbumService $albumService,
private readonly array $photoConfig,
) {
}

Expand All @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand All @@ -115,6 +134,7 @@ public function editAction(): Response|ViewModel
return new ViewModel(
[
'form' => $form,
'album' => $form->getObject(),
],
);
}
Expand Down
22 changes: 18 additions & 4 deletions module/Photo/src/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
}
}
27 changes: 0 additions & 27 deletions module/Photo/src/Controller/Factory/Plugin/AlbumPluginFactory.php

This file was deleted.

Loading

0 comments on commit a91178b

Please sign in to comment.