add order

This commit is contained in:
lubiana 2024-06-14 17:41:00 +02:00
parent 7663f684a4
commit 1dc5306967
No known key found for this signature in database
37 changed files with 1060 additions and 113 deletions

128
src/Entity/FoodOrder.php Normal file
View file

@ -0,0 +1,128 @@
<?php declare(strict_types=1);
namespace App\Entity;
use App\Repository\FoodOrderRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
class FoodOrder
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = null;
#[ORM\Column]
private DateTimeImmutable $createdAt;
#[ORM\Column(nullable: true)]
private DateTimeImmutable|null $closedAt = null;
#[ORM\ManyToOne(inversedBy: 'foodOrders')]
#[ORM\JoinColumn(nullable: false)]
private FoodVendor|null $foodVendor = null;
/**
* @var Collection<int, OrderItem>
*/
#[ORM\OneToMany(targetEntity: OrderItem::class, mappedBy: 'foodOrder', orphanRemoval: true)]
private Collection $orderItems;
public function __construct()
{
$this->createdAt = new DateTimeImmutable;
$this->orderItems = new ArrayCollection;
}
public function getId(): Ulid|null
{
return $this->id;
}
public function getCreatedAt(): DateTimeImmutable|null
{
return $this->createdAt;
}
public function setCreatedAt(DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getClosedAt(): DateTimeImmutable|null
{
return $this->closedAt;
}
public function setClosedAt(DateTimeImmutable|null $closedAt): static
{
$this->closedAt = $closedAt;
return $this;
}
public function isClosed(): bool
{
return $this->closedAt instanceof DateTimeImmutable;
}
public function close(): static
{
return $this->setClosedAt(new DateTimeImmutable);
}
public function open(): static
{
return $this->setClosedAt(null);
}
public function getFoodVendor(): FoodVendor|null
{
return $this->foodVendor;
}
public function setFoodVendor(FoodVendor|null $foodVendor): static
{
$this->foodVendor = $foodVendor;
return $this;
}
/**
* @return Collection<int, OrderItem>
*/
public function getOrderItems(): Collection
{
return $this->orderItems;
}
public function addOrderItem(OrderItem $orderItem): static
{
if (! $this->orderItems->contains($orderItem)) {
$this->orderItems->add($orderItem);
$orderItem->setFoodOrder($this);
}
return $this;
}
public function removeOrderItem(OrderItem $orderItem): static
{
// set the owning side to null (unless already changed)
if ($this->orderItems->removeElement($orderItem) && $orderItem->getFoodOrder() === $this) {
$orderItem->setFoodOrder(null);
}
return $this;
}
}

View file

@ -3,6 +3,8 @@
namespace App\Entity;
use App\Repository\FoodVendorRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\Types\UlidType;
@ -20,6 +22,17 @@ class FoodVendor
#[ORM\Column(length: 50)]
private string|null $name = null;
/**
* @var Collection<int, FoodOrder>
*/
#[ORM\OneToMany(targetEntity: FoodOrder::class, mappedBy: 'foodVendor', orphanRemoval: true)]
private Collection $foodOrders;
public function __construct()
{
$this->foodOrders = new ArrayCollection;
}
public function getId(): Ulid|null
{
return $this->id;
@ -36,4 +49,32 @@ class FoodVendor
return $this;
}
/**
* @return Collection<int, FoodOrder>
*/
public function getFoodOrders(): Collection
{
return $this->foodOrders;
}
public function addFoodOrder(FoodOrder $foodOrder): static
{
if (! $this->foodOrders->contains($foodOrder)) {
$this->foodOrders->add($foodOrder);
$foodOrder->setFoodVendor($this);
}
return $this;
}
public function removeFoodOrder(FoodOrder $foodOrder): static
{
// set the owning side to null (unless already changed)
if ($this->foodOrders->removeElement($foodOrder) && $foodOrder->getFoodVendor() === $this) {
$foodOrder->setFoodVendor(null);
}
return $this;
}
}

70
src/Entity/OrderItem.php Normal file
View file

@ -0,0 +1,70 @@
<?php declare(strict_types=1);
namespace App\Entity;
use App\Repository\OrderItemRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: OrderItemRepository::class)]
class OrderItem
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = null;
#[ORM\Column(length: 255)]
private string|null $name = null;
#[ORM\Column(length: 255, nullable: true)]
private string|null $extras = null;
#[ORM\ManyToOne(inversedBy: 'orderItems')]
#[ORM\JoinColumn(nullable: false)]
private FoodOrder|null $foodOrder = null;
public function getId(): Ulid|null
{
return $this->id;
}
public function getName(): string|null
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getExtras(): string|null
{
return $this->extras;
}
public function setExtras(string|null $extras): static
{
$this->extras = $extras;
return $this;
}
public function getFoodOrder(): FoodOrder|null
{
return $this->foodOrder;
}
public function setFoodOrder(FoodOrder|null $foodOrder): static
{
$this->foodOrder = $foodOrder;
return $this;
}
}