<?php
declare(strict_types=1);
namespace App\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Application\ApiResources\State\Processor\ArticleCreateProcessor;
use App\Application\ApiResources\State\Processor\ArticlePutProcessor;
use App\Application\Controller\Api\ArticleDuplicateAction;
use App\Domain\Entity\Behavior\Identifiable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
use Gedmo\Timestampable\Traits\Timestampable;
#[ApiResource(
operations: [
new Delete(security: "is_granted('ROLE_ADMIN')"),
new GetCollection(paginationEnabled: false, filters: ['article.search_filter', 'article.query_filter', 'soft_delete_filter', 'article.order_filter']),
new Get(),
new Post(
security: "is_granted('ROLE_ADMIN')",
processor: ArticleCreateProcessor::class
),
new Put(
security: "is_granted('ROLE_ADMIN')",
processor: ArticlePutProcessor::class
),
new Get(
uriTemplate: '/articles/{uuid}/duplicate',
controller: ArticleDuplicateAction::class,
security: "is_granted('ROLE_ADMIN')"
),
],
normalizationContext: ['groups' => ['article_read']],
denormalizationContext: ['groups' => ['article_write']],
filters: ['translation.groups'],
)]
class Article
{
public array $MEDIA_TYPES = [
"blog" => "Blog",
"facebook" => "Facebook",
"instagram" => "Instagram",
"linkedin" => "LinkedIn",
"site_internet" => "Site internet",
"tiktok" => "TikTok",
"youtube" => "YouTube",
];
public $ENTITY_TYPE = ["activity", "poi"];
use Identifiable;
use SoftDeleteable;
use Timestampable;
/** @var Collection<ArticleLocale> */
public Collection $locales;
public ?\DateTime $zhistUpdate = null;
/**
* @param ?Media $media
* @param bool $status
* @param ?string $poiType
* @param string $title
* @param ?string $mediaType
*/
public function __construct(
public string $title,
public ?Media $media = null,
public ?string $poiType = null,
public ?string $mediaType = null,
public bool $status = false,
public ?string $entityType = null,
) {
$this->locales = new ArrayCollection();
}
/**
* @return string
*/
public function getType(): string
{
return $this->poiType;
}
public function addLocale(ArticleLocale $locale): self
{
$this->locales->add($locale);
$locale->setArticle($this);
return $this;
}
public function removeLocale(ArticleLocale $locale): self
{
$this->locales->removeElement($locale);
return $this;
}
public function getLocales(): Collection
{
return $this->locales;
}
public function getFormatedMediaType(string $mediaType): string
{
return $this->MEDIA_TYPES[$mediaType];
}
}