src/Entity/Gestiform/Formations/Entreprise/Entreprise.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gestiform\Formations\Entreprise;
  3. use App\Entity\Common\Convention;
  4. use App\Entity\Gestiform\Admin\MasterListe\Masterlistelg;
  5. use App\Entity\Gestiform\Admin\Tiers;
  6. use App\Entity\Gestiform\Formations\Devis\Devis;
  7. use App\Entity\Gestiform\Formations\Dossier\Dossier;
  8. use App\Entity\Gestiform\Formations\Financeur\Financeur;
  9. use App\Entity\Gestiform\Formations\Financement\Financement;
  10. use App\Repository\Gestiform\Formations\Entreprise\EntrepriseRepository;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. /**
  15.  * @ORM\Entity(repositoryClass=EntrepriseRepository::class)
  16.  */
  17. class Entreprise extends Tiers
  18. {
  19.     /**
  20.      * @ORM\Column(type="boolean", nullable=true)
  21.      */
  22.     private ?bool $delegataire false;
  23.     /**
  24.      * @ORM\OneToMany(targetEntity=Financement::class, mappedBy="entreprise",cascade={"persist"})
  25.      */
  26.     private Collection $financements;
  27.     /**
  28.      * @ORM\Column(type="boolean", nullable=true)
  29.      */
  30.     private ?bool $assuranceChomage false;
  31.     /**
  32.      * @ORM\Column(type="string", length=255, nullable=true)
  33.      */
  34.     private ?string $rna null;
  35.     /**
  36.      * @ORM\Column(type="string", length=255, nullable=true)
  37.      */
  38.     private ?string $effectif null;
  39.     /**
  40.      * @ORM\Column(type="text",  nullable=true)
  41.      */
  42.     private ?string $cart null;
  43.     /**
  44.      * @ORM\Column(type="string", length=255, nullable=true)
  45.      */
  46.     private ?string $activitePrincipale null;
  47.     /**
  48.      * @ORM\ManyToOne(targetEntity=Masterlistelg::class,cascade={"persist"})
  49.      * @ORM\JoinColumn(nullable=true)
  50.      */
  51.     private ?Masterlistelg $type null;
  52.     /**
  53.      * @ORM\ManyToOne(targetEntity=Masterlistelg::class,cascade={"persist"})
  54.      * @ORM\JoinColumn(nullable=true)
  55.      */
  56.     private ?Masterlistelg $typeEmployeur null;
  57.     /**
  58.      * @ORM\ManyToOne(targetEntity=Masterlistelg::class,cascade={"persist"})
  59.      * @ORM\JoinColumn(nullable=true)
  60.      */
  61.     private ?Masterlistelg $employeurSpecifique null;
  62.     /**
  63.      * @ORM\ManyToOne(targetEntity=Masterlistelg::class,cascade={"persist"})
  64.      * @ORM\JoinColumn(nullable=true)
  65.      */
  66.     private ?Masterlistelg $naf null;
  67.     /**
  68.      * @ORM\ManyToOne(targetEntity=Financeur::class,cascade={"persist"})
  69.      * @ORM\JoinColumn(nullable=true)
  70.      */
  71.     private ?Financeur $financeurEntreprise null;
  72.     /**
  73.      * @ORM\ManyToOne(targetEntity=Masterlistelg::class,cascade={"persist"})
  74.      * @ORM\JoinColumn(nullable=true)
  75.      */
  76.     private ?Masterlistelg $adhesionRegimeChomagePublic null;
  77.     /**
  78.      * @ORM\OneToMany(targetEntity=Convention::class, mappedBy="entreprise",cascade={"persist"})
  79.      */
  80.     private Collection $conventions;
  81.     /**
  82.      * @ORM\OneToMany(targetEntity=Devis::class, mappedBy="entreprise",cascade={"all"})
  83.      */
  84.     private Collection $deviss;
  85.     /**
  86.      * @ORM\OneToMany(targetEntity=Dossier::class, mappedBy="entreprise",cascade={"persist"})
  87.      */
  88.     private Collection $dossiers;
  89.     /**
  90.      * @ORM\OneToMany(targetEntity=FormateurEntreprise::class, mappedBy="entreprise",cascade={"persist"})
  91.      */
  92.     private Collection $formateurEntreprises;
  93.     /**
  94.      * @ORM\OneToMany(targetEntity=Contrat::class, mappedBy="entreprise",cascade={"all"})
  95.      */
  96.     private Collection $contrats;
  97.     /**
  98.      * @ORM\Column( type="text", nullable=true)
  99.      */
  100.     private ?string $missionProposee null;
  101.     public function __construct()
  102.     {
  103.         parent::__construct();
  104.         $this->financements = new ArrayCollection();
  105.         $this->conventions = new ArrayCollection();
  106.         $this->contrats = new ArrayCollection();
  107.         $this->deviss = new ArrayCollection();
  108.         $this->dossiers = new ArrayCollection();
  109.         $this->formateurEntreprises = new ArrayCollection();
  110.     }
  111.     public function getEffectif(): ?string
  112.     {
  113.         return $this->effectif;
  114.     }
  115.     public function setEffectif(?string $effectif): self
  116.     {
  117.         $this->effectif $effectif;
  118.         return $this;
  119.     }
  120.     public function getRna(): ?string
  121.     {
  122.         return $this->rna;
  123.     }
  124.     public function setRna(?string $rna): self
  125.     {
  126.         $this->rna $rna;
  127.         return $this;
  128.     }
  129.     public function getType(): ?Masterlistelg
  130.     {
  131.         return $this->type;
  132.     }
  133.     public function setType(?Masterlistelg $type): self
  134.     {
  135.         $this->type $type;
  136.         return $this;
  137.     }
  138.     public function getNaf(): ?Masterlistelg
  139.     {
  140.         return $this->naf;
  141.     }
  142.     public function setNaf(?Masterlistelg $naf): self
  143.     {
  144.         $this->naf $naf;
  145.         return $this;
  146.     }
  147.     /**
  148.      * @return Collection<int, Convention>
  149.      */
  150.     public function getConventions(): Collection
  151.     {
  152.         return $this->conventions;
  153.     }
  154.     public function addConvention(Convention $convention): self
  155.     {
  156.         if (!$this->conventions->contains($convention)) {
  157.             $this->conventions->add($convention);
  158.             $convention->setEntreprise($this);
  159.         }
  160.         return $this;
  161.     }
  162.     public function removeConvention(Convention $convention): self
  163.     {
  164.         if ($this->conventions->removeElement($convention)) {
  165.             // set the owning side to null (unless already changed)
  166.             if ($convention->getEntreprise() === $this) {
  167.                 $convention->setEntreprise(null);
  168.             }
  169.         }
  170.         return $this;
  171.     }
  172.     /**
  173.      * @return Collection<int, Devis>
  174.      */
  175.     public function getDeviss(): Collection
  176.     {
  177.         return $this->deviss;
  178.     }
  179.     public function addDeviss(Devis $deviss): self
  180.     {
  181.         if (!$this->deviss->contains($deviss)) {
  182.             $this->deviss->add($deviss);
  183.             $deviss->setEntreprise($this);
  184.         }
  185.         return $this;
  186.     }
  187.     public function removeDeviss(Devis $deviss): self
  188.     {
  189.         if ($this->deviss->removeElement($deviss)) {
  190.             // set the owning side to null (unless already changed)
  191.             if ($deviss->getEntreprise() === $this) {
  192.                 $deviss->setEntreprise(null);
  193.             }
  194.         }
  195.         return $this;
  196.     }
  197.     /**
  198.      * @return Collection<int, Dossier>
  199.      */
  200.     public function getDossiers(): Collection
  201.     {
  202.         return $this->dossiers;
  203.     }
  204.     public function addDossier(Dossier $dossier): self
  205.     {
  206.         if (!$this->dossiers->contains($dossier)) {
  207.             $this->dossiers->add($dossier);
  208.             $dossier->setEntreprise($this);
  209.         }
  210.         return $this;
  211.     }
  212.     public function removeDossier(Dossier $dossier): self
  213.     {
  214.         if ($this->dossiers->removeElement($dossier)) {
  215.             // set the owning side to null (unless already changed)
  216.             if ($dossier->getEntreprise() === $this) {
  217.                 $dossier->setEntreprise(null);
  218.             }
  219.         }
  220.         return $this;
  221.     }
  222.     public function getContactPrincipal()
  223.     {
  224.         $contacts $this->getContacts();
  225.         foreach ($contacts as $item) {
  226.             if ($item->isPrincipal())
  227.                 return $item;
  228.         }
  229.         return null;
  230.     }
  231.     public function getDelegataire(): ?bool
  232.     {
  233.         return $this->delegataire;
  234.     }
  235.     public function setDelegataire(?bool $delegataire): self
  236.     {
  237.         $this->delegataire $delegataire;
  238.         return $this;
  239.     }
  240.     public function isDelegataire(): ?bool
  241.     {
  242.         return $this->delegataire;
  243.     }
  244.     /**
  245.      * @return Collection<int, FormateurEntreprise>
  246.      */
  247.     public function getFormateurEntreprises(): Collection
  248.     {
  249.         return $this->formateurEntreprises;
  250.     }
  251.     public function addFormateurEntreprise(FormateurEntreprise $formateurEntreprise): self
  252.     {
  253.         if (!$this->formateurEntreprises->contains($formateurEntreprise)) {
  254.             $this->formateurEntreprises->add($formateurEntreprise);
  255.             $formateurEntreprise->setEntreprise($this);
  256.         }
  257.         return $this;
  258.     }
  259.     public function removeFormateurEntreprise(FormateurEntreprise $formateurEntreprise): self
  260.     {
  261.         if ($this->formateurEntreprises->removeElement($formateurEntreprise)) {
  262.             // set the owning side to null (unless already changed)
  263.             if ($formateurEntreprise->getEntreprise() === $this) {
  264.                 $formateurEntreprise->setEntreprise(null);
  265.             }
  266.         }
  267.         return $this;
  268.     }
  269.     /**
  270.      * @return Collection<int, Contrat>
  271.      */
  272.     public function getContrats(): Collection
  273.     {
  274.         return $this->contrats;
  275.     }
  276.     public function addContrat(Contrat $contrat): self
  277.     {
  278.         if (!$this->contrats->contains($contrat)) {
  279.             $this->contrats->add($contrat);
  280.             $contrat->setEntreprise($this);
  281.         }
  282.         return $this;
  283.     }
  284.     public function removeContrat(Contrat $contrat): self
  285.     {
  286.         // set the owning side to null (unless already changed)
  287.         if ($this->contrats->removeElement($contrat) && $contrat->getEntreprise() === $this) {
  288.             $contrat->setEntreprise(null);
  289.         }
  290.         return $this;
  291.     }
  292.     /**
  293.      * @throws \JsonException
  294.      */
  295.     public function setMissionProposee($missionProposee): self
  296.     {
  297.         if (is_array($missionProposee)) {
  298.             $this->missionProposee json_encode($missionProposeeJSON_THROW_ON_ERROR);
  299.         } elseif (is_string($missionProposee)) {
  300.             json_decode($missionProposeefalse512JSON_THROW_ON_ERROR);
  301.             if (json_last_error() === JSON_ERROR_NONE) {
  302.                 $this->missionProposee $missionProposee;
  303.             } else {
  304.                 throw new \InvalidArgumentException('Invalid JSON string.');
  305.             }
  306.         } else {
  307.             throw new \InvalidArgumentException('Expected an array or a JSON string.');
  308.         }
  309.         return $this;
  310.     }
  311.     /**
  312.      * @throws \JsonException
  313.      */
  314.     public function removeFormateurFromMission(string $missionIdstring $formateurId): self
  315.     {
  316.         $missionsProposees $this->getMissionProposee() ?? [];
  317.         foreach ($missionsProposees as &$mission) {
  318.             if ($mission['id'] === $missionId) {
  319.                 if (isset($mission['formateurs'])) {
  320.                     $mission['formateurs'] = array_filter($mission['formateurs'],
  321.                         static function ($formateur) use ($formateurId) {
  322.                             return $formateur['id'] !== $formateurId;
  323.                         });
  324.                     $mission['formateurs'] = array_values($mission['formateurs']);
  325.                 }
  326.             }
  327.         }
  328.         $this->missionProposee json_encode($missionsProposeesJSON_THROW_ON_ERROR);
  329.         return $this;
  330.     }
  331.     /**
  332.      * @throws \JsonException
  333.      */
  334.     public function getMissionProposee()
  335.     {
  336.         if ($this->missionProposee === null || $this->missionProposee === "") {
  337.             return [];
  338.         }
  339.         return json_decode($this->missionProposeetrue512JSON_THROW_ON_ERROR);
  340.     }
  341.     /**
  342.      * @throws \JsonException
  343.      */
  344.     public function addFormateurMissionProposee(string $idstring $idFormateurstring $nomFormateur): self
  345.     {
  346.         $missionProposee $this->getMissionProposee() ?? [];
  347.         $modified false;
  348.         foreach ($missionProposee as &$item) {
  349.             if ($item['id'] === $id) {
  350.                 $item['formateurs'] = $item['formateurs'] ?? [];
  351.                 // Check if formateur already exists
  352.                 $formateurExists false;
  353.                 foreach ($item['formateurs'] as $formateur) {
  354.                     if ($formateur['id'] === $idFormateur) {
  355.                         $formateurExists true;
  356.                         break;
  357.                     }
  358.                 }
  359.                 if (!$formateurExists) {
  360.                     $item['formateurs'][] = [
  361.                         'id' => $idFormateur,
  362.                         'nom' => $nomFormateur
  363.                     ];
  364.                     $item['state'] = true;
  365.                     $modified true;
  366.                 }
  367.             }
  368.         }
  369.         if ($modified) {
  370.             $this->missionProposee json_encode($missionProposeeJSON_THROW_ON_ERROR);
  371.         }
  372.         return $this;
  373.     }
  374.     /**
  375.      * @throws \JsonException
  376.      */
  377.     public function addMissionProposee(string $idstring $title$state null$sevent = []): self
  378.     {
  379.         $missionProposee $this->getMissionProposee() ?? [];
  380.         $exist false;
  381.         foreach ($missionProposee as &$item) {
  382.             if ($item['id'] === $id) {
  383.                 $item['title'] = $title;
  384.                 $item['state'] = $state;
  385.                 $item['week'] = $sevent['week'];
  386.                 $item['start'] = $sevent['start'];
  387.                 $item['end'] = $sevent['end'];
  388.                 $exist true;
  389.             }
  390.         }
  391.         if (!$exist) {
  392.             $missionProposee[] = [
  393.                 'id' => $id,
  394.                 'title' => $title,
  395.                 'state' => $state,
  396.                 'week' => $sevent['week'],
  397.                 'start' => $sevent['start'],
  398.                 'end' => $sevent['end']
  399.             ];
  400.         }
  401.         $this->missionProposee json_encode($missionProposeeJSON_THROW_ON_ERROR);
  402.         return $this;
  403.     }
  404.     /**
  405.      * @throws \JsonException
  406.      */
  407.     public function getMissionProposeeById(string $id)
  408.     {
  409.         $missionProposee json_decode($this->missionProposeetrue512JSON_THROW_ON_ERROR) ?? [];
  410.         foreach ($missionProposee as $item) {
  411.             if ($item['id'] === $id) {
  412.                 return $item;
  413.             }
  414.         }
  415.         return null;
  416.     }
  417.     /**
  418.      * @throws \JsonException
  419.      */
  420.     public function removeMissionProposee(string $intitule): self
  421.     {
  422.         $missionProposee json_decode($this->missionProposeetrue512JSON_THROW_ON_ERROR) ?? [];
  423.         foreach ($missionProposee as $key => $item) {
  424.             if ($item['id'] === $intitule) {
  425.                 unset($missionProposee[$key]);
  426.             }
  427.         }
  428.         $this->missionProposee json_encode(array_values($missionProposee), JSON_THROW_ON_ERROR);
  429.         return $this;
  430.     }
  431.     /**
  432.      * @throws \JsonException
  433.      */
  434.     public function verifMissionProposee(string $id): bool
  435.     {
  436.         $missionProposee json_decode($this->missionProposeetrue512JSON_THROW_ON_ERROR) ?? [];
  437.         $exist false;
  438.         foreach ($missionProposee as &$item) {
  439.             if ($item['id'] === $id) {
  440.                 $exist true;
  441.             }
  442.         }
  443.         return $exist;
  444.     }
  445.     /**
  446.      * @throws \JsonException
  447.      */
  448.     public function verifStateMission(string $id): bool
  449.     {
  450.         $missionProposee json_decode($this->missionProposeetrue512JSON_THROW_ON_ERROR) ?? [];
  451.         $exist false;
  452.         foreach ($missionProposee as &$item) {
  453.             if ($item['id'] === $id && $item['state']) {
  454.                 $exist true;
  455.             }
  456.         }
  457.         return $exist;
  458.     }
  459.     /**
  460.      * @throws \JsonException
  461.      */
  462.     public function confirmerMission(string $id): self
  463.     {
  464.         $missionProposee json_decode($this->missionProposeetrue512JSON_THROW_ON_ERROR) ?? [];
  465.         foreach ($missionProposee as &$item) {
  466.             if ($item['id'] === $id) {
  467.                 $item['state'] = true;
  468.                 break;
  469.             }
  470.         }
  471.         $this->missionProposee json_encode(array_values($missionProposee), JSON_THROW_ON_ERROR);
  472.         return $this;
  473.     }
  474.     public function getFinanceurEntreprise(): ?Financeur
  475.     {
  476.         return $this->financeurEntreprise;
  477.     }
  478.     public function setFinanceurEntreprise(?Financeur $financeurEntreprise): self
  479.     {
  480.         $this->financeurEntreprise $financeurEntreprise;
  481.         return $this;
  482.     }
  483.     public function getTypeEmployeur(): ?Masterlistelg
  484.     {
  485.         return $this->typeEmployeur;
  486.     }
  487.     public function setTypeEmployeur(?Masterlistelg $typeEmployeur): self
  488.     {
  489.         $this->typeEmployeur $typeEmployeur;
  490.         return $this;
  491.     }
  492.     public function getEmployeurSpecifique(): ?Masterlistelg
  493.     {
  494.         return $this->employeurSpecifique;
  495.     }
  496.     public function setEmployeurSpecifique(?Masterlistelg $employeurSpecifique): self
  497.     {
  498.         $this->employeurSpecifique $employeurSpecifique;
  499.         return $this;
  500.     }
  501.     public function getActivitePrincipale(): ?string
  502.     {
  503.         return $this->activitePrincipale;
  504.     }
  505.     public function setActivitePrincipale(?string $activitePrincipale): self
  506.     {
  507.         $this->activitePrincipale $activitePrincipale;
  508.         return $this;
  509.     }
  510.     public function getAdhesionRegimeChomagePublic(): ?Masterlistelg
  511.     {
  512.         return $this->adhesionRegimeChomagePublic;
  513.     }
  514.     public function setAdhesionRegimeChomagePublic(?Masterlistelg $adhesionRegimeChomagePublic): self
  515.     {
  516.         $this->adhesionRegimeChomagePublic $adhesionRegimeChomagePublic;
  517.         return $this;
  518.     }
  519.     public function getCart()
  520.     {
  521.         if ($this->cart === null) {
  522.             return [];
  523.         }
  524.         return json_decode($this->carttrue);
  525.     }
  526.     /**
  527.      * @throws \JsonException
  528.      */
  529.     public function addCart(string $idModulestring $intitulestring $duree): self
  530.     {
  531.         $exit false;
  532.         $items $this->getCart();
  533.         foreach ($items as $item) {
  534.             if ($item['id'] === $idModule) {
  535.                 $exit true;
  536.             }
  537.         }
  538.         if (!$exit) {
  539.             $items[] = [
  540.                 'id' => $idModule,
  541.                 'intitule' => $intitule,
  542.                 'duree' => $duree,
  543.             ];
  544.         }
  545.         $this->cart json_encode($itemsJSON_THROW_ON_ERROR);
  546.         return $this;
  547.     }
  548.     /**
  549.      * @throws \JsonException
  550.      */
  551.     public function removeCart(int $idModule): self
  552.     {
  553.         $items $this->getCart();
  554.         if (array_key_exists($idModule$items) === true) {
  555.             unset($items[$idModule]);
  556.         }
  557.         $this->cart json_encode($itemsJSON_THROW_ON_ERROR);
  558.         return $this;
  559.     }
  560.     public function removeCarts(): self
  561.     {
  562.         $this->cart NULL;
  563.         return $this;
  564.     }
  565.     public function getAssuranceChomage(): ?bool
  566.     {
  567.         return $this->assuranceChomage;
  568.     }
  569.     public function setAssuranceChomage(?bool $assuranceChomage): Entreprise
  570.     {
  571.         $this->assuranceChomage $assuranceChomage;
  572.         return $this;
  573.     }
  574. }