]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - application/front/controller/visitor/PictureWallController.php
Handle pagination through BookmarkService
[github/shaarli/Shaarli.git] / application / front / controller / visitor / PictureWallController.php
CommitLineData
485b168a
A
1<?php
2
3declare(strict_types=1);
4
2899ebb5 5namespace Shaarli\Front\Controller\Visitor;
485b168a
A
6
7use Shaarli\Front\Exception\ThumbnailsDisabledException;
1a8ac737 8use Shaarli\Render\TemplatePage;
485b168a
A
9use Shaarli\Thumbnailer;
10use Slim\Http\Request;
11use Slim\Http\Response;
12
13/**
14 * Class PicturesWallController
15 *
16 * Slim controller used to render the pictures wall page.
17 * If thumbnails mode is set to NONE, we just render the template without any image.
485b168a 18 */
2899ebb5 19class PictureWallController extends ShaarliVisitorController
485b168a
A
20{
21 public function index(Request $request, Response $response): Response
22 {
23 if ($this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) === Thumbnailer::MODE_NONE) {
24 throw new ThumbnailsDisabledException();
25 }
26
27 $this->assignView(
28 'pagetitle',
53054b2b 29 t('Picture wall') . ' - ' . $this->container->conf->get('general.title', 'Shaarli')
485b168a
A
30 );
31
32 // Optionally filter the results:
9b8c0a45
A
33 $bookmarks = $this->container->bookmarkService->search($request->getQueryParams())->getBookmarks();
34 $links = [];
485b168a
A
35
36 // Get only bookmarks which have a thumbnail.
37 // Note: we do not retrieve thumbnails here, the request is too heavy.
38 $formatter = $this->container->formatterFactory->getFormatter('raw');
9b8c0a45
A
39 foreach ($bookmarks as $key => $bookmark) {
40 if (!empty($bookmark->getThumbnail())) {
41 $links[] = $formatter->format($bookmark);
485b168a
A
42 }
43 }
44
9b8c0a45 45 $data = ['linksToDisplay' => $links];
9fbc4229
A
46 $this->executePageHooks('render_picwall', $data, TemplatePage::PICTURE_WALL);
47
485b168a
A
48 foreach ($data as $key => $value) {
49 $this->assignView($key, $value);
50 }
51
1a8ac737 52 return $response->write($this->render(TemplatePage::PICTURE_WALL));
485b168a 53 }
485b168a 54}