src/Entity/Contact.php line 12

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