Completed
Pull Request — development (#495)
by Mirco
08:08
created

PageController::indexAction()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
nc 2
nop 1
dl 0
loc 22
rs 9.2
c 1
b 0
f 0
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use AppBundle\Entity\PageGroup;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7
use Symfony\Component\HttpFoundation\Response;
8
9
class PageController extends AbstractController
10
{
11
    /**
12
     * Index action to show given page by slug.
13
     *
14
     * @param string $slug
15
     *
16
     * @return Response
0 ignored issues
show
introduced by
Response => \Symfony\Component\HttpFoundation\Response
Loading history...
17
     *
18
     * @Route("/page/{slug}/", name="page")
19
     */
20
    public function indexAction($slug)
21
    {
22
        $slug = strtolower($slug);
23
        $this->setMenu(MNU_START);
24
25
        $repository = $this->getDoctrine()->getRepository('AppBundle:PageGroup');
26
        $pageBlocksQueryBuilder = $repository->getPageBlocksBySlugQueryBuilder(
27
            $slug,
28
            'pageGroup.active = 1 AND pageBlocks.active = 1'
29
        );
30
31
        /** @var PageGroup $pageGroup */
0 ignored issues
show
introduced by
PageGroup => \AppBundle\Entity\PageGroup
Loading history...
32
        $pageGroup = $pageBlocksQueryBuilder->getQuery()->getOneOrNullResult();
33
34
        if (!$pageGroup || $pageGroup->getPageBlocks()->count() === 0) {
35
            throw $this->createNotFoundException('Page not found.');
36
        }
37
38
        return $this->render('@App/Pages/index.html.twig', [
39
            'pageGroup' => $pageGroup
40
        ]);
41
    }
42
43
}
44