1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\NewsBundle\Action; |
13
|
|
|
|
14
|
|
|
use Sonata\NewsBundle\Model\BlogInterface; |
15
|
|
|
use Sonata\NewsBundle\Model\PostManagerInterface; |
16
|
|
|
use Sonata\SeoBundle\Seo\SeoPageInterface; |
17
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
20
|
|
|
use Symfony\Component\Translation\TranslatorInterface; |
21
|
|
|
|
22
|
|
|
abstract class AbstractPostArchiveAction extends Controller |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var BlogInterface |
26
|
|
|
*/ |
27
|
|
|
private $blog; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var PostManagerInterface |
31
|
|
|
*/ |
32
|
|
|
private $postManager; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var TranslatorInterface |
36
|
|
|
*/ |
37
|
|
|
private $translator; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var SeoPageInterface|null |
41
|
|
|
*/ |
42
|
|
|
private $seoPage; |
43
|
|
|
|
44
|
|
|
public function __construct(BlogInterface $blog, PostManagerInterface $postManager, TranslatorInterface $translator) |
45
|
|
|
{ |
46
|
|
|
$this->blog = $blog; |
47
|
|
|
$this->postManager = $postManager; |
48
|
|
|
$this->translator = $translator; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @internal |
53
|
|
|
* |
54
|
|
|
* NEXT_MAJOR: make this method protected |
55
|
|
|
* |
56
|
|
|
* @return Response |
57
|
|
|
*/ |
58
|
|
|
final public function renderArchive(Request $request, array $criteria = [], array $parameters = []) |
59
|
|
|
{ |
60
|
|
|
$pager = $this->postManager->getPager( |
61
|
|
|
$criteria, |
62
|
|
|
$request->get('page', 1) |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$parameters = array_merge([ |
66
|
|
|
'pager' => $pager, |
67
|
|
|
'blog' => $this->blog, |
68
|
|
|
'tag' => false, |
69
|
|
|
'collection' => false, |
70
|
|
|
'route' => $request->get('_route'), |
71
|
|
|
'route_parameters' => $request->get('_route_params'), |
72
|
|
|
], $parameters); |
73
|
|
|
|
74
|
|
|
$response = $this->render( |
75
|
|
|
sprintf('@SonataNews/Post/archive.%s.twig', $request->getRequestFormat()), |
76
|
|
|
$parameters |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
if ('rss' === $request->getRequestFormat()) { |
80
|
|
|
$response->headers->set('Content-Type', 'application/rss+xml'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $response; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param null|SeoPageInterface $seoPage |
88
|
|
|
*/ |
89
|
|
|
public function setSeoPage(SeoPageInterface $seoPage = null) |
90
|
|
|
{ |
91
|
|
|
$this->seoPage = $seoPage; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $id |
96
|
|
|
* @param string|null $domain |
97
|
|
|
* @param string|null $locale |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
final protected function trans($id, array $parameters = [], $domain = 'SonataNewsBundle', $locale = null) |
102
|
|
|
{ |
103
|
|
|
return $this->translator->trans($id, $parameters, $domain, $locale); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return BlogInterface |
108
|
|
|
*/ |
109
|
|
|
final protected function getBlog() |
110
|
|
|
{ |
111
|
|
|
return $this->blog; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return null|SeoPageInterface |
116
|
|
|
*/ |
117
|
|
|
final protected function getSeoPage() |
118
|
|
|
{ |
119
|
|
|
return $this->seoPage; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return PostManagerInterface |
124
|
|
|
*/ |
125
|
|
|
final protected function getPostManager() |
126
|
|
|
{ |
127
|
|
|
return $this->postManager; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|