src/Uniski/ResourceBundle/Entity/Insurance.php line 16

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 Uniski\CommerceBundle\Exception\PriceNotFoundException;
  6. use Uniski\ConfigBundle\Entity\Category;
  7. /**
  8. * @ORM\Entity
  9. * @ORM\Table(name="insurance")
  10. *
  11. * Insurance entity
  12. */
  13. class Insurance
  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 string
  30.    * @ORM\Column(name="description", type="text")
  31.    */
  32.   protected $description;
  33.   /**
  34.    * @var string
  35.    * @ORM\ManyToOne(targetEntity="Document", cascade={"all"})
  36.    * @ORM\JoinColumn(name="document_id", referencedColumnName="id", nullable=true)
  37.    */
  38.   protected $document;
  39.   /**
  40.    * @var \Doctrine\Common\Collections\ArrayCollection
  41.    * @ORM\OneToMany(targetEntity="InsuranceRate", mappedBy="insurance", cascade={"all"})
  42.    */
  43.   protected $rates;
  44.   /**
  45.    * @var   \Doctrine\Common\Collections\ArrayCollection
  46.    * @ORM\ManyToMany(targetEntity="Product", mappedBy="insurances")
  47.    */
  48.   protected $products;
  49.   protected $currentPrice;
  50.     /**
  51.      * Get id
  52.      *
  53.      * @return integer
  54.      */
  55.     public function getId()
  56.     {
  57.         return $this->id;
  58.     }
  59.     /**
  60.      * Set name
  61.      *
  62.      * @param string $name
  63.      *
  64.      * @return Insurance
  65.      */
  66.     public function setName($name)
  67.     {
  68.         $this->name $name;
  69.         return $this;
  70.     }
  71.     /**
  72.      * Get name
  73.      *
  74.      * @return string
  75.      */
  76.     public function getName()
  77.     {
  78.         return $this->name;
  79.     }
  80.     /**
  81.      * Set description
  82.      *
  83.      * @param string $description
  84.      *
  85.      * @return Insurance
  86.      */
  87.     public function setDescription($description)
  88.     {
  89.         $this->description $description;
  90.         return $this;
  91.     }
  92.     /**
  93.      * Get description
  94.      *
  95.      * @return string
  96.      */
  97.     public function getDescription()
  98.     {
  99.         return $this->description;
  100.     }
  101.     /**
  102.      * Set document
  103.      *
  104.      * @param \Uniski\ResourceBundle\Entity\Document $document
  105.      *
  106.      * @return Insurance
  107.      */
  108.     public function setDocument(\Uniski\ResourceBundle\Entity\Document $document null)
  109.     {
  110.         $this->document $document;
  111.         return $this;
  112.     }
  113.     /**
  114.      * Get document
  115.      *
  116.      * @return \Uniski\ResourceBundle\Entity\Document
  117.      */
  118.     public function getDocument()
  119.     {
  120.         return $this->document;
  121.     }
  122.     /**
  123.      * Constructor
  124.      */
  125.     public function __construct()
  126.     {
  127.         $this->rates = new \Doctrine\Common\Collections\ArrayCollection();
  128.     }
  129.     /**
  130.      * Add rate
  131.      *
  132.      * @param \Uniski\ResourceBundle\Entity\InsuranceRate $rate
  133.      *
  134.      * @return Insurance
  135.      */
  136.     public function addRate(\Uniski\ResourceBundle\Entity\InsuranceRate $rate)
  137.     {
  138.         if ($this->rates->contains($rate)) return $this;
  139.         $rate->setInsurance($this);
  140.         $this->rates->add($rate);
  141.         return $this;
  142.     }
  143.     /**
  144.      * Remove rate
  145.      *
  146.      * @param \Uniski\ResourceBundle\Entity\InsuranceRate $rate
  147.      */
  148.     public function removeRate(\Uniski\ResourceBundle\Entity\InsuranceRate $rate)
  149.     {
  150.         if (!$this->rates->contains($rate)) return $this;
  151.         $this->rates->removeElement($rate);
  152.         return $this;
  153.     }
  154.     /**
  155.      * Get rates
  156.      *
  157.      * @return \Doctrine\Common\Collections\ArrayCollection
  158.      */
  159.     public function getRates()
  160.     {
  161.         return $this->rates;
  162.     }
  163.     /**
  164.      * Set product
  165.      *
  166.      * @param \Uniski\ResourceBundle\Entity\Product $product
  167.      *
  168.      * @return Insurance
  169.      */
  170.     public function addProduct(\Uniski\ResourceBundle\Entity\Product $product null)
  171.     {
  172.         $this->products $product;
  173.         return $this;
  174.     }
  175.     /**
  176.      * Get product
  177.      *
  178.      * @return ArrayCollection
  179.      */
  180.     public function getProducts()
  181.     {
  182.         return $this->products;
  183.     }
  184.     /**
  185.      * Get product
  186.      *
  187.      * @return ArrayCollection
  188.      */
  189.     public function setProducts(ArrayCollection $products)
  190.     {
  191.         $this->products $products;
  192.         return $this;
  193.     }
  194.     public function getPrice(Category $zone$days)
  195.     {
  196.       foreach($this->rates as $rate) {
  197.         if ($rate->getZone()->getId() == $zone->getId())
  198.           return $rate->getPrice($days);
  199.       }
  200.       throw new PriceNotFoundException();
  201.     }
  202.     /**
  203.      * Gets the value of currentPrice.
  204.      *
  205.      * @return mixed
  206.      */
  207.     public function getCurrentPrice()
  208.     {
  209.         return $this->currentPrice;
  210.     }
  211.     /**
  212.      * Sets the value of currentPrice.
  213.      *
  214.      * @param mixed $currentPrice the current price
  215.      *
  216.      * @return self
  217.      */
  218.     public function setCurrentPrice($currentPrice)
  219.     {
  220.         $this->currentPrice $currentPrice;
  221.         return $this;
  222.     }
  223.     /**
  224.      * Remove product
  225.      *
  226.      * @param \Uniski\ResourceBundle\Entity\Product $product
  227.      */
  228.     public function removeProduct(\Uniski\ResourceBundle\Entity\Product $product)
  229.     {
  230.         $this->products->removeElement($product);
  231.     }
  232. }