|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Asylamba\Modules\Promethee\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use Asylamba\Classes\Entity\AbstractRepository; |
|
6
|
|
|
|
|
7
|
|
|
use Asylamba\Modules\Promethee\Model\TechnologyQueue; |
|
8
|
|
|
|
|
9
|
|
|
class TechnologyQueueRepository extends AbstractRepository |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @param int $id |
|
13
|
|
|
* @return TechnologyQueue $technologyQueue |
|
14
|
|
|
*/ |
|
15
|
|
|
public function get($id) |
|
16
|
|
|
{ |
|
17
|
|
|
if (($tq = $this->unitOfWork->getObject(TechnologyQueue::class, $id)) !== null) { |
|
18
|
|
|
return $tq; |
|
19
|
|
|
} |
|
20
|
|
|
$statement = $this->connection->prepare('SELECT * FROM technologyQueue WHERE id = :id'); |
|
21
|
|
|
$statement->execute(['id' => $id]); |
|
22
|
|
|
if (($row = $statement->fetch()) === false) { |
|
23
|
|
|
return null; |
|
24
|
|
|
} |
|
25
|
|
|
$technologyQueue = $this->format($row); |
|
26
|
|
|
$this->unitOfWork->addObject($technologyQueue); |
|
27
|
|
|
return $technologyQueue; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param int $playerId |
|
32
|
|
|
* @param int $technology |
|
33
|
|
|
* @return TechnologyQueue $technologyQueue |
|
34
|
|
|
*/ |
|
35
|
|
|
public function getPlayerTechnologyQueue($playerId, $technology) |
|
36
|
|
|
{ |
|
37
|
|
|
$statement = $this->connection->prepare('SELECT * FROM technologyQueue WHERE rPlayer = :player_id AND technology = :technology'); |
|
38
|
|
|
$statement->execute(['player_id' => $playerId, 'technology' => $technology]); |
|
39
|
|
|
if (($row = $statement->fetch()) === false) { |
|
40
|
|
|
return null; |
|
41
|
|
|
} |
|
42
|
|
|
if (($tq = $this->unitOfWork->getObject(TechnologyQueue::class, (int) $row['id'])) !== null) { |
|
43
|
|
|
return $tq; |
|
44
|
|
|
} |
|
45
|
|
|
$technologyQueue = $this->format($row); |
|
46
|
|
|
$this->unitOfWork->addObject($technologyQueue); |
|
47
|
|
|
return $technologyQueue; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getAll() |
|
54
|
|
|
{ |
|
55
|
|
|
$statement = $this->connection->query('SELECT * FROM technologyQueue'); |
|
56
|
|
|
|
|
57
|
|
|
$data = []; |
|
58
|
|
|
while ($row = $statement->fetch()) { |
|
59
|
|
|
if (($tq = $this->unitOfWork->getObject(TechnologyQueue::class, (int) $row['id'])) !== null) { |
|
60
|
|
|
$data[] = $tq; |
|
61
|
|
|
continue; |
|
62
|
|
|
} |
|
63
|
|
|
$technologyQueue = $this->format($row); |
|
64
|
|
|
$this->unitOfWork->addObject($technologyQueue); |
|
65
|
|
|
$data[] = $technologyQueue; |
|
66
|
|
|
} |
|
67
|
|
|
return $data; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param int $placeId |
|
72
|
|
|
* @return array |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getPlaceQueues($placeId) |
|
75
|
|
|
{ |
|
76
|
|
|
$statement = $this->connection->prepare('SELECT * FROM technologyQueue WHERE rPlace = :place_id ORDER BY dEnd'); |
|
77
|
|
|
$statement->execute(['place_id' => $placeId]); |
|
78
|
|
|
|
|
79
|
|
|
$data = []; |
|
80
|
|
|
while ($row = $statement->fetch()) { |
|
81
|
|
|
if (($tq = $this->unitOfWork->getObject(TechnologyQueue::class, (int) $row['id'])) !== null) { |
|
82
|
|
|
$data[] = $tq; |
|
83
|
|
|
continue; |
|
84
|
|
|
} |
|
85
|
|
|
$technologyQueue = $this->format($row); |
|
86
|
|
|
$this->unitOfWork->addObject($technologyQueue); |
|
87
|
|
|
$data[] = $technologyQueue; |
|
88
|
|
|
} |
|
89
|
|
|
return $data; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param int $playerId |
|
94
|
|
|
* @return array |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getPlayerQueues($playerId) |
|
97
|
|
|
{ |
|
98
|
|
|
$statement = $this->connection->prepare('SELECT * FROM technologyQueue WHERE rPlayer = :player_id'); |
|
99
|
|
|
$statement->execute(['player_id' => $playerId]); |
|
100
|
|
|
|
|
101
|
|
|
$data = []; |
|
102
|
|
|
while ($row = $statement->fetch()) { |
|
103
|
|
|
if (($tq = $this->unitOfWork->getObject(TechnologyQueue::class, (int) $row['id'])) !== null) { |
|
104
|
|
|
$data[] = $tq; |
|
105
|
|
|
continue; |
|
106
|
|
|
} |
|
107
|
|
|
$technologyQueue = $this->format($row); |
|
108
|
|
|
$this->unitOfWork->addObject($technologyQueue); |
|
109
|
|
|
$data[] = $technologyQueue; |
|
110
|
|
|
} |
|
111
|
|
|
return $data; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param TechnologyQueue $technologyQueue |
|
116
|
|
|
*/ |
|
117
|
|
|
public function insert($technologyQueue) |
|
118
|
|
|
{ |
|
119
|
|
|
$qr = $this->connection->prepare('INSERT INTO |
|
120
|
|
|
technologyQueue(rPlayer, rPlace, technology, targetLevel, dStart, dEnd) |
|
121
|
|
|
VALUES(?, ?, ?, ?, ?, ?)'); |
|
122
|
|
|
$qr->execute(array( |
|
123
|
|
|
$technologyQueue->getPlayerId(), |
|
124
|
|
|
$technologyQueue->getPlaceId(), |
|
125
|
|
|
$technologyQueue->getTechnology(), |
|
126
|
|
|
$technologyQueue->getTargetLevel(), |
|
127
|
|
|
$technologyQueue->getCreatedAt(), |
|
128
|
|
|
$technologyQueue->getEndedAt() |
|
129
|
|
|
)); |
|
130
|
|
|
$technologyQueue->setId($this->connection->lastInsertId()); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function update($technologyQueue) |
|
134
|
|
|
{ |
|
135
|
|
|
$statement = $this->connection->prepare( |
|
136
|
|
|
'UPDATE technologyQueue SET |
|
137
|
|
|
targetlevel = ?, |
|
138
|
|
|
dStart = ?, |
|
139
|
|
|
dEnd = ? |
|
140
|
|
|
WHERE id = ?'); |
|
141
|
|
|
$statement->execute(array( |
|
142
|
|
|
$technologyQueue->getTargetLevel(), |
|
143
|
|
|
$technologyQueue->getCreatedAt(), |
|
144
|
|
|
$technologyQueue->getEndedAt(), |
|
145
|
|
|
$technologyQueue->getId() |
|
146
|
|
|
)); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @param TechnologyQueue $technologyQueue |
|
151
|
|
|
*/ |
|
152
|
|
|
public function remove($technologyQueue) |
|
153
|
|
|
{ |
|
154
|
|
|
$statement = $this->connection->prepare('DELETE FROM technologyQueue WHERE id = :id'); |
|
155
|
|
|
$statement->execute(['id' => $technologyQueue->getId()]); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @param array $data |
|
160
|
|
|
* @return TechnologyQueue |
|
161
|
|
|
*/ |
|
162
|
|
|
public function format($data) |
|
163
|
|
|
{ |
|
164
|
|
|
return |
|
165
|
|
|
(new TechnologyQueue()) |
|
166
|
|
|
->setId((int) $data['id']) |
|
167
|
|
|
->setPlayerId((int) $data['rPlayer']) |
|
168
|
|
|
->setTechnology((int) $data['technology']) |
|
169
|
|
|
->setTargetLevel((int) $data['targetLevel']) |
|
170
|
|
|
->setCreatedAt($data['dStart']) |
|
171
|
|
|
->setEndedAt($data['dEnd']) |
|
172
|
|
|
; |
|
173
|
|
|
} |
|
174
|
|
|
} |