Completed
Push — master ( 19732d...076741 )
by Paweł
11:47
created

getCountForArticleInternalPageViews()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Analytics Bundle.
7
 *
8
 * Copyright 2018 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 2018 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\AnalyticsBundle\Repository;
18
19
use SWP\Bundle\AnalyticsBundle\Model\ArticleEventInterface;
20
use SWP\Bundle\ContentBundle\Model\ArticleInterface;
21
use SWP\Bundle\StorageBundle\Doctrine\ORM\EntityRepository;
22
23
class ArticleEventRepository extends EntityRepository implements ArticleEventRepositoryInterface
24
{
25
    public function getCountForArticleInternalPageViews(ArticleInterface $article): int
26
    {
27
        $qb = $this->createQueryBuilder('ae')
28
            ->select('COUNT(ae.id)')
29
            ->andWhere('ae.action = :action')
30
            ->andWhere('ae.pageViewSource = :pageviewSource')
31
            ->leftJoin('ae.articleStatistics', 'ast')
32
            ->andWhere('ast.article = :article')
33
            ->setParameters([
34
                'article' => $article,
35
                'action' => ArticleEventInterface::ACTION_PAGEVIEW,
36
                'pageviewSource' => ArticleEventInterface::PAGEVIEW_SOURCE_INTERNAL,
37
            ]);
38
39
        return (int) $qb->getQuery()->getSingleScalarResult();
40
    }
41
}
42