-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathWishlistRepository.php
More file actions
160 lines (142 loc) · 4.78 KB
/
Copy pathWishlistRepository.php
File metadata and controls
160 lines (142 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusWishlistPlugin\Repository;
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Channel\Model\ChannelInterface;
use Sylius\Component\Core\Model\ShopUserInterface;
class WishlistRepository extends EntityRepository implements WishlistRepositoryInterface
{
public function findOneByShopUser(ShopUserInterface $shopUser): ?WishlistInterface
{
return $this->createQueryBuilder('o')
->where('o.shopUser = :shopUser')
->setParameter('shopUser', $shopUser)
->getQuery()
->setMaxResults(1)
->getOneOrNullResult()
;
}
public function findByToken(string $token): ?WishlistInterface
{
return $this->createQueryBuilder('o')
->where('o.token = :token')
->setParameter('token', $token)
->getQuery()
->setMaxResults(1)
->getOneOrNullResult()
;
}
public function findAllByToken(string $token): array
{
return $this->createQueryBuilder('o')
->where('o.token = :token')
->setParameter('token', $token)
->getQuery()
->getResult()
;
}
public function findAllByShopUser(int $shopUser): array
{
return $this->createQueryBuilder('o')
->where('o.shopUser = :shopUser')
->setParameter('shopUser', $shopUser)
->getQuery()
->getResult()
;
}
public function findAllByShopUserAndToken(int $shopUser, string $token): array
{
$qb = $this->createQueryBuilder('o');
return $qb->where('o.shopUser = :shopUser')
->orWhere($qb->expr()->andX(
'o.token = :token',
'o.shopUser IS NULL',
))
->setParameter('token', $token)
->setParameter('shopUser', $shopUser)
->getQuery()
->getResult()
;
}
public function findAllByAnonymous(?string $token): array
{
return $this->createQueryBuilder('o')
->where('o.token = :token')
->andWhere('o.shopUser IS NULL')
->setParameter('token', $token)
->getQuery()
->getResult()
;
}
public function findOneByShopUserAndChannel(
ShopUserInterface $shopUser,
ChannelInterface $channel,
): ?WishlistInterface {
return $this->createQueryBuilder('o')
->where('o.shopUser = :shopUser')
->andWhere('o.channel = :channel')
->setParameter('shopUser', $shopUser)
->setParameter('channel', $channel)
->setMaxResults(1)
->getQuery()
->setMaxResults(1)
->getOneOrNullResult()
;
}
public function findAllByAnonymousAndChannel(?string $token, ChannelInterface $channel): array
{
$qb = $this->createQueryBuilder('o')
->andWhere('o.channel = :channel')
->andWhere('o.shopUser IS NULL')
->setParameter('channel', $channel)
;
if (null !== $token) {
$qb
->andWhere('o.token = :token')
->setParameter('token', $token);
}
return $qb->getQuery()->getResult();
}
public function findOneByTokenAndName(string $token, string $name): ?WishlistInterface
{
return $this->createQueryBuilder('o')
->where('o.token = :token')
->andWhere('o.name =:name')
->setParameter('token', $token)
->setParameter('name', $name)
->getQuery()
->setMaxResults(1)
->getOneOrNullResult()
;
}
public function findOneByShopUserAndName(ShopUserInterface $shopUser, string $name): ?WishlistInterface
{
return $this->createQueryBuilder('o')
->where('o.shopUser = :shopUser')
->andWhere('o.name =:name')
->setParameter('shopUser', $shopUser)
->setParameter('name', $name)
->getQuery()
->setMaxResults(1)
->getOneOrNullResult()
;
}
public function deleteAllAnonymousUntil(\DateTime $until): int
{
return $this->createQueryBuilder('o')
->delete(WishlistInterface::class, 'o')
->where('o.shopUser IS NULL')
->andWhere('o.updatedAt < :until')
->setParameter('until', $until)
->getQuery()
->execute()
;
}
}