diff --git a/migrations/Version20240917064754.php b/migrations/Version20240917064754.php new file mode 100644 index 0000000..64f1f9b --- /dev/null +++ b/migrations/Version20240917064754.php @@ -0,0 +1,43 @@ +addSql('CREATE TABLE command_task (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, datetime DATETIME NOT NULL, notes VARCHAR(255) DEFAULT NULL, status VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_F3D475A8D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE command_task_command (command_task_id INT NOT NULL, command_id INT NOT NULL, INDEX IDX_BB417CA862DC5265 (command_task_id), INDEX IDX_BB417CA833E1689A (command_id), PRIMARY KEY(command_task_id, command_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE command_task_command_group (command_task_id INT NOT NULL, command_group_id INT NOT NULL, INDEX IDX_C43618BD62DC5265 (command_task_id), INDEX IDX_C43618BDC7B800D6 (command_group_id), PRIMARY KEY(command_task_id, command_group_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE command_task_command ADD CONSTRAINT FK_BB417CA862DC5265 FOREIGN KEY (command_task_id) REFERENCES command_task (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE command_task_command ADD CONSTRAINT FK_BB417CA833E1689A FOREIGN KEY (command_id) REFERENCES command (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE command_task_command_group ADD CONSTRAINT FK_C43618BD62DC5265 FOREIGN KEY (command_task_id) REFERENCES command_task (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE command_task_command_group ADD CONSTRAINT FK_C43618BDC7B800D6 FOREIGN KEY (command_group_id) REFERENCES command_group (id) ON DELETE CASCADE'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE command_task_command DROP FOREIGN KEY FK_BB417CA862DC5265'); + $this->addSql('ALTER TABLE command_task_command DROP FOREIGN KEY FK_BB417CA833E1689A'); + $this->addSql('ALTER TABLE command_task_command_group DROP FOREIGN KEY FK_C43618BD62DC5265'); + $this->addSql('ALTER TABLE command_task_command_group DROP FOREIGN KEY FK_C43618BDC7B800D6'); + $this->addSql('DROP TABLE command_task'); + $this->addSql('DROP TABLE command_task_command'); + $this->addSql('DROP TABLE command_task_command_group'); + } +} diff --git a/src/Entity/Command.php b/src/Entity/Command.php index 97964f2..14e485e 100644 --- a/src/Entity/Command.php +++ b/src/Entity/Command.php @@ -28,10 +28,17 @@ class Command extends AbstractEntity #[ORM\ManyToMany(targetEntity: CommandGroup::class, mappedBy: 'commands')] private Collection $commandGroups; + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: CommandTask::class, mappedBy: 'command')] + private Collection $commandTasks; + public function __construct() { parent::__construct(); $this->commandGroups = new ArrayCollection(); + $this->commandTasks = new ArrayCollection(); } public function getScript(): ?string @@ -96,4 +103,31 @@ class Command extends AbstractEntity return $this; } + + /** + * @return Collection + */ + public function getCommandTasks(): Collection + { + return $this->commandTasks; + } + + public function addCommandTask(CommandTask $commandTask): static + { + if (!$this->commandTasks->contains($commandTask)) { + $this->commandTasks->add($commandTask); + $commandTask->addCommand($this); + } + + return $this; + } + + public function removeCommandTask(CommandTask $commandTask): static + { + if ($this->commandTasks->removeElement($commandTask)) { + $commandTask->removeCommand($this); + } + + return $this; + } } diff --git a/src/Entity/CommandGroup.php b/src/Entity/CommandGroup.php index f0061c3..30befcb 100644 --- a/src/Entity/CommandGroup.php +++ b/src/Entity/CommandGroup.php @@ -22,10 +22,17 @@ class CommandGroup extends AbstractEntity #[ORM\Column] private ?int $position = null; + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: CommandTask::class, mappedBy: 'commandGroup')] + private Collection $commandTasks; + public function __construct() { parent::__construct(); $this->commands = new ArrayCollection(); + $this->commandTasks = new ArrayCollection(); } /** @@ -75,4 +82,31 @@ class CommandGroup extends AbstractEntity return $this; } + + /** + * @return Collection + */ + public function getCommandTasks(): Collection + { + return $this->commandTasks; + } + + public function addCommandTask(CommandTask $commandTask): static + { + if (!$this->commandTasks->contains($commandTask)) { + $this->commandTasks->add($commandTask); + $commandTask->addCommandGroup($this); + } + + return $this; + } + + public function removeCommandTask(CommandTask $commandTask): static + { + if ($this->commandTasks->removeElement($commandTask)) { + $commandTask->removeCommandGroup($this); + } + + return $this; + } } diff --git a/src/Entity/CommandTask.php b/src/Entity/CommandTask.php new file mode 100644 index 0000000..3684eb4 --- /dev/null +++ b/src/Entity/CommandTask.php @@ -0,0 +1,126 @@ + + */ + #[ORM\ManyToMany(targetEntity: Command::class, inversedBy: 'commandTasks')] + private Collection $commands; + + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: CommandGroup::class, inversedBy: 'commandTasks')] + private Collection $commandGroups; + + #[ORM\Column(type: Types::DATETIME_MUTABLE)] + private ?\DateTimeInterface $datetime = null; + + #[ORM\Column(length: 255, nullable: true)] + private ?string $notes = null; + + #[ORM\Column(length: 255)] + private ?string $status = null; + + public function __construct() + { + parent::__construct(); + + $this->commands = new ArrayCollection(); + $this->commandGroups = new ArrayCollection(); + } + + /** + * @return Collection + */ + public function getCommands(): Collection + { + return $this->commands; + } + + public function addCommand(Command $command): static + { + if (!$this->commands->contains($command)) { + $this->commands->add($command); + } + + return $this; + } + + public function removeCommand(Command $command): static + { + $this->commands->removeElement($command); + + return $this; + } + + /** + * @return Collection + */ + public function getCommandGroups(): Collection + { + return $this->commandGroups; + } + + public function addCommandGroup(CommandGroup $commandGroup): static + { + if (!$this->commandGroups->contains($commandGroup)) { + $this->commandGroups->add($commandGroup); + } + + return $this; + } + + public function removeCommandGroup(CommandGroup $commandGroup): static + { + $this->commandGroups->removeElement($commandGroup); + + return $this; + } + + public function getDatetime(): ?\DateTimeInterface + { + return $this->datetime; + } + + public function setDatetime(\DateTimeInterface $datetime): static + { + $this->datetime = $datetime; + + return $this; + } + + public function getNotes(): ?string + { + return $this->notes; + } + + public function setNotes(?string $notes): static + { + $this->notes = $notes; + + return $this; + } + + public function getStatus(): ?string + { + return $this->status; + } + + public function setStatus(string $status): static + { + $this->status = $status; + + return $this; + } +} diff --git a/src/Model/CommandTaskStatus.php b/src/Model/CommandTaskStatus.php new file mode 100644 index 0000000..9c1cab1 --- /dev/null +++ b/src/Model/CommandTaskStatus.php @@ -0,0 +1,33 @@ + 'Pendiente', + self::IN_PROGRESS => 'En progreso', + self::COMPLETED => 'Completado', + self::FAILED => 'Fallido', + ]; + + public static function getStatus(): array + { + return self::STATUS; + } + + public static function getCommandTaskStatus(string $status): ?string + { + return self::STATUS[$status] ?? null; + } + + public static function getStatusKeys(): array + { + return array_keys(self::STATUS); + } +} \ No newline at end of file diff --git a/src/Repository/CommandTaskRepository.php b/src/Repository/CommandTaskRepository.php new file mode 100644 index 0000000..e7b8cf7 --- /dev/null +++ b/src/Repository/CommandTaskRepository.php @@ -0,0 +1,43 @@ + + */ +class CommandTaskRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, CommandTask::class); + } + + // /** + // * @return CommandTask[] Returns an array of CommandTask objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('c') + // ->andWhere('c.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('c.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?CommandTask + // { + // return $this->createQueryBuilder('c') + // ->andWhere('c.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +}