<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\OrderBy;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="cal_accommodation_room")
* @ORM\Entity(repositoryClass="App\Repository\AccommodationRoomRepository")
* @ORM\EntityListeners({"App\Entity\Listener\AccommodationRoomListener"})
*/
class AccommodationRoom
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Accommodation", inversedBy="rooms")
*/
private $accommodation;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Translation", cascade={"persist"}, orphanRemoval=true)
*/
private $name;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Translation", cascade={"persist"}, orphanRemoval=true)
*/
private $description;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $surface;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\PropertyListItem")
* @ORM\JoinTable(name="cal_accommodation_rooms_equipments")
*/
private $equipments;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\PropertyListItem")
* @ORM\JoinTable(name="cal_accommodation_rooms_services")
*/
private $services;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\PropertyListItem")
* @ORM\JoinTable(name="cal_accommodation_rooms_charges_details")
*/
private $chargesDetails;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $privateBathroom = false;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $privateToilet = false;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $privateKitchen = false;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $maxHousingAssistance;
private $depositFees = 500;
/**
* @ORM\Column(type="integer")
*/
private $rent;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $additionalRent;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $additionalRentDetails;
/**
* @ORM\Column(type="integer")
*/
private $entranceFees;
/**
* @ORM\Column(type="integer")
*/
private $chargesFees;
/**
* @ORM\Column(type="integer")
*/
private $servicesFees;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $cleaningFees = 20;
/**
* @ORM\OneToMany(targetEntity="App\Entity\AccommodationImage", mappedBy="room", cascade={"persist"}, orphanRemoval=true)
* @ORM\OrderBy({"position" = "ASC"})
*/
private $images;
/**
* @var \DateTime $createdAt
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @var \DateTime $updated
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updatedAt;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $disabled = false;
/**
* @ORM\OneToMany(targetEntity="App\Entity\BookingRoom", mappedBy="room")
*/
private $bookingRooms;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserInfo", mappedBy="room", cascade={"persist"}, orphanRemoval=true)
* @ORM\OrderBy({"position" = "ASC"})
*/
private $waitingListUsers;
/**
* @ORM\OneToMany(targetEntity="App\Entity\AccommodationZone", mappedBy="room", cascade={"persist"}, orphanRemoval=true)
* @OrderBy({"priority" = "DESC"})
*/
private $zones;
/**
* @ORM\OneToOne(targetEntity="App\Entity\AccommodationOccupancy", cascade={"persist"}, orphanRemoval=false)
*/
private $occupancy;
/**
* @ORM\OneToMany(targetEntity="App\Entity\AccommodationOccupancy", mappedBy="room")
* @ORM\OrderBy({"createdAt" = "DESC"})
*/
private $occupancies;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $ongoingBooking = false;
/**
* @ORM\OneToOne(targetEntity="App\Entity\RoomStats", cascade={"persist"}, orphanRemoval=false)
*/
private $stats;
/**
* @ORM\OneToMany(targetEntity="App\Entity\RoomStats", mappedBy="room")
* @ORM\OrderBy({"createdAt" = "DESC"})
*/
private $statsHistory;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Maintenance", mappedBy="room")
*/
private $maintenances;
/**
* @ORM\OneToMany (targetEntity="App\Entity\Survey", mappedBy="room")
*/
private $surveys;
//--------------------------------------------------------------
// Utilities
//--------------------------------------------------------------
public function __toString(): string {
return $this->getName();
}
public function __construct()
{
$this->images = new ArrayCollection();
$this->waitingListUsers = new ArrayCollection();
$this->bookingRooms = new ArrayCollection();
$this->occupancies = new ArrayCollection();
$this->zones = new ArrayCollection();
$this->statsHistory = new ArrayCollection();
$this->maintenances = new ArrayCollection();
$this->surveys = new ArrayCollection();
$this->zones = new ArrayCollection();
}
public function getAvailablilityDate()
{
// If a booking is ongoing, the room is not available
if($this->isOngoingBooking()) return null;
if(!empty($this->getOccupancy())) {
if(!empty($this->getOccupancy()->getTo())) {
// If the occupant is leaving, the room is available the day after
$date = clone $this->getOccupancy()->getTo();
$date->modify("+1 day");
return $date;
} else {
// If there is an occupant, the room is not available
return null;
}
}
// The room is available
return new \DateTime("yesterday");
}
public function isAvailable()
{
$now = new \DateTime("now");
return empty($this->isOngoingBooking()) && (!empty($this->getAvailablilityDate()) || $this->getAvailablilityDate() <= $now);
}
public function getActiveBookings() {
return $this->getBookingRooms()->filter(function (BookingRoom $bookingRoom) {
return $bookingRoom->getBooking()->isActive();
});
}
public function getCurrentRoommate() {
if (!empty($this->getOccupancy())) {
return $this->getOccupancy()->getUser();
} else {
return null;
}
}
public function isOccupied() {
return !empty($this->getCurrentRoommate());
}
public function hasEmptyZone() {
if ($this->getZones()->count() === 0) return true;
$hasEmptyZone = false;
foreach ($this->getZones() as $zone) {
if ($zone->isEmpty()) $hasEmptyZone = true;
}
return $hasEmptyZone;
}
public function getTotalRent() {
return $this->getRent() + $this->getChargesFees();
}
//--------------------------------------------------------------
// Collections
//--------------------------------------------------------------
public function addImage(AccommodationImage $image)
{
$image->setRoom($this);
$this->images[] = $image;
return $this;
}
public function removeImage(AccommodationImage $image)
{
$this->images->removeElement($image);
}
public function addWaitingListUser(UserInfo $user)
{
$user->setRoom($this);
$this->waitingListUsers[] = $user;
return $this;
}
public function removeWaitingListUser(UserInfo $user)
{
$this->waitingListUsers->removeElement($user);
}
public function addFurniture(AccommodationFurniture $furniture)
{
$furniture->setRoom($this);
$this->furnitures[] = $furniture;
return $this;
}
public function removeFurniture(AccommodationFurniture $furniture)
{
$this->furnitures->removeElement($furniture);
}
public function addOccupancy(AccommodationOccupancy $occupancy)
{
$occupancy->setRoom($this);
$this->occupancies[] = $occupancy;
return $this;
}
public function removeOccupancy(AccommodationOccupancy $occupancy)
{
$this->occupancies->removeElement($occupancy);
}
//--------------------------------------------------------------
// Getters and setters
//--------------------------------------------------------------
public function getImages()
{
return $this->images;
}
public function getCover()
{
return (!empty($this->images) && count($this->images) > 0) ? $this->images[0] : null;
}
public function setImages($images)
{
$this->images = $images;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return mixed
*/
public function getDescription()
{
return $this->description;
}
/**
* @param mixed $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* @return mixed
*/
public function getSurface()
{
return $this->surface;
}
/**
* @param mixed $surface
*/
public function setSurface($surface)
{
$this->surface = $surface;
}
/**
* @return mixed
*/
public function getEquipments()
{
return $this->equipments;
}
/**
* @param mixed $equipments
*/
public function setEquipments($equipments)
{
$this->equipments = $equipments;
}
/**
* @return mixed
*/
public function getServices()
{
return $this->services;
}
/**
* @param mixed $services
*/
public function setServices($services)
{
$this->services = $services;
}
/**
* @return mixed
*/
public function getPrivateBathroom()
{
return $this->privateBathroom;
}
/**
* @param mixed $privateBathroom
*/
public function setPrivateBathroom($privateBathroom)
{
$this->privateBathroom = $privateBathroom;
}
/**
* @return mixed
*/
public function getPrivateToilet()
{
return $this->privateToilet;
}
/**
* @param mixed $privateToilet
*/
public function setPrivateToilet($privateToilet)
{
$this->privateToilet = $privateToilet;
}
/**
* @return mixed
*/
public function getPrivateKitchen()
{
return $this->privateKitchen;
}
/**
* @param mixed $privateKitchen
*/
public function setPrivateKitchen($privateKitchen)
{
$this->privateKitchen = $privateKitchen;
}
/**
* @return mixed
*/
public function getMaxHousingAssistance()
{
return $this->maxHousingAssistance;
}
/**
* @param mixed $maxHousingAssistance
*/
public function setMaxHousingAssistance($maxHousingAssistance)
{
$this->maxHousingAssistance = $maxHousingAssistance;
}
/**
* @return mixed
*/
public function getRent()
{
return $this->rent;
}
/**
* @param mixed $rent
*/
public function setRent($rent)
{
$this->rent = $rent;
}
/**
* @return mixed
*/
public function getEntranceFees()
{
return $this->entranceFees;
}
/**
* @param mixed $entranceFees
*/
public function setEntranceFees($entranceFees)
{
$this->entranceFees = $entranceFees;
}
/**
* @return mixed
*/
public function getChargesFees()
{
return $this->chargesFees;
}
/**
* @param mixed $chargesFees
*/
public function setChargesFees($chargesFees)
{
$this->chargesFees = $chargesFees;
}
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return mixed
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @param mixed $updatedAt
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
}
/**
* @return mixed
*/
public function getDisabled()
{
return $this->disabled;
}
/**
* @param mixed $disabled
*/
public function setDisabled($disabled)
{
$this->disabled = $disabled;
}
/**
* @return mixed
*/
public function getAccommodation()
{
return $this->accommodation;
}
/**
* @param mixed $accommodation
*/
public function setAccommodation($accommodation)
{
$this->accommodation = $accommodation;
}
/**
* @return mixed
*/
public function getBookingRooms()
{
return $this->bookingRooms;
}
/**
* @param mixed $bookingRooms
*/
public function setBookingRooms($bookingRooms)
{
$this->bookingRooms = $bookingRooms;
}
/**
* @return mixed
*/
public function getWaitingListUsers()
{
return $this->waitingListUsers;
}
/**
* @param mixed $waitingListUsers
*/
public function setWaitingListUsers($waitingListUsers)
{
$this->waitingListUsers = $waitingListUsers;
}
/**
* @return mixed
*/
public function getServicesFees()
{
return $this->servicesFees;
}
/**
* @param mixed $servicesFees
*/
public function setServicesFees($servicesFees): void
{
$this->servicesFees = $servicesFees;
}
/**
* @param bool $available
*/
public function setAvailable(bool $available)
{
$this->available = $available;
}
/**
* @return mixed
*/
public function getChargesDetails()
{
return $this->chargesDetails;
}
/**
* @param mixed $chargesDetails
*/
public function setChargesDetails($chargesDetails): void
{
$this->chargesDetails = $chargesDetails;
}
/**
* @return int
*/
public function getDepositFees(): int
{
return $this->depositFees;
}
/**
* @param int $depositFees
*/
public function setDepositFees(int $depositFees): void
{
$this->depositFees = $depositFees;
}
/**
* @return mixed
*/
public function isOngoingBooking()
{
return $this->ongoingBooking;
}
/**
* @param bool $ongoingBooking
*/
public function setOngoingBooking(bool $ongoingBooking): void
{
$this->ongoingBooking = $ongoingBooking;
}
/**
* @return mixed
*/
public function getOccupancy()
{
return $this->occupancy;
}
/**
* @param mixed $occupancy
*/
public function setOccupancy($occupancy): void
{
$this->occupancy = $occupancy;
}
/**
* @return mixed
*/
public function getOccupancies()
{
return $this->occupancies;
}
/**
* @param mixed $occupancies
*/
public function setOccupancies($occupancies): void
{
$this->occupancies = $occupancies;
}
/**
* @return mixed
*/
public function getStats()
{
return $this->stats;
}
/**
* @param mixed $stats
*/
public function setStats($stats): void
{
$this->stats = $stats;
}
/**
* @return mixed
*/
public function getStatsHistory()
{
return $this->statsHistory;
}
/**
* @param mixed $statsHistory
*/
public function setStatsHistory($statsHistory): void
{
$this->statsHistory = $statsHistory;
}
/**
* @return mixed
*/
public function getZones()
{
return $this->zones;
}
/**
* @param mixed $zones
*/
public function setZones($zones): void
{
$this->zones = $zones;
}
/**
* @return ArrayCollection
*/
public function getSurveys()
{
return $this->surveys;
}
/**
* @param ArrayCollection $surveys
*/
public function setSurveys($surveys): void
{
$this->surveys = $surveys;
}
/**
* @return int
*/
public function getCleaningFees()
{
return $this->cleaningFees;
}
/**
* @param int $cleaningFees
*/
public function setCleaningFees($cleaningFees): void
{
$this->cleaningFees = $cleaningFees;
}
/**
* @return mixed
*/
public function getAdditionalRent()
{
return $this->additionalRent;
}
/**
* @param mixed $additionalRent
*/
public function setAdditionalRent($additionalRent): void
{
$this->additionalRent = $additionalRent;
}
/**
* @return mixed
*/
public function getAdditionalRentDetails()
{
return $this->additionalRentDetails;
}
/**
* @param mixed $additionalRentDetails
*/
public function setAdditionalRentDetails($additionalRentDetails): void
{
$this->additionalRentDetails = $additionalRentDetails;
}
}