src/Entity/Reference/ReferenceCollaboratorState.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Reference;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Agent;
  5. use App\Repository\Reference\ReferenceCollaboratorStateRepository;
  6. use App\Traits\RankTrait;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. /**
  12.  * @ApiResource(
  13.  *     security= "is_granted('ROLE_MANAGER')",
  14.  *     normalizationContext={"groups"={"reference-collaborator-state:read"}, "swagger_definition_name"="Read"},
  15.  *     denormalizationContext={"groups"={"reference-collaborator-state:write"}, "swagger_definition_name"="Write"},
  16.  *     itemOperations={
  17.  *          "get"
  18.  *     },
  19.  *     collectionOperations={
  20.  *           "get",
  21.  *
  22.  *     },
  23.  *     attributes={
  24.  *          "pagination_items_per_page"=10,
  25.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  26.  *     },
  27.  *     order={"rank"}
  28.  * )
  29.  * @ORM\Entity(repositoryClass=ReferenceCollaboratorStateRepository::class)
  30.  */
  31. class ReferenceCollaboratorState
  32. {
  33.     use RankTrait;
  34.     public const TRANSLATION_DOMAIN 'reference_collaborator';
  35.     public const REFERENCE_COLLABORATOR_STATE_ACTIVE 'reference.collaborator.state.ACTIVE';
  36.     public const REFERENCE_COLLABORATOR_STATE_SUSPENDED 'reference.collaborator.state.SUSPENDED';
  37.     public const REFERENCE_COLLABORATOR_STATE_DISABLED 'reference.collaborator.state.DISABLED';
  38.     public const REFERENCE_COLLABORATOR_STATE_ARCHIVED 'reference.collaborator.state.ARCHIVED';
  39.     public const CODE_IN_ACTIVE '0';
  40.     public const CODE_SUSPENDED '1';
  41.     public const CODE_DISABLED '2';
  42.     public const CODE_ARCHIVED '-1';
  43.     public const ALL_REFERENCE_COLLABORATOR_STATE = [
  44.         self::REFERENCE_COLLABORATOR_STATE_ACTIVE,
  45.         self::REFERENCE_COLLABORATOR_STATE_SUSPENDED,
  46.         self::REFERENCE_COLLABORATOR_STATE_DISABLED,
  47.         self::REFERENCE_COLLABORATOR_STATE_ARCHIVED
  48.     ];
  49.     public const ALL_CODES = [
  50.         self::CODE_IN_ACTIVE,
  51.         self::CODE_SUSPENDED,
  52.         self::CODE_DISABLED,
  53.         self::CODE_ARCHIVED
  54.     ];
  55.     /**
  56.      * @ORM\Id
  57.      * @ORM\GeneratedValue
  58.      * @ORM\Column(type="integer")
  59.      *
  60.      * @Groups({
  61.      *   "abstract-collaborator:read",
  62.      *   "reference-collaborator-state:read",
  63.      *   "agent:read"
  64.      * })
  65.      *
  66.      */
  67.     private $id;
  68.     /**
  69.      * @ORM\Column(type="string", length=255)
  70.      *@Groups({
  71.      *  "abstract-collaborator:read",
  72.      *  "reference-collaborator-state:read",
  73.      *  "agent:read"
  74.      * })
  75.      */
  76.     private ?string $code;
  77.     /**
  78.      * @ORM\Column(type="string", length=255)
  79.      *
  80.      * @Groups({
  81.      *   "abstract-collaborator:read",
  82.      *   "reference-collaborator-state:read",
  83.      *   "agent:read"
  84.      * })
  85.      */
  86.     private ?string $name;
  87.     /**
  88.      * @ORM\OneToMany(targetEntity=Agent::class, mappedBy="status")
  89.      */
  90.     private $agents;
  91.     public function __construct()
  92.     {
  93.         $this->agents = new ArrayCollection();
  94.     }
  95.     public function getId(): ?int
  96.     {
  97.         return $this->id;
  98.     }
  99.     public function getCode(): ?string
  100.     {
  101.         return $this->code;
  102.     }
  103.     public function setCode(string $code): self
  104.     {
  105.         $this->code $code;
  106.         return $this;
  107.     }
  108.     public function getName(): ?string
  109.     {
  110.         return $this->name;
  111.     }
  112.     public function setName(string $name): self
  113.     {
  114.         $this->name $name;
  115.         return $this;
  116.     }
  117.     /**
  118.      * @return Collection|Agent[]
  119.      */
  120.     public function getAgents(): Collection
  121.     {
  122.         return $this->agents;
  123.     }
  124.     public function addAgent(Agent $agent): self
  125.     {
  126.         if (!$this->agents->contains($agent)) {
  127.             $this->agents[] = $agent;
  128.             $agent->setStatus($this);
  129.         }
  130.         return $this;
  131.     }
  132.     public function removeAgent(Agent $agent): self
  133.     {
  134.         if ($this->agents->removeElement($agent)) {
  135.             // set the owning side to null (unless already changed)
  136.             if ($agent->getStatus() === $this) {
  137.                 $agent->setStatus(null);
  138.             }
  139.         }
  140.         return $this;
  141.     }
  142. }