Completed
Pull Request — development (#546)
by Nick
06:25
created

PageController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B indexAction() 0 32 3
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
 */
14
class PageController extends AbstractController
15
{
16
    /**
17
     * Index action to show given page by slug.
18
     *
19
     * @param string $slug
20
     *
21
     * @return Response
0 ignored issues
show
introduced by
Response => \Symfony\Component\HttpFoundation\Response
Loading history...
22
     *
23
     * @Route("/page/{slug}/", name="page")
24
     */
25
    public function indexAction($slug)
26
    {
27
        $slug = strtolower($slug);
28
        $this->setMenu(MNU_START);
29
30
        $pageService = $this->get('oc.page.page_service');
31
        $blockService = $this->get('oc.page.block_service');
32
33
        $page = $pageService->fetchOneBy([
34
            'slug' => $slug,
35
            'active' => 1
36
        ]);
37
38
        if (!$page) {
39
            throw $this->createNotFoundException();
40
        }
41
42
        $pageBlocks = $blockService->fetchBy([
43
            'page_id' => $page->id,
44
            'locale' => $this->getGlobalContext()->getLocale(),
45
            'active' => 1
46
        ]);
47
48
        if (count($pageBlocks) === 0) {
49
            return $this->render('@App/Page/fallback.html.twig');
50
        }
51
52
        return $this->render('@App/Page/index.html.twig', [
53
            'page' => $page,
54
            'pageBlocks' => $pageBlocks
55
        ]);
56
    }
57
58
59
0 ignored issues
show
introduced by
2 empty lines and more are not allowed
Loading history...
60
}
61