diff --git a/migrations/Version20241114160014.php b/migrations/Version20241114160014.php deleted file mode 100644 index c219157..0000000 --- a/migrations/Version20241114160014.php +++ /dev/null @@ -1,52 +0,0 @@ -addSql('ALTER TABLE reservations DROP CONSTRAINT fk_4da2394de1870d'); - $this->addSql('DROP INDEX idx_4da2394de1870d'); - $this->addSql('ALTER TABLE reservations RENAME COLUMN tabl_id TO table_id'); - $this->addSql('ALTER TABLE reservations ADD CONSTRAINT FK_4DA239ECFF285C FOREIGN KEY (table_id) REFERENCES tables (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX IDX_4DA239ECFF285C ON reservations (table_id)'); - $this->addSql('ALTER TABLE statut_tables DROP CONSTRAINT fk_33c8a3754de1870d'); - $this->addSql('DROP INDEX idx_33c8a3754de1870d'); - $this->addSql('ALTER TABLE statut_tables RENAME COLUMN tabl_id TO table_id'); - $this->addSql('ALTER TABLE statut_tables ADD CONSTRAINT FK_33C8A375ECFF285C FOREIGN KEY (table_id) REFERENCES tables (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX IDX_33C8A375ECFF285C ON statut_tables (table_id)'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_497B315E5126AC48 ON utilisateurs (mail)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('DROP INDEX UNIQ_497B315E5126AC48'); - $this->addSql('ALTER TABLE statut_tables DROP CONSTRAINT FK_33C8A375ECFF285C'); - $this->addSql('DROP INDEX IDX_33C8A375ECFF285C'); - $this->addSql('ALTER TABLE statut_tables RENAME COLUMN table_id TO tabl_id'); - $this->addSql('ALTER TABLE statut_tables ADD CONSTRAINT fk_33c8a3754de1870d FOREIGN KEY (tabl_id) REFERENCES tables (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX idx_33c8a3754de1870d ON statut_tables (tabl_id)'); - $this->addSql('ALTER TABLE reservations DROP CONSTRAINT FK_4DA239ECFF285C'); - $this->addSql('DROP INDEX IDX_4DA239ECFF285C'); - $this->addSql('ALTER TABLE reservations RENAME COLUMN table_id TO tabl_id'); - $this->addSql('ALTER TABLE reservations ADD CONSTRAINT fk_4da2394de1870d FOREIGN KEY (tabl_id) REFERENCES tables (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX idx_4da2394de1870d ON reservations (tabl_id)'); - } -} diff --git a/migrations/Version20241114160729.php b/migrations/Version20241114160729.php deleted file mode 100644 index 8011f79..0000000 --- a/migrations/Version20241114160729.php +++ /dev/null @@ -1,50 +0,0 @@ -addSql('ALTER TABLE reservations DROP CONSTRAINT fk_4da239ecff285c'); - $this->addSql('DROP INDEX idx_4da239ecff285c'); - $this->addSql('ALTER TABLE reservations RENAME COLUMN table_id TO tables_id'); - $this->addSql('ALTER TABLE reservations ADD CONSTRAINT FK_4DA23985405FD2 FOREIGN KEY (tables_id) REFERENCES tables (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX IDX_4DA23985405FD2 ON reservations (tables_id)'); - $this->addSql('ALTER TABLE statut_tables DROP CONSTRAINT fk_33c8a375ecff285c'); - $this->addSql('DROP INDEX idx_33c8a375ecff285c'); - $this->addSql('ALTER TABLE statut_tables RENAME COLUMN table_id TO tables_id'); - $this->addSql('ALTER TABLE statut_tables ADD CONSTRAINT FK_33C8A37585405FD2 FOREIGN KEY (tables_id) REFERENCES tables (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX IDX_33C8A37585405FD2 ON statut_tables (tables_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE statut_tables DROP CONSTRAINT FK_33C8A37585405FD2'); - $this->addSql('DROP INDEX IDX_33C8A37585405FD2'); - $this->addSql('ALTER TABLE statut_tables RENAME COLUMN tables_id TO table_id'); - $this->addSql('ALTER TABLE statut_tables ADD CONSTRAINT fk_33c8a375ecff285c FOREIGN KEY (table_id) REFERENCES tables (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX idx_33c8a375ecff285c ON statut_tables (table_id)'); - $this->addSql('ALTER TABLE reservations DROP CONSTRAINT FK_4DA23985405FD2'); - $this->addSql('DROP INDEX IDX_4DA23985405FD2'); - $this->addSql('ALTER TABLE reservations RENAME COLUMN tables_id TO table_id'); - $this->addSql('ALTER TABLE reservations ADD CONSTRAINT fk_4da239ecff285c FOREIGN KEY (table_id) REFERENCES tables (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX idx_4da239ecff285c ON reservations (table_id)'); - } -} diff --git a/migrations/Version20241114164216.php b/migrations/Version20241114164216.php deleted file mode 100644 index 65df11e..0000000 --- a/migrations/Version20241114164216.php +++ /dev/null @@ -1,46 +0,0 @@ -addSql('CREATE TABLE tables_clients (tables_id INT NOT NULL, clients_id INT NOT NULL, PRIMARY KEY(tables_id, clients_id))'); - $this->addSql('CREATE INDEX IDX_80F8906E85405FD2 ON tables_clients (tables_id)'); - $this->addSql('CREATE INDEX IDX_80F8906EAB014612 ON tables_clients (clients_id)'); - $this->addSql('ALTER TABLE tables_clients ADD CONSTRAINT FK_80F8906E85405FD2 FOREIGN KEY (tables_id) REFERENCES tables (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE tables_clients ADD CONSTRAINT FK_80F8906EAB014612 FOREIGN KEY (clients_id) REFERENCES clients (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE clients_tables DROP CONSTRAINT fk_8190d6c6ab014612'); - $this->addSql('ALTER TABLE clients_tables DROP CONSTRAINT fk_8190d6c685405fd2'); - $this->addSql('DROP TABLE clients_tables'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('CREATE TABLE clients_tables (clients_id INT NOT NULL, tables_id INT NOT NULL, PRIMARY KEY(clients_id, tables_id))'); - $this->addSql('CREATE INDEX idx_8190d6c685405fd2 ON clients_tables (tables_id)'); - $this->addSql('CREATE INDEX idx_8190d6c6ab014612 ON clients_tables (clients_id)'); - $this->addSql('ALTER TABLE clients_tables ADD CONSTRAINT fk_8190d6c6ab014612 FOREIGN KEY (clients_id) REFERENCES clients (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE clients_tables ADD CONSTRAINT fk_8190d6c685405fd2 FOREIGN KEY (tables_id) REFERENCES tables (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE tables_clients DROP CONSTRAINT FK_80F8906E85405FD2'); - $this->addSql('ALTER TABLE tables_clients DROP CONSTRAINT FK_80F8906EAB014612'); - $this->addSql('DROP TABLE tables_clients'); - } -} diff --git a/src/Controller/TablesController.php b/src/Controller/TablesController.php index c1c834b..d22febe 100644 --- a/src/Controller/TablesController.php +++ b/src/Controller/TablesController.php @@ -72,4 +72,22 @@ final class TablesController extends AbstractController return $this->redirectToRoute('app_tables_index', [], Response::HTTP_SEE_OTHER); } + + #[Route('/update/statut/{id}', name: 'app_tables_update_statut', methods: ['POST'])] + public function update(Request $request, EntityManagerInterface $entityManager, $id): Response + { + $table = $entityManager->getRepository(Tables::class)->find($id); + + if (!$table) { + throw $this->createNotFoundException('Table not found'); + } + + $libre = $request->request->get('libre') === '1'; + $table->setLibre($libre); + + $entityManager->persist($table); + $entityManager->flush(); + + return $this->redirectToRoute('app_tables_index'); + } } diff --git a/src/Entity/Tables.php b/src/Entity/Tables.php index 1d1820a..762528e 100644 --- a/src/Entity/Tables.php +++ b/src/Entity/Tables.php @@ -36,9 +36,12 @@ class Tables /** * @var Collection */ - #[ORM\ManyToMany(targetEntity: Utilisateurs::class, mappedBy: 'tables')] + #[ORM\ManyToMany(targetEntity: Utilisateurs::class, inversedBy: 'tables')] private Collection $utilisateurs; + #[ORM\Column(type: 'boolean', options: ['default' => true])] + private ?bool $libre = null; + public function __construct() { $this->Clients = new ArrayCollection(); @@ -165,4 +168,16 @@ class Tables return $this; } + + public function isLibre(): ?bool + { + return $this->libre; + } + + public function setLibre(bool $libre): static + { + $this->libre = $libre; + + return $this; + } } diff --git a/src/Entity/Utilisateurs.php b/src/Entity/Utilisateurs.php index c9a6ead..987c637 100644 --- a/src/Entity/Utilisateurs.php +++ b/src/Entity/Utilisateurs.php @@ -41,7 +41,7 @@ class Utilisateurs implements UserInterface, PasswordAuthenticatedUserInterface /** * @var Collection */ - #[ORM\ManyToMany(targetEntity: Tables::class, inversedBy: 'utilisateurs')] + #[ORM\ManyToMany(targetEntity: Tables::class, mappedBy: 'utilisateurs')] private Collection $tables; public function __construct() diff --git a/src/Form/AddUserFormType.php b/src/Form/AddUserFormType.php index c017c3c..4c8b2bd 100644 --- a/src/Form/AddUserFormType.php +++ b/src/Form/AddUserFormType.php @@ -17,6 +17,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Form\CallbackTransformer; use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotBlank; +use function Sodium\add; class AddUserFormType extends AbstractType { @@ -48,6 +49,12 @@ class AddUserFormType extends AbstractType 'expanded' => true, 'multiple' => true, ]) + ->add('Tables', EntityType::class, [ + 'class' => Tables::class, + 'choice_label' => 'id', + 'multiple' => true, + 'expanded' => true, + ]) ->add('Enregistrer', SubmitType::class); } diff --git a/src/Form/TablesType.php b/src/Form/TablesType.php index f4a3d05..5f8e941 100644 --- a/src/Form/TablesType.php +++ b/src/Form/TablesType.php @@ -3,10 +3,12 @@ namespace App\Form; use App\Entity\Clients; +use App\Entity\StatutTables; use App\Entity\Tables; use App\Entity\Utilisateurs; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -21,12 +23,15 @@ class TablesType extends AbstractType 'multiple' => true, 'expanded' => true, ]) - ->add('utilisateurs', EntityType::class, [ + ->add('Utilisateurs', EntityType::class, [ 'class' => Utilisateurs::class, 'choice_label' => 'id', 'multiple' => true, 'expanded' => true, ]) + ->add('libre', HiddenType::class, [ + 'data' => true, + ]) ; } diff --git a/templates/tables/index.html.twig b/templates/tables/index.html.twig index a0af7b4..8d3e42a 100644 --- a/templates/tables/index.html.twig +++ b/templates/tables/index.html.twig @@ -22,33 +22,62 @@

Tables index

- +
- - + + + + + {% for table in tables %} + + + + + + + {% else %} - + {% endfor %}
IdactionsNuméro de TableClient AssignéUtilisateur AssignéLibre ?Actions
{{ table.id }} -
- - {{ include('tables/_delete_form.html.twig') }} + {% for client in table.Clients %} + {{ client.nom }}{% if not loop.last %}, {% endif %} + {% else %} + Aucun + {% endfor %} +
+ {% for utilisateur in table.utilisateurs %} + {{ utilisateur.nom }}{% if not loop.last %}, {% endif %} + {% else %} + Aucun + {% endfor %} + + + + + Modifier + +
+ + +
Aucun enregistrement trouvéAucun enregistrement trouvé
+ Créer une tables