Mise a jour de la section tables(Ajout des User, Client et Statut) , correction de la base (relation Table_utilisateurs) et rajout de css et quelques fonctions pratique

This commit is contained in:
Joshua 2025-04-03 17:08:35 +02:00
parent 0e5fb02d64
commit 41798397d3
9 changed files with 84 additions and 158 deletions

@ -1,52 +0,0 @@
<?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 Version20241114160014 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('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)');
}
}

@ -1,50 +0,0 @@
<?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 Version20241114160729 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('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)');
}
}

@ -1,46 +0,0 @@
<?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 Version20241114164216 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 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');
}
}

@ -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');
}
}

@ -36,9 +36,12 @@ class Tables
/**
* @var Collection<int, Utilisateurs>
*/
#[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;
}
}

@ -41,7 +41,7 @@ class Utilisateurs implements UserInterface, PasswordAuthenticatedUserInterface
/**
* @var Collection<int, Tables>
*/
#[ORM\ManyToMany(targetEntity: Tables::class, inversedBy: 'utilisateurs')]
#[ORM\ManyToMany(targetEntity: Tables::class, mappedBy: 'utilisateurs')]
private Collection $tables;
public function __construct()

@ -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);
}

@ -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,
])
;
}

@ -22,33 +22,62 @@
<div id="container_modal">
<h1>Tables index</h1>
<table class="table">
<table>
<thead>
<tr>
<th>Id</th>
<th>actions</th>
<th>Numéro de Table</th>
<th>Client Assigné</th>
<th>Utilisateur Assigné</th>
<th>Libre ?</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for table in tables %}
<tr>
<td>{{ table.id }}</td>
<td>
<form method="post" action="{{ path('app_tables_delete', {'id': table.id}) }}" onsubmit="return confirm('Es-tu sur de vouloir le supprimer ?');">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ table.id) }}">
{{ include('tables/_delete_form.html.twig') }}
{% for client in table.Clients %}
{{ client.nom }}{% if not loop.last %}, {% endif %}
{% else %}
Aucun
{% endfor %}
</td>
<td>
{% for utilisateur in table.utilisateurs %}
{{ utilisateur.nom }}{% if not loop.last %}, {% endif %}
{% else %}
Aucun
{% endfor %}
</td>
<td>
<form method="POST" action="{{ path('app_tables_update_statut', {'id': table.id}) }}">
<input type="checkbox" name="libre" value="1" {% if table.libre %}checked{% endif %}>
<button type="submit">Mettre à jour</button>
</form>
</td>
<td>
<a href="{{ path('app_tables_edit', {'id': table.id}) }}">Modifier</a>
<form method="post" action="{{ path('app_tables_delete', {'id': table.id}) }}" onsubmit="return confirm('Es-tu sûr de vouloir le supprimer ?');" style="display:inline;">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ table.id) }}">
<button type="submit">Supprimer</button>
</form>
</td>
</tr>
{% else %}
<tr>
<td colspan="2">Aucun enregistrement trouvé</td>
<td colspan="5">Aucun enregistrement trouvé</td>
</tr>
{% endfor %}
</tbody>
</table>
<a onclick="addTable(this)" href="{{ path('app_tables_new')}}">Créer une tables</a>
</div>