|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of EC-CUBE |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
|
7
|
|
|
* |
|
8
|
|
|
* http://www.lockon.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\Repository; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\DBAL\Exception\DriverException; |
|
17
|
|
|
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; |
|
18
|
|
|
use Eccube\Entity\News; |
|
19
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* NewsRepository |
|
23
|
|
|
* |
|
24
|
|
|
* This class was generated by the Doctrine ORM. Add your own custom |
|
25
|
|
|
* repository methods below. |
|
26
|
|
|
*/ |
|
27
|
|
|
class NewsRepository extends AbstractRepository |
|
28
|
|
|
{ |
|
29
|
|
|
public function __construct(RegistryInterface $registry) |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct($registry, News::class); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* 新着情報を登録します. |
|
36
|
|
|
* |
|
37
|
|
|
* @param $News |
|
38
|
|
|
*/ |
|
39
|
|
|
public function save($News) |
|
40
|
|
|
{ |
|
41
|
|
|
$em = $this->getEntityManager(); |
|
42
|
|
|
$em->persist($News); |
|
43
|
|
|
$em->flush($News); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* 新着情報を削除します. |
|
48
|
|
|
* |
|
49
|
|
|
* @param News $News |
|
50
|
|
|
* |
|
51
|
|
|
* @throws ForeignKeyConstraintViolationException 外部キー制約違反の場合 |
|
52
|
|
|
* @throws DriverException SQLiteの場合, 外部キー制約違反が発生すると, DriverExceptionをthrowします. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function delete($News) |
|
55
|
|
|
{ |
|
56
|
|
|
$em = $this->getEntityManager(); |
|
57
|
|
|
$em->remove($News); |
|
58
|
|
|
$em->flush($News); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return \Doctrine\ORM\QueryBuilder |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getQueryBuilderAll() |
|
65
|
|
|
{ |
|
66
|
|
|
$qb = $this->createQueryBuilder('n'); |
|
67
|
|
|
$qb->orderBy('n.publish_date', 'DESC') |
|
68
|
|
|
->addOrderBy('n.id', 'DESC'); |
|
69
|
|
|
|
|
70
|
|
|
return $qb; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return mixed |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getList() |
|
77
|
|
|
{ |
|
78
|
|
|
$qb = $this->createQueryBuilder('n'); |
|
79
|
|
|
$qb->where('n.publish_date <= :date') |
|
80
|
|
|
->andWhere('n.visible = TRUE') |
|
81
|
|
|
->setParameter('date', new \DateTime()) |
|
82
|
|
|
->orderBy('n.publish_date', 'DESC') |
|
83
|
|
|
->addOrderBy('n.id', 'DESC'); |
|
84
|
|
|
|
|
85
|
|
|
return $qb->getQuery()->getResult(); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|