src/Entity/Landing.php line 84
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types,
Doctrine\Common\Collections\Collection,
Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups,
Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Metadata\ApiResource,
ApiPlatform\Metadata\ApiProperty,
ApiPlatform\Metadata\Get,
ApiPlatform\Metadata\GetCollection,
ApiPlatform\Metadata\Post,
ApiPlatform\Metadata\Put,
ApiPlatform\Metadata\Delete,
ApiPlatform\Metadata\ApiFilter,
ApiPlatform\Doctrine\Orm\Filter\OrderFilter,
ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\OrdStatTrait,
App\Entity\Trait\TimestampableTrait,
App\Entity\Trait\TranslatableTrait,
App\Entity\Trait\ArchivedTrait,
App\Entity\Trait\Languages\LandingLanguagesTrait,
App\Entity\Interface\TranslatableInterface,
App\Entity\Interface\OrdStatableInterface,
App\Entity\Interface\LanguageableInterface,
App\Entity\Interface\CloneableInterface,
App\Entity\Interface\ArchivableInterface,
App\Repository\LandingRepository,
App\Util\ClassUtils,
App\Lib\Actions,
App\DTO\CloneDTO,
App\StateProcessor\CloneProcessor,
App\Security\Voter\CloneVoter,
App\Security\Voter\ArchivableVoter,
App\Enum\Language;
#[ApiResource(
description: 'Landings',
normalizationContext: ['groups' => [
'read',
'read:' . self::class,
'read:' . self::class . 'Translation',
'read:' . AbstractThumb::class
]],
denormalizationContext: ['groups' => ['write']],
security: 'is_granted("' . Landing::class . '")',
order: ['ord' => 'desc'],
operations: [
new GetCollection(),
new Post(
uriTemplate: '/landings/clone',
input: CloneDTO::class,
processor: CloneProcessor::class,
security: 'is_granted("' . Actions::CLONE .'")',
securityMessage: CloneVoter::MESSAGE
),
new Post(denormalizationContext: ['groups' => ['write', 'post']]),
new Get(),
new Put(),
new Delete(
securityPostDenormalize: 'is_granted("' . Actions::DELETE . '", object)',
securityPostDenormalizeMessage: ArchivableVoter::MESSAGE
),
],
extraProperties: ['standard_put' => false],
)]
#[ApiFilter(BooleanFilter::class, properties: ['isArchived', 'stat'])]
#[ApiFilter(OrderFilter::class, properties: [
'workingTitle',
'nativeTitle',
'nativeLanguage',
'updatedAt',
'stat',
'ord'
])]
#[ORM\Entity(repositoryClass: LandingRepository::class)]
class Landing implements
TranslatableInterface,
OrdStatableInterface,
LanguageableInterface,
ArchivableInterface,
CloneableInterface
{
use IdTrait,
UuidTrait,
OrdStatTrait,
TimestampableTrait,
TranslatableTrait,
LandingLanguagesTrait,
ArchivedTrait;
#[ApiProperty(description: 'Working title')]
#[Groups(['read', 'write'])]
#[Assert\NotBlank]
#[ORM\Column(type: Types::STRING, length: 511)]
protected string $workingTitle;
#[ApiProperty(description: 'Subdomain')]
#[Groups(['read', 'write'])]
#[Assert\NotNull]
#[Assert\Regex(
pattern: '/^[a-zA-Z0-9](?:[a-zA-Z0-9-_]{0,61}[a-zA-Z0-9])?$/',
message: 'Invalid subdomain. Only english letters, numbers and middle or lower dash are allowed.'
)]
#[ORM\Column(type: Types::STRING, length: 32, unique: true)]
private string $subdomain;
#[ApiProperty(description: 'Per page')]
#[Groups(['read:' . self::class, 'write'])]
#[Assert\Range(min: 1)]
#[ORM\Column(type: Types::INTEGER, options: ['default' => 32])]
private int $perPage = 32;
#[ApiProperty(description: 'Journals')]
#[ORM\OneToMany(targetEntity: LandingJournal::class, mappedBy: 'parent', cascade: ['persist', 'remove'])]
#[ORM\OrderBy(['ord' => 'desc'])]
private Collection $journals;
#[ApiProperty(description: 'Slides')]
#[ORM\OneToMany(targetEntity: LandingSlide::class, mappedBy: 'parent', cascade: ['persist', 'remove'])]
#[ORM\OrderBy(['ord' => 'desc'])]
private Collection $slides;
#[ApiProperty(description: 'Pages')]
#[ORM\OneToMany(targetEntity: LandingPage::class, mappedBy: 'parent', cascade: ['persist', 'remove'])]
#[ORM\OrderBy(['ord' => 'desc'])]
private Collection $pages;
#[ApiProperty(description: 'Menu items')]
#[ORM\OneToMany(targetEntity: LandingMenuItem::class, mappedBy: 'parent', cascade: ['persist', 'remove'])]
#[ORM\OrderBy(['ord' => 'desc'])]
private Collection $menuItems;
#[ApiProperty(description: 'Menu items')]
#[ORM\OneToMany(targetEntity: LandingFooterItem::class, mappedBy: 'parent', cascade: ['persist', 'remove'])]
#[ORM\OrderBy(['ord' => 'desc'])]
private Collection $footerItems;
public function __construct(?array $languages)
{
$this->setUuid();
$this->translations = new ArrayCollection();
$this->journals = new ArrayCollection();
$this->slides = new ArrayCollection();
$this->pages = new ArrayCollection();
$this->menuItems = new ArrayCollection();
$this->footerItems = new ArrayCollection();
$this->setLanguages($languages ?? Language::DEFAULT_LANDING);
new LandingPage(
parent: $this,
workingTitle: 'Strona główna',
idName: 'home',
ord: 1,
stat: true
);
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
}
public function getWorkingTitle(): string
{
return $this->workingTitle;
}
public function setWorkingTitle(string $workingTitle): self
{
$this->workingTitle = $workingTitle;
return $this;
}
public function getSubdomain(): string
{
return $this->subdomain;
}
public function setSubdomain(string $subdomain): self
{
$this->subdomain = $subdomain;
return $this;
}
public function getPerPage(): int
{
return $this->perPage;
}
public function setPerPage(int $perPage): self
{
$this->perPage = $perPage;
return $this;
}
/**
* @return Collection|LandingJournal[]
*/
public function getJournals(): Collection
{
return $this->journals;
}
public function addJournal(LandingJournal $journal): self
{
if ($this->journals->contains($journal)) {
return $this;
}
$this->journals[] = $journal;
return $this;
}
public function removeJournal(LandingJournal $journal): self
{
$this->journals->removeElement($journal);
return $this;
}
public function resetJournals(): self
{
$this->journals = new ArrayCollection();
return $this;
}
#[Groups(['read:' . self::class])]
public function getJournalsCount(): int
{
return $this->journals->count();
}
/**
* @return Collection|LandingSlide[]
*/
public function getSlides(): Collection
{
return $this->slides;
}
public function addSlide(LandingSlide $slide): self
{
if ($this->slides->contains($slide)) {
return $this;
}
$this->slides[] = $slide;
return $this;
}
public function removeSlide(LandingSlide $slide): self
{
$this->slides->removeElement($slide);
return $this;
}
public function resetSlides(): self
{
$this->slides = new ArrayCollection();
return $this;
}
/**
* @return Collection|LandingPage[]
*/
public function getPages(): Collection
{
return $this->pages;
}
public function addPage(LandingPage $page): self
{
if ($this->pages->contains($page)) {
return $this;
}
$this->pages[] = $page;
return $this;
}
public function removePage(LandingPage $page): self
{
$this->pages->removeElement($page);
return $this;
}
public function resetPages(): self
{
$this->pages = new ArrayCollection();
return $this;
}
/**
* @return Collection|LandingMenuItem[]
*/
public function getMenuItems(): Collection
{
return $this->menuItems;
}
public function addMenuItem(LandingMenuItem $menuItem): self
{
if ($this->menuItems->contains($menuItem)) {
return $this;
}
$this->menuItems[] = $menuItem;
return $this;
}
public function removeMenuItem(LandingMenuItem $menuItem): self
{
$this->menuItems->removeElement($menuItem);
return $this;
}
public function resetMenuItems(): self
{
$this->menuItems = new ArrayCollection();
return $this;
}
/**
* @return Collection|LandingFooterItem[]
*/
public function getFooterItems(): Collection
{
return $this->footerItems;
}
public function addFooterItem(LandingFooterItem $footerItem): self
{
if ($this->footerItems->contains($footerItem)) {
return $this;
}
$this->footerItems[] = $footerItem;
return $this;
}
public function removeFooterItem(LandingFooterItem $footerItem): self
{
$this->footerItems->removeElement($footerItem);
return $this;
}
public function resetFooterItems(): self
{
$this->footerItems = new ArrayCollection();
return $this;
}
public function clone(): self
{
$clone = clone $this;
$clone->id = null;
$clone->setUuid();
$clone->ord = 0;
$clone->stat = false;
$nativeLanguage = $clone->getNativeLanguage();
$nativeTranslation = $clone->getTranslation($nativeLanguage);
$nativeTranslation->setTitle($nativeTranslation->getTitle() . ' [KOPIA]');
ClassUtils::cloneCollection($this, $clone, 'translations');
$clone
->resetJournals()
->resetSlides()
->resetPages()
->resetMenuItems()
->resetFooterItems();
$clone->createdAt = new \DateTimeImmutable();
$clone->updatedAt = new \DateTimeImmutable();
return $clone;
}
}