<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use phpDocumentor\Reflection\Types\Integer;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Exception\ValidatorException;
use App\Utils\File\FileServiceTrait;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass="App\Repository\JobPositionRepository")
* @Vich\Uploadable
*/
class JobPosition implements \JsonSerializable
{
use FileServiceTrait;
public $targetDirectory;
const FILE_PICTURE = "sharePicture";
const FILE_LOGO = "additionalLogo";
const FILES = [
self::FILE_PICTURE => [
'types' => ['gif', 'jpg', 'jpeg', 'png', 'tif', 'svg'],
'dir' => '/job_position_picture',
'size' => 5*1024*1024,
],
self::FILE_LOGO => [
'types' => ['gif', 'jpg', 'jpeg', 'png', 'tif', 'svg'],
'dir' => '/company_logo',
'size' => 5*1024*1024,
],
];
const APPLYING_TYPE_INTERNAL = 1;
const APPLYING_TYPE_EXTERNAL = 2;
const APPLYING_TYPES = [
self::APPLYING_TYPE_INTERNAL => "Internal",
self::APPLYING_TYPE_EXTERNAL => "External"
];
const JOB_SUB_TYPE_CHOOSE = 0;
const JOB_SUB_TYPE_REMOTE = 1;
const JOB_SUB_TYPE_HYBRID = 2;
const JOB_SUB_TYPE_REGULAR = 3;
const JOB_SUB_TYPES = [
self::JOB_SUB_TYPE_CHOOSE => "Choose",
self::JOB_SUB_TYPE_REMOTE => "Remote",
self::JOB_SUB_TYPE_HYBRID => "Hybrid",
self::JOB_SUB_TYPE_REGULAR => "Regular"
];
const JOB_SALARY_CHOOSE = 0;
const JOB_SALARY_YES = 1;
const JOB_SALARY_NO = 2;
const JOB_SALARY = [
self::JOB_SALARY_CHOOSE => "Choose",
self::JOB_SALARY_YES => "Yes",
self::JOB_SALARY_NO => "No",
];
const JOB_APPLICANTS_CHOOSE = 0;
const JOB_APPLICANTS_MIN = 1;
const JOB_APPLICANTS_MAX = 2;
const JOB_APPLICANTS = [
self::JOB_APPLICANTS_CHOOSE => "Choose",
self::JOB_APPLICANTS_MIN => "Min",
self::JOB_APPLICANTS_MAX => "Max",
];
const STATUS_DRAFT = 1;
const STATUS_ACTIVE = 2;
const STATUS_INACTIVE = 3;
const STATUS_EXPIRED = 4;
const STATUS_DELETED = 5;
const STATUSES = [
self::STATUS_DRAFT => "Draft",
self::STATUS_ACTIVE => "Active",
self::STATUS_INACTIVE => "Inactive",
self::STATUS_EXPIRED => "Expired",
self::STATUS_DELETED => "Deleted"
];
const VALID_IN_DAYS = 30;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
public $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="jobPositions")
* @ORM\JoinColumn(nullable=false)
*/
public $company;
/**
* @ORM\Column(type="string", length=255)
*/
public $title;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Department")
* @ORM\JoinColumn(nullable=false)
*/
public $department;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
public $refNumber;
/**
* @ORM\Column(type="text", nullable=false)
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $location;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\City")
* @ORM\JoinColumn(nullable=false)
*/
private $city;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\JobType", inversedBy="jobPositions")
* @ORM\JoinColumn(nullable=false)
*/
private $jobType;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\JobSubType", inversedBy="jobPositions")
* @ORM\JoinColumn(nullable=false)
*/
private $jobSubType;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\PositionLevel", inversedBy="jobPositions")
* @ORM\JoinColumn(nullable=false)
*/
private $positionLevel;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $workingHours;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Skill")
*/
private $skills;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Language")
*/
private $languages;
/**
* @ORM\Column(type="integer", nullable=false)
*/
private $applyingType;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $applyingUrl;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\ApplyingDocument")
*/
private $requiredDocuments;
/**
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $publishedAt;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $validTo;
/**
* @ORM\Column(type="boolean", options={"default":"0"})
*/
public $featured = FALSE;
/**
* @ORM\Column(type="boolean", options={"default":"0"})
*/
public $companyFeatured = FALSE;
/**
* @ORM\OneToMany(targetEntity="App\Entity\JobApply", mappedBy="jobPosition")
*/
public $applicants;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $slug;
/**
* @ORM\Column(type="boolean", options={"default":"0"})
*/
public $promoted = FALSE;
/**
* @ORM\Column(type="boolean", options={"default":"0"})
*/
public $alreadyPromoted = FALSE;
/**
* @ORM\Column(type="integer")
*/
private $status;
/**
* @ORM\Column(type="integer", nullable=true),
*/
private $totalViews;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $secondaryEmail;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $minSalary;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $maxSalary;
/**
* @ORM\Column(name="latitude", type="decimal", precision=20, scale=16)
*/
private $latitude;
/**
* @ORM\Column(name="longitude", type="decimal", precision=20, scale=16)
*/
private $longitude;
/**
* @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 $logoThumbnail;
/**
* @Vich\UploadableField(mapping="thumbnails", fileNameProperty="logoThumbnail")
* @var File|null
*/
private $logoImageFile;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
public function __construct()
{
$this->setCreatedAt(new \DateTime());
$this->setStatus(self::STATUS_DRAFT);
$this->department = new ArrayCollection();
$this->skills = new ArrayCollection();
$this->languages = new ArrayCollection();
$this->requiredDocuments = new ArrayCollection();
$this->applicants = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Company
*/
public function getCompany(): ?Company {
return $this->company;
}
/**
* @param Company $company
*
* @return JobPosition
*/
public function setCompany(Company $company): self {
$this->company = $company;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
/**
* @return Collection|Department[]
*/
public function getDepartments(): Collection
{
return $this->department;
}
public function addDepartment(Department $department): self
{
if (!$this->department->contains($department)) {
$this->department[] = $department;
}
return $this;
}
public function removeDepartment(Department $department): self
{
if ($this->department->contains($department)) {
$this->department->removeElement($department);
}
return $this;
}
public function setDepartments(ArrayCollection $departments): self
{
$this->department = $departments;
return $this;
}
public function getRefNumber(): ?string
{
return $this->refNumber;
}
public function setRefNumber(?string $refNumber): self
{
$this->refNumber = $refNumber;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getLocation(): ?string
{
return $this->location;
}
public function setLocation(?string $location): self
{
$this->location = $location;
return $this;
}
public function getCity(): ?City
{
return $this->city;
}
public function setCity(City $city): self
{
$this->city = $city;
return $this;
}
public function getJobType(): ?JobType
{
return $this->jobType;
}
public function setJobType(JobType $jobType): self
{
$this->jobType = $jobType;
return $this;
}
public function getJobSubType(): ?JobSubType
{
return $this->jobSubType;
}
public function setJobSubType(?JobSubType $jobSubType): self
{
$this->jobSubType = $jobSubType;
return $this;
}
public function getPositionLevel(): ?PositionLevel
{
return $this->positionLevel;
}
public function setPositionLevel(PositionLevel $positionLevel): self
{
$this->positionLevel = $positionLevel;
return $this;
}
public function getWorkingHours(): ?string
{
return $this->workingHours;
}
public function setWorkingHours(?string $workingHours): self
{
$this->workingHours = $workingHours;
return $this;
}
/**
* @return Collection|Skill[]
*/
public function getSkills(): Collection
{
return $this->skills;
}
public function addSkill(Skill $skill): self
{
if (!$this->skills->contains($skill)) {
$this->skills[] = $skill;
}
return $this;
}
public function removeSkill(Skill $skill): self
{
if ($this->skills->contains($skill)) {
$this->skills->removeElement($skill);
}
return $this;
}
public function setSkills(ArrayCollection $skills): self
{
$this->skills = $skills;
return $this;
}
/**
* @return Collection|Language[]
*/
public function getLanguages(): Collection
{
return $this->languages;
}
public function addLanguage(Language $language): self
{
if (!$this->languages->contains($language)) {
$this->languages[] = $language;
}
return $this;
}
public function removeLanguage(Language $language): self
{
if ($this->languages->contains($language)) {
$this->languages->removeElement($language);
}
return $this;
}
public function setLanguages(ArrayCollection $languages): self
{
$this->languages = $languages;
return $this;
}
public function getApplyingType(): ?int
{
return $this->applyingType;
}
public function setApplyingType(int $applyingType): self
{
if(!array_key_exists($applyingType, self::APPLYING_TYPES)){
throw new ValidatorException("Job position applying type is now valid");
}
$this->applyingType = $applyingType;
return $this;
}
public function getApplyingUrl(): ?string
{
return $this->applyingUrl;
}
public function setApplyingUrl(?string $applyingUrl): self
{
$this->applyingUrl = $applyingUrl;
return $this;
}
/**
* @return Collection|ApplyingDocument[]
*/
public function getRequiredDocuments(): Collection
{
return $this->requiredDocuments;
}
public function addRequiredDocument(ApplyingDocument $requiredDocument): self
{
if (!$this->requiredDocuments->contains($requiredDocument)) {
$this->requiredDocuments[] = $requiredDocument;
}
return $this;
}
public function removeRequiredDocument(ApplyingDocument $requiredDocument): self
{
if ($this->requiredDocuments->contains($requiredDocument)) {
$this->requiredDocuments->removeElement($requiredDocument);
}
return $this;
}
public function setRequiredDocuments(ArrayCollection $requiredDocuments): self
{
$this->requiredDocuments = $requiredDocuments;
return $this;
}
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime {
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*
* @return JobPosition
*/
public function setCreatedAt(\DateTime $createdAt): self {
$this->createdAt = $createdAt;
return $this;
}
/**
* @return null|\DateTime
*/
public function getPublishedAt(): ?\DateTime {
return $this->publishedAt;
}
/**
* @param null|\DateTime $publishedAt
*
* @return JobPosition
*/
public function setPublishedAt(?\DateTime $publishedAt): self {
$this->publishedAt = $publishedAt;
return $this;
}
/**
* @return \DateTime
*/
public function getValidTo(): ?\DateTime {
return $this->validTo;
}
/**
* @param \DateTime $validTo
*
* @return JobPosition
*/
public function setValidTo(?\DateTime $validTo): self {
$this->validTo = $validTo;
return $this;
}
/**
* @return bool
*/
public function getFeatured(): bool {
return $this->featured;
}
/**
* @param bool $featured
*
* @return JobPosition
*/
public function setFeatured(bool $featured): self {
$this->featured = $featured;
return $this;
}
/**
* @return bool
*/
public function getCompanyFeatured(): bool {
return $this->companyFeatured;
}
/**
* @param bool $companyFeatured
*
* @return JobPosition
*/
public function setCompanyFeatured(bool $companyFeatured): self {
$this->companyFeatured = $companyFeatured;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
if(!array_key_exists($status, self::STATUSES)){
throw new ValidatorException("Job position status is not valid");
}
$this->status = $status;
return $this;
}
public function getTotalViews(): ?int
{
return $this->totalViews;
}
public function setTotalViews($views): self
{
$this->totalViews += $views;
return $this;
}
/**
* @return Collection|JobApply[]
*/
public function getApplicants() {
return $this->applicants;
}
/**
* @return string|null
*/
public function getSlug(): ?string
{
return $this->slug;
}
/**
* @param string $slug
*
* @return self
*/
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return bool
*/
public function getPromoted(): bool {
return $this->promoted;
}
/**
* @param bool $promoted
*
* @return JobPosition
*/
public function setPromoted(bool $promoted): self {
$this->promoted = $promoted;
return $this;
}
/**
* @return bool
*/
public function getAlreadyPromoted(): bool {
return $this->alreadyPromoted;
}
/**
* @param bool $promoted
*
* @return JobPosition
*/
public function setAlreadyPromoted(bool $alreadyPromoted): self {
$this->alreadyPromoted = $alreadyPromoted;
return $this;
}
public function getMinSalary(): ?int
{
return $this->minSalary;
}
public function setMinSalary(?int $minSalary): self
{
$this->minSalary = $minSalary;
return $this;
}
public function getMaxSalary(): ?int
{
return $this->maxSalary;
}
public function setMaxSalary(?int $maxSalary): self
{
$this->maxSalary = $maxSalary;
return $this;
}
public function getLatitude(): ?string
{
return $this->latitude;
}
public function setLatitude(?string $latitude): self
{
$this->latitude = $latitude;
return $this;
}
public function getLongitude(): ?string
{
return $this->longitude;
}
public function setLongitude(?string $longitude): self
{
$this->longitude = $longitude;
return $this;
}
/**
* @param JobApply $jobApply
*
* @return JobPosition
*/
public function addJobPosition(JobApply $jobApply): self
{
if (!$this->applicants->contains($jobApply)) {
$this->applicants[] = $jobApply;
}
return $this;
}
/**
* @param JobApply $jobApply
*
* @return JobPosition
*/
public function removeJobPosition(JobApply $jobApply): self
{
if ($this->applicants->contains($jobApply)) {
$this->applicants->removeElement($jobApply);
}
return $this;
}
public function __toString() {
return $this->getTitle();
}
public function getSecondaryEmail(): ?string
{
return $this->secondaryEmail;
}
public function setSecondaryEmail(?string $secondaryEmail): self
{
$this->secondaryEmail = $secondaryEmail;
return $this;
}
public function getPicture(){
return $this->getFileService()->getFile($this, self::FILE_PICTURE);
}
public function setPicture(?UploadedFile $file){
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;
}
public function removePicture(){
$file = $this->getFileService()->getFile($this, self::FILE_PICTURE);
if($file) {
$this->getFileService()->delete($file);
}
return $this;
}
public function getLogo(){
return $this->getFileService()->getFile($this, self::FILE_LOGO);
}
public function setLogo(?UploadedFile $file){
if($file) {
$oldFile = $this->getFileService()->getFile($this, self::FILE_LOGO);
$newFile = $this->getFileService()->upload($file, $this, self::FILE_LOGO);
if($newFile && $oldFile){
$this->getFileService()->delete($oldFile);
}
}
return $this;
}
public function removeLogo(){
$file = $this->getFileService()->getFile($this, self::FILE_LOGO);
if($file) {
$this->getFileService()->delete($file);
}
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(?string $pictureThumbnail)
{
$this->pictureThumbnail = $pictureThumbnail;
return $this;
}
/**
* Get the value of pictureImageFile
*/
public function getPictureImageFile()
{
return $this->pictureImageFile;
}
/**
* Set the value of pictureImageFile
*
* @return self
*/
public function setPictureImageFile(?UploadedFile $pictureImageFile = null)
{
$this->pictureImageFile = $pictureImageFile;
if ($pictureImageFile) {
$this->setPicture($pictureImageFile);
$this->updatedAt = (new \DateTime());
}
return $this;
}
/**
* Get the value of logoThumbnail
*
* @return string|null
*/
public function getLogoThumbnail()
{
return $this->logoThumbnail;
}
/**
* Set the value of logoThumbnail
*
* @param string|null $logoThumbnail
*
* @return self
*/
public function setLogoThumbnail(?string $logoThumbnail)
{
$this->logoThumbnail = $logoThumbnail;
return $this;
}
/**
* Get the value of logoImageFile
*
* @return File|null
*/
public function getLogoImageFile()
{
return $this->logoImageFile;
}
/**
* Set the value of logoImageFile
*
* @return self
*/
public function setLogoImageFile(?UploadedFile $logoImageFile = null)
{
$this->logoImageFile = $logoImageFile;
if ($logoImageFile) {
$this->setLogo($logoImageFile);
$this->updatedAt = (new \DateTime());
}
return $this;
}
/**
* @param null|\DateTime $updatedAt
*
* @return JobPosition
*/
public function setUpdatedAt(?\DateTime $updatedAt): self {
$this->updatedAt = $updatedAt;
return $this;
}
/**
* 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(),
'company' => $this->getCompany(),
'title' => $this->getTitle(),
'department' => $this->getDepartments()->getValues(),
'refNumber' => $this->getRefNumber(),
'descriptions' => $this->getDescription(),
'location' => $this->getLocation(),
'city' => $this->getCity(),
'jobType' => $this->getJobType(),
'jobTypeByLocation' => ($this->getJobSubType() && $this->getJobSubType()->getId() != self::JOB_SUB_TYPE_REGULAR) ? $this->getJobSubType() : null,
'positionLevel' => $this->getPositionLevel(),
'workingHours' => $this->getWorkingHours(),
'applyingType' => $this->getApplyingType(),
'applyingUrl' => $this->getApplyingUrl(),
'createdAt' => $this->getCreatedAt(),
'validTo' => $this->getValidTo(),
'skills' => $this->getSkills()->getValues(),
'languages' => $this->getLanguages()->getValues(),
'requiredDocuments' => $this->getRequiredDocuments()->getValues(),
'featured' => $this->getFeatured(),
'companyFeatured' => $this->getCompanyFeatured(),
'status' => $this->getStatus(),
'countApplyJobPositions' => $this->getApplicants()->count(),
'slug' => $this->getSlug(),
'promoted' => $this->getPromoted(),
'alreadyPromoted' => $this->getAlreadyPromoted(),
'totalViews' => $this->getTotalViews(),
'secondaryEmail' => $this->getSecondaryEmail(),
'salaryStart' => $this->getMinSalary(),
'salaryEnd' => $this->getMaxSalary(),
'sharePicture' => $this->getPicture(),
'additionalLogo' => $this->getLogo(),
'latitude' => $this->getLatitude(),
'longitude' => $this->getLongitude(),
'publishedAt' => $this->getPublishedAt(),
];
}
}