src/Domain/Entity/Attribute.php line 51

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Post;
  8. use ApiPlatform\Metadata\Put;
  9. use App\Admin\Controller\Api\GetRevisionAttributeListAction;
  10. use App\Application\Controller\Api\Attribute\DeleteAction;
  11. use App\Domain\Entity\Behavior\Identifiable;
  12. use App\Domain\Entity\Enumeration\AttributeCategory;
  13. use App\Domain\Entity\Media\Picto;
  14. use App\Domain\Entity\Translation\AttributeTranslation;
  15. use DateTime;
  16. use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
  17. use Gedmo\Timestampable\Traits\Timestampable;
  18. use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
  19. use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
  20. /**
  21.  * Class Attribute
  22.  *
  23.  * @package App\Domain\Entity
  24.  */
  25. #[ApiResource(
  26.     operations: [
  27.         new Delete(controllerDeleteAction::class, security"is_granted('ROLE_ADMIN')"),
  28.         new Get(),
  29.         new GetCollection(filters: [
  30.             'attribute.label_filter',
  31.             'attribute.search_filter',
  32.             'attribute.query_filter',
  33.             'attribute.order_filter',
  34.             'soft_delete_filter',
  35.         ]),
  36.         new GetCollection(
  37.             uriTemplate'/attributes/revisions/list',
  38.             controllerGetRevisionAttributeListAction::class,
  39.             security"is_granted('ROLE_ADMIN')"
  40.         ),
  41.         new Post(normalizationContext: ['groups' => 'translations'], security"is_granted('ROLE_ADMIN')"),
  42.         new Put(normalizationContext: ['groups' => ['translations']], security"is_granted('ROLE_ADMIN')"),
  43.     ],
  44.     normalizationContext: ['groups' => ['attribute_read']],
  45.     denormalizationContext: ['groups' => ['attribute_write']],
  46.     filters: ['translation.groups']
  47. )]
  48. class Attribute extends AbstractTranslatable
  49. {
  50.     use Identifiable;
  51.     use SoftDeleteable;
  52.     use Timestampable;
  53.     public const ATTRIBUTE_CATEGORY_BRAND 'attribute_category_brand';
  54.     public const ATTRIBUTE_CATEGORY_LABEL 'attribute_category_label';
  55.     public const ATTRIBUTE_CATEGORY_LANGUAGE 'attribute_category_language';
  56.     public const ATTRIBUTE_CATEGORY_PAYMENT 'attribute_category_payment';
  57.     public const ATTRIBUTE_CATEGORY_PLACE 'attribute_category_place';
  58.     public const ATTRIBUTE_CATEGORY_PRICE 'attribute_category_price';
  59.     public const ATTRIBUTE_CATEGORY_SERVICE 'attribute_category_service';
  60.     public const ATTRIBUTE_CATEGORY_SOURCES 'attribute_category_sources';
  61.     public const SERVICE_PARKING 'parking';
  62.     public const SERVICE_PARKING_SERVICE 'parking_service';
  63.     public const SERVICE_PARKING_ELECTRICITY 'parking_electricity';
  64.     public const SERVICE_PARKING_WATER 'parking_water';
  65.     public const SERVICE_PACKAGE_CAMPER_VAN 'package_camper_van';
  66.     public const SERVICE_PACKAGE_CARAVAN 'package_caravan';
  67.     public const SERVICE_SLEEP 'sleep';
  68.     public function __construct(
  69.         public AttributeCategory $category,
  70.         public bool $favorite false,
  71.         public ?Attribute $parent null,
  72.         public ?Picto $picto null,
  73.         public ?string $section null,
  74.         public ?string $remoteId null,
  75.         public ?DateTime $zhistUpdate null,
  76.         public ?string $code null,
  77.     ) {
  78.         parent::__construct();
  79.     }
  80.     /**
  81.      * @return string|null
  82.      */
  83.     public function getLabel(): ?string
  84.     {
  85.         return $this->getTranslationType()->getLabel();
  86.     }
  87.     /**
  88.      * @param string $label
  89.      */
  90.     public function setLabel(string $label): void
  91.     {
  92.         $this->getTranslationType()->setLabel($label);
  93.     }
  94.     public function getTranslationType(?string $locale null): AttributeTranslation
  95.     {
  96.         return $this->getTranslation($locale);
  97.     }
  98.     protected function createTranslation(): TranslationInterface
  99.     {
  100.         return new AttributeTranslation();
  101.     }
  102. }