<?php
namespace App\Entity;
use App\Entity\Traits\LinkTrait;
use App\Entity\Traits\MetaTrait;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Traits\ActiveTrait;
use App\Entity\Traits\DeleteTrait;
use App\Repository\NewsRepository;
use App\Entity\Traits\SubTitleTrait;
use App\Entity\Traits\TranslateTrait;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Entity\Traits\ImageUploadTrait;
use App\Entity\Traits\TitleAndContentTrait;
use App\Entity\Traits\ThirdImageUploadTrait;
use App\Entity\Traits\SecondImageUploadTrait;
use App\Entity\Traits\SitemapableTrait;
use App\Entity\Interfaces\DefaultLinkedEntity;
use Gedmo\Timestampable\Traits\TimestampableEntity;
/**
* News.
*
* @Gedmo\Loggable
*
* @Gedmo\TranslationEntity(class="App\Entity\NewsTranslations")
*/
#[ORM\Entity(repositoryClass: NewsRepository::class)]
#[ORM\Table(name: 'news')]
class News implements DefaultLinkedEntity
{
use TitleAndContentTrait;
use SubTitleTrait;
use LinkTrait;
use MetaTrait;
use ActiveTrait;
use DeleteTrait;
use ImageUploadTrait;
use SecondImageUploadTrait;
use ThirdImageUploadTrait;
use TimestampableEntity;
use TranslateTrait;
use SitemapableTrait;
public $imageUpload;
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private int $id;
/**
* @Gedmo\Versioned
*
* @Gedmo\Translatable
*/
#[ORM\Column(name: 'excerpt', type: 'text', nullable: true)]
private ?string $excerpt = null;
/**
* @Gedmo\Versioned
*/
#[ORM\Column(name: 'publish_date', type: 'datetime')]
private ?\DateTimeInterface $publishDate = null;
/**
* @Gedmo\Versioned
*/
#[ORM\Column(name: 'thumbnail', type: 'string', length: 255, nullable: true)]
private ?string $thumbnail = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $content2 = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $kicker = null;
#[ORM\Column(type: 'boolean', nullable: false)]
private bool $featured = false;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'news')]
#[ORM\JoinColumn(nullable: false)]
private ?User $updatedBy = null;
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set excerpt.
*
* @param string $excerpt
*
* @return News
*/
public function setExcerpt($excerpt)
{
$this->excerpt = $excerpt;
return $this;
}
/**
* Get excerpt.
*
* @return string
*/
public function getExcerpt()
{
return $this->excerpt;
}
/**
* Set publishDate.
*
* @param \DateTime|\DateTimeImmutable $publishDate
*
* @return News
*/
public function setPublishDate(\DateTimeInterface $publishDate)
{
$this->publishDate = $publishDate;
return $this;
}
/**
* Get publishDate.
*
* @return \DateTime
*/
public function getPublishDate()
{
return $this->publishDate;
}
/**
* Set thumbnail.
*
* @param string $thumbnail
*
* @return News
*/
public function setThumbnail($thumbnail)
{
$this->thumbnail = $thumbnail;
return $this;
}
/**
* Get thumbnail.
*
* @return string
*/
public function getThumbnail()
{
return $this->thumbnail;
}
// REQUIRED BY THE META LINKS TRAIT
public function getLinkedPageId(): int
{
return 3;
}
public function getUpdatedBy(): ?User
{
return $this->updatedBy;
}
public function setUpdatedBy(?User $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function getContent2(): ?string
{
return $this->content2;
}
public function setContent2(?string $content2): self
{
$this->content2 = $content2;
return $this;
}
public function getKicker(): ?string
{
return $this->kicker;
}
public function setKicker(?string $kicker): self
{
$this->kicker = $kicker;
return $this;
}
public function isFeatured(): bool
{
return $this->featured;
}
public function setFeatured(bool $featured): void
{
$this->featured = $featured;
}
public function getSitemapRouteParams(): array
{
return ['slug' => $this->getSlug()];
}
public function isIncludedInSitemap(): bool
{
$now = new \DateTime();
// if ($this->id === 2) {
// dd($this->isActive(),
// ! $this->isDeleted(),
// $this->getPublishDate() < $now);
// }
return $this->isActive() &&
! $this->isDeleted() &&
$this->getPublishDate() < $now
;
}
}