Compare commits

...

3 Commits

Author SHA1 Message Date
Julien Rosset b890b8300f Move machine's extra information from Task to Recipe 2 months ago
Julien Rosset e0b171a200 Create entity Task & add assertions to all entities 2 months ago
Julien Rosset a8f2f4f4c4 Create entities 2 months ago

@ -0,0 +1,101 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250525132541 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->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);
}
}

@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250526164743 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
CREATE TABLE task (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, produced_material_id INT NOT NULL, recipe_id INT DEFAULT NULL, parent_task_id INT DEFAULT NULL, root_task_id INT DEFAULT NULL, machine_extra_info1 VARCHAR(255) DEFAULT NULL, machine_extra_info2 VARCHAR(255) DEFAULT NULL, quantity_to_produce INT NOT NULL, quantity_provided_at_start INT NOT NULL, INDEX IDX_527EDB25A76ED395 (user_id), INDEX IDX_527EDB252B1CB36C (produced_material_id), INDEX IDX_527EDB2559D8A214 (recipe_id), INDEX IDX_527EDB25FFFE75C0 (parent_task_id), INDEX IDX_527EDB2561F7494C (root_task_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE task ADD CONSTRAINT FK_527EDB25A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE task ADD CONSTRAINT FK_527EDB252B1CB36C FOREIGN KEY (produced_material_id) REFERENCES material (id) ON DELETE CASCADE
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE task ADD CONSTRAINT FK_527EDB2559D8A214 FOREIGN KEY (recipe_id) REFERENCES recipe (id) ON DELETE CASCADE
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE task ADD CONSTRAINT FK_527EDB25FFFE75C0 FOREIGN KEY (parent_task_id) REFERENCES task (id) ON DELETE CASCADE
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE task ADD CONSTRAINT FK_527EDB2561F7494C FOREIGN KEY (root_task_id) REFERENCES task (id) ON DELETE CASCADE
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE material_type ADD stack_name VARCHAR(50) NOT NULL
SQL);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
ALTER TABLE task DROP FOREIGN KEY FK_527EDB25A76ED395
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE task DROP FOREIGN KEY FK_527EDB252B1CB36C
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE task DROP FOREIGN KEY FK_527EDB2559D8A214
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE task DROP FOREIGN KEY FK_527EDB25FFFE75C0
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE task DROP FOREIGN KEY FK_527EDB2561F7494C
SQL);
$this->addSql(<<<'SQL'
DROP TABLE task
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE material_type DROP stack_name
SQL);
}
}

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250526170059 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
ALTER TABLE recipe ADD machine_extra_info1 VARCHAR(255) DEFAULT NULL, ADD machine_extra_info2 VARCHAR(255) DEFAULT NULL
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE task DROP machine_extra_info1, DROP machine_extra_info2
SQL);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
ALTER TABLE recipe DROP machine_extra_info1, DROP machine_extra_info2
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE task ADD machine_extra_info1 VARCHAR(255) DEFAULT NULL, ADD machine_extra_info2 VARCHAR(255) DEFAULT NULL
SQL);
}
}

@ -0,0 +1,106 @@
<?php
namespace App\Entity;
use App\Repository\InputRecipeMaterialRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* A material consumed by a recipe
*/
#[ORM\Entity(repositoryClass: InputRecipeMaterialRepository::class)]
#[UniqueEntity(fields: ['recipe', 'material'], message: 'Ce matériau est déjà consommé par cette recette')]
class InputRecipeMaterial {
use TBaseEntity;
/**
* @var Recipe|null The recipe
*/
#[ORM\ManyToOne(inversedBy: 'inputMaterials')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[Assert\NotNull(message: 'Veuillez sélectionner une recette')]
#[Assert\Valid]
private ?Recipe $recipe = null;
/**
* @var Material|null The material
*/
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
#[Assert\NotNull(message: 'Veuillez sélectionner un matériau')]
#[Assert\Valid]
private ?Material $material = null;
/**
* @var int|null The consumed quantity
*/
#[ORM\Column]
#[Assert\Type(type: 'integer', message: 'La quantité consommée doit être un nombre entier')]
#[Assert\NotNull(message: 'Veuillez saisir une quantité consommée')]
#[Assert\Positive(message: 'La quantité consommée doit être strictement positive')]
private ?int $consumedQuantity = null;
/**
* The recipe
*
* @return Recipe|null The recipe
*/
public function getRecipe (): ?Recipe {
return $this->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;
}
}

@ -0,0 +1,130 @@
<?php
namespace App\Entity;
use App\Repository\MachineRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* A machine
*/
#[ORM\Entity(repositoryClass: MachineRepository::class)]
#[UniqueEntity(fields: ['name'], message: 'Il existe déjà une machine avec ce nom')]
class Machine {
use TBaseEntity;
use TNamedEntity;
/**
* @var string|null The label for the first extra information
*/
#[ORM\Column(length: 255, nullable: true)]
#[Assert\NotBlank(message: 'Veuillez saisir un nom d\'information complémentaire n° 1', allowNull: true)]
private ?string $labelExtraInfo1 = null;
/**
* @var string|null The label for the second extra information
*/
#[ORM\Column(length: 255, nullable: true)]
#[Assert\NotBlank(message: 'Veuillez saisir un nom d\'information complémentaire n° 2', allowNull: true)]
private ?string $labelExtraInfo2 = null;
/**
* @var Collection<int, Recipe> The recipes
*/
#[ORM\OneToMany(targetEntity: Recipe::class, mappedBy: 'machine', orphanRemoval: true)]
#[Assert\Valid]
private Collection $recipes;
/**
* Initialization
*/
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<int, Recipe> 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;
}
}

@ -0,0 +1,134 @@
<?php
namespace App\Entity;
use App\Repository\MaterialRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* A material
*/
#[ORM\Entity(repositoryClass: MaterialRepository::class)]
#[UniqueEntity(fields: ['name'], message: 'Il existe déjà un matériau avec ce nom')]
class Material {
use TBaseEntity;
use TNamedEntity;
/**
* @var MaterialType|null The type
*/
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
#[Assert\NotNull(message: 'Veuillez sélectionner un type de matériau')]
#[Assert\Valid]
private ?MaterialType $type = null;
/**
* @var bool|null Is the material craftable by default?
*/
#[ORM\Column]
#[Assert\Type(type: 'bool', message: 'L\'indicateur de si le matériau est craftable par défaut doit être un booléen')]
#[Assert\NotNull(message: 'Veuillez indiquer si le matériau est craftable par défaut')]
private ?bool $isCraftableByDefault = null;
/**
* @var Collection<int, OutputRecipeMaterial> The recipes
*/
#[ORM\OneToMany(targetEntity: OutputRecipeMaterial::class, mappedBy: 'material', orphanRemoval: true)]
#[Assert\Valid]
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<int, OutputRecipeMaterial> 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;
}
}

@ -0,0 +1,75 @@
<?php
namespace App\Entity;
use App\Repository\MaterialTypeRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* A material type
*/
#[ORM\Entity(repositoryClass: MaterialTypeRepository::class)]
#[UniqueEntity(fields: ['name'], message: 'Il existe déjà un type de matériau avec ce nom')]
class MaterialType {
use TBaseEntity;
use TNamedEntity;
/**
* @var string|null The “stack” name
*/
#[ORM\Column(length: 50)]
#[Assert\NotBlank(message: 'Veuillez saisir un nom de pile')]
private ?string $stackName = null;
/**
* @var int|null The “stack” size
*/
#[ORM\Column]
#[Assert\Type(type: 'integer', message: 'La taille de pile doit être un nombre entier')]
#[Assert\NotNull(message: 'Veuillez saisir une taille de pile')]
#[Assert\Positive(message: 'La taille de pile doit être strictement positive')]
private ?int $stackSize = null;
/**
* The “stack” name
*
* @return string|null The “stack” name
*/
public function getStackName (): ?string {
return $this->stackName;
}
/**
* Set the “stack” name
*
* @param string $stackName The “stack” name
*
* @return $this
*/
public function setStackName (string $stackName): static {
$this->stackName = $stackName;
return $this;
}
/**
* The “stack” size
*
* @return int|null The “stack” size
*/
public function getStackSize (): ?int {
return $this->stackSize;
}
/**
* Set the “stack” size
*
* @param int $stackSize The “stack” size
*
* @return $this
*/
public function setStackSize (int $stackSize): static {
$this->stackSize = $stackSize;
return $this;
}
}

@ -0,0 +1,106 @@
<?php
namespace App\Entity;
use App\Repository\OutputRecipeMaterialRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* A material produced by a recipe
*/
#[ORM\Entity(repositoryClass: OutputRecipeMaterialRepository::class)]
#[UniqueEntity(fields: ['recipe', 'material'], message: 'Ce matériau est déjà produite par cette recette')]
class OutputRecipeMaterial {
use TBaseEntity;
/**
* @var Recipe|null The recipe
*/
#[ORM\ManyToOne(inversedBy: 'outputMaterials')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[Assert\NotNull(message: 'Veuillez sélectionner une recette')]
#[Assert\Valid]
private ?Recipe $recipe = null;
/**
* @var Material|null The material
*/
#[ORM\ManyToOne(inversedBy: 'recipes')]
#[ORM\JoinColumn(nullable: false)]
#[Assert\NotNull(message: 'Veuillez sélectionner un matériau')]
#[Assert\Valid]
private ?Material $material = null;
/**
* @var float|null The produced quantity
*/
#[ORM\Column]
#[Assert\Type(type: 'float', message: 'La quantité produite doit être un nombre réel')]
#[Assert\NotNull(message: 'Veuillez saisir une quantité produite')]
#[Assert\Positive(message: 'La quantité produite doit être strictement positive')]
private ?float $producedQuantity = null;
/**
* The recipe
*
* @return Recipe|null The recipe
*/
public function getRecipe (): ?Recipe {
return $this->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;
}
}

@ -0,0 +1,236 @@
<?php
namespace App\Entity;
use App\Repository\RecipeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* A crafting recipe
*/
#[ORM\Entity(repositoryClass: RecipeRepository::class)]
class Recipe {
use TBaseEntity;
use TNamedEntity;
/**
* @var Machine|null The crafting machine
*/
#[ORM\ManyToOne(inversedBy: 'recipes')]
#[ORM\JoinColumn(nullable: false)]
#[Assert\NotNull(message: 'Veuillez sélectionner une machine de fabrication')]
#[Assert\Valid]
private ?Machine $machine = null;
/**
* @var string|null The machine's first extra information
*/
#[ORM\Column(length: 255, nullable: true)]
#[Assert\NotBlank(message: 'Veuillez saisir l\'information complémentaire n° 1', allowNull: true)]
private ?string $machineExtraInfo1 = null;
/**
* @var string|null The machine's second extra information
*/
#[ORM\Column(length: 255, nullable: true)]
#[Assert\NotBlank(message: 'Veuillez saisir l\'information complémentaire n° 2', allowNull: true)]
private ?string $machineExtraInfo2 = null;
/**
* @var float|null The crafting time, in seconds
*/
#[ORM\Column]
#[Assert\Type(type: 'float', message: 'Le temps de production doit être un nombre réel')]
#[Assert\NotNull(message: 'Veuillez saisir un temps de production')]
#[Assert\Positive(message: 'Le temps de production doit être strictement positive')]
private ?float $craftingTime = null;
/**
* @var Collection<int, InputRecipeMaterial> The consumed materials
*/
#[ORM\OneToMany(targetEntity: InputRecipeMaterial::class, mappedBy: 'recipe', orphanRemoval: true)]
#[Assert\Count(min: 1, minMessage: 'Veuillez ajouter au moins un matériau consommé')]
#[Assert\Valid]
private Collection $consumedMaterials;
/**
* @var Collection<int, OutputRecipeMaterial> The produced materials
*/
#[ORM\OneToMany(targetEntity: OutputRecipeMaterial::class, mappedBy: 'recipe', orphanRemoval: true)]
#[Assert\Count(min: 1, minMessage: 'Veuillez ajouter au moins un matériau produit')]
#[Assert\Valid]
private Collection $producedMaterials;
/**
* Initialization
*/
public function __construct () {
$this->consumedMaterials = new ArrayCollection();
$this->producedMaterials = 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 machine's first extra information
*
* @return string|null The machine's first extra information
*/
public function getMachineExtraInfo1 (): ?string {
return $this->machineExtraInfo1;
}
/**
* Set the machine's first extra information
*
* @param string|null $machineExtraInfo1 The machine's first extra information
*
* @return $this
*/
public function setMachineExtraInfo1 (?string $machineExtraInfo1): self {
$this->machineExtraInfo1 = $machineExtraInfo1;
return $this;
}
/**
* The machine's second extra information
*
* @return string|null The machine's second extra information
*/
public function getMachineExtraInfo2 (): ?string {
return $this->machineExtraInfo2;
}
/**
* Set the machine's second extra information
*
* @param string|null $machineExtraInfo2 The machine's second extra information
*
* @return $this
*/
public function setMachineExtraInfo2 (?string $machineExtraInfo2): self {
$this->machineExtraInfo2 = $machineExtraInfo2;
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 consumed materials
*
* @return Collection<int, InputRecipeMaterial> The consumed materials
*/
public function getConsumedMaterials (): Collection {
return $this->consumedMaterials;
}
/**
* Add a consumed material
*
* @param InputRecipeMaterial $inputMaterial The consumed material
*
* @return $this
*/
public function addConsumedMaterial (InputRecipeMaterial $inputMaterial): static {
if (!$this->consumedMaterials->contains($inputMaterial)) {
$this->consumedMaterials->add($inputMaterial);
$inputMaterial->setRecipe($this);
}
return $this;
}
/**
* Remove a consumed material
*
* @param InputRecipeMaterial $inputMaterial The consumed material
*
* @return $this
*/
public function removeConsumedMaterial (InputRecipeMaterial $inputMaterial): static {
if ($this->consumedMaterials->removeElement($inputMaterial)) {
// set the owning side to null (unless already changed)
if ($inputMaterial->getRecipe() === $this) {
$inputMaterial->setRecipe(null);
}
}
return $this;
}
/**
* The produced materials
*
* @return Collection<int, OutputRecipeMaterial> The produced materials
*/
public function getProducedMaterials(): Collection
{
return $this->producedMaterials;
}
/**
* Add a produced material
*
* @param OutputRecipeMaterial $outputMaterial The produced material
*
* @return $this
*/
public function addProducedMaterial(OutputRecipeMaterial $outputMaterial): static
{
if (!$this->producedMaterials->contains($outputMaterial)) {
$this->producedMaterials->add($outputMaterial);
$outputMaterial->setRecipe($this);
}
return $this;
}
/**
* Remove a produced material
*
* @param OutputRecipeMaterial $outputMaterial The produced material
*
* @return $this
*/
public function removeProducedMaterial(OutputRecipeMaterial $outputMaterial): static
{
if ($this->producedMaterials->removeElement($outputMaterial)) {
// set the owning side to null (unless already changed)
if ($outputMaterial->getRecipe() === $this) {
$outputMaterial->setRecipe(null);
}
}
return $this;
}
}

@ -0,0 +1,30 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
/**
* Implementation for the base of an entity: id
*/
trait TBaseEntity {
/**
* @var int|null The internal id
*
* @noinspection PhpPropertyNamingConventionInspection
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
/**
* The internal id
*
* @return int|null The internal id
*/
public function getId (): ?int {
return $this->id;
}
}

@ -1,45 +0,0 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
/**
* Implementation for the base implementation of an entity: id, creation and last update date and time
*/
trait TEntityBase {
/**
* @var int|null The internal id
*
* @noinspection PhpPropertyNamingConventionInspection
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
/**
* Les données du trait qui doivent être inclus dans le JSON
*
* @return array Les données du trait qui doivent être inclus dans le JSON
*
* @see JsonSerializable::jsonSerialize()
*
* @noinspection PhpMethodNamingConventionInspection
*/
protected final function TEntityBase__jsonSerialize (): array {
return [
'id' => $this->getId(),
];
}
/**
* The internal id
*
* @return int|null The internal id
*/
public function getId (): ?int {
return $this->id;
}
}

@ -0,0 +1,39 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Implementation for an entity with a name
*/
trait TNamedEntity {
/**
* @var string|null The name
*/
#[ORM\Column(length: 50)]
#[Assert\NotBlank(message: 'Veuillez saisir un email')]
private ?string $name = null;
/**
* The name
*
* @return string|null The name
*/
public function getName (): ?string {
return $this->name;
}
/**
* Set the name
*
* @param string $name The name
*
* @return $this
*/
public function setName (string $name): static {
$this->name = $name;
return $this;
}
}

@ -0,0 +1,274 @@
<?php
namespace App\Entity;
use App\Repository\TaskRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* A crafting task
*/
#[ORM\Entity(repositoryClass: TaskRepository::class)]
class Task {
use TBaseEntity;
/**
* @var User|null The user
*/
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[Assert\NotNull(message: 'Veuillez sélectionner un utilisateur')]
#[Assert\Valid]
private ?User $user = null;
/**
* @var Material|null The produced material
*/
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[Assert\NotNull(message: 'Veuillez sélectionner le matériau à produire')]
#[Assert\Valid]
private ?Material $producedMaterial = null;
/**
* @var Recipe|null The recipe
*/
#[ORM\ManyToOne]
#[ORM\JoinColumn(onDelete: 'CASCADE')]
#[Assert\Valid]
private ?Recipe $recipe = null;
/**
* @var int|null The quantity asked / to produce
*/
#[ORM\Column]
#[Assert\Type(type: 'integer', message: 'La quantité à produire doit être un nombre entier')]
#[Assert\NotNull(message: 'Veuillez saisir une quantité à produire')]
#[Assert\Positive(message: 'La quantité à produire doit être strictement positive')]
private ?int $quantityToProduce = null;
/**
* @var int|null The quantity already provided at the start
*/
#[ORM\Column]
#[Assert\Type(type: 'integer', message: 'La quantité de départ doit être un nombre entier')]
#[Assert\NotNull(message: 'Veuillez saisir une quantité de départ')]
#[Assert\PositiveOrZero(message: 'La quantité de départ doit être positive ou nulle')]
private ?int $quantityProvidedAtStart = null;
/**
* @var Task|null The parent task
*/
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'childTasks')]
#[ORM\JoinColumn(onDelete: 'CASCADE')]
#[Assert\Valid]
private ?self $parentTask = null;
/**
* @var Collection<int, self> The child tasks
*/
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parentTask', orphanRemoval: true)]
#[Assert\Valid]
private Collection $childTasks;
/**
* @var Task|null The root task
*/
#[ORM\ManyToOne(targetEntity: self::class)]
#[ORM\JoinColumn(onDelete: 'CASCADE')]
#[Assert\Valid]
private ?self $rootTask = null;
/**
* Initialization
*/
public function __construct () {
$this->childTasks = new ArrayCollection();
}
/**
* The user
*
* @return User|null The user
*/
public function getUser (): ?User {
return $this->user;
}
/**
* Set the user
*
* @param User|null $user The user
*
* @return $this
*/
public function setUser (?User $user): static {
$this->user = $user;
return $this;
}
/**
* The produced material
*
* @return Material|null The produced material
*/
public function getProducedMaterial (): ?Material {
return $this->producedMaterial;
}
/**
* Set the produced material
*
* @param Material|null $producedMaterial The produced material
*
* @return $this
*/
public function setProducedMaterial (?Material $producedMaterial): static {
$this->producedMaterial = $producedMaterial;
return $this;
}
/**
* The recipe
*
* @return Recipe|null The recipe
*/
public function getRecipe (): ?Recipe {
return $this->recipe;
}
/**
* The recipe
*
* @param Recipe|null $recipe The recipe
*
* @return $this
*/
public function setRecipe (?Recipe $recipe): static {
$this->recipe = $recipe;
return $this;
}
/**
* The quantity asked / to produce
*
* @return int|null The quantity asked / to produce
*/
public function getQuantityToProduce (): ?int {
return $this->quantityToProduce;
}
/**
* Set the quantity asked / to produce
*
* @param int $quantityToProduce The quantity asked / to produce
*
* @return $this
*/
public function setQuantityToProduce (int $quantityToProduce): static {
$this->quantityToProduce = $quantityToProduce;
return $this;
}
/**
* The quantity already provided at the start
*
* @return int|null The quantity already provided at the start
*/
public function getQuantityProvidedAtStart (): ?int {
return $this->quantityProvidedAtStart;
}
/**
* Set the quantity already provided at the start
*
* @param int $quantityProvidedAtStart The quantity already provided at the start
*
* @return $this
*/
public function setQuantityProvidedAtStart (int $quantityProvidedAtStart): static {
$this->quantityProvidedAtStart = $quantityProvidedAtStart;
return $this;
}
/**
* The parent task
*
* @return self|null The parent task
*/
public function getParentTask (): ?self {
return $this->parentTask;
}
/**
* Set the parent task
*
* @param Task|null $parentTask The parent task
*
* @return $this
*/
public function setParentTask (?self $parentTask): static {
$this->parentTask = $parentTask;
return $this;
}
/**
* The child tasks
*
* @return Collection<int, self> The child tasks
*/
public function getChildTasks (): Collection {
return $this->childTasks;
}
/**
* Add a child task
*
* @param Task $childTask The child task
*
* @return $this
*/
public function addChildTask (self $childTask): static {
if (!$this->childTasks->contains($childTask)) {
$this->childTasks->add($childTask);
$childTask->setParentTask($this);
}
return $this;
}
/**
* Remove a child task
*
* @param Task $childTask The child task
*
* @return $this
*/
public function removeChildTask (self $childTask): static {
if ($this->childTasks->removeElement($childTask)) {
// set the owning side to null (unless already changed)
if ($childTask->getParentTask() === $this) {
$childTask->setParentTask(null);
}
}
return $this;
}
/**
* The root task
*
* @return self|null The root task
*/
public function getRootTask (): ?self {
return $this->rootTask;
}
/**
* Set the root task
*
* @param Task|null $rootTask The root task
*
* @return $this
*/
public function setRootTask (?self $rootTask): static {
$this->rootTask = $rootTask;
return $this;
}
}

@ -3,10 +3,6 @@
namespace App\Entity; namespace App\Entity;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Stringable; use Stringable;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
@ -20,7 +16,7 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: UserRepository::class)] #[ORM\Entity(repositoryClass: UserRepository::class)]
#[UniqueEntity(fields: ['email'], message: 'Il existe déjà un compte avec cette adresse mail')] #[UniqueEntity(fields: ['email'], message: 'Il existe déjà un compte avec cette adresse mail')]
class User implements UserInterface, PasswordAuthenticatedUserInterface, Stringable { class User implements UserInterface, PasswordAuthenticatedUserInterface, Stringable {
use TEntityBase; use TBaseEntity;
/** /**
* @var string The email * @var string The email
@ -39,6 +35,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Stringa
* @var string|null The name * @var string|null The name
*/ */
#[ORM\Column(length: 100, nullable: true)] #[ORM\Column(length: 100, nullable: true)]
#[Assert\NotBlank(message: 'Veuillez saisir un nom', allowNull: true)]
private ?string $name = null; private ?string $name = null;
/** /**

@ -0,0 +1,16 @@
<?php
namespace App\Repository;
use App\Entity\InputRecipeMaterial;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<InputRecipeMaterial>
*/
class InputRecipeMaterialRepository extends ServiceEntityRepository {
public function __construct (ManagerRegistry $registry) {
parent::__construct($registry, InputRecipeMaterial::class);
}
}

@ -0,0 +1,16 @@
<?php
namespace App\Repository;
use App\Entity\Machine;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Machine>
*/
class MachineRepository extends ServiceEntityRepository {
public function __construct (ManagerRegistry $registry) {
parent::__construct($registry, Machine::class);
}
}

@ -0,0 +1,16 @@
<?php
namespace App\Repository;
use App\Entity\Material;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Material>
*/
class MaterialRepository extends ServiceEntityRepository {
public function __construct (ManagerRegistry $registry) {
parent::__construct($registry, Material::class);
}
}

@ -0,0 +1,16 @@
<?php
namespace App\Repository;
use App\Entity\MaterialType;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<MaterialType>
*/
class MaterialTypeRepository extends ServiceEntityRepository {
public function __construct (ManagerRegistry $registry) {
parent::__construct($registry, MaterialType::class);
}
}

@ -0,0 +1,16 @@
<?php
namespace App\Repository;
use App\Entity\OutputRecipeMaterial;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<OutputRecipeMaterial>
*/
class OutputRecipeMaterialRepository extends ServiceEntityRepository {
public function __construct (ManagerRegistry $registry) {
parent::__construct($registry, OutputRecipeMaterial::class);
}
}

@ -0,0 +1,16 @@
<?php
namespace App\Repository;
use App\Entity\Recipe;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Recipe>
*/
class RecipeRepository extends ServiceEntityRepository {
public function __construct (ManagerRegistry $registry) {
parent::__construct($registry, Recipe::class);
}
}

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Task;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Task>
*/
class TaskRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Task::class);
}
// /**
// * @return Task[] Returns an array of Task objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('t')
// ->andWhere('t.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('t.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Task
// {
// return $this->createQueryBuilder('t')
// ->andWhere('t.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

@ -30,6 +30,7 @@ class LoggerService implements LoggerInterface {
/** /**
* @inheritDoc * @inheritDoc
* @noinspection PhpHierarchyChecksInspection
*/ */
public function log ($level, string|Stringable $message, array $context = []): void { public function log ($level, string|Stringable $message, array $context = []): void {
$this->loggerBase->log($level, $message, $context); $this->loggerBase->log($level, $message, $context);

Loading…
Cancel
Save