1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainAltapayBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* This repository is implemented using the principles described here: |
9
|
|
|
* https://www.tomasvotruba.cz/blog/2017/10/16/how-to-use-repository-with-doctrine-as-service-in-symfony/ |
10
|
|
|
*/ |
11
|
|
|
class SiteSettingRepository extends EntityRepository |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param int $siteId |
15
|
|
|
* @param string $setting |
16
|
|
|
* @return SiteSetting|null |
17
|
|
|
*/ |
18
|
|
|
public function findBySiteIdAndSetting(int $siteId, string $setting) : ?SiteSetting |
19
|
|
|
{ |
20
|
|
|
/** @var SiteSetting $obj */ |
21
|
|
|
$obj = $this->repository->findOneBy([ |
22
|
|
|
'siteId' => $siteId, |
23
|
|
|
'setting' => $setting |
24
|
|
|
]); |
25
|
|
|
|
26
|
|
|
return $obj; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param int $siteId |
31
|
|
|
* @param array|null $orderBy |
32
|
|
|
* @param int|null $limit |
33
|
|
|
* @param int|null $offset |
34
|
|
|
* @return SiteSetting[]|null |
35
|
|
|
*/ |
36
|
|
|
public function findBySiteId(int $siteId, array $orderBy = null, int $limit = null, int $offset = null) : ?array |
37
|
|
|
{ |
38
|
|
|
/** @var SiteSetting[] $objs */ |
39
|
|
|
$objs = $this->repository->findBy([ |
40
|
|
|
'siteId' => $siteId, |
41
|
|
|
], $orderBy, $limit, $offset); |
42
|
|
|
|
43
|
|
|
return $objs; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Usage: |
48
|
|
|
* $collection = SiteSettingRepository::findBySiteIdIndexedBySetting($siteId) |
49
|
|
|
* echo $collection['setting']->getVal(); |
50
|
|
|
* |
51
|
|
|
* @param int $siteId |
52
|
|
|
* @return SiteSetting[]|null |
53
|
|
|
*/ |
54
|
|
|
public function findBySiteIdIndexedBySetting(int $siteId) : ?array |
55
|
|
|
{ |
56
|
|
|
$qb = $this->repository->createQueryBuilder('s'); |
57
|
|
|
$qb |
58
|
|
|
->where($qb->expr()->eq('s.siteId', $siteId)) |
59
|
|
|
->indexBy('s', 's.setting') |
60
|
|
|
; |
61
|
|
|
|
62
|
|
|
return $qb->getQuery()->getResult(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $setting |
67
|
|
|
* @param array|null $orderBy |
68
|
|
|
* @param int|null $limit |
69
|
|
|
* @param int|null $offset |
70
|
|
|
* @return SiteSetting[]|null |
71
|
|
|
*/ |
72
|
|
|
public function findBySetting(string $setting, array $orderBy = null, int $limit = null, int $offset = null) : ?array |
73
|
|
|
{ |
74
|
|
|
/** @var SiteSetting[] $objs */ |
75
|
|
|
$objs = $this->repository->findBy([ |
76
|
|
|
'setting' => $setting, |
77
|
|
|
], $orderBy, $limit, $offset); |
78
|
|
|
|
79
|
|
|
return $objs; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|