Implement recipes
This commit is contained in:
parent
f2a85c6c7d
commit
d09cf430e1
@ -4,6 +4,8 @@ namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Product;
|
||||
use App\Entity\QuantityUnit;
|
||||
use App\Entity\Recipe;
|
||||
use App\Entity\RecipeProductLine;
|
||||
use App\Entity\User;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
|
||||
@ -39,6 +41,10 @@ class DashboardController extends AbstractDashboardController
|
||||
yield MenuItem::linkToCrud('Products', 'fas fa-list', Product::class);
|
||||
yield MenuItem::linkToCrud('Quantity units', 'fas fa-list', QuantityUnit::class);
|
||||
|
||||
yield MenuItem::section('Product lists', 'fas fa-folder-open');
|
||||
yield MenuItem::linkToCrud('Recipes', 'fas fa-list', Recipe::class);
|
||||
yield MenuItem::linkToCrud('Recipe product lines', 'fas fa-list', RecipeProductLine::class);
|
||||
|
||||
yield MenuItem::section('Administration', 'fas fa-folder-open');
|
||||
yield MenuItem::linkToCrud('User', 'fas fa-list', User::class);
|
||||
}
|
||||
|
38
src/Controller/Admin/RecipeCrudController.php
Normal file
38
src/Controller/Admin/RecipeCrudController.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Recipe;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
|
||||
class RecipeCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Recipe::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;
|
||||
}
|
||||
|
||||
}
|
39
src/Controller/Admin/RecipeProductLineCrudController.php
Normal file
39
src/Controller/Admin/RecipeProductLineCrudController.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\RecipeProductLine;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
|
||||
class RecipeProductLineCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return RecipeProductLine::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('recipe');
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
@ -21,6 +21,11 @@ abstract class AbstractProductLine
|
||||
#[ORM\ManyToOne(targetEntity: Product::class)]
|
||||
private $product;
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return sprintf('%dx %s', $this->count, $this->product);
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
|
@ -25,6 +25,11 @@ class Product
|
||||
#[ORM\ManyToOne(targetEntity: QuantityUnit::class)]
|
||||
private $quantityUnit;
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
|
95
src/Entity/Recipe.php
Normal file
95
src/Entity/Recipe.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\RecipeRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: RecipeRepository::class)]
|
||||
class Recipe
|
||||
{
|
||||
#[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: 'recipe', targetEntity: RecipeProductLine::class)]
|
||||
private $productLines;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->productLines = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
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|RecipeProductLine[]
|
||||
*/
|
||||
public function getProductLines(): Collection
|
||||
{
|
||||
return $this->productLines;
|
||||
}
|
||||
|
||||
public function addProductLine(RecipeProductLine $productLine): self
|
||||
{
|
||||
if (!$this->productLines->contains($productLine)) {
|
||||
$this->productLines[] = $productLine;
|
||||
$productLine->setRecipe($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeProductLine(RecipeProductLine $productLine): self
|
||||
{
|
||||
if ($this->productLines->removeElement($productLine)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($productLine->getRecipe() === $this) {
|
||||
$productLine->setRecipe(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -7,5 +7,18 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
#[ORM\Entity]
|
||||
class RecipeProductLine extends AbstractProductLine
|
||||
{
|
||||
#[ORM\ManyToOne(targetEntity: Recipe::class, inversedBy: 'productLines')]
|
||||
private $recipe;
|
||||
|
||||
public function getRecipe(): ?Recipe
|
||||
{
|
||||
return $this->recipe;
|
||||
}
|
||||
|
||||
public function setRecipe(?Recipe $recipe): self
|
||||
{
|
||||
$this->recipe = $recipe;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
50
src/Repository/RecipeRepository.php
Normal file
50
src/Repository/RecipeRepository.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Recipe;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @method Recipe|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Recipe|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Recipe[] findAll()
|
||||
* @method Recipe[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class RecipeRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Recipe::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Recipe[] Returns an array of Recipe objects
|
||||
// */
|
||||
/*
|
||||
public function findByExampleField($value)
|
||||
{
|
||||
return $this->createQueryBuilder('r')
|
||||
->andWhere('r.exampleField = :val')
|
||||
->setParameter('val', $value)
|
||||
->orderBy('r.id', 'ASC')
|
||||
->setMaxResults(10)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
public function findOneBySomeField($value): ?Recipe
|
||||
{
|
||||
return $this->createQueryBuilder('r')
|
||||
->andWhere('r.exampleField = :val')
|
||||
->setParameter('val', $value)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user