1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backend\Modules\Location\Domain\Location; |
4
|
|
|
|
5
|
|
|
use Backend\Modules\Location\Domain\LocationSetting\LocationSetting; |
6
|
|
|
use Common\Exception\CanNotSetExtraIdException; |
7
|
|
|
use Common\Locale; |
8
|
|
|
use Backend\Core\Language\Locale as BackendLocale; |
9
|
|
|
use DateTime; |
10
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
11
|
|
|
use Doctrine\Common\Collections\Collection; |
12
|
|
|
use Doctrine\ORM\Mapping as ORM; |
13
|
|
|
use Frontend\Core\Language\Locale as FrontendLocale; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @ORM\Table(name="location") |
17
|
|
|
* @ORM\Entity(repositoryClass="Backend\Modules\Location\Domain\Location\LocationRepository") |
18
|
|
|
* @ORM\HasLifecycleCallbacks |
19
|
|
|
*/ |
20
|
|
|
class Location |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var int |
24
|
|
|
* |
25
|
|
|
* @ORM\Id |
26
|
|
|
* @ORM\GeneratedValue |
27
|
|
|
* @ORM\Column(type="integer") |
28
|
|
|
*/ |
29
|
|
|
private $id; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Locale |
33
|
|
|
* |
34
|
|
|
* @ORM\Column(type="locale") |
35
|
|
|
*/ |
36
|
|
|
private $locale; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @TODO: map this to some sort of Extra entity |
40
|
|
|
* @var integer |
41
|
|
|
* |
42
|
|
|
* @ORM\Column(type="integer") |
43
|
|
|
*/ |
44
|
|
|
private $extraId; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
* |
49
|
|
|
* @ORM\Column(type="string") |
50
|
|
|
*/ |
51
|
|
|
private $title; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var string |
55
|
|
|
* |
56
|
|
|
* @ORM\Column(type="string") |
57
|
|
|
*/ |
58
|
|
|
private $street; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var string |
62
|
|
|
* |
63
|
|
|
* @ORM\Column(type="string") |
64
|
|
|
*/ |
65
|
|
|
private $number; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string |
69
|
|
|
* |
70
|
|
|
* @ORM\Column(type="string") |
71
|
|
|
*/ |
72
|
|
|
private $zip; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var string |
76
|
|
|
* |
77
|
|
|
* @ORM\Column(type="string") |
78
|
|
|
*/ |
79
|
|
|
private $city; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var string |
83
|
|
|
* |
84
|
|
|
* @ORM\Column(type="string") |
85
|
|
|
*/ |
86
|
|
|
private $country; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @var float |
90
|
|
|
* |
91
|
|
|
* @ORM\Column(type="float") |
92
|
|
|
*/ |
93
|
|
|
private $latitude; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var float |
97
|
|
|
* |
98
|
|
|
* @ORM\Column(type="float") |
99
|
|
|
*/ |
100
|
|
|
private $longitude; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @var bool |
104
|
|
|
* |
105
|
|
|
* @ORM\Column(type="boolean", options={"default" = true}) |
106
|
|
|
*/ |
107
|
|
|
private $showInOverview; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @var Collection |
111
|
|
|
* |
112
|
|
|
* @ORM\OneToMany( |
113
|
|
|
* targetEntity="Backend\Modules\Location\Domain\LocationSetting\LocationSetting", |
114
|
|
|
* mappedBy="location", |
115
|
|
|
* cascade={"persist"}, |
116
|
|
|
* orphanRemoval=true |
117
|
|
|
* ) |
118
|
|
|
*/ |
119
|
|
|
private $settings; |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @var DateTime |
123
|
|
|
* |
124
|
|
|
* @ORM\Column(type="datetime") |
125
|
|
|
*/ |
126
|
|
|
private $createdOn; |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @var DateTime |
130
|
|
|
* |
131
|
|
|
* @ORM\Column(type="datetime") |
132
|
|
|
*/ |
133
|
|
|
private $editedOn; |
134
|
|
|
|
135
|
2 |
|
public function __construct( |
136
|
|
|
Locale $locale, |
137
|
|
|
string $title, |
138
|
|
|
string $street, |
139
|
|
|
string $number, |
140
|
|
|
string $zip, |
141
|
|
|
string $city, |
142
|
|
|
string $country, |
143
|
|
|
float $latitude, |
144
|
|
|
float $longitude, |
145
|
|
|
bool $showInOverview = true, |
146
|
|
|
int $extraId = null |
147
|
|
|
) { |
148
|
2 |
|
$this->locale = $locale; |
149
|
2 |
|
$this->title = $title; |
150
|
2 |
|
$this->street = $street; |
151
|
2 |
|
$this->number = $number; |
152
|
2 |
|
$this->zip = $zip; |
153
|
2 |
|
$this->city = $city; |
154
|
2 |
|
$this->country = $country; |
155
|
2 |
|
$this->latitude = $latitude; |
156
|
2 |
|
$this->longitude = $longitude; |
157
|
2 |
|
$this->showInOverview = $showInOverview; |
158
|
2 |
|
$this->extraId = $extraId; |
159
|
|
|
|
160
|
2 |
|
$this->settings = new ArrayCollection(); |
161
|
2 |
|
} |
162
|
|
|
|
163
|
1 |
|
public function update( |
164
|
|
|
string $title, |
165
|
|
|
string $street, |
166
|
|
|
string $number, |
167
|
|
|
string $zip, |
168
|
|
|
string $city, |
169
|
|
|
string $country, |
170
|
|
|
float $latitude, |
171
|
|
|
float $longitude, |
172
|
|
|
bool $showInOverview = true |
173
|
|
|
) { |
174
|
1 |
|
$this->title = $title; |
175
|
1 |
|
$this->street = $street; |
176
|
1 |
|
$this->number = $number; |
177
|
1 |
|
$this->zip = $zip; |
178
|
1 |
|
$this->city = $city; |
179
|
1 |
|
$this->country = $country; |
180
|
1 |
|
$this->latitude = $latitude; |
181
|
1 |
|
$this->longitude = $longitude; |
182
|
1 |
|
$this->showInOverview = $showInOverview; |
183
|
1 |
|
} |
184
|
|
|
|
185
|
2 |
|
public function getId(): int |
186
|
|
|
{ |
187
|
2 |
|
return $this->id; |
188
|
|
|
} |
189
|
|
|
|
190
|
2 |
|
public function getLocale(): Locale |
191
|
|
|
{ |
192
|
2 |
|
return $this->locale; |
193
|
|
|
} |
194
|
|
|
|
195
|
2 |
|
public function getExtraId(): int |
196
|
|
|
{ |
197
|
2 |
|
return $this->extraId; |
198
|
|
|
} |
199
|
|
|
|
200
|
2 |
|
public function getTitle(): string |
201
|
|
|
{ |
202
|
2 |
|
return $this->title; |
203
|
|
|
} |
204
|
|
|
|
205
|
1 |
|
public function getStreet(): string |
206
|
|
|
{ |
207
|
1 |
|
return $this->street; |
208
|
|
|
} |
209
|
|
|
|
210
|
1 |
|
public function getNumber(): string |
211
|
|
|
{ |
212
|
1 |
|
return $this->number; |
213
|
|
|
} |
214
|
|
|
|
215
|
1 |
|
public function getZip(): string |
216
|
|
|
{ |
217
|
1 |
|
return $this->zip; |
218
|
|
|
} |
219
|
|
|
|
220
|
1 |
|
public function getCity(): string |
221
|
|
|
{ |
222
|
1 |
|
return $this->city; |
223
|
|
|
} |
224
|
|
|
|
225
|
1 |
|
public function getCountry(): string |
226
|
|
|
{ |
227
|
1 |
|
return $this->country; |
228
|
|
|
} |
229
|
|
|
|
230
|
1 |
|
public function getLatitude(): float |
231
|
|
|
{ |
232
|
1 |
|
return $this->latitude; |
233
|
|
|
} |
234
|
|
|
|
235
|
1 |
|
public function getLongitude(): float |
236
|
|
|
{ |
237
|
1 |
|
return $this->longitude; |
238
|
|
|
} |
239
|
|
|
|
240
|
1 |
|
public function isShowInOverview(): bool |
241
|
|
|
{ |
242
|
1 |
|
return $this->showInOverview; |
243
|
|
|
} |
244
|
|
|
|
245
|
4 |
|
public function getSettings(): Collection |
246
|
|
|
{ |
247
|
4 |
|
return $this->settings; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
public function getCreatedOn(): DateTime |
251
|
|
|
{ |
252
|
|
|
return $this->createdOn; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
public function getEditedOn(): DateTime |
256
|
|
|
{ |
257
|
|
|
return $this->editedOn; |
258
|
|
|
} |
259
|
|
|
|
260
|
1 |
|
public function setExtraId(int $extraId): void |
261
|
|
|
{ |
262
|
1 |
|
if ($this->extraId !== null) { |
263
|
|
|
throw new CanNotSetExtraIdException(); |
264
|
|
|
} |
265
|
|
|
|
266
|
1 |
|
$this->extraId = $extraId; |
267
|
1 |
|
} |
268
|
|
|
|
269
|
1 |
|
public function addSetting(LocationSetting $setting): void |
270
|
|
|
{ |
271
|
1 |
|
$this->settings->add($setting); |
272
|
1 |
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @ORM\PrePersist |
276
|
|
|
*/ |
277
|
1 |
|
public function prePersist(): void |
278
|
|
|
{ |
279
|
1 |
|
$this->createdOn = $this->editedOn = new DateTime(); |
280
|
1 |
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @ORM\PreUpdate |
284
|
|
|
*/ |
285
|
1 |
|
public function preUpdate(): void |
286
|
|
|
{ |
287
|
1 |
|
$this->editedOn = new DateTime(); |
288
|
1 |
|
} |
289
|
|
|
|
290
|
2 |
|
public static function fromArray(array $item): self |
291
|
|
|
{ |
292
|
2 |
|
if (APPLICATION === 'Frontend') { |
|
|
|
|
293
|
|
|
$locale = FrontendLocale::fromString($item['language']); |
294
|
|
|
} else { |
295
|
2 |
|
$locale = BackendLocale::fromString($item['language']); |
296
|
|
|
} |
297
|
|
|
|
298
|
2 |
|
return new self( |
299
|
2 |
|
$locale, |
300
|
2 |
|
$item['title'], |
301
|
2 |
|
$item['street'], |
302
|
2 |
|
$item['number'], |
303
|
2 |
|
$item['zip'], |
304
|
2 |
|
$item['city'], |
305
|
2 |
|
$item['country'], |
306
|
2 |
|
$item['lat'], |
307
|
2 |
|
$item['lng'], |
308
|
2 |
|
$item['show_overview'] ?? true, |
309
|
2 |
|
$item['extra_id'] ?? null |
310
|
|
|
); |
311
|
|
|
} |
312
|
|
|
|
313
|
3 |
|
public function toArray(): array |
314
|
|
|
{ |
315
|
|
|
return [ |
316
|
3 |
|
'id' => $this->id, |
317
|
3 |
|
'language' => $this->locale->getLocale(), |
318
|
3 |
|
'title' => $this->title, |
319
|
3 |
|
'street' => $this->street, |
320
|
3 |
|
'number' => $this->number, |
321
|
3 |
|
'zip' => $this->zip, |
322
|
3 |
|
'city' => $this->city, |
323
|
3 |
|
'country' => $this->country, |
324
|
3 |
|
'lat' => $this->latitude, |
325
|
3 |
|
'lng' => $this->longitude, |
326
|
3 |
|
'show_overview' => (int) $this->showInOverview, |
327
|
3 |
|
'extra_id' => $this->extraId, |
328
|
3 |
|
'settings' => $this->settings->toArray(), |
329
|
|
|
]; |
330
|
|
|
} |
331
|
|
|
} |
332
|
|
|
|