src/Entity/News.php line 61
<?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\SearchFilter;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\OrdStatTrait,
App\Entity\Trait\TimestampableTrait,
App\Entity\Trait\TranslatableTrait,
App\Entity\Trait\ImportIdTrait,
App\Entity\Trait\Languages\SiteLanguagesTrait,
App\Entity\Interface\TranslatableInterface,
App\Entity\Interface\OrdStatableInterface,
App\Entity\Interface\LanguageableInterface,
App\Entity\Interface\BlockableInterface,
App\Entity\Interface\BlockInterface,
App\Repository\NewsRepository,
App\Enum\Language;
#[ApiResource(
description: 'News',
normalizationContext: ['groups' => [
'read',
'read:' . self::class,
'read:' . self::class . 'Translation',
'read:' . AbstractThumb::class
]],
denormalizationContext: ['groups' => ['write']],
security: 'is_granted("' . News::class . '")',
order: ['ord' => 'desc'],
operations: [
new GetCollection(),
new Post(denormalizationContext: ['groups' => ['write', 'post']]),
new Get(),
new Put(),
new Delete(),
],
extraProperties: ['standard_put' => false],
)]
#[ApiFilter(SearchFilter::class, properties: ['idName' => 'exact'])]
#[ApiFilter(OrderFilter::class, properties: ['ord'])]
#[ORM\Entity(repositoryClass: NewsRepository::class)]
class News implements
TranslatableInterface,
OrdStatableInterface,
LanguageableInterface,
BlockableInterface
{
use IdTrait,
UuidTrait,
OrdStatTrait,
TimestampableTrait,
TranslatableTrait,
SiteLanguagesTrait,
ImportIdTrait;
#[ApiProperty(description: 'Working title')]
#[Groups(['read', 'write'])]
#[Assert\NotBlank]
#[ORM\Column(type: Types::STRING, length: 511, unique: true)]
private string $workingTitle;
#[ApiProperty(description: 'Is UJ')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $isUj = false;
#[ApiProperty(description: 'Published at')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::DATE_IMMUTABLE, options: ['default' => '1970-01-01'])]
private \DateTimeImmutable $publishedAt;
#[ApiProperty(description: 'Blocks', writableLink: false)]
#[ORM\OneToMany(
targetEntity: NewsBlock::class,
mappedBy: 'parent',
cascade: ['persist', 'remove']
)]
#[ORM\OrderBy(['ord' => 'desc'])]
private Collection $blocks;
public function __construct(string $workingTitle, ?array $languages)
{
$this->setUuid();
$this->workingTitle = $workingTitle;
$this->translations = new ArrayCollection();
$this->blocks = new ArrayCollection();
$this->setLanguages($languages ?? Language::DEFAULT_SITE);
$this->publishedAt = new \DateTimeImmutable();
$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 getIsUj(): bool
{
return $this->isUj;
}
public function setIsUj(bool $isUj): self
{
$this->isUj = $isUj;
return $this;
}
public function getPublishedAt(): \DateTimeImmutable
{
return $this->publishedAt;
}
public function setPublishedAt(\DateTimeImmutable $publishedAt): self
{
$this->publishedAt = $publishedAt;
return $this;
}
/**
* @return Collection|NewsBlock[]
*/
public function getBlocks(): Collection
{
return $this->blocks;
}
public function addBlock(BlockInterface $block): self
{
if ($this->blocks->contains($block)) {
return $this;
}
$this->blocks[] = $block;
return $this;
}
public function removeBlock(BlockInterface $block): self
{
$this->blocks->removeElement($block);
return $this;
}
public function resetBlocks(): self
{
$this->blocks = new ArrayCollection();
return $this;
}
}