<?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\ValueObject\GeoLocation;
use Uniski\ResourceBundle\Entity\ValueObject\SkiStation;
use Uniski\Utils\TeaserGenerator;
/**
* @ORM\Entity
**/
class Destination
{
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var string
* @ORM\Column(name="name", type="string")
*/
protected $name;
/**
* @var array
* @ORM\Column(name="location", type="json", nullable=true)
*/
protected $location;
/**
* @var string
* @ORM\Column(name="description", type="text", nullable=true)
*/
protected $description;
/**
* @var array
* @ORM\Column(name="seo", type="json")
*/
protected $seo;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(length=128, unique=true)
*/
private $slug;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToMany(targetEntity="Image", cascade={"all"})
* @ORM\JoinTable(name="destination_images",
* joinColumns={@ORM\JoinColumn(name="destination_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="image_id", referencedColumnName="id")})
*/
protected $images;
/**
* @var \Uniski\ResourceBundle\Entity\Image
* @ORM\ManyToOne(targetEntity="Image", cascade={"all"})
*/
protected $mainImage;
/**
* @var Uniski\ConfigBundle\Entity\Category
* @ORM\ManyToOne(targetEntity="Uniski\ConfigBundle\Entity\Category")
*
*/
protected $zone;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToOne(targetEntity="Uniski\ConfigBundle\Entity\Category")
*
* Ski, Vacaciones, Aventura
*/
protected $category;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\OneToMany(targetEntity="Product", mappedBy="destination", cascade={"all"})
*/
protected $products;
/**
* @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 SkiStation
* @ORM\Embedded(class="Uniski\ResourceBundle\Entity\ValueObject\SkiStation")
*/
protected $ski;
/**
* @var integer
* @ORM\Column(type="smallint")
*/
protected $priority;
/**
* @var boolean
* @ORM\Column(type="boolean")
*/
protected $active;
/**
* @var GeoLocation
* @ORM\Embedded(class="Uniski\ResourceBundle\Entity\ValueObject\GeoLocation")
*/
protected $geoLocation;
function __construct()
{
$this->images = new ArrayCollection();
$this->products = new ArrayCollection();
$this->ski = new SkiStation();
$this->active = true;
$this->priority = 0;
}
/**
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @param integer $id
*
* @return self
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*
* @return self
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*
* @return self
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get seo
*
* @return array
*/
public function getSeo()
{
$seo = $this->seo;
if (empty($seo['title']) && $this->name) {
$seo['title'] = sprintf("Ofertas esquí %s", $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;
}
/**
* @param array $seo
*
* @return self
*/
public function setSeo($seo)
{
$this->seo = $seo;
return $this;
}
/**
* @return mixed
*/
public function getSlug()
{
return $this->slug;
}
/**
* @param mixed $slug
*
* @return self
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getImages()
{
return $this->images;
}
/**
* @param \Doctrine\Common\Collections\ArrayCollection $images
*
* @return self
*/
public function setImages($images)
{
$this->images = $images;
return $this;
}
/**
* 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);
}
/**
* @return \Uniski\ResourceBundle\Entity\Image
*/
public function getMainImage()
{
return $this->mainImage;
}
/**
* @param \Uniski\ResourceBundle\Entity\Image $mainImage
*
* @return self
*/
public function setMainImage($mainImage)
{
$this->mainImage = $mainImage;
return $this;
}
/**
* @return Uniski\ConfigBundle\Entity\Category
*/
public function getZone()
{
return $this->zone;
}
/**
* @param Uniski\ConfigBundle\Entity\Category $zone
*
* @return self
*/
public function setZone($zone)
{
$this->zone = $zone;
return $this;
}
/**
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getCategory()
{
return $this->category;
}
/**
* @param \Doctrine\Common\Collections\ArrayCollection $category
*
* @return self
*/
public function setCategory($category)
{
$this->category = $category;
return $this;
}
/**
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getProducts()
{
return $this->products;
}
/**
* @param \Doctrine\Common\Collections\ArrayCollection $products
*
* @return self
*/
public function setProducts(\Doctrine\Common\Collections\ArrayCollection $products)
{
$this->products = $products;
return $this;
}
public function addProduct(Product $product)
{
if (!$this->products->contains($product)) {
$product->setDestination($this);
$this->products->add($product);
}
return $this;
}
public function removeProduct($product)
{
if ($this->products->contains($product)) {
$product->setDestination(null);
$this->products->remove($product);
}
return $this;
}
public function getAvailableProducts()
{
$products = [];
if (!$this->products) return [];
foreach ($this->products as $product) {
if ($product->getActive()) $products[] = $product;
}
return $products;
}
/**
* @return SkiStation
*/
public function getSki()
{
return $this->ski;
}
/**
* @param SkiStation $ski
*
* @return self
*/
public function setSki(SkiStation $ski)
{
$this->ski = $ski;
return $this;
}
/**
* @return array
*/
public function getLocation()
{
return $this->location;
}
/**
* @param array $location
*
* @return self
*/
public function setLocation($location)
{
$this->location = $location;
return $this;
}
/**
* @return integer
*/
public function getPriority()
{
return $this->priority;
}
/**
* @param integer $priority
*
* @return self
*/
public function setPriority($priority)
{
$this->priority = $priority;
return $this;
}
/**
* @return boolean
*/
public function isActive()
{
return $this->active;
}
/**
* @param boolean $active
*
* @return self
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
public function getLatitude()
{
if (!$this->geoLocation) return null;
return $this->geoLocation->getLatitude();
}
public function getLongitude()
{
if (!$this->geoLocation) return null;
return $this->geoLocation->getLongitude();
}
/**
* @return GeoLocation
*/
public function getGeoLocation()
{
return $this->geoLocation;
}
/**
* @param GeoLocation $geoLocation
*
* @return self
*/
public function setGeoLocation(GeoLocation $geoLocation)
{
$this->geoLocation = $geoLocation;
return $this;
}
}