<?php
namespace App\Entity;
use App\Config;
use App\Repository\SocietyRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\String\Slugger\AsciiSlugger;
/**
* @ORM\Entity(repositoryClass=SocietyRepository::class)
*/
class Society
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $siren;
/**
* @ORM\OneToOne(targetEntity=User::class, inversedBy="society", cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $type;
/**
* @ORM\Column(type="json")
*/
private $employe_number = [];
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $ca;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $contact;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $site;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $linkedin;
/**
* @ORM\OneToMany(targetEntity=Offer::class, mappedBy="society")
* @ORM\OrderBy({"id" = "DESC"})
*/
private $offers;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $profileView;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $canUpload;
/**
* @ORM\Column(type="integer")
*/
private $intercontratNumber = 0;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $package;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $packageDate;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $priorizeNumber;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $onceEveryday;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $onceWeek;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $pauseDate;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $packageExpireAt;
/**
* @ORM\OneToMany(targetEntity=Commande::class, mappedBy="society")
* @ORM\OrderBy({"id" = "DESC"})
*/
private $commandes;
/**
* @ORM\OneToMany(targetEntity=ProfileVisit::class, mappedBy="society")
* @ORM\OrderBy({"id" = "DESC"})
*/
private $profileVisits;
/**
* @ORM\OneToMany(targetEntity=Annonce::class, mappedBy="society", orphanRemoval=true)
*/
private $annonces;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\Column(type="string", length=150, nullable=true)
*/
private $adress;
/**
* @ORM\Column(type="string", length=150)
*/
private $ville;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $pauseNumber;
/**
* @ORM\OneToMany(targetEntity=AnnonceVisit::class, mappedBy="society", orphanRemoval=true)
*/
private $annonceVisits;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $intercontratUne;
/**
* @ORM\OneToMany(targetEntity=CompteRecrutement::class, mappedBy="societe")
*/
private $compteRecrutements;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $twitter;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $instagram;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $facebook;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $presentationYoutube;
/**
* @ORM\Column(type="string", length=150, nullable=true)
*/
private $slug;
public function __construct()
{
$this->offers = new ArrayCollection();
$this->commandes = new ArrayCollection();
$this->profileVisits = new ArrayCollection();
$this->annonces = new ArrayCollection();
$this->annonceVisits = new ArrayCollection();
$this->compteRecrutements = new ArrayCollection();
}
//----------------------------------------------------
public function packageIsTest(): ?bool {
$commandes = $this->getCommandes();
if(! empty($commandes)){
$lastdate = null;
$cm = null;
foreach ($commandes as $commande){
if (! $lastdate){
$lastdate = $commande->getCreatedAt();
}
if ($lastdate <= $commande->getCreatedAt()){
$cm = $commande;
$lastdate = $commande->getCreatedAt();
}
}
if($cm){
return $cm->isIsTest();
}
}
return false;
}
public function packageActive(): ?Commande{
$commandes = $this->getCommandes();
$commandeEncours = [];
if(! empty($commandes)){
foreach ($commandes as $commande){
if($commande->getEndDate() > new \DateTime()){
$commandeEncours[] = $commande;
}
}
}
if(! empty($commandeEncours)){
$lastdate = null;
$cmEnCour = null;
foreach ($commandeEncours as $commande){
if (! $lastdate){
$lastdate = $commande->getCreatedAt();
}
if ($lastdate >= $commande->getCreatedAt()){
$cmEnCour = $commande;
$lastdate = $commande->getCreatedAt();
}
}
return $cmEnCour;
}
return null;
}
public function updateSlug(){
$slugger = new AsciiSlugger();
$defaultNum = 10000;
$numero = $defaultNum + $this->getId();
$slug = strtolower($slugger->slug($numero.'-'.$this->getName()));
$this->setSlug($slug);
}
//----------------------------------------------------
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSiren(): ?string
{
return $this->siren;
}
public function setSiren(?string $siren): self
{
$this->siren = $siren;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(User $user): self
{
$this->user = $user;
return $this;
}
public function getEmployeNumber(): ?array
{
return $this->employe_number;
}
public function setEmployeNumber(array $employe_number): self
{
$this->employe_number = $employe_number;
return $this;
}
public function getContact(): ?string
{
return $this->contact;
}
public function setContact(?string $contact): self
{
$this->contact = $contact;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getSite(): ?string
{
return $this->site;
}
public function setSite(?string $site): self
{
$this->site = $site;
return $this;
}
public function getLinkedin(): ?string
{
return $this->linkedin;
}
public function setLinkedin(?string $linkedin): self
{
$this->linkedin = $linkedin;
return $this;
}
/**
* @return Collection|Offer[]
*/
public function getOffers(): Collection
{
return $this->offers;
}
public function addOffer(Offer $offer): self
{
if (!$this->offers->contains($offer)) {
$this->offers[] = $offer;
$offer->setSociety($this);
}
return $this;
}
public function removeOffer(Offer $offer): self
{
if ($this->offers->removeElement($offer)) {
// set the owning side to null (unless already changed)
if ($offer->getSociety() === $this) {
$offer->setSociety(null);
}
}
return $this;
}
public function getProfileView(): ?int
{
return $this->profileView;
}
public function setProfileView(?int $profileView): self
{
$this->profileView = $profileView;
return $this;
}
public function getCanUpload(): ?bool
{
return $this->canUpload;
}
public function setCanUpload(?bool $canUpload): self
{
$this->canUpload = $canUpload;
return $this;
}
public function getIntercontratNumber(): ?int
{
return $this->intercontratNumber;
}
public function setIntercontratNumber(int $intercontratNumber): self
{
$this->intercontratNumber = $intercontratNumber;
return $this;
}
public function getPackage(): ?string
{
return $this->package;
}
public function setPackage(?string $package): self
{
$this->package = $package;
return $this;
}
public function getPackageDate(): ?\DateTimeInterface
{
return $this->packageDate;
}
public function setPackageDate(?\DateTimeInterface $packageDate): self
{
$this->packageDate = $packageDate;
return $this;
}
public function getPriorizeNumber(): ?int
{
return $this->priorizeNumber;
}
public function setPriorizeNumber(?int $priorizeNumber): self
{
$this->priorizeNumber = $priorizeNumber;
return $this;
}
public function getOnceEveryday(): ?int
{
return $this->onceEveryday;
}
public function setOnceEveryday(?int $onceEveryday): self
{
$this->onceEveryday = $onceEveryday;
return $this;
}
public function getOnceWeek(): ?int
{
return $this->onceWeek;
}
public function setOnceWeek(?int $onceWeek): self
{
$this->onceWeek = $onceWeek;
return $this;
}
public function getPauseDate(): ?\DateTimeInterface
{
return $this->pauseDate;
}
public function setPauseDate(?\DateTimeInterface $pauseDate): self
{
$this->pauseDate = $pauseDate;
return $this;
}
public function getPackageExpireAt(): ?\DateTime
{
return $this->packageExpireAt;
}
public function setPackageExpireAt(?\DateTime $packageExpireAt): self
{
$this->packageExpireAt = $packageExpireAt;
return $this;
}
/**
* @return Collection|Commande[]
*/
public function getCommandes(): Collection
{
return $this->commandes;
}
public function addCommande(Commande $commande): self
{
if (!$this->commandes->contains($commande)) {
$this->commandes[] = $commande;
$commande->setSociety($this);
}
return $this;
}
public function removeCommande(Commande $commande): self
{
if ($this->commandes->removeElement($commande)) {
// set the owning side to null (unless already changed)
if ($commande->getSociety() === $this) {
$commande->setSociety(null);
}
}
return $this;
}
public function canViewProfile(): bool
{
return $this->profileView > 0;
}
public function canAddIntercontrat(): bool
{
return $this->intercontratNumber > 0 || $this->intercontratNumber === -1;
}
public function decreaseProfileView()
{
$this->profileView--;
}
/**
* @return Collection|ProfileVisit[]
*/
public function getProfileVisits(): Collection
{
return $this->profileVisits;
}
public function addProfileVisit(ProfileVisit $profileVisit): self
{
if (!$this->profileVisits->contains($profileVisit)) {
$this->profileVisits[] = $profileVisit;
$profileVisit->setSociety($this);
}
return $this;
}
public function removeProfileVisit(ProfileVisit $profileVisit): self
{
if ($this->profileVisits->removeElement($profileVisit)) {
// set the owning side to null (unless already changed)
if ($profileVisit->getSociety() === $this) {
$profileVisit->setSociety(null);
}
}
return $this;
}
public function packageString()
{
return empty($this->package) ? 'Aucun' : Config::PACKAGE_LIST[$this->package]['name'];
}
/**
* @return Collection|Annonce[]
*/
public function getAnnonces(): Collection
{
return $this->annonces;
}
public function addAnnonce(Annonce $annonce): self
{
if (!$this->annonces->contains($annonce)) {
$this->annonces[] = $annonce;
$annonce->setSociety($this);
}
return $this;
}
public function removeAnnonce(Annonce $annonce): self
{
if ($this->annonces->removeElement($annonce)) {
// set the owning side to null (unless already changed)
if ($annonce->getSociety() === $this) {
$annonce->setSociety(null);
}
}
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getVille(): ?string
{
return $this->ville;
}
public function setVille(string $ville): self
{
$this->ville = $ville;
return $this;
}
public function getPauseNumber(): ?int
{
return $this->pauseNumber;
}
public function setPauseNumber(?int $pauseNumber): self
{
$this->pauseNumber = $pauseNumber;
return $this;
}
public function decreasePauseNumber(): self
{
$this->pauseNumber = $this->pauseNumber - 1;
return $this;
}
public function isPaused(): bool
{
return $this->pauseDate > new \DateTime();
}
public function hasActivePackage(): bool
{
return $this->getPackage() != null && ! $this->hasExpiredPackage();
}
public function hasExpiredPackage(): bool
{
return $this->getPackageExpireAt() < new \DateTime();
}
/**
* @return Collection|AnnonceVisit[]
*/
public function getAnnonceVisits(): Collection
{
return $this->annonceVisits;
}
public function addAnnonceVisit(AnnonceVisit $annonceVisit): self
{
if (!$this->annonceVisits->contains($annonceVisit)) {
$this->annonceVisits[] = $annonceVisit;
$annonceVisit->setSociety($this);
}
return $this;
}
public function removeAnnonceVisit(AnnonceVisit $annonceVisit): self
{
if ($this->annonceVisits->removeElement($annonceVisit)) {
// set the owning side to null (unless already changed)
if ($annonceVisit->getSociety() === $this) {
$annonceVisit->setSociety(null);
}
}
return $this;
}
public function getPackageName()
{
return Config::PACKAGE_LIST[$this->package]['name'];
}
public function getIntercontratUne(): ?int
{
return $this->intercontratUne ?? 0;
}
public function setIntercontratUne(?int $intercontratUne): self
{
$this->intercontratUne = $intercontratUne;
return $this;
}
public function isCanUpload(): ?bool
{
return $this->canUpload;
}
public function getCa(): ?int
{
return $this->ca;
}
public function setCa(?int $ca): self
{
$this->ca = $ca;
return $this;
}
public function getAdress(): ?string
{
return $this->adress;
}
public function setAdress(?string $adress): self
{
$this->adress = $adress;
return $this;
}
/**
* @return Collection<int, CompteRecrutement>
*/
public function getCompteRecrutements(): Collection
{
return $this->compteRecrutements;
}
public function addCompteRecrutement(CompteRecrutement $compteRecrutement): self
{
if (!$this->compteRecrutements->contains($compteRecrutement)) {
$this->compteRecrutements[] = $compteRecrutement;
$compteRecrutement->setSociete($this);
}
return $this;
}
public function removeCompteRecrutement(CompteRecrutement $compteRecrutement): self
{
if ($this->compteRecrutements->removeElement($compteRecrutement)) {
// set the owning side to null (unless already changed)
if ($compteRecrutement->getSociete() === $this) {
$compteRecrutement->setSociete(null);
}
}
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getTwitter(): ?string
{
return $this->twitter;
}
public function setTwitter(?string $twitter): self
{
$this->twitter = $twitter;
return $this;
}
public function getInstagram(): ?string
{
return $this->instagram;
}
public function setInstagram(?string $instagram): self
{
$this->instagram = $instagram;
return $this;
}
public function getFacebook(): ?string
{
return $this->facebook;
}
public function setFacebook(?string $facebook): self
{
$this->facebook = $facebook;
return $this;
}
public function getPresentationYoutube(): ?string
{
return $this->presentationYoutube;
}
public function setPresentationYoutube(?string $presentationYoutube): self
{
$this->presentationYoutube = $presentationYoutube;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
}