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 Doctrine\ORM\Query\Expr\Orx; |
16
|
|
|
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; |
17
|
|
|
use Sylius\Component\Currency\Model\CurrencyInterface; |
18
|
|
|
use Sylius\Component\Currency\Model\ExchangeRateInterface; |
19
|
|
|
use Sylius\Component\Currency\Repository\ExchangeRateRepositoryInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Jan Góralski <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class ExchangeRateRepository extends EntityRepository implements ExchangeRateRepositoryInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
* |
29
|
|
|
* @throws NonUniqueResultException |
30
|
|
|
*/ |
31
|
|
|
public function findOneWithCurrencyPair($firstCurrencyCode, $secondCurrencyCode) |
32
|
|
|
{ |
33
|
|
|
$expr = $this->getEntityManager()->getExpressionBuilder(); |
34
|
|
|
|
35
|
|
|
return $this->createQueryBuilder('o') |
36
|
|
|
->addSelect('sourceCurrency') |
37
|
|
|
->addSelect('targetCurrency') |
38
|
|
|
->innerJoin('o.sourceCurrency', 'sourceCurrency') |
39
|
|
|
->innerJoin('o.targetCurrency', 'targetCurrency') |
40
|
|
|
->andWhere($expr->orX( |
41
|
|
|
'sourceCurrency.code = :firstCurrency AND targetCurrency.code = :secondCurrency', |
42
|
|
|
'targetCurrency.code = :firstCurrency AND sourceCurrency.code = :secondCurrency' |
43
|
|
|
)) |
44
|
|
|
->setParameter('firstCurrency', $firstCurrencyCode) |
45
|
|
|
->setParameter('secondCurrency', $secondCurrencyCode) |
46
|
|
|
->getQuery() |
47
|
|
|
->getOneOrNullResult() |
48
|
|
|
; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|