src/CoreBundle/Entity/Vehicles/Feature.php line 13

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity\Vehicles;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Application\Sonata\MediaBundle\Entity\Media;
  5. use Application\Sonata\MediaBundle\Entity\Gallery;
  6. use Doctrine\Common\Collections\Collection;
  7. /**
  8.  * Feature
  9.  */
  10. class Feature
  11. {
  12.     /**
  13.      * @var integer
  14.      */
  15.     private $id;
  16.     /**
  17.      * @var integer
  18.      */
  19.     private $temp_id;
  20.     /**
  21.      * @var Media
  22.      */
  23.     private $image;
  24.     /**
  25.      * @var Collection
  26.      */
  27.     private $content;
  28.     /**
  29.      * @var Vehicle
  30.      */
  31.     private $vehicle;
  32.     /**
  33.      * @var FeatureGroup
  34.      */
  35.     private $group;
  36.     /**
  37.      * Constructor
  38.      */
  39.     public function __construct()
  40.     {
  41.         $this->content = new ArrayCollection();
  42.         $this->content->add((new FeatureContent())->setLanguage('ru')->setFeature($this));
  43.         $this->content->add((new FeatureContent())->setLanguage('ua')->setFeature($this));
  44.     }
  45.     /**
  46.      * Set id
  47.      *
  48.      * @param integer $id
  49.      *
  50.      * @return Feature
  51.      */
  52.     public function setId($id)
  53.     {
  54.         $this->id $id;
  55.         return $this;
  56.     }
  57.     /**
  58.      * Get id
  59.      *
  60.      * @return integer
  61.      */
  62.     public function getId()
  63.     {
  64.         return $this->id;
  65.     }
  66.     /**
  67.      * Set tempId
  68.      *
  69.      * @param integer $tempId
  70.      *
  71.      * @return Feature
  72.      */
  73.     public function setTempId($tempId)
  74.     {
  75.         $this->temp_id $tempId;
  76.         return $this;
  77.     }
  78.     /**
  79.      * Get tempId
  80.      *
  81.      * @return integer
  82.      */
  83.     public function getTempId()
  84.     {
  85.         return $this->temp_id;
  86.     }
  87.     /**
  88.      * Set image
  89.      *
  90.      * @param Media $image
  91.      *
  92.      * @return Feature
  93.      */
  94.     public function setImage(Media $image null)
  95.     {
  96.         $this->image $image;
  97.         return $this;
  98.     }
  99.     /**
  100.      * Get image
  101.      *
  102.      * @return Media
  103.      */
  104.     public function getImage()
  105.     {
  106.         return $this->image;
  107.     }
  108.     /**
  109.      * Add content
  110.      *
  111.      * @param FeatureContent $content
  112.      *
  113.      * @return Feature
  114.      */
  115.     public function addContent(FeatureContent $content)
  116.     {
  117.         $this->content[] = $content;
  118.         return $this;
  119.     }
  120.     /**
  121.      * Remove content
  122.      *
  123.      * @param FeatureContent $content
  124.      */
  125.     public function removeContent(FeatureContent $content)
  126.     {
  127.         $this->content->removeElement($content);
  128.     }
  129.     /**
  130.      * Get content
  131.      *
  132.      * @return Collection
  133.      */
  134.     public function getContent()
  135.     {
  136.         return $this->content;
  137.     }
  138.     public function getContentByLocale($locale)
  139.     {
  140.         /** @var FeatureContent $item */
  141.         foreach ($this->getContent() as $item) {
  142.             if($item->getLanguage() == $locale) {
  143.                 return $item;
  144.             }
  145.         }
  146.         return $this->getContent()->first();
  147.     }
  148.     /**
  149.      * Set vehicle
  150.      *
  151.      * @param Vehicle $vehicle
  152.      *
  153.      * @return Feature
  154.      */
  155.     public function setVehicle(Vehicle $vehicle null)
  156.     {
  157.         $this->vehicle $vehicle;
  158.         return $this;
  159.     }
  160.     /**
  161.      * Get vehicle
  162.      *
  163.      * @return Vehicle
  164.      */
  165.     public function getVehicle()
  166.     {
  167.         return $this->vehicle;
  168.     }
  169.     /**
  170.      * Set group
  171.      *
  172.      * @param FeatureGroup $group
  173.      *
  174.      * @return Feature
  175.      */
  176.     public function setGroup(FeatureGroup $group null)
  177.     {
  178.         $this->group $group;
  179.         return $this;
  180.     }
  181.     /**
  182.      * Get group
  183.      *
  184.      * @return FeatureGroup
  185.      */
  186.     public function getGroup()
  187.     {
  188.         return $this->group;
  189.     }
  190.     public function __toString()
  191.     {
  192.         if(!$this->content->count()) {
  193.             return '';
  194.         }
  195.         return (string) $this->content->first()->getTitle();
  196.     }
  197.     /**
  198.      * @var Gallery
  199.      */
  200.     private $video;
  201.     /**
  202.      * Set video
  203.      *
  204.      * @param Gallery $video
  205.      *
  206.      * @return Feature
  207.      */
  208.     public function setVideo(Gallery $video null)
  209.     {
  210.         $this->video $video;
  211.         return $this;
  212.     }
  213.     /**
  214.      * Get video
  215.      *
  216.      * @return Gallery
  217.      */
  218.     public function getVideo()
  219.     {
  220.         return $this->video;
  221.     }
  222. }