src/Entity/Collection.php line 55
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types,
Doctrine\Common\Collections\Collection as DoctrineCollection,
Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
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;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\OrdStatTrait,
App\Entity\Trait\TimestampableTrait,
App\Entity\Trait\TranslatableTrait,
App\Entity\Trait\Languages\SiteLanguagesTrait,
App\Entity\Interface\TranslatableInterface,
App\Entity\Interface\OrdStatableInterface,
App\Entity\Interface\LanguageableInterface,
App\Repository\CollectionRepository,
App\Enum\Language;
#[ApiResource(
description: 'Collections',
normalizationContext: ['groups' => [
'read',
'read:' . self::class,
'read:' . self::class . 'Translation',
'read:' . AbstractThumb::class
]],
denormalizationContext: ['groups' => ['write']],
security: 'is_granted("' . self::class . '")',
order: ['ord' => 'desc'],
operations: [
new GetCollection(),
new Post(denormalizationContext: ['groups' => ['write', 'post']]),
new Get(),
new Put(),
new Delete(),
],
extraProperties: ['standard_put' => false],
)]
#[ApiFilter(OrderFilter::class, properties: ['ord'])]
#[ORM\Entity(repositoryClass: CollectionRepository::class)]
class Collection implements TranslatableInterface, OrdStatableInterface, LanguageableInterface
{
use IdTrait,
UuidTrait,
OrdStatTrait,
TimestampableTrait,
TranslatableTrait,
SiteLanguagesTrait;
#[ApiProperty(description: 'Is visible on home')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $isVisibleOnHome = false;
#[ApiProperty(description: 'Is UJ')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $isUj = false;
#[ApiProperty(description: 'Articles')]
#[ORM\OneToMany(targetEntity: CollectionArticle::class, mappedBy: 'parent', cascade: ['persist', 'remove'])]
#[ORM\OrderBy(['ord' => 'desc'])]
private DoctrineCollection $articles;
#[ApiProperty(description: 'Issues')]
#[ORM\OneToMany(targetEntity: CollectionIssue::class, mappedBy: 'parent', cascade: ['persist', 'remove'])]
#[ORM\OrderBy(['ord' => 'desc'])]
private DoctrineCollection $issues;
public function __construct(?array $languages)
{
$this->setUuid();
$this->translations = new ArrayCollection();
$this->articles = new ArrayCollection();
$this->issues = new ArrayCollection();
$this->setLanguages($languages ?? Language::DEFAULT_SITE);
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
}
public function getIsVisibleOnHome(): bool
{
return $this->isVisibleOnHome;
}
public function setIsVisibleOnHome(bool $isVisibleOnHome): self
{
$this->isVisibleOnHome = $isVisibleOnHome;
return $this;
}
public function getIsUj(): bool
{
return $this->isUj;
}
public function setIsUj(bool $isUj): self
{
$this->isUj = $isUj;
return $this;
}
/**
* @return DoctrineCollection|CollectionArticle[]
*/
public function getArticles(): DoctrineCollection
{
return $this->articles;
}
public function addArticle(CollectionArticle $article): self
{
if ($this->articles->contains($article)) {
return $this;
}
$this->articles[] = $article;
return $this;
}
public function removeArticle(CollectionArticle $article): self
{
$this->articles->removeElement($article);
return $this;
}
public function getArticlesCount(): int
{
return $this->articles->count();
}
/**
* @return DoctrineCollection|CollectionIssue[]
*/
public function getIssues(): DoctrineCollection
{
return $this->issues;
}
public function addIssue(CollectionIssue $issue): self
{
if ($this->issues->contains($issue)) {
return $this;
}
$this->issues[] = $issue;
return $this;
}
public function removeIssue(CollectionIssue $issue): self
{
$this->issues->removeElement($issue);
return $this;
}
public function getIssuesCount(): int
{
return $this->issues->count();
}
public function getElementsCount(): int
{
return $this->getIssuesCount() + $this->getArticlesCount();
}
}