Completed
Pull Request — development (#546)
by Nick
07:54 queued 01:05
created

PageController::indexAction()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 32
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 19
nc 3
nop 1
dl 0
loc 32
rs 8.8571
c 0
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
/**
10
 * Class PageController
11
 *
12
 * @package AppBundle\Controller
0 ignored issues
show
introduced by
Unexpected tag type @package in doc block
Loading history...
13
 * @author Nick Lubisch <[email protected]>
14
 */
15
class PageController extends AbstractController
16
{
17
    /**
18
     * Index action to show given page by slug.
19
     *
20
     * @param string $slug
21
     *
22
     * @return Response
0 ignored issues
show
introduced by
Response => \Symfony\Component\HttpFoundation\Response
Loading history...
23
     *
24
     * @Route("/page/{slug}/", name="page")
25
     */
26
    public function indexAction($slug)
27
    {
28
        $slug = strtolower($slug);
29
        $this->setMenu(MNU_START);
30
31
        $pageService = $this->get('oc.page.page_service');
32
        $blockService = $this->get('oc.page.block_service');
33
34
        $page = $pageService->fetchOneBy([
35
            'slug' => $slug,
36
            'active' => 1
37
        ]);
38
39
        if (!$page) {
40
            throw $this->createNotFoundException();
41
        }
42
43
        $pageBlocks = $blockService->fetchBy([
44
            'page_id' => $page->id,
45
            'locale' => $this->getGlobalContext()->getLocale(),
46
            'active' => 1
47
        ]);
48
49
        if (count($pageBlocks) === 0) {
50
            return $this->render('@App/Page/fallback.html.twig');
51
        }
52
53
        return $this->render('@App/Page/index.html.twig', [
54
            'page' => $page,
55
            'pageBlocks' => $pageBlocks
56
        ]);
57
    }
58
59
60
0 ignored issues
show
introduced by
2 empty lines and more are not allowed
Loading history...
61
}
62