<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\GenderRepository;
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_AGENT') or is_granted('ROLE_MANAGER')",
* normalizationContext={"groups"={"gender:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"gender:write"}, "swagger_definition_name"="Write"},
* itemOperations={
* "get"
* },
* collectionOperations={
* "get",
* "milkiya_genders"={
* "security"="is_granted('PUBLIC_ACCESS')",
* "normalization_context"={"groups"={"milkiya:read"}},
* "method"="GET",
* "path"="/internal/genders",
* "pagination_enabled" = false
* },
* },
* attributes={
* "pagination_items_per_page"=10,
* "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
* }
* )
* @ORM\Entity(repositoryClass=GenderRepository::class)
*/
class Gender
{
public const REFERENCE_GENDER_MALE = 'reference.gender.MALE';
public const REFERENCE_GENDER_FEMALE = 'reference.gender.FEMALE';
public const REFERENCE_CODE_GENDER_MALE = 'M';
public const REFERENCE_CODE_GENDER_FEMALE = 'F';
public const ALL_REFERENCE_GENDER = [
self::REFERENCE_GENDER_MALE,
self::REFERENCE_GENDER_FEMALE,
];
public const ALL_REFERENCE_CODE_GENDER = [
self::REFERENCE_CODE_GENDER_MALE,
self::REFERENCE_CODE_GENDER_FEMALE,
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Groups({
* "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 $id;
/**
* @ORM\Column(type="string", length=255)
*
* @Groups({
* "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;
/**
* @ORM\Column(type="string", length=255)
*
* @Groups({
* "directory:collaborator:search",
* "directory:people:search",
* "agent:read",
* "candidate:read",
* "gender:read",
* "contact:read",
* "mandate:read",
* "property:read",
* "transaction-item:read",
* "prescriber:read",
* "business-indication:item:read",
* "milkiya:read"
* })
*/
private ?string $code;
/**
* @ORM\OneToMany(targetEntity=AbstractPeople::class, mappedBy="gender")
*/
private $abstractPeople;
public function __construct()
{
$this->abstractPeople = new ArrayCollection();
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|AbstractPeople[]
*/
public function getAbstractPeople(): Collection
{
return $this->abstractPeople;
}
public function addAbstractPerson(AbstractPeople $abstractPerson): self
{
if (!$this->abstractPeople->contains($abstractPerson)) {
$this->abstractPeople[] = $abstractPerson;
$abstractPerson->setGender($this);
}
return $this;
}
public function removeAbstractPerson(AbstractPeople $abstractPerson): self
{
// set the owning side to null (unless already changed)
if ($this->abstractPeople->removeElement($abstractPerson) && $abstractPerson->getGender() === $this) {
$abstractPerson->setGender(null);
}
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
}