src/CoreBundle/Entity/BodyRepairCategory.php line 12

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Application\Sonata\MediaBundle\Entity\Media;
  5. use Doctrine\Common\Collections\Collection;
  6. /**
  7.  * BodyRepairCategory
  8.  */
  9. class BodyRepairCategory
  10. {
  11.     /**
  12.      * @var integer
  13.      */
  14.     private $id;
  15.     /**
  16.      * @var boolean
  17.      */
  18.     private $state;
  19.     /**
  20.      * @var string
  21.      */
  22.     private $url;
  23.     /**
  24.      * @var integer
  25.      */
  26.     private $position;
  27.     /**
  28.      * @var Media
  29.      */
  30.     private $image;
  31.     /**
  32.      * @var Collection
  33.      */
  34.     private $content;
  35.     /**
  36.      * @var Collection
  37.      */
  38.     private $child_category;
  39.     /**
  40.      * @var \CoreBundle\Entity\BodyRepairCategory
  41.      */
  42.     private $parent_category;
  43.     /**
  44.      * @var Collection
  45.      */
  46.     private $repairs;
  47.     /**
  48.      * Constructor
  49.      */
  50.     public function __construct()
  51.     {
  52.         $this->repairs = new ArrayCollection();
  53.         $this->content = new ArrayCollection();
  54.         $this->content->add((new BodyRepairCategoryContent())->setLanguage('ru'));
  55.         $this->content->add((new BodyRepairCategoryContent())->setLanguage('ua'));
  56.         $this->child_category = new ArrayCollection();
  57.     }
  58.     /**
  59.      * Get id
  60.      *
  61.      * @return integer
  62.      */
  63.     public function getId()
  64.     {
  65.         return $this->id;
  66.     }
  67.     /**
  68.      * Set state
  69.      *
  70.      * @param boolean $state
  71.      *
  72.      * @return BodyRepairCategory
  73.      */
  74.     public function setState($state)
  75.     {
  76.         $this->state $state;
  77.         return $this;
  78.     }
  79.     /**
  80.      * Get state
  81.      *
  82.      * @return boolean
  83.      */
  84.     public function getState()
  85.     {
  86.         return $this->state;
  87.     }
  88.     /**
  89.      * Set url
  90.      *
  91.      * @param string $url
  92.      *
  93.      * @return BodyRepairCategory
  94.      */
  95.     public function setUrl($url)
  96.     {
  97.         $this->url $url;
  98.         return $this;
  99.     }
  100.     /**
  101.      * Get url
  102.      *
  103.      * @return string
  104.      */
  105.     public function getUrl()
  106.     {
  107.         return $this->url;
  108.     }
  109.     /**
  110.      * Set position
  111.      *
  112.      * @param integer $position
  113.      *
  114.      * @return BodyRepairCategory
  115.      */
  116.     public function setPosition($position)
  117.     {
  118.         $this->position $position;
  119.         return $this;
  120.     }
  121.     /**
  122.      * Get position
  123.      *
  124.      * @return integer
  125.      */
  126.     public function getPosition()
  127.     {
  128.         return $this->position;
  129.     }
  130.     /**
  131.      * Set image
  132.      *
  133.      * @param Media $image
  134.      *
  135.      * @return BodyRepairCategory
  136.      */
  137.     public function setImage(Media $image null)
  138.     {
  139.         $this->image $image;
  140.         return $this;
  141.     }
  142.     /**
  143.      * Get image
  144.      *
  145.      * @return Media
  146.      */
  147.     public function getImage()
  148.     {
  149.         return $this->image;
  150.     }
  151.     /**
  152.      * Add content
  153.      *
  154.      * @param BodyRepairCategoryContent $content
  155.      *
  156.      * @return BodyRepairCategory
  157.      */
  158.     public function addContent(BodyRepairCategoryContent $content)
  159.     {
  160.         $this->content[] = $content;
  161.         return $this;
  162.     }
  163.     /**
  164.      * Remove content
  165.      *
  166.      * @param BodyRepairCategoryContent $content
  167.      */
  168.     public function removeContent(BodyRepairCategoryContent $content)
  169.     {
  170.         $this->content->removeElement($content);
  171.     }
  172.     /**
  173.      * Get content
  174.      *
  175.      * @return Collection
  176.      */
  177.     public function getContent()
  178.     {
  179.         return $this->content;
  180.     }
  181.     /**
  182.      * Add childCategory
  183.      *
  184.      * @param \CoreBundle\Entity\BodyRepairCategory $childCategory
  185.      *
  186.      * @return BodyRepairCategory
  187.      */
  188.     public function addChildCategory(\CoreBundle\Entity\BodyRepairCategory $childCategory)
  189.     {
  190.         $this->child_category[] = $childCategory;
  191.         return $this;
  192.     }
  193.     /**
  194.      * Remove childCategory
  195.      *
  196.      * @param \CoreBundle\Entity\BodyRepairCategory $childCategory
  197.      */
  198.     public function removeChildCategory(\CoreBundle\Entity\BodyRepairCategory $childCategory)
  199.     {
  200.         $this->child_category->removeElement($childCategory);
  201.     }
  202.     /**
  203.      * Get childCategory
  204.      *
  205.      * @return Collection
  206.      */
  207.     public function getChildCategory()
  208.     {
  209.         return $this->child_category;
  210.     }
  211.     /**
  212.      * Set parentCategory
  213.      *
  214.      * @param \CoreBundle\Entity\BodyRepairCategory $parentCategory
  215.      *
  216.      * @return BodyRepairCategory
  217.      */
  218.     public function setParentCategory(\CoreBundle\Entity\BodyRepairCategory $parentCategory null)
  219.     {
  220.         $this->parent_category $parentCategory;
  221.         return $this;
  222.     }
  223.     /**
  224.      * Get parentCategory
  225.      *
  226.      * @return \CoreBundle\Entity\BodyRepairCategory
  227.      */
  228.     public function getParentCategory()
  229.     {
  230.         return $this->parent_category;
  231.     }
  232.     public function getNameCategory()
  233.     {
  234.         return $this->content->first() ? (string) $this->content->first()->getTitle() : '';
  235.     }
  236.     public function __toString()
  237.     {
  238.         return $this->content->first() ? (string) $this->content->first()->getTitle() : '';
  239.     }
  240.     /**
  241.      * @param $locale
  242.      * @return BodyRepairCategoryContent|false|string
  243.      */
  244.     public function getContentByLocale($locale null)
  245.     {
  246.         /** @var BodyRepairCategoryContent $content */
  247.         foreach ($this->content as $content) {
  248.             if($content->getLanguage() == $locale) {
  249.                 return $content;
  250.             }
  251.         }
  252.         return $this->content->first();
  253.     }
  254.     /**
  255.      * @var float
  256.      */
  257.     private $price;
  258.     /**
  259.      * Set price
  260.      *
  261.      * @param float $price
  262.      *
  263.      * @return BodyRepairCategory
  264.      */
  265.     public function setPrice($price)
  266.     {
  267.         $this->price $price;
  268.         return $this;
  269.     }
  270.     /**
  271.      * Get price
  272.      *
  273.      * @return float
  274.      */
  275.     public function getPrice()
  276.     {
  277.         return $this->price;
  278.     }
  279. }