<?php
namespace Uniski\ResourceBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Uniski\ResourceBundle\Entity\Address;
use Uniski\ResourceBundle\Entity\HotelRate;
use Uniski\Utils\TeaserGenerator;
/**
* @ORM\Entity
* @ORM\Table("hotel", indexes={@ORM\Index(name="source_code_idx", columns={"source_code"})})
*/
class Hotel implements RateableInterface
{
const STOCK_STOCK_KEY = 'Cupos';
const STOCK_RELEASE_KEY = 'Release';
const RESTRICTION_MIN_NIGHTS_KEY = 'Min noches';
const BOARD_ACCOMODATION_ONLY = 'SA';
const BOARD_BREAKFAST = 'AD';
const BOARD_HALF = 'MP';
const BOARD_FULL = 'PC';
const FILTER_SCORE_EXTRAORDINARY = 3;
const FILTER_SCORE_VERY_GOOD = 2;
const FILTER_SCORE_GOOD = 1;
const FILTER_SCORE_NULL = 0;
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToMany(targetEntity="Image", cascade={"all"})
* @ORM\JoinTable(name="hotel_images",
* joinColumns={@ORM\JoinColumn(name="hotel_id", referencedColumnName="id", onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")})
*/
protected $images;
/**
* @var \Uniski\ResourceBundle\Entity\Image
* @ORM\ManyToOne(targetEntity="Image", cascade={"all"})
*/
protected $mainImage;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToMany(targetEntity="Uniski\ConfigBundle\Entity\Category")
* @ORM\JoinTable(name="hotel_tags",
* joinColumns={@ORM\JoinColumn(name="hotel_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")})
*
* Low cost, De lujo, Familias, Recomendado
*/
protected $tags;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToMany(targetEntity="Shop")
* @ORM\JoinTable(name="hotel_shops",
* joinColumns={@ORM\JoinColumn(name="hotel_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="shop_id", referencedColumnName="id")})
*/
protected $shops;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToOne(targetEntity="Uniski\ConfigBundle\Entity\Category")
*
* Aparthotel, Alberge, Apartamento, Hotel, Hostal, Otros
*/
protected $hotelType;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToMany(targetEntity="HotelRate", cascade={"all"}, orphanRemoval=true)
* @ORM\JoinTable(name="hotel_rates",
* joinColumns={@ORM\JoinColumn(name="hotel_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="rate_id", referencedColumnName="id")})
*/
protected $rates;
/**
* @var string
* @ORM\Column(name="name", type="string")
*/
protected $name;
/**
* @var integer
* @ORM\Column(name="stars", type="integer")
*/
protected $stars;
/**
* @var Uniski\ConfigBundle\Entity\Category
* @ORM\ManyToOne(targetEntity="Uniski\ConfigBundle\Entity\Category")
*
*/
protected $zone;
/**
* @var Address
* @ORM\ManyToOne(targetEntity="Address", cascade={"all"})
*/
protected $address;
/**
* @var string
* @ORM\Column(name="phone", type="string", nullable=true)
*/
protected $phone;
/**
* @var float
* @ORM\Column(name="score", type="decimal", precision=4, scale=2, nullable=true)
*/
protected $score;
/**
* @var string
* @ORM\Column(name="description", type="text")
*/
protected $description;
/**
* @var string
* @ORM\Column(name="area_description", type="text", nullable=true)
*/
protected $areaDescription;
/**
* @var string
* @ORM\Column(name="room_description", type="text", nullable=true)
*/
protected $roomDescription;
/**
* @var string
* @ORM\Column(name="service_description", type="text", nullable=true)
*/
protected $serviceDescription;
/**
* @var string
* @ORM\Column(name="restaurant_description", type="text", nullable=true)
*/
protected $restaurantDescription;
/**
* @var string
* @ORM\Column(name="comments", type="text", nullable=true)
*/
protected $comments;
/**
* @var array
* @ORM\Column(name="seo", type="json", nullable=true)
*/
protected $seo;
/**
* @var array
* @ORM\Column(name="bookingConditions", type="json", nullable=true)
*
* Descuento 3r adulto, descuento 4rt adulto,
* suplemento individual, descuento niño,
* niño gratis de 0 a [edat]
* niño descuento hasta [edat]
*/
protected $bookingConditions;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\OneToMany(targetEntity="RoomStock", mappedBy="hotel", cascade={"all"})
*/
protected $stocks;
/**
* @var array
* @ORM\Column(name="rooms", type="json", nullable=true)
* Individual, doble, triple, cuadruple, etc.
*/
protected $rooms;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(length=128, unique=true)
*/
private $slug;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToMany(targetEntity="Product", inversedBy="hotels")
* @ORM\JoinTable(name="hotel_product")
*/
protected $products;
/**
* @var string
* @ORM\Column(name="email", type="string", nullable=true)
*/
protected $email;
/**
* @var boolean
* @ORM\Column(name="highlighted", type="boolean")
*/
protected $highlighted;
/**
* @var integer
* @ORM\Column(name="position", type="integer")
*/
protected $position;
/**
* @var boolean
* @ORM\Column(name="searchable", type="boolean")
*/
protected $searchable;
/**
* @var \DateTime $created
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @var \DateTime $updated
*
* @Gedmo\Timestampable
* @ORM\Column(type="datetime")
*/
private $updated;
/**
* @var string
* @ORM\Column(type="text", nullable=true)
*/
private $bondInstructions;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\OneToMany(targetEntity="RoomRestriction", mappedBy="hotel", cascade={"all"})
*/
protected $restrictions;
/**
* @ORM\Column(type="smallint", nullable=true)
*/
protected $priority;
/**
* @ORM\Column(type="boolean")
*/
protected $external;
/**
* @ORM\Column(type="string", length=30, nullable=true)
*/
protected $source;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
protected $sourceCode;
/**
* @var string
* @ORM\Column(type="text", nullable=true)
*/
protected $cancellationPolicy;
/**
* @var float
* @ORM\Column(name="commission", type="decimal", precision=4, scale=2, nullable=true)
*/
protected $commissionPercentage;
/**
* Calculated rates from other processes
* in order to avoid multiple requests to booking APIs
* @var array
*/
protected $calculatedBookingRates;
public function setCalculatedBookingRates($rates)
{
$this->calculatedBookingRates = $rates;
return $this;
}
public function calculatedBookingRates()
{
return $this->calculatedBookingRates;
}
public function clearCalculatedBookingRates()
{
$this->calculatedBookingRates = null;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Constructor
*/
public function __construct()
{
$this->images = new \Doctrine\Common\Collections\ArrayCollection();
$this->tags = new \Doctrine\Common\Collections\ArrayCollection();
$this->shops = new \Doctrine\Common\Collections\ArrayCollection();
$this->rates = new \Doctrine\Common\Collections\ArrayCollection();
$this->products = new \Doctrine\Common\Collections\ArrayCollection();
$this->highlighted = false;
$this->position = 0;
$this->searchable = true;
$this->stars = 0;
$this->external = false;
$this->rooms = [
"0" => ['name' => 'Habitación doble uso individual', 'capacity' => 1],
"1" => ['name' => 'Habitación doble', 'capacity' => 2],
"2" => ['name' => 'Habitación triple', 'capacity' => 3],
"3" => ['name' => 'Habitación cuadruple', 'capacity' => 4]
];
}
/**
* Set name
*
* @param string $name
*
* @return Hotel
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set stars
*
* @param integer $stars
*
* @return Hotel
*/
public function setStars($stars)
{
$this->stars = $stars;
return $this;
}
/**
* Get stars
*
* @return integer
*/
public function getStars()
{
return $this->stars;
}
/**
* Set city
*
* @param string $city
*
* @return Hotel
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set address
*
* @param Address $address
*
* @return Hotel
*/
public function setAddress(Address $address)
{
$this->address = $address;
return $this;
}
public function removeAddress()
{
$this->address = null;
return $this;
}
/**
* Get address
*
* @return Address
*/
public function getAddress()
{
return $this->address;
}
/**
* Set location
*
* @param array $location
*
* @return Hotel
*/
public function setLocation($location)
{
$this->location = $location;
return $this;
}
/**
* Get location
*
* @return array
*/
public function getLocation()
{
return $this->location;
}
/**
* Set phone
*
* @param string $phone
*
* @return Hotel
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set score
*
* @param string $score
*
* @return Hotel
*/
public function setScore($score)
{
$this->score = $score;
return $this;
}
/**
* Get score
*
* @return string
*/
public function getScore()
{
return $this->score;
}
/**
* Set description
*
* @param string $description
*
* @return Hotel
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set areaDescription
*
* @param string $areaDescription
*
* @return Hotel
*/
public function setAreaDescription($areaDescription)
{
$this->areaDescription = $areaDescription;
return $this;
}
/**
* Get areaDescription
*
* @return string
*/
public function getAreaDescription()
{
return $this->areaDescription;
}
/**
* Set roomDescription
*
* @param string $roomDescription
*
* @return Hotel
*/
public function setRoomDescription($roomDescription)
{
$this->roomDescription = $roomDescription;
return $this;
}
/**
* Get roomDescription
*
* @return string
*/
public function getRoomDescription()
{
return $this->roomDescription;
}
/**
* Set serviceDescription
*
* @param string $serviceDescription
*
* @return Hotel
*/
public function setServiceDescription($serviceDescription)
{
$this->serviceDescription = $serviceDescription;
return $this;
}
/**
* Get serviceDescription
*
* @return string
*/
public function getServiceDescription()
{
return $this->serviceDescription;
}
/**
* Set restaurantDescription
*
* @param string $restaurantDescription
*
* @return Hotel
*/
public function setRestaurantDescription($restaurantDescription)
{
$this->restaurantDescription = $restaurantDescription;
return $this;
}
/**
* Get restaurantDescription
*
* @return string
*/
public function getRestaurantDescription()
{
return $this->restaurantDescription;
}
/**
* Set comments
*
* @param string $comments
*
* @return Hotel
*/
public function setComments($comments)
{
$this->comments = $comments;
return $this;
}
/**
* Get comments
*
* @return string
*/
public function getComments()
{
return $this->comments;
}
/**
* Set seo
*
* @param array $seo
*
* @return Hotel
*/
public function setSeo($seo)
{
$this->seo = $seo;
return $this;
}
/**
* Get seo
*
* @return array
*/
public function getSeo()
{
$seo = $this->seo;
if (empty($seo['title']) && $this->name) {
$seo['title'] = sprintf("Ofertas esquí %s con Forfait", $this->name);
}
if (empty($seo['description']) && $this->name && $this->zone) {
$zone = $this->zone->getName();
$seo['description'] = sprintf(
"Las mejores ofertas de esquí %s . Hotel y forfait al mejor precio para disfrutar de tu viaje de esquí en %s",
$this->name,
$zone
);
}
return $seo;
}
/**
* Set bookingConditions
*
* @param array $bookingConditions
*
* @return Hotel
*/
public function setBookingConditions($bookingConditions)
{
$this->bookingConditions = $bookingConditions;
return $this;
}
/**
* Get bookingConditions
*
* @return array
*/
public function getBookingConditions()
{
return $this->bookingConditions;
}
/**
* Add image
*
* @param \Uniski\ResourceBundle\Entity\Image $image
*
* @return Hotel
*/
public function addImage(\Uniski\ResourceBundle\Entity\Image $image)
{
$this->images[] = $image;
return $this;
}
/**
* Remove image
*
* @param \Uniski\ResourceBundle\Entity\Image $image
*/
public function removeImage(\Uniski\ResourceBundle\Entity\Image $image)
{
$this->images->removeElement($image);
}
/**
* Get images
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getImages()
{
return $this->images;
}
/**
* Add tag
*
* @param \Uniski\ConfigBundle\Entity\Category $tag
*
* @return Hotel
*/
public function addTag(\Uniski\ConfigBundle\Entity\Category $tag)
{
$this->tags[] = $tag;
return $this;
}
/**
* Remove tag
*
* @param \Uniski\ConfigBundle\Entity\Category $tag
*/
public function removeTag(\Uniski\ConfigBundle\Entity\Category $tag)
{
$this->tags->removeElement($tag);
}
/**
* Get tags
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getTags()
{
return $this->tags;
}
/**
* Add shop
*
* @param \Uniski\ResourceBundle\Entity\Shop $shop
*
* @return Hotel
*/
public function addShop(\Uniski\ResourceBundle\Entity\Shop $shop)
{
$this->shops[] = $shop;
return $this;
}
/**
* Remove shop
*
* @param \Uniski\ResourceBundle\Entity\Shop $shop
*/
public function removeShop(\Uniski\ResourceBundle\Entity\Shop $shop)
{
$this->shops->removeElement($shop);
}
/**
* Get shops
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getShops()
{
return $this->shops;
}
/**
* Set hotelType
*
* @param \Uniski\ConfigBundle\Entity\Category $hotelType
*
* @return Hotel
*/
public function setHotelType(\Uniski\ConfigBundle\Entity\Category $hotelType = null)
{
$this->hotelType = $hotelType;
return $this;
}
/**
* Get hotelType
*
* @return \Uniski\ConfigBundle\Entity\Category
*/
public function getHotelType()
{
return $this->hotelType;
}
/**
* Add rate
*
* @param \Uniski\ResourceBundle\Entity\PriceRate $rate
*
* @return Hotel
*/
public function setRate(ArrayCollection $rates)
{
$this->rates = $rates;
return $this;
}
/**
* Add rate
*
* @param \Uniski\ResourceBundle\Entity\PriceRate $rate
*
* @return Hotel
*/
public function addRate(\Uniski\ResourceBundle\Entity\PriceRate $rate)
{
$this->rates[] = $rate;
return $this;
}
/**
* Remove rate
*
* @param \Uniski\ResourceBundle\Entity\PriceRate $rate
*/
public function removeRate(\Uniski\ResourceBundle\Entity\PriceRate $rate)
{
$this->rates->removeElement($rate);
}
/**
* Get rates
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRates()
{
return $this->rates;
}
/**
* Set zone
*
* @param \Uniski\ConfigBundle\Entity\Category $zone
*
* @return Hotel
*/
public function setZone(\Uniski\ConfigBundle\Entity\Category $zone = null)
{
$this->zone = $zone;
return $this;
}
/**
* Get zone
*
* @return \Uniski\ConfigBundle\Entity\Category
*/
public function getZone()
{
return $this->zone;
}
/**
* Add stock
*
* @param \Uniski\ResourceBundle\Entity\RoomStock $stock
*
* @return Hotel
*/
public function addStock(\Uniski\ResourceBundle\Entity\RoomStock $stock)
{
//Avoid duplicates, if we are adding an stock where date and roomtype are
//the same, update the old stock entity
foreach ($this->stocks as $oldStock) {
if ($oldStock->getDate()->getTimestamp() === $stock->getDate()->getTimestamp() &&
$oldStock->getRoomType() === $stock->getRoomType()) {
$oldStock->setStock($stock->getStock());
$oldStock->setRoomType($stock->getRoomType());
$oldStock->setBoardplan($stock->getBoardplan());
return $this;
}
}
$this->stocks[] = $stock;
return $this;
}
/**
* Remove stock
*
* @param \Uniski\ResourceBundle\Entity\RoomStock $stock
*/
public function removeStock(\Uniski\ResourceBundle\Entity\RoomStock $stock)
{
$this->stocks->removeElement($stock);
}
/**
* Get stocks
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getStocks()
{
return $this->stocks;
}
public function removeAllStock()
{
$this->stocks->removeAll();
return $this;
}
public function setStocks(ArrayCollection $stocks)
{
$this->stocks = $stocks;
}
/**
* Add room
*
* @param array $room
*
* @return Hotel
*/
public function setRooms($room)
{
$this->rooms = $room;
return $this;
}
/**
* Get rooms
*
* It keeps legacy roomTypes which they were only the array key index
*
* @return array
*/
public function getRooms()
{
if ($this->getSource() === "HOTELBEDS" &&
$this->calculatedBookingRates()
) {
if (!$this->calculatedBookingRates['rooms']) return null;
$rooms = [];
$indice=0;
/**
* 04/11/2019 NOTA AR: Por cada habitación de hotelbeds, le asigno la capacidad de la habitación y el rateKey
*/
foreach ($this->calculatedBookingRates['rooms'] as $room) {
$net=0;
$children=0;
$adults=0;
foreach ($room['rates'] as $key => $rate) {
if ($net == 0 || $net == $rate['net'] || $children != $rate['children'] || $adults != $rate['adults']) {
$net = $rate['net'];
$children=$rate['children'];
$adults=$rate['adults'];
$numMax = $rate['children'] + $rate['adults'];
$rooms[$indice] = $room;
$rooms[$indice]['capacity'] = $numMax;
$rooms[$indice]['maxCapacity'] = $numMax;
$rooms[$indice]['rateKey'] = $rate['rateKey'];
if (empty($rooms[$indice]['type'])) $rooms[$indice]['type'] = $room['code'];
$indice += 1;
}
}
}
}
else
{
if (!$this->rooms) return null;
$rooms = [];
foreach ($this->rooms as $key => $room) {
$rooms[$key] = $room;
if (empty($rooms[$key]['type'])) $rooms[$key]['type'] = $key;
}
}
return $rooms;
}
/**
* Get room by roomType
*
* It keeps legacy roomTypes which they were only the array key index
*
* @return array
*/
public function getRoom($roomType)
{
$rooms = $this->getRooms();
if (!$rooms) return null;
foreach ($this->rooms as $key => $room) {
$currentRoomType = $key;
if (isset($room['type'])) $currentRoomType = $room['type'];
if ($currentRoomType == $roomType ) {
return $room;
}
}
return $rooms;
}
/**
* Set slug
*
* @param string $slug
*
* @return Hotel
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set mainImage
*
* @param \Uniski\ResourceBundle\Entity\Image $mainImage
*
* @return Hotel
*/
public function setMainImage(\Uniski\ResourceBundle\Entity\Image $mainImage = null)
{
$this->mainImage = $mainImage;
return $this;
}
/**
* Get mainImage
*
* @return \Uniski\ResourceBundle\Entity\Image
*/
public function getMainImage()
{
return $this->mainImage;
}
/**
* Add product
*
* @return Hotel
*/
public function addProduct(\Uniski\ResourceBundle\Entity\Product $product)
{
if($this->products->contains($product)) return;
$this->products[] = $product;
$product->addHotel($this);
}
/**
* Remove product
*
* @param \Uniski\ResourceBundle\Entity\Product $product
*/
public function removeProduct(\Uniski\ResourceBundle\Entity\Product $product)
{
if(!$this->products->contains($product)) return;
$this->products->removeElement($product);
$product->removeHotel($this);
}
/**
* Get products
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProducts()
{
return $this->products;
}
/**
* Gets the value of email.
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Sets the value of email.
*
* @param string $email the email
*
* @return self
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Set highlighted
*
* @param boolean $highlighted
*
* @return Hotel
*/
public function setHighlighted($highlighted)
{
$this->highlighted = $highlighted;
return $this;
}
/**
* Get highlighted
*
* @return boolean
*/
public function getHighlighted()
{
return $this->highlighted;
}
/**
* Set position
*
* @param integer $position
*
* @return Hotel
*/
public function setPosition($position)
{
$this->position = $position;
return $this;
}
/**
* Get position
*
* @return integer
*/
public function getPosition()
{
return $this->position;
}
public function getStockModel()
{
$model = [];
foreach ($this->getRooms() as $key => $room) {
//Backwards compatibility with legacy roomType index
$roomType = isset($room['type']) ?
$roomType = $room['type']:
$key;
$model[$roomType] = [
self::STOCK_STOCK_KEY => 0,
self::STOCK_RELEASE_KEY => 0,
];
}
return $model;
}
public function getRestrictionModel()
{
$model = [];
foreach ($this->getRooms() as $key => $room) {
//Backwards compatibility with legacy roomType index
$roomType = isset($room['type']) ?
$roomType = $room['type']:
$key;
$model[$roomType] = [
self::RESTRICTION_MIN_NIGHTS_KEY => 0,
];
}
return $model;
}
protected $minPrice;
/**
* Gets the value of minPrice.
*
* @return mixed
*/
public function getMinPrice()
{
return $this->minPrice;
}
/**
* Sets the value of minPrice.
*
* @param mixed $minPrice the min price
*
* @return self
*/
public function setMinPrice($minPrice)
{
$this->minPrice = $minPrice;
return $this;
}
public function isApartment()
{
if ( $this->getHotelType() &&
in_array($this->getHotelType()->getName(),['Apartamento','Aparthotel','Residencia'])) {
return true;
}
return false;
}
/**
* Gets the value of searchable.
*
* @return boolean
*/
public function getSearchable()
{
return $this->searchable;
}
/**
* Sets the value of searchable.
*
* @param boolean $searchable the searchable
*
* @return self
*/
public function setSearchable($searchable)
{
$this->searchable = $searchable;
return $this;
}
/**
* Gets the value of created.
*
* @return \DateTime $created
*/
public function getCreated()
{
return $this->created;
}
/**
* Sets the value of created.
*
* @param \DateTime $created $created the created
*
* @return self
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Gets the value of updated.
*
* @return \DateTime $updated
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Sets the value of updated.
*
* @param \DateTime $updated $updated the updated
*
* @return self
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
public function createRate()
{
return new HotelRate();
}
/**
* Gets the value of bondInstructions.
*
* @return string
*/
public function getBondInstructions()
{
return $this->bondInstructions;
}
/**
* Sets the value of bondInstructions.
*
* @param string $bondInstructions the bond instructions
*
* @return self
*/
public function setBondInstructions($bondInstructions)
{
$this->bondInstructions = $bondInstructions;
return $this;
}
/**
* Add stock
*
* @param \Uniski\ResourceBundle\Entity\RoomRestriction $stock
*
* @return Hotel
*/
public function addRestriction(RoomRestriction $restriction)
{
//Updated: avoid duplicates, if we are adding an stock where date and room type are
//the same, update the old stock entity
foreach ($this->restrictions as $oldRestriction) {
if ($oldRestriction->getDate()->getTimestamp() === $restriction->getDate()->getTimestamp() &&
strval($oldRestriction->getRoomType()) === strval($restriction->getRoomType())) {
$oldRestriction->setMinNights($restriction->getMinNights());
$oldRestriction->setRoomType($restriction->getRoomType());
return $this;
}
}
$this->restrictions[] = $restriction;
return $this;
}
/**
* Remove stock
*
* @param \Uniski\ResourceBundle\Entity\RoomRestriction $restriction
*/
public function removeRestriction(RoomRestriction $restriction)
{
$this->restrictions->removeElement($restriction);
}
/**
* Get restrictions
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRestrictions()
{
return $this->restrictions;
}
public function removeAllRestrictions()
{
$this->restrictions->removeAll();
return $this;
}
/**
* @return mixed
*/
public function getPriority()
{
return $this->priority;
}
/**
* @param mixed $priority
*
* @return self
*/
public function setPriority($priority)
{
$this->priority = $priority;
return $this;
}
/**
* @return string
*/
public function getCancellationPolicy()
{
return $this->cancellationPolicy;
}
/**
* @param string $cancellationPolicy
*
* @return self
*/
public function setCancellationPolicy($cancellationPolicy)
{
$this->cancellationPolicy = $cancellationPolicy;
return $this;
}
/**
* @return mixed
*/
public function getSource()
{
return $this->source;
}
/**
* @param mixed $source
*
* @return self
*/
public function setSource($source)
{
$this->source = $source;
return $this;
}
/**
* @return mixed
*/
public function getSourceCode()
{
return $this->sourceCode;
}
/**
* @param mixed $sourceCode
*
* @return self
*/
public function setSourceCode($sourceCode)
{
$this->sourceCode = $sourceCode;
return $this;
}
/**
* @return float
*/
public function getCommissionPercentage()
{
return $this->commissionPercentage;
}
/**
* @param float $commissionPercentage
*
* @return self
*/
public function setCommissionPercentage($commissionPercentage)
{
$this->commissionPercentage = $commissionPercentage;
return $this;
}
/**
* @return mixed
*/
public function isExternal()
{
return $this->external;
}
/**
* @param mixed $external
*
* @return self
*/
public function setExternal($external)
{
$this->external = $external;
return $this;
}
public function getDistanceFrom($longitude, $latitude)
{
if (!$this->getAddress() || !$this->getAddress()->hasCoordinates()) return 9999;
$lat1 = $this->getAddress()->getLatitude();
$lon1 = $this->getAddress()->getLongitude();
$lat2 = $latitude;
$lon2 = $longitude;
if (($lat1 == $lat2) && ($lon1 == $lon2)) {
return 0;
}
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
return $miles * 1.609344;
}
}