From b479fbf5ed752ed9bfccf5c078b89293b73364c8 Mon Sep 17 00:00:00 2001 From: lubiana Date: Thu, 27 Jun 2024 17:14:59 +0200 Subject: [PATCH] #21 add planned closing time to food order --- src/Entity/FoodOrder.php | 7 +++++-- src/Form/FoodOrderType.php | 3 +++ src/Repository/FoodOrderRepository.php | 2 +- tests/Controller/OrderItemControllerTest.php | 1 + tests/DbWebTest.php | 1 + 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Entity/FoodOrder.php b/src/Entity/FoodOrder.php index 847542b..72a9530 100644 --- a/src/Entity/FoodOrder.php +++ b/src/Entity/FoodOrder.php @@ -3,6 +3,7 @@ namespace App\Entity; use App\Repository\FoodOrderRepository; +use DateInterval; use DateTimeImmutable; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; @@ -36,6 +37,7 @@ class FoodOrder public function __construct() { $this->orderItems = new ArrayCollection; + $this->open(); } public function getId(): Ulid|null @@ -62,7 +64,7 @@ class FoodOrder public function isClosed(): bool { - return $this->closedAt instanceof DateTimeImmutable; + return $this->closedAt instanceof DateTimeImmutable && $this->closedAt->getTimestamp() <= (new DateTimeImmutable)->getTimestamp(); } public function close(): static @@ -72,7 +74,8 @@ class FoodOrder public function open(): static { - return $this->setClosedAt(null); + $this->closedAt = (new DateTimeImmutable)->add(new DateInterval('PT1H')); + return $this; } public function getFoodVendor(): FoodVendor|null diff --git a/src/Form/FoodOrderType.php b/src/Form/FoodOrderType.php index bfe9dc4..b0f177b 100644 --- a/src/Form/FoodOrderType.php +++ b/src/Form/FoodOrderType.php @@ -21,6 +21,9 @@ final class FoodOrderType extends AbstractType 'class' => FoodVendor::class, 'choice_label' => 'name', ]) + ->add(child: 'closedAt', options: [ + 'label' => 'closes at', + ]) ; if ($action !== null) { $builder->setAction($action); diff --git a/src/Repository/FoodOrderRepository.php b/src/Repository/FoodOrderRepository.php index 4438819..aea76d5 100644 --- a/src/Repository/FoodOrderRepository.php +++ b/src/Repository/FoodOrderRepository.php @@ -27,7 +27,7 @@ final class FoodOrderRepository extends ServiceEntityRepository /** * @return FoodOrder[] */ - public function findLatestEntries(int $limit = 10): array + public function findLatestEntries(int $limit = 5): array { $qb = $this->createQueryBuilder('alias'); diff --git a/tests/Controller/OrderItemControllerTest.php b/tests/Controller/OrderItemControllerTest.php index a5f6da2..706d1c1 100644 --- a/tests/Controller/OrderItemControllerTest.php +++ b/tests/Controller/OrderItemControllerTest.php @@ -39,6 +39,7 @@ final class OrderItemControllerTest extends DbWebTest $this->manager->persist($this->menuItem); $this->manager->flush(); + $this->menuItemRepository = static::getContainer()->get(MenuItemRepository::class); } diff --git a/tests/DbWebTest.php b/tests/DbWebTest.php index c2491c6..18ef24a 100644 --- a/tests/DbWebTest.php +++ b/tests/DbWebTest.php @@ -27,6 +27,7 @@ abstract class DbWebTest extends WebTestCase ->getAllMetadata(); $schemaTool->dropDatabase(); $schemaTool->updateSchema($metadata); + $this->repository = $this->manager->getRepository($this->getEntityClass()); } } -- 2.39.5