1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Core\Utils\EntityUtils; |
4
|
|
|
|
5
|
|
|
use Core\DatabaseManager; |
6
|
|
|
use Doctrine\ORM\EntityRepository; |
7
|
|
|
|
8
|
|
|
class EntitySelect |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var EntityRepository |
12
|
|
|
*/ |
13
|
|
|
private $repository = null; |
14
|
|
|
|
15
|
|
|
private $entityName = null; |
16
|
|
|
private $criteria = null; |
17
|
|
|
private $orderBy = null; |
18
|
|
|
private $offsetStart = null; |
19
|
|
|
private $offsetLength = null; |
20
|
|
|
|
21
|
|
|
public static function select($entityName) |
22
|
|
|
{ |
23
|
|
|
return new self($entityName); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
private function __construct($entityName) |
27
|
|
|
{ |
28
|
|
|
$this->entityName = $entityName; |
29
|
|
|
$this->repository = DatabaseManager::getEntityManager()->getRepository($entityName); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function findById($id) |
33
|
|
|
{ |
34
|
|
|
return $this->repository->find($id); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function find() |
38
|
|
|
{ |
39
|
|
|
return $this->repository->findBy($this->criteria, $this->orderBy, $this->offsetLength, $this->offsetStart); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function findOne() |
43
|
|
|
{ |
44
|
|
|
return $this->repository->findOneBy($this->criteria, $this->orderBy); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function findAll() |
48
|
|
|
{ |
49
|
|
|
return $this->repository->findAll(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function criteria(array $criteria) |
53
|
|
|
{ |
54
|
|
|
$this->criteria = $criteria; |
55
|
|
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function orderBy(array $orderBy) |
59
|
|
|
{ |
60
|
|
|
$this->orderBy = $orderBy; |
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function offsetStart($offsetStart) |
65
|
|
|
{ |
66
|
|
|
$this->offsetStart = $offsetStart; |
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function offsetLength($offsetLength) |
71
|
|
|
{ |
72
|
|
|
$this->offsetLength = $offsetLength; |
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
} |