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\CoreBundle\Doctrine\ORM; |
15
|
|
|
|
16
|
|
|
use Doctrine\ORM\QueryBuilder; |
17
|
|
|
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; |
18
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
19
|
|
|
use Sylius\Component\Core\Repository\ProductReviewRepositoryInterface; |
20
|
|
|
use Sylius\Component\Review\Model\ReviewInterface; |
21
|
|
|
|
22
|
|
|
class ProductReviewRepository extends EntityRepository implements ProductReviewRepositoryInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function findLatestByProductId($productId, int $count): array |
28
|
|
|
{ |
29
|
|
|
return $this->createQueryBuilder('o') |
30
|
|
|
->andWhere('o.reviewSubject = :productId') |
31
|
|
|
->andWhere('o.status = :status') |
32
|
|
|
->setParameter('productId', $productId) |
33
|
|
|
->setParameter('status', ReviewInterface::STATUS_ACCEPTED) |
34
|
|
|
->addOrderBy('o.createdAt', 'DESC') |
35
|
|
|
->setMaxResults($count) |
36
|
|
|
->getQuery() |
37
|
|
|
->getResult() |
38
|
|
|
; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function findAcceptedByProductSlugAndChannel(string $slug, string $locale, ChannelInterface $channel): array |
45
|
|
|
{ |
46
|
|
|
return $this->createQueryBuilder('o') |
47
|
|
|
->innerJoin('o.reviewSubject', 'product') |
48
|
|
|
->innerJoin('product.translations', 'translation') |
49
|
|
|
->andWhere('translation.locale = :locale') |
50
|
|
|
->andWhere('translation.slug = :slug') |
51
|
|
|
->andWhere(':channel MEMBER OF product.channels') |
52
|
|
|
->andWhere('o.status = :status') |
53
|
|
|
->setParameter('locale', $locale) |
54
|
|
|
->setParameter('slug', $slug) |
55
|
|
|
->setParameter('channel', $channel) |
56
|
|
|
->setParameter('status', ReviewInterface::STATUS_ACCEPTED) |
57
|
|
|
->getQuery() |
58
|
|
|
->getResult() |
59
|
|
|
; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function createQueryBuilderByProductCode(string $locale, string $productCode): QueryBuilder |
66
|
|
|
{ |
67
|
|
|
return $this->createQueryBuilder('o') |
68
|
|
|
->innerJoin('o.reviewSubject', 'product') |
69
|
|
|
->innerJoin('product.translations', 'translation') |
70
|
|
|
->andWhere('translation.locale = :locale') |
71
|
|
|
->andWhere('product.code = :productCode') |
72
|
|
|
->setParameter('locale', $locale) |
73
|
|
|
->setParameter('productCode', $productCode) |
74
|
|
|
; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
|
|
public function findOneByIdAndProductCode($id, string $productCode): ?ReviewInterface |
81
|
|
|
{ |
82
|
|
|
return $this->createQueryBuilder('o') |
83
|
|
|
->innerJoin('o.reviewSubject', 'product') |
84
|
|
|
->andWhere('product.code = :productCode') |
85
|
|
|
->andWhere('o.id = :id') |
86
|
|
|
->setParameter('productCode', $productCode) |
87
|
|
|
->setParameter('id', $id) |
88
|
|
|
->getQuery() |
89
|
|
|
->getOneOrNullResult() |
90
|
|
|
; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|