src/Entity/Contact.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ContactRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassContactRepository::class)]
  9. #[ORM\Index(name'idx_contact_type_etat_date'columns: ['contact_type_id''etat''date_creation'])]
  10. class Contact
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $denomination null;
  18.     #[ORM\Column(length9)]
  19.     private ?string $siren null;
  20.     #[ORM\Column(length255)]
  21.     private ?string $nom null;
  22.     #[ORM\Column(length255)]
  23.     private ?string $tel1 null;
  24.     #[ORM\Column(length255)]
  25.     private ?string $email null;
  26.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  27.     private ?\DateTimeInterface $date_creation null;
  28.     #[ORM\Column(name'date_modification'typeTypes::DATETIME_MUTABLEnullabletrue)]
  29.     private ?\DateTimeInterface $datemodification null;
  30.     #[ORM\Column(typeTypes::INTEGERoptions: ['default' => 1])]
  31.     private int $etat 1;
  32.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  33.     private ?array $data null;
  34.     #[ORM\OneToMany(mappedBy'contact'targetEntityObjet::class, cascade: ['remove'])]
  35.     private Collection $objets;
  36.     #[ORM\OneToMany(mappedBy'contact'targetEntityDossier::class, cascade: ['remove'])]
  37.     private Collection $dossiers;
  38.     #[ORM\ManyToOne(inversedBy'contacts')]
  39.     private ?ContactType $contact_type null;
  40.     #[ORM\OneToMany(mappedBy'contact'targetEntityVariableValue::class, cascade: ['remove'])]
  41.     private Collection $variableValues;
  42.     #[ORM\ManyToOne(inversedBy'associatedContacts')]
  43.     #[ORM\JoinColumn(name"parent_contact_id"referencedColumnName"id"nullabletrue)]
  44.     private ?Contact $parentContact null;
  45.     #[ORM\OneToMany(mappedBy'parentContact'targetEntityContact::class, cascade: ['remove'])]
  46.     private Collection $associatedContacts;
  47.     #[ORM\Column(length255nullabletrue)]
  48.     private ?string $compte_client null;
  49.     #[ORM\Column(length255nullabletrue)]
  50.     private ?string $tel2 null;
  51.     #[ORM\Column(length255nullabletrue)]
  52.     private ?string $adresse null;
  53.     #[ORM\Column(length255nullabletrue)]
  54.     private ?string $siret null;
  55.     #[ORM\Column(length255nullabletrue)]
  56.     private ?string $poste null;
  57.     #[ORM\Column(nullabletrue)]
  58.     private ?bool $emailing null;
  59.     #[ORM\Column(nullabletrue)]
  60.     private ?bool $antispam null;
  61.     #[ORM\ManyToOne(inversedBy'contacts')]
  62.     private ?User $utilisateur null;
  63.     #[ORM\OneToMany(mappedBy'contact'targetEntityFichier::class)]
  64.     private Collection $fichiers;
  65.     public function __construct()
  66.     {
  67.         $this->objets = new ArrayCollection();
  68.         $this->dossiers = new ArrayCollection();
  69.         $this->variableValues = new ArrayCollection();
  70.         $this->associatedContacts = new ArrayCollection();
  71.         $this->fichiers = new ArrayCollection();
  72.     }
  73.     public function getId(): ?int
  74.     {
  75.         return $this->id;
  76.     }
  77.     public function getDenomination(): ?string
  78.     {
  79.         return $this->denomination;
  80.     }
  81.     public function setDenomination(string $denomination): static
  82.     {
  83.         $this->denomination $denomination;
  84.         return $this;
  85.     }
  86.     public function getSiren(): ?string
  87.     {
  88.         return $this->siren;
  89.     }
  90.     public function setSiren(string $siren): static
  91.     {
  92.         $this->siren $siren;
  93.         return $this;
  94.     }
  95.     public function getNom(): ?string
  96.     {
  97.         return $this->nom;
  98.     }
  99.     public function setNom(string $nom): static
  100.     {
  101.         $this->nom $nom;
  102.         return $this;
  103.     }
  104.     public function getTel1(): ?string
  105.     {
  106.         return $this->tel1;
  107.     }
  108.     public function setTel1(string $tel1): static
  109.     {
  110.         $this->tel1 $tel1;
  111.         return $this;
  112.     }
  113.     public function getEmail(): ?string
  114.     {
  115.         return $this->email;
  116.     }
  117.     public function setEmail(string $email): static
  118.     {
  119.         $this->email $email;
  120.         return $this;
  121.     }
  122.     public function getDateCreation(): ?\DateTimeInterface
  123.     {
  124.         return $this->date_creation;
  125.     }
  126.     public function setDateCreation(\DateTimeInterface $date_creation): static
  127.     {
  128.         $this->date_creation $date_creation;
  129.         return $this;
  130.     }
  131.     public function getDatemodification(): ?\DateTimeInterface
  132.     {
  133.         return $this->datemodification;
  134.     }
  135.     public function setDatemodification(?\DateTimeInterface $datemodification): static
  136.     {
  137.         $this->datemodification $datemodification;
  138.         return $this;
  139.     }
  140.     public function setObjets(Collection $objets): static
  141.     {
  142.         $this->objets $objets;
  143.         return $this;
  144.     }
  145.     /**
  146.      * @return Collection<int, Objet>
  147.      */
  148.     public function getObjets(): Collection
  149.     {
  150.         return $this->objets;
  151.     }
  152.     /**
  153.      * @return Collection<int, Objet>
  154.      */
  155.     public function getLevelOneObjets(): Collection
  156.     {
  157.         $levelOneObjets = new ArrayCollection();
  158.         foreach ($this->objets as $objet) {
  159.             if (!$objet->getObjet()) {
  160.                 $levelOneObjets->add($objet);
  161.             }
  162.         }
  163.         return $levelOneObjets;
  164.     }
  165.     /**
  166.      * @return Collection<int, Objet>
  167.      */
  168.     public function getObjetsLevelOneObjetType(): Collection
  169.     {
  170.         return $this->objets;
  171.     }
  172.     public function addObjet(Objet $objet): static
  173.     {
  174.         if (!$this->objets->contains($objet)) {
  175.             $this->objets->add($objet);
  176.             $objet->setContact($this);
  177.         }
  178.         return $this;
  179.     }
  180.     public function removeObjet(Objet $objet): static
  181.     {
  182.         if ($this->objets->removeElement($objet)) {
  183.             // set the owning side to null (unless already changed)
  184.             if ($objet->getContact() === $this) {
  185.                 $objet->setContact(null);
  186.             }
  187.         }
  188.         return $this;
  189.     }
  190.     /**
  191.      * @return Collection<int, Dossier>
  192.      */
  193.     public function getDossiers(): Collection
  194.     {
  195.         return $this->dossiers;
  196.     }
  197.     public function addDossier(Dossier $dossier): static
  198.     {
  199.         if (!$this->dossiers->contains($dossier)) {
  200.             $this->dossiers->add($dossier);
  201.             $dossier->setContact($this);
  202.         }
  203.         return $this;
  204.     }
  205.     public function removeDossier(Dossier $dossier): static
  206.     {
  207.         if ($this->dossiers->removeElement($dossier)) {
  208.             // set the owning side to null (unless already changed)
  209.             if ($dossier->getContact() === $this) {
  210.                 $dossier->setContact(null);
  211.             }
  212.         }
  213.         return $this;
  214.     }
  215.     public function getContactType(): ?ContactType
  216.     {
  217.         return $this->contact_type;
  218.     }
  219.     public function setContactType(?ContactType $contact_type): static
  220.     {
  221.         $this->contact_type $contact_type;
  222.         return $this;
  223.     }
  224.     /**
  225.      * @return Collection<int, VariableValue>
  226.      */
  227.     public function getVariableValues(): Collection
  228.     {
  229.         return $this->variableValues;
  230.     }
  231.     public function addVariableValue(VariableValue $variableValue): static
  232.     {
  233.         if (!$this->variableValues->contains($variableValue)) {
  234.             $this->variableValues->add($variableValue);
  235.             $variableValue->setContact($this);
  236.         }
  237.         return $this;
  238.     }
  239.     public function removeVariableValue(VariableValue $variableValue): static
  240.     {
  241.         if ($this->variableValues->removeElement($variableValue)) {
  242.             // set the owning side to null (unless already changed)
  243.             if ($variableValue->getContact() === $this) {
  244.                 $variableValue->setContact(null);
  245.             }
  246.         }
  247.         return $this;
  248.     }
  249.     public function getParentContact(): ?Contact
  250.     {
  251.         return $this->parentContact;
  252.     }
  253.     public function setParentContact(?Contact $parentContact): static
  254.     {
  255.         $this->parentContact $parentContact;
  256.         return $this;
  257.     }
  258.     public function setAssociatedContacts(Collection $associatedContacts): static
  259.     {
  260.         $this->associatedContacts $associatedContacts;
  261.         return $this;
  262.     }
  263.     /**
  264.      * @return Collection<int, Contact>
  265.      */
  266.     public function getAssociatedContacts(): Collection
  267.     {
  268.         return $this->associatedContacts;
  269.     }
  270.     public function addAssociatedContact(Contact $associatedContact): static
  271.     {
  272.         if (!$this->associatedContacts->contains($associatedContact)) {
  273.             $this->associatedContacts->add($associatedContact);
  274.             $associatedContact->setParentContact($this);
  275.         }
  276.         return $this;
  277.     }
  278.     public function removeAssociatedContact(Contact $associatedContact): static
  279.     {
  280.         if ($this->associatedContacts->removeElement($associatedContact)) {
  281.             $associatedContact->setParentContact(null);
  282.         }
  283.         return $this;
  284.     }
  285.     public function getCompteClient(): ?string
  286.     {
  287.         return $this->compte_client;
  288.     }
  289.     public function setCompteClient(?string $compte_client): static
  290.     {
  291.         $this->compte_client $compte_client;
  292.         return $this;
  293.     }
  294.     public function getTel2(): ?string
  295.     {
  296.         return $this->tel2;
  297.     }
  298.     public function setTel2(?string $tel2): static
  299.     {
  300.         $this->tel2 $tel2;
  301.         return $this;
  302.     }
  303.     public function getAdresse(): ?string
  304.     {
  305.         return $this->adresse;
  306.     }
  307.     public function setAdresse(?string $adresse): static
  308.     {
  309.         $this->adresse $adresse;
  310.         return $this;
  311.     }
  312.     public function getSiret(): ?string
  313.     {
  314.         return $this->siret;
  315.     }
  316.     public function setSiret(?string $siret): static
  317.     {
  318.         $this->siret $siret;
  319.         return $this;
  320.     }
  321.     public function getPoste(): ?string
  322.     {
  323.         return $this->poste;
  324.     }
  325.     public function setPoste(?string $poste): static
  326.     {
  327.         $this->poste $poste;
  328.         return $this;
  329.     }
  330.     public function isEmailing(): ?bool
  331.     {
  332.         return $this->emailing;
  333.     }
  334.     public function setEmailing(?bool $emailing): static
  335.     {
  336.         $this->emailing $emailing;
  337.         return $this;
  338.     }
  339.     public function isAntispam(): ?bool
  340.     {
  341.         return $this->antispam;
  342.     }
  343.     public function setAntispam(?bool $antispam): static
  344.     {
  345.         $this->antispam $antispam;
  346.         return $this;
  347.     }
  348.     public function getUtilisateur(): ?User
  349.     {
  350.         return $this->utilisateur;
  351.     }
  352.     public function setUtilisateur(?User $utilisateur): static
  353.     {
  354.         $this->utilisateur $utilisateur;
  355.         return $this;
  356.     }
  357.     /**
  358.      * @return Collection<int, Fichier>
  359.      */
  360.     public function getFichiers(): Collection
  361.     {
  362.         return $this->fichiers;
  363.     }
  364.     public function addFichier(Fichier $fichier): static
  365.     {
  366.         if (!$this->fichiers->contains($fichier)) {
  367.             $this->fichiers->add($fichier);
  368.             $fichier->setContact($this);
  369.         }
  370.         return $this;
  371.     }
  372.     public function removeFichier(Fichier $fichier): static
  373.     {
  374.         if ($this->fichiers->removeElement($fichier)) {
  375.             // set the owning side to null (unless already changed)
  376.             if ($fichier->getContact() === $this) {
  377.                 $fichier->setContact(null);
  378.             }
  379.         }
  380.         return $this;
  381.     }
  382.     public function __toString()
  383.     {
  384.         return (string) $this->id;  // Ou une autre propriété qui représente bien l'objet
  385.     }
  386.     public function getEtat(): int
  387.     {
  388.         return $this->etat;
  389.     }
  390.     public function setEtat(int $etat): static
  391.     {
  392.         $this->etat $etat;
  393.         return $this;
  394.     }
  395.     public function getData(): ?array
  396.     {
  397.         return $this->data;
  398.     }
  399.     public function setData(?array $data): static
  400.     {
  401.         $this->data $data;
  402.         return $this;
  403.     }
  404.     /**
  405.      * Get the public URL for this contact
  406.      *
  407.      * @param string|null $baseUrl Base URL for the application
  408.      * @return string Full URL to contact show page
  409.      */
  410.     public function getLienUrl(?string $baseUrl null): string
  411.     {
  412.         if ($baseUrl === null) {
  413.             // Auto-detect base URL from request if available
  414.             if (isset($_SERVER['HTTP_HOST'])) {
  415.                 $scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' 'https' 'http';
  416.                 $baseUrl $scheme '://' $_SERVER['HTTP_HOST'];
  417.             } else {
  418.                 // Fallback to environment-based URL
  419.                 $env $_ENV['APP_ENV'] ?? 'dev';
  420.                 $baseUrl $env === 'prod'
  421.                     ? ($_ENV['APP_URL_PROD'] ?? 'https://evapi.click')
  422.                     : ($_ENV['APP_URL_DEV'] ?? 'http://localhost');
  423.             }
  424.         }
  425.         return rtrim($baseUrl'/') . '/contact/' $this->id;
  426.     }
  427.     /**
  428.      * Get QR code as base64 encoded PNG image
  429.      *
  430.      * @param int $size Image size in pixels (default: 150)
  431.      * @return string Base64 encoded PNG image with data URI prefix
  432.      */
  433.     public function getQrCode(int $size 150): string
  434.     {
  435.         $qrCodeGenerator = new \App\Service\QRCodeGenerator();
  436.         return $qrCodeGenerator->generateBase64($this->getLienUrl(), $size);
  437.     }
  438. }