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

ProductReviewRepository::findLatestByProductId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 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