1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Gerard van Helden <[email protected]> |
4
|
|
|
* @copyright Zicht Online <http://zicht.nl> |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Zicht\Bundle\PageBundle\Controller; |
8
|
|
|
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
11
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
12
|
|
|
use Zicht\Bundle\PageBundle\Model\PageInterface; |
13
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
14
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
15
|
|
|
use Zicht\Bundle\PageBundle\Entity\ControllerPageInterface; |
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
17
|
|
|
use Zicht\Bundle\PageBundle\Model\ViewValidationInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Controller for public page actions |
21
|
|
|
*/ |
22
|
|
|
class PageController extends AbstractController |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Redirects to the page identified by the passed id. |
26
|
|
|
* |
27
|
|
|
* @param string $id |
28
|
|
|
* @return Response |
29
|
|
|
* |
30
|
|
|
* @Route("page/{id}/redirect", name="page_redirect") |
31
|
|
|
*/ |
32
|
|
|
public function redirectAction($id) |
33
|
|
|
{ |
34
|
|
|
return new RedirectResponse($this->generateUrl('zicht_page_page_view', array('id' => $id))); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Redirects to the specified page. This is useful for posting an autocomplete ID, which in turn redirects to |
40
|
|
|
* the specified page. |
41
|
|
|
* |
42
|
|
|
* @param Request $r |
43
|
|
|
* @return Response |
44
|
|
|
* |
45
|
|
|
* @Route("/goto") |
46
|
|
|
*/ |
47
|
|
|
public function gotoAction(Request $r) |
48
|
|
|
{ |
49
|
|
|
return $this->redirect( |
50
|
|
|
$this->get('zicht_url.provider')->url($this->getPageManager()->findForView($r->get('id'))) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* View a page. |
57
|
|
|
* |
58
|
|
|
* @param Request $request |
59
|
|
|
* @param string $id |
60
|
|
|
* @return Response |
61
|
|
|
* |
62
|
|
|
* @Route("page/{id}") |
63
|
|
|
*/ |
64
|
3 |
|
public function viewAction(Request $request, $id) |
65
|
|
|
{ |
66
|
|
|
/** @var $pageManager \Zicht\Bundle\PageBundle\Manager\PageManager */ |
67
|
3 |
|
$pageManager = $this->getPageManager(); |
68
|
3 |
|
$page = $pageManager->findForView($id); |
69
|
|
|
|
70
|
3 |
|
if (null !== ($validator = $this->getViewActionValidator())) { |
71
|
3 |
|
$validator->validate($page); |
72
|
2 |
|
} |
73
|
|
|
|
74
|
2 |
|
if ($page instanceof ControllerPageInterface) { |
75
|
1 |
|
return $this->forward( |
76
|
1 |
|
$page->getController(), |
77
|
1 |
|
(array)$page->getControllerParameters() |
78
|
|
|
+ array( |
79
|
1 |
|
'parameters' => $request->query->all(), |
80
|
1 |
|
'_locale' => $request->attributes->get('_locale'), |
81
|
1 |
|
'_internal_url' => $request->attributes->get('_internal_url'), |
82
|
1 |
|
), |
83
|
1 |
|
$request->query->all() |
84
|
1 |
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
return $this->renderPage($page); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return null|ViewValidationInterface |
92
|
|
|
*/ |
93
|
3 |
|
protected function getViewActionValidator() |
94
|
|
|
{ |
95
|
3 |
|
if (($validator = $this->get('zicht_page.controller.view_validator')) instanceof ViewValidationInterface) { |
96
|
3 |
|
return $validator; |
97
|
|
|
} |
98
|
|
|
return null; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Render a page with the specified additional template variables. |
103
|
|
|
* |
104
|
|
|
* @param PageInterface $page |
105
|
|
|
* @param array $vars |
106
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
107
|
|
|
*/ |
108
|
1 |
|
public function renderPage(PageInterface $page, $vars = array()) |
109
|
|
|
{ |
110
|
1 |
|
return $this->render( |
111
|
1 |
|
$this->getPageManager()->getTemplate($page), |
112
|
|
|
$vars + array( |
113
|
1 |
|
'page' => $page, |
114
|
1 |
|
'id' => $page->getId(), |
115
|
|
|
) |
116
|
1 |
|
); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|