src/Uniski/ResourceBundle/Entity/Extra.php line 12

Open in your IDE?
  1. <?php
  2. namespace Uniski\ResourceBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Uniski\ResourceBundle\Entity\Product;
  5. /**
  6. * @ORM\Entity
  7. * @ORM\Table("extra")
  8. */
  9. class Extra implements RateableInterface
  10. {
  11.     const TYPE_FORFAIT 'forfait';
  12.     const TYPE_NORMAL 'normal';
  13.     
  14.     const DATE_CHOICES_TYPE_FULL            'full';
  15.     const DATE_CHOICES_TYPE_ACTIVITY        'activity';
  16.     const DATE_CHOICES_TYPE_EXTRA_ACTIVITY  'extra';
  17.   /**
  18.    * @var integer
  19.    *
  20.    * @ORM\Id
  21.    * @ORM\Column(name="id", type="integer")
  22.    * @ORM\GeneratedValue(strategy="IDENTITY")
  23.    */
  24.   protected $id;
  25.   /**
  26.    * @var   \Uniski\ResourceBundle\Entity\Image
  27.    * @ORM\ManyToOne(targetEntity="Image", cascade={"all"})
  28.    * @ORM\JoinColumn(name="image_id", referencedColumnName="id", nullable=true)
  29.    */
  30.   protected $image;
  31.   /**
  32.    * @var   \Doctrine\Common\Collections\ArrayCollection
  33.    * @ORM\Column(name="price", type="decimal", precision=8, scale=2, nullable=true)
  34.    */
  35.   protected $price;
  36.   /**
  37.    * @var  string
  38.    * @ORM\Column(name="name", type="string")
  39.    */
  40.   protected $name;
  41.   /**
  42.    * @var  string
  43.    * @ORM\Column(name="subtitle", type="string", nullable=true)
  44.    */
  45.   protected $subtitle;
  46.   /**
  47.    * @var  string
  48.    * @ORM\Column(name="description", type="text")
  49.    */
  50.   protected $description;
  51.   /**
  52.    * @var Product
  53.    * @ORM\ManyToOne(targetEntity="Product", inversedBy="extras")
  54.    */
  55.   protected $product;
  56.   /**
  57.    * @var  array
  58.    * @ORM\Column(type="json")
  59.    */
  60.   protected $bookingConditions;
  61.   /**
  62.    * Tells if the extra is attached to the activity. If true
  63.    * the number of people doing the activity can't be less
  64.    * than the number of amount of selected extras.
  65.    *
  66.    * @var boolean
  67.    * @ORM\Column(type="boolean")
  68.    */
  69.   protected $attached;
  70.   /**
  71.    * @var   \Doctrine\Common\Collections\ArrayCollection
  72.    * @ORM\ManyToMany(targetEntity="PriceRate", cascade={"all"}, orphanRemoval=true)
  73.    * @ORM\JoinTable(name="extra_rates",
  74.    *   joinColumns={@ORM\JoinColumn(name="extra_id", referencedColumnName="id")},
  75.    *   inverseJoinColumns={@ORM\JoinColumn(name="rate_id", referencedColumnName="id")})
  76.    */
  77.   protected $rates;
  78.   /**
  79.    * This is used in case of the extra has a price per date but the duration
  80.    * is not the same as main activity, so the price depends of this number of
  81.    * days.
  82.    * @var  integer
  83.    * @ORM\Column(type="smallint", nullable=true)
  84.    */
  85.   protected $days;
  86.   /**
  87.    * @ORM\Column(type="json")
  88.    */
  89.   protected $options;
  90.   /**
  91.    * @ORM\Column(name="extra_type", type="string", length=10, nullable=true)
  92.    */
  93.   protected $type;
  94.   protected $adultPrice;
  95.   protected $juniorPrice;
  96.   protected $kidPrice;
  97.     function __construct()
  98.     {
  99.         $this->type self::TYPE_NORMAL;
  100.     }
  101.     /**
  102.      * Get id
  103.      *
  104.      * @return integer
  105.      */
  106.     public function getId()
  107.     {
  108.         return $this->id;
  109.     }
  110.     /**
  111.      * Set price
  112.      *
  113.      * @param string $price
  114.      *
  115.      * @return Extra
  116.      */
  117.     public function setPrice($price)
  118.     {
  119.         $this->price $price;
  120.         return $this;
  121.     }
  122.     /**
  123.      * Get price
  124.      *
  125.      * @return string
  126.      */
  127.     public function getPrice()
  128.     {
  129.         return $this->price;
  130.     }
  131.     /**
  132.      * Set name
  133.      *
  134.      * @param string $name
  135.      *
  136.      * @return Extra
  137.      */
  138.     public function setName($name)
  139.     {
  140.         $this->name $name;
  141.         return $this;
  142.     }
  143.     /**
  144.      * Get name
  145.      *
  146.      * @return string
  147.      */
  148.     public function getName()
  149.     {
  150.         return $this->name;
  151.     }
  152.     /**
  153.      * Set name
  154.      *
  155.      * @param string $subtitle
  156.      *
  157.      * @return Extra
  158.      */
  159.     public function setSubTitle($subtitle)
  160.     {
  161.         $this->subtitle $subtitle;
  162.         return $this;
  163.     }
  164.     /**
  165.      * Get subTitle
  166.      *
  167.      * @return string
  168.      */
  169.     public function getSubTitle()
  170.     {
  171.         return $this->subtitle;
  172.     }
  173.     /**
  174.      * Set description
  175.      *
  176.      * @param string $description
  177.      *
  178.      * @return Extra
  179.      */
  180.     public function setDescription($description)
  181.     {
  182.         $this->description $description;
  183.         return $this;
  184.     }
  185.     /**
  186.      * Get description
  187.      *
  188.      * @return string
  189.      */
  190.     public function getDescription()
  191.     {
  192.         return $this->description;
  193.     }
  194.     /**
  195.      * Set image
  196.      *
  197.      * @param \Uniski\ResourceBundle\Entity\Image $image
  198.      *
  199.      * @return Extra
  200.      */
  201.     public function setImage(\Uniski\ResourceBundle\Entity\Image $image null)
  202.     {
  203.         $this->image $image;
  204.         return $this;
  205.     }
  206.     /**
  207.      * Get image
  208.      *
  209.      * @return \Uniski\ResourceBundle\Entity\Image
  210.      */
  211.     public function getImage()
  212.     {
  213.         return $this->image;
  214.     }
  215.     /**
  216.      * Set product
  217.      *
  218.      * @param Product $product
  219.      *
  220.      * @return Extra
  221.      */
  222.     public function setProduct(Product $product null)
  223.     {
  224.         $this->product $product;
  225.         return $this;
  226.     }
  227.     /**
  228.      * Get product
  229.      *
  230.      * @return Product
  231.      */
  232.     public function getProduct()
  233.     {
  234.         return $this->product;
  235.     }
  236.     /**
  237.      * Gets the Tells if the extra is attached to the activity. If true
  238. the number of people doing the activity can't be less
  239. than the number of amount of selected extras.
  240.      *
  241.      * @return boolean
  242.      */
  243.     public function getAttached()
  244.     {
  245.         return $this->attached;
  246.     }
  247.     /**
  248.      * Sets the Tells if the extra is attached to the activity. If true
  249. the number of people doing the activity can't be less
  250. than the number of amount of selected extras.
  251.      *
  252.      * @param boolean $attached the attached
  253.      *
  254.      * @return self
  255.      */
  256.     public function setAttached($attached)
  257.     {
  258.         $this->attached $attached;
  259.         return $this;
  260.     }
  261.     /**
  262.      *
  263.      * @return  array
  264.      */
  265.     public function getBookingConditions()
  266.     {
  267.         return $this->bookingConditions;
  268.     }
  269.     /**
  270.      *
  271.      * @param  array $bookingConditions the booking conditions
  272.      *
  273.      * @return self
  274.      */
  275.     public function setBookingConditions($bookingConditions)
  276.     {
  277.         $this->bookingConditions $bookingConditions;
  278.         return $this;
  279.     }
  280.     /**
  281.      * Add rate
  282.      *
  283.      * @param \Uniski\ResourceBundle\Entity\PriceRate $rate
  284.      *
  285.      * @return Product
  286.      */
  287.     public function addRate(\Uniski\ResourceBundle\Entity\PriceRate $rate)
  288.     {
  289.         $this->rates[] = $rate;
  290.         return $this;
  291.     }
  292.     /**
  293.      * Remove rate
  294.      *
  295.      * @param \Uniski\ResourceBundle\Entity\PriceRate $rate
  296.      */
  297.     public function removeRate(\Uniski\ResourceBundle\Entity\PriceRate $rate)
  298.     {
  299.         $this->rates->removeElement($rate);
  300.     }
  301.     /**
  302.      * Get rates
  303.      *
  304.      * @return \Doctrine\Common\Collections\ArrayCollection
  305.      */
  306.     public function getRates()
  307.     {
  308.         return $this->rates;
  309.     }
  310.     public function createRate()
  311.     {
  312.       return new ActivityRate();
  313.     }
  314.     /**
  315.      * Gets the This is used in case of the extra has a price per date but the duration
  316. is not the same as main activity, so the price depends of this number of
  317. days.
  318.      *
  319.      * @return  integer
  320.      */
  321.     public function getDays()
  322.     {
  323.         return $this->days;
  324.     }
  325.     /**
  326.      * Sets the This is used in case of the extra has a price per date but the duration
  327. is not the same as main activity, so the price depends of this number of
  328. days.
  329.      *
  330.      * @param  integer $days the days
  331.      *
  332.      * @return self
  333.      */
  334.     public function setDays($days)
  335.     {
  336.         $this->days $days;
  337.         return $this;
  338.     }
  339.     /**
  340.      * Gets the value of adultPrice.
  341.      *
  342.      * @return mixed
  343.      */
  344.     public function getAdultPrice()
  345.     {
  346.         return $this->adultPrice $this->adultPrice $this->price;
  347.     }
  348.     /**
  349.      * Sets the value of adultPrice.
  350.      *
  351.      * @param mixed $adultPrice the adult price
  352.      *
  353.      * @return self
  354.      */
  355.     public function setAdultPrice($adultPrice)
  356.     {
  357.         $this->adultPrice $adultPrice;
  358.         return $this;
  359.     }
  360.     /**
  361.      * Gets the value of juniorPrice.
  362.      *
  363.      * @return mixed
  364.      */
  365.     public function getJuniorPrice()
  366.     {
  367.         return $this->juniorPrice;
  368.     }
  369.     /**
  370.      * Sets the value of juniorPrice.
  371.      *
  372.      * @param mixed $juniorPrice the junior price
  373.      *
  374.      * @return self
  375.      */
  376.     public function setJuniorPrice($juniorPrice)
  377.     {
  378.         $this->juniorPrice $juniorPrice;
  379.         return $this;
  380.     }
  381.     /**
  382.      * Gets the value of kidPrice.
  383.      *
  384.      * @return mixed
  385.      */
  386.     public function getKidPrice()
  387.     {
  388.         return $this->kidPrice;
  389.     }
  390.     /**
  391.      * Sets the value of kidPrice.
  392.      *
  393.      * @param mixed $kidPrice the kid price
  394.      *
  395.      * @return self
  396.      */
  397.     public function setKidPrice($kidPrice)
  398.     {
  399.         $this->kidPrice $kidPrice;
  400.         return $this;
  401.     }
  402.     /**
  403.      * @return mixed
  404.      */
  405.     public function getOptions()
  406.     {
  407.         return $this->options;
  408.     }
  409.     /**
  410.      * @param mixed $options
  411.      *
  412.      * @return self
  413.      */
  414.     public function setOptions($options)
  415.     {
  416.         $this->options $options;
  417.         return $this;
  418.     }
  419.     public function getOptionsLabel()
  420.     {
  421.         if ( !$this->options || empty($this->options['label']) ) return null;
  422.         return $this->options['label'];
  423.     }
  424.     public function getOptionsChoices()
  425.     {
  426.         if ( !$this->options || empty($this->options['choices']) ) return null;
  427.         $choices = [];
  428.         foreach (explode(","$this->options['choices']) as $value) {
  429.             $value trim($value);
  430.             $choices[$value] = $value;
  431.         }
  432.         return $choices;
  433.     }
  434.     public function getDateChoices(
  435.         \DateTime $dateIn,
  436.         \DateTime $dateOut,
  437.         \DateTime $dateStart,
  438.         \DateTime $dateEnd
  439.     )
  440.     {
  441.         $dateIn = new \DateTime($dateIn->format('Y-m-d'));
  442.         $dateOut = new \DateTime($dateOut->format('Y-m-d'));
  443.         $dateStart = new \DateTime($dateStart->format('Y-m-d'));
  444.         $dateEnd = new \DateTime($dateEnd->format('Y-m-d'));
  445.         $choices = [];
  446.         $date    = new \DateTime($dateIn->format("c"));
  447.         
  448.         if (!$this->options || empty($this->options['date_choices_type'])) return null;
  449.         $type $this->options['date_choices_type'];
  450.         while ($date <= $dateOut) {
  451.             if (
  452.                 ($type == self::DATE_CHOICES_TYPE_FULL) ||
  453.                 ($type == self::DATE_CHOICES_TYPE_ACTIVITY && $date >= $dateStart && $date <= $dateEnd) ||
  454.                 ($type == self::DATE_CHOICES_TYPE_EXTRA_ACTIVITY && $date $dateStart || $date $dateEnd)
  455.             ) {
  456.                 $choices[$date->format('d/m/Y')] = $date->format('Y-m-d');
  457.             }
  458.             $date->add(new \DateInterval("P1D"));
  459.         }
  460.         return $choices;
  461.     }
  462.     /**
  463.      * @return mixed
  464.      */
  465.     public function getType()
  466.     {
  467.         return $this->type;
  468.     }
  469.     /**
  470.      * @param mixed $type
  471.      *
  472.      * @return self
  473.      */
  474.     public function setType($type)
  475.     {
  476.         $this->type $type;
  477.         return $this;
  478.     }
  479.     public function getAgeType($age)
  480.     {
  481.         if ($this->bookingConditions != null) {
  482.             if ($age $this->bookingConditions['maxJuniorAge'])     return "adult";
  483.             else if ($age $this->bookingConditions['maxKidsAge'])  return "junior";
  484.             else if ($age $this->bookingConditions['maxFreeAge'])  return "kid";
  485.         }
  486.         return "adult";
  487.     }
  488. }