|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Oc\Page\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Oc\AbstractController; |
|
6
|
|
|
use AppBundle\Entity\PageGroup; |
|
7
|
|
|
use Oc\Page\BlockService; |
|
8
|
|
|
use Oc\Page\PageService; |
|
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class PageController |
|
14
|
|
|
* |
|
15
|
|
|
* @package Oc\Page\Controller |
|
16
|
|
|
*/ |
|
17
|
|
|
class PageController extends AbstractController |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var PageService |
|
21
|
|
|
*/ |
|
22
|
|
|
private $pageService; |
|
23
|
|
|
/** |
|
24
|
|
|
* @var BlockService |
|
25
|
|
|
*/ |
|
26
|
|
|
private $blockService; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* PageController constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param PageService $pageService |
|
32
|
|
|
* @param BlockService $blockService |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(PageService $pageService, BlockService $blockService) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->pageService = $pageService; |
|
37
|
|
|
$this->blockService = $blockService; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Index action to show given page by slug. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $slug |
|
44
|
|
|
* |
|
45
|
|
|
* @return Response |
|
46
|
|
|
* |
|
47
|
|
|
* @Route("/page/{slug}/", name="page") |
|
48
|
|
|
*/ |
|
49
|
|
|
public function indexAction($slug) |
|
50
|
|
|
{ |
|
51
|
|
|
$slug = strtolower($slug); |
|
52
|
|
|
$this->setMenu(MNU_START); |
|
53
|
|
|
|
|
54
|
|
|
$page = $this->pageService->fetchOneBy([ |
|
55
|
|
|
'slug' => $slug, |
|
56
|
|
|
'active' => 1 |
|
57
|
|
|
]); |
|
58
|
|
|
|
|
59
|
|
|
if (!$page) { |
|
60
|
|
|
throw $this->createNotFoundException(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$pageBlocks = $this->blockService->fetchBy([ |
|
64
|
|
|
'page_id' => $page->id, |
|
65
|
|
|
'locale' => $this->getGlobalContext()->getLocale(), |
|
66
|
|
|
'active' => 1 |
|
67
|
|
|
]); |
|
68
|
|
|
|
|
69
|
|
|
if (count($pageBlocks) === 0) { |
|
70
|
|
|
return $this->render('page/fallback.html.twig'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $this->render('page/index.html.twig', [ |
|
74
|
|
|
'page' => $page, |
|
75
|
|
|
'pageBlocks' => $pageBlocks |
|
76
|
|
|
]); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|