1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the AsmTranslationLoaderBundle package. |
4
|
|
|
* |
5
|
|
|
* (c) Marc Aschmann <[email protected]> |
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 Asm\TranslationLoaderBundle\Entity; |
12
|
|
|
|
13
|
|
|
use Doctrine\ORM\EntityRepository; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Translation repository class for the Doctrine ORM storage layer implementation. |
17
|
|
|
* |
18
|
|
|
* @package Asm\TranslationLoaderBundle\Entity |
19
|
|
|
* @author Marc Aschmann <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class TranslationRepository extends EntityRepository |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Check for translations younger than timestamp. |
26
|
|
|
* |
27
|
|
|
* @param integer $timestamp |
28
|
|
|
* @return integer |
29
|
|
|
*/ |
30
|
|
|
public function findTranslationFreshness($timestamp) |
31
|
|
|
{ |
32
|
|
|
return $this |
33
|
|
|
->createQueryBuilder('t') |
34
|
|
|
->select('count(t.transKey)') |
35
|
|
|
->where('t.dateUpdated > :timestamp') |
36
|
|
|
->setParameter('timestamp', $timestamp, \PDO::PARAM_INT) |
37
|
|
|
->getQuery() |
38
|
|
|
->getSingleScalarResult(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get a filtered list of translations. |
43
|
|
|
* |
44
|
|
|
* @param array $criteria |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public function getTranslationList(array $criteria) |
48
|
|
|
{ |
49
|
|
|
$queryBuilder = $this |
50
|
|
|
->createQueryBuilder('t') |
51
|
|
|
->select('t'); |
52
|
|
|
|
53
|
|
|
// filter |
54
|
|
|
if (true === isset($criteria['filter']) && '' != $criteria['filter']) { |
55
|
|
|
if (false === isset($criteria['value']) || '' != $criteria['value']) { |
56
|
|
|
$queryBuilder->where( |
57
|
|
|
$queryBuilder->expr()->like( |
58
|
|
|
't.' . $criteria['filter'], |
59
|
|
|
$queryBuilder->expr()->literal($criteria['value'].'%') |
60
|
|
|
) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
// order |
66
|
|
|
if (true === isset($criteria['order']) && '' != $criteria['order']) { |
67
|
|
|
if (false === isset($criteria['type']) || '' != $criteria['type']) { |
68
|
|
|
$criteria['type'] = 'ASC'; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$queryBuilder->addOrderBy('t.' . $criteria['order'], $criteria['type']); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $queryBuilder |
75
|
|
|
->getQuery() |
76
|
|
|
->getResult(); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|