From 8cbe57bd31df9320ff44e43f36d6121607950dd8 Mon Sep 17 00:00:00 2001 From: LouLocatex Date: Thu, 9 Jan 2025 09:22:39 +0400 Subject: [PATCH] mise en place des entity + mise en place du projet --- .env | 4 +- migrations/Version20250109052207.php | 47 +++++++++ src/Entity/Categorie.php | 78 +++++++++++++++ src/Entity/Menu.php | 102 ++++++++++++++++++++ src/Entity/Plat.php | 121 +++++++++++++++++++++++ src/Entity/Restaurant.php | 123 ++++++++++++++++++++++++ src/Repository/CategorieRepository.php | 43 +++++++++ src/Repository/MenuRepository.php | 43 +++++++++ src/Repository/PlatRepository.php | 43 +++++++++ src/Repository/RestaurantRepository.php | 43 +++++++++ 10 files changed, 645 insertions(+), 2 deletions(-) create mode 100644 migrations/Version20250109052207.php create mode 100644 src/Entity/Categorie.php create mode 100644 src/Entity/Menu.php create mode 100644 src/Entity/Plat.php create mode 100644 src/Entity/Restaurant.php create mode 100644 src/Repository/CategorieRepository.php create mode 100644 src/Repository/MenuRepository.php create mode 100644 src/Repository/PlatRepository.php create mode 100644 src/Repository/RestaurantRepository.php diff --git a/.env b/.env index 32ab3c6..a06b6b3 100644 --- a/.env +++ b/.env @@ -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 ### diff --git a/migrations/Version20250109052207.php b/migrations/Version20250109052207.php new file mode 100644 index 0000000..5786fb1 --- /dev/null +++ b/migrations/Version20250109052207.php @@ -0,0 +1,47 @@ +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'); + } +} diff --git a/src/Entity/Categorie.php b/src/Entity/Categorie.php new file mode 100644 index 0000000..7f7c5e3 --- /dev/null +++ b/src/Entity/Categorie.php @@ -0,0 +1,78 @@ + + */ + #[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 + */ + 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; + } +} diff --git a/src/Entity/Menu.php b/src/Entity/Menu.php new file mode 100644 index 0000000..0922772 --- /dev/null +++ b/src/Entity/Menu.php @@ -0,0 +1,102 @@ + + */ + #[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 + */ + 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; + } +} diff --git a/src/Entity/Plat.php b/src/Entity/Plat.php new file mode 100644 index 0000000..dfb78ce --- /dev/null +++ b/src/Entity/Plat.php @@ -0,0 +1,121 @@ + + */ + #[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 + */ + 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; + } +} diff --git a/src/Entity/Restaurant.php b/src/Entity/Restaurant.php new file mode 100644 index 0000000..dae213a --- /dev/null +++ b/src/Entity/Restaurant.php @@ -0,0 +1,123 @@ + + */ + #[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 + */ + 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; + } +} diff --git a/src/Repository/CategorieRepository.php b/src/Repository/CategorieRepository.php new file mode 100644 index 0000000..372a8b2 --- /dev/null +++ b/src/Repository/CategorieRepository.php @@ -0,0 +1,43 @@ + + */ +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() + // ; + // } +} diff --git a/src/Repository/MenuRepository.php b/src/Repository/MenuRepository.php new file mode 100644 index 0000000..f70d20e --- /dev/null +++ b/src/Repository/MenuRepository.php @@ -0,0 +1,43 @@ + + */ +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() + // ; + // } +} diff --git a/src/Repository/PlatRepository.php b/src/Repository/PlatRepository.php new file mode 100644 index 0000000..3db69ec --- /dev/null +++ b/src/Repository/PlatRepository.php @@ -0,0 +1,43 @@ + + */ +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() + // ; + // } +} diff --git a/src/Repository/RestaurantRepository.php b/src/Repository/RestaurantRepository.php new file mode 100644 index 0000000..cae2d2e --- /dev/null +++ b/src/Repository/RestaurantRepository.php @@ -0,0 +1,43 @@ + + */ +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() + // ; + // } +}