<?php
namespace App\Entity;
use App\Constants\ActiveConstants;
use App\Repository\PageRepository;
use App\Traits\ActivityTrait;
use App\Traits\MetaImageTrait;
use App\Traits\MetaTrait;
use App\Traits\SlugTrait;
use App\Traits\TimeTrackTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: PageRepository::class)]
#[ORM\Table(name: 'page')]
#[ORM\HasLifecycleCallbacks]
class Page
{
use ActivityTrait;
use MetaImageTrait;
use MetaTrait;
use SlugTrait;
use TimeTrackTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[Assert\NotNull]
#[ORM\Column(name: 'title', type: 'string', length: 191)]
private ?string $title = null;
#[ORM\Column(name: 'content', type: Types::TEXT, nullable: true)]
private ?string $content = null;
#[ORM\ManyToMany(targetEntity: "App\Entity\Company", inversedBy: 'pages', cascade: ['persist'], orphanRemoval: false)]
#[ORM\JoinTable(name: 'pages_companies')]
#[ORM\JoinColumn(name: 'page_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
#[ORM\InverseJoinColumn(name: 'company_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
private Collection $companies;
#[ORM\Column(name: 'display_locations', type: Types::JSON, nullable: true)]
private ?array $displayLocations = [];
public function __construct()
{
$this->companies = new ArrayCollection();
}
public function __toString()
{
return (string) ($this->title ?? $this->id);
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): static
{
$this->content = $content;
return $this;
}
/**
* @return Collection<int, Company>
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): static
{
if (!$this->companies->contains($company)) {
$this->companies->add($company);
}
return $this;
}
public function removeCompany(Company $company): static
{
$this->companies->removeElement($company);
return $this;
}
public function getDisplayLocations(): array
{
return $this->displayLocations ?? [];
}
public function setDisplayLocations(?array $displayLocations): static
{
$this->displayLocations = $displayLocations ?? [];
return $this;
}
public function getSlug()
{
return $this->slug;
}
public function setSlug($slug): static
{
$this->slug = $slug;
return $this;
}
/**
* @return \DateTime|null
*/
public function getCreatedAt()
{
return $this->createdAt;
}
public function setCreatedAt($createdAt = null): static
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return \DateTime|null
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
public function setUpdatedAt($updatedAt = null): static
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getActive()
{
return $this->active;
}
public function setActive($active): static
{
$this->active = $active;
return $this;
}
public function getActiveLabel(): string
{
return $this->active ? ActiveConstants::LABEL_YES : ActiveConstants::LABEL_NO;
}
public function getMetaImage(): ?SonataMediaMedia
{
return $this->meta_image;
}
public function setMetaImage(?SonataMediaMedia $meta_image): static
{
$this->meta_image = $meta_image;
return $this;
}
public function getMetaTitle()
{
return $this->metaTitle;
}
public function setMetaTitle($metaTitle): static
{
$this->metaTitle = $metaTitle;
return $this;
}
public function getMetaDescription()
{
return $this->metaDescription;
}
public function setMetaDescription($metaDescription): static
{
$this->metaDescription = $metaDescription;
return $this;
}
public function getMetaKeywords()
{
return $this->metaKeywords;
}
public function setMetaKeywords($metaKeywords): static
{
$this->metaKeywords = $metaKeywords;
return $this;
}
public function getMetaCanonical()
{
return $this->metaCanonical;
}
public function setMetaCanonical($metaCanonical): static
{
$this->metaCanonical = $metaCanonical;
return $this;
}
}