<?php
namespace App\Entity;
use App\Entity\Enum\ContratType;
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)
*/
private $location;
/**
* @ORM\Column(type="text")
*/
public $description;
/**
* @ORM\Column(type="integer")
*/
private $duration_value;
/**
* @ORM\Column(type="string", length=255)
*/
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", cascade={"persist"})
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*/
private $society;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $editedByAdmin;
// getter et setter pour le champ editedByAdmin
public function getEditedByAdmin(): ?bool
{
return $this->editedByAdmin;
}
public function setEditedByAdmin(?bool $editedByAdmin): self
{
$this->editedByAdmin = $editedByAdmin;
return $this;
}
/**
* @return mixed
*/
public function getUser()
{
return $this->user;
}
/**
* @param mixed $user
*/
public function setUser($user): void
{
$this->user = $user;
}
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="offers")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*/
private $user;
/**
* @ORM\Column(type="boolean")
*/
private $renew;
/**
* @ORM\Column(type="integer",nullable=true)
*/
private $invalid;
/**
* @return mixed
*/
public function getInvalid()
{
return $this->invalid;
}
/**
* @param mixed $invalid
*/
public function setInvalid($invalid): void
{
$this->invalid = $invalid;
}
/**
* @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)
*/
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="datetime", nullable=true)
*/
private $dateRemonter;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $checkLinkExtern;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $linkExtern;
/**
* @ORM\Column(type="string", length=9, nullable=true)
*/
private $siren;
/**
* @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="string", length=150, nullable=true)
*/
private $slug = null;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
public $siteMapIndex = true;
/**
* @ORM\OneToMany(targetEntity=OfferVisit::class, mappedBy="offer", orphanRemoval=true)
*/
private $offerVisits;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $cdi;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $montantMin;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $reasonRejection;
/**
* @ORM\Column(type="json", nullable=true)
*/
private ?array $contrats = []; // Stocke plusieurs contrats en tant que tableau
public function getContrats(): ?array
{
return $this->contrats;
}
public function setContrats(?array $contrats): self
{
$this->contrats = $contrats; // Le tableau de valeurs
return $this;
}
/**
* @return mixed
*/
public function getReasonRejection()
{
return $this->reasonRejection;
}
/**
* @param mixed $reasonRejection
*/
public function setReasonRejection($reasonRejection): void
{
$this->reasonRejection = $reasonRejection;
}
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $montantMax;
/**
* @return mixed
*/
public function getCdi()
{
return $this->cdi;
}
/**
* @param mixed $cdi
*/
public function setCdi($cdi): void
{
$this->cdi = $cdi;
}
/**
* @return mixed
*/
public function getMontantMin()
{
return $this->montantMin;
}
/**
* @param mixed $montantMin
*/
public function setMontantMin($montantMin): void
{
$this->montantMin = $montantMin;
}
/**
* @return mixed
*/
public function getMontantMax()
{
return $this->montantMax;
}
/**
* @param mixed $montantMax
*/
public function setMontantMax($montantMax): void
{
$this->montantMax = $montantMax;
}
public function __construct()
{
$this->candidatures = new ArrayCollection();
$this->offerFavorites = new ArrayCollection();
$this->offerVisits = new ArrayCollection();
}
//---------------------------------------------------------------
public function updateSlug()
{
$slugger = new AsciiSlugger();
$defaultNum = 10000;
$numero = $defaultNum + $this->getId();
$slug = strtolower($slugger->slug($this->getTitle() . '-' . $numero));
$this->setSlug($slug);
}
public function getCodePostal(): ?string
{
if ($this->ville) {
$villeCP = explode(' ', $this->getVille());
$cp = $villeCP[0];
if (strlen($cp) === 5 && ctype_digit($cp)) {
return $cp;
}
}
return null;
}
//---------------------------------------------------------------
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 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 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 getSociety(): ?Society
{
return $this->society;
}
public function setSociety(?Society $society): self
{
$this->society = $society;
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;
}
/**
* @ORM\PrePersist
*/
public function setCreatedAtAutomatically()
{
if ($this->getCreatedAt() === null) {
$this->setCreatedAt(new \DateTime());
}
if ($this->getLinkExtern() !== null or $this->user !== null) {
$expire = (new \DateTime())->add(new \DateInterval('P2M'));
} else {
$expire = (new \DateTime())->add(new \DateInterval('P6M'));
}
$this->setExpireAt($expire);
}
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';
}
// Affiche une seule valeur si min = max
if ($this->min_tjm == $this->max_tjm) {
return $this->min_tjm . '€ HT';
}
return $this->min_tjm . ' - ' . $this->max_tjm . '€ HT';
}
public function getCostTextCdi(): string
{
if (empty($this->montantMax) && empty($this->montantMin)) {
return 'Selon profil';
}
if (empty($this->montantMin)) {
return 'Max ' . $this->formatK($this->montantMax) . '€ annuel';
}
if (empty($this->montantMax)) {
return 'Min ' . $this->formatMin($this->montantMin) . '€ annuel';
}
// Affiche une seule valeur si min = max
if ($this->montantMin == $this->montantMax) {
return $this->formatK($this->montantMin) . '€ annuel';
}
return $this->formatMin($this->montantMin) . ' - ' . $this->formatK($this->montantMax) . '€ annuel';
}
/**
* Formate un nombre en ajoutant 'K' si >= 1000 (uniquement pour le max)
*/
private function formatK(int $amount): string
{
return ($amount >= 1000) ? ($amount / 1000) . 'K' : (string)$amount;
}
/**
* Formate le min en supprimant les milliers inutiles
*/
private function formatMin(int $amount): string
{
return ($amount >= 1000) ? (string)($amount / 1000) : (string)$amount;
}
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 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 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 getDateRemonter(): ?\DateTimeInterface
{
return $this->dateRemonter;
}
public function setDateRemonter(?\DateTimeInterface $dateRemonter): Offer
{
$this->dateRemonter = $dateRemonter;
return $this;
}
public function isCheckLinkExtern(): ?bool
{
return $this->checkLinkExtern;
}
public function setCheckLinkExtern(?bool $checkLinkExtern): self
{
$this->checkLinkExtern = $checkLinkExtern;
return $this;
}
public function getLinkExtern(): ?string
{
return $this->linkExtern;
}
public function setLinkExtern(?string $linkExtern): self
{
$this->linkExtern = $linkExtern;
return $this;
}
public function getSiren(): ?string
{
return $this->siren;
}
public function setSiren(?string $siren): self
{
$this->siren = $siren;
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 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;
}
/**
* @return Collection<int, OfferVisit>
*/
public function getOfferVisits(): Collection
{
return $this->offerVisits;
}
public function addOfferVisit(OfferVisit $offerVisit): self
{
if (!$this->offerVisits->contains($offerVisit)) {
$this->offerVisits->add($offerVisit);
$offerVisit->setOffer($this);
}
return $this;
}
public function removeOfferVisit(OfferVisit $offerVisit): self
{
if ($this->offerVisits->removeElement($offerVisit)) {
// set the owning side to null (unless already changed)
if ($offerVisit->getOffer() === $this) {
$offerVisit->setOffer(null);
}
}
return $this;
}
public function isSiteMapIndex(): ?bool
{
return $this->siteMapIndex;
}
public function setSiteMapIndex(?bool $siteMapIndex): self
{
$this->siteMapIndex = $siteMapIndex;
return $this;
}
}