Failed Conditions
Branch issue#666 (91903a)
by Guilherme
08:25
created

CountryRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findPreferred() 0 6 1
A isPreferred() 0 6 1
A findByString() 0 12 1
A findOneByString() 0 12 1
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\CoreBundle\Entity;
12
13
use Doctrine\ORM\EntityRepository;
14
use Doctrine\ORM\AbstractQuery;
15
16
class CountryRepository extends EntityRepository
17
{
18
19
    public function findByString($string)
20
    {
21
        $qb = $this->getEntityManager()->createQueryBuilder();
22
23
        return $qb
24
                ->select('c')
25
                ->from('LoginCidadaoCoreBundle:Country', 'c')
26
                ->where('c.name LIKE :string OR LOWER(c.name) LIKE :string')
27
                ->addOrderBy('c.preference', 'DESC')
28
                ->addOrderBy('c.name', 'ASC')
29
                ->setParameter('string', "$string%")
30
                ->getQuery()->getResult();
31
    }
32
33
    public function findOneByString($string)
34
    {
35
        $qb = $this->getEntityManager()->createQueryBuilder();
36
37
        return $qb
38
                ->select('c')
39
                ->from('LoginCidadaoCoreBundle:Country', 'c')
40
                ->orWhere('c.name = :string')
41
                ->orWhere('c.iso2 = :string')
42
                ->orWhere('c.iso3 = :string')
43
                ->setParameter('string', $string)
44
                ->getQuery()->getOneOrNullResult();
45
    }
46
47
    public function findPreferred()
48
    {
49
        return $this->createQueryBuilder('c')
50
                ->where('c.preference > 0')
51
                ->addOrderBy('c.preference', 'DESC')
52
                ->getQuery()->getResult();
53
    }
54
    
55
    public function isPreferred($var)
56
    {
57
        return $this->createQueryBuilder('c')
58
                ->select('count(c) total')
59
                ->where('c.preference > 0 and c = :country')->setParameter('country', $var)          
60
                ->getQuery()->getResult(AbstractQuery::HYDRATE_SINGLE_SCALAR);
61
        
62
    }
63
64
}
65