Implemented entities for new RoomCategory BedType system.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\BedType;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\UrlField;
|
||||
|
||||
class BedTypeCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return BedType::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield TextField::new('name');
|
||||
yield UrlField::new('iconUrl');
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
#[IsGranted("ROLE_ADMIN")]
|
||||
class RoomAvailabilityAdminController extends AbstractController
|
||||
{
|
||||
|
||||
private $adminUrlGenerator;
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
@@ -129,19 +128,4 @@ class RoomAvailabilityAdminController extends AbstractController
|
||||
'categoryId' => $categoryId,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/roomAvailabilityTEST/', name: 'admin_roomAvailability_test')]
|
||||
public function availabilityTest(EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$avl = new RoomAvailability();
|
||||
|
||||
$avl->setDay(new \DateTime("2024-04-24"));
|
||||
$avl->setRoomCategory($entityManager->find(RoomCategory::class, 4));
|
||||
$avl->setNumAvailable(2);
|
||||
|
||||
$entityManager->persist($avl);
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->json($avl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\RoomCategoryBedType;
|
||||
use App\Form\RoomCategoryBedTypeForm;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Page;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\Field;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
@@ -27,13 +30,10 @@ class RoomCategoryCrudController extends AbstractCrudController
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
return [
|
||||
//IdField::new('id'),
|
||||
TextField::new('name'),
|
||||
TextField::new('description'),
|
||||
TextField::new('bedType'),
|
||||
IntegerField::new('maxGuestNum'),
|
||||
CollectionField::new('roomCategoryPhotos')->useEntryCrudForm()
|
||||
];
|
||||
yield TextField::new('name');
|
||||
yield TextField::new('description');
|
||||
yield TextField::new('bedType');
|
||||
yield IntegerField::new('maxGuestNum');
|
||||
yield CollectionField::new('roomCategoryPhotos')->useEntryCrudForm();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\BedType;
|
||||
use App\Entity\Booking;
|
||||
use App\Entity\ConfigVariable;
|
||||
use App\Entity\FareTable;
|
||||
@@ -40,6 +41,9 @@ class SomniaDashboardController extends AbstractDashboardController
|
||||
yield MenuItem::linkToRoute('Room Availability', 'fas fa-calendar-check', 'admin_roomAvailability');
|
||||
yield MenuItem::linkToCrud('Fare Tables', 'fas fa-table', FareTable::class);
|
||||
yield MenuItem::linkToCrud('Room Fares', 'fas fa-tag', RoomFare::class);
|
||||
|
||||
yield MenuItem::Section('Category Configuration');
|
||||
yield MenuItem::linkToCrud('Bed Types', 'fas fa-bed', BedType::class);
|
||||
|
||||
yield MenuItem::Section('App Management');
|
||||
yield MenuItem::linkToCrud('Config Vars', 'fas fa-gear', ConfigVariable::class);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\BedTypeRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: BedTypeRepository::class)]
|
||||
class BedType
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $iconUrl = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIconUrl(): ?string
|
||||
{
|
||||
return $this->iconUrl;
|
||||
}
|
||||
|
||||
public function setIconUrl(?string $iconUrl): static
|
||||
{
|
||||
$this->iconUrl = $iconUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+37
-15
@@ -22,9 +22,6 @@ class RoomCategory
|
||||
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||
private ?string $description = null;
|
||||
|
||||
#[ORM\Column(length: 64, nullable: true)]
|
||||
private ?string $bedType = null;
|
||||
|
||||
#[ORM\Column(nullable: false)]
|
||||
private ?int $maxGuestNum = null;
|
||||
|
||||
@@ -34,9 +31,16 @@ class RoomCategory
|
||||
#[ORM\OneToMany(targetEntity: RoomCategoryPhoto::class, mappedBy: 'roomCategory', orphanRemoval: true, cascade: ['persist'])]
|
||||
private Collection $roomCategoryPhotos;
|
||||
|
||||
/**
|
||||
* @var Collection<int, RoomCategoryBedType>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: RoomCategoryBedType::class, mappedBy: 'roomCategory', orphanRemoval: true, cascade: ['persist'])]
|
||||
private Collection $roomCategoryBedTypes;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->roomCategoryPhotos = new ArrayCollection();
|
||||
$this->roomCategoryBedTypes = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -68,18 +72,6 @@ class RoomCategory
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBedType(): ?string
|
||||
{
|
||||
return $this->bedType;
|
||||
}
|
||||
|
||||
public function setBedType(?string $bedType): static
|
||||
{
|
||||
$this->bedType = $bedType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMaxGuestNum(): ?int
|
||||
{
|
||||
return $this->maxGuestNum;
|
||||
@@ -126,4 +118,34 @@ class RoomCategory
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, RoomCategoryBedType>
|
||||
*/
|
||||
public function getRoomCategoryBedTypes(): Collection
|
||||
{
|
||||
return $this->roomCategoryBedTypes;
|
||||
}
|
||||
|
||||
public function addRoomCategoryBedType(RoomCategoryBedType $roomCategoryBedType): static
|
||||
{
|
||||
if (!$this->roomCategoryBedTypes->contains($roomCategoryBedType)) {
|
||||
$this->roomCategoryBedTypes->add($roomCategoryBedType);
|
||||
$roomCategoryBedType->setRoomCategory($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeRoomCategoryBedType(RoomCategoryBedType $roomCategoryBedType): static
|
||||
{
|
||||
if ($this->roomCategoryBedTypes->removeElement($roomCategoryBedType)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($roomCategoryBedType->getRoomCategory() === $this) {
|
||||
$roomCategoryBedType->setRoomCategory(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\RoomCategoryBedTypeRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: RoomCategoryBedTypeRepository::class)]
|
||||
class RoomCategoryBedType
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(inversedBy: 'roomCategoryBedTypes')]
|
||||
#[ORM\JoinColumn(nullable: false, onDelete: "CASCADE")]
|
||||
private ?RoomCategory $roomCategory = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?BedType $bedType = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $amount = null;
|
||||
|
||||
public function __construct(RoomCategory $roomCat, BedType $bedType) {
|
||||
$this->roomCategory = $roomCat;
|
||||
$this->bedType = $bedType;
|
||||
}
|
||||
|
||||
public function getAmount(): ?int
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
public function setAmount(int $amount): static
|
||||
{
|
||||
$this->amount = $amount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRoomCategory(): ?RoomCategory
|
||||
{
|
||||
return $this->roomCategory;
|
||||
}
|
||||
|
||||
public function setRoomCategory(?RoomCategory $roomCategory): static
|
||||
{
|
||||
$this->roomCategory = $roomCategory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBedType(): ?BedType
|
||||
{
|
||||
return $this->bedType;
|
||||
}
|
||||
|
||||
public function setBedType(?BedType $bedType): static
|
||||
{
|
||||
$this->bedType = $bedType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\BedType;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<BedType>
|
||||
*
|
||||
* @method BedType|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method BedType|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method BedType[] findAll()
|
||||
* @method BedType[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class BedTypeRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, BedType::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return BedType[] Returns an array of BedType objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('b')
|
||||
// ->andWhere('b.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('b.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?BedType
|
||||
// {
|
||||
// return $this->createQueryBuilder('b')
|
||||
// ->andWhere('b.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\RoomCategoryBedType;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<RoomCategoryBedType>
|
||||
*
|
||||
* @method RoomCategoryBedType|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method RoomCategoryBedType|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method RoomCategoryBedType[] findAll()
|
||||
* @method RoomCategoryBedType[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class RoomCategoryBedTypeRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, RoomCategoryBedType::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return RoomCategoryBedType[] Returns an array of RoomCategoryBedType objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('r.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?RoomCategoryBedType
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user