Skip to content

Commit

Permalink
Replace getForbiddenCategories by getForbiddenAlbums
Browse files Browse the repository at this point in the history
Cope with #65. Start fixing code for PHPStan : cope with #89
  • Loading branch information
nikrou committed Mar 4, 2022
1 parent 608efc1 commit 320719e
Show file tree
Hide file tree
Showing 45 changed files with 600 additions and 381 deletions.
28 changes: 14 additions & 14 deletions features/web/search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ Feature: Searching for images
When I am on homepage
And I follow "Search"
Then the select "authors" should contain:
"""
author1 (one photo)
author2 (2 photos)
author3 (one photo)
"""
"""
author1 (one photo)
author2 (2 photos)
author3 (one photo)
"""
When I select "author2" from "authors"
And I press "Submit"
Then I should see photo "photo 2"
Expand All @@ -75,10 +75,10 @@ Feature: Searching for images
When I am on homepage
And I follow "Search"
Then the select "tags" should contain:
"""
tag 1 (2 photos)
tag 2 (2 photos)
"""
"""
tag 1 (2 photos)
tag 2 (2 photos)
"""
When I select "tag 2" from "tags"
And I press "Submit"
Then I should see photo "photo 1"
Expand All @@ -91,11 +91,11 @@ Feature: Searching for images
When I am on homepage
And I follow "Search"
Then the select "tags" should contain:
"""
tag 1 (2 photos)
tag 2 (3 photos)
tag 3 (one photo)
"""
"""
tag 1 (2 photos)
tag 2 (3 photos)
tag 3 (one photo)
"""
When I select "tag 2" from "tags"
And I press "Submit"
Then I should see photo "photo 1"
Expand Down
12 changes: 6 additions & 6 deletions src/Controller/Admin/AdminAlbumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AdminAlbumController extends AbstractController
{
private TranslatorInterface $translator;

protected function setTabsheet(int $album_id, string $section = 'properties', int $parent_id = null): array
protected function setTabsheet(int $album_id, string $section = 'properties', int $parent_id = null): TabSheet
{
$tabsheet = new TabSheet();
$tabsheet->add('properties', $this->translator->trans('Properties', [], 'admin'), $this->generateUrl('admin_album', ['album_id' => $album_id, 'parent_id' => $parent_id]), 'fa-pencil');
Expand All @@ -50,7 +50,7 @@ protected function setTabsheet(int $album_id, string $section = 'properties', in
$tabsheet->add('notification', $this->translator->trans('Notification', [], 'admin'), $this->generateUrl('admin_album_notification', ['album_id' => $album_id, 'parent_id' => $parent_id]), 'fa-envelope');
$tabsheet->select($section);

return ['tabsheet' => $tabsheet];
return $tabsheet;
}

public function properties(
Expand Down Expand Up @@ -234,7 +234,7 @@ public function properties(
$tpl_params['CACHE_KEYS'] = Utils::getAdminClientCacheKeys($managerRegistry, ['categories'], $this->generateUrl('homepage'));
$tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums_options');
$tpl_params['PAGE_TITLE'] = $translator->trans('Album', [], 'admin');
$tpl_params = array_merge($this->setTabsheet($album_id, 'properties', $parent_id), $tpl_params);
$tpl_params['tabsheet'] = $this->setTabsheet($album_id, 'properties', $parent_id);

return $this->render('album_properties.html.twig', $tpl_params);
}
Expand Down Expand Up @@ -363,7 +363,7 @@ public function sort_order(
$tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums_options');
$tpl_params['PAGE_TITLE'] = $translator->trans('Album', [], 'admin');
$tpl_params['ALBUM_ID'] = $album_id;
$tpl_params = array_merge($this->setTabsheet($album_id, 'sort_order', $parent_id), $tpl_params);
$tpl_params['tabsheet'] = $this->setTabsheet($album_id, 'sort_order', $parent_id);

return $this->render('album_sort_order.html.twig', $tpl_params);
}
Expand Down Expand Up @@ -516,7 +516,7 @@ public function permissions(
$tpl_params['U_PAGE'] = $this->generateUrl('admin_albums');
$tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums_options');
$tpl_params['PAGE_TITLE'] = $translator->trans('Album', [], 'admin');
$tpl_params = array_merge($this->setTabsheet($album_id, 'permissions', $parent_id), $tpl_params);
$tpl_params['tabsheet'] = $this->setTabsheet($album_id, 'permissions', $parent_id);

return $this->render('album_permissions.html.twig', $tpl_params);
}
Expand Down Expand Up @@ -603,7 +603,7 @@ public function notification(
$tpl_params['U_PAGE'] = $this->generateUrl('admin_albums');
$tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums_options');
$tpl_params['PAGE_TITLE'] = $translator->trans('Album', [], 'admin');
$tpl_params = array_merge($this->setTabsheet($album_id, 'notification', $parent_id), $tpl_params);
$tpl_params['tabsheet'] = $this->setTabsheet($album_id, 'notification', $parent_id);

return $this->render('album_notification.html.twig', $tpl_params);
}
Expand Down
17 changes: 9 additions & 8 deletions src/Controller/Admin/AdminAlbumsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@
use Phyxo\TabSheet\TabSheet;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class AdminAlbumsController extends AbstractController
{
private $translator;
private TranslatorInterface $translator;

protected function setTabsheet(string $section = 'list'): array
protected function setTabsheet(string $section = 'list'): TabSheet
{
$tabsheet = new TabSheet();
$tabsheet->add('list', $this->translator->trans('List', [], 'admin'), $this->generateUrl('admin_albums'), 'fa-bars');
$tabsheet->add('move', $this->translator->trans('Move', [], 'admin'), $this->generateUrl('admin_albums_move'), 'fa-move');
$tabsheet->select($section);

return ['tabsheet' => $tabsheet];
return $tabsheet;
}

public function list(
Expand All @@ -43,7 +44,7 @@ public function list(
CsrfTokenManagerInterface $csrfTokenManager,
TranslatorInterface $translator,
ImageAlbumRepository $imageAlbumRepository
) {
): Response {
$tpl_params = [];
$this->translator = $translator;

Expand Down Expand Up @@ -133,12 +134,12 @@ public function list(
$tpl_params['U_PAGE'] = $this->generateUrl('admin_albums');
$tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums');
$tpl_params['PAGE_TITLE'] = $translator->trans('Albums', [], 'admin');
$tpl_params = array_merge($this->setTabsheet('list'), $tpl_params);
$tpl_params['tabsheet'] = $this->setTabsheet('list');

return $this->render('albums_list.html.twig', $tpl_params);
}

public function update(Request $request, int $parent_id = null, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator)
public function update(Request $request, int $parent_id = null, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator): Response
{
if ($request->isMethod('POST')) {
if ($request->request->get('submitManualOrder')) { // save manual category ordering
Expand Down Expand Up @@ -195,7 +196,7 @@ public function update(Request $request, int $parent_id = null, AlbumRepository
return $this->redirectToRoute('admin_albums', ['parent_id' => $parent_id]);
}

public function move(Request $request, int $parent_id = null, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator)
public function move(Request $request, int $parent_id = null, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator): Response
{
$tpl_params = [];
$this->translator = $translator;
Expand Down Expand Up @@ -226,7 +227,7 @@ public function move(Request $request, int $parent_id = null, AlbumRepository $a
$tpl_params['U_PAGE'] = $this->generateUrl('admin_albums_move');
$tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums');
$tpl_params['PAGE_TITLE'] = $translator->trans('Albums', [], 'admin');
$tpl_params = array_merge($this->setTabsheet('move'), $tpl_params);
$tpl_params['tabsheet'] = $this->setTabsheet('move');

return $this->render('albums_move.html.twig', $tpl_params);
}
Expand Down
12 changes: 7 additions & 5 deletions src/Controller/Admin/AdminAlbumsOptionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
use Phyxo\TabSheet\TabSheet;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;

class AdminAlbumsOptionsController extends AbstractController
{
private $translator;
private TranslatorInterface $translator;

protected function setTabsheet(Conf $conf, string $section = 'status'): array
protected function setTabsheet(Conf $conf, string $section = 'status'): TabSheet
{
$tabsheet = new TabSheet();
$tabsheet->add('status', $this->translator->trans('Public / Private', [], 'admin'), $this->generateUrl('admin_albums_options'), 'fa-lock');
Expand All @@ -37,10 +38,10 @@ protected function setTabsheet(Conf $conf, string $section = 'status'): array
}
$tabsheet->select($section);

return ['tabsheet' => $tabsheet];
return $tabsheet;
}

public function index(Request $request, string $section, Conf $conf, AlbumMapper $albumMapper, AlbumRepository $albumRepository, TranslatorInterface $translator)
public function index(Request $request, string $section, Conf $conf, AlbumMapper $albumMapper, AlbumRepository $albumRepository, TranslatorInterface $translator): Response
{
$tpl_params = [];
$this->translator = $translator;
Expand Down Expand Up @@ -83,11 +84,12 @@ public function index(Request $request, string $section, Conf $conf, AlbumMapper
$tpl_params['U_PAGE'] = $this->generateUrl('admin_albums_options', ['section' => $section]);
$tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums_options');
$tpl_params['PAGE_TITLE'] = $this->translator->trans('Public / Private', [], 'admin');
$tpl_params = array_merge($this->setTabsheet($conf, $section), $tpl_params);
$tpl_params['tabsheet'] = $this->setTabsheet($conf, $section);

return $this->render('albums_options.html.twig', $tpl_params);
}

/** @phpstan-ignore-next-line */ // @FIX: define return type
protected function getCatsBySection(string $section, AlbumRepository $albumRepository): array
{
$cats_true = [];
Expand Down
36 changes: 26 additions & 10 deletions src/Controller/Admin/AdminBatchManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,19 @@ public function __construct(AppUserService $appUserService)
$this->user = $appUserService->getUser();
}

protected function setTabsheet(string $section = 'global'): array
protected function setTabsheet(string $section = 'global'): TabSheet
{
$tabsheet = new TabSheet();
$tabsheet->add('global', $this->translator->trans('global mode', [], 'admin'), $this->generateUrl('admin_batch_manager_global'));
$tabsheet->add('unit', $this->translator->trans('unit mode', [], 'admin'), $this->generateUrl('admin_batch_manager_unit'));
$tabsheet->select($section);

return ['tabsheet' => $tabsheet];
return $tabsheet;
}

/**
* @param array<string, int|float|bool|string|null|array<int>> $filter
*/
protected function appendFilter(SessionInterface $session, array $filter = []): void
{
$previous_filter = $this->getFilter($session);
Expand All @@ -70,6 +73,9 @@ protected function appendFilter(SessionInterface $session, array $filter = []):
$session->set('bulk_manager_filter', array_merge($previous_filter, $filter));
}

/**
* @return array<string, int|float|bool|string|null|array<int>>
*/
protected function getFilter(SessionInterface $session): array
{
$filter = $session->has('bulk_manager_filter') ? $session->get('bulk_manager_filter'): [];
Expand Down Expand Up @@ -415,7 +421,7 @@ public function global(
$tpl_params['U_PAGE'] = $this->generateUrl('admin_batch_manager_global');
$tpl_params['F_ACTION'] = $this->generateUrl('admin_batch_manager_global');
$tpl_params['PAGE_TITLE'] = $translator->trans('Site manager', [], 'admin');
$tpl_params = array_merge($this->setTabsheet('global'), $tpl_params);
$tpl_params['tabsheet'] = $this->setTabsheet('global');

return $this->render('batch_manager_global.html.twig', $tpl_params);
}
Expand All @@ -428,6 +434,9 @@ public function emptyCaddie(Request $request, CaddieRepository $caddieRepository
return $this->redirectToRoute('admin_batch_manager_global', ['start' => $request->get('start')]);
}

/**
* @param int[] $collection
*/
protected function actionOnCollection(
Request $request,
TagMapper $tagMapper,
Expand All @@ -438,7 +447,7 @@ protected function actionOnCollection(
CaddieRepository $caddieRepository,
ImageTagRepository $imageTagRepository,
array $collection = []
) {
): ?Response {
// if the user tries to apply an action, it means that there is at least 1 photo in the selection
if (count($collection) === 0 && !$request->request->get('submitFilter')) {
$this->addFlash('error', $this->translator->trans('Select at least one photo', [], 'admin'));
Expand Down Expand Up @@ -596,6 +605,8 @@ protected function actionOnCollection(

if ($redirect) {
return $this->redirectToRoute('admin_batch_manager_global');
} else {
return null;
}
}

Expand All @@ -606,6 +617,9 @@ protected function filterFromSession(SessionInterface $session): void
}
}

/**
* @return array<string, int|float|bool|string|null|array<int>>
*/
protected function getFilterSetsFromFilter(
SearchMapper $searchMapper,
ImageMapper $imageMapper,
Expand All @@ -630,7 +644,7 @@ protected function getFilterSetsFromFilter(

case 'favorites':
$user_favorites = [];
foreach ($favoriteRepository->findUserFavorites($this->user->getId(), $this->user->getUserInfos()->getForbiddenCategories()) as $favorite) {
foreach ($favoriteRepository->findUserFavorites($this->user->getId(), $this->user->getUserInfos()->getForbiddenAlbums()) as $favorite) {
$user_favorites[] = $favorite->getImage()->geId();
}
$filter_sets[] = $user_favorites;
Expand Down Expand Up @@ -755,7 +769,7 @@ protected function getFilterSetsFromFilter(
if (!empty($bulk_manager_filter['tags'])) {
$image_ids = [];
foreach ($imageMapper->getRepository()->getImageIdsForTags(
$this->user->getUserInfos()->getForbiddenCategories(),
$this->user->getUserInfos()->getForbiddenAlbums(),
$bulk_manager_filter['tags'],
$bulk_manager_filter['tag_mode']
) as $image) {
Expand Down Expand Up @@ -823,16 +837,18 @@ protected function getFilterSetsFromFilter(
}

if (!empty($bulk_manager_filter['search']) && !empty($bulk_manager_filter['search']['q'])) {
/** @phpstan-ignore-next-line */
$result = $searchMapper->getQuickSearchResults($bulk_manager_filter['search']['q'], $this->user);
if (!empty($result['items']) && !empty($result['qs']['unmatched_terms'])) {
// $tpl_params ??? $template->assign('no_search_results', $result['qs']['unmatched_terms']);
}
// if (!empty($result['items']) && !empty($result['qs']['unmatched_terms'])) {
// // $tpl_params ??? $template->assign('no_search_results', $result['qs']['unmatched_terms']);
// }
$filter_sets[] = $result['items'];
}

return $filter_sets;
}

/** @phpstan-ignore-next-line */ // @FIX: define return type
protected function setDimensions(ImageMapper $imageMapper, SessionInterface $session): array
{
$tpl_params = [];
Expand Down Expand Up @@ -1169,7 +1185,7 @@ public function unit(
$tpl_params['CACHE_KEYS'] = Utils::getAdminClientCacheKeys($managerRegistry, ['tags', 'categories'], $this->generateUrl('homepage'));
$tpl_params['ws'] = $this->generateUrl('ws');

$tpl_params = array_merge($this->setTabsheet('unit'), $tpl_params);
$tpl_params['tabsheet'] = $this->setTabsheet('unit');

return $this->render('batch_manager_unit.html.twig', $tpl_params);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/Admin/AdminCommentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ class AdminCommentsController extends AbstractController
{
private TranslatorInterface $translator;

protected function setTabsheet(string $section = 'all'): array
protected function setTabsheet(string $section = 'all'): TabSheet
{
$tabsheet = new TabSheet();
$tabsheet->add('all', $this->translator->trans('All comments', [], 'admin'), $this->generateUrl('admin_comments'));
$tabsheet->add('pending', $this->translator->trans('Pending comments', [], 'admin'), $this->generateUrl('admin_comments', ['section' => 'pending']));
$tabsheet->select($section);

return ['tabsheet' => $tabsheet];
return $tabsheet;
}

public function index(
Expand Down Expand Up @@ -83,7 +83,7 @@ public function index(

$tpl_params['U_PAGE'] = $this->generateUrl('admin_comments', ['section' => $section, 'start' => $start]);
$tpl_params['PAGE_TITLE'] = $translator->trans('Comments', [], 'admin');
$tpl_params = array_merge($this->setTabsheet($section), $tpl_params);
$tpl_params['tabsheet'] = $this->setTabsheet($section);

$tpl_params['navbar'] = Utils::createNavigationBar(
$router,
Expand Down
Loading

0 comments on commit 320719e

Please sign in to comment.