<?php
namespace App\Entity\Reference;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* normalizationContext={"groups"={"personType_reference:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"personType_reference:write"}, "swagger_definition_name"="Write"},
* itemOperations={
* "get"
* },
* collectionOperations={
* "get",
* },
* attributes={
* "pagination_items_per_page"=10,
* "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
* }
* )
*/
class PersonTypeReference
{
public const TRANSLATION_DOMAIN = 'reference_personType';
public const REFERENCE_PERSON_TYPE_MORAL = 'reference.personType.moral';
public const REFERENCE_PERSON_TYPE_PHYSICAL = 'reference.personType.physical';
public const REFERENCE_CODE_PERSON_TYPE_MORAL = 'Moral';
public const REFERENCE_CODE_PERSON_TYPE_PHYSICAL = 'Physical';
public const ALL_PERSON_TYPE_NAME = [
self::REFERENCE_PERSON_TYPE_PHYSICAL,
self::REFERENCE_PERSON_TYPE_MORAL,
];
public const ALL_PERSON_TYPE_CODE = [
self::REFERENCE_CODE_PERSON_TYPE_PHYSICAL,
self::REFERENCE_CODE_PERSON_TYPE_MORAL,
];
public const ALL_PERSON_TYPE = [
self::REFERENCE_CODE_PERSON_TYPE_PHYSICAL => self::REFERENCE_PERSON_TYPE_PHYSICAL,
self::REFERENCE_CODE_PERSON_TYPE_MORAL => self::REFERENCE_PERSON_TYPE_MORAL
];
/**
* @ApiProperty(identifier=true)
* @Groups({
* "personType_reference:read",
* "abstract-collaborator:read",
* "directory:collaborator:search",
* "directory:people:search",
* "agent:read",
* "candidate:read",
* "gender:read",
* "contact:read",
* "prescriber:read",
* "mandate:read",
* "property:read",
* "transaction-item:read",
* "business-indication:item:read",
* "milkiya:read"
* })
*/
private ?int $id;
/**
* @Groups({
* "personType_reference:read",
* "abstract-collaborator:read",
* "directory:collaborator:search",
* "directory:people:search",
* "agent:read",
* "candidate:read",
* "gender:read",
* "contact:read",
* "prescriber:read",
* "mandate:read",
* "property:read",
* "transaction-item:read",
* "business-indication:item:read",
* "milkiya:read"
* })
*/
private ?string $name;
/**
* @Groups({
* "personType_reference:read",
* "abstract-collaborator:read",
* "directory:collaborator:search",
* "directory:people:search",
* "agent:read",
* "candidate:read",
* "gender:read",
* "contact:read",
* "prescriber:read",
* "mandate:read",
* "property:read",
* "transaction-item:read",
* "business-indication:item:read",
* "milkiya:read"
* })
*/
private ?string $code;
public function getId(): ?int
{
return $this->id;
}
public function setId(string $id): self
{
$this->id = $id;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
/**
* @param string $code
* @return PersonTypeReference|null
*/
public static function createFromCode(string $code): ?PersonTypeReference
{
return (new PersonTypeReference())
->setCode($code)
->setName(PersonTypeReference::ALL_PERSON_TYPE[$code]);
}
}