src/Uniski/ResourceBundle/Entity/Destination.php line 15

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\ValueObject\GeoLocation;
  7. use Uniski\ResourceBundle\Entity\ValueObject\SkiStation;
  8. use Uniski\Utils\TeaserGenerator;
  9. /**
  10. * @ORM\Entity
  11. **/
  12. class Destination
  13. {
  14.     
  15.     /**
  16.      * @var integer
  17.      *
  18.      * @ORM\Id
  19.      * @ORM\Column(name="id", type="integer")
  20.      * @ORM\GeneratedValue(strategy="IDENTITY")
  21.      */
  22.     protected $id;
  23.     /**
  24.      * @var  string
  25.      * @ORM\Column(name="name", type="string")
  26.      */
  27.     protected $name;
  28.     /**
  29.      * @var  array
  30.      * @ORM\Column(name="location", type="json", nullable=true)
  31.      */
  32.     protected $location;
  33.     /**
  34.      * @var  string
  35.      * @ORM\Column(name="description", type="text", nullable=true)
  36.      */
  37.     protected $description;
  38.     /**
  39.      * @var  array
  40.      * @ORM\Column(name="seo", type="json")
  41.      */
  42.     protected $seo;
  43.     /**
  44.      * @Gedmo\Slug(fields={"name"})
  45.      * @ORM\Column(length=128, unique=true)
  46.      */
  47.     private $slug;
  48.     /**
  49.      * @var   \Doctrine\Common\Collections\ArrayCollection
  50.      * @ORM\ManyToMany(targetEntity="Image", cascade={"all"})
  51.      * @ORM\JoinTable(name="destination_images",
  52.      *   joinColumns={@ORM\JoinColumn(name="destination_id", referencedColumnName="id")},
  53.      *   inverseJoinColumns={@ORM\JoinColumn(name="image_id", referencedColumnName="id")})
  54.      */
  55.     protected $images;
  56.     /**
  57.      * @var   \Uniski\ResourceBundle\Entity\Image
  58.      * @ORM\ManyToOne(targetEntity="Image", cascade={"all"})
  59.      */
  60.     protected $mainImage;
  61.     /**
  62.      * @var   Uniski\ConfigBundle\Entity\Category
  63.      * @ORM\ManyToOne(targetEntity="Uniski\ConfigBundle\Entity\Category")
  64.      *
  65.      */
  66.     protected $zone;
  67.     /**
  68.      * @var   \Doctrine\Common\Collections\ArrayCollection
  69.      * @ORM\ManyToOne(targetEntity="Uniski\ConfigBundle\Entity\Category")
  70.      *
  71.      * Ski, Vacaciones, Aventura
  72.      */
  73.     protected $category;
  74.     /**
  75.      * @var \Doctrine\Common\Collections\ArrayCollection
  76.      * @ORM\OneToMany(targetEntity="Product", mappedBy="destination", cascade={"all"})
  77.      */
  78.     protected $products;
  79.     /**
  80.      * @var \DateTime $created
  81.      *
  82.      * @Gedmo\Timestampable(on="create")
  83.      * @ORM\Column(type="datetime")
  84.      */
  85.     private $created;
  86.     /**
  87.      * @var \DateTime $updated
  88.      *
  89.      * @Gedmo\Timestampable
  90.      * @ORM\Column(type="datetime")
  91.      */
  92.     private $updated;
  93.     /**
  94.     * @var SkiStation
  95.     * @ORM\Embedded(class="Uniski\ResourceBundle\Entity\ValueObject\SkiStation")
  96.     */
  97.     protected $ski;
  98.     /**
  99.      * @var integer
  100.      * @ORM\Column(type="smallint")
  101.      */
  102.     protected $priority;
  103.     /**
  104.      * @var boolean
  105.      * @ORM\Column(type="boolean")
  106.      */
  107.     protected $active;
  108.     /**
  109.     * @var GeoLocation
  110.     * @ORM\Embedded(class="Uniski\ResourceBundle\Entity\ValueObject\GeoLocation")
  111.     */
  112.     protected $geoLocation;
  113.     function __construct()
  114.     {
  115.         $this->images   = new ArrayCollection();
  116.         $this->products = new ArrayCollection();
  117.         $this->ski      = new SkiStation();
  118.         $this->active   true;
  119.         $this->priority 0
  120.     }
  121.     /**
  122.      * @return integer
  123.      */
  124.     public function getId()
  125.     {
  126.         return $this->id;
  127.     }
  128.     /**
  129.      * @param integer $id
  130.      *
  131.      * @return self
  132.      */
  133.     public function setId($id)
  134.     {
  135.         $this->id $id;
  136.         return $this;
  137.     }
  138.     /**
  139.      * @return  string
  140.      */
  141.     public function getName()
  142.     {
  143.         return $this->name;
  144.     }
  145.     /**
  146.      * @param  string $name
  147.      *
  148.      * @return self
  149.      */
  150.     public function setName($name)
  151.     {
  152.         $this->name $name;
  153.         return $this;
  154.     }
  155.     /**
  156.      * @return  string
  157.      */
  158.     public function getDescription()
  159.     {
  160.         return $this->description;
  161.     }
  162.     /**
  163.      * @param  string $description
  164.      *
  165.      * @return self
  166.      */
  167.     public function setDescription($description)
  168.     {
  169.         $this->description $description;
  170.         return $this;
  171.     }
  172.     /**
  173.      * Get seo
  174.      *
  175.      * @return array
  176.      */
  177.     public function getSeo()
  178.     {
  179.         $seo $this->seo;
  180.         
  181.         if (empty($seo['title']) && $this->name) {
  182.             $seo['title'] = sprintf("Ofertas esquí %s"$this->name);
  183.         }
  184.         if (empty($seo['description']) && $this->name && $this->zone) {
  185.             $zone $this->zone->getName();
  186.             $seo['description'] = sprintf(
  187.                 "Las mejores ofertas de esquí %s . Hotel y forfait al mejor precio para disfrutar de tu viaje de esquí en %s",                
  188.                 $this->name,
  189.                 $zone
  190.             );
  191.         }
  192.         return $seo;
  193.     }
  194.     /**
  195.      * @param  array $seo
  196.      *
  197.      * @return self
  198.      */
  199.     public function setSeo($seo)
  200.     {
  201.         $this->seo $seo;
  202.         return $this;
  203.     }
  204.     /**
  205.      * @return mixed
  206.      */
  207.     public function getSlug()
  208.     {
  209.         return $this->slug;
  210.     }
  211.     /**
  212.      * @param mixed $slug
  213.      *
  214.      * @return self
  215.      */
  216.     public function setSlug($slug)
  217.     {
  218.         $this->slug $slug;
  219.         return $this;
  220.     }
  221.     /**
  222.      * @return   \Doctrine\Common\Collections\ArrayCollection
  223.      */
  224.     public function getImages()
  225.     {
  226.         return $this->images;
  227.     }
  228.     /**
  229.      * @param   \Doctrine\Common\Collections\ArrayCollection $images
  230.      *
  231.      * @return self
  232.      */
  233.     public function setImages($images)
  234.     {
  235.         $this->images $images;
  236.         return $this;
  237.     }
  238.     /**
  239.      * Add image
  240.      *
  241.      * @param \Uniski\ResourceBundle\Entity\Image $image
  242.      *
  243.      * @return Product
  244.      */
  245.     public function addImage(\Uniski\ResourceBundle\Entity\Image $image)
  246.     {
  247.         $this->images[] = $image;
  248.         return $this;
  249.     }
  250.     /**
  251.      * Remove image
  252.      *
  253.      * @param \Uniski\ResourceBundle\Entity\Image $image
  254.      */
  255.     public function removeImage(\Uniski\ResourceBundle\Entity\Image $image)
  256.     {
  257.         $this->images->removeElement($image);
  258.     }
  259.     /**
  260.      * @return   \Uniski\ResourceBundle\Entity\Image
  261.      */
  262.     public function getMainImage()
  263.     {
  264.         return $this->mainImage;
  265.     }
  266.     /**
  267.      * @param   \Uniski\ResourceBundle\Entity\Image $mainImage
  268.      *
  269.      * @return self
  270.      */
  271.     public function setMainImage($mainImage)
  272.     {
  273.         $this->mainImage $mainImage;
  274.         return $this;
  275.     }
  276.     /**
  277.      * @return   Uniski\ConfigBundle\Entity\Category
  278.      */
  279.     public function getZone()
  280.     {
  281.         return $this->zone;
  282.     }
  283.     /**
  284.      * @param   Uniski\ConfigBundle\Entity\Category $zone
  285.      *
  286.      * @return self
  287.      */
  288.     public function setZone($zone)
  289.     {
  290.         $this->zone $zone;
  291.         return $this;
  292.     }
  293.     /**
  294.      * @return   \Doctrine\Common\Collections\ArrayCollection
  295.      */
  296.     public function getCategory()
  297.     {
  298.         return $this->category;
  299.     }
  300.     /**
  301.      * @param   \Doctrine\Common\Collections\ArrayCollection $category
  302.      *
  303.      * @return self
  304.      */
  305.     public function setCategory($category)
  306.     {
  307.         $this->category $category;
  308.         return $this;
  309.     }
  310.     /**
  311.      * @return \Doctrine\Common\Collections\ArrayCollection
  312.      */
  313.     public function getProducts()
  314.     {
  315.         return $this->products;
  316.     }
  317.     /**
  318.      * @param \Doctrine\Common\Collections\ArrayCollection $products
  319.      *
  320.      * @return self
  321.      */
  322.     public function setProducts(\Doctrine\Common\Collections\ArrayCollection $products)
  323.     {
  324.         $this->products $products;
  325.         return $this;
  326.     }
  327.     public function addProduct(Product $product)
  328.     {
  329.         if (!$this->products->contains($product)) {
  330.             $product->setDestination($this);
  331.             $this->products->add($product);
  332.         }
  333.         return $this;
  334.     }
  335.     public function removeProduct($product)
  336.     {
  337.         if ($this->products->contains($product)) {
  338.             $product->setDestination(null);
  339.             $this->products->remove($product);
  340.         }
  341.         return $this;
  342.     }
  343.     public function getAvailableProducts()
  344.     {
  345.         $products = [];
  346.         
  347.         if (!$this->products) return [];
  348.         
  349.         foreach ($this->products as $product) {
  350.             if ($product->getActive()) $products[] = $product;
  351.         }
  352.         return $products;
  353.     }
  354.     /**
  355.      * @return SkiStation
  356.      */
  357.     public function getSki()
  358.     {
  359.         return $this->ski;
  360.     }
  361.     /**
  362.      * @param SkiStation $ski
  363.      *
  364.      * @return self
  365.      */
  366.     public function setSki(SkiStation $ski)
  367.     {
  368.         $this->ski $ski;
  369.         return $this;
  370.     }
  371.     /**
  372.      * @return  array
  373.      */
  374.     public function getLocation()
  375.     {
  376.         return $this->location;
  377.     }
  378.     /**
  379.      * @param  array $location
  380.      *
  381.      * @return self
  382.      */
  383.     public function setLocation($location)
  384.     {
  385.         $this->location $location;
  386.         return $this;
  387.     }
  388.     /**
  389.      * @return integer
  390.      */
  391.     public function getPriority()
  392.     {
  393.         return $this->priority;
  394.     }
  395.     /**
  396.      * @param integer $priority
  397.      *
  398.      * @return self
  399.      */
  400.     public function setPriority($priority)
  401.     {
  402.         $this->priority $priority;
  403.         return $this;
  404.     }
  405.     /**
  406.      * @return boolean
  407.      */
  408.     public function isActive()
  409.     {
  410.         return $this->active;
  411.     }
  412.     /**
  413.      * @param boolean $active
  414.      *
  415.      * @return self
  416.      */
  417.     public function setActive($active)
  418.     {
  419.         $this->active $active;
  420.         return $this;
  421.     }
  422.     public function getLatitude()
  423.     {
  424.         if (!$this->geoLocation) return null;
  425.         return $this->geoLocation->getLatitude();
  426.     }
  427.     public function getLongitude()
  428.     {
  429.         if (!$this->geoLocation) return null;
  430.         return $this->geoLocation->getLongitude();
  431.     }
  432.     /**
  433.      * @return GeoLocation
  434.      */
  435.     public function getGeoLocation()
  436.     {
  437.         return $this->geoLocation;
  438.     }
  439.     /**
  440.      * @param GeoLocation $geoLocation
  441.      *
  442.      * @return self
  443.      */
  444.     public function setGeoLocation(GeoLocation $geoLocation)
  445.     {
  446.         $this->geoLocation $geoLocation;
  447.         return $this;
  448.     }
  449. }