<?php
namespace App\Domain\Entity;
use ApiPlatform\Metadata\ApiProperty;
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\Admin\Controller\Api\GetRevisionEnumerationListAction;
use App\Domain\Entity\Behavior\Identifiable;
use App\Domain\Entity\Translation\EnumerationTranslation;
use DateTime;
use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
use Gedmo\Timestampable\Traits\Timestampable;
use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
/**
* Class Enumeration
*
* @package App\Domain\Entity
*/
#[ApiResource(
operations : [
new Delete(security: "is_granted('ROLE_ADMIN')"),
new GetCollection(filters: ['enumeration.type_filter', 'enumeration.query_filter', 'soft_delete_filter']),
new GetCollection(
uriTemplate: '/enumerations/revisions/list',
controller : GetRevisionEnumerationListAction::class
),
new Get(),
new Post(normalizationContext: ['groups' => ['translations']]),
new Put(normalizationContext: ['groups' => ['translations']]),
],
normalizationContext : ['groups' => ['enumeration_read']],
denormalizationContext: ['groups' => ['enumeration_write']]
)]
class Enumeration extends AbstractTranslatable
{
use Identifiable;
use SoftDeleteable;
use Timestampable;
public ?string $remoteId = null;
/**
* @param string $code
* @param bool $enabled
* @param string|null $color
* @param Enumeration|null $parent
* @param int|null $position
* @param string|null $section
* @param DateTime|null $zhistUpdate
*/
public function __construct(
#[ApiProperty(openapiContext: ['nullable' => false])]
public string $code,
#[ApiProperty(openapiContext: ['nullable' => false])]
public bool $enabled,
public ?string $color = null,
public ?Enumeration $parent = null,
public ?int $position = null,
public ?string $section = null,
public ?DateTime $zhistUpdate = null,
) {
parent::__construct();
}
public static function getAdministrable(): array
{
return [
'currency_type',
'parking_time',
'media_type',
'camper_van_type',
];
}
/**
* @param string|null $locale
*
* @return string|null
*/
public function getValue(?string $locale = null): ?string
{
return $this->getTranslationType($locale)->getValue();
}
/**
* @param string|null $value
*/
public function setValue(?string $value): void
{
$this->getTranslationType()->setValue($value);
}
public function getTranslationType(?string $locale = null): EnumerationTranslation
{
return $this->getTranslation($locale);
}
protected function createTranslation(): TranslationInterface
{
return new EnumerationTranslation();
}
}