futtern/src/Entity/OrderItem.php
2025-06-15 12:57:18 +02:00

108 lines
2.4 KiB
PHP

<?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\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: true)]
private FoodOrder|null $foodOrder = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private MenuItem|null $menuItem = null;
#[ORM\Column(length: 255, options: [
'default' => 'nobody',
])]
private string|null $createdBy = 'nobody';
public function __construct(
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = new Ulid
) {
$this->id ??= new Ulid;
}
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;
}
public function getMenuItem(): MenuItem|null
{
return $this->menuItem;
}
public function setMenuItem(MenuItem|null $menuItem): static
{
$this->menuItem = $menuItem;
$this->name = $menuItem->getName();
return $this;
}
public function getCreatedBy(): string|null
{
return $this->createdBy;
}
public function setCreatedBy(string $createdBy): static
{
$this->createdBy = $createdBy;
return $this;
}
}