1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Rafał Muszyński <[email protected]> |
5
|
|
|
* @copyright 2015 Sourcefabric z.ú. |
6
|
|
|
* @license http://www.gnu.org/licenses/gpl-3.0.txt |
7
|
|
|
*/ |
8
|
|
|
namespace Newscoop\PaywallBundle\Entity\Repository; |
9
|
|
|
|
10
|
|
|
use Doctrine\ORM\EntityRepository; |
11
|
|
|
use Newscoop\PaywallBundle\Entity\Currency; |
12
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
13
|
|
|
use Sylius\Component\Currency\Model\CurrencyInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Currency repository. |
17
|
|
|
*/ |
18
|
|
|
class CurrencyRepository extends EntityRepository implements RepositoryInterface |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Finds active currencies. |
22
|
|
|
*/ |
23
|
|
|
public function findActive() |
24
|
|
|
{ |
25
|
|
|
$qb = $this |
26
|
|
|
->createQueryBuilder('d') |
27
|
|
|
->where('d.isActive = true') |
28
|
|
|
; |
29
|
|
|
|
30
|
|
|
return $qb |
31
|
|
|
->getQuery() |
32
|
|
|
; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Finds the default currency. |
37
|
|
|
* |
38
|
|
|
* @return null|Currency |
39
|
|
|
*/ |
40
|
|
|
public function findDefaultOne() |
41
|
|
|
{ |
42
|
|
|
$qb = $this |
43
|
|
|
->createQueryBuilder('d') |
44
|
|
|
->where('d.isActive = true') |
45
|
|
|
->andWhere('d.default = true') |
46
|
|
|
; |
47
|
|
|
|
48
|
|
|
return $qb |
49
|
|
|
->getQuery()->getOneOrNullResult(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Find all available currencies. |
54
|
|
|
*/ |
55
|
|
|
public function findAllAvailable() |
56
|
|
|
{ |
57
|
|
|
$qb = $this |
58
|
|
|
->createQueryBuilder('d') |
59
|
|
|
; |
60
|
|
|
|
61
|
|
|
return $qb |
62
|
|
|
->getQuery() |
63
|
|
|
; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
public function createPaginator(array $criteria = null, array $orderBy = null) |
70
|
|
|
{ |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
public function createNew() |
77
|
|
|
{ |
78
|
|
|
return new Currency(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Checks if currency exists. |
83
|
|
|
* |
84
|
|
|
* @param CurrencyInterface $currency |
85
|
|
|
* |
86
|
|
|
* @return Doctrine\ORM\Query |
87
|
|
|
*/ |
88
|
|
|
public function checkIfExists(CurrencyInterface $currency) |
89
|
|
|
{ |
90
|
|
|
$qb = $this->createQueryBuilder('d') |
91
|
|
|
->select('count(d)') |
92
|
|
|
->where('d.code = :code') |
93
|
|
|
->andWhere('d.id <> :id') |
94
|
|
|
->setParameters(array( |
95
|
|
|
'code' => $currency->getCode(), |
96
|
|
|
'id' => $currency->getId(), |
97
|
|
|
)) |
98
|
|
|
; |
99
|
|
|
|
100
|
|
|
return $qb |
101
|
|
|
->getQuery(); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|