|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\ApiBundle\Filters; |
|
15
|
|
|
|
|
16
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter; |
|
17
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface; |
|
18
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
19
|
|
|
use Webmozart\Assert\Assert; |
|
20
|
|
|
|
|
21
|
|
|
final class ExchangeRateFilter extends AbstractContextAwareFilter |
|
22
|
|
|
{ |
|
23
|
|
|
protected function filterProperty( |
|
24
|
|
|
string $property, |
|
25
|
|
|
$value, |
|
26
|
|
|
QueryBuilder $queryBuilder, |
|
27
|
|
|
QueryNameGeneratorInterface $queryNameGenerator, |
|
28
|
|
|
string $resourceClass, |
|
29
|
|
|
string $operationName = null |
|
30
|
|
|
) { |
|
31
|
|
|
if ($property === 'currencyCode') { |
|
32
|
|
|
$queryBuilder |
|
33
|
|
|
->innerJoin('o.sourceCurrency', 'sourceCurrency') |
|
34
|
|
|
->innerJoin('o.targetCurrency', 'targetCurrency') |
|
35
|
|
|
->where('sourceCurrency.code LIKE CONCAT(\'%\', :code, \'%\')') |
|
36
|
|
|
->orWhere('targetCurrency.code LIKE CONCAT(\'%\', :code, \'%\')') |
|
37
|
|
|
->setParameter('code', $value) |
|
38
|
|
|
; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getDescription(string $resourceClass): array |
|
43
|
|
|
{ |
|
44
|
|
|
$description = []; |
|
45
|
|
|
|
|
46
|
|
|
$description['currencyCode'] = [ |
|
47
|
|
|
'type' => 'string', |
|
48
|
|
|
'required' => false, |
|
49
|
|
|
'property' => 'currencyCode', |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
return $description; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|