src/Entity/Candidate.php line 817

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Utils\File\FileServiceTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\UploadedFile;
  8. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\CandidateRepository")
  11.  * @Vich\Uploadable
  12.  */
  13. class Candidate implements \JsonSerializable
  14. {
  15.     use FileServiceTrait;
  16.     const FILE_PICTURE = "picture";
  17.     const FILE_CV = "cv";
  18.     const FILES = [
  19.         self::FILE_PICTURE => [
  20.             'types' => ['gif', 'jpg', 'jpeg', 'png', 'tif', 'svg'],
  21.             'dir' => '/candidate/picture',
  22.             'size' => 5*1024*1024,
  23.         ],
  24.         self::FILE_CV => [
  25.             'types' => ['doc', 'docx', 'odt', 'pdf', 'rtf', 'txt'],
  26.             'dir' => '/candidate/cv',
  27.             'size' => 5*1024*1024,
  28.         ],
  29.     ];
  30.     /**
  31.      * @ORM\Id()
  32.      * @ORM\GeneratedValue()
  33.      * @ORM\Column(type="integer")
  34.      */
  35.     private $id;
  36.     /**
  37.      * @ORM\OneToOne(targetEntity="User", inversedBy="candidate")
  38.      * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  39.      */
  40.     private $user;
  41.     /**
  42.      * @ORM\Column(type="string", length=127)
  43.      */
  44.     private $name;
  45.     /**
  46.      * @ORM\Column(type="string", length=255, nullable=true)
  47.      */
  48.     private $address;
  49.     /**
  50.      * @ORM\Column(type="integer", nullable=true)
  51.      */
  52.     private $age;
  53.     /**
  54.      * @ORM\Column(type="string", length=20, nullable=true)
  55.      */
  56.     private $phone;
  57.     /**
  58.      * @ORM\Column(type="text", nullable=true)
  59.      */
  60.     private $description;
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      */
  64.     private $website;
  65.     /**
  66.      * @ORM\Column(type="string", length=255, nullable=true)
  67.      */
  68.     private $facebook;
  69.     /**
  70.      * @ORM\Column(type="string", length=255, nullable=true)
  71.      */
  72.     private $twitter;
  73.     /**
  74.      * @ORM\Column(type="string", length=255, nullable=true)
  75.      */
  76.     private $linkedin;
  77.     /**
  78.      * @ORM\Column(type="string", length=255, nullable=true)
  79.      */
  80.     private $instagram;
  81.     /**
  82.      * @ORM\OneToMany(targetEntity="App\Entity\AdditionalSkill", mappedBy="candidate", cascade={"remove"})
  83.      */
  84.     private $additionalSkills;
  85.     /**
  86.      * @ORM\OneToMany(targetEntity="App\Entity\Education", mappedBy="candidate", cascade={"remove"})
  87.      */
  88.     private $educations;
  89.     /**
  90.      * @ORM\OneToMany(targetEntity="App\Entity\WorkExperience", mappedBy="candidate", cascade={"remove"})
  91.      */
  92.     private $workExperiences;
  93.     /**
  94.      * @ORM\OneToMany(targetEntity="App\Entity\AdditionalLanguage", mappedBy="candidate", cascade={"remove"})
  95.      */
  96.     private $additionalLanguages;
  97.     /**
  98.      * @ORM\ManyToMany(targetEntity="App\Entity\Company", mappedBy="followers")
  99.      */
  100.     private $followedCompanies;
  101.     /**
  102.      * @ORM\OneToMany(targetEntity="App\Entity\JobApply", mappedBy="candidate")
  103.      */
  104.     public $applicants;
  105.      /**
  106.      * @ORM\Column(type="string", length=255, nullable=true)
  107.      * @var string|null
  108.      */
  109.     private $pictureThumbnail;
  110.      /**
  111.      * @Vich\UploadableField(mapping="thumbnails", fileNameProperty="pictureThumbnail")
  112.      * @var File|null
  113.      */
  114.     private $pictureImageFile;
  115.      /**
  116.      * @ORM\Column(type="string", length=255, nullable=true)
  117.      * @var string|null
  118.      */
  119.     private $cvPreview;
  120.      /**
  121.      * @Vich\UploadableField(mapping="thumbnails", fileNameProperty="cvPreview")
  122.      * @var File|null
  123.      */
  124.     private $cvFile;
  125.     /**
  126.      * @ORM\Column(type="datetime", nullable=true)
  127.      */
  128.     private $updatedAt;
  129.     public function __construct()
  130.     {
  131.         $this->additionalSkills = new ArrayCollection();
  132.         $this->educations = new ArrayCollection();
  133.         $this->workExperiences = new ArrayCollection();
  134.         $this->additionalLanguages = new ArrayCollection();
  135.         $this->followedCompanies = new ArrayCollection();
  136.         $this->applicants = new ArrayCollection();
  137.         $this->updatedAt = new \DateTime();
  138.     }
  139.     /**
  140.      * @return int|null
  141.      */
  142.     public function getId(): ?int {
  143.         return $this->id;
  144.     }
  145.     /**
  146.      * @param int $id
  147.      *
  148.      * @return Candidate
  149.      */
  150.     public function setId(int $id): Candidate {
  151.         $this->id = $id;
  152.         return $this;
  153.     }
  154.     /**
  155.      * @return User|null
  156.      */
  157.     public function getUser(): ?User {
  158.         return $this->user;
  159.     }
  160.     /**
  161.      * @param User $user
  162.      *
  163.      * @return Candidate
  164.      */
  165.     public function setUser(User $user): Candidate {
  166.         $this->user = $user;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @param User $user
  171.      *
  172.      * @return Candidate
  173.      */
  174.     public function removeUser(User $user): Candidate {
  175.         if ($this->user == $user) {
  176.             $this->user = null;
  177.         }
  178.         return $this;
  179.     }
  180.     /**
  181.      * @return string|null
  182.      */
  183.     public function getName(): ?string {
  184.         return $this->name;
  185.     }
  186.     /**
  187.      * @param string $name
  188.      *
  189.      * @return Candidate
  190.      */
  191.     public function setName(string $name): Candidate {
  192.         $this->name = $name;
  193.         return $this;
  194.     }
  195.     /**
  196.      * @return string|null
  197.      */
  198.     public function getAddress(): ?string {
  199.         return $this->address;
  200.     }
  201.     /**
  202.      * @param int|null $age
  203.      *
  204.      * @return Candidate
  205.      */
  206.     public function setAge(?int $age): Candidate {
  207.         $this->age = $age;
  208.         return $this;
  209.     }
  210.     /**
  211.      * @return int|null
  212.      */
  213.     public function getAge(): ?int {
  214.         return $this->age;
  215.     }
  216.     /**
  217.      * @param string|null $address
  218.      *
  219.      * @return Candidate
  220.      */
  221.     public function setAddress(?string $address): Candidate {
  222.         $this->address = $address;
  223.         return $this;
  224.     }
  225.     /**
  226.      * @return string|null
  227.      */
  228.     public function getPhone(): ?string {
  229.         return $this->phone;
  230.     }
  231.     /**
  232.      * @param string|null $phone
  233.      *
  234.      * @return Candidate
  235.      */
  236.     public function setPhone(?string $phone): Candidate {
  237.         $this->phone = $phone;
  238.         return $this;
  239.     }
  240.     /**
  241.      * @return string|null
  242.      */
  243.     public function getDescription(): ?string {
  244.         return $this->description;
  245.     }
  246.     /**
  247.      * @param string|null $description
  248.      *
  249.      * @return Candidate
  250.      */
  251.     public function setDescription(?string $description): Candidate {
  252.         $this->description = $description;
  253.         return $this;
  254.     }
  255.     /**
  256.      * @return string|null
  257.      */
  258.     public function getWebsite(): ?string
  259.     {
  260.         return $this->website;
  261.     }
  262.     /**
  263.      * @param string|null $website
  264.      *
  265.      * @return Candidate
  266.      */
  267.     public function setWebsite(?string $website): self
  268.     {
  269.         $this->website = $website;
  270.         return $this;
  271.     }
  272.     public function getFacebook(): ?string
  273.     {
  274.         return $this->facebook;
  275.     }
  276.     public function setFacebook(?string $facebook): self
  277.     {
  278.         $this->facebook = $facebook;
  279.         return $this;
  280.     }
  281.     public function getTwitter(): ?string
  282.     {
  283.         return $this->twitter;
  284.     }
  285.     public function setTwitter(?string $twitter): self
  286.     {
  287.         $this->twitter = $twitter;
  288.         return $this;
  289.     }
  290.     public function getLinkedin(): ?string
  291.     {
  292.         return $this->linkedin;
  293.     }
  294.     public function setLinkedin(?string $linkedin): self
  295.     {
  296.         $this->linkedin = $linkedin;
  297.         return $this;
  298.     }
  299.     public function getInstagram(): ?string
  300.     {
  301.         return $this->instagram;
  302.     }
  303.     public function setInstagram(?string $instagram): self
  304.     {
  305.         $this->instagram = $instagram;
  306.         return $this;
  307.     }
  308.     /**
  309.  * @return Collection|AdditionalSkill[]
  310.  */
  311.     public function getAdditionalSkills(): Collection
  312.     {
  313.         return $this->additionalSkills;
  314.     }
  315.     /**
  316.      * @param AdditionalSkill $additionalSkill
  317.      *
  318.      * @return Candidate
  319.      */
  320.     public function addAdditionalSkill(AdditionalSkill $additionalSkill): self
  321.     {
  322.         if (!$this->additionalSkills->contains($additionalSkill)) {
  323.             $this->additionalSkills[] = $additionalSkill;
  324.         }
  325.         return $this;
  326.     }
  327.     /**
  328.      * @param AdditionalSkill $additionalSkill
  329.      *
  330.      * @return Candidate
  331.      */
  332.     public function removeAdditionalSkill(AdditionalSkill $additionalSkill): self
  333.     {
  334.         if ($this->additionalSkills->contains($additionalSkill)) {
  335.             $this->additionalSkills->removeElement($additionalSkill);
  336.         }
  337.         return $this;
  338.     }
  339.     /**
  340.      * @param ArrayCollection $additionalSkills
  341.      *
  342.      * @return Candidate
  343.      */
  344.     public function setAdditionalSkills(ArrayCollection $additionalSkills): self
  345.     {
  346.         $this->additionalSkills = $additionalSkills;
  347.         return $this;
  348.     }
  349.     /**
  350.      * @return Collection|Education[]
  351.      */
  352.     public function getEducations(): Collection
  353.     {
  354.         return $this->educations;
  355.     }
  356.     /**
  357.      * @param Education $education
  358.      *
  359.      * @return Candidate
  360.      */
  361.     public function addEducation(Education $education): self
  362.     {
  363.         if (!$this->educations->contains($education)) {
  364.             $this->educations[] = $education;
  365.         }
  366.         return $this;
  367.     }
  368.     /**
  369.      * @param Education $education
  370.      *
  371.      * @return Candidate
  372.      */
  373.     public function removeEducation(Education $education): self
  374.     {
  375.         if ($this->educations->contains($education)) {
  376.             $this->educations->removeElement($education);
  377.         }
  378.         return $this;
  379.     }
  380.     /**
  381.      * @param ArrayCollection $educations
  382.      *
  383.      * @return Candidate
  384.      */
  385.     public function setEducations(ArrayCollection $educations): self
  386.     {
  387.         $this->educations = $educations;
  388.         return $this;
  389.     }
  390.     /**
  391.      * @return Collection|WorkExperience[]
  392.      */
  393.     public function getWorkExperiences(): Collection
  394.     {
  395.         return $this->workExperiences;
  396.     }
  397.     /**
  398.      * @param WorkExperience $workExperience
  399.      *
  400.      * @return Candidate
  401.      */
  402.     public function addWorkExperience(WorkExperience $workExperience): self
  403.     {
  404.         if (!$this->workExperiences->contains($workExperience)) {
  405.             $this->workExperiences[] = $workExperience;
  406.         }
  407.         return $this;
  408.     }
  409.     /**
  410.      * @param WorkExperience $workExperience
  411.      *
  412.      * @return Candidate
  413.      */
  414.     public function removeWorkExperience(WorkExperience $workExperience): self
  415.     {
  416.         if ($this->workExperiences->contains($workExperience)) {
  417.             $this->workExperiences->removeElement($workExperience);
  418.         }
  419.         return $this;
  420.     }
  421.     /**
  422.      * @param ArrayCollection $workExperiences
  423.      *
  424.      * @return Candidate
  425.      */
  426.     public function setWorkExperiences(ArrayCollection $workExperiences): self
  427.     {
  428.         $this->workExperiences = $workExperiences;
  429.         return $this;
  430.     }
  431.     /**
  432.      * @return Collection|AdditionalLanguage[]
  433.      */
  434.     public function getAdditionalLanguages(): Collection
  435.     {
  436.         return $this->additionalLanguages;
  437.     }
  438.     /**
  439.      * @param AdditionalLanguage $additionalLanguages
  440.      *
  441.      * @return Candidate
  442.      */
  443.     public function addAdditionalLanguage(AdditionalLanguage $additionalLanguages): self
  444.     {
  445.         if (!$this->additionalLanguages->contains($additionalLanguages)) {
  446.             $this->additionalLanguages[] = $additionalLanguages;
  447.         }
  448.         return $this;
  449.     }
  450.     /**
  451.      * @param AdditionalLanguage $additionalLanguages
  452.      *
  453.      * @return Candidate
  454.      */
  455.     public function removeAdditionalLanguage(AdditionalLanguage $additionalLanguages): self
  456.     {
  457.         if ($this->additionalLanguages->contains($additionalLanguages)) {
  458.             $this->additionalLanguages->removeElement($additionalLanguages);
  459.         }
  460.         return $this;
  461.     }
  462.     /**
  463.      * @param ArrayCollection $additionalLanguages
  464.      *
  465.      * @return self
  466.      */
  467.     public function setAdditionalLanguages(ArrayCollection $additionalLanguages): self {
  468.         $this->additionalLanguages = $additionalLanguages;
  469.         return $this;
  470.     }
  471.     /**
  472.      * @return Collection|Company[]
  473.      */
  474.     public function getFollowedCompanies(): Collection
  475.     {
  476.         return $this->followedCompanies;
  477.     }
  478.     /**
  479.      * @param Company $followedCompany
  480.      *
  481.      * @return Candidate
  482.      */
  483.     public function addFollower(Company $followedCompany): self
  484.     {
  485.         if (!$this->followedCompanies->contains($followedCompany)) {
  486.             $this->followedCompanies[] = $followedCompany;
  487.         }
  488.         return $this;
  489.     }
  490.     /**
  491.      * @param Company $followedCompany
  492.      *
  493.      * @return Candidate
  494.      */
  495.     public function removeFollower(Company $followedCompany): self
  496.     {
  497.         if ($this->followedCompanies->contains($followedCompany)) {
  498.             $this->followedCompanies->removeElement($followedCompany);
  499.         }
  500.         return $this;
  501.     }
  502.     /**
  503.      * @param ArrayCollection $followedCompanies
  504.      *
  505.      * @return Candidate
  506.      */
  507.     public function setFollowedCompanies(ArrayCollection $followedCompanies): self
  508.     {
  509.         $this->followedCompanies = $followedCompanies;
  510.         return $this;
  511.     }
  512.     /**
  513.      * @return File|null
  514.      */
  515.     public function getPicture(){
  516.         return $this->getFileService()->getFile($this, self::FILE_PICTURE);
  517.     }
  518.     /**
  519.      * @param UploadedFile|null $file
  520.      *
  521.      * @return Candidate
  522.      */
  523.     public function setPicture(?UploadedFile $file): self{
  524.         if($file) {
  525.             $oldFile = $this->getFileService()->getFile($this, self::FILE_PICTURE);
  526.             $newFile = $this->getFileService()->upload($file, $this, self::FILE_PICTURE);
  527.             if($newFile && $oldFile){
  528.                 $this->getFileService()->delete($oldFile);
  529.             }
  530.         }
  531.         return $this;
  532.     }
  533.     /**
  534.      * @return Candidate
  535.      */
  536.     public function removePicture(): self{
  537.         $file = $this->getFileService()->getFile($this, self::FILE_PICTURE);
  538.         if($file) {
  539.             $this->getFileService()->delete($file);
  540.         }
  541.         return $this;
  542.     }
  543.     /**
  544.      * @return File|null
  545.      */
  546.     public function getCV(){
  547.         return $this->getFileService()->getFile($this, self::FILE_CV);
  548.     }
  549.     /**
  550.      * @param UploadedFile|null $file
  551.      *
  552.      * @return Candidate
  553.      */
  554.     public function setCV(?UploadedFile $file): self{
  555.         if($file) {
  556.             $this->getFileService()->upload($file, $this, self::FILE_CV);
  557.         }
  558.         return $this;
  559.     }
  560.     /**
  561.      * @return Candidate
  562.      */
  563.     public function removeCV(): self{
  564.         $file = $this->getFileService()->getFile($this, self::FILE_CV);
  565.         if($file) {
  566.             $this->getFileService()->delete($file);
  567.         }
  568.         return $this;
  569.     }
  570.     /**
  571.      * @return Collection|JobApply[]
  572.      */
  573.     public function getApplicants() {
  574.         return $this->applicants;
  575.     }
  576.     /**
  577.      * @param JobApply $jobApply
  578.      *
  579.      * @return Candidate
  580.      */
  581.     public function addJobPosition(JobApply $jobApply): self
  582.     {
  583.         if (!$this->applicants->contains($jobApply)) {
  584.             $this->applicants[] = $jobApply;
  585.         }
  586.         return $this;
  587.     }
  588.     /**
  589.      * @param JobApply $jobApply
  590.      *
  591.      * @return Candidate
  592.      */
  593.     public function removeJobPosition(JobApply $jobApply): self
  594.     {
  595.         if ($this->applicants->contains($jobApply)) {
  596.             $this->applicants->removeElement($jobApply);
  597.         }
  598.         return $this;
  599.     }
  600.      /**
  601.      * Get the value of pictureThumbnail
  602.      *
  603.      * @return  string|null
  604.      */ 
  605.     public function getPictureThumbnail()
  606.     {
  607.         return $this->pictureThumbnail;
  608.     }
  609.     /**
  610.      * Set the value of pictureThumbnail
  611.      *
  612.      * @param  string|null  $pictureThumbnail
  613.      *
  614.      * @return  self
  615.      */ 
  616.     public function setPictureThumbnail($pictureThumbnail)
  617.     {
  618.         $this->pictureThumbnail = $pictureThumbnail;
  619.         return $this;
  620.     }
  621.     /**
  622.      * Get the value of pictureImageFile
  623.      *
  624.      * @return  File|null
  625.      */ 
  626.     public function getPictureImageFile()
  627.     {
  628.         return $this->pictureImageFile;
  629.     }
  630.     /**
  631.      * Set the value of pictureImageFile
  632.      *
  633.      * @return  self
  634.      */ 
  635.     public function setPictureImageFile($pictureImageFile)
  636.     {
  637.         $this->pictureImageFile = $pictureImageFile;
  638.         if ($pictureImageFile) {
  639.             $this->setPicture($pictureImageFile);
  640.             $this->updatedAt = (new \DateTime());
  641.         }
  642.         return $this;
  643.     }
  644.     /**
  645.      * Get the value of cvPreview
  646.      *
  647.      * @return  string|null
  648.      */ 
  649.     public function getCvPreview()
  650.     {
  651.         return $this->cvPreview;
  652.     }
  653.     /**
  654.      * Set the value of cvPreview
  655.      *
  656.      * @param  string|null  $cvPreview
  657.      *
  658.      * @return  self
  659.      */ 
  660.     public function setCvPreview($cvPreview)
  661.     {
  662.         $this->cvPreview = $cvPreview;
  663.         return $this;
  664.     }
  665.     /**
  666.      * Get the value of cvFile
  667.      *
  668.      * @return  File|null
  669.      */ 
  670.     public function getCvFile()
  671.     {
  672.         return $this->cvFile;
  673.     }
  674.     /**
  675.      * Set the value of cvFile
  676.      *
  677.      * @return  self
  678.      */ 
  679.     public function setCvFile($cvFile)
  680.     {
  681.         $this->cvFile = $cvFile;
  682.         if ($cvFile) {
  683.             $this->setCV($cvFile);
  684.             $this->updatedAt = (new \DateTime());
  685.         }
  686.         return $this;
  687.     }
  688.     public function __toString() {
  689.         return $this->getName();
  690.     }
  691.     /**
  692.      * Specify data which should be serialized to JSON
  693.      *
  694.      * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
  695.      * @return mixed data which can be serialized by <b>json_encode</b>,
  696.      * which is a value of any type other than a resource.
  697.      * @since 5.4.0
  698.      */
  699.     public function jsonSerialize() {
  700.         return [
  701.             'id' => $this->getId(),
  702.             'email' => $this->getUser()->getEmail(),
  703.             'picture' => $this->getPicture(),
  704.             'cv' => $this->getCV(),
  705.             'name' => $this->getName(),
  706.             'address' => $this->getAddress(),
  707.             'age' => $this->getAge(),
  708.             'phone' => $this->getPhone(),
  709.             'description' => $this->getDescription(),
  710.             'website' => $this->getWebsite(),
  711.             'facebook' => $this->getFacebook(),
  712.             'twitter' => $this->getTwitter(),
  713.             'linkedin' => $this->getLinkedin(),
  714.             'instagram' => $this->getInstagram(),
  715.             'additionalSkills' => $this->getAdditionalSkills()->getValues(),
  716.             'educations' => $this->getEducations()->getValues(),
  717.             'workExperiences' => $this->getWorkExperiences()->getValues(),
  718.             'additionalLanguages' => $this->getAdditionalLanguages()->getValues(),
  719.             'followedCompanies' => $this->getFollowedCompanies()->map(function($obj){return $obj->getId();})->getValues()
  720.         ];
  721.     }
  722. }