#21 add planned closing time to food order
This commit is contained in:
parent
634f13d968
commit
b479fbf5ed
5 changed files with 11 additions and 3 deletions
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Repository\FoodOrderRepository;
|
use App\Repository\FoodOrderRepository;
|
||||||
|
use DateInterval;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
@ -36,6 +37,7 @@ class FoodOrder
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->orderItems = new ArrayCollection;
|
$this->orderItems = new ArrayCollection;
|
||||||
|
$this->open();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): Ulid|null
|
public function getId(): Ulid|null
|
||||||
|
@ -62,7 +64,7 @@ class FoodOrder
|
||||||
|
|
||||||
public function isClosed(): bool
|
public function isClosed(): bool
|
||||||
{
|
{
|
||||||
return $this->closedAt instanceof DateTimeImmutable;
|
return $this->closedAt instanceof DateTimeImmutable && $this->closedAt->getTimestamp() <= (new DateTimeImmutable)->getTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(): static
|
public function close(): static
|
||||||
|
@ -72,7 +74,8 @@ class FoodOrder
|
||||||
|
|
||||||
public function open(): static
|
public function open(): static
|
||||||
{
|
{
|
||||||
return $this->setClosedAt(null);
|
$this->closedAt = (new DateTimeImmutable)->add(new DateInterval('PT1H'));
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFoodVendor(): FoodVendor|null
|
public function getFoodVendor(): FoodVendor|null
|
||||||
|
|
|
@ -21,6 +21,9 @@ final class FoodOrderType extends AbstractType
|
||||||
'class' => FoodVendor::class,
|
'class' => FoodVendor::class,
|
||||||
'choice_label' => 'name',
|
'choice_label' => 'name',
|
||||||
])
|
])
|
||||||
|
->add(child: 'closedAt', options: [
|
||||||
|
'label' => 'closes at',
|
||||||
|
])
|
||||||
;
|
;
|
||||||
if ($action !== null) {
|
if ($action !== null) {
|
||||||
$builder->setAction($action);
|
$builder->setAction($action);
|
||||||
|
|
|
@ -27,7 +27,7 @@ final class FoodOrderRepository extends ServiceEntityRepository
|
||||||
/**
|
/**
|
||||||
* @return FoodOrder[]
|
* @return FoodOrder[]
|
||||||
*/
|
*/
|
||||||
public function findLatestEntries(int $limit = 10): array
|
public function findLatestEntries(int $limit = 5): array
|
||||||
{
|
{
|
||||||
$qb = $this->createQueryBuilder('alias');
|
$qb = $this->createQueryBuilder('alias');
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ final class OrderItemControllerTest extends DbWebTest
|
||||||
|
|
||||||
$this->manager->persist($this->menuItem);
|
$this->manager->persist($this->menuItem);
|
||||||
$this->manager->flush();
|
$this->manager->flush();
|
||||||
|
|
||||||
$this->menuItemRepository = static::getContainer()->get(MenuItemRepository::class);
|
$this->menuItemRepository = static::getContainer()->get(MenuItemRepository::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ abstract class DbWebTest extends WebTestCase
|
||||||
->getAllMetadata();
|
->getAllMetadata();
|
||||||
$schemaTool->dropDatabase();
|
$schemaTool->dropDatabase();
|
||||||
$schemaTool->updateSchema($metadata);
|
$schemaTool->updateSchema($metadata);
|
||||||
|
|
||||||
$this->repository = $this->manager->getRepository($this->getEntityClass());
|
$this->repository = $this->manager->getRepository($this->getEntityClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue