<?php
namespace App\Entity;
use App\Utils\File\FileServiceTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass="App\Repository\CandidateRepository")
* @Vich\Uploadable
*/
class Candidate implements \JsonSerializable
{
use FileServiceTrait;
const FILE_PICTURE = "picture";
const FILE_CV = "cv";
const FILES = [
self::FILE_PICTURE => [
'types' => ['gif', 'jpg', 'jpeg', 'png', 'tif', 'svg'],
'dir' => '/candidate/picture',
'size' => 5*1024*1024,
],
self::FILE_CV => [
'types' => ['doc', 'docx', 'odt', 'pdf', 'rtf', 'txt'],
'dir' => '/candidate/cv',
'size' => 5*1024*1024,
],
];
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToOne(targetEntity="User", inversedBy="candidate")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
/**
* @ORM\Column(type="string", length=127)
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $address;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $age;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $website;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $facebook;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $twitter;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $linkedin;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $instagram;
/**
* @ORM\OneToMany(targetEntity="App\Entity\AdditionalSkill", mappedBy="candidate", cascade={"remove"})
*/
private $additionalSkills;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Education", mappedBy="candidate", cascade={"remove"})
*/
private $educations;
/**
* @ORM\OneToMany(targetEntity="App\Entity\WorkExperience", mappedBy="candidate", cascade={"remove"})
*/
private $workExperiences;
/**
* @ORM\OneToMany(targetEntity="App\Entity\AdditionalLanguage", mappedBy="candidate", cascade={"remove"})
*/
private $additionalLanguages;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Company", mappedBy="followers")
*/
private $followedCompanies;
/**
* @ORM\OneToMany(targetEntity="App\Entity\JobApply", mappedBy="candidate")
*/
public $applicants;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @var string|null
*/
private $pictureThumbnail;
/**
* @Vich\UploadableField(mapping="thumbnails", fileNameProperty="pictureThumbnail")
* @var File|null
*/
private $pictureImageFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @var string|null
*/
private $cvPreview;
/**
* @Vich\UploadableField(mapping="thumbnails", fileNameProperty="cvPreview")
* @var File|null
*/
private $cvFile;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
public function __construct()
{
$this->additionalSkills = new ArrayCollection();
$this->educations = new ArrayCollection();
$this->workExperiences = new ArrayCollection();
$this->additionalLanguages = new ArrayCollection();
$this->followedCompanies = new ArrayCollection();
$this->applicants = new ArrayCollection();
$this->updatedAt = new \DateTime();
}
/**
* @return int|null
*/
public function getId(): ?int {
return $this->id;
}
/**
* @param int $id
*
* @return Candidate
*/
public function setId(int $id): Candidate {
$this->id = $id;
return $this;
}
/**
* @return User|null
*/
public function getUser(): ?User {
return $this->user;
}
/**
* @param User $user
*
* @return Candidate
*/
public function setUser(User $user): Candidate {
$this->user = $user;
return $this;
}
/**
* @param User $user
*
* @return Candidate
*/
public function removeUser(User $user): Candidate {
if ($this->user == $user) {
$this->user = null;
}
return $this;
}
/**
* @return string|null
*/
public function getName(): ?string {
return $this->name;
}
/**
* @param string $name
*
* @return Candidate
*/
public function setName(string $name): Candidate {
$this->name = $name;
return $this;
}
/**
* @return string|null
*/
public function getAddress(): ?string {
return $this->address;
}
/**
* @param int|null $age
*
* @return Candidate
*/
public function setAge(?int $age): Candidate {
$this->age = $age;
return $this;
}
/**
* @return int|null
*/
public function getAge(): ?int {
return $this->age;
}
/**
* @param string|null $address
*
* @return Candidate
*/
public function setAddress(?string $address): Candidate {
$this->address = $address;
return $this;
}
/**
* @return string|null
*/
public function getPhone(): ?string {
return $this->phone;
}
/**
* @param string|null $phone
*
* @return Candidate
*/
public function setPhone(?string $phone): Candidate {
$this->phone = $phone;
return $this;
}
/**
* @return string|null
*/
public function getDescription(): ?string {
return $this->description;
}
/**
* @param string|null $description
*
* @return Candidate
*/
public function setDescription(?string $description): Candidate {
$this->description = $description;
return $this;
}
/**
* @return string|null
*/
public function getWebsite(): ?string
{
return $this->website;
}
/**
* @param string|null $website
*
* @return Candidate
*/
public function setWebsite(?string $website): self
{
$this->website = $website;
return $this;
}
public function getFacebook(): ?string
{
return $this->facebook;
}
public function setFacebook(?string $facebook): self
{
$this->facebook = $facebook;
return $this;
}
public function getTwitter(): ?string
{
return $this->twitter;
}
public function setTwitter(?string $twitter): self
{
$this->twitter = $twitter;
return $this;
}
public function getLinkedin(): ?string
{
return $this->linkedin;
}
public function setLinkedin(?string $linkedin): self
{
$this->linkedin = $linkedin;
return $this;
}
public function getInstagram(): ?string
{
return $this->instagram;
}
public function setInstagram(?string $instagram): self
{
$this->instagram = $instagram;
return $this;
}
/**
* @return Collection|AdditionalSkill[]
*/
public function getAdditionalSkills(): Collection
{
return $this->additionalSkills;
}
/**
* @param AdditionalSkill $additionalSkill
*
* @return Candidate
*/
public function addAdditionalSkill(AdditionalSkill $additionalSkill): self
{
if (!$this->additionalSkills->contains($additionalSkill)) {
$this->additionalSkills[] = $additionalSkill;
}
return $this;
}
/**
* @param AdditionalSkill $additionalSkill
*
* @return Candidate
*/
public function removeAdditionalSkill(AdditionalSkill $additionalSkill): self
{
if ($this->additionalSkills->contains($additionalSkill)) {
$this->additionalSkills->removeElement($additionalSkill);
}
return $this;
}
/**
* @param ArrayCollection $additionalSkills
*
* @return Candidate
*/
public function setAdditionalSkills(ArrayCollection $additionalSkills): self
{
$this->additionalSkills = $additionalSkills;
return $this;
}
/**
* @return Collection|Education[]
*/
public function getEducations(): Collection
{
return $this->educations;
}
/**
* @param Education $education
*
* @return Candidate
*/
public function addEducation(Education $education): self
{
if (!$this->educations->contains($education)) {
$this->educations[] = $education;
}
return $this;
}
/**
* @param Education $education
*
* @return Candidate
*/
public function removeEducation(Education $education): self
{
if ($this->educations->contains($education)) {
$this->educations->removeElement($education);
}
return $this;
}
/**
* @param ArrayCollection $educations
*
* @return Candidate
*/
public function setEducations(ArrayCollection $educations): self
{
$this->educations = $educations;
return $this;
}
/**
* @return Collection|WorkExperience[]
*/
public function getWorkExperiences(): Collection
{
return $this->workExperiences;
}
/**
* @param WorkExperience $workExperience
*
* @return Candidate
*/
public function addWorkExperience(WorkExperience $workExperience): self
{
if (!$this->workExperiences->contains($workExperience)) {
$this->workExperiences[] = $workExperience;
}
return $this;
}
/**
* @param WorkExperience $workExperience
*
* @return Candidate
*/
public function removeWorkExperience(WorkExperience $workExperience): self
{
if ($this->workExperiences->contains($workExperience)) {
$this->workExperiences->removeElement($workExperience);
}
return $this;
}
/**
* @param ArrayCollection $workExperiences
*
* @return Candidate
*/
public function setWorkExperiences(ArrayCollection $workExperiences): self
{
$this->workExperiences = $workExperiences;
return $this;
}
/**
* @return Collection|AdditionalLanguage[]
*/
public function getAdditionalLanguages(): Collection
{
return $this->additionalLanguages;
}
/**
* @param AdditionalLanguage $additionalLanguages
*
* @return Candidate
*/
public function addAdditionalLanguage(AdditionalLanguage $additionalLanguages): self
{
if (!$this->additionalLanguages->contains($additionalLanguages)) {
$this->additionalLanguages[] = $additionalLanguages;
}
return $this;
}
/**
* @param AdditionalLanguage $additionalLanguages
*
* @return Candidate
*/
public function removeAdditionalLanguage(AdditionalLanguage $additionalLanguages): self
{
if ($this->additionalLanguages->contains($additionalLanguages)) {
$this->additionalLanguages->removeElement($additionalLanguages);
}
return $this;
}
/**
* @param ArrayCollection $additionalLanguages
*
* @return self
*/
public function setAdditionalLanguages(ArrayCollection $additionalLanguages): self {
$this->additionalLanguages = $additionalLanguages;
return $this;
}
/**
* @return Collection|Company[]
*/
public function getFollowedCompanies(): Collection
{
return $this->followedCompanies;
}
/**
* @param Company $followedCompany
*
* @return Candidate
*/
public function addFollower(Company $followedCompany): self
{
if (!$this->followedCompanies->contains($followedCompany)) {
$this->followedCompanies[] = $followedCompany;
}
return $this;
}
/**
* @param Company $followedCompany
*
* @return Candidate
*/
public function removeFollower(Company $followedCompany): self
{
if ($this->followedCompanies->contains($followedCompany)) {
$this->followedCompanies->removeElement($followedCompany);
}
return $this;
}
/**
* @param ArrayCollection $followedCompanies
*
* @return Candidate
*/
public function setFollowedCompanies(ArrayCollection $followedCompanies): self
{
$this->followedCompanies = $followedCompanies;
return $this;
}
/**
* @return File|null
*/
public function getPicture(){
return $this->getFileService()->getFile($this, self::FILE_PICTURE);
}
/**
* @param UploadedFile|null $file
*
* @return Candidate
*/
public function setPicture(?UploadedFile $file): self{
if($file) {
$oldFile = $this->getFileService()->getFile($this, self::FILE_PICTURE);
$newFile = $this->getFileService()->upload($file, $this, self::FILE_PICTURE);
if($newFile && $oldFile){
$this->getFileService()->delete($oldFile);
}
}
return $this;
}
/**
* @return Candidate
*/
public function removePicture(): self{
$file = $this->getFileService()->getFile($this, self::FILE_PICTURE);
if($file) {
$this->getFileService()->delete($file);
}
return $this;
}
/**
* @return File|null
*/
public function getCV(){
return $this->getFileService()->getFile($this, self::FILE_CV);
}
/**
* @param UploadedFile|null $file
*
* @return Candidate
*/
public function setCV(?UploadedFile $file): self{
if($file) {
$this->getFileService()->upload($file, $this, self::FILE_CV);
}
return $this;
}
/**
* @return Candidate
*/
public function removeCV(): self{
$file = $this->getFileService()->getFile($this, self::FILE_CV);
if($file) {
$this->getFileService()->delete($file);
}
return $this;
}
/**
* @return Collection|JobApply[]
*/
public function getApplicants() {
return $this->applicants;
}
/**
* @param JobApply $jobApply
*
* @return Candidate
*/
public function addJobPosition(JobApply $jobApply): self
{
if (!$this->applicants->contains($jobApply)) {
$this->applicants[] = $jobApply;
}
return $this;
}
/**
* @param JobApply $jobApply
*
* @return Candidate
*/
public function removeJobPosition(JobApply $jobApply): self
{
if ($this->applicants->contains($jobApply)) {
$this->applicants->removeElement($jobApply);
}
return $this;
}
/**
* Get the value of pictureThumbnail
*
* @return string|null
*/
public function getPictureThumbnail()
{
return $this->pictureThumbnail;
}
/**
* Set the value of pictureThumbnail
*
* @param string|null $pictureThumbnail
*
* @return self
*/
public function setPictureThumbnail($pictureThumbnail)
{
$this->pictureThumbnail = $pictureThumbnail;
return $this;
}
/**
* Get the value of pictureImageFile
*
* @return File|null
*/
public function getPictureImageFile()
{
return $this->pictureImageFile;
}
/**
* Set the value of pictureImageFile
*
* @return self
*/
public function setPictureImageFile($pictureImageFile)
{
$this->pictureImageFile = $pictureImageFile;
if ($pictureImageFile) {
$this->setPicture($pictureImageFile);
$this->updatedAt = (new \DateTime());
}
return $this;
}
/**
* Get the value of cvPreview
*
* @return string|null
*/
public function getCvPreview()
{
return $this->cvPreview;
}
/**
* Set the value of cvPreview
*
* @param string|null $cvPreview
*
* @return self
*/
public function setCvPreview($cvPreview)
{
$this->cvPreview = $cvPreview;
return $this;
}
/**
* Get the value of cvFile
*
* @return File|null
*/
public function getCvFile()
{
return $this->cvFile;
}
/**
* Set the value of cvFile
*
* @return self
*/
public function setCvFile($cvFile)
{
$this->cvFile = $cvFile;
if ($cvFile) {
$this->setCV($cvFile);
$this->updatedAt = (new \DateTime());
}
return $this;
}
public function __toString() {
return $this->getName();
}
/**
* Specify data which should be serialized to JSON
*
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize() {
return [
'id' => $this->getId(),
'email' => $this->getUser()->getEmail(),
'picture' => $this->getPicture(),
'cv' => $this->getCV(),
'name' => $this->getName(),
'address' => $this->getAddress(),
'age' => $this->getAge(),
'phone' => $this->getPhone(),
'description' => $this->getDescription(),
'website' => $this->getWebsite(),
'facebook' => $this->getFacebook(),
'twitter' => $this->getTwitter(),
'linkedin' => $this->getLinkedin(),
'instagram' => $this->getInstagram(),
'additionalSkills' => $this->getAdditionalSkills()->getValues(),
'educations' => $this->getEducations()->getValues(),
'workExperiences' => $this->getWorkExperiences()->getValues(),
'additionalLanguages' => $this->getAdditionalLanguages()->getValues(),
'followedCompanies' => $this->getFollowedCompanies()->map(function($obj){return $obj->getId();})->getValues()
];
}
}