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