Add ItemExtra entity

This commit is contained in:
Jonas 2024-02-13 21:46:23 +01:00
parent ac248697ff
commit 53009471e1
4 changed files with 138 additions and 3 deletions

60
src/Entity/ItemExtra.php Normal file
View file

@ -0,0 +1,60 @@
<?php
namespace App\Entity;
use App\Repository\ItemExtraRepository;
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: ItemExtraRepository::class)]
class ItemExtra
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid $id;
#[ORM\Column(length: 50)]
private ?string $name = null;
#[ORM\ManyToOne(inversedBy: 'itemExtras')]
#[ORM\JoinColumn(nullable: false)]
private ?MenuItem $menuItem = null;
public function __construct() {
$this->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;
}
}

View file

@ -100,4 +100,34 @@ class MenuItem
return $this;
}
/**
* @return Collection<int, ItemExtra>
*/
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;
}
}

View file

@ -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;

View file

@ -0,0 +1,48 @@
<?php
namespace App\Repository;
use App\Entity\ItemExtra;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<ItemExtra>
*
* @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()
// ;
// }
}