<?php
namespace App\Entity;
use App\Repository\OfferRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\String\Slugger\AsciiSlugger;
/**
* @ORM\Entity(repositoryClass=OfferRepository::class)
* @ORM\HasLifecycleCallbacks()
*/
class Offer implements NormalizableInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
public $id;
/**
* @ORM\Column(type="string", length=255)
*/
public $title;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $min_tjm;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $max_tjm;
/**
* @ORM\Column(type="boolean")
*/
public $open_society = true;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $location;
/**
* @ORM\Column(type="text", nullable=true)
*/
public $description;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $duration_value;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $duration_type;
/**
* @ORM\Column(type="string", length=255)
*/
private $mode_remote = "Non";
/**
* @ORM\Column(type="string", length=255)
*/
private $year_required;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $show_coordinate;
/**
* @ORM\ManyToOne(targetEntity=Society::class, inversedBy="offers")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*/
private $society;
/**
* @ORM\Column(type="boolean")
*/
private $renew;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $created_at;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $expire_at;
/**
* @ORM\Column(type="string", length=5, nullable=true)
*/
private $contact_civility;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $contact_mail;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $contact_phone;
/**
* @ORM\Column(type="string", length=10, nullable=true)
*/
private $starting_type;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $startin_date;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $contact_name;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $questions = [];
/**
* @ORM\OneToMany(targetEntity=Candidature::class, mappedBy="offer")
*/
private $candidatures;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $view = 0;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $unseenCandidature = 0;
/**
* @ORM\OneToMany(targetEntity=OfferFavorite::class, mappedBy="offer", orphanRemoval=true)
*/
private $offerFavorites;
/**
* @ORM\Column(type="string", length=155, nullable=true)
*/
private $ville;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
public $priorize;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
public $weekly;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
public $daily;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $userRecruteur;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $civility;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $typeSearch;
/**
* @ORM\Column(type="integer", nullable=true)
*/
public $salaryPerMonthMin;
/**
* @ORM\Column(type="integer", nullable=true)
*/
public $salaryPerMonthMax;
/**
* @ORM\Column(type="integer", nullable=true)
*/
public $salaryPerHourMin;
/**
* @ORM\Column(type="integer", nullable=true)
*/
public $salaryPerHourMax;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $societyExternName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $linkExtern;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
public $notDraft = true;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $dateRemonter;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $shareOnSocialNetwork = false;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $bySuperAdmin = false;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=true)
*/
private ?User $userByAdmin = null;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
public $siteMapIndex = true;
/**
* @ORM\Column(type="string", length=150, nullable=true)
*/
private $slug = null;
public function __construct()
{
$this->candidatures = new ArrayCollection();
$this->offerFavorites = new ArrayCollection();
$this->typeSearch = "Full-time";
}
// ----------------------------------------------------------------
public function updateSlug(){
$slugger = new AsciiSlugger();
$defaultNum = 10000;
$numero = $defaultNum + $this->getId();
$slug = strtolower($slugger->slug($numero.'-'.$this->getTitle()));
$this->setSlug($slug);
}
public function getSalaryPeerMonthText(){
if(empty($this->salaryPerMonthMin) && empty($this->salaryPerMonthMax)){
return 'Depending on profile';
}
if(empty($this->salaryPerMonthMin)){
return 'Max '.$this->salaryPerMonthMax.' AED';
}
if(empty($this->salaryPerMonthMax)){
return 'Min '.$this->salaryPerMonthMin.' AED';
}
return $this->salaryPerMonthMin.' - '.$this->salaryPerMonthMax.' AED';
}
public function getSalaryPeerHourText(){
if(empty($this->salaryPerHourMin) && empty($this->salaryPerHourMax)){
return 'Depending on profile';
}
if(empty($this->salaryPerHourMin)){
return 'Max '.$this->salaryPerHourMax.' AED';
}
if(empty($this->salaryPerHourMax)){
return 'Min '.$this->salaryPerHourMin.' AED';
}
return $this->salaryPerHourMin.' - '.$this->salaryPerHourMax.' AED';
}
public function getTimeCreateString() {
$date = $this->created_at;
$today = new \DateTime();
$interval = $today->diff($date);
if ($interval->days == 0) {
return 'Posted today';
} elseif ($interval->days == 1) {
return 'Posted 1 day ago';
} elseif ($interval->days >= 2 && $interval->days <= 6) {
return 'Posted ' . $interval->days . ' days ago';
} else {
return 'Posted on ' . $date->format('j M');
}
}
/**
* @ORM\PrePersist
*/
public function setCreatedAtAutomatically()
{
if ($this->getCreatedAt() === null) {
$this->setCreatedAt(new \DateTime());
}
if ($this->expire_at === null){
$expire = (new \DateTime())->add(new \DateInterval('P6M'));
$this->setExpireAt($expire);
}
}
// -----------------------------------------------------------------
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getMinTjm(): ?int
{
return $this->min_tjm;
}
public function setMinTjm(?int $min_tjm): self
{
$this->min_tjm = $min_tjm;
return $this;
}
public function getMaxTjm(): ?int
{
return $this->max_tjm;
}
public function setMaxTjm(?int $max_tjm): self
{
$this->max_tjm = $max_tjm;
return $this;
}
public function getOpenSociety(): ?bool
{
return $this->open_society;
}
public function setOpenSociety(bool $open_society): self
{
$this->open_society = $open_society;
return $this;
}
public function getLocation(): ?string
{
return $this->location;
}
public function setLocation(?string $location): self
{
$this->location = $location;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getModeRemote(): ?string
{
return $this->mode_remote;
}
public function setModeRemote(string $mode_remote): self
{
$this->mode_remote = $mode_remote;
return $this;
}
public function getYearRequired(): ?string
{
return $this->year_required;
}
public function setYearRequired(string $year_required): self
{
$this->year_required = $year_required;
return $this;
}
public function getShowCoordinate(): ?bool
{
return $this->show_coordinate;
}
public function setShowCoordinate(?bool $show_coordinate): self
{
$this->show_coordinate = $show_coordinate;
return $this;
}
public function getRenew(): ?bool
{
return $this->renew;
}
public function setRenew(bool $renew): self
{
$this->renew = $renew;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(?\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getExpireAt(): ?\DateTimeInterface
{
return $this->expire_at;
}
public function setExpireAt(?\DateTimeInterface $expire_at): self
{
$this->expire_at = $expire_at;
return $this;
}
public function getCostText(): string
{
if(empty($this->max_tjm) && empty($this->min_tjm)){
return 'Selon profil';
}
if(empty($this->min_tjm)){
return 'Max '.$this->max_tjm.'€ HT';
}
if(empty($this->max_tjm)){
return 'Min '.$this->min_tjm.'€ HT';
}
return $this->min_tjm.'€'.' - '.$this->max_tjm.'€ HT';
}
public function getDurationText(): string
{
$ending = ($this->duration_type === 'an' && $this->duration_value > 1) ? 's' : '';
return $this->duration_value.' '.$this->duration_type. $ending;
}
public function getContactCivility(): ?string
{
return $this->contact_civility;
}
public function setContactCivility(?string $contact_civility): self
{
$this->contact_civility = $contact_civility;
return $this;
}
public function getContactMail(): ?string
{
return $this->contact_mail;
}
public function setContactMail(?string $contact_mail): self
{
$this->contact_mail = $contact_mail;
return $this;
}
public function getContactPhone(): ?string
{
return $this->contact_phone;
}
public function setContactPhone(?string $contact_phone): self
{
$this->contact_phone = $contact_phone;
return $this;
}
public function getContactName(): ?string
{
return $this->contact_name;
}
public function setContactName(?string $contact_name): self
{
$this->contact_name = $contact_name;
return $this;
}
public function getQuestions(): ?array
{
return $this->questions;
}
public function setQuestions(?array $questions): self
{
if(is_array($questions)){
foreach($questions as $key => $question){
if(empty($question)){
unset($questions[$key]);
}
}
}
$this->questions = $questions;
return $this;
}
/**
* @return Collection|Candidature[]
*/
public function getCandidatures(): Collection
{
return $this->candidatures;
}
public function addCandidature(Candidature $candidature): self
{
if (!$this->candidatures->contains($candidature)) {
$this->candidatures[] = $candidature;
$candidature->setOffer($this);
}
return $this;
}
public function removeCandidature(Candidature $candidature): self
{
if ($this->candidatures->removeElement($candidature)) {
// set the owning side to null (unless already changed)
if ($candidature->getOffer() === $this) {
$candidature->setOffer(null);
}
}
return $this;
}
public function getView(): ?int
{
return $this->view ?? 0;
}
public function setView(?int $view): self
{
$this->view = $view;
return $this;
}
public function incrementView(): self
{
$this->view++;
return $this;
}
public function getUnseenCandidature(): ?int
{
return $this->unseenCandidature ?? 0;
}
public function setUnseenCandidature(?int $unseenCandidature): self
{
$this->unseenCandidature = $unseenCandidature;
return $this;
}
public function incrementUnseenCandidature(): self
{
$this->unseenCandidature++;
return $this;
}
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []): array
{
return [
'title' => $this->getTitle(),
'cost_min' => $this->getMinTjm(),
'cost_max' => $this->getMaxTjm(),
'location' => $this->getLocation(),
'created_at' => $this->getCreatedAt(),
'expire_at' => $this->getExpireAt(),
'description' => $this->getDescription(),
'mode_remote' => $this->getModeRemote(),
'timestamp_create' => $this->getCreatedAt()->getTimestamp(),
'priorize' => $this->getPriorize(),
'daily' => $this->getDaily(),
'weekly' => $this->getWeekly(),
'identification' => $this->getId(),
];
}
/**
* @return Collection|OfferFavorite[]
*/
public function getOfferFavorites(): Collection
{
return $this->offerFavorites;
}
public function addOfferFavorite(OfferFavorite $offerFavorite): self
{
if (!$this->offerFavorites->contains($offerFavorite)) {
$this->offerFavorites[] = $offerFavorite;
$offerFavorite->setOffer($this);
}
return $this;
}
public function removeOfferFavorite(OfferFavorite $offerFavorite): self
{
if ($this->offerFavorites->removeElement($offerFavorite)) {
// set the owning side to null (unless already changed)
if ($offerFavorite->getOffer() === $this) {
$offerFavorite->setOffer(null);
}
}
return $this;
}
public function getVille(): ?string
{
return $this->ville;
}
public function setVille(?string $ville): self
{
$this->ville = $ville;
return $this;
}
public function getAddress(): ?string
{
return empty($this->ville) ? $this->location : $this->ville;
}
public function getPriorize(): ?bool
{
return $this->priorize;
}
public function setPriorize(?bool $priorize): self
{
$this->priorize = $priorize;
return $this;
}
public function getWeekly(): ?bool
{
return $this->weekly;
}
public function setWeekly(?bool $weekly): self
{
$this->weekly = $weekly;
return $this;
}
public function getDaily(): ?bool
{
return $this->daily;
}
public function setDaily(?bool $daily): self
{
$this->daily = $daily;
return $this;
}
public function isToday(): bool
{
$date = new \DateTime();
$matchDate = $this->getCreatedAt();
$interval = $date->diff($matchDate);
return $interval->days == 0;
}
public function isOpenSociety(): ?bool
{
return $this->open_society;
}
public function isShowCoordinate(): ?bool
{
return $this->show_coordinate;
}
public function isRenew(): ?bool
{
return $this->renew;
}
public function isPriorize(): ?bool
{
return $this->priorize;
}
public function isWeekly(): ?bool
{
return $this->weekly;
}
public function isDaily(): ?bool
{
return $this->daily;
}
public function getUserRecruteur(): ?User
{
return $this->userRecruteur;
}
public function setUserRecruteur(?User $userRecruteur): self
{
$this->userRecruteur = $userRecruteur;
return $this;
}
public function getCivility(): ?int
{
return $this->civility;
}
public function setCivility(?int $civility): self
{
$this->civility = $civility;
return $this;
}
public function getTypeSearch(): ?string
{
return $this->typeSearch;
}
public function setTypeSearch(?string $typeSearch): self
{
$this->typeSearch = $typeSearch;
return $this;
}
public function getSalaryPerMonthMin(): ?int
{
return $this->salaryPerMonthMin;
}
public function setSalaryPerMonthMin(?int $salaryPerMonthMin): self
{
$this->salaryPerMonthMin = $salaryPerMonthMin;
return $this;
}
public function getSalaryPerMonthMax(): ?int
{
return $this->salaryPerMonthMax;
}
public function setSalaryPerMonthMax(?int $salaryPerMonthMax): self
{
$this->salaryPerMonthMax = $salaryPerMonthMax;
return $this;
}
public function getSalaryPerHourMin(): ?int
{
return $this->salaryPerHourMin;
}
public function setSalaryPerHourMin(?int $salaryPerHourMin): self
{
$this->salaryPerHourMin = $salaryPerHourMin;
return $this;
}
public function getSalaryPerHourMax(): ?int
{
return $this->salaryPerHourMax;
}
public function setSalaryPerHourMax(?int $salaryPerHourMax): self
{
$this->salaryPerHourMax = $salaryPerHourMax;
return $this;
}
public function getDurationValue(): ?int
{
return $this->duration_value;
}
public function setDurationValue(?int $duration_value): self
{
$this->duration_value = $duration_value;
return $this;
}
public function getDurationType(): ?string
{
return $this->duration_type;
}
public function setDurationType(?string $duration_type): self
{
$this->duration_type = $duration_type;
return $this;
}
public function getStartingType(): ?string
{
return $this->starting_type;
}
public function setStartingType(?string $starting_type): self
{
$this->starting_type = $starting_type;
return $this;
}
public function getStartinDate(): ?\DateTimeInterface
{
return $this->startin_date;
}
public function setStartinDate(?\DateTimeInterface $startin_date): self
{
$this->startin_date = $startin_date;
return $this;
}
public function getSociety(): ?Society
{
return $this->society;
}
public function setSociety(?Society $society): self
{
$this->society = $society;
return $this;
}
public function getSocietyExternName(): ?string
{
return $this->societyExternName;
}
public function setSocietyExternName(?string $societyExternName): self
{
$this->societyExternName = $societyExternName;
return $this;
}
public function getLinkExtern(): ?string
{
return $this->linkExtern;
}
public function setLinkExtern(?string $linkExtern): self
{
$this->linkExtern = $linkExtern;
return $this;
}
public function getDateRemonter(): ?\DateTimeInterface
{
return $this->dateRemonter;
}
public function setDateRemonter(?\DateTimeInterface $dateRemonter): self
{
$this->dateRemonter = $dateRemonter;
return $this;
}
public function isNotDraft(): ?bool
{
return $this->notDraft;
}
public function setNotDraft(?bool $notDraft): self
{
$this->notDraft = $notDraft;
return $this;
}
public function isShareOnSocialNetwork(): ?bool
{
return $this->shareOnSocialNetwork;
}
public function setShareOnSocialNetwork(?bool $shareOnSocialNetwork): self
{
$this->shareOnSocialNetwork = $shareOnSocialNetwork;
return $this;
}
public function isBySuperAdmin(): ?bool
{
return $this->bySuperAdmin;
}
public function setBySuperAdmin(?bool $bySuperAdmin): self
{
$this->bySuperAdmin = $bySuperAdmin;
return $this;
}
public function isSiteMapIndex(): ?bool
{
return $this->siteMapIndex;
}
public function setSiteMapIndex(?bool $siteMapIndex): self
{
$this->siteMapIndex = $siteMapIndex;
return $this;
}
public function getUserByAdmin(): ?User
{
return $this->userByAdmin;
}
public function setUserByAdmin(?User $userByAdmin): self
{
$this->userByAdmin = $userByAdmin;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
}