add option to select previous menuitems #17

Merged
lubiana merged 1 commit from improve-vendors into main 2024-06-26 18:14:09 +00:00
11 changed files with 410 additions and 94 deletions

View file

@ -7,7 +7,7 @@
"php": ">=8.3",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/dbal": "^3",
"doctrine/dbal": "^4",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^3.2",

167
composer.lock generated
View file

@ -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": "5aec19bda25c7cc358299be1a1d67cef",
"content-hash": "ab475528135d157af8dae9e8b967be1a",
"packages": [
{
"name": "doctrine/cache",
@ -187,47 +187,42 @@
},
{
"name": "doctrine/dbal",
"version": "3.8.5",
"version": "4.0.4",
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal.git",
"reference": "0e3536ba088a749985c8801105b6b3ac6c1280b6"
"reference": "50fda19f80724b55ff770bb4ff352407008e63c5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/0e3536ba088a749985c8801105b6b3ac6c1280b6",
"reference": "0e3536ba088a749985c8801105b6b3ac6c1280b6",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/50fda19f80724b55ff770bb4ff352407008e63c5",
"reference": "50fda19f80724b55ff770bb4ff352407008e63c5",
"shasum": ""
},
"require": {
"composer-runtime-api": "^2",
"doctrine/cache": "^1.11|^2.0",
"doctrine/deprecations": "^0.5.3|^1",
"doctrine/event-manager": "^1|^2",
"php": "^7.4 || ^8.0",
"php": "^8.1",
"psr/cache": "^1|^2|^3",
"psr/log": "^1|^2|^3"
},
"require-dev": {
"doctrine/coding-standard": "12.0.0",
"fig/log-test": "^1",
"jetbrains/phpstorm-stubs": "2023.1",
"phpstan/phpstan": "1.11.1",
"jetbrains/phpstorm-stubs": "2023.2",
"phpstan/phpstan": "1.11.5",
"phpstan/phpstan-phpunit": "1.4.0",
"phpstan/phpstan-strict-rules": "^1.6",
"phpunit/phpunit": "9.6.19",
"psalm/plugin-phpunit": "0.18.4",
"phpunit/phpunit": "10.5.22",
"psalm/plugin-phpunit": "0.19.0",
"slevomat/coding-standard": "8.13.1",
"squizlabs/php_codesniffer": "3.9.2",
"symfony/cache": "^5.4|^6.0|^7.0",
"symfony/console": "^4.4|^5.4|^6.0|^7.0",
"vimeo/psalm": "4.30.0"
"squizlabs/php_codesniffer": "3.10.1",
"symfony/cache": "^6.3.8|^7.0",
"symfony/console": "^5.4|^6.3|^7.0",
"vimeo/psalm": "5.24.0"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
},
"bin": [
"bin/doctrine-dbal"
],
"type": "library",
"autoload": {
"psr-4": {
@ -280,7 +275,7 @@
],
"support": {
"issues": "https://github.com/doctrine/dbal/issues",
"source": "https://github.com/doctrine/dbal/tree/3.8.5"
"source": "https://github.com/doctrine/dbal/tree/4.0.4"
},
"funding": [
{
@ -296,7 +291,7 @@
"type": "tidelift"
}
],
"time": "2024-06-08T17:49:56+00:00"
"time": "2024-06-19T11:57:23+00:00"
},
{
"name": "doctrine/deprecations",
@ -1078,16 +1073,16 @@
},
{
"name": "doctrine/persistence",
"version": "3.3.2",
"version": "3.3.3",
"source": {
"type": "git",
"url": "https://github.com/doctrine/persistence.git",
"reference": "477da35bd0255e032826f440b94b3e37f2d56f42"
"reference": "b337726451f5d530df338fc7f68dee8781b49779"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/persistence/zipball/477da35bd0255e032826f440b94b3e37f2d56f42",
"reference": "477da35bd0255e032826f440b94b3e37f2d56f42",
"url": "https://api.github.com/repos/doctrine/persistence/zipball/b337726451f5d530df338fc7f68dee8781b49779",
"reference": "b337726451f5d530df338fc7f68dee8781b49779",
"shasum": ""
},
"require": {
@ -1099,15 +1094,14 @@
"doctrine/common": "<2.10"
},
"require-dev": {
"composer/package-versions-deprecated": "^1.11",
"doctrine/coding-standard": "^11",
"doctrine/coding-standard": "^12",
"doctrine/common": "^3.0",
"phpstan/phpstan": "1.9.4",
"phpstan/phpstan": "1.11.1",
"phpstan/phpstan-phpunit": "^1",
"phpstan/phpstan-strict-rules": "^1.1",
"phpunit/phpunit": "^8.5 || ^9.5",
"symfony/cache": "^4.4 || ^5.4 || ^6.0",
"vimeo/psalm": "4.30.0 || 5.3.0"
"vimeo/psalm": "4.30.0 || 5.24.0"
},
"type": "library",
"autoload": {
@ -1156,7 +1150,7 @@
],
"support": {
"issues": "https://github.com/doctrine/persistence/issues",
"source": "https://github.com/doctrine/persistence/tree/3.3.2"
"source": "https://github.com/doctrine/persistence/tree/3.3.3"
},
"funding": [
{
@ -1172,7 +1166,7 @@
"type": "tidelift"
}
],
"time": "2024-03-12T14:54:36+00:00"
"time": "2024-06-20T10:14:30+00:00"
},
{
"name": "doctrine/sql-formatter",
@ -3103,16 +3097,16 @@
},
{
"name": "symfony/polyfill-intl-grapheme",
"version": "v1.29.0",
"version": "v1.30.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-grapheme.git",
"reference": "32a9da87d7b3245e09ac426c83d334ae9f06f80f"
"reference": "64647a7c30b2283f5d49b874d84a18fc22054b7a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/32a9da87d7b3245e09ac426c83d334ae9f06f80f",
"reference": "32a9da87d7b3245e09ac426c83d334ae9f06f80f",
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/64647a7c30b2283f5d49b874d84a18fc22054b7a",
"reference": "64647a7c30b2283f5d49b874d84a18fc22054b7a",
"shasum": ""
},
"require": {
@ -3161,7 +3155,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.29.0"
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.30.0"
},
"funding": [
{
@ -3177,20 +3171,20 @@
"type": "tidelift"
}
],
"time": "2024-01-29T20:11:03+00:00"
"time": "2024-05-31T15:07:36+00:00"
},
{
"name": "symfony/polyfill-intl-icu",
"version": "v1.29.0",
"version": "v1.30.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-icu.git",
"reference": "07094a28851a49107f3ab4f9120ca2975a64b6e1"
"reference": "e76343c631b453088e2260ac41dfebe21954de81"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-icu/zipball/07094a28851a49107f3ab4f9120ca2975a64b6e1",
"reference": "07094a28851a49107f3ab4f9120ca2975a64b6e1",
"url": "https://api.github.com/repos/symfony/polyfill-intl-icu/zipball/e76343c631b453088e2260ac41dfebe21954de81",
"reference": "e76343c631b453088e2260ac41dfebe21954de81",
"shasum": ""
},
"require": {
@ -3245,7 +3239,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-icu/tree/v1.29.0"
"source": "https://github.com/symfony/polyfill-intl-icu/tree/v1.30.0"
},
"funding": [
{
@ -3261,20 +3255,20 @@
"type": "tidelift"
}
],
"time": "2024-01-29T20:12:16+00:00"
"time": "2024-05-31T15:07:36+00:00"
},
{
"name": "symfony/polyfill-intl-normalizer",
"version": "v1.29.0",
"version": "v1.30.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-normalizer.git",
"reference": "bc45c394692b948b4d383a08d7753968bed9a83d"
"reference": "a95281b0be0d9ab48050ebd988b967875cdb9fdb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/bc45c394692b948b4d383a08d7753968bed9a83d",
"reference": "bc45c394692b948b4d383a08d7753968bed9a83d",
"url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/a95281b0be0d9ab48050ebd988b967875cdb9fdb",
"reference": "a95281b0be0d9ab48050ebd988b967875cdb9fdb",
"shasum": ""
},
"require": {
@ -3326,7 +3320,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.29.0"
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.30.0"
},
"funding": [
{
@ -3342,20 +3336,20 @@
"type": "tidelift"
}
],
"time": "2024-01-29T20:11:03+00:00"
"time": "2024-05-31T15:07:36+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.29.0",
"version": "v1.30.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec"
"reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec",
"reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd22ab50000ef01661e2a31d850ebaa297f8e03c",
"reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c",
"shasum": ""
},
"require": {
@ -3406,7 +3400,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0"
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.30.0"
},
"funding": [
{
@ -3422,25 +3416,24 @@
"type": "tidelift"
}
],
"time": "2024-01-29T20:11:03+00:00"
"time": "2024-06-19T12:30:46+00:00"
},
{
"name": "symfony/polyfill-php83",
"version": "v1.29.0",
"version": "v1.30.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php83.git",
"reference": "86fcae159633351e5fd145d1c47de6c528f8caff"
"reference": "dbdcdf1a4dcc2743591f1079d0c35ab1e2dcbbc9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php83/zipball/86fcae159633351e5fd145d1c47de6c528f8caff",
"reference": "86fcae159633351e5fd145d1c47de6c528f8caff",
"url": "https://api.github.com/repos/symfony/polyfill-php83/zipball/dbdcdf1a4dcc2743591f1079d0c35ab1e2dcbbc9",
"reference": "dbdcdf1a4dcc2743591f1079d0c35ab1e2dcbbc9",
"shasum": ""
},
"require": {
"php": ">=7.1",
"symfony/polyfill-php80": "^1.14"
"php": ">=7.1"
},
"type": "library",
"extra": {
@ -3483,7 +3476,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php83/tree/v1.29.0"
"source": "https://github.com/symfony/polyfill-php83/tree/v1.30.0"
},
"funding": [
{
@ -3499,20 +3492,20 @@
"type": "tidelift"
}
],
"time": "2024-01-29T20:11:03+00:00"
"time": "2024-06-19T12:35:24+00:00"
},
{
"name": "symfony/polyfill-uuid",
"version": "v1.29.0",
"version": "v1.30.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-uuid.git",
"reference": "3abdd21b0ceaa3000ee950097bc3cf9efc137853"
"reference": "2ba1f33797470debcda07fe9dce20a0003df18e9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-uuid/zipball/3abdd21b0ceaa3000ee950097bc3cf9efc137853",
"reference": "3abdd21b0ceaa3000ee950097bc3cf9efc137853",
"url": "https://api.github.com/repos/symfony/polyfill-uuid/zipball/2ba1f33797470debcda07fe9dce20a0003df18e9",
"reference": "2ba1f33797470debcda07fe9dce20a0003df18e9",
"shasum": ""
},
"require": {
@ -3562,7 +3555,7 @@
"uuid"
],
"support": {
"source": "https://github.com/symfony/polyfill-uuid/tree/v1.29.0"
"source": "https://github.com/symfony/polyfill-uuid/tree/v1.30.0"
},
"funding": [
{
@ -3578,7 +3571,7 @@
"type": "tidelift"
}
],
"time": "2024-01-29T20:11:03+00:00"
"time": "2024-05-31T15:07:36+00:00"
},
{
"name": "symfony/property-access",
@ -5580,16 +5573,16 @@
},
{
"name": "phpstan/phpstan",
"version": "1.11.4",
"version": "1.11.5",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "9100a76ce8015b9aa7125b9171ae3a76887b6c82"
"reference": "490f0ae1c92b082f154681d7849aee776a7c1443"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/9100a76ce8015b9aa7125b9171ae3a76887b6c82",
"reference": "9100a76ce8015b9aa7125b9171ae3a76887b6c82",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/490f0ae1c92b082f154681d7849aee776a7c1443",
"reference": "490f0ae1c92b082f154681d7849aee776a7c1443",
"shasum": ""
},
"require": {
@ -5634,7 +5627,7 @@
"type": "github"
}
],
"time": "2024-06-06T12:19:22+00:00"
"time": "2024-06-17T15:10:54+00:00"
},
{
"name": "phpunit/php-code-coverage",
@ -6060,16 +6053,16 @@
},
{
"name": "rector/rector",
"version": "1.1.0",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/rectorphp/rector.git",
"reference": "556509e2dcf527369892b7d411379c4a02f31859"
"reference": "c930cdb21294f10955ddfc31b720971e8333943d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/rectorphp/rector/zipball/556509e2dcf527369892b7d411379c4a02f31859",
"reference": "556509e2dcf527369892b7d411379c4a02f31859",
"url": "https://api.github.com/repos/rectorphp/rector/zipball/c930cdb21294f10955ddfc31b720971e8333943d",
"reference": "c930cdb21294f10955ddfc31b720971e8333943d",
"shasum": ""
},
"require": {
@ -6107,7 +6100,7 @@
],
"support": {
"issues": "https://github.com/rectorphp/rector/issues",
"source": "https://github.com/rectorphp/rector/tree/1.1.0"
"source": "https://github.com/rectorphp/rector/tree/1.1.1"
},
"funding": [
{
@ -6115,7 +6108,7 @@
"type": "github"
}
],
"time": "2024-05-18T09:40:27+00:00"
"time": "2024-06-21T07:51:17+00:00"
},
{
"name": "sebastian/cli-parser",
@ -7704,16 +7697,16 @@
},
{
"name": "symplify/easy-coding-standard",
"version": "12.2.1",
"version": "12.3.0",
"source": {
"type": "git",
"url": "https://github.com/easy-coding-standard/easy-coding-standard.git",
"reference": "095fe591b2e51fd84edd21b8c9be74402eadc50e"
"reference": "f919574aa566b4d00fd06700ca61168aafef66e1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/095fe591b2e51fd84edd21b8c9be74402eadc50e",
"reference": "095fe591b2e51fd84edd21b8c9be74402eadc50e",
"url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/f919574aa566b4d00fd06700ca61168aafef66e1",
"reference": "f919574aa566b4d00fd06700ca61168aafef66e1",
"shasum": ""
},
"require": {
@ -7749,7 +7742,7 @@
],
"support": {
"issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues",
"source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.2.1"
"source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.3.0"
},
"funding": [
{
@ -7761,7 +7754,7 @@
"type": "github"
}
],
"time": "2024-06-02T01:25:21+00:00"
"time": "2024-06-18T07:35:59+00:00"
},
{
"name": "theseer/tokenizer",

View file

@ -0,0 +1,73 @@
<?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 Version20240626175246 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_item (id BLOB NOT NULL, name VARCHAR(255) NOT NULL, food_vendor_id BLOB NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_D754D5506EF983E8 FOREIGN KEY (food_vendor_id) REFERENCES food_vendor (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_D754D5506EF983E8 ON menu_item (food_vendor_id)');
$this->addSql('CREATE TEMPORARY TABLE __temp__food_order AS SELECT id, food_vendor_id, closed_at FROM food_order');
$this->addSql('DROP TABLE food_order');
$this->addSql('CREATE TABLE food_order (id BLOB NOT NULL, food_vendor_id BLOB NOT NULL, closed_at DATETIME DEFAULT NULL, PRIMARY KEY(id), CONSTRAINT FK_44856726EF983E8 FOREIGN KEY (food_vendor_id) REFERENCES food_vendor (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO food_order (id, food_vendor_id, closed_at) SELECT id, food_vendor_id, closed_at FROM __temp__food_order');
$this->addSql('DROP TABLE __temp__food_order');
$this->addSql('CREATE INDEX IDX_44856726EF983E8 ON food_order (food_vendor_id)');
$this->addSql('CREATE TEMPORARY TABLE __temp__food_vendor AS SELECT id, name FROM food_vendor');
$this->addSql('DROP TABLE food_vendor');
$this->addSql('CREATE TABLE food_vendor (id BLOB NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY(id))');
$this->addSql('INSERT INTO food_vendor (id, name) SELECT id, name FROM __temp__food_vendor');
$this->addSql('DROP TABLE __temp__food_vendor');
$this->addSql('CREATE TEMPORARY TABLE __temp__order_item AS SELECT id, food_order_id, name, extras FROM order_item');
$this->addSql('DROP TABLE order_item');
$this->addSql('CREATE TABLE order_item (id BLOB NOT NULL, food_order_id BLOB DEFAULT NULL, name VARCHAR(255) NOT NULL, extras VARCHAR(255) DEFAULT NULL, menu_item_id BLOB DEFAULT NULL, PRIMARY KEY(id), CONSTRAINT FK_52EA1F09A5D24A7A FOREIGN KEY (food_order_id) REFERENCES food_order (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_52EA1F099AB44FE0 FOREIGN KEY (menu_item_id) REFERENCES menu_item (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO order_item (id, food_order_id, name, extras) SELECT id, food_order_id, name, extras FROM __temp__order_item');
$this->addSql('DROP TABLE __temp__order_item');
$this->addSql('CREATE INDEX IDX_52EA1F09A5D24A7A ON order_item (food_order_id)');
$this->addSql('CREATE INDEX IDX_52EA1F099AB44FE0 ON order_item (menu_item_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE menu_item');
$this->addSql('CREATE TEMPORARY TABLE __temp__food_order AS SELECT id, closed_at, food_vendor_id FROM food_order');
$this->addSql('DROP TABLE food_order');
$this->addSql('CREATE TABLE food_order (id BLOB NOT NULL --(DC2Type:ulid)
, closed_at DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
, food_vendor_id BLOB NOT NULL --(DC2Type:ulid)
, PRIMARY KEY(id), CONSTRAINT FK_44856726EF983E8 FOREIGN KEY (food_vendor_id) REFERENCES food_vendor (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO food_order (id, closed_at, food_vendor_id) SELECT id, closed_at, food_vendor_id FROM __temp__food_order');
$this->addSql('DROP TABLE __temp__food_order');
$this->addSql('CREATE INDEX IDX_44856726EF983E8 ON food_order (food_vendor_id)');
$this->addSql('CREATE TEMPORARY TABLE __temp__food_vendor AS SELECT id, name FROM food_vendor');
$this->addSql('DROP TABLE food_vendor');
$this->addSql('CREATE TABLE food_vendor (id BLOB NOT NULL --(DC2Type:ulid)
, name VARCHAR(50) NOT NULL, PRIMARY KEY(id))');
$this->addSql('INSERT INTO food_vendor (id, name) SELECT id, name FROM __temp__food_vendor');
$this->addSql('DROP TABLE __temp__food_vendor');
$this->addSql('CREATE TEMPORARY TABLE __temp__order_item AS SELECT id, name, extras, food_order_id FROM order_item');
$this->addSql('DROP TABLE order_item');
$this->addSql('CREATE TABLE order_item (id BLOB NOT NULL --(DC2Type:ulid)
, name VARCHAR(255) NOT NULL, extras VARCHAR(255) DEFAULT NULL, food_order_id BLOB NOT NULL --(DC2Type:ulid)
, PRIMARY KEY(id), CONSTRAINT FK_52EA1F09A5D24A7A FOREIGN KEY (food_order_id) REFERENCES food_order (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO order_item (id, name, extras, food_order_id) SELECT id, name, extras, food_order_id FROM __temp__order_item');
$this->addSql('DROP TABLE __temp__order_item');
$this->addSql('CREATE INDEX IDX_52EA1F09A5D24A7A ON order_item (food_order_id)');
}
}

View file

@ -0,0 +1,66 @@
<?php declare(strict_types=1);
namespace App\Command;
use App\Entity\MenuItem;
use App\Repository\MenuItemRepository;
use App\Repository\OrderItemRepository;
use Doctrine\ORM\EntityManagerInterface;
use Override;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use function sprintf;
#[AsCommand(
name: 'app:migrate-orderitems-menuitems',
description: 'Migrate orderitems to menu items',
)]
final class MigrateOrderitemsMenuitemsCommand extends Command
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly OrderItemRepository $orderItemRepository,
private readonly MenuItemRepository $menuItemRepository,
) {
parent::__construct();
}
#[Override]
protected function configure(): void {}
#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$orderItems = $this->orderItemRepository->findAll();
foreach ($orderItems as $orderItem) {
$menuItem = $this->menuItemRepository->findOneBy([
'name' => $orderItem->getName(),
'foodVendor' => $orderItem->getFoodOrder()
->getFoodVendor(),
]);
if ($menuItem === null) {
$menuItem = new MenuItem;
$menuItem->setName($orderItem->getName());
$menuItem->setFoodVendor($orderItem->getFoodOrder()->getFoodVendor());
$this->entityManager->persist($menuItem);
$this->entityManager->flush();
$output->writeln(sprintf('Menu item %s added', $menuItem->getName()));
}
$orderItem->setMenuItem($menuItem);
$this->entityManager->persist($orderItem);
}
$this->entityManager->flush();
$io->success('You have a new command! Now make it your own! Pass --help to see your options.');
return Command::SUCCESS;
}
}

View file

@ -3,8 +3,10 @@
namespace App\Controller;
use App\Entity\FoodOrder;
use App\Entity\MenuItem;
use App\Entity\OrderItem;
use App\Form\OrderItemType;
use App\Repository\MenuItemRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@ -15,18 +17,32 @@ use Symfony\Component\Routing\Attribute\Route;
final class OrderItemController extends AbstractController
{
#[Route('/new/{foodOrder}', name: 'app_order_item_new', methods: ['GET', 'POST'])]
public function new(Request $request, FoodOrder $foodOrder, EntityManagerInterface $entityManager): Response
public function new(Request $request, FoodOrder $foodOrder, EntityManagerInterface $entityManager, MenuItemRepository $menuItemRepository): Response
{
if ($foodOrder->isClosed()) {
return $this->redirectToRoute('app_food_order_show', [
'id' => $foodOrder->getId(),
], Response::HTTP_SEE_OTHER);
}
$orderItem = new OrderItem;
$form = $this->createForm(OrderItemType::class, $orderItem);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$menuItem = $menuItemRepository->findOneBy([
'name' => $orderItem->getName(),
'foodVendor' => $foodOrder->getFoodVendor(),
]);
if ($menuItem === null) {
$menuItem = new MenuItem;
$menuItem->setName($orderItem->getName());
$menuItem->setFoodVendor($foodOrder->getFoodVendor());
$entityManager->persist($menuItem);
}
$orderItem->setMenuItem($menuItem);
$orderItem->setFoodOrder($foodOrder);
$entityManager->persist($orderItem);
$entityManager->flush();
@ -35,11 +51,15 @@ final class OrderItemController extends AbstractController
'id' => $foodOrder->getId(),
], Response::HTTP_SEE_OTHER);
}
$menuItems = $menuItemRepository->findBy([
'foodVendor' => $foodOrder->getFoodVendor(),
]);
return $this->render('order_item/new.html.twig', [
'order_item' => $orderItem,
'food_order' => $foodOrder,
'form' => $form,
'menuItems' => $menuItems,
]);
}

View file

@ -28,9 +28,16 @@ class FoodVendor
#[ORM\OneToMany(targetEntity: FoodOrder::class, mappedBy: 'foodVendor', orphanRemoval: true)]
private Collection $foodOrders;
/**
* @var Collection<int, MenuItem>
*/
#[ORM\OneToMany(targetEntity: MenuItem::class, mappedBy: 'foodVendor', orphanRemoval: true)]
private Collection $menuItems;
public function __construct()
{
$this->foodOrders = new ArrayCollection;
$this->menuItems = new ArrayCollection;
}
public function getId(): Ulid|null
@ -77,4 +84,32 @@ class FoodVendor
return $this;
}
/**
* @return Collection<int, MenuItem>
*/
public function getMenuItems(): Collection
{
return $this->menuItems;
}
public function addMenuItem(MenuItem $menuItem): static
{
if (! $this->menuItems->contains($menuItem)) {
$this->menuItems->add($menuItem);
$menuItem->setFoodVendor($this);
}
return $this;
}
public function removeMenuItem(MenuItem $menuItem): static
{
// set the owning side to null (unless already changed)
if ($this->menuItems->removeElement($menuItem) && $menuItem->getFoodVendor() === $this) {
$menuItem->setFoodVendor(null);
}
return $this;
}
}

55
src/Entity/MenuItem.php Normal file
View file

@ -0,0 +1,55 @@
<?php declare(strict_types=1);
namespace App\Entity;
use App\Repository\MenuItemRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: MenuItemRepository::class)]
class MenuItem
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = null;
#[ORM\Column(length: 255)]
private string|null $name = null;
#[ORM\ManyToOne(inversedBy: 'menuItems')]
#[ORM\JoinColumn(nullable: false)]
private FoodVendor|null $foodVendor = null;
public function getId(): Ulid|null
{
return $this->id;
}
public function getName(): string|null
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getFoodVendor(): FoodVendor|null
{
return $this->foodVendor;
}
public function setFoodVendor(FoodVendor|null $foodVendor): static
{
$this->foodVendor = $foodVendor;
return $this;
}
}

View file

@ -24,9 +24,13 @@ class OrderItem
private string|null $extras = null;
#[ORM\ManyToOne(inversedBy: 'orderItems')]
#[ORM\JoinColumn(nullable: false)]
#[ORM\JoinColumn(nullable: true)]
private FoodOrder|null $foodOrder = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: true)]
private MenuItem|null $menuItem = null;
public function getId(): Ulid|null
{
return $this->id;
@ -67,4 +71,16 @@ class OrderItem
return $this;
}
public function getMenuItem(): MenuItem|null
{
return $this->menuItem;
}
public function setMenuItem(MenuItem|null $menuItem): static
{
$this->menuItem = $menuItem;
return $this;
}
}

View file

@ -0,0 +1,43 @@
<?php declare(strict_types=1);
namespace App\Repository;
use App\Entity\MenuItem;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<MenuItem>
*/
final class MenuItemRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, MenuItem::class);
}
// /**
// * @return MenuItem[] Returns an array of MenuItem 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): ?MenuItem
// {
// return $this->createQueryBuilder('m')
// ->andWhere('m.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -7,10 +7,6 @@
<table class="table">
<tbody>
<tr>
<th>Id</th>
<td>{{ food_vendor.id }}</td>
</tr>
<tr>
<th>Name</th>
<td>{{ food_vendor.name }}</td>

View file

@ -7,5 +7,24 @@
{{ include('order_item/_form.html.twig') }}
<div>
<b>click a button to select a given menuitem</b>
</div>
<div>
{% for menuItem in menuItems %}
<button data-menu-item>{{ menuItem.name }}</button>
{% endfor %}
</div>
<hr />
<a class="button" href="{{ path('app_food_order_show', { 'id': food_order.id}) }}">back to list</a>
<script>
document.querySelectorAll('[data-menu-item]').forEach(function(element) {
element.addEventListener('click', function(e) {
document.getElementById('order_item_name').value = e.target.textContent
});
});
</script>
{% endblock %}