|
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
|
|
|
|