src/Uniski/ResourceBundle/Entity/HotelRate.php line 11

Open in your IDE?
  1. <?php
  2. namespace Uniski\ResourceBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5. * @ORM\Entity(repositoryClass="Uniski\ResourceBundle\Repository\HotelRateRepository")
  6. * @ORM\HasLifecycleCallbacks()
  7. **/
  8. class HotelRate extends PriceRate
  9. {
  10.   const PRICE_KEY_GROUP 'group';
  11.   const PRICE_KEY_PAX 'pax';
  12.   const PRICE_TYPE_PAX "pax";
  13.   const PRICE_TYPE_GROUP "group";
  14.   const PRICE_TYPE_ROOM "room";
  15.   /**
  16.    * @var \DateTime
  17.    *
  18.    * @ORM\Column(name="date", type="datetime")
  19.    */
  20.   protected $date;
  21.   /**
  22.    * @var float
  23.    *
  24.    * @ORM\Column(name="percentage", type="decimal", precision=3, scale=2)
  25.    */
  26.   protected $percentage;
  27.   /**
  28.    * @var float
  29.    *
  30.    * @ORM\Column(name="min_price", type="decimal", precision=8, scale=2)
  31.    */
  32.   protected $minPrice;
  33.   /**
  34.    * @var integer
  35.    * @ORM\Column(type="smallint")
  36.    */
  37.   protected $days;
  38.   function __construct()
  39.   {
  40.     $this->days 1;
  41.   }
  42.   /**
  43.    * Gets the value of date.
  44.    *
  45.    * @return \DateTime
  46.    */
  47.   public function getDate()
  48.   {
  49.       return $this->date;
  50.   }
  51.   /**
  52.    * Sets the value of date.
  53.    *
  54.    * @param \DateTime $date the date
  55.    *
  56.    * @return self
  57.    */
  58.   public function setDate(\DateTime $date)
  59.   {
  60.       $this->date $date;
  61.       return $this;
  62.   }
  63.   /**
  64.    * Gets the value of percentage.
  65.    *
  66.    * @return integer
  67.    */
  68.   public function getPercentage()
  69.   {
  70.       return $this->percentage;
  71.   }
  72.   /**
  73.    * Sets the value of percentage.
  74.    *
  75.    * @param integer $percentage the percentage
  76.    *
  77.    * @return self
  78.    */
  79.   public function setPercentage($percentage)
  80.   {
  81.       $this->percentage $percentage;
  82.       return $this;
  83.   }
  84.   /**
  85.    * @ORM\PrePersist
  86.    * @ORM\PreUpdate
  87.    */
  88.   public function calculateMinPrice()
  89.   {
  90.     $this->minPrice null;
  91.     foreach ($this->prices as $roomPrice) {
  92.       foreach ($roomPrice as $boardTypePrice) {
  93.         if (is_numeric($boardTypePrice) && 
  94.             ( $this->minPrice == null ||
  95.               ($boardTypePrice $this->days) < $this->minPrice) ) {
  96.           $this->minPrice $boardTypePrice /$this->days;
  97.         }
  98.       }
  99.     }
  100.   }
  101.     /**
  102.      * Set minPrice
  103.      *
  104.      * @param string $minPrice
  105.      *
  106.      * @return self
  107.      */
  108.     public function setMinPrice($minPrice)
  109.     {
  110.         $this->minPrice $minPrice;
  111.         return $this;
  112.     }
  113.     /**
  114.      * Get minPrice
  115.      *
  116.      * @return string
  117.      */
  118.     public function getMinPrice()
  119.     {
  120.         return $this->minPrice;
  121.     }
  122.     public static function getModel($options null)
  123.     {
  124.       if ($options === null) throw new Exception("Options cannot be null");
  125.       $hotel $options['hotel'];
  126.       $boardPrices = [
  127.           Hotel::BOARD_ACCOMODATION_ONLY => '',
  128.           Hotel::BOARD_BREAKFAST => '',
  129.           Hotel::BOARD_HALF => '',
  130.           Hotel::BOARD_FULL => '',
  131.         ];
  132.       //We set a place for per person prices
  133.       $model = [];
  134.       $model[self::PRICE_KEY_PAX] = $boardPrices;
  135.       foreach ($hotel->getRooms() as $key => $room) {
  136.         $roomType = isset($room["type"]) ? $room["type"] : $key;
  137.         $model[$roomType] = $boardPrices;
  138.       }
  139.       $model[self::PRICE_KEY_GROUP] = $boardPrices;
  140.       return $model;
  141.     }
  142.     /**
  143.      * Gets the value of days.
  144.      *
  145.      * @return integer
  146.      */
  147.     public function getDays()
  148.     {
  149.         return $this->days;
  150.     }
  151.     /**
  152.      * Sets the value of days.
  153.      *
  154.      * @param integer $days the days
  155.      *
  156.      * @return self
  157.      */
  158.     public function setDays($days)
  159.     {
  160.         $this->days $days;
  161.         return $this;
  162.     }
  163.     public function type()
  164.     {
  165.       if (!$this->prices) return null;
  166.       $paxPrices = isset($this->prices[self::PRICE_KEY_PAX]) ? $this->prices[self::PRICE_KEY_PAX]: [];
  167.       $groupPrices = isset($this->prices[self::PRICE_KEY_GROUP]) ? $this->prices[self::PRICE_KEY_GROUP]: [];
  168.       foreach ($paxPrices as $price) {
  169.         if (intval($price) > 0) return self::PRICE_TYPE_PAX;
  170.       }
  171.       foreach ($groupPrices as $price) {
  172.         if (intval($price) > 0) return self::PRICE_TYPE_GROUP;
  173.       }
  174.       return self::PRICE_TYPE_ROOM;
  175.     }
  176. }