<?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\Destination;
use Uniski\ResourceBundle\Entity\Extra;
use Uniski\Utils\TeaserGenerator;
/**
* @ORM\Entity(repositoryClass="Uniski\ResourceBundle\Repository\ProductRepository")
* @ORM\Table(name="product")
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="product_type", type="string")
* @ORM\DiscriminatorMap({
* "product" = "Product",
* "ski" = "Ski",
* "activity" = "Activity",
* "pack" = "Pack"
* })
*/
class Product implements RateableInterface
{
const PRICE_RATE_MODEL_SKI = 'ski';
const PRICE_RATE_MODEL_GENERAL = 'general';
const TAX_NONE = 0;
const TAX_INCLUDED = 1;
const TAX_NOT_INCLUDED = 2;
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var \Uniski\ResourceBundle\Entity\Image
* @ORM\ManyToOne(targetEntity="Image", cascade={"persist"})
*/
protected $mainImage;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToOne(targetEntity="Uniski\ConfigBundle\Entity\Category")
*
*/
protected $zone;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToMany(targetEntity="PriceRate", cascade={"all"}, orphanRemoval=true)
* @ORM\JoinTable(name="product_rates",
* joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="rate_id", referencedColumnName="id")})
*/
protected $rates;
/**
* @var string
* @ORM\Column(name="name", type="string")
*/
protected $name;
/**
* @var string
* @ORM\Column(name="description", type="text", nullable=true)
*/
protected $description;
/**
* @var array
* @ORM\Column(name="seo", type="json")
*/
protected $seo;
/**
* @var array
* @ORM\Column(name="bookingConditions", type="json")
*
* For Ski is like this:
* 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\ManyToMany(targetEntity="Hotel", mappedBy="products")
*/
protected $hotels;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToMany(targetEntity="\Uniski\ConfigBundle\Entity\Category", cascade={"persist"})
* @ORM\JoinTable(name="product_tags",
* joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="tag_id", referencedColumnName="id")})
*/
protected $tags;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(length=128, unique=true)
*/
private $slug;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\OneToMany(targetEntity="Extra", mappedBy="product", cascade={"persist"})
* @ORM\JoinTable(name="product_extra")
*/
protected $extras;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToMany(targetEntity="Insurance", inversedBy="products")
*/
protected $insurances;
/**
* @var float
*
* The absolute value of the product tax
* The tax is per person and night
*
* @ORM\Column(type="decimal", precision=6, scale=2, nullable=true)
*/
protected $tax;
/**
* @var boolean
*
* Whether or not the tax should be included or added to the price.
* If not, the tax won't be included but an warning message will appear
* in booking pages and bonds
*
* @ORM\Column(type="boolean", nullable=true)
*/
protected $addTax;
/**
* @var int
*
* The minimum number of days customer should request for this
* product (e.g. Ski minimum 2 days forfait, Caldea minimum 1 day)
*
* @ORM\Column(type="integer", nullable=true)
*/
protected $minDays;
/**
* @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 \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToMany(targetEntity="Shop")
* @ORM\JoinTable(name="ski_shops",
* joinColumns={@ORM\JoinColumn(name="ski_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="shop_id", referencedColumnName="id")})
*/
protected $shops;
/**
* @var string
* @ORM\Column(type="string", length=10)
*/
protected $priceRateModel;
/**
* @var string
* @ORM\Column(type="string")
*/
protected $productName;
/**
* @var string
* @ORM\Column(type="text", nullable=true)
*/
protected $bondInstructions;
/**
* Destination
* @var Destination
* @ORM\ManyToOne(targetEntity="Destination", inversedBy="products")
*/
protected $destination;
/**
* int
* @ORM\Column(type="smallint")
*/
protected $showTax;
/**
* @ORM\Column(type="boolean")
*/
protected $active;
/**
* Constructor
*/
public function __construct()
{
$this->images = new \Doctrine\Common\Collections\ArrayCollection();
$this->rates = new \Doctrine\Common\Collections\ArrayCollection();
$this->extras = new \Doctrine\Common\Collections\ArrayCollection();
$this->hotels = new \Doctrine\Common\Collections\ArrayCollection();
$this->tags = new \Doctrine\Common\Collections\ArrayCollection();
$this->shops = new \Doctrine\Common\Collections\ArrayCollection();
$this->seo = [];
$this->bookingConditions = [
'allowActivityDiscount' => true
];
$this->minDays = 1;
$this->active = true;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Product
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* @param string $description
*
* @return Product
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set seo
*
* @param array $seo
*
* @return Product
*/
public function setSeo($seo)
{
$this->seo = $seo;
return $this;
}
/**
* Get seo
*
* @return array
*/
public function getSeo()
{
$seo = $this->seo;
if (empty($seo['title'])) $seo['title'] = $this->getName();
if ( empty($seo['description']) &&
!empty($this->getDescription())
) {
$seo['description'] = TeaserGenerator::generate($this->getDescription());
}
if ( empty($seo['description']) &&
!empty($this->getDestination())
) {
$seo['description'] = TeaserGenerator::generate($this->getDestination()->getDescription());
}
return $seo;
}
/**
* Set bookingConditions
*
* @param array $bookingConditions
*
* @return Product
*/
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 Product
*/
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;
}
/**
* Get zone
*
* @return \Uniski\ConfigBundle\Entity\Category
*/
public function getZone()
{
return $this->destination->getZone();
}
/**
* Add rate
*
* @param \Uniski\ResourceBundle\Entity\PriceRate $rate
*
* @return Product
*/
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);
}
/**
* Remove rate
*
* @param \Uniski\ResourceBundle\Entity\PriceRate $rate
*/
public function removeAllRates()
{
$this->rates->clear();
}
/**
* Get rates
*
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getRates()
{
return $this->rates;
}
/**
* Add tag
*
* @param \Uniski\ConfigBundle\Entity\Category $tag
*
* @return Product
*/
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\ArrayCollection
*/
public function getTags()
{
return $this->tags;
}
/**
* Set slug
*
* @param string $slug
*
* @return Product
*/
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 Product
*/
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 hotel
*
* @return Product
*/
public function addHotel(\Uniski\ResourceBundle\Entity\Hotel $hotel)
{
if($this->hotels->contains($hotel)) return;
$this->hotels[] = $hotel;
$hotel->addProduct($this);
}
/**
* Remove hotel
*
* @param \Uniski\ResourceBundle\Entity\Hotel $hotel
*/
public function removeHotel(\Uniski\ResourceBundle\Entity\Hotel $hotel)
{
if(!$this->hotels->contains($hotel)) return;
$this->hotels->removeElement($hotel);
$hotel->removeProduct($this);
}
/**
* Get hotels
*
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getHotels()
{
return $this->hotels;
}
/**
* Add extra
*
* @param \Uniski\ResourceBundle\Entity\Extra $extra
*
* @return Product
*/
public function addExtra(Extra $extra)
{
if ($this->extras->contains($extra)) return;
$this->extras[] = $extra;
$extra->setProduct($this);
return $this;
}
/**
* Remove extra
*
* @param \Uniski\ResourceBundle\Entity\Extra $extra
*/
public function removeExtra(Extra $extra)
{
if (!$this->extras->contains($extra)) return $this;
$this->extras->removeElement($extra);
$extra->setProduct(null);
}
/**
* Get extras
*
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getExtras()
{
return $this->extras;
}
/**
* Add insurance
*
* @param \Uniski\ResourceBundle\Entity\Insurance $insurance
*
* @return Product
*/
public function addInsurances(\Uniski\ResourceBundle\Entity\Insurance $insurance)
{
$this->insurances[] = $insurance;
return $this;
}
/**
* Remove insurance
*
* @param \Uniski\ResourceBundle\Entity\Insurance $insurance
*/
public function removeInsurance(\Uniski\ResourceBundle\Entity\Insurance $insurance)
{
$this->insurances->removeElement($insurance);
}
/**
* Get insurance
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getInsurances()
{
return $this->insurances;
}
/**
* Add insurance
*
* @param \Uniski\ResourceBundle\Entity\Insurance $insurance
*
* @return Product
*/
public function addInsurance(\Uniski\ResourceBundle\Entity\Insurance $insurance)
{
$this->insurances[] = $insurance;
return $this;
}
public function setHotels($hotels)
{
$this->hotels = $hotels;
}
/**
* Gets the value of tax.
*
* @return float
*/
public function getTax()
{
return $this->tax;
}
/**
* Sets the value of tax.
*
* @param float $tax the tax
*
* @return self
*/
public function setTax($tax)
{
$this->tax = $tax;
return $this;
}
/**
* Gets the Whether or not the tax should be included or added to the price
If not, the tax won't be included but an warning message will appear
in booking pages and bonds.
*
* @return boolean
*/
public function getAddTax()
{
return $this->addTax;
}
/**
* Sets the Whether or not the tax should be included or added to the price
If not, the tax won't be included but an warning message will appear
in booking pages and bonds.
*
* @param boolean $addTax the add tax
*
* @return self
*/
public function setAddTax($addTax)
{
$this->addTax = $addTax;
return $this;
}
/**
* Gets the The minimum number of days customer should request for this
product (e.g. Ski minimum 2 days forfait, Caldea minimum 1 day).
*
* @return int
*/
public function getMinDays()
{
return $this->minDays;
}
/**
* Sets the The minimum number of days customer should request for this
product (e.g. Ski minimum 2 days forfait, Caldea minimum 1 day).
*
* @param int $minDays the min days
*
* @return self
*/
public function setMinDays($minDays)
{
$this->minDays = $minDays;
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;
}
/**
* Add shop
*
* @param \Uniski\ResourceBundle\Entity\Shop $shop
*
* @return Product
*/
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;
}
public function setShops(ArrayCollection $shops)
{
$this->shops = $shops;
return $this;
}
public function createRate()
{
switch ($this->priceRateModel) {
case self::PRICE_RATE_MODEL_SKI:
return new SkiRate();
default:
return new ActivityRate();
}
}
/**
* Gets the value of priceRateModel.
*
* @return string
*/
public function getPriceRateModel()
{
return $this->priceRateModel;
}
/**
* Sets the value of priceRateModel.
*
* @param string $priceRateModel the price rate model
*
* @return self
*/
public function setPriceRateModel($priceRateModel)
{
$this->priceRateModel = $priceRateModel;
return $this;
}
/**
* Gets the value of productName.
*
* @return string
*/
public function getProductName()
{
return $this->productName;
}
/**
* Sets the value of productName.
*
* @param string $productName the product name
*
* @return self
*/
public function setProductName($productName)
{
$this->productName = $productName;
return $this;
}
/**
* 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;
}
/**
* @return Destination
*/
public function getDestination()
{
return $this->destination;
}
/**
* @param Destination $destination
*
* @return self
*/
public function setDestination(Destination $destination)
{
$this->destination = $destination;
return $this;
}
/**
* @return mixed
*/
public function getShowTax()
{
return $this->showTax;
}
/**
* @param mixed $showTax
*
* @return self
*/
public function setShowTax($showTax)
{
$this->showTax = $showTax;
return $this;
}
/**
* @return mixed
*/
public function getActive()
{
return $this->active;
}
/**
* @param mixed $active
*
* @return self
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
}