Passed
Push — master ( 8c7b25...c84451 )
by Julito
10:55
created

LanguageRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 40
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findAllSubLanguages() 0 13 1
A getAllAvailable() 0 13 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Repository;
8
9
use Chamilo\CoreBundle\Entity\Language;
10
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
11
use Doctrine\Common\Collections\Collection;
12
use Doctrine\ORM\QueryBuilder;
13
use Doctrine\Persistence\ManagerRegistry;
14
15
class LanguageRepository extends ServiceEntityRepository
16
{
17
    public function __construct(ManagerRegistry $registry)
18
    {
19
        parent::__construct($registry, Language::class);
20
    }
21
22
    public function getAllAvailable(): QueryBuilder
23
    {
24
        $qb = $this->createQueryBuilder('l');
25
        $qb
26
            ->where(
27
                $qb->expr()->eq('l.available', true)
28
            )
29
            ->andWhere(
30
                $qb->expr()->isNull('l.parent')
31
            )
32
        ;
33
34
        return $qb;
35
    }
36
37
    /**
38
     * Get all the sub languages that are made available by the admin.
39
     *
40
     * @return Collection|Language[]
41
     */
42
    public function findAllSubLanguages()
43
    {
44
        $qb = $this->createQueryBuilder('l');
45
        $qb->select('l')
46
            ->where(
47
                $qb->expr()->eq('l.available', true)
48
            )
49
            ->andWhere(
50
                $qb->expr()->isNotNull('l.parent')
51
            )
52
        ;
53
54
        return $qb->getQuery()->getResult();
55
    }
56
}
57