<?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\Directory\DirectoryCountryUpdateProcessor;
use App\Application\ApiResources\State\Provider\GetDirectoryCountryProvider;
use App\Domain\Entity\Behavior\Identifiable;
use App\Domain\Entity\Translation\DirectoryCountryTranslation;
use DateTime;
use Doctrine\Common\Collections\Collection;
use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
use Gedmo\Timestampable\Traits\Timestampable;
use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
#[ApiResource(
operations: [
new Delete(security: "is_granted('ROLE_ADMIN')"),
new GetCollection(filters: ['directory_country.search_filter', 'directory_country.query_filter']),
new Get(
requirements: [
'uuid' => '^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$',
],
),
new Get(
uriTemplate: '/directory_countries/slug',
name: 'get_country_by_slug',
provider: GetDirectoryCountryProvider::class,
),
new Post(
normalizationContext: ['groups' => ['translations']],
security: "is_granted('ROLE_ADMIN')",
),
new Put(
normalizationContext: ['groups' => ['translations']],
security: "is_granted('ROLE_ADMIN')",
),
],
normalizationContext: ['groups' => ['directory_country_read']],
denormalizationContext: ['groups' => ['directory_country_write']],
filters: ['translation.groups']
)]
class DirectoryCountry extends AbstractTranslatable
{
use Identifiable;
use SoftDeleteable;
use Timestampable;
/** @var Collection */
private Collection $departments;
public function __construct(
public Media $photo,
public Country $country,
public ?string $reference = null,
public ?string $remoteId = null,
public ?DateTime $zhistUpdate = null,
public ?bool $favorite = false,
) {
parent::__construct();
}
public function createTranslation(): TranslationInterface
{
return new DirectoryCountryTranslation();
}
public function getTranslationType(?string $locale = null): DirectoryCountryTranslation
{
return $this->getTranslation($locale);
}
public function getDescription(?string $locale = null): ?string
{
return $this->getTranslationType($locale)->getDescription();
}
public function setDescription(?string $description, ?string $locale = null): void
{
$this->getTranslationType($locale)->setDescription($description);
}
public function getName(?string $locale = null): ?string
{
return $this->getTranslationType($locale)->getName();
}
public function setName(?string $name, ?string $locale = null): void
{
$this->getTranslationType($locale)->setName($name);
}
public function getTitle(?string $locale = null): ?string
{
return $this->getTranslationType($locale)->getTitle();
}
public function setTitle(?string $title, ?string $locale = null): void
{
$this->getTranslationType($locale)->setTitle($title);
}
}