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