src/Entity/JobApply.php line 296

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Utils\File\FileServiceTrait;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\HttpFoundation\File\UploadedFile;
  6. use Symfony\Component\Validator\Exception\ValidatorException;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\JobApplyRepository")
  9.  * @ORM\Table(name="job_apply",uniqueConstraints={@ORM\UniqueConstraint(name="indx", columns={"job_position_id", "candidate_id"})})
  10.  */
  11. class JobApply implements \JsonSerializable {
  12.     use FileServiceTrait;
  13.     const FILE_OTHER = "other";
  14.     const FILE_CV = "cv";
  15.     const FILES = [
  16.         self::FILE_OTHER => [
  17.             'types' => ['doc', 'docx', 'odt', 'pdf', 'rtf', 'txt', ],
  18.             'dir' => '/job-apply',
  19.             'size' => 5*1024*1024,
  20.         ],
  21.         self::FILE_CV => [
  22.             'types' => ['doc', 'docx', 'odt', 'pdf', 'rtf', 'txt'],
  23.             'dir' => '/job-apply',
  24.             'size' => 5*1024*1024,
  25.         ],
  26.     ];
  27.     // const TYPE_PROFILE = 1;
  28.     // const TYPE_PROFILE_CV = 2;
  29.     // const TYPE_CV = 3;
  30.     // const TYPES = [
  31.     //     self::TYPE_PROFILE => "with profile",
  32.     //     self::TYPE_PROFILE_CV => "with profile CV",
  33.     //     self::TYPE_CV => "with uploading CV"
  34.     // ];
  35.     const TYPE_PROFILE_AND_CV = 1;
  36.     const TYPE_CV = 2;
  37.     const TYPES = [
  38.         self::TYPE_PROFILE_AND_CV => "with profile and/or with profile CV",
  39.         self::TYPE_CV => "with uploading CV"
  40.     ];
  41.     const STATUS_NEW = 1;
  42.     const STATUS_APPROVED = 2;
  43.     const STATUS_NOT_APPROVED = 3;
  44.     const STATUS_HIRED = 4;
  45.     const STATUSES = [
  46.         self::STATUS_NEW => "New",
  47.         self::STATUS_APPROVED => "Approved",
  48.         self::STATUS_NOT_APPROVED => "Not Approved",
  49.         self::STATUS_HIRED => "Hired"
  50.     ];
  51.     /**
  52.      * @ORM\Id()
  53.      * @ORM\GeneratedValue()
  54.      * @ORM\Column(type="integer")
  55.      */
  56.     public $id;
  57.     /**
  58.      * @ORM\ManyToOne(targetEntity="App\Entity\JobPosition", inversedBy="applicants")
  59.      */
  60.     private $jobPosition;
  61.     /**
  62.      * @ORM\ManyToOne(targetEntity="App\Entity\Candidate", inversedBy="applicants")
  63.      */
  64.     private $candidate;
  65.     /**
  66.      * @ORM\Column(type="integer")
  67.      */
  68.     private $type;
  69.     /**
  70.      * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  71.      */
  72.     public $createdAt;
  73.     /**
  74.      * @ORM\Column(type="integer")
  75.      */
  76.     private $status;
  77.     public function __construct() {
  78.         $this->setCreatedAt(new \DateTime());
  79.         $this->setStatus(self::STATUS_NEW);
  80.     }
  81.     /**
  82.      * @return int
  83.      */
  84.     public function getId(): int {
  85.         return $this->id;
  86.     }
  87.     /**
  88.      * @param int $id
  89.      *
  90.      * @return JobApply
  91.      */
  92.     public function setId(int $id): self {
  93.         $this->id = $id;
  94.         return $this;
  95.     }
  96.     /**
  97.      * @return JobPosition
  98.      */
  99.     public function getJobPosition(): ?JobPosition {
  100.         return $this->jobPosition;
  101.     }
  102.     /**
  103.      * @param JobPosition $jobPosition
  104.      *
  105.      * @return JobApply
  106.      */
  107.     public function setJobPosition(JobPosition $jobPosition): self {
  108.         $this->jobPosition = $jobPosition;
  109.         return $this;
  110.     }
  111.     /**
  112.      * @return Candidate
  113.      */
  114.     public function getCandidate(): ?Candidate {
  115.         return $this->candidate;
  116.     }
  117.     /**
  118.      * @param Candidate $candidate
  119.      *
  120.      * @return JobApply
  121.      */
  122.     public function setCandidate(Candidate $candidate): self {
  123.         $this->candidate = $candidate;
  124.         return $this;
  125.     }
  126.     /**
  127.      * @return \DateTime
  128.      */
  129.     public function getCreatedAt(): \DateTime {
  130.         return $this->createdAt;
  131.     }
  132.     /**
  133.      * @param \DateTime $createdAt
  134.      *
  135.      * @return JobApply
  136.      */
  137.     public function setCreatedAt(\DateTime $createdAt): self {
  138.         $this->createdAt = $createdAt;
  139.         return $this;
  140.     }
  141.     /**
  142.      * @return int|null
  143.      */
  144.     public function getType(): ?int
  145.     {
  146.         return $this->type;
  147.     }
  148.     /**
  149.      * @param int $type
  150.      *
  151.      * @return JobApply
  152.      */
  153.     public function setType(int $type): self
  154.     {
  155.         if(!array_key_exists($type, self::TYPES)){
  156.             throw new ValidatorException("Job Apply type is not valid");
  157.         }
  158.         $this->type = $type;
  159.         return $this;
  160.     }
  161.     /**
  162.      * @return int|null
  163.      */
  164.     public function getStatus(): ?int
  165.     {
  166.         return $this->status;
  167.     }
  168.     /**
  169.      * @param int $status
  170.      *
  171.      * @return JobApply
  172.      */
  173.     public function setStatus(int $status): self
  174.     {
  175.         if(!array_key_exists($status, self::STATUSES)){
  176.             throw new ValidatorException("Job Apply status is not valid");
  177.         }
  178.         $this->status = $status;
  179.         return $this;
  180.     }
  181.     /**
  182.      * @return File|null
  183.      */
  184.     public function getCV(){
  185.         return $this->getFileService()->getFile($this, self::FILE_CV);
  186.     }
  187.     /**
  188.      * @param UploadedFile|null $file
  189.      *
  190.      * @return JobApply
  191.      */
  192.     public function setCV(?UploadedFile $file): self{
  193.         if($file) {
  194.             $this->getFileService()->upload($file, $this, self::FILE_CV);
  195.         }
  196.         return $this;
  197.     }
  198.     /**
  199.      * @return JobApply
  200.      */
  201.     public function removeCV(): self{
  202.         $file = $this->getFileService()->getFile($this, self::FILE_CV);
  203.         if($file) {
  204.             $this->getFileService()->delete($file);
  205.         }
  206.         return $this;
  207.     }
  208.     /**
  209.      * @return File[]|null
  210.      */
  211.     public function getOtherFiles(){
  212.         return $this->getFileService()->getFiles($this, self::FILE_OTHER);
  213.     }
  214.     /**
  215.      * @param UploadedFile|null $file
  216.      *
  217.      * @return JobApply
  218.      */
  219.     public function addOtherFile(?UploadedFile $file): self{
  220.         if($file) {
  221.             $this->getFileService()->upload($file, $this, self::FILE_OTHER);
  222.         }
  223.         return $this;
  224.     }
  225.     /**
  226.      * @return JobApply
  227.      */
  228.     public function removeOtherFiles(): self{
  229.         $files = $this->getFileService()->getFiles($this, self::FILE_OTHER);
  230.         foreach ($files as $file) {
  231.             $this->getFileService()->delete($file);
  232.         }
  233.         return $this;
  234.     }
  235.     /**
  236.      * @param array $files
  237.      *
  238.      * @return JobApply
  239.      */
  240.     public function setOtherFiles(array $files): self{
  241.         if($files) {
  242.             foreach ($files as $file){
  243.                 $this->getFileService()->upload($file, $this, self::FILE_OTHER);
  244.             }
  245.         }
  246.         return $this;
  247.     }
  248.     public function __toString() {
  249.         return (string)$this->getJobPosition() . ' - ' . (string)$this->getCandidate();
  250.     }
  251.     /**
  252.      * Specify data which should be serialized to JSON
  253.      *
  254.      * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
  255.      * @return mixed data which can be serialized by <b>json_encode</b>,
  256.      * which is a value of any type other than a resource.
  257.      * @since 5.4.0
  258.      */
  259.     public function jsonSerialize() {
  260.         return [
  261.             'id' => $this->getId(),
  262.             'jobPositionId' => $this->getJobPosition(),
  263.             'candidate' => $this->getCandidate(),
  264.             'type' => $this->getType(),
  265.             'cv' => $this->getCV(),
  266.             'otherFiles' => $this->getOtherFiles(),
  267.             'createdAt' => $this->getCreatedAt(),
  268.             'status' => $this->getStatus()
  269.         ];
  270.     }
  271. }