1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PH\Bundle\CoreBundle\Doctrine\ORM; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\QueryBuilder; |
8
|
|
|
use PH\Component\Core\Repository\PaymentMethodRepositoryInterface; |
9
|
|
|
use Sylius\Bundle\PaymentBundle\Doctrine\ORM\PaymentMethodRepository as BaseRepository; |
10
|
|
|
|
11
|
|
|
class PaymentMethodRepository extends BaseRepository implements PaymentMethodRepositoryInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* {@inheritdoc} |
15
|
|
|
*/ |
16
|
|
|
public function findBySupportsRecurring(bool $supportsRecurring): array |
17
|
|
|
{ |
18
|
|
|
return $this->createQueryBuilder('o') |
19
|
|
|
->leftJoin('o.translations', 't') |
20
|
|
|
->addSelect('t') |
21
|
|
|
->where('o.supportsRecurring = :supportsRecurring') |
22
|
|
|
->andWhere('o.enabled = :enabled') |
23
|
|
|
->setParameter('supportsRecurring', $supportsRecurring) |
24
|
|
|
->setParameter('enabled', true) |
25
|
|
|
->getQuery() |
26
|
|
|
->getResult() |
27
|
|
|
; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param QueryBuilder $queryBuilder |
32
|
|
|
* @param array $criteria |
33
|
|
|
*/ |
34
|
|
|
protected function applyCriteria(QueryBuilder $queryBuilder, array $criteria = []): void |
35
|
|
|
{ |
36
|
|
|
$criteria = array_filter($criteria, function ($value) { |
37
|
|
|
return !is_null($value); |
38
|
|
|
}); |
39
|
|
|
|
40
|
|
|
foreach ($criteria as $property => $value) { |
41
|
|
|
if (!in_array($property, array_merge($this->_class->getAssociationNames(), $this->_class->getFieldNames()), true)) { |
42
|
|
|
continue; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$name = $this->getPropertyName($property); |
46
|
|
|
|
47
|
|
|
if (is_array($value)) { |
48
|
|
|
$queryBuilder->andWhere($queryBuilder->expr()->in($name, $value)); |
49
|
|
|
} elseif ('1' === $value || '0' === $value) { |
50
|
|
|
$parameter = str_replace('.', '_', $property); |
51
|
|
|
$queryBuilder |
52
|
|
|
->andWhere($queryBuilder->expr()->eq($name, ':'.$parameter)) |
53
|
|
|
->setParameter($parameter, (int) $value) |
54
|
|
|
; |
55
|
|
|
} elseif ('' !== $value) { |
56
|
|
|
$parameter = str_replace('.', '_', $property); |
57
|
|
|
$queryBuilder |
58
|
|
|
->andWhere($queryBuilder->expr()->eq($name, ':'.$parameter)) |
59
|
|
|
->setParameter($parameter, $value) |
60
|
|
|
; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|