mise en place des entity + mise en place du projet

This commit is contained in:
LouLocatex
2025-01-09 09:22:39 +04:00
parent e05e389841
commit 8cbe57bd31
10 changed files with 645 additions and 2 deletions
+2 -2
View File
@@ -24,9 +24,9 @@ APP_SECRET=
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
DATABASE_URL="mysql://root:@127.0.0.1:3306/EXO_GDP?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
# DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###
###> symfony/messenger ###
+47
View File
@@ -0,0 +1,47 @@
<?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 Version20250109052207 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 menu (id INT AUTO_INCREMENT NOT NULL, restaurant_id INT DEFAULT NULL, nom VARCHAR(255) NOT NULL, date_de_creation DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_7D053A93B1E7706E (restaurant_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE menu_plat (menu_id INT NOT NULL, plat_id INT NOT NULL, INDEX IDX_E8775249CCD7E912 (menu_id), INDEX IDX_E8775249D73DB560 (plat_id), PRIMARY KEY(menu_id, plat_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE plat (id INT AUTO_INCREMENT NOT NULL, categorie_id INT DEFAULT NULL, nom VARCHAR(255) NOT NULL, description LONGTEXT NOT NULL, prix DOUBLE PRECISION NOT NULL, INDEX IDX_2038A207BCF5E72D (categorie_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE restaurant (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(255) NOT NULL, adresse VARCHAR(255) NOT NULL, telephone VARCHAR(255) NOT NULL, chef VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE menu ADD CONSTRAINT FK_7D053A93B1E7706E FOREIGN KEY (restaurant_id) REFERENCES restaurant (id)');
$this->addSql('ALTER TABLE menu_plat ADD CONSTRAINT FK_E8775249CCD7E912 FOREIGN KEY (menu_id) REFERENCES menu (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE menu_plat ADD CONSTRAINT FK_E8775249D73DB560 FOREIGN KEY (plat_id) REFERENCES plat (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE plat ADD CONSTRAINT FK_2038A207BCF5E72D FOREIGN KEY (categorie_id) REFERENCES categorie (id)');
$this->addSql('ALTER TABLE categorie ADD nom VARCHAR(255) NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE menu DROP FOREIGN KEY FK_7D053A93B1E7706E');
$this->addSql('ALTER TABLE menu_plat DROP FOREIGN KEY FK_E8775249CCD7E912');
$this->addSql('ALTER TABLE menu_plat DROP FOREIGN KEY FK_E8775249D73DB560');
$this->addSql('ALTER TABLE plat DROP FOREIGN KEY FK_2038A207BCF5E72D');
$this->addSql('DROP TABLE menu');
$this->addSql('DROP TABLE menu_plat');
$this->addSql('DROP TABLE plat');
$this->addSql('DROP TABLE restaurant');
$this->addSql('ALTER TABLE categorie DROP nom');
}
}
+78
View File
@@ -0,0 +1,78 @@
<?php
namespace App\Entity;
use App\Repository\CategorieRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CategorieRepository::class)]
class Categorie
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $nom = null;
/**
* @var Collection<int, Plat>
*/
#[ORM\OneToMany(targetEntity: Plat::class, mappedBy: 'categorie')]
private Collection $plats;
public function __construct()
{
$this->plats = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): static
{
$this->nom = $nom;
return $this;
}
/**
* @return Collection<int, Plat>
*/
public function getPlats(): Collection
{
return $this->plats;
}
public function addPlat(Plat $plat): static
{
if (!$this->plats->contains($plat)) {
$this->plats->add($plat);
$plat->setCategorie($this);
}
return $this;
}
public function removePlat(Plat $plat): static
{
if ($this->plats->removeElement($plat)) {
// set the owning side to null (unless already changed)
if ($plat->getCategorie() === $this) {
$plat->setCategorie(null);
}
}
return $this;
}
}
+102
View File
@@ -0,0 +1,102 @@
<?php
namespace App\Entity;
use App\Repository\MenuRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: MenuRepository::class)]
class Menu
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $nom = null;
#[ORM\Column]
private ?\DateTimeImmutable $dateDeCreation = null;
/**
* @var Collection<int, plat>
*/
#[ORM\ManyToMany(targetEntity: plat::class, inversedBy: 'menus')]
private Collection $plats;
#[ORM\ManyToOne(inversedBy: 'menus')]
private ?Restaurant $restaurant = null;
public function __construct()
{
$this->plats = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): static
{
$this->nom = $nom;
return $this;
}
public function getDateDeCreation(): ?\DateTimeImmutable
{
return $this->dateDeCreation;
}
public function setDateDeCreation(\DateTimeImmutable $dateDeCreation): static
{
$this->dateDeCreation = $dateDeCreation;
return $this;
}
/**
* @return Collection<int, plat>
*/
public function getPlats(): Collection
{
return $this->plats;
}
public function addPlat(plat $plat): static
{
if (!$this->plats->contains($plat)) {
$this->plats->add($plat);
}
return $this;
}
public function removePlat(plat $plat): static
{
$this->plats->removeElement($plat);
return $this;
}
public function getRestaurant(): ?Restaurant
{
return $this->restaurant;
}
public function setRestaurant(?Restaurant $restaurant): static
{
$this->restaurant = $restaurant;
return $this;
}
}
+121
View File
@@ -0,0 +1,121 @@
<?php
namespace App\Entity;
use App\Repository\PlatRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PlatRepository::class)]
class Plat
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $nom = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $description = null;
#[ORM\Column]
private ?float $prix = null;
#[ORM\ManyToOne(inversedBy: 'plats')]
private ?categorie $categorie = null;
/**
* @var Collection<int, Menu>
*/
#[ORM\ManyToMany(targetEntity: Menu::class, mappedBy: 'plats')]
private Collection $menus;
public function __construct()
{
$this->menus = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): static
{
$this->nom = $nom;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): static
{
$this->description = $description;
return $this;
}
public function getPrix(): ?float
{
return $this->prix;
}
public function setPrix(float $prix): static
{
$this->prix = $prix;
return $this;
}
public function getCategorie(): ?categorie
{
return $this->categorie;
}
public function setCategorie(?categorie $categorie): static
{
$this->categorie = $categorie;
return $this;
}
/**
* @return Collection<int, Menu>
*/
public function getMenus(): Collection
{
return $this->menus;
}
public function addMenu(Menu $menu): static
{
if (!$this->menus->contains($menu)) {
$this->menus->add($menu);
$menu->addPlat($this);
}
return $this;
}
public function removeMenu(Menu $menu): static
{
if ($this->menus->removeElement($menu)) {
$menu->removePlat($this);
}
return $this;
}
}
+123
View File
@@ -0,0 +1,123 @@
<?php
namespace App\Entity;
use App\Repository\RestaurantRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: RestaurantRepository::class)]
class Restaurant
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $nom = null;
#[ORM\Column(length: 255)]
private ?string $adresse = null;
#[ORM\Column(length: 255)]
private ?string $telephone = null;
#[ORM\Column(length: 255)]
private ?string $chef = null;
/**
* @var Collection<int, menu>
*/
#[ORM\OneToMany(targetEntity: menu::class, mappedBy: 'restaurant')]
private Collection $menus;
public function __construct()
{
$this->menus = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): static
{
$this->nom = $nom;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(string $adresse): static
{
$this->adresse = $adresse;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(string $telephone): static
{
$this->telephone = $telephone;
return $this;
}
public function getChef(): ?string
{
return $this->chef;
}
public function setChef(string $chef): static
{
$this->chef = $chef;
return $this;
}
/**
* @return Collection<int, menu>
*/
public function getMenus(): Collection
{
return $this->menus;
}
public function addMenu(menu $menu): static
{
if (!$this->menus->contains($menu)) {
$this->menus->add($menu);
$menu->setRestaurant($this);
}
return $this;
}
public function removeMenu(menu $menu): static
{
if ($this->menus->removeElement($menu)) {
// set the owning side to null (unless already changed)
if ($menu->getRestaurant() === $this) {
$menu->setRestaurant(null);
}
}
return $this;
}
}
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Categorie;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Categorie>
*/
class CategorieRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Categorie::class);
}
// /**
// * @return Categorie[] Returns an array of Categorie 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): ?Categorie
// {
// return $this->createQueryBuilder('c')
// ->andWhere('c.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Menu;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Menu>
*/
class MenuRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Menu::class);
}
// /**
// * @return Menu[] Returns an array of Menu objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('m')
// ->andWhere('m.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('m.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Menu
// {
// return $this->createQueryBuilder('m')
// ->andWhere('m.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Plat;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Plat>
*/
class PlatRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Plat::class);
}
// /**
// * @return Plat[] Returns an array of Plat objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('p.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Plat
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Restaurant;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Restaurant>
*/
class RestaurantRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Restaurant::class);
}
// /**
// * @return Restaurant[] Returns an array of Restaurant objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('r')
// ->andWhere('r.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('r.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Restaurant
// {
// return $this->createQueryBuilder('r')
// ->andWhere('r.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}