src/Entity/Entreprise.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\EntrepriseRepository;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. /**
  8.  * @ORM\Entity(repositoryClass=EntrepriseRepository::class)
  9.  */
  10. class Entreprise
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $RaisonSociale;
  22.     /**
  23.      * @ORM\Column(type="string", length=255, nullable=true)
  24.      */
  25.     private $Siret;
  26.     /**
  27.      * @ORM\Column(type="string", length=255, nullable=true)
  28.      */
  29.     private $Naf;
  30.     /**
  31.      * @ORM\Column(type="string", length=255, nullable=true)
  32.      */
  33.     private $Adresse;
  34.     /**
  35.      * @ORM\Column(type="string", length=255, nullable=true)
  36.      */
  37.     private $Code_Insee;
  38.     /**
  39.      * @ORM\Column(type="string", length=255, nullable=true)
  40.      */
  41.     private $Statut;
  42.     /**
  43.      * @ORM\Column(type="json", nullable=true)
  44.      */
  45.     private $Utilisateur = [];
  46.     /**
  47.      * @ORM\Column(type="string", length=255, nullable=true)
  48.      */
  49.     private $rcs;
  50.     /**
  51.      * @ORM\Column(type="string", length=255, nullable=true)
  52.      */
  53.     private $num_voie;
  54.     /**
  55.      * @ORM\Column(type="string", length=255, nullable=true)
  56.      */
  57.     private $code_postal;
  58.     /**
  59.      * @ORM\Column(type="string", length=255, nullable=true)
  60.      */
  61.     private $commune;
  62.     /**
  63.      * @ORM\OneToMany(targetEntity=Contrat::class, mappedBy="entreprise", orphanRemoval=false, cascade={"persist"})
  64.      */
  65.     private Collection $contrats;
  66.     /** @return Collection<int, Contrat> */
  67.     public function getContrats(): Collection
  68.     {
  69.         return $this->contrats;
  70.     }
  71.     public function addContrat(Contrat $contrat): self
  72.     {
  73.         if (!$this->contrats->contains($contrat)) {
  74.             $this->contrats[] = $contrat;
  75.             $contrat->setEntreprise($this);
  76.         }
  77.         return $this;
  78.     }
  79.     public function removeContrat(Contrat $contrat): self
  80.     {
  81.         if ($this->contrats->removeElement($contrat)) {
  82.             if ($contrat->getEntreprise() === $this) {
  83.                 $contrat->setEntreprise(null);
  84.             }
  85.         }
  86.         return $this;
  87.     }
  88.     /**
  89.      * @ORM\ManyToMany(targetEntity=User::class, mappedBy="entreprises")
  90.      */
  91.     private $users;
  92.     /**
  93.      * @ORM\OneToMany(targetEntity=Facture::class, mappedBy="entreprise")
  94.      */
  95.     private $factures;
  96.     public function __construct()
  97.     {
  98.         $this->users = new ArrayCollection();
  99.         $this->factures = new ArrayCollection();
  100.         $this->Utilisateur = [];
  101.         $this->contrats = new ArrayCollection();
  102.     }
  103.     public function getId(): ?int
  104.     {
  105.         return $this->id;
  106.     }
  107.     public function getRaisonSociale(): ?string
  108.     {
  109.         return $this->RaisonSociale;
  110.     }
  111.     public function setRaisonSociale(string $RaisonSociale): self
  112.     {
  113.         $this->RaisonSociale $RaisonSociale;
  114.         return $this;
  115.     }
  116.     public function getSiret(): ?string
  117.     {
  118.         return $this->Siret;
  119.     }
  120.     public function setSiret(?string $Siret): self
  121.     {
  122.         $this->Siret $Siret;
  123.         return $this;
  124.     }
  125.     public function getNaf(): ?string
  126.     {
  127.         return $this->Naf;
  128.     }
  129.     public function setNaf(?string $Naf): self
  130.     {
  131.         $this->Naf $Naf;
  132.         return $this;
  133.     }
  134.     public function getAdresse(): ?string
  135.     {
  136.         return $this->Adresse;
  137.     }
  138.     public function setAdresse(?string $Adresse): self
  139.     {
  140.         $this->Adresse $Adresse;
  141.         return $this;
  142.     }
  143.     public function getCodeInsee(): ?string
  144.     {
  145.         return $this->Code_Insee;
  146.     }
  147.     public function setCodeInsee(?string $Code_Insee): self
  148.     {
  149.         $this->Code_Insee $Code_Insee;
  150.         return $this;
  151.     }
  152.     public function getStatut(): ?string
  153.     {
  154.         return $this->Statut;
  155.     }
  156.     public function setStatut(?string $Statut): self
  157.     {
  158.         $this->Statut $Statut;
  159.         return $this;
  160.     }
  161.     /**
  162.      * @return array
  163.      */
  164.     public function getUtilisateur(): array
  165.     {
  166.         if ($this->Utilisateur === null) {
  167.             return [];
  168.         }
  169.         
  170.         // Handle case where value might be stored as JSON string
  171.         if (is_string($this->Utilisateur)) {
  172.             $decoded json_decode($this->Utilisateurtrue);
  173.             return is_array($decoded) ? $decoded : [];
  174.         }
  175.         
  176.         // Handle case where value might be a single integer
  177.         if (is_int($this->Utilisateur)) {
  178.             return [strval($this->Utilisateur)];
  179.         }
  180.         
  181.         // Handle case where value is already an array
  182.         if (is_array($this->Utilisateur)) {
  183.             return $this->Utilisateur;
  184.         }
  185.         
  186.         return [];
  187.     }
  188.     public function setUtilisateur(?array $Utilisateur): self
  189.     {
  190.         $this->Utilisateur $Utilisateur ?? [];
  191.         return $this;
  192.     }
  193.     public function addUtilisateur(string $userId): self
  194.     {
  195.         if (!is_array($this->Utilisateur)) {
  196.             $this->Utilisateur = [];
  197.         }
  198.         if (!in_array($userId$this->Utilisateur)) {
  199.             $this->Utilisateur[] = $userId;
  200.         }
  201.         return $this;
  202.     }
  203.     public function removeUtilisateur(string $userId): self
  204.     {
  205.         if (!is_array($this->Utilisateur)) {
  206.             return $this;
  207.         }
  208.         $this->Utilisateur array_filter($this->Utilisateur, function($id) use ($userId) {
  209.             return $id !== $userId;
  210.         });
  211.         return $this;
  212.     }
  213.     public function getRcs(): ?string
  214.     {
  215.         return $this->rcs;
  216.     }
  217.     public function setRcs(?string $rcs): self
  218.     {
  219.         $this->rcs $rcs;
  220.         return $this;
  221.     }
  222.     public function getNumVoie(): ?string
  223.     {
  224.         return $this->num_voie;
  225.     }
  226.     public function setNumVoie(?string $num_voie): self
  227.     {
  228.         $this->num_voie $num_voie;
  229.         return $this;
  230.     }
  231.     public function getCodePostal(): ?string
  232.     {
  233.         return $this->code_postal;
  234.     }
  235.     public function setCodePostal(?string $code_postal): self
  236.     {
  237.         $this->code_postal $code_postal;
  238.         return $this;
  239.     }
  240.     public function getCommune(): ?string
  241.     {
  242.         return $this->commune;
  243.     }
  244.     public function setCommune(?string $commune): self
  245.     {
  246.         $this->commune $commune;
  247.         return $this;
  248.     }
  249.     /**
  250.      * @return Collection|User[]
  251.      */
  252.     public function getUsers(): Collection
  253.     {
  254.         return $this->users;
  255.     }
  256.     public function addUser(User $user): self
  257.     {
  258.         if (!$this->users->contains($user)) {
  259.             $this->users[] = $user;
  260.             $user->addEntreprise($this);
  261.         }
  262.         return $this;
  263.     }
  264.     public function removeUser(User $user): self
  265.     {
  266.         if ($this->users->removeElement($user)) {
  267.             $user->removeEntreprise($this);
  268.         }
  269.         return $this;
  270.     }
  271.     /**
  272.      * @return Collection|Facture[]
  273.      */
  274.     public function getFactures(): Collection
  275.     {
  276.         return $this->factures;
  277.     }
  278.     public function addFacture(Facture $facture): self
  279.     {
  280.         if (!$this->factures->contains($facture)) {
  281.             $this->factures[] = $facture;
  282.             $facture->setEntreprise($this);
  283.         }
  284.         return $this;
  285.     }
  286.     public function removeFacture(Facture $facture): self
  287.     {
  288.         if ($this->factures->removeElement($facture)) {
  289.             // set the owning side to null (unless already changed)
  290.             if ($facture->getEntreprise() === $this) {
  291.                 $facture->setEntreprise(null);
  292.             }
  293.         }
  294.         return $this;
  295.     }
  296. }