<?php
namespace App\Admin\Entity;
use App\Entity\StdPagesTracking;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
/**
* StdPages
*/
#[ORM\Table(name: 'std_pages')]
#[ORM\Index(name: 'fk_std_pages_std_users', columns: ['created_by'])]
#[ORM\Index(name: 'fk_std_pages_std_users_0', columns: ['updated_by'])]
#[ORM\Index(name: 'fk_std_pages_std_templates', columns: ['template_id'])]
#[ORM\Index(name: 'fk_std_pages_std_content_types', columns: ['content_type'])]
#[ORM\Index(name: 'idx_machine_name', columns: ['machine_name'])]
#[ORM\Entity(repositoryClass: 'App\Admin\Repository\StdPagesRepository')]
#[ORM\HasLifecycleCallbacks]
class StdPages
{
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer', nullable: false, options: ['unsigned' => true, 'comment' => 'Page unique identifier'])]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private $id;
/**
* @var string
*/
#[ORM\Column(name: 'name', type: 'string', length: 100, nullable: true, options: ['comment' => 'Page name'])]
private $name;
/**
* @var \StdContentTypes
*/
#[ORM\JoinColumn(name: 'content_type', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: 'StdContentTypes')]
private $contentType;
/**
* @var \StdTemplates|null
*/
#[ORM\JoinColumn(name: 'template_id', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: 'StdTemplates')]
private $templateId;
/**
* @var bool
*/
#[ORM\Column(name: 'is_active', type: 'boolean', nullable: false, options: ['default' => 1, 'comment' => 'Flag that indicates if the page is active'])]
private $isActive = '1';
#[ORM\OneToOne(mappedBy: 'page', targetEntity: StdPagesApprovalStatus::class, cascade: ['persist', 'remove'])]
private ?StdPagesApprovalStatus $approvalStatus = null;
/**
* @var \StdUsers
*/
#[ORM\JoinColumn(name: 'created_by', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: 'StdUsers')]
private $createdBy;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'created_date', type: 'datetime', nullable: false, options: ['comment' => 'Date and time of the record creation'])]
private $createdDate;
/**
* @var \StdUsers
*/
#[ORM\JoinColumn(name: 'updated_by', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: 'StdUsers')]
private $updatedBy;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'updated_date', type: 'datetime', nullable: false, options: ['comment' => 'Date and time the record was last updated'])]
private $updatedDate;
/**
* @var int
*/
#[ORM\Column(name: 'order_value', type: 'integer', nullable: true, options: ['comment' => 'Page order'])]
private $orderValue;
/**
* @var \DateTime|null
*/
#[ORM\Column(name: 'publish_date', type: 'datetime', nullable: true, options: ['comment' => 'Date/hour when to publish page'])]
private $publishDate;
/**
* @var \DateTime|null
*/
#[ORM\Column(name: 'expire_date', type: 'datetime', nullable: true, options: ['comment' => 'Date/time when to expire (unpublish) page'])]
private $expireDate;
/**
* @var Doctrine\Common\Collections\ArrayCollection|null
*/
#[ORM\OneToMany(targetEntity: 'StdFavoritePagesUsers', mappedBy: 'pageId', cascade: ['persist', 'remove'], orphanRemoval: true, fetch: 'EXTRA_LAZY')]
private $favoriteUsers;
#[ORM\JoinTable(name: 'std_page_web_role')]
#[ORM\JoinColumn(name: 'page_id', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'webrole_id', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: 'StdWebRoles', inversedBy: 'pages', cascade: ['persist'])]
private $webroles;
/**
* @var string
*/
#[ORM\Column(name: 'layout', type: 'string', length: 100, nullable: true, options: ['comment' => 'Page layout'])]
private $layout;
/**
* @var Doctrine\Common\Collections\ArrayCollection|null
*/
#[ORM\OneToMany(targetEntity: 'StdPagesContent', mappedBy: 'pageId', cascade: ['persist', 'remove'], orphanRemoval: true)]
private $pagesContent;
#[ORM\OneToMany(mappedBy: 'page', targetEntity: StdPagesTag::class, cascade: ['persist', 'remove'], orphanRemoval: true, fetch: 'EAGER')]
private Collection $tags;
#[ORM\Column(name:'machine_name', type:'string', length: 255, nullable: true)]
private ?string $machineName = null;
/**
* @var bool
*/
#[ORM\Column(name: 'include_sitemap', type: 'boolean', nullable: false, options: ['default' => 1, 'comment' => 'Flag that indicates if the page is to be included in Sitemap'])]
private $includeSitemap = '1';
#[ORM\OneToMany(mappedBy: 'pageId', targetEntity: StdPagesPages::class)]
private Collection $relations;
#[ORM\OneToMany(mappedBy: 'page', targetEntity: StdPagesTracking::class, cascade: ['persist', 'remove'])]
private Collection $trackings;
/**
* @var Collection<int, StdUsers>
*/
#[ORM\ManyToMany(targetEntity: StdUsers::class, inversedBy: 'authoredPages')]
#[ORM\JoinTable(name: 'std_pages_authors')]
private Collection $pageAuthors;
public function __construct()
{
$this->webroles = new ArrayCollection();
$this->pagesContent = new ArrayCollection();
$this->trackings = new ArrayCollection();
$this->relations = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->pageAuthors = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getContentType(): ?StdContentTypes
{
return $this->contentType;
}
public function setContentType(StdContentTypes $contentType): self
{
$this->contentType = $contentType;
return $this;
}
public function getTemplateId(): ?StdTemplates
{
return $this->templateId;
}
public function setTemplateId(?StdTemplates $templateId): self
{
$this->templateId = $templateId;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getCreatedDate(): ?\DateTimeInterface
{
return $this->createdDate;
}
public function setCreatedDate(\DateTimeInterface $createdDate): self
{
$this->createdDate = $createdDate;
return $this;
}
public function getUpdatedDate(): ?\DateTimeInterface
{
return $this->updatedDate;
}
public function setUpdatedDate(\DateTimeInterface $updatedDate): self
{
$this->updatedDate = $updatedDate;
return $this;
}
public function getCreatedBy(): ?StdUsers
{
return $this->createdBy;
}
public function setCreatedBy(?StdUsers $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getUpdatedBy(): ?StdUsers
{
return $this->updatedBy;
}
public function setUpdatedBy(?StdUsers $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function getOrderValue(): ?int
{
return $this->orderValue;
}
public function setOrderValue(?int $orderValue): self
{
$this->orderValue = $orderValue;
return $this;
}
public function getPublishDate(): ?\DateTimeInterface
{
return $this->publishDate;
}
public function setPublishDate(\DateTimeInterface $publishDate): self
{
$this->publishDate = $publishDate;
return $this;
}
public function getLayout(): ?string
{
return $this->layout;
}
public function setLayout(?string $layout): self
{
$this->layout = $layout;
return $this;
}
public function getExpireDate(): ?\DateTimeInterface
{
return $this->expireDate;
}
public function setExpireDate(?\DateTimeInterface $expireDate): self
{
$this->expireDate = $expireDate;
return $this;
}
public function addRole(StdWebRoles $webroles): self
{
$this->webroles[] = $webroles;
return $this;
}
public function removeRole(StdWebRoles $webroles): bool
{
return $this->webroles->removeElement($webroles);
}
public function getRoles(): Collection
{
return $this->webroles;
}
public function getRolesByNames(array $names): ?Collection
{
$criteria = Criteria::create()
->where(Criteria::expr()->in("name", $names));
return $this->getRoles()->matching($criteria);
}
#[ORM\PreUpdate]
public function setUpdated()
{
$this->setUpdatedDate(new \DateTime());
}
#[ORM\PrePersist]
public function setCreated()
{
$this->setUpdatedDate(new \DateTime());
$this->setCreatedDate(new \DateTime());
}
public function __toString() {
return $this->name;
}
/**
* @return Collection|StdPagesContent[]
*/
public function getPagesContent(): ?Collection
{
return $this->pagesContent;
}
public function removePagesContent(StdPagesContent $pagescontent): self
{
if ($this->pagesContent->contains($pagescontent)) {
$this->pagesContent->removeElement($pagescontent);
// set the owning side to null (unless already changed)
if ($pagescontent->getPageId() === $this) {
$pagescontent->setPageId(null);
}
}
return $this;
}
public function addPagesContent(StdPagesContent $pagescontent): self
{
if (!$this->pagesContent->contains($pagescontent)) {
$this->pagesContent[] = $pagescontent;
$pagescontent->setPageId($this);
}
return $this;
}
/**
* @return StdPagesContent
*/
public function getLocalizedContents(StdLanguages $locale): ?StdPagesContent
{
$criteria = Criteria::create()
->where(Criteria::expr()->eq("languageCode", $locale))
->setMaxResults(1);
if($this->getPagesContent()){
$contents = $this->getPagesContent()->matching($criteria);
if(count($contents)){
$contents = array_values($contents->toArray());
return $contents[0];
}else{
return null;
}
}else{
return null;
}
}
public function getMachineName(): ?string
{
return $this->machineName;
}
public function setMachineName(?string $machineName): self
{
$this->machineName = $machineName;
return $this;
}
public function getIncludeSitemap(): ?bool
{
return $this->includeSitemap;
}
public function setIncludeSitemap(bool $includeSitemap): self
{
$this->includeSitemap = $includeSitemap;
return $this;
}
public function addTag(StdPagesTag $tag): self
{
if (!$this->tags->contains($tag)) {
$this->tags[] = $tag;
$tag->setPage($this);
}
return $this;
}
public function removeTag(StdPagesTag $tag): self
{
if ($this->tags->removeElement($tag)) {
if ($tag->getDomainValue() === $this) {
$tag->setDomainValue(null);
}
}
return $this;
}
public function getTags(): Collection {
return $this->tags;
}
public function addTracking(StdPagesTracking $tracking): static
{
if (!$this->trackings->contains($tracking)) {
$this->trackings[] = $tracking;
$tracking->setPage($this);
}
return $this;
}
public function removeTracking(StdPagesTracking $tracking): static
{
if ($this->trackings->removeElement($tracking)) {
if ($tracking->getPage() === $this) {
$tracking->setPage(null);
}
}
return $this;
}
public function getApprovalStatus(): ?StdPagesApprovalStatus
{
return $this->approvalStatus;
}
public function setApprovalStatus(?StdPagesApprovalStatus $approvalStatus): void
{
$this->approvalStatus = $approvalStatus;
if ($approvalStatus !== null && $approvalStatus->getPage() !== $this) {
$approvalStatus->setPage($this);
}
}
public function getRelations(): Collection
{
return $this->relations;
}
public function setRelations(Collection $relations): void
{
$this->relations = $relations;
}
/**
* @return Collection<int, StdUsers>
*/
public function getPageAuthors(): Collection
{
return $this->pageAuthors;
}
public function addPageAuthors(array $users) {
foreach ($users as $user) {
if ($user instanceof StdUsers && !$this->pageAuthors->contains($user)) {
$this->pageAuthors->add($user);
}
}
return $this;
}
public function addPageAuthor(StdUsers $user): self
{
if (!$this->pageAuthors->contains($user)) {
$this->pageAuthors->add($user);
}
return $this;
}
public function removePageAuthor(StdUsers $user): self
{
$this->pageAuthors->removeElement($user);
return $this;
}
}