Completed
Push — master ( 6d05bc...71ecc8 )
by Kamil
25:05
created

ProductReviewRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findLatestByProductId() 0 13 1
A findAcceptedByProductSlugAndChannel() 0 18 1
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
namespace Sylius\Bundle\CoreBundle\Doctrine\ORM;
13
14
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
15
use Sylius\Component\Core\Model\ChannelInterface;
16
use Sylius\Component\Core\Repository\ProductReviewRepositoryInterface;
17
use Sylius\Component\Review\Model\ReviewInterface;
18
19
/**
20
 * @author Mateusz Zalewski <[email protected]>
21
 */
22
class ProductReviewRepository extends EntityRepository implements ProductReviewRepositoryInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function findLatestByProductId($productId)
28
    {
29
        return $this->createQueryBuilder('o')
30
            ->where('o.reviewSubject = :productId')
31
            ->andWhere('o.status = :status')
32
            ->setParameter('productId', $productId)
33
            ->setParameter('status', ReviewInterface::STATUS_ACCEPTED)
34
            ->orderBy('o.createdAt', 'desc')
35
            ->setMaxResults(3)
36
            ->getQuery()
37
            ->getResult()
38
        ;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function findAcceptedByProductSlugAndChannel($slug, $locale, ChannelInterface $channel)
45
    {
46
        return $this->createQueryBuilder('o')
47
            ->innerJoin('o.reviewSubject', 'product')
48
            ->leftJoin('product.translations', 'translation')
49
            ->leftJoin('product.channels', 'channel')
50
            ->where('translation.locale = :locale')
51
            ->andWhere('translation.slug = :slug')
52
            ->andWhere('channel = :channel')
53
            ->andWhere('o.status = :status')
54
            ->setParameter('locale', $locale)
55
            ->setParameter('slug', $slug)
56
            ->setParameter('channel', $channel)
57
            ->setParameter('status', ReviewInterface::STATUS_ACCEPTED)
58
            ->getQuery()
59
            ->getResult()
60
        ;
61
    }
62
}
63