From d09cf430e1d4c94b8983ad0ea61d4b3540f87e5c Mon Sep 17 00:00:00 2001 From: tim Date: Fri, 31 Dec 2021 00:35:19 +0100 Subject: [PATCH] Implement recipes --- src/Controller/Admin/DashboardController.php | 6 ++ src/Controller/Admin/RecipeCrudController.php | 38 ++++++++ .../Admin/RecipeProductLineCrudController.php | 39 ++++++++ src/Entity/AbstractProductLine.php | 5 + src/Entity/Product.php | 5 + src/Entity/Recipe.php | 95 +++++++++++++++++++ src/Entity/RecipeProductLine.php | 13 +++ src/Repository/RecipeRepository.php | 50 ++++++++++ 8 files changed, 251 insertions(+) create mode 100644 src/Controller/Admin/RecipeCrudController.php create mode 100644 src/Controller/Admin/RecipeProductLineCrudController.php create mode 100644 src/Entity/Recipe.php create mode 100644 src/Repository/RecipeRepository.php diff --git a/src/Controller/Admin/DashboardController.php b/src/Controller/Admin/DashboardController.php index e7ab1b9..c835e08 100644 --- a/src/Controller/Admin/DashboardController.php +++ b/src/Controller/Admin/DashboardController.php @@ -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); } diff --git a/src/Controller/Admin/RecipeCrudController.php b/src/Controller/Admin/RecipeCrudController.php new file mode 100644 index 0000000..6440be1 --- /dev/null +++ b/src/Controller/Admin/RecipeCrudController.php @@ -0,0 +1,38 @@ +count, $this->product); + } + public function getId(): ?int { return $this->id; diff --git a/src/Entity/Product.php b/src/Entity/Product.php index 507cdd7..24feda2 100644 --- a/src/Entity/Product.php +++ b/src/Entity/Product.php @@ -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; diff --git a/src/Entity/Recipe.php b/src/Entity/Recipe.php new file mode 100644 index 0000000..eba843b --- /dev/null +++ b/src/Entity/Recipe.php @@ -0,0 +1,95 @@ +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; + } +} diff --git a/src/Entity/RecipeProductLine.php b/src/Entity/RecipeProductLine.php index 1a8415a..6a11d30 100644 --- a/src/Entity/RecipeProductLine.php +++ b/src/Entity/RecipeProductLine.php @@ -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; + } } \ No newline at end of file diff --git a/src/Repository/RecipeRepository.php b/src/Repository/RecipeRepository.php new file mode 100644 index 0000000..8f4a5f4 --- /dev/null +++ b/src/Repository/RecipeRepository.php @@ -0,0 +1,50 @@ +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() + ; + } + */ +}