forked from Somnia/SomniaRooms
Bookings - Easyadmin support.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Controller\Admin\BookingCustomerCrudController;
|
||||
use App\Entity\Booking;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
|
||||
class BookingCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Booking::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
$fieldRefNumber = TextField::new ('refNumber');
|
||||
$fieldBookingTime = DateTimeField::new ('BookingTime');
|
||||
if ($pageName == Crud::PAGE_EDIT) {
|
||||
$fieldRefNumber->setDisabled(true);
|
||||
$fieldBookingTime->setDisabled(true);
|
||||
}
|
||||
|
||||
yield FormField::addFieldset('Booking details');
|
||||
yield $fieldRefNumber;
|
||||
yield $fieldBookingTime;
|
||||
|
||||
yield DateField::new ('ArrivalDate');
|
||||
yield DateField::new ('DepartureDate');
|
||||
|
||||
yield AssociationField::new ('bookingCustomer')->renderAsEmbeddedForm(BookingCustomerCrudController::class);
|
||||
yield CollectionField::new ('bookingRooms')->useEntryCrudForm();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\BookingCustomer;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
|
||||
class BookingCustomerCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return BookingCustomer::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield TextField::new('Name');
|
||||
yield TextField::new('Surname');
|
||||
yield TextField::new('Email');
|
||||
yield TextField::new('PhoneNumber');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Controller\Admin\RoomCategoryCrudController;
|
||||
use App\Entity\BookingRoom;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\MoneyField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
|
||||
|
||||
class BookingRoomCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return BookingRoom::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield AssociationField::new ('RoomCategory')->setCrudController(RoomCategoryCrudController::class);
|
||||
yield NumberField::new ('GuestNumber');
|
||||
yield MoneyField::new ('RoomPrice')->setCurrency("EUR");
|
||||
yield NumberField::new ('Amount');
|
||||
}
|
||||
}
|
||||
@@ -2,20 +2,18 @@
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Booking;
|
||||
use App\Entity\ConfigVariable;
|
||||
use App\Entity\FareTable;
|
||||
use App\Entity\RoomCategory;
|
||||
use App\Entity\RoomFare;
|
||||
use App\Entity\User;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
use App\Entity\RoomCategory;
|
||||
use App\Entity\RoomAvailability;
|
||||
use App\Entity\FareTable;
|
||||
use App\Entity\RoomFare;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\ConfigVariable;
|
||||
|
||||
class SomniaDashboardController extends AbstractDashboardController
|
||||
{
|
||||
#[Route('/admin', name: 'admin')]
|
||||
@@ -26,14 +24,17 @@ class SomniaDashboardController extends AbstractDashboardController
|
||||
|
||||
public function configureDashboard(): Dashboard
|
||||
{
|
||||
return Dashboard::new()
|
||||
return Dashboard::new ()
|
||||
->setTitle('SomniaRooms');
|
||||
}
|
||||
|
||||
public function configureMenuItems(): iterable
|
||||
{
|
||||
yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
|
||||
|
||||
|
||||
yield MenuItem::Section('Booking Management');
|
||||
yield MenuItem::linkToCrud('Bookings', 'fas fa-door-open', Booking::class);
|
||||
|
||||
yield MenuItem::Section('Room Management');
|
||||
yield MenuItem::linkToCrud('Category', 'fas fa-door-open', RoomCategory::class);
|
||||
yield MenuItem::linkToRoute('Room Availability', 'fas fa-calendar-check', 'admin_roomAvailability');
|
||||
|
||||
+29
-9
@@ -19,21 +19,24 @@ class Booking
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
||||
private ?\DateTimeInterface $ArrivalDate = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
||||
#[ORM\Column(type : Types::DATE_MUTABLE)]
|
||||
private ?\DateTimeInterface $DepartureDate = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIMETZ_MUTABLE)]
|
||||
#[ORM\Column(type : Types::DATETIMETZ_MUTABLE)]
|
||||
private ?\DateTimeInterface $BookingTime = null;
|
||||
|
||||
#[ORM\OneToOne(mappedBy: 'Booking', cascade: ['persist', 'remove'])]
|
||||
#[ORM\OneToOne(mappedBy : 'Booking', cascade: ['persist', 'remove'])]
|
||||
private ?BookingCustomer $bookingCustomer = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, BookingRoom>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: BookingRoom::class, mappedBy: 'Booking', orphanRemoval: true)]
|
||||
#[ORM\OneToMany(targetEntity: BookingRoom::class, mappedBy: 'Booking', orphanRemoval: true, cascade: ['persist'])]
|
||||
private Collection $bookingRooms;
|
||||
|
||||
#[ORM\Column(length: 20)]
|
||||
private ?string $refNumber = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bookingRooms = new ArrayCollection();
|
||||
@@ -88,8 +91,8 @@ class Booking
|
||||
public function setBookingCustomer(BookingCustomer $bookingCustomer): static
|
||||
{
|
||||
// set the owning side of the relation if necessary
|
||||
if ($bookingCustomer->getBookingId() !== $this) {
|
||||
$bookingCustomer->setBookingId($this);
|
||||
if ($bookingCustomer->getBooking() !== $this) {
|
||||
$bookingCustomer->setBooking($this);
|
||||
}
|
||||
|
||||
$this->bookingCustomer = $bookingCustomer;
|
||||
@@ -109,7 +112,7 @@ class Booking
|
||||
{
|
||||
if (!$this->bookingRooms->contains($bookingRoom)) {
|
||||
$this->bookingRooms->add($bookingRoom);
|
||||
$bookingRoom->setBookingId($this);
|
||||
$bookingRoom->setBooking($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -119,11 +122,28 @@ class Booking
|
||||
{
|
||||
if ($this->bookingRooms->removeElement($bookingRoom)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($bookingRoom->getBookingId() === $this) {
|
||||
$bookingRoom->setBookingId(null);
|
||||
if ($bookingRoom->getBooking() === $this) {
|
||||
$bookingRoom->setBooking(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRefNumber(): ?string
|
||||
{
|
||||
return $this->refNumber;
|
||||
}
|
||||
|
||||
public function setRefNumber(string $refNumber): static
|
||||
{
|
||||
$this->refNumber = $refNumber;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
function __toString(): string
|
||||
{
|
||||
return $this->getRefNumber();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,4 +93,9 @@ class BookingCustomer
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
function __toString(): string
|
||||
{
|
||||
return $this->getName() . " " . $this->getSurname();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class BookingRoom
|
||||
return $this->RoomCategory;
|
||||
}
|
||||
|
||||
public function setRoomCategoryId(?RoomCategory $RoomCategory): static
|
||||
public function setRoomCategory(?RoomCategory $RoomCategory): static
|
||||
{
|
||||
$this->RoomCategory = $RoomCategory;
|
||||
|
||||
@@ -94,4 +94,9 @@ class BookingRoom
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
function __toString(): string
|
||||
{
|
||||
return $this->getAmount() . " " . $this->getRoomCategory()->getName() . " - " . $this->getGuestNumber() . " Guests";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user