Completed
Push — master ( c3ce72...f2565d )
by Paweł
20s
created

ArticleRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 40
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getByCriteria() 0 7 1
A getArticlesByCriteriaIds() 0 8 1
A applySorting() 0 9 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2017 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2017 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\Repository;
18
19
use Doctrine\ORM\QueryBuilder;
20
use SWP\Bundle\ContentBundle\Doctrine\ORM\ArticleRepository as ContentBundleArticleRepository;
21
use SWP\Component\Common\Criteria\Criteria;
22
23
/**
24
 * Class ArticleRepository.
25
 */
26
class ArticleRepository extends ContentBundleArticleRepository implements ArticleRepositoryInterface
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function getByCriteria(Criteria $criteria, array $sorting): QueryBuilder
32
    {
33
        $qb = parent::getByCriteria($criteria, $sorting);
34
        $qb->leftJoin('a.articleStatistics', 'stats')->addSelect('stats');
35
36
        return $qb;
37
    }
38
39
    /**
40
     * @param Criteria $criteria
41
     *
42
     * @return QueryBuilder
43
     */
44
    public function getArticlesByCriteriaIds(Criteria $criteria): QueryBuilder
45
    {
46
        $queryBuilder = parent::getArticlesByCriteriaIds($criteria)
47
            ->addSelect('stats')
48
            ->leftJoin('a.articleStatistics', 'stats');
49
50
        return $queryBuilder;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    protected function applySorting(QueryBuilder $queryBuilder, array $sorting, string $alias)
57
    {
58
        if (isset($sorting['pageViews']) && !empty($sorting['pageViews'])) {
59
            $queryBuilder->addOrderBy($this->getPropertyName('pageViewsNumber', 'stats'), $sorting['pageViews']);
60
            unset($sorting['pageViews']);
61
        }
62
63
        return parent::applySorting($queryBuilder, $sorting, $alias);
64
    }
65
}
66