src/CoreBundle/Entity/Vehicles/Faq.php line 11

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity\Vehicles;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. /**
  6.  * FAQ
  7.  */
  8. class Faq
  9. {
  10.     /**
  11.      * @var integer
  12.      */
  13.     private $id;
  14.     /**
  15.      * @var integer
  16.      */
  17.     private $temp_id;
  18.     /**
  19.      * @var Collection
  20.      */
  21.     private $content;
  22.     /**
  23.      * @var Vehicle
  24.      */
  25.     private $vehicle;
  26.     /**
  27.      * Constructor
  28.      */
  29.     public function __construct()
  30.     {
  31.         $this->content = new ArrayCollection();
  32.         $this->content->add((new FaqContent())->setLanguage('ru')->setFaq($this));
  33.         $this->content->add((new FaqContent())->setLanguage('ua')->setFaq($this));
  34.     }
  35.     public function __toString()
  36.     {
  37.         if(!$this->content->count()) {
  38.             return '';
  39.         }
  40.         return (string) $this->content->first()->getTitle();
  41.     }
  42.     /**
  43.      * Get id
  44.      *
  45.      * @return integer
  46.      */
  47.     public function getId()
  48.     {
  49.         return $this->id;
  50.     }
  51.     /**
  52.      * Set tempId
  53.      *
  54.      * @param integer $tempId
  55.      *
  56.      * @return Faq
  57.      */
  58.     public function setTempId($tempId)
  59.     {
  60.         $this->temp_id $tempId;
  61.         return $this;
  62.     }
  63.     /**
  64.      * Get tempId
  65.      *
  66.      * @return integer
  67.      */
  68.     public function getTempId()
  69.     {
  70.         return $this->temp_id;
  71.     }
  72.     /**
  73.      * Add content
  74.      *
  75.      * @param FAQContent $content
  76.      *
  77.      * @return Faq
  78.      */
  79.     public function addContent(FAQContent $content)
  80.     {
  81.         $this->content[] = $content;
  82.         return $this;
  83.     }
  84.     /**
  85.      * Remove content
  86.      *
  87.      * @param FAQContent $content
  88.      */
  89.     public function removeContent(FAQContent $content)
  90.     {
  91.         $this->content->removeElement($content);
  92.     }
  93.     /**
  94.      * Get content
  95.      *
  96.      * @return Collection
  97.      */
  98.     public function getContent()
  99.     {
  100.         return $this->content;
  101.     }
  102.     /**
  103.      * Set vehicle
  104.      *
  105.      * @param Vehicle $vehicle
  106.      *
  107.      * @return Faq
  108.      */
  109.     public function setVehicle(Vehicle $vehicle null)
  110.     {
  111.         $this->vehicle $vehicle;
  112.         return $this;
  113.     }
  114.     /**
  115.      * Get vehicle
  116.      *
  117.      * @return Vehicle
  118.      */
  119.     public function getVehicle()
  120.     {
  121.         return $this->vehicle;
  122.     }
  123.     public function getContentByLocale($locale)
  124.     {
  125.         /** @var FaqContent $item */
  126.         foreach ($this->getContent() as $item) {
  127.             if($item->getLanguage() == $locale) {
  128.                 return $item;
  129.             }
  130.         }
  131.         return $this->getContent()->first();
  132.     }
  133. }