From a8f2f4f4c42378978d92052ddf447de8f594447b Mon Sep 17 00:00:00 2001 From: Julien Rosset Date: Sun, 25 May 2025 15:29:49 +0200 Subject: [PATCH] Create entities --- migrations/Version20250525132541.php | 101 ++++++++++ src/Entity/InputRecipeMaterial.php | 98 ++++++++++ src/Entity/Machine.php | 123 ++++++++++++ src/Entity/Material.php | 128 +++++++++++++ src/Entity/MaterialType.php | 44 +++++ src/Entity/OutputRecipeMaterial.php | 98 ++++++++++ src/Entity/Recipe.php | 175 ++++++++++++++++++ src/Entity/TBaseEntity.php | 30 +++ src/Entity/TEntityBase.php | 45 ----- src/Entity/TNamedEntity.php | 38 ++++ src/Entity/User.php | 2 +- .../InputRecipeMaterialRepository.php | 16 ++ src/Repository/MachineRepository.php | 16 ++ src/Repository/MaterialRepository.php | 16 ++ src/Repository/MaterialTypeRepository.php | 16 ++ .../OutputRecipeMaterialRepository.php | 16 ++ src/Repository/RecipeRepository.php | 16 ++ src/Service/LoggerService.php | 1 + 18 files changed, 933 insertions(+), 46 deletions(-) create mode 100644 migrations/Version20250525132541.php create mode 100644 src/Entity/InputRecipeMaterial.php create mode 100644 src/Entity/Machine.php create mode 100644 src/Entity/Material.php create mode 100644 src/Entity/MaterialType.php create mode 100644 src/Entity/OutputRecipeMaterial.php create mode 100644 src/Entity/Recipe.php create mode 100644 src/Entity/TBaseEntity.php delete mode 100644 src/Entity/TEntityBase.php create mode 100644 src/Entity/TNamedEntity.php create mode 100644 src/Repository/InputRecipeMaterialRepository.php create mode 100644 src/Repository/MachineRepository.php create mode 100644 src/Repository/MaterialRepository.php create mode 100644 src/Repository/MaterialTypeRepository.php create mode 100644 src/Repository/OutputRecipeMaterialRepository.php create mode 100644 src/Repository/RecipeRepository.php diff --git a/migrations/Version20250525132541.php b/migrations/Version20250525132541.php new file mode 100644 index 0000000..0a8977a --- /dev/null +++ b/migrations/Version20250525132541.php @@ -0,0 +1,101 @@ +addSql(<<<'SQL' + CREATE TABLE input_recipe_material (id INT AUTO_INCREMENT NOT NULL, recipe_id INT NOT NULL, material_id INT NOT NULL, consumed_quantity INT NOT NULL, INDEX IDX_77575DA759D8A214 (recipe_id), INDEX IDX_77575DA7E308AC6F (material_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB + SQL); + $this->addSql(<<<'SQL' + CREATE TABLE machine (id INT AUTO_INCREMENT NOT NULL, label_extra_info1 VARCHAR(255) DEFAULT NULL, label_extra_info2 VARCHAR(255) DEFAULT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB + SQL); + $this->addSql(<<<'SQL' + CREATE TABLE material (id INT AUTO_INCREMENT NOT NULL, type_id INT NOT NULL, is_craftable_by_default TINYINT(1) NOT NULL, name VARCHAR(50) NOT NULL, INDEX IDX_7CBE7595C54C8C93 (type_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB + SQL); + $this->addSql(<<<'SQL' + CREATE TABLE material_type (id INT AUTO_INCREMENT NOT NULL, stack_size INT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB + SQL); + $this->addSql(<<<'SQL' + CREATE TABLE output_recipe_material (id INT AUTO_INCREMENT NOT NULL, recipe_id INT NOT NULL, material_id INT NOT NULL, produced_quantity DOUBLE PRECISION NOT NULL, INDEX IDX_CB0D94B259D8A214 (recipe_id), INDEX IDX_CB0D94B2E308AC6F (material_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB + SQL); + $this->addSql(<<<'SQL' + CREATE TABLE recipe (id INT AUTO_INCREMENT NOT NULL, machine_id INT NOT NULL, crafting_time DOUBLE PRECISION NOT NULL, name VARCHAR(50) NOT NULL, INDEX IDX_DA88B137F6B75B26 (machine_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE input_recipe_material ADD CONSTRAINT FK_77575DA759D8A214 FOREIGN KEY (recipe_id) REFERENCES recipe (id) ON DELETE CASCADE + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE input_recipe_material ADD CONSTRAINT FK_77575DA7E308AC6F FOREIGN KEY (material_id) REFERENCES material (id) + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE material ADD CONSTRAINT FK_7CBE7595C54C8C93 FOREIGN KEY (type_id) REFERENCES material_type (id) + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE output_recipe_material ADD CONSTRAINT FK_CB0D94B259D8A214 FOREIGN KEY (recipe_id) REFERENCES recipe (id) ON DELETE CASCADE + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE output_recipe_material ADD CONSTRAINT FK_CB0D94B2E308AC6F FOREIGN KEY (material_id) REFERENCES material (id) + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE recipe ADD CONSTRAINT FK_DA88B137F6B75B26 FOREIGN KEY (machine_id) REFERENCES machine (id) + SQL); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql(<<<'SQL' + ALTER TABLE input_recipe_material DROP FOREIGN KEY FK_77575DA759D8A214 + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE input_recipe_material DROP FOREIGN KEY FK_77575DA7E308AC6F + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE material DROP FOREIGN KEY FK_7CBE7595C54C8C93 + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE output_recipe_material DROP FOREIGN KEY FK_CB0D94B259D8A214 + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE output_recipe_material DROP FOREIGN KEY FK_CB0D94B2E308AC6F + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE recipe DROP FOREIGN KEY FK_DA88B137F6B75B26 + SQL); + $this->addSql(<<<'SQL' + DROP TABLE input_recipe_material + SQL); + $this->addSql(<<<'SQL' + DROP TABLE machine + SQL); + $this->addSql(<<<'SQL' + DROP TABLE material + SQL); + $this->addSql(<<<'SQL' + DROP TABLE material_type + SQL); + $this->addSql(<<<'SQL' + DROP TABLE output_recipe_material + SQL); + $this->addSql(<<<'SQL' + DROP TABLE recipe + SQL); + } +} diff --git a/src/Entity/InputRecipeMaterial.php b/src/Entity/InputRecipeMaterial.php new file mode 100644 index 0000000..221e44a --- /dev/null +++ b/src/Entity/InputRecipeMaterial.php @@ -0,0 +1,98 @@ +recipe; + } + /** + * Set the recipe + * + * @param Recipe|null $recipe The recipe + * + * @return $this + */ + public function setRecipe (?Recipe $recipe): static { + $this->recipe = $recipe; + + return $this; + } + + /** + * The material + * + * @return Material|null The material + */ + public function getMaterial (): ?Material { + return $this->material; + } + /** + * Set the material + * + * @param Material|null $material The material + * + * @return $this + */ + public function setMaterial (?Material $material): static { + $this->material = $material; + + return $this; + } + + /** + * The consumed quantity + * + * @return int|null The consumed quantity + */ + public function getConsumedQuantity (): ?int { + return $this->consumedQuantity; + } + /** + * Set the consumed quantity + * + * @param int $consumedQuantity The consumed quantity + * + * @return $this + */ + public function setConsumedQuantity (int $consumedQuantity): static { + $this->consumedQuantity = $consumedQuantity; + + return $this; + } +} diff --git a/src/Entity/Machine.php b/src/Entity/Machine.php new file mode 100644 index 0000000..0895b2c --- /dev/null +++ b/src/Entity/Machine.php @@ -0,0 +1,123 @@ + The recipes + */ + #[ORM\OneToMany(targetEntity: Recipe::class, mappedBy: 'machine', orphanRemoval: true)] + private Collection $recipes; + + public function __construct () { + $this->recipes = new ArrayCollection(); + } + + /** + * The label for the first extra information + * + * @return string|null The label for the first extra information + */ + public function getLabelExtraInfo1 (): ?string { + return $this->labelExtraInfo1; + } + /** + * Set the label for the first extra information + * + * @param string|null $labelExtraInfo1 The label for the first extra information + * + * @return $this + */ + public function setLabelExtraInfo1 (?string $labelExtraInfo1): static { + $this->labelExtraInfo1 = $labelExtraInfo1; + + return $this; + } + + /** + * The label for the second extra information + * + * @return string|null The label for the second extra information + */ + public function getLabelExtraInfo2 (): ?string { + return $this->labelExtraInfo2; + } + /** + * Set the label for the second extra information + * + * @param string|null $labelExtraInfo2 The label for the second extra information + * + * @return $this + */ + public function setLabelExtraInfo2 (?string $labelExtraInfo2): static { + $this->labelExtraInfo2 = $labelExtraInfo2; + + return $this; + } + + /** + * The recipes + * + * @return Collection The recipes + */ + public function getRecipes (): Collection { + return $this->recipes; + } + /** + * Add a recipe + * + * @param Recipe $recipe The recipe + * + * @return $this + */ + public function addRecipe (Recipe $recipe): static { + if (!$this->recipes->contains($recipe)) { + $this->recipes->add($recipe); + $recipe->setMachine($this); + } + + return $this; + } + /** + * Remove a recipe + * + * @param Recipe $recipe The recipe + * + * @return $this + */ + public function removeRecipe (Recipe $recipe): static { + if ($this->recipes->removeElement($recipe)) { + // set the owning side to null (unless already changed) + if ($recipe->getMachine() === $this) { + $recipe->setMachine(null); + } + } + + return $this; + } +} diff --git a/src/Entity/Material.php b/src/Entity/Material.php new file mode 100644 index 0000000..fe5afcd --- /dev/null +++ b/src/Entity/Material.php @@ -0,0 +1,128 @@ + The recipes + */ + #[ORM\OneToMany(targetEntity: OutputRecipeMaterial::class, mappedBy: 'material', orphanRemoval: true)] + private Collection $recipes; + + /** + * Initialization + */ + public function __construct () { + $this->recipes = new ArrayCollection(); + } + + /** + * The type + * + * @return MaterialType|null The type + */ + public function getType (): ?MaterialType { + return $this->type; + } + /** + * Set the type + * + * @param MaterialType|null $type The type + * + * @return $this + */ + public function setType (?MaterialType $type): static { + $this->type = $type; + + return $this; + } + + /** + * Is the material craftable by default? + * + * @return bool|null Is the material craftable by default? + */ + public function isCraftableByDefault (): ?bool { + return $this->isCraftableByDefault; + } + /** + * Set if the material craftable by default + * + * @param bool $isCraftableByDefault Is the material craftable by default? + * + * @return $this + */ + public function setIsCraftableByDefault (bool $isCraftableByDefault): static { + $this->isCraftableByDefault = $isCraftableByDefault; + + return $this; + } + + /** + * The recipes + * + * @return Collection The recipes + */ + public function getRecipes (): Collection { + return $this->recipes; + } + /** + * Add a recipe + * + * @param OutputRecipeMaterial $recipe The recipe + * + * @return $this + */ + public function addRecipe (OutputRecipeMaterial $recipe): static { + if (!$this->recipes->contains($recipe)) { + $this->recipes->add($recipe); + $recipe->setMaterial($this); + } + + return $this; + } + /** + * Remove a recipe + * + * @param OutputRecipeMaterial $recipe The recipe + * + * @return $this + */ + public function removeRecipe (OutputRecipeMaterial $recipe): static { + if ($this->recipes->removeElement($recipe)) { + // set the owning side to null (unless already changed) + if ($recipe->getMaterial() === $this) { + $recipe->setMaterial(null); + } + } + + return $this; + } +} diff --git a/src/Entity/MaterialType.php b/src/Entity/MaterialType.php new file mode 100644 index 0000000..1b4a656 --- /dev/null +++ b/src/Entity/MaterialType.php @@ -0,0 +1,44 @@ +stackSize; + } + /** + * Set the stack size + * + * @param int $stackSize The stack size + * + * @return $this + */ + public function setStackSize (int $stackSize): static { + $this->stackSize = $stackSize; + + return $this; + } +} diff --git a/src/Entity/OutputRecipeMaterial.php b/src/Entity/OutputRecipeMaterial.php new file mode 100644 index 0000000..e8fd704 --- /dev/null +++ b/src/Entity/OutputRecipeMaterial.php @@ -0,0 +1,98 @@ +recipe; + } + /** + * Set the recipe + * + * @param Recipe|null $recipe The recipe + * + * @return $this + */ + public function setRecipe (?Recipe $recipe): static { + $this->recipe = $recipe; + + return $this; + } + + /** + * The material + * + * @return Material|null The material + */ + public function getMaterial (): ?Material { + return $this->material; + } + /** + * Set the material + * + * @param Material|null $material The material + * + * @return $this + */ + public function setMaterial (?Material $material): static { + $this->material = $material; + + return $this; + } + + /** + * The produced quantity + * + * @return float|null The produced quantity + */ + public function getProducedQuantity (): ?float { + return $this->producedQuantity; + } + /** + * Set the produced quantity + * + * @param float $producedQuantity The produced quantity + * + * @return $this + */ + public function setProducedQuantity (float $producedQuantity): static { + $this->producedQuantity = $producedQuantity; + + return $this; + } +} diff --git a/src/Entity/Recipe.php b/src/Entity/Recipe.php new file mode 100644 index 0000000..2c9d974 --- /dev/null +++ b/src/Entity/Recipe.php @@ -0,0 +1,175 @@ + The input materials + */ + #[ORM\OneToMany(targetEntity: InputRecipeMaterial::class, mappedBy: 'recipe', orphanRemoval: true)] + private Collection $inputMaterials; + /** + * @var Collection The output materials + */ + #[ORM\OneToMany(targetEntity: OutputRecipeMaterial::class, mappedBy: 'recipe', orphanRemoval: true)] + private Collection $outputMaterials; + + /** + * Initialization + */ + public function __construct () { + $this->inputMaterials = new ArrayCollection(); + $this->outputMaterials = new ArrayCollection(); + } + + /** + * The crafting machine + * + * @return Machine|null The crafting machine + */ + public function getMachine (): ?Machine { + return $this->machine; + } + /** + * Set the crafting machine + * + * @param Machine|null $machine The crafting machine + * + * @return $this + */ + public function setMachine (?Machine $machine): static { + $this->machine = $machine; + + return $this; + } + + /** + * The crafting time, in seconds + * + * @return float|null The crafting time, in seconds + */ + public function getCraftingTime (): ?float { + return $this->craftingTime; + } + /** + * Set the crafting time, in seconds + * + * @param float $craftingTime The crafting time, in seconds + * + * @return $this + */ + public function setCraftingTime (float $craftingTime): static { + $this->craftingTime = $craftingTime; + + return $this; + } + + /** + * The input materials + * + * @return Collection The input materials + */ + public function getInputMaterials (): Collection { + return $this->inputMaterials; + } + /** + * Add an input material + * + * @param InputRecipeMaterial $inputMaterial The input material + * + * @return $this + */ + public function addInputMaterial (InputRecipeMaterial $inputMaterial): static { + if (!$this->inputMaterials->contains($inputMaterial)) { + $this->inputMaterials->add($inputMaterial); + $inputMaterial->setRecipe($this); + } + + return $this; + } + /** + * Remove an input material + * + * @param InputRecipeMaterial $inputMaterial The input material + * + * @return $this + */ + public function removeInputMaterial (InputRecipeMaterial $inputMaterial): static { + if ($this->inputMaterials->removeElement($inputMaterial)) { + // set the owning side to null (unless already changed) + if ($inputMaterial->getRecipe() === $this) { + $inputMaterial->setRecipe(null); + } + } + + return $this; + } + + /** + * The output materials + * + * @return Collection The output materials + */ + public function getOutputMaterials(): Collection + { + return $this->outputMaterials; + } + /** + * Add an output material + * + * @param OutputRecipeMaterial $outputMaterial The output material + * + * @return $this + */ + public function addOutputMaterial(OutputRecipeMaterial $outputMaterial): static + { + if (!$this->outputMaterials->contains($outputMaterial)) { + $this->outputMaterials->add($outputMaterial); + $outputMaterial->setRecipe($this); + } + + return $this; + } + /** + * Remove an output material + * + * @param OutputRecipeMaterial $outputMaterial The output material + * + * @return $this + */ + public function removeOutputMaterial(OutputRecipeMaterial $outputMaterial): static + { + if ($this->outputMaterials->removeElement($outputMaterial)) { + // set the owning side to null (unless already changed) + if ($outputMaterial->getRecipe() === $this) { + $outputMaterial->setRecipe(null); + } + } + + return $this; + } +} diff --git a/src/Entity/TBaseEntity.php b/src/Entity/TBaseEntity.php new file mode 100644 index 0000000..50cf666 --- /dev/null +++ b/src/Entity/TBaseEntity.php @@ -0,0 +1,30 @@ +id; + } +} \ No newline at end of file diff --git a/src/Entity/TEntityBase.php b/src/Entity/TEntityBase.php deleted file mode 100644 index 063562e..0000000 --- a/src/Entity/TEntityBase.php +++ /dev/null @@ -1,45 +0,0 @@ - $this->getId(), - ]; - } - - /** - * The internal id - * - * @return int|null The internal id - */ - public function getId (): ?int { - return $this->id; - } -} \ No newline at end of file diff --git a/src/Entity/TNamedEntity.php b/src/Entity/TNamedEntity.php new file mode 100644 index 0000000..d95594b --- /dev/null +++ b/src/Entity/TNamedEntity.php @@ -0,0 +1,38 @@ +name; + } + /** + * Set the name + * + * @param string $name The name + * + * @return $this + */ + public function setName (string $name): static { + $this->name = $name; + + return $this; + } +} \ No newline at end of file diff --git a/src/Entity/User.php b/src/Entity/User.php index 1a0ea03..3f0513f 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -20,7 +20,7 @@ use Symfony\Component\Validator\Constraints as Assert; #[ORM\Entity(repositoryClass: UserRepository::class)] #[UniqueEntity(fields: ['email'], message: 'Il existe déjà un compte avec cette adresse mail')] class User implements UserInterface, PasswordAuthenticatedUserInterface, Stringable { - use TEntityBase; + use TBaseEntity; /** * @var string The email diff --git a/src/Repository/InputRecipeMaterialRepository.php b/src/Repository/InputRecipeMaterialRepository.php new file mode 100644 index 0000000..62a2a76 --- /dev/null +++ b/src/Repository/InputRecipeMaterialRepository.php @@ -0,0 +1,16 @@ + + */ +class InputRecipeMaterialRepository extends ServiceEntityRepository { + public function __construct (ManagerRegistry $registry) { + parent::__construct($registry, InputRecipeMaterial::class); + } +} diff --git a/src/Repository/MachineRepository.php b/src/Repository/MachineRepository.php new file mode 100644 index 0000000..6646ded --- /dev/null +++ b/src/Repository/MachineRepository.php @@ -0,0 +1,16 @@ + + */ +class MachineRepository extends ServiceEntityRepository { + public function __construct (ManagerRegistry $registry) { + parent::__construct($registry, Machine::class); + } +} diff --git a/src/Repository/MaterialRepository.php b/src/Repository/MaterialRepository.php new file mode 100644 index 0000000..cd08e9c --- /dev/null +++ b/src/Repository/MaterialRepository.php @@ -0,0 +1,16 @@ + + */ +class MaterialRepository extends ServiceEntityRepository { + public function __construct (ManagerRegistry $registry) { + parent::__construct($registry, Material::class); + } +} diff --git a/src/Repository/MaterialTypeRepository.php b/src/Repository/MaterialTypeRepository.php new file mode 100644 index 0000000..1ea5de8 --- /dev/null +++ b/src/Repository/MaterialTypeRepository.php @@ -0,0 +1,16 @@ + + */ +class MaterialTypeRepository extends ServiceEntityRepository { + public function __construct (ManagerRegistry $registry) { + parent::__construct($registry, MaterialType::class); + } +} diff --git a/src/Repository/OutputRecipeMaterialRepository.php b/src/Repository/OutputRecipeMaterialRepository.php new file mode 100644 index 0000000..d07c6ad --- /dev/null +++ b/src/Repository/OutputRecipeMaterialRepository.php @@ -0,0 +1,16 @@ + + */ +class OutputRecipeMaterialRepository extends ServiceEntityRepository { + public function __construct (ManagerRegistry $registry) { + parent::__construct($registry, OutputRecipeMaterial::class); + } +} diff --git a/src/Repository/RecipeRepository.php b/src/Repository/RecipeRepository.php new file mode 100644 index 0000000..85e00bf --- /dev/null +++ b/src/Repository/RecipeRepository.php @@ -0,0 +1,16 @@ + + */ +class RecipeRepository extends ServiceEntityRepository { + public function __construct (ManagerRegistry $registry) { + parent::__construct($registry, Recipe::class); + } +} diff --git a/src/Service/LoggerService.php b/src/Service/LoggerService.php index 3406372..50cb4b5 100644 --- a/src/Service/LoggerService.php +++ b/src/Service/LoggerService.php @@ -30,6 +30,7 @@ class LoggerService implements LoggerInterface { /** * @inheritDoc + * @noinspection PhpHierarchyChecksInspection */ public function log ($level, string|Stringable $message, array $context = []): void { $this->loggerBase->log($level, $message, $context);