<?phpnamespace CoreBundle\Entity;use CoreBundle\Entity\Vehicles\Vehicle;use Application\Sonata\MediaBundle\Entity\Gallery;use Application\Sonata\MediaBundle\Entity\Media;use DateTime;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;/** * Post */class Post{    /**     * @var integer     */    private $id;    /**     * @var integer     */    private $state;    /**     * @var DateTime     */    private $date_start;    /**     * @var DateTime     */    private $date_end;    /**     * @var DateTime     */    private $date_create;    /**     * @var integer     */    private $bundle;    /**     * @var integer     */    private $post_type;    /**     * @var Collection     */    private $content;    /**     * @var User     */    private $creator;    /**     * @var Dealer     */    private $dealer;    private DateTime $updatedAt;    /**     * Constructor     */    public function __construct()    {        $this->content = new ArrayCollection();        $this->content->add((new PostContent())->setLanguage('ru'));        $this->content->add((new PostContent())->setLanguage('ua'));        $this->date_create = new DateTime();    }    /**     * Get id     *     * @return integer     */    public function getId()    {        return $this->id;    }    /**     * Set state     *     * @param integer $state     *     * @return Post     */    public function setState($state)    {        $this->state = $state;        return $this;    }    /**     * Get state     *     * @return integer     */    public function getState()    {        return $this->state > 0;    }    /**     * Set dateStart     *     * @param DateTime $dateStart     *     * @return Post     */    public function setDateStart($dateStart)    {        $this->date_start = $dateStart;        return $this;    }    /**     * Get dateStart     *     * @return DateTime     */    public function getDateStart()    {        return $this->date_start;    }    /**     * Set dateEnd     *     * @param DateTime $dateEnd     *     * @return Post     */    public function setDateEnd($dateEnd)    {        $this->date_end = $dateEnd;        return $this;    }    /**     * Get dateEnd     *     * @return DateTime     */    public function getDateEnd()    {        return $this->date_end;    }    /**     * Set dateCreate     *     * @param DateTime $dateCreate     *     * @return Post     */    public function setDateCreate($dateCreate)    {        $this->date_create = $dateCreate;        return $this;    }    /**     * Get dateCreate     *     * @return DateTime     */    public function getDateCreate()    {        return $this->date_create;    }    /**     * Set bundle     *     * @param integer $bundle     *     * @return Post     */    public function setBundle($bundle)    {        $this->bundle = $bundle;        return $this;    }    /**     * Get bundle     *     * @return integer     */    public function getBundle()    {        return $this->bundle;    }    /**     * Set postType     *     * @param integer $postType     *     * @return Post     */    public function setPostType($postType)    {        $this->post_type = $postType;        return $this;    }    /**     * Get postType     *     * @return integer     */    public function getPostType()    {        return $this->post_type;    }    /**     * Add content     *     * @param PostContent $content     *     * @return Post     */    public function addContent(PostContent $content)    {        $this->content[] = $content;        return $this;    }    /**     * Remove content     *     * @param PostContent $content     */    public function removeContent(PostContent $content)    {        $this->content->removeElement($content);    }    /**     * Get content     *     * @return Collection     */    public function getContent()    {        return $this->content;    }    /**     * Set creator     *     * @param User $creator     *     * @return Post     */    public function setCreator(User $creator = null)    {        $this->creator = $creator;        return $this;    }    /**     * Get creator     *     * @return User     */    public function getCreator()    {        return $this->creator;    }    /**     * Set dealer     *     * @param Dealer $dealer     *     * @return Post     */    public function setDealer(Dealer $dealer = null)    {        $this->dealer = $dealer;        return $this;    }    /**     * Get dealer     *     * @return Dealer     */    public function getDealer()    {        return $this->dealer;    }    /**     * @var integer     */    private $action_chapter;    /**     * Set actionChapter     *     * @param integer $actionChapter     *     * @return Post     */    public function setActionChapter($actionChapter)    {        $this->action_chapter = $actionChapter;        return $this;    }    /**     * @param string $locale     * @return PostContent     */    public function getContentByLocale($locale = 'ru')    {        if(!$locale) return $this->content->first();        /** @var PostContent $content */        foreach ($this->content as $content) {            if ($content->getLanguage() === $locale) {                return $content;            }        }        return $this->content->first();    }    /**     * Get actionChapter     *     * @return integer     */    public function getActionChapter()    {        return $this->action_chapter;    }    /**     * @param null $locale     * @return string     */    public function getTitle($locale = null)    {        $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->getTitle();    }    /**     * @param null $locale     * @return string     */    public function getSeoDescription($locale = null)    {        $content = $this->getContentByLocale($locale);        if(!$content) return '';        return $content->getSeoDescription();    }    /**     * @param null $locale     * @return Media|string     */    public function getImage($locale = null)    {        $content = $this->getContentByLocale($locale);        if(!$content) return '';        return $content->getImage();    }    /**     * @param null $locale     * @return string     */    public function getContentHtml($locale = null)    {        $content = $this->getContentByLocale($locale);        if(!$content) return '';        return $content->getContent();    }    /**     * @return string     */    public function __toString()    {        return ($this->getContentByLocale()) ? (string) $this->getContentByLocale()->getTitle() : '';    }    /**     * @var string     */    private $url;    /**     * Set url     *     * @param string $url     *     * @return Post     */    public function setUrl($url)    {        $this->url = $url;        return $this;    }    /**     * Get url     *     * @return string     */    public function getUrl()    {        return $this->url;    }    /**     * @var Gallery     */    private $gallery;    /**     * Set gallery     *     * @param Gallery $gallery     *     * @return Post     */    public function setGallery(Gallery $gallery = null)    {        $this->gallery = $gallery;        return $this;    }    /**     * Get gallery     *     * @return Gallery     */    public function getGallery()    {        return $this->gallery;    }    /**     * @var boolean     */    private $on_portal;    /**     * Set onPortal     *     * @param boolean $onPortal     *     * @return Post     */    public function setOnPortal($onPortal)    {        $this->on_portal = $onPortal;        return $this;    }    /**     * Get onPortal     *     * @return boolean     */    public function getOnPortal()    {        return $this->on_portal;    }    /**     * @param $locale     * @return string     */    public function getTypeName($locale)    {        return \CoreBundle\Model\Post::getTypeName($this->getPostType(), $locale);    }    /**     * @param $locale string     * @return string     */    public function getActionTypeName($locale)    {        return \CoreBundle\Model\Post::getTypeName($this->getPostType(), $locale);    }    /**     * @var Collection     */    private $vehicles;    /**     * Add vehicle     *     * @param Vehicle $vehicle     *     * @return Post     */    public function addVehicle(Vehicle $vehicle)    {        $this->vehicles[] = $vehicle;        return $this;    }    /**     * Remove vehicle     *     * @param Vehicle $vehicle     */    public function removeVehicle(Vehicle $vehicle)    {        $this->vehicles->removeElement($vehicle);    }    /**     * Get vehicles     *     * @return Collection     */    public function getVehicles()    {        return $this->vehicles;    }    /**     * @var string     */    private $uid;    /**     * Set uid     *     * @param string $uid     *     * @return Post     */    public function setUid($uid)    {        $this->uid = $uid;        return $this;    }    /**     * Get uid     *     * @return string     */    public function getUid()    {        return $this->uid;    }    /**     * @var Collection     */    private $log;    /**     * Add log     *     * @param PostLog $log     *     * @return Post     */    public function addLog(PostLog $log)    {        $this->log[] = $log;        return $this;    }    /**     * Remove log     *     * @param PostLog $log     */    public function removeLog(PostLog $log)    {        $this->log->removeElement($log);    }    /**     * Get log     *     * @return Collection     */    public function getLog()    {        return $this->log;    }    /**     * @var integer     */    private $active_link;    /**     * Set activeLink     *     * @param integer $activeLink     *     * @return Post     */    public function setActiveLink($activeLink)    {        $this->active_link = $activeLink;        return $this;    }    /**     * Get activeLink     *     * @return integer     */    public function getActiveLink()    {        return $this->active_link > 0;    }    /**     * @var int|null     */    private $show_button;    /**     * @var int|null     */    private $button_type;    /**     * Set showButton.     *     * @param integer $showButton     *     * @return Post     */    public function setShowButton($showButton)    {        $this->show_button = $showButton;        return $this;    }    /**     * Get show_button     *     * @return integer     */    public function getShowButton()    {        return $this->show_button > 0;    }    /**     * @var string|null     */    private $button_text;    /**     * @var string|null     */    private $button_href;    /**     * Set buttonText.     *     * @param string|null $buttonText     *     * @return Post     */    public function setButtonText($buttonText = null)    {        $this->button_text = $buttonText;        return $this;    }    /**     * Get buttonText.     *     * @return string|null     */    public function getButtonText($locale)    {        $content = $this->getContentByLocale($locale);        if(!$content) return '';        return $content->getButtonText();    }    /**     * Set buttonHref.     *     * @param string|null $buttonHref     *     * @return Post     */    public function setButtonHref($buttonHref = null)    {        $this->button_href = $buttonHref;        return $this;    }    /**     * Get buttonHref.     *     * @return string|null     */    public function getButtonHref()    {        return $this->button_href;    }    /**     * @var string|null     */    private $modal_data;    /**     * Set modalData.     *     * @param string|null $modalData     *     * @return Post     */    public function setModalData($modalData = null)    {        $this->modal_data = $modalData;        return $this;    }    /**     * Get modalData.     *     * @return string|null     */    public function getModalData()    {        return $this->modal_data;    }    public function getUpdatedAt(): \DateTimeInterface    {        return $this->updatedAt;    }    public function setUpdatedAt(): self    {        $this->updatedAt = new \DateTime();        return $this;    }}