Add fridge related entities

This commit is contained in:
Tim 2022-01-01 23:10:58 +01:00
parent d09cf430e1
commit 94ff83d89a
7 changed files with 240 additions and 3 deletions

View File

@ -2,6 +2,8 @@
namespace App\Controller\Admin; namespace App\Controller\Admin;
use App\Entity\Fridge;
use App\Entity\FridgeProductLine;
use App\Entity\Product; use App\Entity\Product;
use App\Entity\QuantityUnit; use App\Entity\QuantityUnit;
use App\Entity\Recipe; use App\Entity\Recipe;
@ -44,6 +46,8 @@ class DashboardController extends AbstractDashboardController
yield MenuItem::section('Product lists', 'fas fa-folder-open'); yield MenuItem::section('Product lists', 'fas fa-folder-open');
yield MenuItem::linkToCrud('Recipes', 'fas fa-list', Recipe::class); yield MenuItem::linkToCrud('Recipes', 'fas fa-list', Recipe::class);
yield MenuItem::linkToCrud('Recipe product lines', 'fas fa-list', RecipeProductLine::class); yield MenuItem::linkToCrud('Recipe product lines', 'fas fa-list', RecipeProductLine::class);
yield MenuItem::linkToCrud('Fridges', 'fas fa-list', Fridge::class);
yield MenuItem::linkToCrud('Fridge product lines', 'fas fa-list', FridgeProductLine::class);
yield MenuItem::section('Administration', 'fas fa-folder-open'); yield MenuItem::section('Administration', 'fas fa-folder-open');
yield MenuItem::linkToCrud('User', 'fas fa-list', User::class); yield MenuItem::linkToCrud('User', 'fas fa-list', User::class);

View File

@ -0,0 +1,36 @@
<?php
namespace App\Controller\Admin;
use App\Entity\Fridge;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
class FridgeCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Fridge::class;
}
public function configureFields(string $pageName): iterable
{
$fields = [];
switch ($pageName) {
case Crud::PAGE_INDEX:
case Crud::PAGE_DETAIL:
$fields[] = IdField::new('id');
}
$fields[] = TextField::new('name');
$fields[] = TextField::new('description');
$fields[] = AssociationField::new('productLines');
return $fields;
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Controller\Admin;
use App\Entity\FridgeProductLine;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
class FridgeProductLineCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return FridgeProductLine::class;
}
public function configureFields(string $pageName): iterable
{
$fields = [];
switch ($pageName) {
case Crud::PAGE_INDEX:
case Crud::PAGE_DETAIL:
$fields[] = IdField::new('id');
}
$fields[] = IntegerField::new('count');
$fields[] = AssociationField::new('product');
$fields[] = AssociationField::new('fridge');
return $fields;
}
}

View File

@ -6,11 +6,8 @@ use App\Entity\RecipeProductLine;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField; use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField; use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
class RecipeProductLineCrudController extends AbstractCrudController class RecipeProductLineCrudController extends AbstractCrudController
{ {

90
src/Entity/Fridge.php Normal file
View File

@ -0,0 +1,90 @@
<?php
namespace App\Entity;
use App\Repository\FridgeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: FridgeRepository::class)]
class Fridge
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\Column(type: 'text', nullable: true)]
private $description;
#[ORM\OneToMany(mappedBy: 'fridge', targetEntity: FridgeProductLine::class)]
private $productLines;
public function __construct()
{
$this->productLines = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return Collection|FridgeProductLine[]
*/
public function getProductLines(): Collection
{
return $this->productLines;
}
public function addProductLine(FridgeProductLine $productLine): self
{
if (!$this->productLines->contains($productLine)) {
$this->productLines[] = $productLine;
$productLine->setFridge($this);
}
return $this;
}
public function removeProductLine(FridgeProductLine $productLine): self
{
if ($this->productLines->removeElement($productLine)) {
// set the owning side to null (unless already changed)
if ($productLine->getFridge() === $this) {
$productLine->setFridge(null);
}
}
return $this;
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class FridgeProductLine extends AbstractProductLine
{
#[ORM\ManyToOne(targetEntity: Fridge::class, inversedBy: 'productLines')]
private $fridge;
public function getFridge(): ?Fridge
{
return $this->fridge;
}
public function setFridge(?Fridge $fridge): self
{
$this->fridge = $fridge;
return $this;
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace App\Repository;
use App\Entity\Fridge;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Fridge|null find($id, $lockMode = null, $lockVersion = null)
* @method Fridge|null findOneBy(array $criteria, array $orderBy = null)
* @method Fridge[] findAll()
* @method Fridge[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class FridgeRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Fridge::class);
}
// /**
// * @return Fridge[] Returns an array of Fridge objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('f')
->andWhere('f.exampleField = :val')
->setParameter('val', $value)
->orderBy('f.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?Fridge
{
return $this->createQueryBuilder('f')
->andWhere('f.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}