src/Domain/Entity/Enumeration.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Entity;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Post;
  9. use ApiPlatform\Metadata\Put;
  10. use App\Admin\Controller\Api\GetRevisionEnumerationListAction;
  11. use App\Domain\Entity\Behavior\Identifiable;
  12. use App\Domain\Entity\Translation\EnumerationTranslation;
  13. use DateTime;
  14. use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
  15. use Gedmo\Timestampable\Traits\Timestampable;
  16. use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
  17. use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
  18. /**
  19.  * Class Enumeration
  20.  *
  21.  * @package App\Domain\Entity
  22.  */
  23. #[ApiResource(
  24.     operations            : [
  25.         new Delete(security"is_granted('ROLE_ADMIN')"),
  26.         new GetCollection(filters: ['enumeration.type_filter''enumeration.query_filter''soft_delete_filter']),
  27.         new GetCollection(
  28.             uriTemplate'/enumerations/revisions/list',
  29.             controller GetRevisionEnumerationListAction::class
  30.         ),
  31.         new Get(),
  32.         new Post(normalizationContext: ['groups' => ['translations']]),
  33.         new Put(normalizationContext: ['groups' => ['translations']]),
  34.     ],
  35.     normalizationContext  : ['groups' => ['enumeration_read']],
  36.     denormalizationContext: ['groups' => ['enumeration_write']]
  37. )]
  38. class Enumeration extends AbstractTranslatable
  39. {
  40.     use Identifiable;
  41.     use SoftDeleteable;
  42.     use Timestampable;
  43.     public ?string $remoteId null;
  44.     /**
  45.      * @param string           $code
  46.      * @param bool             $enabled
  47.      * @param string|null      $color
  48.      * @param Enumeration|null $parent
  49.      * @param int|null         $position
  50.      * @param string|null      $section
  51.      * @param DateTime|null    $zhistUpdate
  52.      */
  53.     public function __construct(
  54.         #[ApiProperty(openapiContext: ['nullable' => false])]
  55.         public string $code,
  56.         #[ApiProperty(openapiContext: ['nullable' => false])]
  57.         public bool $enabled,
  58.         public ?string $color null,
  59.         public ?Enumeration $parent null,
  60.         public ?int $position null,
  61.         public ?string $section null,
  62.         public ?DateTime $zhistUpdate null,
  63.     ) {
  64.         parent::__construct();
  65.     }
  66.     public static function getAdministrable(): array
  67.     {
  68.         return [
  69.             'currency_type',
  70.             'parking_time',
  71.             'media_type',
  72.             'camper_van_type',
  73.         ];
  74.     }
  75.     /**
  76.      * @param string|null $locale
  77.      *
  78.      * @return string|null
  79.      */
  80.     public function getValue(?string $locale null): ?string
  81.     {
  82.         return $this->getTranslationType($locale)->getValue();
  83.     }
  84.     /**
  85.      * @param string|null $value
  86.      */
  87.     public function setValue(?string $value): void
  88.     {
  89.         $this->getTranslationType()->setValue($value);
  90.     }
  91.     public function getTranslationType(?string $locale null): EnumerationTranslation
  92.     {
  93.         return $this->getTranslation($locale);
  94.     }
  95.     protected function createTranslation(): TranslationInterface
  96.     {
  97.         return new EnumerationTranslation();
  98.     }
  99. }