GalleryController::viewAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\MediaBundle\Controller;
15
16
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
19
20
/**
21
 * @final since sonata-project/media-bundle 3.21.0
22
 */
23
class GalleryController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated with message: since Symfony 4.2, use "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
24
{
25
    /**
26
     * @return Response
27
     */
28
    public function indexAction()
29
    {
30
        $galleries = $this->get('sonata.media.manager.gallery')->findBy([
31
            'enabled' => true,
32
        ]);
33
34
        return $this->render('@SonataMedia/Gallery/index.html.twig', [
35
            'galleries' => $galleries,
36
        ]);
37
    }
38
39
    /**
40
     * @param string $id
41
     *
42
     * @throws NotFoundHttpException
43
     *
44
     * @return Response
45
     */
46
    public function viewAction($id)
47
    {
48
        $gallery = $this->get('sonata.media.manager.gallery')->findOneBy([
49
            'id' => $id,
50
            'enabled' => true,
51
        ]);
52
53
        if (!$gallery) {
54
            throw new NotFoundHttpException('unable to find the gallery with the id');
55
        }
56
57
        return $this->render('@SonataMedia/Gallery/view.html.twig', [
58
            'gallery' => $gallery,
59
        ]);
60
    }
61
}
62