src/Entity/Contact.php line 21

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\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  9. /**
  10.  * @ORM\Entity(repositoryClass=ContactRepository::class)
  11.  * @ORM\Table(name="contact", indexes={
  12.  *     @ORM\Index(name="idx_contact_active", columns={"is_active"}),
  13.  *     @ORM\Index(name="idx_contact_client", columns={"linked_client_id"}),
  14.  *     @ORM\Index(name="idx_contact_supplier", columns={"linked_supplier_id"}),
  15.  *     @ORM\Index(name="idx_contact_created_at", columns={"created_at"})
  16.  * })
  17.  */
  18. class Contact
  19. {
  20.     /**
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue
  23.      * @ORM\Column(type="integer")
  24.      */
  25.     private ?int $id null;
  26.     /**
  27.      * @ORM\Column(type="string", length=150, nullable=true)
  28.      * @Assert\Length(max=150)
  29.      */
  30.     private ?string $firstName null;
  31.     /**
  32.      * @ORM\Column(type="string", length=150, nullable=true)
  33.      * @Assert\Length(max=150)
  34.      */
  35.     private ?string $lastName null;
  36.     /**
  37.      * @ORM\Column(type="string", length=30, nullable=true)
  38.      * @Assert\Length(max=30)
  39.      */
  40.     private ?string $phone null;
  41.     /**
  42.      * @ORM\Column(name="second_phone", type="string", length=30, nullable=true)
  43.      * @Assert\Length(max=30)
  44.      */
  45.     private ?string $secondPhone null;
  46.     /**
  47.      * @ORM\Column(type="string", length=180, nullable=true)
  48.      * @Assert\Email
  49.      * @Assert\Length(max=180)
  50.      */
  51.     private ?string $email null;
  52.     /**
  53.      * @ORM\Column(name="company_name", type="string", length=255, nullable=true)
  54.      * @Assert\Length(max=255)
  55.      */
  56.     private ?string $companyName null;
  57.     /**
  58.      * @ORM\Column(name="job_title", type="string", length=180, nullable=true)
  59.      * @Assert\Length(max=180)
  60.      */
  61.     private ?string $jobTitle null;
  62.     /**
  63.      * @ORM\Column(type="text", nullable=true)
  64.      */
  65.     private ?string $address null;
  66.     /**
  67.      * @ORM\Column(name="address2", type="text", nullable=true)
  68.      */
  69.     private ?string $address2 null;
  70.     /**
  71.      * @ORM\Column(type="string", length=150, nullable=true)
  72.      * @Assert\Length(max=150)
  73.      */
  74.     private ?string $city null;
  75.     /**
  76.      * @ORM\Column(type="string", length=150, nullable=true)
  77.      * @Assert\Length(max=150)
  78.      */
  79.     private ?string $region null;
  80.     /**
  81.      * @ORM\Column(name="zip_code", type="string", length=40, nullable=true)
  82.      * @Assert\Length(max=40)
  83.      */
  84.     private ?string $zipCode null;
  85.     /**
  86.      * @ORM\Column(type="string", length=120, nullable=true)
  87.      * @Assert\Length(max=120)
  88.      */
  89.     private ?string $country null;
  90.     /**
  91.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="contacts")
  92.      * @ORM\JoinColumn(name="linked_client_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  93.      */
  94.     private ?User $linkedClient null;
  95.     /**
  96.      * @ORM\ManyToOne(targetEntity=Supplier::class, inversedBy="contacts")
  97.      * @ORM\JoinColumn(name="linked_supplier_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  98.      */
  99.     private ?Supplier $linkedSupplier null;
  100.     /**
  101.      * @ORM\Column(name="is_active", type="boolean", options={"default": true})
  102.      */
  103.     private bool $isActive true;
  104.     /**
  105.      * @ORM\Column(type="text", nullable=true)
  106.      */
  107.     private ?string $notes null;
  108.     /**
  109.      * @ORM\ManyToOne(targetEntity=User::class)
  110.      * @ORM\JoinColumn(name="converted_client_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  111.      */
  112.     private ?User $convertedClient null;
  113.     /**
  114.      * @ORM\Column(name="converted_at", type="datetime", nullable=true)
  115.      */
  116.     private ?\DateTimeInterface $convertedAt null;
  117.     /**
  118.      * @ORM\ManyToOne(targetEntity=User::class)
  119.      * @ORM\JoinColumn(name="converted_by_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  120.      */
  121.     private ?User $convertedBy null;
  122.     /**
  123.      * @ORM\ManyToOne(targetEntity=User::class)
  124.      * @ORM\JoinColumn(name="created_by_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  125.      */
  126.     private ?User $createdBy null;
  127.     /**
  128.      * @ORM\ManyToOne(targetEntity=User::class)
  129.      * @ORM\JoinColumn(name="updated_by_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  130.      */
  131.     private ?User $updatedBy null;
  132.     /**
  133.      * @ORM\Column(name="created_at", type="datetime")
  134.      */
  135.     private ?\DateTimeInterface $createdAt null;
  136.     /**
  137.      * @ORM\Column(name="updated_at", type="datetime", nullable=true)
  138.      */
  139.     private ?\DateTimeInterface $updatedAt null;
  140.     /**
  141.      * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="contact", cascade={"remove"})
  142.      */
  143.     private Collection $comments;
  144.     public function __construct()
  145.     {
  146.         $this->comments = new ArrayCollection();
  147.     }
  148.     /**
  149.      * @Assert\Callback
  150.      */
  151.     public function validateLinking(ExecutionContextInterface $context): void
  152.     {
  153.         if ($this->linkedClient && $this->linkedSupplier) {
  154.             $context->buildViolation('Un contact ne peut pas être lié à un client et à un fournisseur en même temps.')
  155.                 ->atPath('linkedClient')
  156.                 ->addViolation();
  157.         }
  158.     }
  159.     public function getId(): ?int
  160.     {
  161.         return $this->id;
  162.     }
  163.     public function getFirstName(): ?string
  164.     {
  165.         return $this->firstName;
  166.     }
  167.     public function setFirstName(?string $firstName): self
  168.     {
  169.         $this->firstName $firstName;
  170.         return $this;
  171.     }
  172.     public function getLastName(): ?string
  173.     {
  174.         return $this->lastName;
  175.     }
  176.     public function setLastName(?string $lastName): self
  177.     {
  178.         $this->lastName $lastName;
  179.         return $this;
  180.     }
  181.     public function getFullName(): string
  182.     {
  183.         $parts array_filter([
  184.             trim((string) $this->firstName),
  185.             trim((string) $this->lastName),
  186.         ]);
  187.         return trim(implode(' '$parts));
  188.     }
  189.     public function getDisplayName(): string
  190.     {
  191.         $fullName $this->getFullName();
  192.         if ($fullName !== '') {
  193.             return $fullName;
  194.         }
  195.         if ($this->companyName) {
  196.             return trim((string) $this->companyName);
  197.         }
  198.         return 'Contact';
  199.     }
  200.     public function getPhone(): ?string
  201.     {
  202.         return $this->phone;
  203.     }
  204.     public function setPhone(?string $phone): self
  205.     {
  206.         $this->phone $phone;
  207.         return $this;
  208.     }
  209.     public function getSecondPhone(): ?string
  210.     {
  211.         return $this->secondPhone;
  212.     }
  213.     public function setSecondPhone(?string $secondPhone): self
  214.     {
  215.         $this->secondPhone $secondPhone;
  216.         return $this;
  217.     }
  218.     public function getEmail(): ?string
  219.     {
  220.         return $this->email;
  221.     }
  222.     public function setEmail(?string $email): self
  223.     {
  224.         $this->email $email;
  225.         return $this;
  226.     }
  227.     public function getCompanyName(): ?string
  228.     {
  229.         return $this->companyName;
  230.     }
  231.     public function setCompanyName(?string $companyName): self
  232.     {
  233.         $this->companyName $companyName;
  234.         return $this;
  235.     }
  236.     public function getJobTitle(): ?string
  237.     {
  238.         return $this->jobTitle;
  239.     }
  240.     public function setJobTitle(?string $jobTitle): self
  241.     {
  242.         $this->jobTitle $jobTitle;
  243.         return $this;
  244.     }
  245.     public function getAddress(): ?string
  246.     {
  247.         return $this->address;
  248.     }
  249.     public function setAddress(?string $address): self
  250.     {
  251.         $this->address $address;
  252.         return $this;
  253.     }
  254.     public function getAddress2(): ?string
  255.     {
  256.         return $this->address2;
  257.     }
  258.     public function setAddress2(?string $address2): self
  259.     {
  260.         $this->address2 $address2;
  261.         return $this;
  262.     }
  263.     public function getCity(): ?string
  264.     {
  265.         return $this->city;
  266.     }
  267.     public function setCity(?string $city): self
  268.     {
  269.         $this->city $city;
  270.         return $this;
  271.     }
  272.     public function getRegion(): ?string
  273.     {
  274.         return $this->region;
  275.     }
  276.     public function setRegion(?string $region): self
  277.     {
  278.         $this->region $region;
  279.         return $this;
  280.     }
  281.     public function getZipCode(): ?string
  282.     {
  283.         return $this->zipCode;
  284.     }
  285.     public function setZipCode(?string $zipCode): self
  286.     {
  287.         $this->zipCode $zipCode;
  288.         return $this;
  289.     }
  290.     public function getCountry(): ?string
  291.     {
  292.         return $this->country;
  293.     }
  294.     public function setCountry(?string $country): self
  295.     {
  296.         $this->country $country;
  297.         return $this;
  298.     }
  299.     public function getLinkedClient(): ?User
  300.     {
  301.         return $this->linkedClient;
  302.     }
  303.     public function setLinkedClient(?User $linkedClient): self
  304.     {
  305.         $this->linkedClient $linkedClient;
  306.         if ($linkedClient !== null) {
  307.             $this->linkedSupplier null;
  308.         }
  309.         return $this;
  310.     }
  311.     public function getLinkedSupplier(): ?Supplier
  312.     {
  313.         return $this->linkedSupplier;
  314.     }
  315.     public function setLinkedSupplier(?Supplier $linkedSupplier): self
  316.     {
  317.         $this->linkedSupplier $linkedSupplier;
  318.         if ($linkedSupplier !== null) {
  319.             $this->linkedClient null;
  320.         }
  321.         return $this;
  322.     }
  323.     public function getLinkType(): string
  324.     {
  325.         if ($this->linkedClient) {
  326.             return 'client';
  327.         }
  328.         if ($this->linkedSupplier) {
  329.             return 'supplier';
  330.         }
  331.         return 'free';
  332.     }
  333.     public function isActive(): bool
  334.     {
  335.         return $this->isActive;
  336.     }
  337.     public function setIsActive(bool $isActive): self
  338.     {
  339.         $this->isActive $isActive;
  340.         return $this;
  341.     }
  342.     public function getNotes(): ?string
  343.     {
  344.         return $this->notes;
  345.     }
  346.     public function setNotes(?string $notes): self
  347.     {
  348.         $this->notes $notes;
  349.         return $this;
  350.     }
  351.     public function getConvertedClient(): ?User
  352.     {
  353.         return $this->convertedClient;
  354.     }
  355.     public function setConvertedClient(?User $convertedClient): self
  356.     {
  357.         $this->convertedClient $convertedClient;
  358.         return $this;
  359.     }
  360.     public function getConvertedAt(): ?\DateTimeInterface
  361.     {
  362.         return $this->convertedAt;
  363.     }
  364.     public function setConvertedAt(?\DateTimeInterface $convertedAt): self
  365.     {
  366.         $this->convertedAt $convertedAt;
  367.         return $this;
  368.     }
  369.     public function getConvertedBy(): ?User
  370.     {
  371.         return $this->convertedBy;
  372.     }
  373.     public function setConvertedBy(?User $convertedBy): self
  374.     {
  375.         $this->convertedBy $convertedBy;
  376.         return $this;
  377.     }
  378.     public function getCreatedBy(): ?User
  379.     {
  380.         return $this->createdBy;
  381.     }
  382.     public function setCreatedBy(?User $createdBy): self
  383.     {
  384.         $this->createdBy $createdBy;
  385.         return $this;
  386.     }
  387.     public function getUpdatedBy(): ?User
  388.     {
  389.         return $this->updatedBy;
  390.     }
  391.     public function setUpdatedBy(?User $updatedBy): self
  392.     {
  393.         $this->updatedBy $updatedBy;
  394.         return $this;
  395.     }
  396.     public function getCreatedAt(): ?\DateTimeInterface
  397.     {
  398.         return $this->createdAt;
  399.     }
  400.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  401.     {
  402.         $this->createdAt $createdAt;
  403.         return $this;
  404.     }
  405.     public function getUpdatedAt(): ?\DateTimeInterface
  406.     {
  407.         return $this->updatedAt;
  408.     }
  409.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  410.     {
  411.         $this->updatedAt $updatedAt;
  412.         return $this;
  413.     }
  414.     /**
  415.      * @return Collection<int, Comment>
  416.      */
  417.     public function getComments(): Collection
  418.     {
  419.         return $this->comments;
  420.     }
  421.     public function addComment(Comment $comment): self
  422.     {
  423.         if (!$this->comments->contains($comment)) {
  424.             $this->comments[] = $comment;
  425.             $comment->setContact($this);
  426.         }
  427.         return $this;
  428.     }
  429.     public function removeComment(Comment $comment): self
  430.     {
  431.         if ($this->comments->removeElement($comment)) {
  432.             if ($comment->getContact() === $this) {
  433.                 $comment->setContact(null);
  434.             }
  435.         }
  436.         return $this;
  437.     }
  438. }