Create entity Task & add assertions to all entities
parent
a8f2f4f4c4
commit
e0b171a200
@ -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,287 @@
|
||||
<?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 string|null The label for the 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 label for the 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 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;
|
||||
}
|
||||
}
|
@ -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()
|
||||
// ;
|
||||
// }
|
||||
}
|
Loading…
Reference in New Issue