src/DcSiteBundle/Entity/AccessoriesCategory.php line 12

Open in your IDE?
  1. <?php
  2. namespace DcSiteBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Application\Sonata\MediaBundle\Entity\Media;
  5. use Doctrine\Common\Collections\Collection;
  6. /**
  7.  * AccessoriesCategory
  8.  */
  9. class AccessoriesCategory
  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 $accessory_items;
  35.     /**
  36.      * @var Collection
  37.      */
  38.     private $content;
  39.     /**
  40.      * @var Collection
  41.      */
  42.     private $child_category;
  43.     /**
  44.      * @var \DcSiteBundle\Entity\AccessoriesCategory
  45.      */
  46.     private $parent_category;
  47.     /**
  48.      * Constructor
  49.      */
  50.     public function __construct()
  51.     {
  52.         $this->accessory_items = new ArrayCollection();
  53.         $this->content = new ArrayCollection();
  54.         $this->content->add((new AccessoriesCategoryContent())->setLanguage('ru'));
  55.         $this->content->add((new AccessoriesCategoryContent())->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 AccessoriesCategory
  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 AccessoriesCategory
  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 AccessoriesCategory
  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 AccessoriesCategory
  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 accessoryItem
  153.      *
  154.      * @param Accessories $accessoryItem
  155.      *
  156.      * @return AccessoriesCategory
  157.      */
  158.     public function addAccessoryItem(Accessories $accessoryItem)
  159.     {
  160.         $this->accessory_items[] = $accessoryItem;
  161.         return $this;
  162.     }
  163.     /**
  164.      * Remove accessoryItem
  165.      *
  166.      * @param Accessories $accessoryItem
  167.      */
  168.     public function removeAccessoryItem(Accessories $accessoryItem)
  169.     {
  170.         $this->accessory_items->removeElement($accessoryItem);
  171.     }
  172.     /**
  173.      * Get accessoryItems
  174.      *
  175.      * @return Collection
  176.      */
  177.     public function getAccessoryItems()
  178.     {
  179.         return $this->accessory_items;
  180.     }
  181.     /**
  182.      * Add content
  183.      *
  184.      * @param AccessoriesCategoryContent $content
  185.      *
  186.      * @return AccessoriesCategory
  187.      */
  188.     public function addContent(AccessoriesCategoryContent $content)
  189.     {
  190.         $this->content[] = $content;
  191.         return $this;
  192.     }
  193.     /**
  194.      * Remove content
  195.      *
  196.      * @param AccessoriesCategoryContent $content
  197.      */
  198.     public function removeContent(AccessoriesCategoryContent $content)
  199.     {
  200.         $this->content->removeElement($content);
  201.     }
  202.     /**
  203.      * Get content
  204.      *
  205.      * @return Collection
  206.      */
  207.     public function getContent()
  208.     {
  209.         return $this->content;
  210.     }
  211.     /**
  212.      * Add childCategory
  213.      *
  214.      * @param \DcSiteBundle\Entity\AccessoriesCategory $childCategory
  215.      *
  216.      * @return AccessoriesCategory
  217.      */
  218.     public function addChildCategory(\DcSiteBundle\Entity\AccessoriesCategory $childCategory)
  219.     {
  220.         $this->child_category[] = $childCategory;
  221.         return $this;
  222.     }
  223.     /**
  224.      * Remove childCategory
  225.      *
  226.      * @param \DcSiteBundle\Entity\AccessoriesCategory $childCategory
  227.      */
  228.     public function removeChildCategory(\DcSiteBundle\Entity\AccessoriesCategory $childCategory)
  229.     {
  230.         $this->child_category->removeElement($childCategory);
  231.     }
  232.     /**
  233.      * Get childCategory
  234.      *
  235.      * @return Collection
  236.      */
  237.     public function getChildCategory()
  238.     {
  239.         return $this->child_category;
  240.     }
  241.     /**
  242.      * Set parentCategory
  243.      *
  244.      * @param \DcSiteBundle\Entity\AccessoriesCategory $parentCategory
  245.      *
  246.      * @return AccessoriesCategory
  247.      */
  248.     public function setParentCategory(\DcSiteBundle\Entity\AccessoriesCategory $parentCategory null)
  249.     {
  250.         $this->parent_category $parentCategory;
  251.         return $this;
  252.     }
  253.     /**
  254.      * Get parentCategory
  255.      *
  256.      * @return \DcSiteBundle\Entity\AccessoriesCategory
  257.      */
  258.     public function getParentCategory()
  259.     {
  260.         return $this->parent_category;
  261.     }
  262.     public function getNameCategory()
  263.     {
  264.         return $this->content->first() ? (string) $this->content->first()->getNameCategory() : '';
  265.     }
  266.     public function __toString()
  267.     {
  268.         return $this->content->first() ? (string) $this->content->first()->getNameCategory() : '';
  269.     }
  270.     public function getContentByLocale($locale null)
  271.     {
  272.         /** @var AccessoriesCategoryContent $content */
  273.         foreach ($this->content as $content) {
  274.             if($content->getLanguage() == $locale) {
  275.                 return $content;
  276.             }
  277.         }
  278.         return $this->content->first();
  279.     }
  280. }