1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
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 Sylius\Bundle\CurrencyBundle\Doctrine\ORM; |
13
|
|
|
|
14
|
|
|
use Doctrine\ORM\NonUniqueResultException; |
15
|
|
|
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; |
16
|
|
|
use Sylius\Component\Currency\Model\CurrencyInterface; |
17
|
|
|
use Sylius\Component\Currency\Model\ExchangeRateInterface; |
18
|
|
|
use Sylius\Component\Currency\Repository\ExchangeRateRepositoryInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Jan Góralski <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class ExchangeRateRepository extends EntityRepository implements ExchangeRateRepositoryInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param CurrencyInterface $firstCurrency |
27
|
|
|
* @param CurrencyInterface $secondCurrency |
28
|
|
|
* |
29
|
|
|
* @return ExchangeRateInterface|null |
30
|
|
|
* |
31
|
|
|
* @throws NonUniqueResultException |
32
|
|
|
*/ |
33
|
|
|
public function findOneWithCurrencyPair(CurrencyInterface $firstCurrency, CurrencyInterface $secondCurrency) |
34
|
|
|
{ |
35
|
|
|
$queryBuilder = $this->createQueryBuilder('o'); |
36
|
|
|
|
37
|
|
|
return $queryBuilder |
38
|
|
|
->where( |
39
|
|
|
$queryBuilder->expr()->andX( |
40
|
|
|
$queryBuilder->expr()->eq('o.sourceCurrency', ':firstCurrency'), |
41
|
|
|
$queryBuilder->expr()->eq('o.targetCurrency', ':secondCurrency') |
42
|
|
|
)) |
43
|
|
|
->orWhere( |
44
|
|
|
$queryBuilder->expr()->andX( |
45
|
|
|
$queryBuilder->expr()->eq('o.sourceCurrency', ':secondCurrency'), |
46
|
|
|
$queryBuilder->expr()->eq('o.targetCurrency', ':firstCurrency') |
47
|
|
|
)) |
48
|
|
|
->setParameter('firstCurrency', $firstCurrency) |
49
|
|
|
->setParameter('secondCurrency', $secondCurrency) |
50
|
|
|
->getQuery() |
51
|
|
|
->getOneOrNullResult() |
52
|
|
|
; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|