From 53009471e147ca37136b49991daccd0f9bd05b0f Mon Sep 17 00:00:00 2001 From: lubiana Date: Tue, 13 Feb 2024 21:46:23 +0100 Subject: [PATCH] Add ItemExtra entity --- src/Entity/ItemExtra.php | 60 ++++++++++++++++++++++++++ src/Entity/MenuItem.php | 30 +++++++++++++ src/Entity/OrderItem.php | 3 -- src/Repository/ItemExtraRepository.php | 48 +++++++++++++++++++++ 4 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 src/Entity/ItemExtra.php create mode 100644 src/Repository/ItemExtraRepository.php diff --git a/src/Entity/ItemExtra.php b/src/Entity/ItemExtra.php new file mode 100644 index 0000000..4aec202 --- /dev/null +++ b/src/Entity/ItemExtra.php @@ -0,0 +1,60 @@ +id = new Ulid; + } + + public function getId(): Ulid + { + return $this->id; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getMenuItem(): ?MenuItem + { + return $this->menuItem; + } + + public function setMenuItem(?MenuItem $menuItem): static + { + $this->menuItem = $menuItem; + + return $this; + } +} diff --git a/src/Entity/MenuItem.php b/src/Entity/MenuItem.php index 45e166f..9d301b3 100644 --- a/src/Entity/MenuItem.php +++ b/src/Entity/MenuItem.php @@ -100,4 +100,34 @@ class MenuItem return $this; } + + /** + * @return Collection + */ + public function getItemExtras(): Collection + { + return $this->itemExtras; + } + + public function addItemExtra(ItemExtra $itemExtra): static + { + if (!$this->itemExtras->contains($itemExtra)) { + $this->itemExtras->add($itemExtra); + $itemExtra->setMenuItem($this); + } + + return $this; + } + + public function removeItemExtra(ItemExtra $itemExtra): static + { + if ($this->itemExtras->removeElement($itemExtra)) { + // set the owning side to null (unless already changed) + if ($itemExtra->getMenuItem() === $this) { + $itemExtra->setMenuItem(null); + } + } + + return $this; + } } diff --git a/src/Entity/OrderItem.php b/src/Entity/OrderItem.php index 9d74a7a..b0c4f2b 100644 --- a/src/Entity/OrderItem.php +++ b/src/Entity/OrderItem.php @@ -27,9 +27,6 @@ class OrderItem #[ORM\JoinColumn(nullable: false)] private ?MenuItem $menuItem = null; - #[ORM\OneToMany(mappedBy: 'orderItem', targetEntity: ItemExtra::class)] - private Collection $extras; - public function __construct() { $this->id = new Ulid; diff --git a/src/Repository/ItemExtraRepository.php b/src/Repository/ItemExtraRepository.php new file mode 100644 index 0000000..2dd61d7 --- /dev/null +++ b/src/Repository/ItemExtraRepository.php @@ -0,0 +1,48 @@ + + * + * @method ItemExtra|null find($id, $lockMode = null, $lockVersion = null) + * @method ItemExtra|null findOneBy(array $criteria, array $orderBy = null) + * @method ItemExtra[] findAll() + * @method ItemExtra[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class ItemExtraRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, ItemExtra::class); + } + +// /** +// * @return ItemExtra[] Returns an array of ItemExtra objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('i') +// ->andWhere('i.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('i.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?ItemExtra +// { +// return $this->createQueryBuilder('i') +// ->andWhere('i.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +}