futtern/src/Entity/MenuItem.php
lubiana 9781bd561f
All checks were successful
/ ls (pull_request) Successful in 2m42s
/ ls (release) Successful in 50s
/ ls (push) Successful in 2m27s
add menuitem aliases
2025-01-25 02:15:49 +01:00

137 lines
3.2 KiB
PHP

<?php declare(strict_types=1);
namespace App\Entity;
use App\Repository\MenuItemRepository;
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: MenuItemRepository::class)]
class MenuItem
{
#[ORM\Column(length: 255)]
private string|null $name = null;
#[ORM\ManyToOne(inversedBy: 'menuItems')]
#[ORM\JoinColumn(nullable: false)]
private FoodVendor|null $foodVendor = null;
#[ORM\Column(nullable: true)]
private DateTimeImmutable|null $deletedAt = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'aliases')]
private self|null $aliasOf = null;
/**
* @var Collection<int, self>
*/
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'aliasOf')]
private Collection $aliases;
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->aliases = new ArrayCollection;
}
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 getFoodVendor(): FoodVendor|null
{
return $this->foodVendor;
}
public function setFoodVendor(FoodVendor|null $foodVendor): static
{
$this->foodVendor = $foodVendor;
return $this;
}
public function isDeleted(): bool
{
return $this->getDeletedAt() instanceof DateTimeImmutable;
}
public function delete(): static
{
$this->setDeletedAt(new DateTimeImmutable);
return $this;
}
public function getDeletedAt(): DateTimeImmutable|null
{
return $this->deletedAt;
}
public function setDeletedAt(DateTimeImmutable|null $deletedAt = new DateTimeImmutable): static
{
$this->deletedAt = $deletedAt;
return $this;
}
public function getAliasOf(): self|null
{
return $this->aliasOf;
}
public function setAliasOf(self|null $aliasOf): static
{
$this->aliasOf = $aliasOf;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getAliases(): Collection
{
return $this->aliases;
}
public function addAlias(self $alias): static
{
if (! $this->aliases->contains($alias)) {
$this->aliases->add($alias);
$alias->setAliasOf($this);
}
return $this;
}
public function removeAlias(self $alias): static
{
// set the owning side to null (unless already changed)
if ($this->aliases->removeElement($alias) && $alias->getAliasOf() === $this) {
$alias->setAliasOf(null);
}
return $this;
}
}