refs #723. First version commandGroup
parent
0219f28b5c
commit
05214bbd2e
|
@ -0,0 +1,37 @@
|
|||
<?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 Version20240916091601 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('CREATE TABLE command_group (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, position INT NOT NULL, name VARCHAR(255) NOT NULL, enabled TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_FE6811F6D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||
$this->addSql('CREATE TABLE command_group_command (command_group_id INT NOT NULL, command_id INT NOT NULL, INDEX IDX_118CE215C7B800D6 (command_group_id), INDEX IDX_118CE21533E1689A (command_id), PRIMARY KEY(command_group_id, command_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||
$this->addSql('ALTER TABLE command_group_command ADD CONSTRAINT FK_118CE215C7B800D6 FOREIGN KEY (command_group_id) REFERENCES command_group (id) ON DELETE CASCADE');
|
||||
$this->addSql('ALTER TABLE command_group_command ADD CONSTRAINT FK_118CE21533E1689A FOREIGN KEY (command_id) REFERENCES command (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_group_command DROP FOREIGN KEY FK_118CE215C7B800D6');
|
||||
$this->addSql('ALTER TABLE command_group_command DROP FOREIGN KEY FK_118CE21533E1689A');
|
||||
$this->addSql('DROP TABLE command_group');
|
||||
$this->addSql('DROP TABLE command_group_command');
|
||||
}
|
||||
}
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Entity;
|
||||
|
||||
use App\Repository\CommandRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: CommandRepository::class)]
|
||||
|
@ -20,9 +22,16 @@ class Command extends AbstractEntity
|
|||
#[ORM\Column]
|
||||
private ?bool $readOnly = null;
|
||||
|
||||
public function getId(): ?int
|
||||
/**
|
||||
* @var Collection<int, CommandGroup>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: CommandGroup::class, mappedBy: 'commands')]
|
||||
private Collection $commandGroups;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
return $this->id;
|
||||
parent::__construct();
|
||||
$this->commandGroups = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getScript(): ?string
|
||||
|
@ -60,4 +69,31 @@ class Command extends AbstractEntity
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, CommandGroup>
|
||||
*/
|
||||
public function getCommandGroups(): Collection
|
||||
{
|
||||
return $this->commandGroups;
|
||||
}
|
||||
|
||||
public function addCommandGroup(CommandGroup $commandGroup): static
|
||||
{
|
||||
if (!$this->commandGroups->contains($commandGroup)) {
|
||||
$this->commandGroups->add($commandGroup);
|
||||
$commandGroup->addCommand($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeCommandGroup(CommandGroup $commandGroup): static
|
||||
{
|
||||
if ($this->commandGroups->removeElement($commandGroup)) {
|
||||
$commandGroup->removeCommand($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\CommandGroupRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: CommandGroupRepository::class)]
|
||||
class CommandGroup extends AbstractEntity
|
||||
{
|
||||
use NameableTrait;
|
||||
use ToggleableTrait;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Command>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Command::class, inversedBy: 'commandGroups')]
|
||||
private Collection $commands;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $position = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->commands = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Command>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
public function getPosition(): ?int
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
public function setPosition(int $position): static
|
||||
{
|
||||
$this->position = $position;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\CommandGroup;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<CommandGroup>
|
||||
*/
|
||||
class CommandGroupRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, CommandGroup::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return CommandGroup[] Returns an array of CommandGroup 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): ?CommandGroup
|
||||
// {
|
||||
// return $this->createQueryBuilder('c')
|
||||
// ->andWhere('c.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
Loading…
Reference in New Issue