<?phpnamespace CoreBundle\Entity;use Doctrine\Common\Collections\ArrayCollection;use Application\Sonata\MediaBundle\Entity\Media;use Doctrine\Common\Collections\Collection;/** * ServicePageCategory */class ServicePageCategory{ /** * @var integer */ private $id; /** * @var boolean */ private $state; /** * @var string */ private $url; /** * @var integer */ private $position; /** * @var Media */ private $image; /** * @var Collection */ private $content; /** * @var Collection */ private $pages; /** * @var \CoreBundle\Entity\ServicePageCategory */ private $parent_category; /** * @var Collection */ private $child_category; /** * Constructor */ public function __construct() { $this->content = new ArrayCollection(); $this->content->add((new ServicePageCategoryContent())->setLanguage('ru')); $this->content->add((new ServicePageCategoryContent())->setLanguage('ua')); $this->pages = new ArrayCollection(); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set state * * @param boolean $state * * @return ServicePageCategory */ public function setState($state) { $this->state = $state; return $this; } /** * Get state * * @return boolean */ public function getState() { return $this->state; } /** * Set url * * @param string $url * * @return ServicePageCategory */ public function setUrl($url) { $this->url = $url; return $this; } /** * Get url * * @return string */ public function getUrl() { return $this->url; } /** * Set position * * @param integer $position * * @return ServicePageCategory */ public function setPosition($position) { $this->position = $position; return $this; } /** * Get position * * @return integer */ public function getPosition() { return $this->position; } /** * Set image * * @param Media $image * * @return ServicePageCategory */ public function setImage(Media $image = null) { $this->image = $image; return $this; } /** * Get image * * @return Media */ public function getImage() { return $this->image; } /** * Add content * * @param ServicePageCategoryContent $content * * @return ServicePageCategory */ public function addContent(ServicePageCategoryContent $content) { $this->content[] = $content; return $this; } /** * Remove content * * @param ServicePageCategoryContent $content */ public function removeContent(ServicePageCategoryContent $content) { $this->content->removeElement($content); } /** * Get content * * @return Collection */ public function getContent() { return $this->content; } /** * Add page * * @param ServicePage $page * * @return ServicePageCategory */ public function addPage(ServicePage $page) { $this->pages[] = $page; return $this; } /** * Remove page * * @param ServicePage $page */ public function removePage(ServicePage $page) { $this->pages->removeElement($page); } /** * Get pages * * @return Collection */ public function getPages() { return $this->pages; } public function getTitle() { return $this->getContentByLocale()->getTitle(); } /** * Set parentCategory * * @param \CoreBundle\Entity\ServicePageCategory $parentCategory * * @return ServicePageCategory */ public function setParentCategory(\CoreBundle\Entity\ServicePageCategory $parentCategory = null) { $this->parent_category = $parentCategory; return $this; } /** * Get parentCategory * * @return \CoreBundle\Entity\ServicePageCategory */ public function getParentCategory() { return $this->parent_category; } /** * Add childCategory * * @param \CoreBundle\Entity\ServicePageCategory $childCategory * * @return ServicePageCategory */ public function addChildCategory(\CoreBundle\Entity\ServicePageCategory $childCategory) { $this->child_category[] = $childCategory; return $this; } /** * Remove childCategory * * @param \CoreBundle\Entity\ServicePageCategory $childCategory */ public function removeChildCategory(\CoreBundle\Entity\ServicePageCategory $childCategory) { $this->child_category->removeElement($childCategory); } /** * Get childCategory * * @return Collection */ public function getChildCategory() { return $this->child_category; } public function __toString() { return $this->content->first() ? (string) $this->content->first()->getTitle() : ''; } public function getContentByLocale($locale = null) { /** @var ServicePageCategoryContent $content */ foreach ($this->content as $content) { if($content->getLanguage() == $locale) { return $content; } } return $this->content->first(); }}