src/Uniski/ResourceBundle/Entity/Hotel.php line 16

Open in your IDE?
  1. <?php
  2. namespace Uniski\ResourceBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. use Uniski\ResourceBundle\Entity\Address;
  7. use Uniski\ResourceBundle\Entity\HotelRate;
  8. use Uniski\Utils\TeaserGenerator;
  9. /**
  10. * @ORM\Entity
  11. * @ORM\Table("hotel", indexes={@ORM\Index(name="source_code_idx", columns={"source_code"})})
  12. */
  13. class Hotel implements RateableInterface
  14. {
  15.   const STOCK_STOCK_KEY 'Cupos';
  16.   const STOCK_RELEASE_KEY 'Release';
  17.   const RESTRICTION_MIN_NIGHTS_KEY 'Min noches';
  18.   const BOARD_ACCOMODATION_ONLY 'SA';
  19.   const BOARD_BREAKFAST 'AD';
  20.   const BOARD_HALF 'MP';
  21.   const BOARD_FULL 'PC';
  22.   const FILTER_SCORE_EXTRAORDINARY 3;
  23.   const FILTER_SCORE_VERY_GOOD 2;
  24.   const FILTER_SCORE_GOOD 1;
  25.   const FILTER_SCORE_NULL 0;
  26.   /**
  27.    * @var integer
  28.    *
  29.    * @ORM\Id
  30.    * @ORM\Column(name="id", type="integer")
  31.    * @ORM\GeneratedValue(strategy="IDENTITY")
  32.    */
  33.   protected $id;
  34.   /**
  35.    * @var   \Doctrine\Common\Collections\ArrayCollection
  36.    * @ORM\ManyToMany(targetEntity="Image", cascade={"all"})
  37.    * @ORM\JoinTable(name="hotel_images",
  38.    *   joinColumns={@ORM\JoinColumn(name="hotel_id", referencedColumnName="id", onDelete="CASCADE")},
  39.    *   inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")})
  40.    */
  41.   protected $images;
  42.   /**
  43.    * @var   \Uniski\ResourceBundle\Entity\Image
  44.    * @ORM\ManyToOne(targetEntity="Image", cascade={"all"})
  45.    */
  46.   protected $mainImage;
  47.   /**
  48.    * @var   \Doctrine\Common\Collections\ArrayCollection
  49.    * @ORM\ManyToMany(targetEntity="Uniski\ConfigBundle\Entity\Category")
  50.    * @ORM\JoinTable(name="hotel_tags",
  51.    *   joinColumns={@ORM\JoinColumn(name="hotel_id", referencedColumnName="id")},
  52.    *   inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")})
  53.    *
  54.    * Low cost, De lujo, Familias, Recomendado
  55.    */
  56.   protected $tags;
  57.   /**
  58.    * @var   \Doctrine\Common\Collections\ArrayCollection
  59.    * @ORM\ManyToMany(targetEntity="Shop")
  60.    * @ORM\JoinTable(name="hotel_shops",
  61.    *   joinColumns={@ORM\JoinColumn(name="hotel_id", referencedColumnName="id")},
  62.    *   inverseJoinColumns={@ORM\JoinColumn(name="shop_id", referencedColumnName="id")})
  63.    */
  64.   protected $shops;
  65.   /**
  66.    * @var   \Doctrine\Common\Collections\ArrayCollection
  67.    * @ORM\ManyToOne(targetEntity="Uniski\ConfigBundle\Entity\Category")
  68.    *
  69.    * Aparthotel, Alberge, Apartamento, Hotel, Hostal, Otros
  70.    */
  71.   protected $hotelType;
  72.   /**
  73.    * @var   \Doctrine\Common\Collections\ArrayCollection
  74.    * @ORM\ManyToMany(targetEntity="HotelRate", cascade={"all"}, orphanRemoval=true)
  75.    * @ORM\JoinTable(name="hotel_rates",
  76.    *   joinColumns={@ORM\JoinColumn(name="hotel_id", referencedColumnName="id")},
  77.    *   inverseJoinColumns={@ORM\JoinColumn(name="rate_id", referencedColumnName="id")})
  78.    */
  79.   protected $rates;
  80.   /**
  81.    * @var  string
  82.    * @ORM\Column(name="name", type="string")
  83.    */
  84.   protected $name;
  85.   /**
  86.    * @var integer
  87.    * @ORM\Column(name="stars", type="integer")
  88.    */
  89.   protected $stars;
  90.   /**
  91.    * @var Uniski\ConfigBundle\Entity\Category
  92.    * @ORM\ManyToOne(targetEntity="Uniski\ConfigBundle\Entity\Category")
  93.    *
  94.    */
  95.   protected $zone;
  96.   /**
  97.    * @var Address
  98.    * @ORM\ManyToOne(targetEntity="Address", cascade={"all"})
  99.    */
  100.   protected $address;
  101.   /**
  102.    * @var  string
  103.    * @ORM\Column(name="phone", type="string", nullable=true)
  104.    */
  105.   protected $phone;
  106.   /**
  107.    * @var  float
  108.    * @ORM\Column(name="score", type="decimal", precision=4, scale=2, nullable=true)
  109.    */
  110.   protected $score;
  111.   /**
  112.    * @var  string
  113.    * @ORM\Column(name="description", type="text")
  114.    */
  115.   protected $description;
  116.   /**
  117.    * @var  string
  118.    * @ORM\Column(name="area_description", type="text", nullable=true)
  119.    */
  120.   protected $areaDescription;
  121.   /**
  122.    * @var  string
  123.    * @ORM\Column(name="room_description", type="text", nullable=true)
  124.    */
  125.   protected $roomDescription;
  126.   /**
  127.    * @var  string
  128.    * @ORM\Column(name="service_description", type="text", nullable=true)
  129.    */
  130.   protected $serviceDescription;
  131.   /**
  132.    * @var  string
  133.    * @ORM\Column(name="restaurant_description", type="text", nullable=true)
  134.    */
  135.   protected $restaurantDescription;
  136.   /**
  137.    * @var  string
  138.    * @ORM\Column(name="comments", type="text", nullable=true)
  139.    */
  140.   protected $comments;
  141.   /**
  142.    * @var  array
  143.    * @ORM\Column(name="seo", type="json", nullable=true)
  144.    */
  145.   protected $seo;
  146.   /**
  147.    * @var  array
  148.    * @ORM\Column(name="bookingConditions", type="json", nullable=true)
  149.    *
  150.    * Descuento 3r adulto, descuento 4rt adulto,
  151.    * suplemento individual, descuento niño,
  152.    * niño gratis de 0 a [edat]
  153.    * niño descuento hasta [edat]
  154.    */
  155.   protected $bookingConditions;
  156.   /**
  157.    * @var   \Doctrine\Common\Collections\ArrayCollection
  158.    * @ORM\OneToMany(targetEntity="RoomStock", mappedBy="hotel", cascade={"all"})
  159.    */
  160.   protected $stocks;
  161.   /**
  162.    * @var array
  163.    * @ORM\Column(name="rooms", type="json", nullable=true)
  164.    * Individual, doble, triple, cuadruple, etc.
  165.    */
  166.   protected $rooms;
  167.   /**
  168.    * @Gedmo\Slug(fields={"name"})
  169.    * @ORM\Column(length=128, unique=true)
  170.    */
  171.   private $slug;
  172.   /**
  173.    * @var \Doctrine\Common\Collections\ArrayCollection
  174.    * @ORM\ManyToMany(targetEntity="Product", inversedBy="hotels")
  175.    * @ORM\JoinTable(name="hotel_product")
  176.    */
  177.   protected $products;
  178.   /**
  179.    * @var string
  180.    * @ORM\Column(name="email", type="string", nullable=true)
  181.    */
  182.   protected $email;
  183.   /**
  184.    * @var boolean
  185.    * @ORM\Column(name="highlighted", type="boolean")
  186.    */
  187.   protected $highlighted;
  188.   /**
  189.    * @var integer
  190.    * @ORM\Column(name="position", type="integer")
  191.    */
  192.   protected $position;
  193.   /**
  194.    * @var boolean
  195.    * @ORM\Column(name="searchable", type="boolean")
  196.    */
  197.   protected $searchable;
  198.   /**
  199.    * @var \DateTime $created
  200.    *
  201.    * @Gedmo\Timestampable(on="create")
  202.    * @ORM\Column(type="datetime")
  203.    */
  204.   private $created;
  205.   /**
  206.    * @var \DateTime $updated
  207.    *
  208.    * @Gedmo\Timestampable
  209.    * @ORM\Column(type="datetime")
  210.    */
  211.   private $updated;
  212.   /**
  213.    * @var  string
  214.    * @ORM\Column(type="text", nullable=true)
  215.    */
  216.   private $bondInstructions;
  217.   /**
  218.    * @var   \Doctrine\Common\Collections\ArrayCollection
  219.    * @ORM\OneToMany(targetEntity="RoomRestriction", mappedBy="hotel", cascade={"all"})
  220.    */
  221.   protected $restrictions;
  222.   /**
  223.    * @ORM\Column(type="smallint", nullable=true)
  224.    */
  225.   protected $priority;
  226.   /**
  227.    * @ORM\Column(type="boolean")
  228.    */
  229.   protected $external;
  230.   /**
  231.    * @ORM\Column(type="string", length=30, nullable=true)
  232.    */
  233.   protected $source;
  234.   /**
  235.    * @ORM\Column(type="string", length=20, nullable=true)
  236.    */
  237.   protected $sourceCode;
  238.   /**
  239.    * @var string
  240.    * @ORM\Column(type="text", nullable=true)
  241.    */
  242.   protected $cancellationPolicy;
  243.   /**
  244.    * @var  float
  245.    * @ORM\Column(name="commission", type="decimal", precision=4, scale=2, nullable=true)
  246.    */
  247.   protected $commissionPercentage;
  248.   /**
  249.    * Calculated rates from other processes
  250.    * in order to avoid multiple requests to booking APIs
  251.    * @var array
  252.    */
  253.   protected $calculatedBookingRates;
  254.   public function setCalculatedBookingRates($rates)
  255.   {
  256.     $this->calculatedBookingRates $rates;
  257.     return $this;
  258.   }
  259.   public function calculatedBookingRates()
  260.   {
  261.     return $this->calculatedBookingRates;
  262.   }
  263.   public function clearCalculatedBookingRates()
  264.   {
  265.     $this->calculatedBookingRates null;
  266.   }
  267.     /**
  268.      * Get id
  269.      *
  270.      * @return integer
  271.      */
  272.     public function getId()
  273.     {
  274.         return $this->id;
  275.     }
  276.     /**
  277.      * Constructor
  278.      */
  279.     public function __construct()
  280.     {
  281.         $this->images = new \Doctrine\Common\Collections\ArrayCollection();
  282.         $this->tags = new \Doctrine\Common\Collections\ArrayCollection();
  283.         $this->shops = new \Doctrine\Common\Collections\ArrayCollection();
  284.         $this->rates = new \Doctrine\Common\Collections\ArrayCollection();
  285.         $this->products = new \Doctrine\Common\Collections\ArrayCollection();
  286.         $this->highlighted false;
  287.         $this->position 0;
  288.         $this->searchable true;
  289.         $this->stars 0;
  290.         $this->external false;
  291.   
  292.         $this->rooms = [
  293.           "0" => ['name' => 'Habitación doble uso individual''capacity' => 1],
  294.           "1" => ['name' => 'Habitación doble''capacity'  => 2],
  295.           "2" => ['name' => 'Habitación triple''capacity'  => 3],
  296.           "3" => ['name' => 'Habitación cuadruple''capacity'  => 4]
  297.         ];
  298.     }
  299.     /**
  300.      * Set name
  301.      *
  302.      * @param string $name
  303.      *
  304.      * @return Hotel
  305.      */
  306.     public function setName($name)
  307.     {
  308.         $this->name $name;
  309.         return $this;
  310.     }
  311.     /**
  312.      * Get name
  313.      *
  314.      * @return string
  315.      */
  316.     public function getName()
  317.     {
  318.         return $this->name;
  319.     }
  320.     /**
  321.      * Set stars
  322.      *
  323.      * @param integer $stars
  324.      *
  325.      * @return Hotel
  326.      */
  327.     public function setStars($stars)
  328.     {
  329.         $this->stars $stars;
  330.         return $this;
  331.     }
  332.     /**
  333.      * Get stars
  334.      *
  335.      * @return integer
  336.      */
  337.     public function getStars()
  338.     {
  339.         return $this->stars;
  340.     }
  341.     /**
  342.      * Set city
  343.      *
  344.      * @param string $city
  345.      *
  346.      * @return Hotel
  347.      */
  348.     public function setCity($city)
  349.     {
  350.         $this->city $city;
  351.         return $this;
  352.     }
  353.     /**
  354.      * Get city
  355.      *
  356.      * @return string
  357.      */
  358.     public function getCity()
  359.     {
  360.         return $this->city;
  361.     }
  362.     /**
  363.      * Set address
  364.      *
  365.      * @param Address $address
  366.      *
  367.      * @return Hotel
  368.      */
  369.     public function setAddress(Address $address)
  370.     {
  371.         $this->address $address;
  372.         return $this;
  373.     }
  374.     public function removeAddress()
  375.     {
  376.       $this->address null;
  377.       return $this;
  378.     }
  379.     /**
  380.      * Get address
  381.      *
  382.      * @return Address
  383.      */
  384.     public function getAddress()
  385.     {
  386.         return $this->address;
  387.     }
  388.     /**
  389.      * Set location
  390.      *
  391.      * @param array $location
  392.      *
  393.      * @return Hotel
  394.      */
  395.     public function setLocation($location)
  396.     {
  397.         $this->location $location;
  398.         return $this;
  399.     }
  400.     /**
  401.      * Get location
  402.      *
  403.      * @return array
  404.      */
  405.     public function getLocation()
  406.     {
  407.         return $this->location;
  408.     }
  409.     /**
  410.      * Set phone
  411.      *
  412.      * @param string $phone
  413.      *
  414.      * @return Hotel
  415.      */
  416.     public function setPhone($phone)
  417.     {
  418.         $this->phone $phone;
  419.         return $this;
  420.     }
  421.     /**
  422.      * Get phone
  423.      *
  424.      * @return string
  425.      */
  426.     public function getPhone()
  427.     {
  428.         return $this->phone;
  429.     }
  430.     /**
  431.      * Set score
  432.      *
  433.      * @param string $score
  434.      *
  435.      * @return Hotel
  436.      */
  437.     public function setScore($score)
  438.     {
  439.         $this->score $score;
  440.         return $this;
  441.     }
  442.     /**
  443.      * Get score
  444.      *
  445.      * @return string
  446.      */
  447.     public function getScore()
  448.     {
  449.         return $this->score;
  450.     }
  451.     /**
  452.      * Set description
  453.      *
  454.      * @param string $description
  455.      *
  456.      * @return Hotel
  457.      */
  458.     public function setDescription($description)
  459.     {
  460.         $this->description $description;
  461.         return $this;
  462.     }
  463.     /**
  464.      * Get description
  465.      *
  466.      * @return string
  467.      */
  468.     public function getDescription()
  469.     {
  470.         return $this->description;
  471.     }
  472.     /**
  473.      * Set areaDescription
  474.      *
  475.      * @param string $areaDescription
  476.      *
  477.      * @return Hotel
  478.      */
  479.     public function setAreaDescription($areaDescription)
  480.     {
  481.         $this->areaDescription $areaDescription;
  482.         return $this;
  483.     }
  484.     /**
  485.      * Get areaDescription
  486.      *
  487.      * @return string
  488.      */
  489.     public function getAreaDescription()
  490.     {
  491.         return $this->areaDescription;
  492.     }
  493.     /**
  494.      * Set roomDescription
  495.      *
  496.      * @param string $roomDescription
  497.      *
  498.      * @return Hotel
  499.      */
  500.     public function setRoomDescription($roomDescription)
  501.     {
  502.         $this->roomDescription $roomDescription;
  503.         return $this;
  504.     }
  505.     /**
  506.      * Get roomDescription
  507.      *
  508.      * @return string
  509.      */
  510.     public function getRoomDescription()
  511.     {
  512.         return $this->roomDescription;
  513.     }
  514.     /**
  515.      * Set serviceDescription
  516.      *
  517.      * @param string $serviceDescription
  518.      *
  519.      * @return Hotel
  520.      */
  521.     public function setServiceDescription($serviceDescription)
  522.     {
  523.         $this->serviceDescription $serviceDescription;
  524.         return $this;
  525.     }
  526.     /**
  527.      * Get serviceDescription
  528.      *
  529.      * @return string
  530.      */
  531.     public function getServiceDescription()
  532.     {
  533.         return $this->serviceDescription;
  534.     }
  535.     /**
  536.      * Set restaurantDescription
  537.      *
  538.      * @param string $restaurantDescription
  539.      *
  540.      * @return Hotel
  541.      */
  542.     public function setRestaurantDescription($restaurantDescription)
  543.     {
  544.         $this->restaurantDescription $restaurantDescription;
  545.         return $this;
  546.     }
  547.     /**
  548.      * Get restaurantDescription
  549.      *
  550.      * @return string
  551.      */
  552.     public function getRestaurantDescription()
  553.     {
  554.         return $this->restaurantDescription;
  555.     }
  556.     /**
  557.      * Set comments
  558.      *
  559.      * @param string $comments
  560.      *
  561.      * @return Hotel
  562.      */
  563.     public function setComments($comments)
  564.     {
  565.         $this->comments $comments;
  566.         return $this;
  567.     }
  568.     /**
  569.      * Get comments
  570.      *
  571.      * @return string
  572.      */
  573.     public function getComments()
  574.     {
  575.         return $this->comments;
  576.     }
  577.     /**
  578.      * Set seo
  579.      *
  580.      * @param array $seo
  581.      *
  582.      * @return Hotel
  583.      */
  584.     public function setSeo($seo)
  585.     {
  586.         $this->seo $seo;
  587.         return $this;
  588.     }
  589.     /**
  590.      * Get seo
  591.      *
  592.      * @return array
  593.      */
  594.     public function getSeo()
  595.     {
  596.         $seo $this->seo;
  597.         
  598.         if (empty($seo['title']) && $this->name) {
  599.             $seo['title'] = sprintf("Ofertas esquí %s con Forfait"$this->name);
  600.         }
  601.         if (empty($seo['description']) && $this->name && $this->zone) {
  602.             $zone $this->zone->getName();
  603.             $seo['description'] = sprintf(
  604.                 "Las mejores ofertas de esquí %s . Hotel y forfait al mejor precio para disfrutar de tu viaje de esquí en %s",
  605.                 $this->name,                
  606.                 $zone
  607.             );
  608.         }
  609.         return $seo;
  610.     }
  611.     /**
  612.      * Set bookingConditions
  613.      *
  614.      * @param array $bookingConditions
  615.      *
  616.      * @return Hotel
  617.      */
  618.     public function setBookingConditions($bookingConditions)
  619.     {
  620.         $this->bookingConditions $bookingConditions;
  621.         return $this;
  622.     }
  623.     /**
  624.      * Get bookingConditions
  625.      *
  626.      * @return array
  627.      */
  628.     public function getBookingConditions()
  629.     {
  630.         return $this->bookingConditions;
  631.     }
  632.     /**
  633.      * Add image
  634.      *
  635.      * @param \Uniski\ResourceBundle\Entity\Image $image
  636.      *
  637.      * @return Hotel
  638.      */
  639.     public function addImage(\Uniski\ResourceBundle\Entity\Image $image)
  640.     {
  641.         $this->images[] = $image;
  642.         return $this;
  643.     }
  644.     /**
  645.      * Remove image
  646.      *
  647.      * @param \Uniski\ResourceBundle\Entity\Image $image
  648.      */
  649.     public function removeImage(\Uniski\ResourceBundle\Entity\Image $image)
  650.     {
  651.         $this->images->removeElement($image);
  652.     }
  653.     /**
  654.      * Get images
  655.      *
  656.      * @return \Doctrine\Common\Collections\Collection
  657.      */
  658.     public function getImages()
  659.     {
  660.         return $this->images;
  661.     }
  662.     /**
  663.      * Add tag
  664.      *
  665.      * @param \Uniski\ConfigBundle\Entity\Category $tag
  666.      *
  667.      * @return Hotel
  668.      */
  669.     public function addTag(\Uniski\ConfigBundle\Entity\Category $tag)
  670.     {
  671.         $this->tags[] = $tag;
  672.         return $this;
  673.     }
  674.     /**
  675.      * Remove tag
  676.      *
  677.      * @param \Uniski\ConfigBundle\Entity\Category $tag
  678.      */
  679.     public function removeTag(\Uniski\ConfigBundle\Entity\Category $tag)
  680.     {
  681.         $this->tags->removeElement($tag);
  682.     }
  683.     /**
  684.      * Get tags
  685.      *
  686.      * @return \Doctrine\Common\Collections\Collection
  687.      */
  688.     public function getTags()
  689.     {
  690.         return $this->tags;
  691.     }
  692.     /**
  693.      * Add shop
  694.      *
  695.      * @param \Uniski\ResourceBundle\Entity\Shop $shop
  696.      *
  697.      * @return Hotel
  698.      */
  699.     public function addShop(\Uniski\ResourceBundle\Entity\Shop $shop)
  700.     {
  701.         $this->shops[] = $shop;
  702.         return $this;
  703.     }
  704.     /**
  705.      * Remove shop
  706.      *
  707.      * @param \Uniski\ResourceBundle\Entity\Shop $shop
  708.      */
  709.     public function removeShop(\Uniski\ResourceBundle\Entity\Shop $shop)
  710.     {
  711.         $this->shops->removeElement($shop);
  712.     }
  713.     /**
  714.      * Get shops
  715.      *
  716.      * @return \Doctrine\Common\Collections\Collection
  717.      */
  718.     public function getShops()
  719.     {
  720.         return $this->shops;
  721.     }
  722.     /**
  723.      * Set hotelType
  724.      *
  725.      * @param \Uniski\ConfigBundle\Entity\Category $hotelType
  726.      *
  727.      * @return Hotel
  728.      */
  729.     public function setHotelType(\Uniski\ConfigBundle\Entity\Category $hotelType null)
  730.     {
  731.         $this->hotelType $hotelType;
  732.         return $this;
  733.     }
  734.     /**
  735.      * Get hotelType
  736.      *
  737.      * @return \Uniski\ConfigBundle\Entity\Category
  738.      */
  739.     public function getHotelType()
  740.     {
  741.         return $this->hotelType;
  742.     }
  743.     /**
  744.      * Add rate
  745.      *
  746.      * @param \Uniski\ResourceBundle\Entity\PriceRate $rate
  747.      *
  748.      * @return Hotel
  749.      */
  750.     public function setRate(ArrayCollection $rates)
  751.     {
  752.         $this->rates $rates;
  753.         return $this;
  754.     }
  755.     /**
  756.      * Add rate
  757.      *
  758.      * @param \Uniski\ResourceBundle\Entity\PriceRate $rate
  759.      *
  760.      * @return Hotel
  761.      */
  762.     public function addRate(\Uniski\ResourceBundle\Entity\PriceRate $rate)
  763.     {
  764.         $this->rates[] = $rate;
  765.         return $this;
  766.     }
  767.     /**
  768.      * Remove rate
  769.      *
  770.      * @param \Uniski\ResourceBundle\Entity\PriceRate $rate
  771.      */
  772.     public function removeRate(\Uniski\ResourceBundle\Entity\PriceRate $rate)
  773.     {
  774.         $this->rates->removeElement($rate);
  775.     }
  776.     /**
  777.      * Get rates
  778.      *
  779.      * @return \Doctrine\Common\Collections\Collection
  780.      */
  781.     public function getRates()
  782.     {
  783.         return $this->rates;
  784.     }
  785.     /**
  786.      * Set zone
  787.      *
  788.      * @param \Uniski\ConfigBundle\Entity\Category $zone
  789.      *
  790.      * @return Hotel
  791.      */
  792.     public function setZone(\Uniski\ConfigBundle\Entity\Category $zone null)
  793.     {
  794.         $this->zone $zone;
  795.         return $this;
  796.     }
  797.     /**
  798.      * Get zone
  799.      *
  800.      * @return \Uniski\ConfigBundle\Entity\Category
  801.      */
  802.     public function getZone()
  803.     {
  804.         return $this->zone;
  805.     }
  806.     /**
  807.      * Add stock
  808.      *
  809.      * @param \Uniski\ResourceBundle\Entity\RoomStock $stock
  810.      *
  811.      * @return Hotel
  812.      */
  813.     public function addStock(\Uniski\ResourceBundle\Entity\RoomStock $stock)
  814.     {
  815.       //Avoid duplicates, if we are adding an stock where date and roomtype are
  816.       //the same, update the old stock entity
  817.       foreach ($this->stocks as $oldStock) {
  818.         if ($oldStock->getDate()->getTimestamp() === $stock->getDate()->getTimestamp() &&
  819.             $oldStock->getRoomType() === $stock->getRoomType()) {
  820.           $oldStock->setStock($stock->getStock());
  821.           $oldStock->setRoomType($stock->getRoomType());
  822.             $oldStock->setBoardplan($stock->getBoardplan());
  823.           return $this;
  824.         }
  825.       }
  826.       $this->stocks[] = $stock;
  827.       return $this;
  828.     }
  829.     /**
  830.      * Remove stock
  831.      *
  832.      * @param \Uniski\ResourceBundle\Entity\RoomStock $stock
  833.      */
  834.     public function removeStock(\Uniski\ResourceBundle\Entity\RoomStock $stock)
  835.     {
  836.         $this->stocks->removeElement($stock);
  837.     }
  838.     /**
  839.      * Get stocks
  840.      *
  841.      * @return \Doctrine\Common\Collections\Collection
  842.      */
  843.     public function getStocks()
  844.     {
  845.         return $this->stocks;
  846.     }
  847.     public function removeAllStock()
  848.     {
  849.       $this->stocks->removeAll();
  850.       return $this;
  851.     }
  852.     public function setStocks(ArrayCollection $stocks)
  853.     {
  854.       $this->stocks $stocks;
  855.     }
  856.     /**
  857.      * Add room
  858.      *
  859.      * @param array $room
  860.      *
  861.      * @return Hotel
  862.      */
  863.     public function setRooms($room)
  864.     {
  865.         $this->rooms $room;
  866.         return $this;
  867.     }
  868.     /**
  869.      * Get rooms
  870.      * 
  871.      * It keeps legacy roomTypes which they were only the array key index
  872.      *
  873.      * @return array
  874.      */
  875.     public function getRooms()
  876.     {
  877.         if ($this->getSource() === "HOTELBEDS" &&
  878.             $this->calculatedBookingRates()
  879.         ) {
  880.             if (!$this->calculatedBookingRates['rooms']) return null;
  881.             $rooms = [];
  882.             $indice=0;
  883.             /**
  884.              * 04/11/2019 NOTA AR: Por cada habitación de hotelbeds, le asigno la capacidad de la habitación y el rateKey
  885.              */
  886.             foreach ($this->calculatedBookingRates['rooms'] as $room) {
  887.                 $net=0;
  888.                 $children=0;
  889.                 $adults=0;
  890.                 foreach ($room['rates'] as $key => $rate) {
  891.                     if ($net == || $net == $rate['net'] || $children != $rate['children'] || $adults != $rate['adults']) {
  892.                         $net $rate['net'];
  893.                         $children=$rate['children'];
  894.                         $adults=$rate['adults'];
  895.                         $numMax $rate['children'] + $rate['adults'];
  896.                         $rooms[$indice] = $room;
  897.                         $rooms[$indice]['capacity'] = $numMax;
  898.                         $rooms[$indice]['maxCapacity'] = $numMax;
  899.                         $rooms[$indice]['rateKey'] = $rate['rateKey'];
  900.                         if (empty($rooms[$indice]['type'])) $rooms[$indice]['type'] = $room['code'];
  901.                         $indice += 1;
  902.                     }
  903.                 }
  904.             }
  905.         }
  906.         else
  907.         {
  908.             if (!$this->rooms) return null;
  909.             $rooms = [];
  910.             foreach ($this->rooms as $key => $room) {
  911.                 $rooms[$key] = $room;
  912.                 if (empty($rooms[$key]['type'])) $rooms[$key]['type'] = $key;
  913.             }
  914.         }
  915.         return $rooms;
  916.     }
  917.     /**
  918.      * Get room by roomType
  919.      * 
  920.      * It keeps legacy roomTypes which they were only the array key index
  921.      *
  922.      * @return array
  923.      */
  924.     public function getRoom($roomType)
  925.     {
  926.         $rooms $this->getRooms();
  927.         if (!$rooms) return null;
  928.         foreach ($this->rooms as $key => $room) {
  929.             
  930.             $currentRoomType $key;
  931.             if (isset($room['type'])) $currentRoomType $room['type'];
  932.             if ($currentRoomType == $roomType ) {
  933.                 return $room;
  934.             }
  935.         }
  936.         return $rooms;
  937.     }
  938.     /**
  939.      * Set slug
  940.      *
  941.      * @param string $slug
  942.      *
  943.      * @return Hotel
  944.      */
  945.     public function setSlug($slug)
  946.     {
  947.         $this->slug $slug;
  948.         return $this;
  949.     }
  950.     /**
  951.      * Get slug
  952.      *
  953.      * @return string
  954.      */
  955.     public function getSlug()
  956.     {
  957.         return $this->slug;
  958.     }
  959.     /**
  960.      * Set mainImage
  961.      *
  962.      * @param \Uniski\ResourceBundle\Entity\Image $mainImage
  963.      *
  964.      * @return Hotel
  965.      */
  966.     public function setMainImage(\Uniski\ResourceBundle\Entity\Image $mainImage null)
  967.     {
  968.         $this->mainImage $mainImage;
  969.         return $this;
  970.     }
  971.     /**
  972.      * Get mainImage
  973.      *
  974.      * @return \Uniski\ResourceBundle\Entity\Image
  975.      */
  976.     public function getMainImage()
  977.     {
  978.         return $this->mainImage;
  979.     }
  980.     /**
  981.      * Add product
  982.      *
  983.      * @return Hotel
  984.      */
  985.     public function addProduct(\Uniski\ResourceBundle\Entity\Product $product)
  986.     {
  987.         if($this->products->contains($product)) return;
  988.         $this->products[] = $product;
  989.         $product->addHotel($this);
  990.     }
  991.     /**
  992.      * Remove product
  993.      *
  994.      * @param \Uniski\ResourceBundle\Entity\Product $product
  995.      */
  996.     public function removeProduct(\Uniski\ResourceBundle\Entity\Product $product)
  997.     {
  998.         if(!$this->products->contains($product)) return;
  999.         $this->products->removeElement($product);
  1000.         $product->removeHotel($this);
  1001.     }
  1002.     /**
  1003.      * Get products
  1004.      *
  1005.      * @return \Doctrine\Common\Collections\Collection
  1006.      */
  1007.     public function getProducts()
  1008.     {
  1009.         return $this->products;
  1010.     }
  1011.     /**
  1012.      * Gets the value of email.
  1013.      *
  1014.      * @return string
  1015.      */
  1016.     public function getEmail()
  1017.     {
  1018.         return $this->email;
  1019.     }
  1020.     /**
  1021.      * Sets the value of email.
  1022.      *
  1023.      * @param string $email the email
  1024.      *
  1025.      * @return self
  1026.      */
  1027.     public function setEmail($email)
  1028.     {
  1029.         $this->email $email;
  1030.         return $this;
  1031.     }
  1032.     /**
  1033.      * Set highlighted
  1034.      *
  1035.      * @param boolean $highlighted
  1036.      *
  1037.      * @return Hotel
  1038.      */
  1039.     public function setHighlighted($highlighted)
  1040.     {
  1041.         $this->highlighted $highlighted;
  1042.         return $this;
  1043.     }
  1044.     /**
  1045.      * Get highlighted
  1046.      *
  1047.      * @return boolean
  1048.      */
  1049.     public function getHighlighted()
  1050.     {
  1051.         return $this->highlighted;
  1052.     }
  1053.     /**
  1054.      * Set position
  1055.      *
  1056.      * @param integer $position
  1057.      *
  1058.      * @return Hotel
  1059.      */
  1060.     public function setPosition($position)
  1061.     {
  1062.         $this->position $position;
  1063.         return $this;
  1064.     }
  1065.     /**
  1066.      * Get position
  1067.      *
  1068.      * @return integer
  1069.      */
  1070.     public function getPosition()
  1071.     {
  1072.         return $this->position;
  1073.     }
  1074.     public function getStockModel()
  1075.     {
  1076.       $model = [];
  1077.       foreach ($this->getRooms() as $key => $room) {
  1078.         //Backwards compatibility with legacy roomType index
  1079.         $roomType = isset($room['type']) ?
  1080.             $roomType $room['type']:
  1081.             $key;
  1082.         $model[$roomType] = [
  1083.           self::STOCK_STOCK_KEY => 0,
  1084.           self::STOCK_RELEASE_KEY => 0,
  1085.         ];
  1086.       }
  1087.       return $model;
  1088.     }
  1089.     public function getRestrictionModel()
  1090.     {
  1091.       $model = [];
  1092.       foreach ($this->getRooms() as $key => $room) {
  1093.         //Backwards compatibility with legacy roomType index
  1094.         $roomType = isset($room['type']) ?
  1095.             $roomType $room['type']:
  1096.             $key;
  1097.         $model[$roomType] = [
  1098.           self::RESTRICTION_MIN_NIGHTS_KEY => 0,
  1099.         ];
  1100.       }
  1101.       return $model;
  1102.     }
  1103.     protected $minPrice;
  1104.     /**
  1105.      * Gets the value of minPrice.
  1106.      *
  1107.      * @return mixed
  1108.      */
  1109.     public function getMinPrice()
  1110.     {
  1111.         return $this->minPrice;
  1112.     }
  1113.     /**
  1114.      * Sets the value of minPrice.
  1115.      *
  1116.      * @param mixed $minPrice the min price
  1117.      *
  1118.      * @return self
  1119.      */
  1120.     public function setMinPrice($minPrice)
  1121.     {
  1122.         $this->minPrice $minPrice;
  1123.         return $this;
  1124.     }
  1125.     public function isApartment()
  1126.     {
  1127.       if ( $this->getHotelType() &&
  1128.            in_array($this->getHotelType()->getName(),['Apartamento','Aparthotel','Residencia'])) {
  1129.             return true;
  1130.       }
  1131.       return false;
  1132.     }
  1133.     /**
  1134.      * Gets the value of searchable.
  1135.      *
  1136.      * @return boolean
  1137.      */
  1138.     public function getSearchable()
  1139.     {
  1140.         return $this->searchable;
  1141.     }
  1142.     /**
  1143.      * Sets the value of searchable.
  1144.      *
  1145.      * @param boolean $searchable the searchable
  1146.      *
  1147.      * @return self
  1148.      */
  1149.     public function setSearchable($searchable)
  1150.     {
  1151.         $this->searchable $searchable;
  1152.         return $this;
  1153.     }
  1154.     /**
  1155.      * Gets the value of created.
  1156.      *
  1157.      * @return \DateTime $created
  1158.      */
  1159.     public function getCreated()
  1160.     {
  1161.         return $this->created;
  1162.     }
  1163.     /**
  1164.      * Sets the value of created.
  1165.      *
  1166.      * @param \DateTime $created $created the created
  1167.      *
  1168.      * @return self
  1169.      */
  1170.     public function setCreated($created)
  1171.     {
  1172.         $this->created $created;
  1173.         return $this;
  1174.     }
  1175.     /**
  1176.      * Gets the value of updated.
  1177.      *
  1178.      * @return \DateTime $updated
  1179.      */
  1180.     public function getUpdated()
  1181.     {
  1182.         return $this->updated;
  1183.     }
  1184.     /**
  1185.      * Sets the value of updated.
  1186.      *
  1187.      * @param \DateTime $updated $updated the updated
  1188.      *
  1189.      * @return self
  1190.      */
  1191.     public function setUpdated($updated)
  1192.     {
  1193.         $this->updated $updated;
  1194.         return $this;
  1195.     }
  1196.     public function createRate()
  1197.     {
  1198.       return new HotelRate();
  1199.     }
  1200.     /**
  1201.      * Gets the value of bondInstructions.
  1202.      *
  1203.      * @return  string
  1204.      */
  1205.     public function getBondInstructions()
  1206.     {
  1207.         return $this->bondInstructions;
  1208.     }
  1209.     /**
  1210.      * Sets the value of bondInstructions.
  1211.      *
  1212.      * @param  string $bondInstructions the bond instructions
  1213.      *
  1214.      * @return self
  1215.      */
  1216.     public function setBondInstructions($bondInstructions)
  1217.     {
  1218.         $this->bondInstructions $bondInstructions;
  1219.         return $this;
  1220.     }
  1221.     /**
  1222.      * Add stock
  1223.      *
  1224.      * @param \Uniski\ResourceBundle\Entity\RoomRestriction $stock
  1225.      *
  1226.      * @return Hotel
  1227.      */
  1228.     public function addRestriction(RoomRestriction $restriction)
  1229.     {
  1230.       //Updated: avoid duplicates, if we are adding an stock where date and room type are
  1231.       //the same, update the old stock entity
  1232.       foreach ($this->restrictions as $oldRestriction) {
  1233.         if ($oldRestriction->getDate()->getTimestamp() === $restriction->getDate()->getTimestamp() &&
  1234.             strval($oldRestriction->getRoomType()) === strval($restriction->getRoomType())) {
  1235.           $oldRestriction->setMinNights($restriction->getMinNights());
  1236.           $oldRestriction->setRoomType($restriction->getRoomType());
  1237.           return $this;
  1238.         }
  1239.       }
  1240.       $this->restrictions[] = $restriction;
  1241.       return $this;
  1242.     }
  1243.     /**
  1244.      * Remove stock
  1245.      *
  1246.      * @param \Uniski\ResourceBundle\Entity\RoomRestriction $restriction
  1247.      */
  1248.     public function removeRestriction(RoomRestriction $restriction)
  1249.     {
  1250.         $this->restrictions->removeElement($restriction);
  1251.     }
  1252.     /**
  1253.      * Get restrictions
  1254.      *
  1255.      * @return \Doctrine\Common\Collections\Collection
  1256.      */
  1257.     public function getRestrictions()
  1258.     {
  1259.         return $this->restrictions;
  1260.     }
  1261.     public function removeAllRestrictions()
  1262.     {
  1263.       $this->restrictions->removeAll();
  1264.       return $this;
  1265.     }
  1266.     /**
  1267.      * @return mixed
  1268.      */
  1269.     public function getPriority()
  1270.     {
  1271.         return $this->priority;
  1272.     }
  1273.     /**
  1274.      * @param mixed $priority
  1275.      *
  1276.      * @return self
  1277.      */
  1278.     public function setPriority($priority)
  1279.     {
  1280.         $this->priority $priority;
  1281.         return $this;
  1282.     }
  1283.     /**
  1284.      * @return string
  1285.      */
  1286.     public function getCancellationPolicy()
  1287.     {
  1288.         return $this->cancellationPolicy;
  1289.     }
  1290.     /**
  1291.      * @param string $cancellationPolicy
  1292.      *
  1293.      * @return self
  1294.      */
  1295.     public function setCancellationPolicy($cancellationPolicy)
  1296.     {
  1297.         $this->cancellationPolicy $cancellationPolicy;
  1298.         return $this;
  1299.     }
  1300.     /**
  1301.      * @return mixed
  1302.      */
  1303.     public function getSource()
  1304.     {
  1305.         return $this->source;
  1306.     }
  1307.     /**
  1308.      * @param mixed $source
  1309.      *
  1310.      * @return self
  1311.      */
  1312.     public function setSource($source)
  1313.     {
  1314.         $this->source $source;
  1315.         return $this;
  1316.     }
  1317.     /**
  1318.      * @return mixed
  1319.      */
  1320.     public function getSourceCode()
  1321.     {
  1322.         return $this->sourceCode;
  1323.     }
  1324.     /**
  1325.      * @param mixed $sourceCode
  1326.      *
  1327.      * @return self
  1328.      */
  1329.     public function setSourceCode($sourceCode)
  1330.     {
  1331.         $this->sourceCode $sourceCode;
  1332.         return $this;
  1333.     }
  1334.     /**
  1335.      * @return  float
  1336.      */
  1337.     public function getCommissionPercentage()
  1338.     {
  1339.         return $this->commissionPercentage;
  1340.     }
  1341.     /**
  1342.      * @param  float $commissionPercentage
  1343.      *
  1344.      * @return self
  1345.      */
  1346.     public function setCommissionPercentage($commissionPercentage)
  1347.     {
  1348.         $this->commissionPercentage $commissionPercentage;
  1349.         return $this;
  1350.     }
  1351.     /**
  1352.      * @return mixed
  1353.      */
  1354.     public function isExternal()
  1355.     {
  1356.         return $this->external;
  1357.     }
  1358.     /**
  1359.      * @param mixed $external
  1360.      *
  1361.      * @return self
  1362.      */
  1363.     public function setExternal($external)
  1364.     {
  1365.         $this->external $external;
  1366.         return $this;
  1367.     }
  1368.     public function getDistanceFrom($longitude$latitude
  1369.     {
  1370.         if (!$this->getAddress() || !$this->getAddress()->hasCoordinates()) return 9999;
  1371.         
  1372.         $lat1 $this->getAddress()->getLatitude();
  1373.         $lon1 $this->getAddress()->getLongitude();
  1374.         $lat2 $latitude;
  1375.         $lon2 $longitude;
  1376.         if (($lat1 == $lat2) && ($lon1 == $lon2)) {
  1377.             return 0;
  1378.         }
  1379.         
  1380.         $theta $lon1 $lon2;
  1381.         $dist sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
  1382.         $dist acos($dist);
  1383.         $dist rad2deg($dist);
  1384.         $miles $dist 60 1.1515;
  1385.         return $miles 1.609344;
  1386.     }
  1387. }