src/Entity/Candidate.php line 93

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  7. use App\Controller\Manager\Sponsorship\RefuseCandidateController;
  8. use App\Controller\Manager\Sponsorship\ValidateCandidateController;
  9. use App\Entity\Reference\ProfessionalStatusReference;
  10. use App\Entity\Reference\ReferenceCandidateStatus;
  11. use App\Repository\CandidateRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. /**
  18.  * @ApiResource(
  19.  *     security="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  20.  *     normalizationContext={"groups"={"candidate:read"}, "swagger_definition_name"="Read"},
  21.  *     denormalizationContext={"groups"={"candidate:write"},
  22.  *                             "swagger_definition_name"="Write","skip_null_values" = true},
  23.  *     itemOperations={
  24.  *          "get" = {
  25.  *                  "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')"
  26.  *              },
  27.  *          "put" = {
  28.  *                  "denormalization_context"={"groups"={"candidate:put"}},
  29.  *                  "security"="is_granted('ROLE_MANAGER')"
  30.  *              },
  31.  *        "validate_candidate"={
  32.  *              "denormalization_context"={"groups"={"candidate:validate"}},
  33.  *              "security"="is_granted('ROLE_MANAGER')",
  34.  *              "method"="PATCH",
  35.  *              "path"="/candidate/{id}/validate",
  36.  *              "controller"=ValidateCandidateController::class,
  37.  *              "read"=true,
  38.  *              "write"=false,
  39.  *          },
  40.  *         "refuse_candidate"={
  41.  *              "security"="is_granted('ROLE_MANAGER')",
  42.  *              "denormalization_context"={"groups"={"candidate:refuse"}},
  43.  *              "method"="PATCH",
  44.  *              "path"="/candidate/{id}/refuse",
  45.  *              "controller"= RefuseCandidateController::class,
  46.  *              "read"=true,
  47.  *              "write"=false,
  48.  *          }
  49.  *
  50.  *     },
  51.  *     collectionOperations={
  52.  *         "get" = {
  53.  *                  "security "="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')"
  54.  *              },
  55.  *          "post" = {
  56.  *                  "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  57.  *                  "validation_groups"={"Default"}
  58.  *              },
  59.  *     },
  60.  *
  61.  *     attributes={
  62.  *          "pagination_items_per_page"=10,
  63.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  64.  *     }
  65.  * )
  66.  * @ApiFilter(SearchFilter::class, properties={
  67.  *     "referenceStatus": "exact"
  68.  * })
  69.  * @ApiFilter(OrderFilter::class,
  70.  *   properties={"id","firstName","lastName","sponsor.firstName","sponsor.lastName","referenceStatus.name","createdAt"},
  71.  *   arguments= {"orderParameterName" : "order"})
  72.  * @ORM\Entity(repositoryClass=CandidateRepository::class)
  73.  * @UniqueEntity(
  74.  *          fields={"cin" },
  75.  *          entityClass=Candidate::class,
  76.  *          message="AbstractPeople with cin {{ value }} is already used."
  77.  * )
  78.  * @UniqueEntity(
  79.  *           fields={"email"},
  80.  *           entityClass=Candidate::class,
  81.  *           message="AbstractPeople with email {{ value }} is already used."
  82.  * )
  83.  * @UniqueEntity(
  84.  *           fields={"professionalEmail"},
  85.  *           entityClass=Candidate::class,
  86.  *           message="AbstractPeople with emailPro {{ value }} is already used."
  87.  * )
  88.  * @ORM\HasLifecycleCallbacks()
  89.  */
  90. class Candidate extends AbstractPeople implements Loggable
  91. {
  92.     /**
  93.      * @ORM\ManyToOne(targetEntity=Agent::class, inversedBy="candidates")
  94.      * @ORM\JoinColumn(nullable=false)
  95.      * @Groups({
  96.      *   "candidate:read","siege:write","siege:put"
  97.      * })
  98.      */
  99.     private ?Agent $sponsor null;
  100.     /**
  101.      * @ORM\ManyToOne(targetEntity=ReferenceCandidateStatus::class)
  102.      * @ORM\JoinColumn(nullable=false)
  103.      * @Groups({
  104.      *   "candidate:read","siege:put"
  105.      * })
  106.      */
  107.     private ?ReferenceCandidateStatus $referenceStatus;
  108.     /**
  109.      * @ORM\Column(type="text", nullable=true)
  110.      * @Assert\Type("string")
  111.      */
  112.     private ?string $refuseReason;
  113.     /**
  114.      * @ORM\OneToMany(targetEntity=IdentityVerificationImage::class, mappedBy="candidate")
  115.      *
  116.      * @Groups({
  117.      *   "candidate:read"
  118.      * })
  119.      */
  120.     private $identityFiles;
  121.     /**
  122.      * @ORM\OneToOne(targetEntity=Sector::class, cascade={"persist", "remove"})
  123.      *
  124.      * @Groups({
  125.      *   "abstract-colloborator:read",
  126.      *   "directory:collaborator:search",
  127.      *    "candidate:read","candidate:write","candidate:put"
  128.      * })
  129.      */
  130.     private ?Sector $sector;
  131.     /**
  132.      * @ORM\Column(type="string", length=100, nullable=true)
  133.      * @Groups({
  134.      *   "abstract-colloborator:read",
  135.      *   "directory:collaborator:search",
  136.      *    "candidate:read","candidate:write","candidate:put"
  137.      * })
  138.      */
  139.     private $cnss;
  140.     /**
  141.      * @ORM\Column(type="boolean", nullable=true)
  142.      * @Groups({
  143.      *   "abstract-colloborator:read",
  144.      *   "directory:collaborator:search",
  145.      *    "candidate:read","candidate:write","candidate:put"
  146.      * })
  147.      */
  148.     private $subjectToVAT;
  149.     /**
  150.      * @ORM\ManyToOne(targetEntity=Nationality::class)
  151.      * @ORM\JoinColumn(nullable=true)
  152.      * @Groups({
  153.      *   "abstract-colloborator:read",
  154.      *   "directory:collaborator:search",
  155.      *    "candidate:read","candidate:write","candidate:put"
  156.      * })
  157.      */
  158.     private $nationality;
  159.     /**
  160.      * @ORM\Column(type="string", length=255, nullable=true)
  161.      * @Groups({
  162.      *   "abstract-colloborator:read",
  163.      *   "directory:collaborator:search",
  164.      *    "candidate:read","candidate:write","candidate:put"
  165.      * })
  166.      */
  167.     private $professionalStatus;
  168.     /**
  169.      * @ORM\Column(type="string", length=255, nullable=true)
  170.      * @Groups({
  171.      *   "abstract-colloborator:read",
  172.      *   "directory:collaborator:search",
  173.      *   "candidate:read","candidate:put"
  174.      * })
  175.      */
  176.     private $professionalEmail;
  177.     public function __construct()
  178.     {
  179.         $this->identityFiles = new ArrayCollection();
  180.     }
  181.     public function getSponsor(): ?Agent
  182.     {
  183.         return $this->sponsor;
  184.     }
  185.     public function setSponsor(?Agent $sponsor): self
  186.     {
  187.         $this->sponsor $sponsor;
  188.         return $this;
  189.     }
  190.     public function getReferenceStatus(): ?ReferenceCandidateStatus
  191.     {
  192.         return $this->referenceStatus;
  193.     }
  194.     public function setReferenceStatus(?ReferenceCandidateStatus $referenceStatus): self
  195.     {
  196.         $this->referenceStatus $referenceStatus;
  197.         return $this;
  198.     }
  199.     public function getRefuseReason(): ?string
  200.     {
  201.         return $this->refuseReason;
  202.     }
  203.     public function setRefuseReason(?string $refuseReason): self
  204.     {
  205.         $this->refuseReason $refuseReason;
  206.         return $this;
  207.     }
  208.     /**
  209.      * @return IdentityVerificationImage[]
  210.      */
  211.     public function getIdentityFiles()
  212.     {
  213.         return $this->identityFiles;
  214.     }
  215.     public function addIdentityFile(IdentityVerificationImage $identityFile): self
  216.     {
  217.         if (!$this->identityFiles->contains($identityFile)) {
  218.             $this->identityFiles[] = $identityFile;
  219.             $identityFile->setCandidate($this);
  220.         }
  221.         return $this;
  222.     }
  223.     public function removeIdentityFile(IdentityVerificationImage $identityFile): self
  224.     {
  225.         // set the owning side to null (unless already changed)
  226.         if ($this->identityFiles->removeElement($identityFile) && $identityFile->getCandidate() === $this) {
  227.             $identityFile->setCandidate(null);
  228.         }
  229.         return $this;
  230.     }
  231.     public function getSector(): ?Sector
  232.     {
  233.         return $this->sector;
  234.     }
  235.     public function setSector(?Sector $sector): self
  236.     {
  237.         $this->sector $sector;
  238.         return $this;
  239.     }
  240.     public function getCnss(): ?string
  241.     {
  242.         return $this->cnss;
  243.     }
  244.     public function setCnss(?string $cnss): self
  245.     {
  246.         $this->cnss $cnss;
  247.         return $this;
  248.     }
  249.     public function getSubjectToVAT(): ?bool
  250.     {
  251.         return $this->subjectToVAT;
  252.     }
  253.     public function setSubjectToVAT(?bool $subjectToVAT): self
  254.     {
  255.         $this->subjectToVAT $subjectToVAT;
  256.         return $this;
  257.     }
  258.     public function getNationality(): ?Nationality
  259.     {
  260.         return $this->nationality;
  261.     }
  262.     public function setNationality(?Nationality $nationality): self
  263.     {
  264.         $this->nationality $nationality;
  265.         return $this;
  266.     }
  267.     public function getProfessionalStatus(): ?string
  268.     {
  269.         return $this->professionalStatus;
  270.     }
  271.     public function setProfessionalStatus(?string $professionalStatus): self
  272.     {
  273.         $this->professionalStatus $professionalStatus;
  274.         return $this;
  275.     }
  276.     public function getProfessionalEmail(): ?string
  277.     {
  278.         return $this->professionalEmail;
  279.     }
  280.     public function setProfessionalEmail(?string $professionalEmail): self
  281.     {
  282.         $this->professionalEmail $professionalEmail;
  283.         return $this;
  284.     }
  285.     /**
  286.      * @return array
  287.      */
  288.     public function getFields(): array
  289.     {
  290.         return [
  291.             'gender' => 'gender',
  292.             'address' => 'address',
  293.             'email' => 'email',
  294.             'mainPhone' => 'mainPhone',
  295.             'birthDay' => 'birthDay',
  296.             'cin' => 'cin',
  297.             'sponsor' => 'sponsor',
  298.             'referenceStatus' => 'referenceStatus',
  299.             'sector' => 'sector',
  300.             'nationality' => 'nationality',
  301.             'cnss' => 'cnss',
  302.             'professionalStatus' => 'professionalStatus'
  303.         ];
  304.     }
  305. }