src/Entity/AccommodationRoom.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping\OrderBy;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity
  9.  * @ORM\Table(name="cal_accommodation_room")
  10.  * @ORM\Entity(repositoryClass="App\Repository\AccommodationRoomRepository")
  11.  * @ORM\EntityListeners({"App\Entity\Listener\AccommodationRoomListener"})
  12.  */
  13. class AccommodationRoom
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\ManyToOne(targetEntity="App\Entity\Accommodation", inversedBy="rooms")
  23.      */
  24.     private $accommodation;
  25.     /**
  26.      * @ORM\OneToOne(targetEntity="App\Entity\Translation", cascade={"persist"}, orphanRemoval=true)
  27.      */
  28.     private $name;
  29.     /**
  30.      * @ORM\OneToOne(targetEntity="App\Entity\Translation", cascade={"persist"}, orphanRemoval=true)
  31.      */
  32.     private $description;
  33.     /**
  34.      * @ORM\Column(type="integer", nullable=true)
  35.      */
  36.     private $surface;
  37.     /**
  38.      * @ORM\ManyToMany(targetEntity="App\Entity\PropertyListItem")
  39.      * @ORM\JoinTable(name="cal_accommodation_rooms_equipments")
  40.      */
  41.     private $equipments;
  42.     /**
  43.      * @ORM\ManyToMany(targetEntity="App\Entity\PropertyListItem")
  44.      * @ORM\JoinTable(name="cal_accommodation_rooms_services")
  45.      */
  46.     private $services;
  47.     /**
  48.      * @ORM\ManyToMany(targetEntity="App\Entity\PropertyListItem")
  49.      * @ORM\JoinTable(name="cal_accommodation_rooms_charges_details")
  50.      */
  51.     private $chargesDetails;
  52.     /**
  53.      * @ORM\Column(type="boolean", nullable=true)
  54.      */
  55.     private $privateBathroom false;
  56.     /**
  57.      * @ORM\Column(type="boolean", nullable=true)
  58.      */
  59.     private $privateToilet false;
  60.     /**
  61.      * @ORM\Column(type="boolean", nullable=true)
  62.      */
  63.     private $privateKitchen false;
  64.     /**
  65.      * @ORM\Column(type="integer", nullable=true)
  66.      */
  67.     private $maxHousingAssistance;
  68.     private $depositFees 500;
  69.     /**
  70.      * @ORM\Column(type="integer")
  71.      */
  72.     private $rent;
  73.     /**
  74.      * @ORM\Column(type="integer", nullable=true)
  75.      */
  76.     private $additionalRent;
  77.     /**
  78.      * @ORM\Column(type="string", length=255, nullable=true)
  79.      */
  80.     private $additionalRentDetails;
  81.     /**
  82.      * @ORM\Column(type="integer")
  83.      */
  84.     private $entranceFees;
  85.     /**
  86.      * @ORM\Column(type="integer")
  87.      */
  88.     private $chargesFees;
  89.     /**
  90.      * @ORM\Column(type="integer")
  91.      */
  92.     private $servicesFees;
  93.     /**
  94.      * @ORM\Column(type="integer", nullable=true)
  95.      */
  96.     private $cleaningFees 20;
  97.     /**
  98.      * @ORM\OneToMany(targetEntity="App\Entity\AccommodationImage", mappedBy="room", cascade={"persist"}, orphanRemoval=true)
  99.      * @ORM\OrderBy({"position" = "ASC"})
  100.      */
  101.     private $images;
  102.     /**
  103.      * @var \DateTime $createdAt
  104.      *
  105.      * @Gedmo\Timestampable(on="create")
  106.      * @ORM\Column(type="datetime")
  107.      */
  108.     private $createdAt;
  109.     /**
  110.      * @var \DateTime $updated
  111.      *
  112.      * @Gedmo\Timestampable(on="update")
  113.      * @ORM\Column(type="datetime")
  114.      */
  115.     private $updatedAt;
  116.     /**
  117.      * @ORM\Column(type="boolean", nullable=true)
  118.      */
  119.     private $disabled false;
  120.     /**
  121.      * @ORM\OneToMany(targetEntity="App\Entity\BookingRoom", mappedBy="room")
  122.      */
  123.     private $bookingRooms;
  124.     /**
  125.      * @ORM\OneToMany(targetEntity="App\Entity\UserInfo", mappedBy="room", cascade={"persist"}, orphanRemoval=true)
  126.      * @ORM\OrderBy({"position" = "ASC"})
  127.      */
  128.     private $waitingListUsers;
  129.     /**
  130.      * @ORM\OneToMany(targetEntity="App\Entity\AccommodationZone", mappedBy="room", cascade={"persist"}, orphanRemoval=true)
  131.      * @OrderBy({"priority" = "DESC"})
  132.      */
  133.     private $zones;
  134.     /**
  135.      * @ORM\OneToOne(targetEntity="App\Entity\AccommodationOccupancy", cascade={"persist"}, orphanRemoval=false)
  136.      */
  137.     private $occupancy;
  138.     /**
  139.      * @ORM\OneToMany(targetEntity="App\Entity\AccommodationOccupancy", mappedBy="room")
  140.      * @ORM\OrderBy({"createdAt" = "DESC"})
  141.      */
  142.     private $occupancies;
  143.     /**
  144.      * @ORM\Column(type="boolean", nullable=true)
  145.      */
  146.     private $ongoingBooking false;
  147.     /**
  148.      * @ORM\OneToOne(targetEntity="App\Entity\RoomStats", cascade={"persist"}, orphanRemoval=false)
  149.      */
  150.     private $stats;
  151.     /**
  152.      * @ORM\OneToMany(targetEntity="App\Entity\RoomStats", mappedBy="room")
  153.      * @ORM\OrderBy({"createdAt" = "DESC"})
  154.      */
  155.     private $statsHistory;
  156.     /**
  157.      * @ORM\OneToMany(targetEntity="App\Entity\Maintenance", mappedBy="room")
  158.      */
  159.     private $maintenances;
  160.     /**
  161.      * @ORM\OneToMany  (targetEntity="App\Entity\Survey", mappedBy="room")
  162.      */
  163.     private $surveys;
  164.     //--------------------------------------------------------------
  165.     // Utilities
  166.     //--------------------------------------------------------------
  167.     public function __toString(): string {
  168.         return $this->getName();
  169.     }
  170.     public function __construct()
  171.     {
  172.         $this->images = new ArrayCollection();
  173.         $this->waitingListUsers = new ArrayCollection();
  174.         $this->bookingRooms = new ArrayCollection();
  175.         $this->occupancies = new ArrayCollection();
  176.         $this->zones = new ArrayCollection();
  177.         $this->statsHistory = new ArrayCollection();
  178.         $this->maintenances = new ArrayCollection();
  179.         $this->surveys = new ArrayCollection();
  180.         $this->zones = new ArrayCollection();
  181.     }
  182.     public function getAvailablilityDate()
  183.     {
  184.         // If a booking is ongoing, the room is not available
  185.         if($this->isOngoingBooking()) return null;
  186.         if(!empty($this->getOccupancy())) {
  187.             if(!empty($this->getOccupancy()->getTo())) {
  188.                 // If the occupant is leaving, the room is available the day after
  189.                 $date = clone $this->getOccupancy()->getTo();
  190.                 $date->modify("+1 day");
  191.                 return $date;
  192.             } else {
  193.                 // If there is an occupant, the room is not available
  194.                 return null;
  195.             }
  196.         }
  197.         // The room is available
  198.         return new \DateTime("yesterday");
  199.     }
  200.     public function isAvailable()
  201.     {
  202.         $now = new \DateTime("now");
  203.         return empty($this->isOngoingBooking()) && (!empty($this->getAvailablilityDate()) || $this->getAvailablilityDate() <= $now);
  204.     }
  205.     public function getActiveBookings() {
  206.         return $this->getBookingRooms()->filter(function (BookingRoom $bookingRoom) {
  207.             return $bookingRoom->getBooking()->isActive();
  208.         });
  209.     }
  210.     public function getCurrentRoommate() {
  211.         if (!empty($this->getOccupancy())) {
  212.             return $this->getOccupancy()->getUser();
  213.         } else {
  214.             return null;
  215.         }
  216.     }
  217.     public function isOccupied() {
  218.         return !empty($this->getCurrentRoommate());
  219.     }
  220.     public function hasEmptyZone() {
  221.         if ($this->getZones()->count() === 0) return true;
  222.         $hasEmptyZone false;
  223.         foreach ($this->getZones() as $zone) {
  224.             if ($zone->isEmpty()) $hasEmptyZone true;
  225.         }
  226.         return $hasEmptyZone;
  227.     }
  228.     public function getTotalRent() {
  229.         return $this->getRent() + $this->getChargesFees();
  230.     }
  231.     //--------------------------------------------------------------
  232.     // Collections
  233.     //--------------------------------------------------------------
  234.     public function addImage(AccommodationImage $image)
  235.     {
  236.         $image->setRoom($this);
  237.         $this->images[] = $image;
  238.         return $this;
  239.     }
  240.     public function removeImage(AccommodationImage $image)
  241.     {
  242.         $this->images->removeElement($image);
  243.     }
  244.     public function addWaitingListUser(UserInfo $user)
  245.     {
  246.         $user->setRoom($this);
  247.         $this->waitingListUsers[] = $user;
  248.         return $this;
  249.     }
  250.     public function removeWaitingListUser(UserInfo $user)
  251.     {
  252.         $this->waitingListUsers->removeElement($user);
  253.     }
  254.     public function addFurniture(AccommodationFurniture $furniture)
  255.     {
  256.         $furniture->setRoom($this);
  257.         $this->furnitures[] = $furniture;
  258.         return $this;
  259.     }
  260.     public function removeFurniture(AccommodationFurniture $furniture)
  261.     {
  262.         $this->furnitures->removeElement($furniture);
  263.     }
  264.     public function addOccupancy(AccommodationOccupancy $occupancy)
  265.     {
  266.         $occupancy->setRoom($this);
  267.         $this->occupancies[] = $occupancy;
  268.         return $this;
  269.     }
  270.     public function removeOccupancy(AccommodationOccupancy $occupancy)
  271.     {
  272.         $this->occupancies->removeElement($occupancy);
  273.     }
  274.     //--------------------------------------------------------------
  275.     // Getters and setters
  276.     //--------------------------------------------------------------
  277.     public function getImages()
  278.     {
  279.         return $this->images;
  280.     }
  281.     public function getCover()
  282.     {
  283.         return (!empty($this->images) && count($this->images) > 0) ? $this->images[0] : null;
  284.     }
  285.     public function setImages($images)
  286.     {
  287.         $this->images $images;
  288.     }
  289.     /**
  290.      * @return mixed
  291.      */
  292.     public function getId()
  293.     {
  294.         return $this->id;
  295.     }
  296.     /**
  297.      * @param mixed $id
  298.      */
  299.     public function setId($id)
  300.     {
  301.         $this->id $id;
  302.     }
  303.     /**
  304.      * @return mixed
  305.      */
  306.     public function getName()
  307.     {
  308.         return $this->name;
  309.     }
  310.     /**
  311.      * @param mixed $name
  312.      */
  313.     public function setName($name)
  314.     {
  315.         $this->name $name;
  316.     }
  317.     /**
  318.      * @return mixed
  319.      */
  320.     public function getDescription()
  321.     {
  322.         return $this->description;
  323.     }
  324.     /**
  325.      * @param mixed $description
  326.      */
  327.     public function setDescription($description)
  328.     {
  329.         $this->description $description;
  330.     }
  331.     /**
  332.      * @return mixed
  333.      */
  334.     public function getSurface()
  335.     {
  336.         return $this->surface;
  337.     }
  338.     /**
  339.      * @param mixed $surface
  340.      */
  341.     public function setSurface($surface)
  342.     {
  343.         $this->surface $surface;
  344.     }
  345.     /**
  346.      * @return mixed
  347.      */
  348.     public function getEquipments()
  349.     {
  350.         return $this->equipments;
  351.     }
  352.     /**
  353.      * @param mixed $equipments
  354.      */
  355.     public function setEquipments($equipments)
  356.     {
  357.         $this->equipments $equipments;
  358.     }
  359.     /**
  360.      * @return mixed
  361.      */
  362.     public function getServices()
  363.     {
  364.         return $this->services;
  365.     }
  366.     /**
  367.      * @param mixed $services
  368.      */
  369.     public function setServices($services)
  370.     {
  371.         $this->services $services;
  372.     }
  373.     /**
  374.      * @return mixed
  375.      */
  376.     public function getPrivateBathroom()
  377.     {
  378.         return $this->privateBathroom;
  379.     }
  380.     /**
  381.      * @param mixed $privateBathroom
  382.      */
  383.     public function setPrivateBathroom($privateBathroom)
  384.     {
  385.         $this->privateBathroom $privateBathroom;
  386.     }
  387.     /**
  388.      * @return mixed
  389.      */
  390.     public function getPrivateToilet()
  391.     {
  392.         return $this->privateToilet;
  393.     }
  394.     /**
  395.      * @param mixed $privateToilet
  396.      */
  397.     public function setPrivateToilet($privateToilet)
  398.     {
  399.         $this->privateToilet $privateToilet;
  400.     }
  401.     /**
  402.      * @return mixed
  403.      */
  404.     public function getPrivateKitchen()
  405.     {
  406.         return $this->privateKitchen;
  407.     }
  408.     /**
  409.      * @param mixed $privateKitchen
  410.      */
  411.     public function setPrivateKitchen($privateKitchen)
  412.     {
  413.         $this->privateKitchen $privateKitchen;
  414.     }
  415.     /**
  416.      * @return mixed
  417.      */
  418.     public function getMaxHousingAssistance()
  419.     {
  420.         return $this->maxHousingAssistance;
  421.     }
  422.     /**
  423.      * @param mixed $maxHousingAssistance
  424.      */
  425.     public function setMaxHousingAssistance($maxHousingAssistance)
  426.     {
  427.         $this->maxHousingAssistance $maxHousingAssistance;
  428.     }
  429.     /**
  430.      * @return mixed
  431.      */
  432.     public function getRent()
  433.     {
  434.         return $this->rent;
  435.     }
  436.     /**
  437.      * @param mixed $rent
  438.      */
  439.     public function setRent($rent)
  440.     {
  441.         $this->rent $rent;
  442.     }
  443.     /**
  444.      * @return mixed
  445.      */
  446.     public function getEntranceFees()
  447.     {
  448.         return $this->entranceFees;
  449.     }
  450.     /**
  451.      * @param mixed $entranceFees
  452.      */
  453.     public function setEntranceFees($entranceFees)
  454.     {
  455.         $this->entranceFees $entranceFees;
  456.     }
  457.     /**
  458.      * @return mixed
  459.      */
  460.     public function getChargesFees()
  461.     {
  462.         return $this->chargesFees;
  463.     }
  464.     /**
  465.      * @param mixed $chargesFees
  466.      */
  467.     public function setChargesFees($chargesFees)
  468.     {
  469.         $this->chargesFees $chargesFees;
  470.     }
  471.     /**
  472.      * @return \DateTime
  473.      */
  474.     public function getCreatedAt(): \DateTime
  475.     {
  476.         return $this->createdAt;
  477.     }
  478.     /**
  479.      * @param \DateTime $createdAt
  480.      */
  481.     public function setCreatedAt(\DateTime $createdAt)
  482.     {
  483.         $this->createdAt $createdAt;
  484.     }
  485.     /**
  486.      * @return mixed
  487.      */
  488.     public function getUpdatedAt()
  489.     {
  490.         return $this->updatedAt;
  491.     }
  492.     /**
  493.      * @param mixed $updatedAt
  494.      */
  495.     public function setUpdatedAt($updatedAt)
  496.     {
  497.         $this->updatedAt $updatedAt;
  498.     }
  499.     /**
  500.      * @return mixed
  501.      */
  502.     public function getDisabled()
  503.     {
  504.         return $this->disabled;
  505.     }
  506.     /**
  507.      * @param mixed $disabled
  508.      */
  509.     public function setDisabled($disabled)
  510.     {
  511.         $this->disabled $disabled;
  512.     }
  513.     /**
  514.      * @return mixed
  515.      */
  516.     public function getAccommodation()
  517.     {
  518.         return $this->accommodation;
  519.     }
  520.     /**
  521.      * @param mixed $accommodation
  522.      */
  523.     public function setAccommodation($accommodation)
  524.     {
  525.         $this->accommodation $accommodation;
  526.     }
  527.     /**
  528.      * @return mixed
  529.      */
  530.     public function getBookingRooms()
  531.     {
  532.         return $this->bookingRooms;
  533.     }
  534.     /**
  535.      * @param mixed $bookingRooms
  536.      */
  537.     public function setBookingRooms($bookingRooms)
  538.     {
  539.         $this->bookingRooms $bookingRooms;
  540.     }
  541.     /**
  542.      * @return mixed
  543.      */
  544.     public function getWaitingListUsers()
  545.     {
  546.         return $this->waitingListUsers;
  547.     }
  548.     /**
  549.      * @param mixed $waitingListUsers
  550.      */
  551.     public function setWaitingListUsers($waitingListUsers)
  552.     {
  553.         $this->waitingListUsers $waitingListUsers;
  554.     }
  555.     /**
  556.      * @return mixed
  557.      */
  558.     public function getServicesFees()
  559.     {
  560.         return $this->servicesFees;
  561.     }
  562.     /**
  563.      * @param mixed $servicesFees
  564.      */
  565.     public function setServicesFees($servicesFees): void
  566.     {
  567.         $this->servicesFees $servicesFees;
  568.     }
  569.     /**
  570.      * @param bool $available
  571.      */
  572.     public function setAvailable(bool $available)
  573.     {
  574.         $this->available $available;
  575.     }
  576.     /**
  577.      * @return mixed
  578.      */
  579.     public function getChargesDetails()
  580.     {
  581.         return $this->chargesDetails;
  582.     }
  583.     /**
  584.      * @param mixed $chargesDetails
  585.      */
  586.     public function setChargesDetails($chargesDetails): void
  587.     {
  588.         $this->chargesDetails $chargesDetails;
  589.     }
  590.     /**
  591.      * @return int
  592.      */
  593.     public function getDepositFees(): int
  594.     {
  595.         return $this->depositFees;
  596.     }
  597.     /**
  598.      * @param int $depositFees
  599.      */
  600.     public function setDepositFees(int $depositFees): void
  601.     {
  602.         $this->depositFees $depositFees;
  603.     }
  604.     /**
  605.      * @return mixed
  606.      */
  607.     public function isOngoingBooking()
  608.     {
  609.         return $this->ongoingBooking;
  610.     }
  611.     /**
  612.      * @param bool $ongoingBooking
  613.      */
  614.     public function setOngoingBooking(bool $ongoingBooking): void
  615.     {
  616.         $this->ongoingBooking $ongoingBooking;
  617.     }
  618.     /**
  619.      * @return mixed
  620.      */
  621.     public function getOccupancy()
  622.     {
  623.         return $this->occupancy;
  624.     }
  625.     /**
  626.      * @param mixed $occupancy
  627.      */
  628.     public function setOccupancy($occupancy): void
  629.     {
  630.         $this->occupancy $occupancy;
  631.     }
  632.     /**
  633.      * @return mixed
  634.      */
  635.     public function getOccupancies()
  636.     {
  637.         return $this->occupancies;
  638.     }
  639.     /**
  640.      * @param mixed $occupancies
  641.      */
  642.     public function setOccupancies($occupancies): void
  643.     {
  644.         $this->occupancies $occupancies;
  645.     }
  646.     /**
  647.      * @return mixed
  648.      */
  649.     public function getStats()
  650.     {
  651.         return $this->stats;
  652.     }
  653.     /**
  654.      * @param mixed $stats
  655.      */
  656.     public function setStats($stats): void
  657.     {
  658.         $this->stats $stats;
  659.     }
  660.     /**
  661.      * @return mixed
  662.      */
  663.     public function getStatsHistory()
  664.     {
  665.         return $this->statsHistory;
  666.     }
  667.     /**
  668.      * @param mixed $statsHistory
  669.      */
  670.     public function setStatsHistory($statsHistory): void
  671.     {
  672.         $this->statsHistory $statsHistory;
  673.     }
  674.     /**
  675.      * @return mixed
  676.      */
  677.     public function getZones()
  678.     {
  679.         return $this->zones;
  680.     }
  681.     /**
  682.      * @param mixed $zones
  683.      */
  684.     public function setZones($zones): void
  685.     {
  686.         $this->zones $zones;
  687.     }
  688.     /**
  689.      * @return ArrayCollection
  690.      */
  691.     public function getSurveys()
  692.     {
  693.         return $this->surveys;
  694.     }
  695.     /**
  696.      * @param ArrayCollection $surveys
  697.      */
  698.     public function setSurveys($surveys): void
  699.     {
  700.         $this->surveys $surveys;
  701.     }
  702.     /**
  703.      * @return int
  704.      */
  705.     public function getCleaningFees()
  706.     {
  707.         return $this->cleaningFees;
  708.     }
  709.     /**
  710.      * @param int $cleaningFees
  711.      */
  712.     public function setCleaningFees($cleaningFees): void
  713.     {
  714.         $this->cleaningFees $cleaningFees;
  715.     }
  716.     /**
  717.      * @return mixed
  718.      */
  719.     public function getAdditionalRent()
  720.     {
  721.         return $this->additionalRent;
  722.     }
  723.     /**
  724.      * @param mixed $additionalRent
  725.      */
  726.     public function setAdditionalRent($additionalRent): void
  727.     {
  728.         $this->additionalRent $additionalRent;
  729.     }
  730.     /**
  731.      * @return mixed
  732.      */
  733.     public function getAdditionalRentDetails()
  734.     {
  735.         return $this->additionalRentDetails;
  736.     }
  737.     /**
  738.      * @param mixed $additionalRentDetails
  739.      */
  740.     public function setAdditionalRentDetails($additionalRentDetails): void
  741.     {
  742.         $this->additionalRentDetails $additionalRentDetails;
  743.     }
  744. }