<?php
namespace Uniski\ResourceBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Uniski\CommerceBundle\Exception\PriceNotFoundException;
use Uniski\ConfigBundle\Entity\Category;
/**
* @ORM\Entity
* @ORM\Table(name="insurance")
*
* Insurance entity
*/
class Insurance
{
/**
* @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 string
* @ORM\Column(name="description", type="text")
*/
protected $description;
/**
* @var string
* @ORM\ManyToOne(targetEntity="Document", cascade={"all"})
* @ORM\JoinColumn(name="document_id", referencedColumnName="id", nullable=true)
*/
protected $document;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\OneToMany(targetEntity="InsuranceRate", mappedBy="insurance", cascade={"all"})
*/
protected $rates;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToMany(targetEntity="Product", mappedBy="insurances")
*/
protected $products;
protected $currentPrice;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Insurance
*/
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 Insurance
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set document
*
* @param \Uniski\ResourceBundle\Entity\Document $document
*
* @return Insurance
*/
public function setDocument(\Uniski\ResourceBundle\Entity\Document $document = null)
{
$this->document = $document;
return $this;
}
/**
* Get document
*
* @return \Uniski\ResourceBundle\Entity\Document
*/
public function getDocument()
{
return $this->document;
}
/**
* Constructor
*/
public function __construct()
{
$this->rates = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add rate
*
* @param \Uniski\ResourceBundle\Entity\InsuranceRate $rate
*
* @return Insurance
*/
public function addRate(\Uniski\ResourceBundle\Entity\InsuranceRate $rate)
{
if ($this->rates->contains($rate)) return $this;
$rate->setInsurance($this);
$this->rates->add($rate);
return $this;
}
/**
* Remove rate
*
* @param \Uniski\ResourceBundle\Entity\InsuranceRate $rate
*/
public function removeRate(\Uniski\ResourceBundle\Entity\InsuranceRate $rate)
{
if (!$this->rates->contains($rate)) return $this;
$this->rates->removeElement($rate);
return $this;
}
/**
* Get rates
*
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getRates()
{
return $this->rates;
}
/**
* Set product
*
* @param \Uniski\ResourceBundle\Entity\Product $product
*
* @return Insurance
*/
public function addProduct(\Uniski\ResourceBundle\Entity\Product $product = null)
{
$this->products = $product;
return $this;
}
/**
* Get product
*
* @return ArrayCollection
*/
public function getProducts()
{
return $this->products;
}
/**
* Get product
*
* @return ArrayCollection
*/
public function setProducts(ArrayCollection $products)
{
$this->products = $products;
return $this;
}
public function getPrice(Category $zone, $days)
{
foreach($this->rates as $rate) {
if ($rate->getZone()->getId() == $zone->getId())
return $rate->getPrice($days);
}
throw new PriceNotFoundException();
}
/**
* Gets the value of currentPrice.
*
* @return mixed
*/
public function getCurrentPrice()
{
return $this->currentPrice;
}
/**
* Sets the value of currentPrice.
*
* @param mixed $currentPrice the current price
*
* @return self
*/
public function setCurrentPrice($currentPrice)
{
$this->currentPrice = $currentPrice;
return $this;
}
/**
* Remove product
*
* @param \Uniski\ResourceBundle\Entity\Product $product
*/
public function removeProduct(\Uniski\ResourceBundle\Entity\Product $product)
{
$this->products->removeElement($product);
}
}