|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* AnimeDb package. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Peter Gribanov <[email protected]> |
|
6
|
|
|
* @copyright Copyright (c) 2011, Peter Gribanov |
|
7
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace AnimeDb\Bundle\CatalogBundle\Repository; |
|
11
|
|
|
|
|
12
|
|
|
use Doctrine\ORM\EntityRepository; |
|
13
|
|
|
use AnimeDb\Bundle\CatalogBundle\Entity\Storage as StorageEntity; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @author Peter Gribanov <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class Storage extends EntityRepository |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @return int |
|
22
|
|
|
*/ |
|
23
|
|
|
public function count() |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->getEntityManager()->createQuery(' |
|
26
|
|
|
SELECT |
|
27
|
|
|
COUNT(s) |
|
28
|
|
|
FROM |
|
29
|
|
|
AnimeDbCatalogBundle:Storage s |
|
30
|
|
|
')->getSingleScalarResult(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param array $types |
|
35
|
|
|
* |
|
36
|
|
|
* @return StorageEntity[] |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getList(array $types = []) |
|
39
|
|
|
{ |
|
40
|
|
|
if (!$types || $types == StorageEntity::getTypes()) { |
|
|
|
|
|
|
41
|
|
|
return $this->getEntityManager()->createQuery(' |
|
42
|
|
|
SELECT |
|
43
|
|
|
s |
|
44
|
|
|
FROM |
|
45
|
|
|
AnimeDbCatalogBundle:Storage s |
|
46
|
|
|
ORDER BY |
|
47
|
|
|
s.id DESC |
|
48
|
|
|
')->getResult(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $this->getEntityManager()->createQuery(' |
|
52
|
|
|
SELECT |
|
53
|
|
|
s |
|
54
|
|
|
FROM |
|
55
|
|
|
AnimeDbCatalogBundle:Storage s |
|
56
|
|
|
WHERE |
|
57
|
|
|
s.type IN (:types) |
|
58
|
|
|
ORDER BY |
|
59
|
|
|
s.id DESC |
|
60
|
|
|
') |
|
61
|
|
|
->setParameter(':types', $types) |
|
62
|
|
|
->getResult(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param int|null $id |
|
67
|
|
|
* |
|
68
|
|
|
* @return \DateTime|null |
|
69
|
|
|
*/ |
|
70
|
|
View Code Duplication |
public function getLastUpdate($id = null) |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
|
|
if ($id) { |
|
|
|
|
|
|
73
|
|
|
$result = $this->getEntityManager()->createQuery(' |
|
74
|
|
|
SELECT |
|
75
|
|
|
s.date_update |
|
76
|
|
|
FROM |
|
77
|
|
|
AnimeDbCatalogBundle:Storage s |
|
78
|
|
|
WHERE |
|
79
|
|
|
s.id = :id' |
|
80
|
|
|
) |
|
81
|
|
|
->setParameter(':id', $id) |
|
82
|
|
|
->getOneOrNullResult(); |
|
83
|
|
|
} else { |
|
84
|
|
|
$result = $this->getEntityManager()->createQuery(' |
|
85
|
|
|
SELECT |
|
86
|
|
|
s.date_update |
|
87
|
|
|
FROM |
|
88
|
|
|
AnimeDbCatalogBundle:Storage s |
|
89
|
|
|
ORDER BY |
|
90
|
|
|
s.date_update DESC' |
|
91
|
|
|
) |
|
92
|
|
|
->setMaxResults(1) |
|
93
|
|
|
->getOneOrNullResult(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $result ? $result['date_update'] : null; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @return StorageEntity|null |
|
101
|
|
|
*/ |
|
102
|
|
|
public function getLast() |
|
103
|
|
|
{ |
|
104
|
|
|
return $this |
|
105
|
|
|
->createQueryBuilder('s') |
|
106
|
|
|
->addOrderBy('s.id', 'DESC') |
|
107
|
|
|
->setMaxResults(1) |
|
108
|
|
|
->getQuery() |
|
109
|
|
|
->getOneOrNullResult(); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.