src/Entity/Gender.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\GenderRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. /**
  10.  * @ApiResource(
  11.  *     security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  12.  *     normalizationContext={"groups"={"gender:read"}, "swagger_definition_name"="Read"},
  13.  *     denormalizationContext={"groups"={"gender:write"}, "swagger_definition_name"="Write"},
  14.  *     itemOperations={
  15.  *          "get"
  16.  *     },
  17.  *     collectionOperations={
  18.  *          "get",
  19.  *           "milkiya_genders"={
  20.  *              "security"="is_granted('PUBLIC_ACCESS')",
  21.  *              "normalization_context"={"groups"={"milkiya:read"}},
  22.  *              "method"="GET",
  23.  *              "path"="/internal/genders",
  24.  *              "pagination_enabled" = false
  25.  *          },
  26.  *     },
  27.  *     attributes={
  28.  *          "pagination_items_per_page"=10,
  29.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  30.  *     }
  31.  * )
  32.  * @ORM\Entity(repositoryClass=GenderRepository::class)
  33.  */
  34. class Gender
  35. {
  36.     public const REFERENCE_GENDER_MALE 'reference.gender.MALE';
  37.     public const REFERENCE_GENDER_FEMALE 'reference.gender.FEMALE';
  38.     public const REFERENCE_CODE_GENDER_MALE 'M';
  39.     public const REFERENCE_CODE_GENDER_FEMALE 'F';
  40.     public const ALL_REFERENCE_GENDER = [
  41.         self::REFERENCE_GENDER_MALE,
  42.         self::REFERENCE_GENDER_FEMALE,
  43.     ];
  44.     public const ALL_REFERENCE_CODE_GENDER = [
  45.         self::REFERENCE_CODE_GENDER_MALE,
  46.         self::REFERENCE_CODE_GENDER_FEMALE,
  47.     ];
  48.     /**
  49.      * @ORM\Id
  50.      * @ORM\GeneratedValue
  51.      * @ORM\Column(type="integer")
  52.      *
  53.      * @Groups({
  54.      *   "directory:collaborator:search",
  55.      *   "directory:people:search",
  56.      *   "agent:read",
  57.      *   "candidate:read",
  58.      *   "gender:read",
  59.      *   "contact:read",
  60.      *   "prescriber:read",
  61.      *   "mandate:read",
  62.      *   "property:read",
  63.      *   "transaction-item:read",
  64.      *   "business-indication:item:read",
  65.      *    "milkiya:read"
  66.      * })
  67.      */
  68.     private $id;
  69.     /**
  70.      * @ORM\Column(type="string", length=255)
  71.      *
  72.      * @Groups({
  73.      *   "directory:collaborator:search",
  74.      *   "directory:people:search",
  75.      *   "agent:read",
  76.      *   "candidate:read",
  77.      *   "gender:read",
  78.      *   "contact:read",
  79.      *   "prescriber:read",
  80.      *   "mandate:read",
  81.      *   "property:read",
  82.      *   "transaction-item:read",
  83.      *   "business-indication:item:read",
  84.      *   "milkiya:read"
  85.      * })
  86.      */
  87.     private ?string $name;
  88.     /**
  89.      * @ORM\Column(type="string", length=255)
  90.      *
  91.      * @Groups({
  92.      *   "directory:collaborator:search",
  93.      *   "directory:people:search",
  94.      *   "agent:read",
  95.      *   "candidate:read",
  96.      *   "gender:read",
  97.      *   "contact:read",
  98.      *   "mandate:read",
  99.      *   "property:read",
  100.      *   "transaction-item:read",
  101.      *   "prescriber:read",
  102.      *   "business-indication:item:read",
  103.      *   "milkiya:read"
  104.      * })
  105.      */
  106.     private ?string $code;
  107.     /**
  108.      * @ORM\OneToMany(targetEntity=AbstractPeople::class, mappedBy="gender")
  109.      */
  110.     private $abstractPeople;
  111.     public function __construct()
  112.     {
  113.         $this->abstractPeople = new ArrayCollection();
  114.     }
  115.     /**
  116.      * @return int|null
  117.      */
  118.     public function getId(): ?int
  119.     {
  120.         return $this->id;
  121.     }
  122.     public function getName(): ?string
  123.     {
  124.         return $this->name;
  125.     }
  126.     public function setName(string $name): self
  127.     {
  128.         $this->name $name;
  129.         return $this;
  130.     }
  131.     /**
  132.      * @return Collection|AbstractPeople[]
  133.      */
  134.     public function getAbstractPeople(): Collection
  135.     {
  136.         return $this->abstractPeople;
  137.     }
  138.     public function addAbstractPerson(AbstractPeople $abstractPerson): self
  139.     {
  140.         if (!$this->abstractPeople->contains($abstractPerson)) {
  141.             $this->abstractPeople[] = $abstractPerson;
  142.             $abstractPerson->setGender($this);
  143.         }
  144.         return $this;
  145.     }
  146.     public function removeAbstractPerson(AbstractPeople $abstractPerson): self
  147.     {
  148.         // set the owning side to null (unless already changed)
  149.         if ($this->abstractPeople->removeElement($abstractPerson) && $abstractPerson->getGender() === $this) {
  150.             $abstractPerson->setGender(null);
  151.         }
  152.         return $this;
  153.     }
  154.     public function getCode(): ?string
  155.     {
  156.         return $this->code;
  157.     }
  158.     public function setCode(string $code): self
  159.     {
  160.         $this->code $code;
  161.         return $this;
  162.     }
  163. }