<?php
namespace App\Entity\Reference;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Agent;
use App\Repository\Reference\ReferenceCollaboratorStateRepository;
use App\Traits\RankTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* security= "is_granted('ROLE_MANAGER')",
* normalizationContext={"groups"={"reference-collaborator-state:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"reference-collaborator-state:write"}, "swagger_definition_name"="Write"},
* itemOperations={
* "get"
* },
* collectionOperations={
* "get",
*
* },
* attributes={
* "pagination_items_per_page"=10,
* "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
* },
* order={"rank"}
* )
* @ORM\Entity(repositoryClass=ReferenceCollaboratorStateRepository::class)
*/
class ReferenceCollaboratorState
{
use RankTrait;
public const TRANSLATION_DOMAIN = 'reference_collaborator';
public const REFERENCE_COLLABORATOR_STATE_ACTIVE = 'reference.collaborator.state.ACTIVE';
public const REFERENCE_COLLABORATOR_STATE_SUSPENDED = 'reference.collaborator.state.SUSPENDED';
public const REFERENCE_COLLABORATOR_STATE_DISABLED = 'reference.collaborator.state.DISABLED';
public const REFERENCE_COLLABORATOR_STATE_ARCHIVED = 'reference.collaborator.state.ARCHIVED';
public const CODE_IN_ACTIVE = '0';
public const CODE_SUSPENDED = '1';
public const CODE_DISABLED = '2';
public const CODE_ARCHIVED = '-1';
public const ALL_REFERENCE_COLLABORATOR_STATE = [
self::REFERENCE_COLLABORATOR_STATE_ACTIVE,
self::REFERENCE_COLLABORATOR_STATE_SUSPENDED,
self::REFERENCE_COLLABORATOR_STATE_DISABLED,
self::REFERENCE_COLLABORATOR_STATE_ARCHIVED
];
public const ALL_CODES = [
self::CODE_IN_ACTIVE,
self::CODE_SUSPENDED,
self::CODE_DISABLED,
self::CODE_ARCHIVED
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Groups({
* "abstract-collaborator:read",
* "reference-collaborator-state:read",
* "agent:read"
* })
*
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*@Groups({
* "abstract-collaborator:read",
* "reference-collaborator-state:read",
* "agent:read"
* })
*/
private ?string $code;
/**
* @ORM\Column(type="string", length=255)
*
* @Groups({
* "abstract-collaborator:read",
* "reference-collaborator-state:read",
* "agent:read"
* })
*/
private ?string $name;
/**
* @ORM\OneToMany(targetEntity=Agent::class, mappedBy="status")
*/
private $agents;
public function __construct()
{
$this->agents = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|Agent[]
*/
public function getAgents(): Collection
{
return $this->agents;
}
public function addAgent(Agent $agent): self
{
if (!$this->agents->contains($agent)) {
$this->agents[] = $agent;
$agent->setStatus($this);
}
return $this;
}
public function removeAgent(Agent $agent): self
{
if ($this->agents->removeElement($agent)) {
// set the owning side to null (unless already changed)
if ($agent->getStatus() === $this) {
$agent->setStatus(null);
}
}
return $this;
}
}