diff --git a/composer.json b/composer.json index 30f24ad..f7de482 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "symfony/mime": "5.3.*", "symfony/monolog-bundle": "^3.1", "symfony/notifier": "5.3.*", + "symfony/polyfill-intl-messageformatter": "^1.23", "symfony/process": "5.3.*", "symfony/property-access": "5.3.*", "symfony/property-info": "5.3.*", diff --git a/composer.lock b/composer.lock index 390ac10..c4cf603 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "175432fded863dfe3a648f350fb0e1f8", + "content-hash": "d42139fe22addc9e70ea4697931bd5da", "packages": [ { "name": "composer/package-versions-deprecated", @@ -5021,6 +5021,90 @@ ], "time": "2021-05-27T09:27:20+00:00" }, + { + "name": "symfony/polyfill-intl-messageformatter", + "version": "v1.23.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-messageformatter.git", + "reference": "22c4bba53bfadde90a4c1b32088e720638a42a83" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-messageformatter/zipball/22c4bba53bfadde90a4c1b32088e720638a42a83", + "reference": "22c4bba53bfadde90a4c1b32088e720638a42a83", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Intl\\MessageFormatter\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's MessageFormatter class and related functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "intl", + "messageformatter", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-messageformatter/tree/v1.23.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-02-19T12:13:01+00:00" + }, { "name": "symfony/polyfill-intl-normalizer", "version": "v1.23.0", diff --git a/config/packages/translation.yaml b/config/packages/translation.yaml index abb76aa..6ebae5e 100644 --- a/config/packages/translation.yaml +++ b/config/packages/translation.yaml @@ -1,5 +1,5 @@ framework: - default_locale: en + default_locale: fr translator: default_path: '%kernel.project_dir%/translations' fallbacks: diff --git a/docker-compose.yaml b/docker-compose.yaml index 48bedf1..f996034 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,14 +1,26 @@ version: '3.7' services: - database: - image: 'postgres:alpine' - environment: - POSTGRES_PASSWORD: main - POSTGRES_USER: main - POSTGRES_DB: main + apache-php74: + build: + context: docker/apache + depends_on: + - mysql57 + volumes: + - type: bind + source: . + target: /var/www/html/ + ports: + - 8080:80 + + mysql57: + build: + context: docker/mysql + volumes: + - ~/Projects/tmp/mysql57_dblemenu:/var/lib/mysql + - ./docker/mysql/config:/etc/mysql/conf.d ports: - # To allow the host machine to access the ports below, modify the lines below. - # For example, to allow the host to connect to port 3306 on the container, you would change - # "3306" to "3306:3306". Where the first port is exposed to the host and the second is the container port. - # See https://docs.docker.com/compose/compose-file/#ports for more information. - - '5432:5432' + - "3307:3306" + environment: + - MYSQL_ROOT_PASSWORD=root + +#https://stackoverflow.com/questions/38088279/communication-between-multiple-docker-compose-projects diff --git a/docker/README b/docker/README new file mode 100644 index 0000000..c530355 --- /dev/null +++ b/docker/README @@ -0,0 +1,3 @@ +https://github.com/Oipnet/Docker-compose-apache-php_fpm + +Organisation pas degeu \ No newline at end of file diff --git a/docker/apache/Dockerfile b/docker/apache/Dockerfile new file mode 100644 index 0000000..54bdbe3 --- /dev/null +++ b/docker/apache/Dockerfile @@ -0,0 +1,23 @@ +FROM php:7.4-apache + +RUN apt update && apt install -y zip unzip libzip-dev zlib1g-dev libsodium-dev libonig-dev +RUN docker-php-ext-install -j$(nproc) mbstring bcmath zip sodium json opcache mysqli pdo pdo_mysql + +ADD sites-available /etc/apache2/sites-available + +WORKDIR /var/www/html + +ENV TZ=UTC +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +RUN a2ensite 999-gryapi +RUN a2dissite 000-default +RUN a2dissite default-ssl +#RUN /usr/sbin/apache2ctl -D FOREGROUND +RUN a2enmod rewrite +RUN service apache2 restart + +RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/20-xdebug.ini +RUN echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/20-xdebug.ini + +EXPOSE 80 \ No newline at end of file diff --git a/docker/apache/sites-available/999-gryapi.conf b/docker/apache/sites-available/999-gryapi.conf new file mode 100644 index 0000000..62dc170 --- /dev/null +++ b/docker/apache/sites-available/999-gryapi.conf @@ -0,0 +1,54 @@ +ServerName le-menu.local + + + ServerName le-menu.local + ServerAlias www.le-menu.local + # The ServerName directive sets the request scheme, hostname and port that the server uses to identify itself. + # This is used when creating redirection URLs. In the context of virtual hosts, the ServerName specifies what + # hostname must appear in the request's Host: header to match this virtual host. For the default virtual host + # (this file) this value is not decisive as it is used as a last resort host regardless. However, you must set + # it for any further virtual host explicitly. + + ServerAdmin webmaster@localhost + DocumentRoot /var/www/html/public/ + + DirectoryIndex /index.php + + + AllowOverride None + Order Allow,Deny + Allow from All + + FallbackResource /index.php + + + # uncomment the following lines if you install assets as symlinks + # or run into problems when compiling LESS/Sass/CoffeeScript assets + # + # Options FollowSymlinks + # + + # optionally disable the fallback resource for the asset directories + # which will allow Apache to return a 404 error when files are + # not found instead of passing the request to Symfony + + DirectoryIndex disabled + FallbackResource disabled + + ErrorLog /var/log/apache2/project_error.log + CustomLog /var/log/apache2/project_access.log combined + + # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, error, crit, alert, emerg. It is also + #possible to configure the loglevel for particular modules, e.g. LogLevel info ssl:warn + ErrorLog ${APACHE_LOG_DIR}/error-lemenu.log + CustomLog ${APACHE_LOG_DIR}/access-lemenu.log combined + # For most configuration files from conf-available/, which are enabled or disabled at a global level, it 1is + #possible to include a line for only one particular virtual host. For example the following line enables the CGI + #configuration for this host only after it has been globally disabled with "a2disconf". Include + #conf-available/serve-cgi-bin.conf + + # optionally set the value of the environment variables used in the application + #SetEnv APP_ENV prod + #SetEnv APP_SECRET + #SetEnv DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name" + \ No newline at end of file diff --git a/docker/mysql/Dockerfile b/docker/mysql/Dockerfile new file mode 100644 index 0000000..30d16c5 --- /dev/null +++ b/docker/mysql/Dockerfile @@ -0,0 +1 @@ +FROM mysql:5.7 \ No newline at end of file diff --git a/docker/mysql/config/myCustomConf.cnf b/docker/mysql/config/myCustomConf.cnf new file mode 100644 index 0000000..e549d2a --- /dev/null +++ b/docker/mysql/config/myCustomConf.cnf @@ -0,0 +1,3 @@ +[mysqld] +sql-mode='ANSI,TRADITIONAL' +# TRADITIONAL is equivalent to STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, and NO_ENGINE_SUBSTITUTION. \ No newline at end of file diff --git a/migrations/Version20210722151853.php b/migrations/Version20210722151853.php new file mode 100644 index 0000000..5778880 --- /dev/null +++ b/migrations/Version20210722151853.php @@ -0,0 +1,71 @@ +addSql('CREATE TABLE ingredient (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE ingredient_tag (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE ingredient_tag_ingredient (ingredient_tag_id INT NOT NULL, ingredient_id INT NOT NULL, INDEX IDX_A003A3A056A8A350 (ingredient_tag_id), INDEX IDX_A003A3A0933FE08C (ingredient_id), PRIMARY KEY(ingredient_tag_id, ingredient_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE menu (id INT AUTO_INCREMENT NOT NULL, restaurant_id INT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, activate TINYINT(1) NOT NULL, INDEX IDX_7D053A93B1E7706E (restaurant_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE menu_item (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, price DOUBLE PRECISION UNSIGNED DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE menu_item_ingredient (menu_item_id INT NOT NULL, ingredient_id INT NOT NULL, INDEX IDX_EA047E5E9AB44FE0 (menu_item_id), INDEX IDX_EA047E5E933FE08C (ingredient_id), PRIMARY KEY(menu_item_id, ingredient_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE menu_item_tag (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE menu_item_tag_menu_item (menu_item_tag_id INT NOT NULL, menu_item_id INT NOT NULL, INDEX IDX_E3EE59FA54D70892 (menu_item_tag_id), INDEX IDX_E3EE59FA9AB44FE0 (menu_item_id), PRIMARY KEY(menu_item_tag_id, menu_item_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE menu_section (id INT AUTO_INCREMENT NOT NULL, menu_section_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, price DOUBLE PRECISION UNSIGNED DEFAULT NULL, INDEX IDX_A5A86751F98E57A8 (menu_section_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE menu_section_menu_item (menu_section_id INT NOT NULL, menu_item_id INT NOT NULL, INDEX IDX_982775A6F98E57A8 (menu_section_id), INDEX IDX_982775A69AB44FE0 (menu_item_id), PRIMARY KEY(menu_section_id, menu_item_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE restaurant (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, currency VARCHAR(5) DEFAULT \'EUR\' NOT NULL, activate TINYINT(1) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE ingredient_tag_ingredient ADD CONSTRAINT FK_A003A3A056A8A350 FOREIGN KEY (ingredient_tag_id) REFERENCES ingredient_tag (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE ingredient_tag_ingredient ADD CONSTRAINT FK_A003A3A0933FE08C FOREIGN KEY (ingredient_id) REFERENCES ingredient (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE menu ADD CONSTRAINT FK_7D053A93B1E7706E FOREIGN KEY (restaurant_id) REFERENCES restaurant (id)'); + $this->addSql('ALTER TABLE menu_item_ingredient ADD CONSTRAINT FK_EA047E5E9AB44FE0 FOREIGN KEY (menu_item_id) REFERENCES menu_item (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE menu_item_ingredient ADD CONSTRAINT FK_EA047E5E933FE08C FOREIGN KEY (ingredient_id) REFERENCES ingredient (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE menu_item_tag_menu_item ADD CONSTRAINT FK_E3EE59FA54D70892 FOREIGN KEY (menu_item_tag_id) REFERENCES menu_item_tag (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE menu_item_tag_menu_item ADD CONSTRAINT FK_E3EE59FA9AB44FE0 FOREIGN KEY (menu_item_id) REFERENCES menu_item (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE menu_section ADD CONSTRAINT FK_A5A86751F98E57A8 FOREIGN KEY (menu_section_id) REFERENCES menu_section (id)'); + $this->addSql('ALTER TABLE menu_section_menu_item ADD CONSTRAINT FK_982775A6F98E57A8 FOREIGN KEY (menu_section_id) REFERENCES menu_section (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE menu_section_menu_item ADD CONSTRAINT FK_982775A69AB44FE0 FOREIGN KEY (menu_item_id) REFERENCES menu_item (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 ingredient_tag_ingredient DROP FOREIGN KEY FK_A003A3A0933FE08C'); + $this->addSql('ALTER TABLE menu_item_ingredient DROP FOREIGN KEY FK_EA047E5E933FE08C'); + $this->addSql('ALTER TABLE ingredient_tag_ingredient DROP FOREIGN KEY FK_A003A3A056A8A350'); + $this->addSql('ALTER TABLE menu_item_ingredient DROP FOREIGN KEY FK_EA047E5E9AB44FE0'); + $this->addSql('ALTER TABLE menu_item_tag_menu_item DROP FOREIGN KEY FK_E3EE59FA9AB44FE0'); + $this->addSql('ALTER TABLE menu_section_menu_item DROP FOREIGN KEY FK_982775A69AB44FE0'); + $this->addSql('ALTER TABLE menu_item_tag_menu_item DROP FOREIGN KEY FK_E3EE59FA54D70892'); + $this->addSql('ALTER TABLE menu_section DROP FOREIGN KEY FK_A5A86751F98E57A8'); + $this->addSql('ALTER TABLE menu_section_menu_item DROP FOREIGN KEY FK_982775A6F98E57A8'); + $this->addSql('ALTER TABLE menu DROP FOREIGN KEY FK_7D053A93B1E7706E'); + $this->addSql('DROP TABLE ingredient'); + $this->addSql('DROP TABLE ingredient_tag'); + $this->addSql('DROP TABLE ingredient_tag_ingredient'); + $this->addSql('DROP TABLE menu'); + $this->addSql('DROP TABLE menu_item'); + $this->addSql('DROP TABLE menu_item_ingredient'); + $this->addSql('DROP TABLE menu_item_tag'); + $this->addSql('DROP TABLE menu_item_tag_menu_item'); + $this->addSql('DROP TABLE menu_section'); + $this->addSql('DROP TABLE menu_section_menu_item'); + $this->addSql('DROP TABLE restaurant'); + } +} diff --git a/migrations/Version20210722220605.php b/migrations/Version20210722220605.php new file mode 100644 index 0000000..9fb5b2e --- /dev/null +++ b/migrations/Version20210722220605.php @@ -0,0 +1,33 @@ +addSql('CREATE TABLE menu_menu_section (menu_id INT NOT NULL, menu_section_id INT NOT NULL, INDEX IDX_DAAA96F4CCD7E912 (menu_id), INDEX IDX_DAAA96F4F98E57A8 (menu_section_id), PRIMARY KEY(menu_id, menu_section_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE menu_menu_section ADD CONSTRAINT FK_DAAA96F4CCD7E912 FOREIGN KEY (menu_id) REFERENCES menu (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE menu_menu_section ADD CONSTRAINT FK_DAAA96F4F98E57A8 FOREIGN KEY (menu_section_id) REFERENCES menu_section (id) ON DELETE CASCADE'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE menu_menu_section'); + } +} diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..89195e2 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,19 @@ + + + + + + + + + + + + bin/ + config/ + public/ + src/ + tests/ + + diff --git a/src/Controller/RoutingController.php b/src/Controller/RoutingController.php index d83283f..a2e988f 100644 --- a/src/Controller/RoutingController.php +++ b/src/Controller/RoutingController.php @@ -3,10 +3,7 @@ namespace App\Controller; -use App\DTO\Menu; -use App\DTO\MenuItem; -use App\DTO\MenuSection; -use App\DTO\Restaurant; +use App\Entity\Restaurant; use App\Form\PropertySearchType; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; @@ -21,53 +18,18 @@ public function __construct() } /** - * @Route("{restaurantName}", name="restaurantDesc") + * @Route("{restaurantName}", name="restaurant") * @param Environment $twig * @return Response * @throws \Twig\Error\LoaderError * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError */ - public function restaurantPage(Environment $twig) { + public function restaurantPage(string $restaurantName, Environment $twig) { - $restaurant = new Restaurant(); - $restaurant->name = 'Le BÔ$phɵǒrœ ȘỚỸßØå'; + $restaurantRepo = $this->getDoctrine()->getRepository(Restaurant::class); - $menu = new Menu(); - $menu->name = "Menu 12/03"; - $menu->hasMenuItem = []; - - $menuSection = new MenuSection(); - $menuSection->name = 'Coucou'; - - $menuSection2 = new MenuSection(); - $menuSection2->name = 'Coucou 2'; - $menuSection2->hasMenuSection = []; - - - $menuSection2_1 = new MenuSection(); - $menuSection2_1->name = 'Coucou 2-1'; - $menuSection2_1->hasMenuItem = []; - - $menuItem = new MenuItem(); - $menuItem->name = "Kebab"; - $menuItem->description = "De la viande Hallal"; - - $menuItem2 = new MenuItem(); - $menuItem2->name = "KPop"; - $menuItem2->description = "Viande Coreene"; - - $menuSection2->hasMenuItem[] = $menuItem2; - - $menuSection2_1->hasMenuItem[] = $menuItem; - - $menuSection2->hasMenuSection[] = $menuSection2_1; - - - $restaurant->hasMenu = $menu; - $menu->hasMenuSection[] = $menuSection; - $menu->hasMenuSection[] = $menuSection2; - $menu->hasMenuSection[] = new MenuSection(); + $restaurant = $restaurantRepo->findOneBy(['id' => 1]); $content = $twig->render('restaurant.html.twig', [ @@ -85,16 +47,11 @@ public function restaurantPage(Environment $twig) { * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError */ - public function menuList(Environment $twig) { + public function menuList(string $restaurantName, Environment $twig) { - $restaurant = new Restaurant(); - $restaurant->name = 'Le BÔ$phɵrœ'; + $restaurantRepo = $this->getDoctrine()->getRepository(Restaurant::class); - $menu = new Menu(); - $menu->name = "Menu 12/03"; - $menu->hasMenuItem = []; - - $restaurant->hasMenu = [$menu]; + $restaurant = $restaurantRepo->findOneBy(['id' => 1]); $content = $twig->render('menuList.html.twig', [ @@ -113,51 +70,17 @@ public function menuList(Environment $twig) { * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError */ - public function menuPage(Environment $twig) { - - $restaurant = new Restaurant(); - $restaurant->name = 'MacDo'; - - $menu = new Menu(); - $menu->name = "Produits"; - $menu->hasMenuItem = []; - - $menuSection = new MenuSection(); - $menuSection->name = 'Des trucs'; - - $menuSection2 = new MenuSection(); - $menuSection2->name = 'Nos Menus'; - $menuSection2->description = ''; - $menuSection2->hasMenuSection = []; - - - $menuSection2_1 = new MenuSection(); - $menuSection2_1->name = 'Le Menu Maxi BEST OF'; - $menuSection2_1->description = '1 sandwich + 1 frites - + 1 bouteille'; - $menuSection2_1->price = 10.0; - $menuSection2_1->hasMenuItem = []; - - $menuItem = new MenuItem(); - $menuItem->name = "Texas Cheese 🍕"; - $menuItem->description = "Sauce Tomate, Mozzarella, Chorizo, Fromage de chèvre, Tomates fraîches"; - - $menuItem2 = new MenuItem(); - $menuItem2->name = "Harlem Margherita"; - $menuItem2->description = "Sauce Tomate, Mozzarella"; - $menuItem2->price = 12.5; - - $menuSection2->hasMenuItem[] = $menuItem2; + public function menuPage(string $restaurantName, string $menuName, Environment $twig) { - $menuSection2_1->hasMenuItem[] = $menuItem; - $menuSection2->hasMenuSection[] = $menuSection2_1; + $restaurantRepo = $this->getDoctrine()->getRepository(Restaurant::class); + $restaurant = $restaurantRepo->findOneBy(['id' => 1]); + $menus = $restaurant->getHasMenu(); + foreach ($menus as $menu) { + $menuSection = $menu->getHasMenuSection(); + } - $restaurant->hasMenu = [$menu]; - $menu->hasMenuSection[] = $menuSection; - $menu->hasMenuSection[] = $menuSection2; - $menu->hasMenuSection[] = new MenuSection(); $form = $this->createForm(PropertySearchType::class, []); diff --git a/src/Entity/Menu.php b/src/Entity/Menu.php index a1ebc4d..0b57eab 100644 --- a/src/Entity/Menu.php +++ b/src/Entity/Menu.php @@ -3,6 +3,8 @@ namespace App\Entity; use App\Repository\MenuRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** @@ -38,6 +40,16 @@ class Menu */ private $activate = true; + /** + * @ORM\ManyToMany(targetEntity=MenuSection::class, inversedBy="menus") + */ + private $hasMenuSection; + + public function __construct() + { + $this->hasMenuSection = new ArrayCollection(); + } + public function getId(): ?int { return $this->id; @@ -90,4 +102,28 @@ public function setActivate(bool $activate): self return $this; } + + /** + * @return Collection|MenuSection[] + */ + public function getHasMenuSection(): Collection + { + return $this->hasMenuSection; + } + + public function addHasMenuSection(MenuSection $hasMenuSection): self + { + if (!$this->hasMenuSection->contains($hasMenuSection)) { + $this->hasMenuSection[] = $hasMenuSection; + } + + return $this; + } + + public function removeHasMenuSection(MenuSection $hasMenuSection): self + { + $this->hasMenuSection->removeElement($hasMenuSection); + + return $this; + } } diff --git a/src/Entity/MenuItem.php b/src/Entity/MenuItem.php index 228d04f..d4af916 100644 --- a/src/Entity/MenuItem.php +++ b/src/Entity/MenuItem.php @@ -37,12 +37,12 @@ class MenuItem /** * @ORM\ManyToMany(targetEntity=MenuSection::class, mappedBy="hasMenuItem") */ - private ArrayCollection $menuSections; + private $menuSections; /** * @ORM\ManyToMany(targetEntity=MenuItemTag::class, mappedBy="attach") */ - private ArrayCollection $menuItemTags; + private $menuItemTags; /** * @ORM\ManyToMany(targetEntity=Ingredient::class, inversedBy="menuItems") diff --git a/src/Entity/MenuSection.php b/src/Entity/MenuSection.php index cb89b4e..e6a37be 100644 --- a/src/Entity/MenuSection.php +++ b/src/Entity/MenuSection.php @@ -33,27 +33,33 @@ class MenuSection /** * @ORM\Column(type="float", nullable=true, options={"unsigned"=true}) */ - private float $price = 0.0; + private ?float $price = 0.0; /** * @ORM\ManyToOne(targetEntity=MenuSection::class, inversedBy="hasMenuSection") */ - private ArrayCollection $menuSection; + private $menuSection; /** * @ORM\OneToMany(targetEntity=MenuSection::class, mappedBy="menuSection") */ - private ArrayCollection $hasMenuSection; + private $hasMenuSection; /** * @ORM\ManyToMany(targetEntity=MenuItem::class, inversedBy="menuSections") */ - private ArrayCollection $hasMenuItem; + private $hasMenuItem; + + /** + * @ORM\ManyToMany(targetEntity=Menu::class, mappedBy="hasMenuSection") + */ + private $menus; public function __construct() { $this->hasMenuSection = new ArrayCollection(); $this->hasMenuItem = new ArrayCollection(); + $this->menus = new ArrayCollection(); } public function getId(): ?int @@ -162,4 +168,31 @@ public function removeHasMenuItem(MenuItem $hasMenuItem): self return $this; } + + /** + * @return Collection|Menu[] + */ + public function getMenus(): Collection + { + return $this->menus; + } + + public function addMenu(Menu $menu): self + { + if (!$this->menus->contains($menu)) { + $this->menus[] = $menu; + $menu->addHasMenuSection($this); + } + + return $this; + } + + public function removeMenu(Menu $menu): self + { + if ($this->menus->removeElement($menu)) { + $menu->removeHasMenuSection($this); + } + + return $this; + } } diff --git a/src/Entity/Restaurant.php b/src/Entity/Restaurant.php index 9328a2c..1d94a7c 100644 --- a/src/Entity/Restaurant.php +++ b/src/Entity/Restaurant.php @@ -31,7 +31,7 @@ class Restaurant private string $description; /** - * @ORM\Column(type="string", length=5, options={"default" : 'EUR'}) + * @ORM\Column(type="string", length=5, options={"default" : "EUR"}) * @Assert\Currency */ private string $currency; diff --git a/src/Form/PropertySearchType.php b/src/Form/PropertySearchType.php index 184971b..e658c8b 100644 --- a/src/Form/PropertySearchType.php +++ b/src/Form/PropertySearchType.php @@ -39,37 +39,37 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'Vege' => 'Vege', */ //'DiabeticDiet' => 'DiabeticDiet', - 'GlutenFreeDiet' => $this->translator->trans('GlutenFreeDiet'), //Doublon déja dans les allergenes - 'HalalDiet' => $this->translator->trans('HalalDiet'), - 'HinduDiet' => $this->translator->trans('HinduDiet'), - 'KosherDiet' => $this->translator->trans('KosherDiet'), - //'LowCalorieDiet' => 'LowCalorieDiet', - //'LowFatDiet' => 'LowFatDiet', - 'LowLactoseDiet' => $this->translator->trans('LowLactoseDiet'), //Doublon déja dans les allergenes - //'LowSaltDiet' => 'LowSaltDiet', - 'VeganDiet' => $this->translator->trans('VeganDiet'), - 'VegetarianDiet' => $this->translator->trans('VegetarianDiet'), - 'NoPork' => $this->translator->trans('No Pork'), - 'AlcoholFree' => $this->translator->trans('no Alcohol'), + $this->translator->trans('GlutenFreeDiet') => 'GlutenFreeDiet', //Doublon déja dans les allergenes + $this->translator->trans('HalalDiet') => 'HalalDiet', + $this->translator->trans('HinduDiet') => 'HinduDiet', + $this->translator->trans('KosherDiet') => 'KosherDiet', + //'LowCalorieDiet)' => '/'''LowCalorieDiet', + //'LowFatDiet)' => '/'''LowFatDiet', + $this->translator->trans('LowLactoseDiet') => 'LowLactoseDiet', //Doublon déja dans les allergenes + //'LowSaltDiet)' => '/'''LowSaltDiet', + $this->translator->trans('VeganDiet') => 'VeganDiet', + $this->translator->trans('VegetarianDiet') => 'VegetarianDiet', + $this->translator->trans('NoPork') => 'NoPork', + $this->translator->trans('AlcoholFree') => 'AlcoholFree', ], 'multiple' => true]) ->add('allergy', ChoiceType::class, [ 'required' => false, 'choices' => [ - 'peanut' => $this->translator->trans('peanut'), - 'celery' => $this->translator->trans('celery'), - 'shellfish' => $this->translator->trans('shellfish'), - 'nut' => $this->translator->trans('nut'), - 'gluten' => $this->translator->trans('gluten'), - 'lactose' => $this->translator->trans('lactose'), - 'lupine' => $this->translator->trans('lupine'), - 'mollusc' => $this->translator->trans('mollusc'), - 'mustard' => $this->translator->trans('mustard'), - 'egg' => $this->translator->trans('egg'), - 'fish' => $this->translator->trans('fish'), - 'sesame' => $this->translator->trans('sesame'), - 'soy' => $this->translator->trans('soy'), - 'sulphites' => $this->translator->trans('sulphites') + $this->translator->trans('peanut') => 'peanut', + $this->translator->trans('celery') => 'celery', + $this->translator->trans('shellfish') => 'shellfish', + $this->translator->trans('nut') => 'nut', + $this->translator->trans('gluten') => 'gluten', + $this->translator->trans('lactose') => 'lactose', + $this->translator->trans('lupine') => 'lupine', + $this->translator->trans('mollusc') => 'mollusc', + $this->translator->trans('mustard') => 'mustard', + $this->translator->trans('egg') => 'egg', + $this->translator->trans('fish') => 'fish', + $this->translator->trans('sesame') => 'sesame', + $this->translator->trans('soy') => 'soy', + $this->translator->trans('sulphites') => 'sulphites', ], 'multiple' => true ]) diff --git a/symfony.lock b/symfony.lock index 0afff99..24e9877 100644 --- a/symfony.lock +++ b/symfony.lock @@ -487,6 +487,9 @@ "symfony/polyfill-intl-idn": { "version": "v1.23.0" }, + "symfony/polyfill-intl-messageformatter": { + "version": "v1.23.0" + }, "symfony/polyfill-intl-normalizer": { "version": "v1.23.0" }, diff --git a/templates/menu.html.twig b/templates/menu.html.twig new file mode 100644 index 0000000..cfdd20f --- /dev/null +++ b/templates/menu.html.twig @@ -0,0 +1,47 @@ +{% extends "base.html.twig" %} + +{# +{% import "macroHtmlMenu.html.twig" as macroHtmlMenu %} +{% import "macroJsonMenu.json.twig" as macroJsonMenu %} +#} +{% block title %}{{ restaurant.name }} - {{ restaurant.hasMenu[0].name}}{% endblock %} + +{% block body %} + +
+ {{ form_start(form) }} + {{ form_end(form) }} +
+

{{ restaurant.hasMenu[0].name }}

+
+ {# {{ macroHtmlMenu.section(restaurant.hasMenu[0].hasMenuSection, restaurant.currency, 2) }} #} +
+{% endblock %} + +{# + +{% block javascripts %} + +{% endblock %} + +#} \ No newline at end of file diff --git a/templates/menuList.html.twig b/templates/menuList.html.twig new file mode 100644 index 0000000..9ad714f --- /dev/null +++ b/templates/menuList.html.twig @@ -0,0 +1,12 @@ +{% extends "base.html.twig" %} + +{% block title %}{{ restaurant.name }} - Les Menus{% endblock %} + +{% block body %} +

{{ restaurant.name }}

+ +{% endblock %} \ No newline at end of file diff --git a/templates/restaurant.html.twig b/templates/restaurant.html.twig new file mode 100644 index 0000000..5c8e825 --- /dev/null +++ b/templates/restaurant.html.twig @@ -0,0 +1,9 @@ +{% extends "base.html.twig" %} + +{% block title %}{{ restaurant.name }}{% endblock %} + +{% block body %} +

{{ restaurant.name }}

+
{{ restaurant.description }}
+ {% trans %}menus{% endtrans %} +{% endblock %} \ No newline at end of file diff --git a/translations/messages+intl-icu.fr.xlf b/translations/messages+intl-icu.fr.xlf index 0bf8bbe..bb546c1 100644 --- a/translations/messages+intl-icu.fr.xlf +++ b/translations/messages+intl-icu.fr.xlf @@ -33,12 +33,12 @@ VegetarianDiet végétarien - - No Pork + + NoPork sans porc - - no Alcohol + + AlcoholFree sans alcool