Passed
Push — master ( 76abd2...ab5d59 )
by Julito
10:01
created

LegalRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Repository;
5
6
use Doctrine\ORM\EntityRepository;
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8
use Doctrine\Common\Persistence\ManagerRegistry;
9
10
/**
11
 * Class LegalRepository.
12
 *
13
 * @package Chamilo\CoreBundle\Repository
14
 */
15
class LegalRepository extends EntityRepository
16
{
17
    public function __construct(ManagerRegistry $registry)
18
    {
19
        parent::__construct($registry, Language::class);
20
    }
21
22
    /**
23
     * Count the legal terms by language (only count one set of terms for each
24
     * language).
25
     *
26
     * @throws \Exception
27
     *
28
     * @return int
29
     */
30
    public function countAllActiveLegalTerms()
31
    {
32
        $qb = $this->createQueryBuilder('l');
33
        $qb->select('l.languageId, COUNT(l.id)')
34
            ->groupBy('l.languageId');
35
36
        return count($qb->getQuery()->getResult());
37
    }
38
39
    /**
40
     * Get the latest version of terms of the given type and language.
41
     *
42
     * @param int $typeId     The type of terms:
43
     *                        0 for general text,
44
     *                        1 for general HTML link,
45
     *                        101 for private data collection,
46
     *                        etc - see personal_data.php
47
     * @param int $languageId The Id of the language
48
     *
49
     * @return array The terms for those type and language
50
     */
51
    public function findOneByTypeAndLanguage($typeId, $languageId)
52
    {
53
        $qb = $this->createQueryBuilder('l');
54
        $qb->select('l.content')
55
            ->where($qb->expr()->eq('l.type', $typeId))
56
            ->andWhere($qb->expr()->eq('l.languageId', $languageId));
57
58
        return $qb->getQuery()->getResult();
59
    }
60
}
61