src/Entity/Gestiform/Formations/Entreprise/Entreprise.php line 20
<?phpnamespace App\Entity\Gestiform\Formations\Entreprise;use App\Entity\Common\Convention;use App\Entity\Common\Document;use App\Entity\Common\Upload;use App\Entity\Gestiform\Admin\MasterListe\Masterlistelg;use App\Entity\Gestiform\Admin\Tiers;use App\Entity\Gestiform\Formations\Devis\Devis;use App\Entity\Gestiform\Formations\Dossier\Dossier;use App\Entity\Gestiform\Formations\Financement\Financement;use App\Entity\Gestiform\Formations\Financeur\Financeur;use App\Repository\Gestiform\Formations\Entreprise\EntrepriseRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use InvalidArgumentException;use JsonException;#[ORM\Entity(repositoryClass: EntrepriseRepository::class)]class Entreprise extends Tiers{#[ORM\Column(type: 'boolean', nullable: true)]private ?bool $delegataire = false;#[ORM\OneToMany(mappedBy: 'entreprise', targetEntity: Financement::class, cascade: ['persist'])]private Collection $financements;#[ORM\Column(type: 'boolean', nullable: true)]private ?bool $assuranceChomage = false;#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $rna = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $effectif = null;#[ORM\Column(type: 'text', nullable: true)]private ?string $cart = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $activitePrincipale = null;#[ORM\JoinColumn(nullable: true)]#[ORM\ManyToOne(targetEntity: Masterlistelg::class, cascade: ['persist'])]private ?Masterlistelg $type = null;#[ORM\JoinColumn(nullable: true)]#[ORM\ManyToOne(targetEntity: Masterlistelg::class, cascade: ['persist'])]private ?Masterlistelg $typeEmployeur = null;#[ORM\JoinColumn(nullable: true)]#[ORM\ManyToOne(targetEntity: Masterlistelg::class, cascade: ['persist'])]private ?Masterlistelg $employeurSpecifique = null;#[ORM\JoinColumn(nullable: true)]#[ORM\ManyToOne(targetEntity: Masterlistelg::class, cascade: ['persist'])]private ?Masterlistelg $naf = null;#[ORM\JoinColumn(nullable: true)]#[ORM\ManyToOne(targetEntity: Financeur::class, cascade: ['persist'])]private ?Financeur $financeurEntreprise = null;#[ORM\JoinColumn(nullable: true)]#[ORM\ManyToOne(targetEntity: Masterlistelg::class, cascade: ['persist'])]private ?Masterlistelg $adhesionRegimeChomagePublic = null;#[ORM\OneToMany(mappedBy: 'entreprise', targetEntity: Convention::class, cascade: ['persist'])]private Collection $conventions;#[ORM\OneToMany(mappedBy: 'entreprise', targetEntity: Devis::class, cascade: ['all'])]private Collection $deviss;#[ORM\OneToMany(mappedBy: 'entreprise', targetEntity: Dossier::class, cascade: ['persist'])]private Collection $dossiers;#[ORM\OneToMany(mappedBy: 'entreprise', targetEntity: FormateurEntreprise::class, cascade: ['persist'])]private Collection $formateurEntreprises;#[ORM\OneToMany(mappedBy: 'entreprise', targetEntity: Contrat::class, cascade: ['all'])]private Collection $contrats;#[ORM\Column(type: 'text', nullable: true)]private ?string $missionProposee = null;#[ORM\OneToMany(mappedBy: 'entreprise', targetEntity: Document::class, cascade: ['persist'])]private Collection $documents;#[ORM\JoinColumn(nullable: true)]#[ORM\OneToOne(targetEntity: Upload::class, cascade: ['persist', 'remove'])]private ?Upload $cachet = null;public function __construct(){parent::__construct();$this->financements = new ArrayCollection();$this->conventions = new ArrayCollection();$this->contrats = new ArrayCollection();$this->deviss = new ArrayCollection();$this->dossiers = new ArrayCollection();$this->formateurEntreprises = new ArrayCollection();$this->documents = new ArrayCollection();}public function getEffectif(): ?string{return $this->effectif;}public function setEffectif(?string $effectif): self{$this->effectif = $effectif;return $this;}public function getRna(): ?string{return $this->rna;}public function setRna(?string $rna): self{$this->rna = $rna;return $this;}public function getType(): ?Masterlistelg{return $this->type;}public function setType(?Masterlistelg $type): self{$this->type = $type;return $this;}public function getNaf(): ?Masterlistelg{return $this->naf;}public function setNaf(?Masterlistelg $naf): self{$this->naf = $naf;return $this;}/*** @return Collection<int, Convention>*/public function getConventions(): Collection{return $this->conventions;}public function addConvention(Convention $convention): self{if (!$this->conventions->contains($convention)) {$this->conventions->add($convention);$convention->setEntreprise($this);}return $this;}public function removeConvention(Convention $convention): self{// set the owning side to null (unless already changed)if ($this->conventions->removeElement($convention) && $convention->getEntreprise() === $this) {$convention->setEntreprise(null);}return $this;}/*** @return Collection<int, Devis>*/public function getDeviss(): Collection{return $this->deviss;}public function addDeviss(Devis $deviss): self{if (!$this->deviss->contains($deviss)) {$this->deviss->add($deviss);$deviss->setEntreprise($this);}return $this;}public function removeDeviss(Devis $deviss): self{// set the owning side to null (unless already changed)if ($this->deviss->removeElement($deviss) && $deviss->getEntreprise() === $this) {$deviss->setEntreprise(null);}return $this;}/*** @return Collection<int, Dossier>*/public function getDossiers(): Collection{return $this->dossiers;}public function addDossier(Dossier $dossier): self{if (!$this->dossiers->contains($dossier)) {$this->dossiers->add($dossier);$dossier->setEntreprise($this);}return $this;}public function removeDossier(Dossier $dossier): self{// set the owning side to null (unless already changed)if ($this->dossiers->removeElement($dossier) && $dossier->getEntreprise() === $this) {$dossier->setEntreprise(null);}return $this;}public function getContactPrincipal(){$contacts = $this->getContacts();foreach ($contacts as $item) {if ($item->isPrincipal()) {return $item;}}return null;}public function getDelegataire(): ?bool{return $this->delegataire;}public function setDelegataire(?bool $delegataire): self{$this->delegataire = $delegataire;return $this;}public function isDelegataire(): ?bool{return $this->delegataire;}/*** @return Collection<int, FormateurEntreprise>*/public function getFormateurEntreprises(): Collection{return $this->formateurEntreprises;}public function addFormateurEntreprise(FormateurEntreprise $formateurEntreprise): self{if (!$this->formateurEntreprises->contains($formateurEntreprise)) {$this->formateurEntreprises->add($formateurEntreprise);$formateurEntreprise->setEntreprise($this);}return $this;}public function removeFormateurEntreprise(FormateurEntreprise $formateurEntreprise): self{// set the owning side to null (unless already changed)if ($this->formateurEntreprises->removeElement($formateurEntreprise) && $formateurEntreprise->getEntreprise() === $this) {$formateurEntreprise->setEntreprise(null);}return $this;}/*** @return Collection<int, Contrat>*/public function getContrats(): Collection{return $this->contrats;}public function addContrat(Contrat $contrat): self{if (!$this->contrats->contains($contrat)) {$this->contrats->add($contrat);$contrat->setEntreprise($this);}return $this;}public function removeContrat(Contrat $contrat): self{// set the owning side to null (unless already changed)if ($this->contrats->removeElement($contrat) && $contrat->getEntreprise() === $this) {$contrat->setEntreprise(null);}return $this;}/*** @throws JsonException*/public function setMissionProposee($missionProposee): self{if (is_array($missionProposee)) {$this->missionProposee = json_encode($missionProposee, JSON_THROW_ON_ERROR);} elseif (is_string($missionProposee)) {json_decode($missionProposee, false, 512, JSON_THROW_ON_ERROR);if (json_last_error() === JSON_ERROR_NONE) {$this->missionProposee = $missionProposee;} else {throw new InvalidArgumentException('Invalid JSON string.');}} else {throw new InvalidArgumentException('Expected an array or a JSON string.');}return $this;}/*** @throws JsonException*/public function removeFormateurFromMission(string $missionId, string $formateurId): self{$missionsProposees = $this->getMissionProposee() ?? [];foreach ($missionsProposees as &$mission) {if ($mission['id'] === $missionId && isset($mission['formateurs'])) {$mission['formateurs'] = array_filter($mission['formateurs'],static function ($formateur) use ($formateurId) {return $formateur['id'] !== $formateurId;});$mission['formateurs'] = array_values($mission['formateurs']);}}$this->missionProposee = json_encode($missionsProposees, JSON_THROW_ON_ERROR);return $this;}/*** @throws JsonException*/public function getMissionProposee(){if ($this->missionProposee === null || $this->missionProposee === "") {return [];}return json_decode($this->missionProposee, true, 512, JSON_THROW_ON_ERROR);}/*** @throws JsonException*/public function addFormateurMissionProposee(string $id, string $idFormateur, string $nomFormateur): self{$missionProposee = $this->getMissionProposee() ?? [];$modified = false;foreach ($missionProposee as &$item) {if ($item['id'] === $id) {$item['formateurs'] = $item['formateurs'] ?? [];// Check if formateur already exists$formateurExists = false;foreach ($item['formateurs'] as $formateur) {if ($formateur['id'] === $idFormateur) {$formateurExists = true;break;}}if (!$formateurExists) {$item['formateurs'][] = ['id' => $idFormateur,'nom' => $nomFormateur];$item['state'] = true;$modified = true;}}}if ($modified) {$this->missionProposee = json_encode($missionProposee, JSON_THROW_ON_ERROR);}return $this;}/*** @throws JsonException*/public function addMissionProposee(string $id, string $title, $state = null, $sevent = []): self{$missionProposee = $this->getMissionProposee() ?? [];$exist = false;foreach ($missionProposee as &$item) {if ($item['id'] === $id) {$item['title'] = $title;$item['state'] = $state;$item['week'] = $sevent['week'];$item['start'] = $sevent['start'];$item['end'] = $sevent['end'];$exist = true;}}if (!$exist) {$missionProposee[] = ['id' => $id,'title' => $title,'state' => $state,'week' => $sevent['week'],'start' => $sevent['start'],'end' => $sevent['end']];}$this->missionProposee = json_encode($missionProposee, JSON_THROW_ON_ERROR);return $this;}/*** @throws JsonException*/public function getMissionProposeeById(string $id){$missionProposee = json_decode($this->missionProposee, true, 512, JSON_THROW_ON_ERROR) ?? [];foreach ($missionProposee as $item) {if ($item['id'] === $id) {return $item;}}return null;}/*** @throws JsonException*/public function removeMissionProposee(string $id): self{$missionProposee = [];if (!empty($this->missionProposee)) {$cleanJson = preg_replace('/[\x00-\x1F\x7F]/u', '', $this->missionProposee);try {$missionProposee = json_decode($cleanJson, true, 512, JSON_THROW_ON_ERROR);} catch (\JsonException $e) {dump($e->getMessage());$missionProposee = [];}}foreach ($missionProposee as $key => $item) {if (($item['id'] ?? null) === $id) {unset($missionProposee[$key]);}}$this->missionProposee = json_encode(array_values($missionProposee), JSON_THROW_ON_ERROR);return $this;}/*** @throws JsonException*/public function verifMissionProposee(string $id): bool{$json = $this->missionProposee ?? '[]';$missionProposee = json_decode($json, true, 512, JSON_THROW_ON_ERROR) ?? [];$exist = false;foreach ($missionProposee as &$item) {if ($item['id'] === $id) {$exist = true;}}return $exist;}/*** @throws JsonException*/public function verifStateMission(string $id): bool{$missionProposee = json_decode((string) $this->missionProposee, true, 512, JSON_THROW_ON_ERROR) ?? [];$exist = false;foreach ($missionProposee as &$item) {if ($item['id'] === $id && $item['state']) {$exist = true;}}return $exist;}/*** @throws JsonException*/public function confirmerMission(string $id): self{$missionProposee = json_decode((string) $this->missionProposee, true, 512, JSON_THROW_ON_ERROR) ?? [];foreach ($missionProposee as &$item) {if ($item['id'] === $id) {$item['state'] = true;break;}}$this->missionProposee = json_encode(array_values($missionProposee), JSON_THROW_ON_ERROR);return $this;}public function getFinanceurEntreprise(): ?Financeur{return $this->financeurEntreprise;}public function setFinanceurEntreprise(?Financeur $financeurEntreprise): self{$this->financeurEntreprise = $financeurEntreprise;return $this;}public function getTypeEmployeur(): ?Masterlistelg{return $this->typeEmployeur;}public function setTypeEmployeur(?Masterlistelg $typeEmployeur): self{$this->typeEmployeur = $typeEmployeur;return $this;}public function getEmployeurSpecifique(): ?Masterlistelg{return $this->employeurSpecifique;}public function setEmployeurSpecifique(?Masterlistelg $employeurSpecifique): self{$this->employeurSpecifique = $employeurSpecifique;return $this;}public function getActivitePrincipale(): ?string{return $this->activitePrincipale;}public function setActivitePrincipale(?string $activitePrincipale): self{$this->activitePrincipale = $activitePrincipale;return $this;}public function getAdhesionRegimeChomagePublic(): ?Masterlistelg{return $this->adhesionRegimeChomagePublic;}public function setAdhesionRegimeChomagePublic(?Masterlistelg $adhesionRegimeChomagePublic): self{$this->adhesionRegimeChomagePublic = $adhesionRegimeChomagePublic;return $this;}public function getCart(){if ($this->cart === null) {return [];}return json_decode($this->cart, true);}/*** @throws JsonException*/public function addCart(string $idModule, string $intitule, string $duree): self{$exit = false;$items = $this->getCart();foreach ($items as $item) {if ($item['id'] === $idModule) {$exit = true;}}if (!$exit) {$items[] = ['id' => $idModule,'intitule' => $intitule,'duree' => $duree,];}$this->cart = json_encode($items, JSON_THROW_ON_ERROR);return $this;}/*** @throws JsonException*/public function removeCart(int $idModule): self{$items = $this->getCart();if (array_key_exists($idModule, $items)) {unset($items[$idModule]);}$this->cart = json_encode($items, JSON_THROW_ON_ERROR);return $this;}public function removeCarts(): self{$this->cart = NULL;return $this;}public function getAssuranceChomage(): ?bool{return $this->assuranceChomage;}public function setAssuranceChomage(?bool $assuranceChomage): Entreprise{$this->assuranceChomage = $assuranceChomage;return $this;}public function isAssuranceChomage(): ?bool{return $this->assuranceChomage;}public function setCart(?string $cart): self{$this->cart = $cart;return $this;}/*** @return Collection<int, Financement>*/public function getFinancements(): Collection{return $this->financements;}public function addFinancement(Financement $financement): self{if (!$this->financements->contains($financement)) {$this->financements->add($financement);$financement->setEntreprise($this);}return $this;}public function removeFinancement(Financement $financement): self{if ($this->financements->removeElement($financement)) {// set the owning side to null (unless already changed)if ($financement->getEntreprise() === $this) {$financement->setEntreprise(null);}}return $this;}/*** @return Collection<int, Document>*/public function getDocuments(): Collection{return $this->documents;}public function addDocument(Document $document): self{if (!$this->documents->contains($document)) {$this->documents->add($document);$document->setEntreprise($this);}return $this;}public function removeDocument(Document $document): self{if ($this->documents->removeElement($document)) {// set the owning side to null (unless already changed)if ($document->getEntreprise() === $this) {$document->setEntreprise(null);}}return $this;}public function getCachet(): ?Upload{return $this->cachet;}public function setCachet(?Upload $cachet): self{$this->cachet = $cachet;return $this;}}