src/Entity/Society.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Config;
  4. use App\Repository\SocietyRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\String\Slugger\AsciiSlugger;
  10. /**
  11.  * @ORM\Entity(repositoryClass=SocietyRepository::class)
  12.  */
  13. class Society
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="string", length=255)
  23.      */
  24.     private $name;
  25.     /**
  26.      * @ORM\Column(type="string", length=255, nullable=true)
  27.      */
  28.     private $siren;
  29.     /**
  30.      * @ORM\OneToOne(targetEntity=User::class, inversedBy="society", cascade={"persist", "remove"})
  31.      * @ORM\JoinColumn(nullable=false)
  32.      */
  33.     private $user;
  34.     /**
  35.      * @ORM\Column(type="string", length=255)
  36.      */
  37.     private $type;
  38.     /**
  39.      * @ORM\Column(type="json")
  40.      */
  41.     private $employe_number = [];
  42.     /**
  43.      * @ORM\Column(type="integer", nullable=true)
  44.      */
  45.     private $ca;
  46.     /**
  47.      * @ORM\Column(type="string", length=255, nullable=true)
  48.      */
  49.     private $contact;
  50.     /**
  51.      * @ORM\Column(type="string", length=255, nullable=true)
  52.      */
  53.     private $phone;
  54.     /**
  55.      * @ORM\Column(type="string", length=255, nullable=true)
  56.      */
  57.     private $site;
  58.     /**
  59.      * @ORM\Column(type="string", length=255, nullable=true)
  60.      */
  61.     private $linkedin;
  62.     /**
  63.      * @ORM\OneToMany(targetEntity=Offer::class, mappedBy="society")
  64.      * @ORM\OrderBy({"id" = "DESC"})
  65.      */
  66.     private $offers;
  67.     /**
  68.      * @ORM\Column(type="integer", nullable=true)
  69.      */
  70.     private $profileView;
  71.     /**
  72.      * @ORM\Column(type="boolean", nullable=true)
  73.      */
  74.     private $canUpload;
  75.     /**
  76.      * @ORM\Column(type="integer")
  77.      */
  78.     private $intercontratNumber 0;
  79.     /**
  80.      * @ORM\Column(type="string", length=255, nullable=true)
  81.      */
  82.     private $package;
  83.     /**
  84.      * @ORM\Column(type="datetime", nullable=true)
  85.      */
  86.     private $packageDate;
  87.     /**
  88.      * @ORM\Column(type="integer", nullable=true)
  89.      */
  90.     private $priorizeNumber;
  91.     /**
  92.      * @ORM\Column(type="integer", nullable=true)
  93.      */
  94.     private $onceEveryday;
  95.     /**
  96.      * @ORM\Column(type="integer", nullable=true)
  97.      */
  98.     private $onceWeek;
  99.     /**
  100.      * @ORM\Column(type="date", nullable=true)
  101.      */
  102.     private $pauseDate;
  103.     /**
  104.      * @ORM\Column(type="datetime", nullable=true)
  105.      */
  106.     private $packageExpireAt;
  107.     /**
  108.      * @ORM\OneToMany(targetEntity=Commande::class, mappedBy="society")
  109.      * @ORM\OrderBy({"id" = "DESC"})
  110.      */
  111.     private $commandes;
  112.     /**
  113.      * @ORM\OneToMany(targetEntity=ProfileVisit::class, mappedBy="society")
  114.      * @ORM\OrderBy({"id" = "DESC"})
  115.      */
  116.     private $profileVisits;
  117.     /**
  118.      * @ORM\OneToMany(targetEntity=Annonce::class, mappedBy="society", orphanRemoval=true)
  119.      */
  120.     private $annonces;
  121.     /**
  122.      * @ORM\Column(type="text", nullable=true)
  123.      */
  124.     private $description;
  125.     /**
  126.      * @ORM\Column(type="string", length=150, nullable=true)
  127.      */
  128.     private $adress;
  129.     /**
  130.      * @ORM\Column(type="string", length=150)
  131.      */
  132.     private $ville;
  133.     /**
  134.      * @ORM\Column(type="integer", nullable=true)
  135.      */
  136.     private $pauseNumber;
  137.     /**
  138.      * @ORM\OneToMany(targetEntity=AnnonceVisit::class, mappedBy="society", orphanRemoval=true)
  139.      */
  140.     private $annonceVisits;
  141.     /**
  142.      * @ORM\Column(type="integer", nullable=true)
  143.      */
  144.     private $intercontratUne;
  145.     /**
  146.      * @ORM\OneToMany(targetEntity=CompteRecrutement::class, mappedBy="societe")
  147.      */
  148.     private $compteRecrutements;
  149.     /**
  150.      * @ORM\Column(type="string", length=150, nullable=true)
  151.      */
  152.     private $slug null;
  153.     public function __construct()
  154.     {
  155.         $this->offers = new ArrayCollection();
  156.         $this->commandes = new ArrayCollection();
  157.         $this->profileVisits = new ArrayCollection();
  158.         $this->annonces = new ArrayCollection();
  159.         $this->annonceVisits = new ArrayCollection();
  160.         $this->compteRecrutements = new ArrayCollection();
  161.     }
  162.     /**
  163.      * @ORM\Column(type="integer", nullable=true)
  164.      */
  165.     private $nbMission;
  166.     /**
  167.      * @return mixed
  168.      */
  169.     public function getPostIntercontrat()
  170.     {
  171.         return $this->postIntercontrat;
  172.     }
  173.     /**
  174.      * @param mixed $postIntercontrat
  175.      */
  176.     public function setPostIntercontrat($postIntercontrat): void
  177.     {
  178.         $this->postIntercontrat $postIntercontrat;
  179.     }
  180.     /**
  181.      * @ORM\Column(type="string", length=150, nullable=true)
  182.      */
  183.     private $postIntercontrat;
  184.     /**
  185.      * @return mixed
  186.      */
  187.     public function getNbMission()
  188.     {
  189.         return $this->nbMission;
  190.     }
  191.     /**
  192.      * @param mixed $nbMission
  193.      */
  194.     public function setNbMission($nbMission): void
  195.     {
  196.         $this->nbMission $nbMission;
  197.     }
  198.     //----------------------------------------------------
  199.     public function packageIsTest(): ?bool {
  200.         $commandes $this->getCommandes();
  201.         if(count($commandes) > 0){
  202.             $lastdate null;
  203.             $cm null;
  204.             foreach ($commandes as $commande){
  205.                 if (! $lastdate){
  206.                     $lastdate $commande->getCreatedAt();
  207.                 }
  208.                 if ($lastdate <= $commande->getCreatedAt()){
  209.                     $cm $commande;
  210.                     $lastdate $commande->getCreatedAt();
  211.                 }
  212.             }
  213.             return $cm->isIsTest();
  214.         }
  215.         return false;
  216.     }
  217.     public function packageActive(): ?Commande{
  218.         $commandes $this->getCommandes();
  219.         $commandeEncours = [];
  220.         if(! empty($commandes)){
  221.             foreach ($commandes as $commande){
  222.                 if($commande->getEndDate() > new \DateTime()){
  223.                     $commandeEncours[] = $commande;
  224.                 }
  225.             }
  226.         }
  227.         if(! empty($commandeEncours)){
  228.             $lastdate null;
  229.             $cmEnCour null;
  230.             foreach ($commandeEncours as $commande){
  231.                 if (! $lastdate){
  232.                     $lastdate $commande->getCreatedAt();
  233.                 }
  234.                 if ($lastdate >= $commande->getCreatedAt()){
  235.                     $cmEnCour $commande;
  236.                     $lastdate $commande->getCreatedAt();
  237.                 }
  238.             }
  239.             return $cmEnCour;
  240.         }
  241.         return null;
  242.     }
  243.     private function domainName($url) {
  244.         // Supprimer le protocole (http, https, etc.)
  245.         $url preg_replace('#^https?://#'''$url);
  246.         // Obtenir le nom de domaine
  247.         $domain_parts explode('.'$url);
  248.         $num_parts count($domain_parts);
  249.         if ($num_parts >= 2) {
  250.             // Si le domaine a un sous-domaine (ex: sou.exemple.fr)
  251.             if ($num_parts && strlen($domain_parts[$num_parts 2]) <= 3) {
  252.                 $domain $domain_parts[$num_parts 3] . '.' $domain_parts[$num_parts 2] . '.' $domain_parts[$num_parts 1];
  253.             } else {
  254.                 // Si le domaine n'a pas de sous-domaine (ex: exemple.fr)
  255.                 $domain $domain_parts[$num_parts 2] . '.' $domain_parts[$num_parts 1];
  256.             }
  257.             return $domain;
  258.         } else {
  259.             // Si l'URL n'est pas valide ou ne contient pas de domaine
  260.             return null;
  261.         }
  262.     }
  263.     public function getDomainName(){
  264.         if (! $this->site){
  265.             return "";
  266.         }
  267.         return $this->domainName($this->site);
  268.     }
  269.     public function updateSlug(){
  270.         $slugger = new AsciiSlugger();
  271.         $defaultNum 10000;
  272.         $numero $defaultNum $this->getId();
  273.         $slug strtolower($slugger->slug($numero.'-'.$this->getName()));
  274.         $this->setSlug($slug);
  275.     }
  276.     //----------------------------------------------------
  277.     public function getId(): ?int
  278.     {
  279.         return $this->id;
  280.     }
  281.     public function getName(): ?string
  282.     {
  283.         return $this->name;
  284.     }
  285.     public function setName(string $name): self
  286.     {
  287.         $this->name $name;
  288.         return $this;
  289.     }
  290.     public function getSiren(): ?string
  291.     {
  292.         return $this->siren;
  293.     }
  294.     public function setSiren(?string $siren): self
  295.     {
  296.         $this->siren $siren;
  297.         return $this;
  298.     }
  299.     public function getUser(): ?User
  300.     {
  301.         return $this->user;
  302.     }
  303.     public function setUser(User $user): self
  304.     {
  305.         $this->user $user;
  306.         return $this;
  307.     }
  308.     public function getType(): ?string
  309.     {
  310.         return $this->type;
  311.     }
  312.     public function setType(string $type): self
  313.     {
  314.         $this->type $type;
  315.         return $this;
  316.     }
  317.     public function getEmployeNumber(): ?array
  318.     {
  319.         return $this->employe_number;
  320.     }
  321.     public function setEmployeNumber(array $employe_number): self
  322.     {
  323.         $this->employe_number $employe_number;
  324.         return $this;
  325.     }
  326.     public function getContact(): ?string
  327.     {
  328.         return $this->contact;
  329.     }
  330.     public function setContact(?string $contact): self
  331.     {
  332.         $this->contact $contact;
  333.         return $this;
  334.     }
  335.     public function getPhone(): ?string
  336.     {
  337.         return $this->phone;
  338.     }
  339.     public function setPhone(?string $phone): self
  340.     {
  341.         $this->phone $phone;
  342.         return $this;
  343.     }
  344.     public function getSite(): ?string
  345.     {
  346.         return $this->site;
  347.     }
  348.     public function setSite(?string $site): self
  349.     {
  350.         $this->site $site;
  351.         return $this;
  352.     }
  353.     public function getLinkedin(): ?string
  354.     {
  355.         return $this->linkedin;
  356.     }
  357.     public function setLinkedin(?string $linkedin): self
  358.     {
  359.         $this->linkedin $linkedin;
  360.         return $this;
  361.     }
  362.     /**
  363.      * @return Collection|Offer[]
  364.      */
  365.     public function getOffers(): Collection
  366.     {
  367.         return $this->offers;
  368.     }
  369.     public function addOffer(Offer $offer): self
  370.     {
  371.         if (!$this->offers->contains($offer)) {
  372.             $this->offers[] = $offer;
  373.             $offer->setSociety($this);
  374.         }
  375.         return $this;
  376.     }
  377.     public function removeOffer(Offer $offer): self
  378.     {
  379.         if ($this->offers->removeElement($offer)) {
  380.             // set the owning side to null (unless already changed)
  381.             if ($offer->getSociety() === $this) {
  382.                 $offer->setSociety(null);
  383.             }
  384.         }
  385.         return $this;
  386.     }
  387.     public function getProfileView(): ?int
  388.     {
  389.         return $this->profileView;
  390.     }
  391.     public function setProfileView(?int $profileView): self
  392.     {
  393.         $this->profileView $profileView;
  394.         return $this;
  395.     }
  396.     public function getCanUpload(): ?bool
  397.     {
  398.         return $this->canUpload;
  399.     }
  400.     public function setCanUpload(?bool $canUpload): self
  401.     {
  402.         $this->canUpload $canUpload;
  403.         return $this;
  404.     }
  405.     public function getIntercontratNumber(): ?int
  406.     {
  407.         return $this->intercontratNumber;
  408.     }
  409.     public function setIntercontratNumber(int $intercontratNumber): self
  410.     {
  411.         $this->intercontratNumber $intercontratNumber;
  412.         return $this;
  413.     }
  414.     public function getPackage(): ?string
  415.     {
  416.         return $this->package;
  417.     }
  418.     public function setPackage(?string $package): self
  419.     {
  420.         $this->package $package;
  421.         return $this;
  422.     }
  423.     public function getPackageDate(): ?\DateTimeInterface
  424.     {
  425.         return $this->packageDate;
  426.     }
  427.     public function setPackageDate(?\DateTimeInterface $packageDate): self
  428.     {
  429.         $this->packageDate $packageDate;
  430.         return $this;
  431.     }
  432.     public function getPriorizeNumber(): ?int
  433.     {
  434.         return $this->priorizeNumber;
  435.     }
  436.     public function setPriorizeNumber(?int $priorizeNumber): self
  437.     {
  438.         $this->priorizeNumber $priorizeNumber;
  439.         return $this;
  440.     }
  441.     public function getOnceEveryday(): ?int
  442.     {
  443.         return $this->onceEveryday;
  444.     }
  445.     public function setOnceEveryday(?int $onceEveryday): self
  446.     {
  447.         $this->onceEveryday $onceEveryday;
  448.         return $this;
  449.     }
  450.     public function getOnceWeek(): ?int
  451.     {
  452.         return $this->onceWeek;
  453.     }
  454.     public function setOnceWeek(?int $onceWeek): self
  455.     {
  456.         $this->onceWeek $onceWeek;
  457.         return $this;
  458.     }
  459.     public function getPauseDate(): ?\DateTimeInterface
  460.     {
  461.         return $this->pauseDate;
  462.     }
  463.     public function setPauseDate(?\DateTimeInterface $pauseDate): self
  464.     {
  465.         $this->pauseDate $pauseDate;
  466.         return $this;
  467.     }
  468.     public function getPackageExpireAt(): ?\DateTime
  469.     {
  470.         return $this->packageExpireAt;
  471.     }
  472.     public function setPackageExpireAt(?\DateTime $packageExpireAt): self
  473.     {
  474.         $this->packageExpireAt $packageExpireAt;
  475.         return $this;
  476.     }
  477.     /**
  478.      * @return Collection|Commande[]
  479.      */
  480.     public function getCommandes(): Collection
  481.     {
  482.         return $this->commandes;
  483.     }
  484.     public function addCommande(Commande $commande): self
  485.     {
  486.         if (!$this->commandes->contains($commande)) {
  487.             $this->commandes[] = $commande;
  488.             $commande->setSociety($this);
  489.         }
  490.         return $this;
  491.     }
  492.     public function removeCommande(Commande $commande): self
  493.     {
  494.         if ($this->commandes->removeElement($commande)) {
  495.             // set the owning side to null (unless already changed)
  496.             if ($commande->getSociety() === $this) {
  497.                 $commande->setSociety(null);
  498.             }
  499.         }
  500.         return $this;
  501.     }
  502.     public function canViewProfile(): bool
  503.     {
  504.         return $this->profileView 0;
  505.     }
  506.     public function canAddIntercontrat(): bool
  507.     {
  508.         return $this->intercontratNumber || $this->intercontratNumber === -1;
  509.     }
  510.     public function decreaseProfileView()
  511.     {
  512.         $this->profileView--;
  513.     }
  514.     /**
  515.      * @return Collection|ProfileVisit[]
  516.      */
  517.     public function getProfileVisits(): Collection
  518.     {
  519.         return $this->profileVisits;
  520.     }
  521.     public function addProfileVisit(ProfileVisit $profileVisit): self
  522.     {
  523.         if (!$this->profileVisits->contains($profileVisit)) {
  524.             $this->profileVisits[] = $profileVisit;
  525.             $profileVisit->setSociety($this);
  526.         }
  527.         return $this;
  528.     }
  529.     public function removeProfileVisit(ProfileVisit $profileVisit): self
  530.     {
  531.         if ($this->profileVisits->removeElement($profileVisit)) {
  532.             // set the owning side to null (unless already changed)
  533.             if ($profileVisit->getSociety() === $this) {
  534.                 $profileVisit->setSociety(null);
  535.             }
  536.         }
  537.         return $this;
  538.     }
  539.     public function packageString()
  540.     {
  541.         return empty($this->package) ? 'Aucun' Config::PACKAGE_LIST[$this->package]['name'];
  542.     }
  543.     /**
  544.      * @return Collection|Annonce[]
  545.      */
  546.     public function getAnnonces(): Collection
  547.     {
  548.         return $this->annonces;
  549.     }
  550.     public function addAnnonce(Annonce $annonce): self
  551.     {
  552.         if (!$this->annonces->contains($annonce)) {
  553.             $this->annonces[] = $annonce;
  554.             $annonce->setSociety($this);
  555.         }
  556.         return $this;
  557.     }
  558.     public function removeAnnonce(Annonce $annonce): self
  559.     {
  560.         if ($this->annonces->removeElement($annonce)) {
  561.             // set the owning side to null (unless already changed)
  562.             if ($annonce->getSociety() === $this) {
  563.                 $annonce->setSociety(null);
  564.             }
  565.         }
  566.         return $this;
  567.     }
  568.     public function getDescription(): ?string
  569.     {
  570.         return $this->description;
  571.     }
  572.     public function setDescription(?string $description): self
  573.     {
  574.         $this->description $description;
  575.         return $this;
  576.     }
  577.     public function getVille(): ?string
  578.     {
  579.         return $this->ville;
  580.     }
  581.     public function setVille(string $ville): self
  582.     {
  583.         $this->ville $ville;
  584.         return $this;
  585.     }
  586.     public function getPauseNumber(): ?int
  587.     {
  588.         return $this->pauseNumber;
  589.     }
  590.     public function setPauseNumber(?int $pauseNumber): self
  591.     {
  592.         $this->pauseNumber $pauseNumber;
  593.         return $this;
  594.     }
  595.     public function decreasePauseNumber(): self
  596.     {
  597.         $this->pauseNumber $this->pauseNumber 1;
  598.         return $this;
  599.     }
  600.     public function isPaused(): bool
  601.     {
  602.         return $this->pauseDate > new \DateTime();
  603.     }
  604.     public function hasActivePackage(): bool
  605.     {
  606.         return $this->getPackage() != null && ! $this->hasExpiredPackage();
  607.     }
  608.     public function hasExpiredPackage(): bool
  609.     {
  610.         return $this->getPackageExpireAt() < new \DateTime();
  611.     }
  612.     /**
  613.      * @return Collection|AnnonceVisit[]
  614.      */
  615.     public function getAnnonceVisits(): Collection
  616.     {
  617.         return $this->annonceVisits;
  618.     }
  619.     public function addAnnonceVisit(AnnonceVisit $annonceVisit): self
  620.     {
  621.         if (!$this->annonceVisits->contains($annonceVisit)) {
  622.             $this->annonceVisits[] = $annonceVisit;
  623.             $annonceVisit->setSociety($this);
  624.         }
  625.         return $this;
  626.     }
  627.     public function removeAnnonceVisit(AnnonceVisit $annonceVisit): self
  628.     {
  629.         if ($this->annonceVisits->removeElement($annonceVisit)) {
  630.             // set the owning side to null (unless already changed)
  631.             if ($annonceVisit->getSociety() === $this) {
  632.                 $annonceVisit->setSociety(null);
  633.             }
  634.         }
  635.         return $this;
  636.     }
  637.     public function getPackageName()
  638.     {
  639.         return Config::PACKAGE_LIST[$this->package]['name'];
  640.     }
  641.     public function getIntercontratUne(): ?int
  642.     {
  643.         return $this->intercontratUne ?? 0;
  644.     }
  645.     public function setIntercontratUne(?int $intercontratUne): self
  646.     {
  647.         $this->intercontratUne $intercontratUne;
  648.         return $this;
  649.     }
  650.     public function isCanUpload(): ?bool
  651.     {
  652.         return $this->canUpload;
  653.     }
  654.     public function getCa(): ?int
  655.     {
  656.         return $this->ca;
  657.     }
  658.     public function setCa(?int $ca): self
  659.     {
  660.         $this->ca $ca;
  661.         return $this;
  662.     }
  663.     public function getAdress(): ?string
  664.     {
  665.         return $this->adress;
  666.     }
  667.     public function setAdress(?string $adress): self
  668.     {
  669.         $this->adress $adress;
  670.         return $this;
  671.     }
  672.     /**
  673.      * @return Collection<int, CompteRecrutement>
  674.      */
  675.     public function getCompteRecrutements(): Collection
  676.     {
  677.         return $this->compteRecrutements;
  678.     }
  679.     public function addCompteRecrutement(CompteRecrutement $compteRecrutement): self
  680.     {
  681.         if (!$this->compteRecrutements->contains($compteRecrutement)) {
  682.             $this->compteRecrutements[] = $compteRecrutement;
  683.             $compteRecrutement->setSociete($this);
  684.         }
  685.         return $this;
  686.     }
  687.     public function removeCompteRecrutement(CompteRecrutement $compteRecrutement): self
  688.     {
  689.         if ($this->compteRecrutements->removeElement($compteRecrutement)) {
  690.             // set the owning side to null (unless already changed)
  691.             if ($compteRecrutement->getSociete() === $this) {
  692.                 $compteRecrutement->setSociete(null);
  693.             }
  694.         }
  695.         return $this;
  696.     }
  697.     public function getSlug(): ?string
  698.     {
  699.         return $this->slug;
  700.     }
  701.     public function setSlug(?string $slug): self
  702.     {
  703.         $this->slug $slug;
  704.         return $this;
  705.     }
  706.     public function __toString(): string
  707.     {
  708.         return $this->name// Ou toute propriété identifiable
  709.     }
  710. }