<?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\SitemapableTrait;
use App\Entity\Traits\TitleAndContentTrait;
use App\Entity\Interfaces\DefaultLinkedEntity;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* 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 TimestampableEntity;
use TranslateTrait;
use SitemapableTrait;
public $imageUpload;
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private readonly 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\ManyToOne(targetEntity: User::class, inversedBy: 'news')]
#[ORM\JoinColumn(nullable: false)]
private ?\App\Entity\User $updatedBy = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $cta_text;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $cta_link;
#[ORM\Column(type: 'boolean')]
private $featuredOnNewsPage = false;
#[ORM\Column(type: 'boolean')]
private $featuredInWisdomComponent = false;
/**
* Override slug from LinkTrait to disable auto-update.
* Slug will only be auto-generated on create, but can be manually set.
*
* @Gedmo\Translatable
*
* @Gedmo\Versioned
*
* @Gedmo\Slug(fields={"title"}, separator="-", updatable=false)
*/
#[ORM\Column(length: 255, unique: true)]
private ?string $slug = 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 getCtaText(): ?string
{
return $this->cta_text;
}
public function setCtaText(?string $cta_text): self
{
$this->cta_text = $cta_text;
return $this;
}
public function getCtaLink(): ?string
{
return $this->cta_link;
}
public function setCtaLink(?string $cta_link): self
{
$this->cta_link = $cta_link;
return $this;
}
public function getFeaturedOnNewsPage(): ?bool
{
return $this->featuredOnNewsPage;
}
public function setFeaturedOnNewsPage(bool $featuredOnNewsPage): self
{
$this->featuredOnNewsPage = $featuredOnNewsPage;
return $this;
}
public function getFeaturedInWisdomComponent(): ?bool
{
return $this->featuredInWisdomComponent;
}
public function setFeaturedInWisdomComponent(bool $featuredInWisdomComponent): self
{
$this->featuredInWisdomComponent = $featuredInWisdomComponent;
return $this;
}
/**
* Override setSlug from LinkTrait to allow manual setting.
* If empty string is provided, set to null to allow auto-generation on create.
*/
public function setSlug(?string $slug): void
{
// Convert empty string to null so Gedmo can auto-generate on create
$this->slug = ($slug === '' || $slug === null) ? null : $slug;
}
public function getSitemapRouteParams(): array
{
return ['slug' => $this->getSlug()];
}
public function isIncludedInSitemap(): bool
{
$now = new \DateTime();
return $this->isActive() &&
! $this->isDeleted() &&
$this->getPublishDate() < $now
;
}
}