1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.ec-cube.co.jp/ |
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 Eccube\Controller; |
15
|
|
|
|
16
|
|
|
use Eccube\Repository\NewsRepository; |
17
|
|
|
use Eccube\Repository\ProductRepository; |
18
|
|
|
use Symfony\Component\HttpFoundation\Response; |
19
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
20
|
|
|
|
21
|
|
|
class RssFeedController extends AbstractController |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var ProductRepository |
25
|
|
|
*/ |
26
|
|
|
protected $productRepository; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var NewsRepository |
30
|
|
|
*/ |
31
|
|
|
protected $newsRepository; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* RssFeedController constructor. |
35
|
|
|
* |
36
|
|
|
* @param ProductRepository $productRepository |
37
|
|
|
* @param NewsRepository $newsRepository |
38
|
|
|
*/ |
39
|
|
|
public function __construct(ProductRepository $productRepository, NewsRepository $newsRepository) |
40
|
|
|
{ |
41
|
|
|
$this->productRepository = $productRepository; |
42
|
|
|
$this->newsRepository = $newsRepository; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @Route("/products_feed.xml", name="rss_feed_for_products") |
47
|
|
|
*/ |
48
|
|
|
public function products() |
49
|
|
|
{ |
50
|
|
|
$products = $this->productRepository->findBy( |
51
|
|
|
['Status' => 1], |
52
|
|
|
[ |
53
|
|
|
'create_date' => 'DESC', |
54
|
|
|
'id' => 'DESC', |
55
|
|
|
], |
56
|
|
|
20 |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$response = new Response(); |
60
|
|
|
$response->headers->set('Content-Type', 'application/xml; charset=UTF-8'); |
61
|
|
|
|
62
|
|
|
return $this->render( |
63
|
|
|
'Feed/products.xml.twig', |
64
|
|
|
['products' => $products], |
65
|
|
|
$response |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @Route("/news_feed.xml", name="rss_feed_for_news") |
71
|
|
|
*/ |
72
|
|
|
public function news() |
73
|
|
|
{ |
74
|
|
|
$builder = $this->newsRepository->createQueryBuilder('news'); |
75
|
|
|
$news = $builder |
76
|
|
|
->where('news.visible = :visible') |
77
|
|
|
->andWhere($builder->expr()->lte('news.publish_date', ':now')) |
78
|
|
|
->setParameters([ |
79
|
|
|
'visible' => true, |
80
|
|
|
'now' => new \DateTime(), |
81
|
|
|
]) |
82
|
|
|
->orderBy('news.publish_date', 'DESC') |
83
|
|
|
->addOrderBy('news.id', 'DESC') |
84
|
|
|
->setMaxResults(20) |
85
|
|
|
->getQuery() |
86
|
|
|
->getResult(); |
87
|
|
|
|
88
|
|
|
$response = new Response(); |
89
|
|
|
$response->headers->set('Content-Type', 'application/xml; charset=UTF-8'); |
90
|
|
|
|
91
|
|
|
return $this->render( |
92
|
|
|
'Feed/news.xml.twig', |
93
|
|
|
['news' => $news], |
94
|
|
|
$response |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|