src/Entity/Reference/PersonTypeReference.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Reference;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use Symfony\Component\Serializer\Annotation\Groups;
  6. /**
  7.  * @ApiResource(
  8.  *     security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  9.  *     normalizationContext={"groups"={"personType_reference:read"}, "swagger_definition_name"="Read"},
  10.  *     denormalizationContext={"groups"={"personType_reference:write"}, "swagger_definition_name"="Write"},
  11.  *     itemOperations={
  12.  *          "get"
  13.  *     },
  14.  *     collectionOperations={
  15.  *           "get",
  16.  *     },
  17.  *     attributes={
  18.  *          "pagination_items_per_page"=10,
  19.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  20.  *     }
  21.  * )
  22.  */
  23. class PersonTypeReference
  24. {
  25.     public const TRANSLATION_DOMAIN 'reference_personType';
  26.     public const REFERENCE_PERSON_TYPE_MORAL 'reference.personType.moral';
  27.     public const REFERENCE_PERSON_TYPE_PHYSICAL 'reference.personType.physical';
  28.     public const REFERENCE_CODE_PERSON_TYPE_MORAL 'Moral';
  29.     public const REFERENCE_CODE_PERSON_TYPE_PHYSICAL 'Physical';
  30.     public const ALL_PERSON_TYPE_NAME = [
  31.         self::REFERENCE_PERSON_TYPE_PHYSICAL,
  32.         self::REFERENCE_PERSON_TYPE_MORAL,
  33.     ];
  34.     public const ALL_PERSON_TYPE_CODE = [
  35.         self::REFERENCE_CODE_PERSON_TYPE_PHYSICAL,
  36.         self::REFERENCE_CODE_PERSON_TYPE_MORAL,
  37.     ];
  38.     public const ALL_PERSON_TYPE = [
  39.         self::REFERENCE_CODE_PERSON_TYPE_PHYSICAL => self::REFERENCE_PERSON_TYPE_PHYSICAL,
  40.         self::REFERENCE_CODE_PERSON_TYPE_MORAL => self::REFERENCE_PERSON_TYPE_MORAL
  41.     ];
  42.     /**
  43.      * @ApiProperty(identifier=true)
  44.      * @Groups({
  45.      *   "personType_reference:read",
  46.      *   "abstract-collaborator:read",
  47.      *   "directory:collaborator:search",
  48.      *   "directory:people:search",
  49.      *   "agent:read",
  50.      *   "candidate:read",
  51.      *   "gender:read",
  52.      *   "contact:read",
  53.      *   "prescriber:read",
  54.      *   "mandate:read",
  55.      *   "property:read",
  56.      *   "transaction-item:read",
  57.      *   "business-indication:item:read",
  58.      *   "milkiya:read"
  59.      * })
  60.      */
  61.     private ?int $id;
  62.     /**
  63.      * @Groups({
  64.      *   "personType_reference:read",
  65.      *   "abstract-collaborator:read",
  66.      *   "directory:collaborator:search",
  67.      *   "directory:people:search",
  68.      *   "agent:read",
  69.      *   "candidate:read",
  70.      *   "gender:read",
  71.      *   "contact:read",
  72.      *   "prescriber:read",
  73.      *   "mandate:read",
  74.      *   "property:read",
  75.      *   "transaction-item:read",
  76.      *   "business-indication:item:read",
  77.      *   "milkiya:read"
  78.      * })
  79.      */
  80.     private ?string $name;
  81.     /**
  82.      * @Groups({
  83.      *   "personType_reference:read",
  84.      *   "abstract-collaborator:read",
  85.      *   "directory:collaborator:search",
  86.      *   "directory:people:search",
  87.      *   "agent:read",
  88.      *   "candidate:read",
  89.      *   "gender:read",
  90.      *   "contact:read",
  91.      *   "prescriber:read",
  92.      *   "mandate:read",
  93.      *   "property:read",
  94.      *   "transaction-item:read",
  95.      *   "business-indication:item:read",
  96.      *   "milkiya:read"
  97.      * })
  98.      */
  99.     private ?string $code;
  100.     public function getId(): ?int
  101.     {
  102.         return $this->id;
  103.     }
  104.     public function setId(string $id): self
  105.     {
  106.         $this->id $id;
  107.         return $this;
  108.     }
  109.     public function getName(): ?string
  110.     {
  111.         return $this->name;
  112.     }
  113.     public function setName(string $name): self
  114.     {
  115.         $this->name $name;
  116.         return $this;
  117.     }
  118.     public function getCode(): ?string
  119.     {
  120.         return $this->code;
  121.     }
  122.     public function setCode(?string $code): self
  123.     {
  124.         $this->code $code;
  125.         return $this;
  126.     }
  127.     /**
  128.      * @param string $code
  129.      * @return PersonTypeReference|null
  130.      */
  131.     public static function createFromCode(string $code): ?PersonTypeReference
  132.     {
  133.         return (new PersonTypeReference())
  134.             ->setCode($code)
  135.             ->setName(PersonTypeReference::ALL_PERSON_TYPE[$code]);
  136.     }
  137. }