Newer
Older
use App\Dto\DtoCollection;
use App\Dto\DtoInterface;
use App\Dto\FileDto;
use App\Dto\KitchenTypeDto;
use App\Dto\RestaurantDetailElementDto;
use App\Dto\RestaurantListingElementDto;
use App\Dto\TagDto;
use App\Repository\RestaurantsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Ramsey\Collection\Collection as RamseyCollection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: RestaurantsRepository::class)]
class Restaurants implements PrototypeElementDto
{
#[ORM\Id]
#[ORM\Column(type: Types::GUID)]
private ?string $id = null;
#[ORM\Column]
private ?bool $active = null;
#[ORM\Column]
private ?int $sort = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column]
private ?\DateTimeImmutable $updateAt = null;
#[ORM\ManyToOne(inversedBy: 'restaurantsTypes')]
#[ORM\ManyToOne(inversedBy: 'restaurantsSettlements')]
private ?Settlements $settlement = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(length: 255)]
private ?string $code = null;
#[ORM\Column(length: 255)]
private ?string $description = null;
#[ORM\Column(length: 255)]
private ?string $receipt = null;
#[ORM\Column(length: 255)]
private ?string $receiptInfo = null;
#[ORM\Column(length: 255)]
private ?string $phone = null;
#[ORM\Column(length: 255)]
private ?string $email = null;
#[ORM\Column(length: 255)]
private ?string $address = null;
#[ORM\Column(length: 255)]
private ?string $tags = null;
#[ORM\Column(length: 255)]
private ?string $site = null;
#[ORM\Column(length: 1000)]
private ?string $coordinates = null;
#[ORM\Column(length: 255)]
private ?string $howToFind = null;
/**
* @var Collection<int, Kitchens>
*/
#[ORM\ManyToMany(targetEntity: Kitchens::class, inversedBy: 'restaurants')]
private Collection $kitchens;
#[ORM\ManyToOne(inversedBy: 'restaurantsPreview')]
private ?File $previewImage = null;
#[ORM\ManyToOne(inversedBy: 'restaurantsDetail')]
private ?File $detailImage = null;
/**
* @var Collection<int, File>
*/
#[ORM\ManyToMany(targetEntity: File::class, inversedBy: 'restaurantsGallery')]
private Collection $gallery;
public function __construct()
{
$this->kitchens = new ArrayCollection();
$this->gallery = new ArrayCollection();
public function getId(): ?string
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
{
return $this->id;
}
public function setId(string $id): static
{
$this->id = $id;
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): static
{
$this->active = $active;
return $this;
}
public function getSort(): ?int
{
return $this->sort;
}
public function setSort(int $sort): static
{
$this->sort = $sort;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdateAt(): ?\DateTimeImmutable
{
return $this->updateAt;
}
public function setUpdateAt(\DateTimeImmutable $updateAt): static
{
$this->updateAt = $updateAt;
return $this;
}
public function getType(): ?RestaurantTypes
{
return $this->type;
}
public function setType(?RestaurantTypes $type): static
{
$this->type = $type;
return $this;
}
public function getSettlement(): ?Settlements
{
return $this->settlement;
}
public function setSettlement(?Settlements $settlement): static
{
$this->settlement = $settlement;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): static
{
$this->code = $code;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): static
{
$this->description = $description;
return $this;
}
public function getReceipt(): ?string
{
return $this->receipt;
}
public function setReceipt(string $receipt): static
{
$this->receipt = $receipt;
return $this;
}
public function getReceiptInfo(): ?string
{
return $this->receiptInfo;
}
public function setReceiptInfo(string $receiptInfo): static
{
$this->receiptInfo = $receiptInfo;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): static
{
$this->phone = $phone;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): static
{
$this->address = $address;
return $this;
}
public function getTags(): ?string
{
return $this->tags;
}
public function setTags(string $tags): static
{
$this->tags = $tags;
return $this;
}
public function getSite(): ?string
{
return $this->site;
}
public function setSite(string $site): static
{
$this->site = $site;
return $this;
}
public function getCoordinates(): string
public function setCoordinates(string $coordinates): static
{
$this->coordinates = $coordinates;
return $this;
}
public function getHowToFind(): ?string
return $this->howToFind;
public function setHowToFind(string $howToFind): static
$this->howToFind = $howToFind;
/**
* @return Collection<int, Kitchens>
*/
public function getKitchens(): Collection
return $this->kitchens;
public function addKitchen(Kitchens $kitchen): static
if (!$this->kitchens->contains($kitchen)) {
$this->kitchens->add($kitchen);
}
public function removeKitchen(Kitchens $kitchen): static
$this->kitchens->removeElement($kitchen);
return $this;
public function getPreviewImage(): ?File
return $this->previewImage;
}
public function setPreviewImage(?File $previewImage): static
{
$this->previewImage = $previewImage;
public function getDetailImage(): ?File
return $this->detailImage;
public function setDetailImage(?File $detailImage): static
$this->detailImage = $detailImage;
* @return Collection<int, File>
public function getGallery(): Collection
return $this->gallery;
public function addGallery(File $gallery): static
if (!$this->gallery->contains($gallery)) {
$this->gallery->add($gallery);
public function removeGallery(File $gallery): static
$this->gallery->removeElement($gallery);
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
/** @inheritDoc */
public function getDto(): DtoInterface
{
$dto = new RestaurantListingElementDto();
$dto->id = $this->getId();
$dto->name = $this->getName();
$dto->code = $this->getCode();
$dto->type = $this->getType()->getDto();
$dto->check = $this->getReceipt();
$dto->image = $this->getPreviewImage()?->getDto();
$dto->detail_link = 'api/v1/restaurants/' . $this->getId();
return $dto;
}
/** @inheritDoc
* @throws \JsonException Если получен неправильный json с бд
*/
public function getExtendedDto(): DtoInterface
{
$dto = new RestaurantDetailElementDto();
$dto->id = $this->getId();
$dto->name = $this->getName();
$dto->code = $this->getCode();
$dto->coordinates = $this->getCoordinates();
$dto->type = $this->getType()->getDto();
$dto->check = $this->getReceipt();
$dto->check_info = $this->getReceiptInfo();
$dto->kitchen = new DtoCollection(
KitchenTypeDto::class,
$this->getKitchens()
->map(function(Kitchens $kitchen) {
return $kitchen->getDto();
})
->toArray()
);
$dto->phone = $this->decode($this->getPhone(), 'phone');
$dto->email = $this->decode($this->getEmail(), 'email');
$dto->address = $this->decode($this->getAddress(), 'address');
$dto->tags = $this->decodeTags($this->getTags());
$dto->site = $this->getSite();
$dto->image = $this->getPreviewImage()?->getDto();
$dto->gallery = new DtoCollection(
FileDto::class,
$this->getGallery()
->map(function(File $file) {
return $file->getDto();
})
->toArray()
);
return $dto;
}
/**
* @throws \JsonException Если получен неправильный json с бд
* @return ?DtoCollection<string>
*/
private function decode(?string $jsonString, string $name): ?DtoCollection
{
if ($jsonString === null) {
return null;
}
return new DtoCollection(
'string|null',
json_decode(
$jsonString,
true,
512,
JSON_THROW_ON_ERROR
)[$name]
);
}
private function decodeTags(?string $jsonString): ?DtoCollection
{
if ($jsonString === null) {
return null;
}
$jsonCollection = new RamseyCollection(
'array',
json_decode(
$jsonString,
true,
512,
JSON_THROW_ON_ERROR
)
);
return new DtoCollection(
TagDto::class,
$jsonCollection
->map(function(array $tag) {
$tagDto = new TagDto();
$tagDto->name = key($tag);
$tagDto->list = new DtoCollection(
'string',
$tag
);
return $tagDto;
})
->toArray()
);
}