<?phpnamespace DcSiteBundle\Entity;use Application\Sonata\MediaBundle\Entity\Media;use CoreBundle\Entity\Dealer;use Doctrine\Common\Collections\Collection;use Doctrine\Common\Collections\ArrayCollection;/** * ServiceWorkCategory */class ServiceWorkCategory{    /**     * @var integer     */    private $id;    /**     * @var integer     */    private $state;    /**     * @var string     */    private $url;    /**     * @var integer     */    private $position;    /**     * @var Media     */    private $image;    /**     * @var Collection     */    private $content;    /**     * @var Dealer     */    private $dealer;    /**     * @var \DcSiteBundle\Entity\ServiceWorkCategory     */    private $parent_category;    /**     * @var Collection     */    private $work_items;    /**     * Constructor     */    public function __construct()    {        $this->content = new ArrayCollection();        $this->content->add((new ServiceWorkCategoryContent())->setLanguage('ru'));        $this->content->add((new ServiceWorkCategoryContent())->setLanguage('ua'));        $this->work_items = new ArrayCollection();    }    /**     * @return string     */    public function __toString()    {        return (string) $this->getTitle();    }    /**     * Get id     *     * @return integer     */    public function getId()    {        return $this->id;    }    /**     * Set state     *     * @param integer $state     *     * @return ServiceWorkCategory     */    public function setState($state)    {        $this->state = $state;        return $this;    }    /**     * Get state     *     * @return integer     */    public function getState()    {        return $this->state > 0;    }    /**     * Set url     *     * @param string $url     *     * @return ServiceWorkCategory     */    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 ServiceWorkCategory     */    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 ServiceWorkCategory     */    public function setImage(Media $image = null)    {        $this->image = $image;        return $this;    }    /**     * Get image     *     * @return Media     */    public function getImage()    {        return $this->image;    }    /**     * Add content     *     * @param ServiceWorkCategoryContent $content     *     * @return ServiceWorkCategory     */    public function addContent(ServiceWorkCategoryContent $content)    {        $this->content[] = $content;        return $this;    }    /**     * Remove content     *     * @param ServiceWorkCategoryContent $content     */    public function removeContent(ServiceWorkCategoryContent $content)    {        $this->content->removeElement($content);    }    /**     * Get content     *     * @return Collection     */    public function getContent()    {        return $this->content;    }    /**     * Set dealer     *     * @param Dealer $dealer     *     * @return ServiceWorkCategory     */    public function setDealer(Dealer $dealer = null)    {        $this->dealer = $dealer;        return $this;    }    /**     * Get dealer     *     * @return Dealer     */    public function getDealer()    {        return $this->dealer;    }    /**     * Set parentCategory     *     * @param \DcSiteBundle\Entity\ServiceWorkCategory $parentCategory     *     * @return ServiceWorkCategory     */    public function setParentCategory(\DcSiteBundle\Entity\ServiceWorkCategory $parentCategory = null)    {        $this->parent_category = $parentCategory;        return $this;    }    /**     * Get parentCategory     *     * @return \DcSiteBundle\Entity\ServiceWorkCategory     */    public function getParentCategory()    {        return $this->parent_category;    }    /**     * Add workItem     *     * @param ServiceWork $workItem     *     * @return ServiceWorkCategory     */    public function addWorkItem(ServiceWork $workItem)    {        $this->work_items[] = $workItem;        return $this;    }    /**     * Remove workItem     *     * @param ServiceWork $workItem     */    public function removeWorkItem(ServiceWork $workItem)    {        $this->work_items->removeElement($workItem);    }    /**     * Get workItems     *     * @return Collection     */    public function getWorkItems()    {        return $this->work_items;    }    private function getContentByLocale($locale = 'ru')    {        if(!$locale) return $this->content->first();        /** @var ServiceWorkCategoryContent $content */        foreach ($this->content as $content) {            if ($content->getLanguage() === $locale) {                return $content;            }        }        return $this->content->first();    }    /**     * @param null $locale     * @return string     */    public function getTitle($locale = 'ua')    {        $content = $this->getContentByLocale($locale);        if(!$content) return '';        return $content->getTitle();    }    /**     * @param null $locale     * @return string     */    public function getDescription($locale = null)    {        $content = $this->getContentByLocale($locale);        if(!$content) return '';        return $content->getDescription();    }    /**     * @param null $locale     * @return string     */    public function getSeoTitle($locale = null)    {        $content = $this->getContentByLocale($locale);        if(!$content) return '';        return $content->getSeoTitle();    }    /**     * @param null $locale     * @return string     */    public function getSeoDescription($locale = null)    {        $content = $this->getContentByLocale($locale);        if(!$content) return '';        return $content->getSeoDescription();    }}