<?php
namespace Uniski\ResourceBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Uniski\ResourceBundle\Entity\Product;
/**
* @ORM\Entity
* @ORM\Table("extra")
*/
class Extra implements RateableInterface
{
const TYPE_FORFAIT = 'forfait';
const TYPE_NORMAL = 'normal';
const DATE_CHOICES_TYPE_FULL = 'full';
const DATE_CHOICES_TYPE_ACTIVITY = 'activity';
const DATE_CHOICES_TYPE_EXTRA_ACTIVITY = 'extra';
/**
* @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={"all"})
* @ORM\JoinColumn(name="image_id", referencedColumnName="id", nullable=true)
*/
protected $image;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\Column(name="price", type="decimal", precision=8, scale=2, nullable=true)
*/
protected $price;
/**
* @var string
* @ORM\Column(name="name", type="string")
*/
protected $name;
/**
* @var string
* @ORM\Column(name="subtitle", type="string", nullable=true)
*/
protected $subtitle;
/**
* @var string
* @ORM\Column(name="description", type="text")
*/
protected $description;
/**
* @var Product
* @ORM\ManyToOne(targetEntity="Product", inversedBy="extras")
*/
protected $product;
/**
* @var array
* @ORM\Column(type="json")
*/
protected $bookingConditions;
/**
* Tells if the extra is attached to the activity. If true
* the number of people doing the activity can't be less
* than the number of amount of selected extras.
*
* @var boolean
* @ORM\Column(type="boolean")
*/
protected $attached;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToMany(targetEntity="PriceRate", cascade={"all"}, orphanRemoval=true)
* @ORM\JoinTable(name="extra_rates",
* joinColumns={@ORM\JoinColumn(name="extra_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="rate_id", referencedColumnName="id")})
*/
protected $rates;
/**
* This is used in case of the extra has a price per date but the duration
* is not the same as main activity, so the price depends of this number of
* days.
* @var integer
* @ORM\Column(type="smallint", nullable=true)
*/
protected $days;
/**
* @ORM\Column(type="json")
*/
protected $options;
/**
* @ORM\Column(name="extra_type", type="string", length=10, nullable=true)
*/
protected $type;
protected $adultPrice;
protected $juniorPrice;
protected $kidPrice;
function __construct()
{
$this->type = self::TYPE_NORMAL;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set price
*
* @param string $price
*
* @return Extra
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* @return string
*/
public function getPrice()
{
return $this->price;
}
/**
* Set name
*
* @param string $name
*
* @return Extra
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set name
*
* @param string $subtitle
*
* @return Extra
*/
public function setSubTitle($subtitle)
{
$this->subtitle = $subtitle;
return $this;
}
/**
* Get subTitle
*
* @return string
*/
public function getSubTitle()
{
return $this->subtitle;
}
/**
* Set description
*
* @param string $description
*
* @return Extra
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set image
*
* @param \Uniski\ResourceBundle\Entity\Image $image
*
* @return Extra
*/
public function setImage(\Uniski\ResourceBundle\Entity\Image $image = null)
{
$this->image = $image;
return $this;
}
/**
* Get image
*
* @return \Uniski\ResourceBundle\Entity\Image
*/
public function getImage()
{
return $this->image;
}
/**
* Set product
*
* @param Product $product
*
* @return Extra
*/
public function setProduct(Product $product = null)
{
$this->product = $product;
return $this;
}
/**
* Get product
*
* @return Product
*/
public function getProduct()
{
return $this->product;
}
/**
* Gets the Tells if the extra is attached to the activity. If true
the number of people doing the activity can't be less
than the number of amount of selected extras.
*
* @return boolean
*/
public function getAttached()
{
return $this->attached;
}
/**
* Sets the Tells if the extra is attached to the activity. If true
the number of people doing the activity can't be less
than the number of amount of selected extras.
*
* @param boolean $attached the attached
*
* @return self
*/
public function setAttached($attached)
{
$this->attached = $attached;
return $this;
}
/**
*
* @return array
*/
public function getBookingConditions()
{
return $this->bookingConditions;
}
/**
*
* @param array $bookingConditions the booking conditions
*
* @return self
*/
public function setBookingConditions($bookingConditions)
{
$this->bookingConditions = $bookingConditions;
return $this;
}
/**
* 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);
}
/**
* Get rates
*
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getRates()
{
return $this->rates;
}
public function createRate()
{
return new ActivityRate();
}
/**
* Gets the This is used in case of the extra has a price per date but the duration
is not the same as main activity, so the price depends of this number of
days.
*
* @return integer
*/
public function getDays()
{
return $this->days;
}
/**
* Sets the This is used in case of the extra has a price per date but the duration
is not the same as main activity, so the price depends of this number of
days.
*
* @param integer $days the days
*
* @return self
*/
public function setDays($days)
{
$this->days = $days;
return $this;
}
/**
* Gets the value of adultPrice.
*
* @return mixed
*/
public function getAdultPrice()
{
return $this->adultPrice ? $this->adultPrice : $this->price;
}
/**
* Sets the value of adultPrice.
*
* @param mixed $adultPrice the adult price
*
* @return self
*/
public function setAdultPrice($adultPrice)
{
$this->adultPrice = $adultPrice;
return $this;
}
/**
* Gets the value of juniorPrice.
*
* @return mixed
*/
public function getJuniorPrice()
{
return $this->juniorPrice;
}
/**
* Sets the value of juniorPrice.
*
* @param mixed $juniorPrice the junior price
*
* @return self
*/
public function setJuniorPrice($juniorPrice)
{
$this->juniorPrice = $juniorPrice;
return $this;
}
/**
* Gets the value of kidPrice.
*
* @return mixed
*/
public function getKidPrice()
{
return $this->kidPrice;
}
/**
* Sets the value of kidPrice.
*
* @param mixed $kidPrice the kid price
*
* @return self
*/
public function setKidPrice($kidPrice)
{
$this->kidPrice = $kidPrice;
return $this;
}
/**
* @return mixed
*/
public function getOptions()
{
return $this->options;
}
/**
* @param mixed $options
*
* @return self
*/
public function setOptions($options)
{
$this->options = $options;
return $this;
}
public function getOptionsLabel()
{
if ( !$this->options || empty($this->options['label']) ) return null;
return $this->options['label'];
}
public function getOptionsChoices()
{
if ( !$this->options || empty($this->options['choices']) ) return null;
$choices = [];
foreach (explode(",", $this->options['choices']) as $value) {
$value = trim($value);
$choices[$value] = $value;
}
return $choices;
}
public function getDateChoices(
\DateTime $dateIn,
\DateTime $dateOut,
\DateTime $dateStart,
\DateTime $dateEnd
)
{
$dateIn = new \DateTime($dateIn->format('Y-m-d'));
$dateOut = new \DateTime($dateOut->format('Y-m-d'));
$dateStart = new \DateTime($dateStart->format('Y-m-d'));
$dateEnd = new \DateTime($dateEnd->format('Y-m-d'));
$choices = [];
$date = new \DateTime($dateIn->format("c"));
if (!$this->options || empty($this->options['date_choices_type'])) return null;
$type = $this->options['date_choices_type'];
while ($date <= $dateOut) {
if (
($type == self::DATE_CHOICES_TYPE_FULL) ||
($type == self::DATE_CHOICES_TYPE_ACTIVITY && $date >= $dateStart && $date <= $dateEnd) ||
($type == self::DATE_CHOICES_TYPE_EXTRA_ACTIVITY && $date < $dateStart || $date > $dateEnd)
) {
$choices[$date->format('d/m/Y')] = $date->format('Y-m-d');
}
$date->add(new \DateInterval("P1D"));
}
return $choices;
}
/**
* @return mixed
*/
public function getType()
{
return $this->type;
}
/**
* @param mixed $type
*
* @return self
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
public function getAgeType($age)
{
if ($this->bookingConditions != null) {
if ($age > $this->bookingConditions['maxJuniorAge']) return "adult";
else if ($age > $this->bookingConditions['maxKidsAge']) return "junior";
else if ($age > $this->bookingConditions['maxFreeAge']) return "kid";
}
return "adult";
}
}