<?php
namespace App\Entity\Pages;
use App\Entity\HeaderImage;
use App\Entity\ListImage;
use App\Entity\NewsCategory;
use App\Entity\NewsTag;
use App\Entity\Traits\MenuTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
use Kunstmaan\ArticleBundle\Entity\AbstractArticlePage;
use Kunstmaan\NodeSearchBundle\Helper\SearchTypeInterface;
use Kunstmaan\PagePartBundle\Helper\HasPageTemplateInterface;
use Kunstmaan\NodeBundle\Entity\HideSidebarInNodeEditInterface;
use App\Form\Pages\NewsPageAdminType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Validator\Constraints\Collection;
/**
* @ORM\Entity(repositoryClass="App\Repository\NewsPageRepository")
* @ORM\Table(name="gcs_news_pages")
* @ORM\HasLifecycleCallbacks
* @ORM\AssociationOverrides(
* @ORM\AssociationOverride(name="headerImage",
* joinTable=@ORM\JoinTable(name="gcs_pages_header_images_news_page"),
* joinColumns=@ORM\JoinColumn(
* name="news_page_id", referencedColumnName="id"
* )
* ),
* @ORM\AssociationOverride(name="listImage",
* joinTable=@ORM\JoinTable(name="gcs_pages_list_images_news_page"),
* joinColumns=@ORM\JoinColumn(
* name="news_page_id", referencedColumnName="id"
* )
* )
* )
*/
class NewsPage extends AbstractArticlePage implements HasPageTemplateInterface, SearchTypeInterface, HideSidebarInNodeEditInterface
{
use MenuTrait;
/**
* @var \App\Entity\NewsAuthor
*
* @ORM\ManyToOne(targetEntity="App\Entity\NewsAuthor")
* @ORM\JoinColumn(name="news_author_id", referencedColumnName="id")
*/
protected $author;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="App\Entity\NewsCategory", cascade={"persist"}, inversedBy="news")
*/
protected $categories;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="App\Entity\NewsTag", cascade={"persist"}, inversedBy="news")
*/
protected $tags;
/**
* @ORM\Column(type="boolean")
*/
private $showOnHomepage = false;
public function __construct()
{
$this->categories = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->headerImage = new ArrayCollection();
$this->listImage = new ArrayCollection(); }
/**
* @param \App\Entity\NewsAuthor $author
* @return $this
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* @return \App\Entity\NewsAuthor $author
*/
public function getAuthor()
{
return $this->author;
}
/**
* @param \App\Entity\NewsCategory $category
* @return $this
*/
public function setCategories($category)
{
$this->categories = $category;
return $this;
}
/**
* @return ArrayCollection
*/
public function getCategories()
{
return $this->categories;
}
public function getCategoriesNames()
{
$array = [];
/** @var NewsCategory $category */
foreach ($this->getCategories() as $category) {
$array[] = $category->getName();
}
return $array;
}
public function getCategoriesIds()
{
$array = [];
/** @var NewsCategory $category */
foreach ($this->getCategories() as $category) {
$array[] = $category->getId();
}
return $array;
}
/**
* @param \App\Entity\NewsTag $tag
* @return $this
*/
public function setTags($tag)
{
$this->tags = $tag;
return $this;
}
/**
* @return ArrayCollection
*/
public function getTags()
{
return $this->tags;
}
public function removeCategories(NewsCategory $category): self
{
if ($this->categories->contains($category)) {
$this->categories->removeElement($category);
}
return $this;
}
public function removeTags(NewsTag $tag): self
{
if ($this->tags->contains($tag)) {
$this->tags->removeElement($tag);
}
return $this;
}
/**
* Returns the default backend form type for this page
*
* @return string
*/
public function getDefaultAdminType()
{
return NewsPageAdminType::class;
}
/**
* {@inheritdoc}
*/
public function getSearchType()
{
return 'News';
}
/**
* @return array
*/
public function getPagePartAdminConfigurations()
{
return array('newsmain');
}
/**
* {@inheritdoc}
*/
public function getPageTemplates()
{
return array('newspage');
}
public function getDefaultView()
{
return 'Pages/NewsPage/view.html.twig';
}
/**
* Before persisting this entity, check the date.
* When no date is present, fill in current date and time.
*
* @ORM\PrePersist
*/
public function _prePersist()
{
// Set date to now when none is set
if ($this->date == null) {
$this->setDate(new \DateTime());
}
}
public function getShowOnHomepage(): ?bool
{
return $this->showOnHomepage;
}
public function setShowOnHomepage(bool $showOnHomepage): self
{
$this->showOnHomepage = $showOnHomepage;
return $this;
}
}