|
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 Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
19
|
|
|
|
|
20
|
|
|
abstract class AbstractPostArchiveAction extends Controller |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var BlogInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
private $blog; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var PostManagerInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
private $postManager; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct(BlogInterface $blog, PostManagerInterface $postManager) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->blog = $blog; |
|
35
|
|
|
$this->postManager = $postManager; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @internal |
|
40
|
|
|
* |
|
41
|
|
|
* NEXT_MAJOR: make this method protected |
|
42
|
|
|
* |
|
43
|
|
|
* @return Response |
|
44
|
|
|
*/ |
|
45
|
|
|
final public function renderArchive(Request $request, array $criteria = [], array $parameters = []) |
|
46
|
|
|
{ |
|
47
|
|
|
$pager = $this->postManager->getPager( |
|
48
|
|
|
$criteria, |
|
49
|
|
|
$request->get('page', 1) |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
$parameters = array_merge([ |
|
53
|
|
|
'pager' => $pager, |
|
54
|
|
|
'blog' => $this->blog, |
|
55
|
|
|
'tag' => false, |
|
56
|
|
|
'collection' => false, |
|
57
|
|
|
'route' => $request->get('_route'), |
|
58
|
|
|
'route_parameters' => $request->get('_route_params'), |
|
59
|
|
|
], $parameters); |
|
60
|
|
|
|
|
61
|
|
|
$response = $this->render( |
|
62
|
|
|
sprintf('@SonataNews/Post/archive.%s.twig', $request->getRequestFormat()), |
|
63
|
|
|
$parameters |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
if ('rss' === $request->getRequestFormat()) { |
|
67
|
|
|
$response->headers->set('Content-Type', 'application/rss+xml'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $response; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return PostManagerInterface |
|
75
|
|
|
*/ |
|
76
|
|
|
final protected function getPostManager() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->postManager; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|