PonthubFileUserRepository::hasBeenDownloadedBy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
namespace KI\PonthubBundle\Repository;
3
4
use KI\CoreBundle\Repository\ResourceRepository;
5
use KI\PonthubBundle\Entity\PonthubFile;
6
use KI\PonthubBundle\Entity\Serie;
7
use KI\UserBundle\Entity\User;
8
9
class PonthubFileUserRepository extends ResourceRepository
10
{
11
    public function hasBeenDownloadedBy(PonthubFile $file, User $user)
12
    {
13
        return $this->createQueryBuilder('pfu')
14
            ->select('COUNT(pfu.id)')
15
            ->where('pfu.user = :user')
16
            ->andWhere('pfu.file = :file')
17
            ->setParameter('file', $file)
18
            ->setParameter('user', $user)
19
            ->getQuery()
20
            ->getSingleScalarResult() > 0;
21
    }
22
23
    public function getSerieDownloads(Serie $serie)
24
    {
25
//        return $this->createQueryBuilder('pfu')
26
//            ->select('COUNT(pfu.id)')
27
//            ->leftJoin('pfu.file', 'e')
28
//            ->where('e.serie = :serie')
29
//            ->setParameter('serie', $serie)
30
//            ->getQuery()
31
//            ->getSingleScalarResult();
32
33
        return $this->getEntityManager()->createQuery('SELECT COUNT(pfu.id) FROM
34
                    KIPonthubBundle:Episode episode,
35
                    KIPonthubBundle:PonthubFileUser pfu
36
                    WHERE pfu.file = episode
37
                    AND episode.serie = :serie
38
                    ')
39
            ->setParameter('serie', $serie)
40
            ->getSingleScalarResult();
41
    }
42
}
43