src/Entity/Stakeholder.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimestampableTrait;
  4. use App\Repository\StakeholderRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Uid\Uuid;
  10. #[ORM\Entity(repositoryClassStakeholderRepository::class)]
  11. #[ORM\Table(name'stakeholder')]
  12. #[ORM\UniqueConstraint(
  13.     name'unique_email_firm_category',
  14.     columns: ['email''accounting_firm_id''stakeholder_category_id']
  15. )]
  16. #[UniqueEntity(
  17.     fields: ['email''accountingFirm''stakeholderCategory'],
  18.     errorPath'email',
  19.     message'Cet email existe déjà.'
  20. )]
  21. class Stakeholder
  22. {
  23.     use TimestampableTrait;
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue]
  26.     #[ORM\Column(type'integer')]
  27.     private $id;
  28.     #[ORM\ManyToOne(targetEntityAccountingFirm::class, inversedBy'stakeholders')]
  29.     #[ORM\JoinColumn(nullablefalse)]
  30.     private $accountingFirm;
  31.     #[ORM\Column(type'string'length255nullabletrue)]
  32.     private $companyName;
  33.     #[ORM\Column(type'string'length255nullabletrue)]
  34.     private $lastname;
  35.     #[ORM\Column(type'string'length255nullabletrue)]
  36.     private $firstname;
  37.     #[ORM\Column(type'string'length255nullabletrue)]
  38.     private $email;
  39.     #[ORM\Column(type'string'length255nullabletrue)]
  40.     private $phone;
  41.     #[ORM\Column(type'date'nullabletrue)]
  42.     private $birthdayDate;
  43.     #[ORM\Column(type'text'nullabletrue)]
  44.     private $description;
  45.     #[ORM\Column(type'uuid'uniquetruenullabletrue)]
  46.     private ?Uuid $token null;
  47.     // Stocke un tableau de couples [email => uuid]
  48.     #[ORM\Column(type'json')]
  49.     private $listEmails = [];
  50.     #[ORM\ManyToOne(targetEntityStakeholderCategory::class, inversedBy'stakeholders')]
  51.     #[ORM\JoinColumn(nullablefalse)]
  52.     private $stakeholderCategory;
  53.     #[ORM\ManyToMany(targetEntityStakeholderTag::class, inversedBy'stakeholders')]
  54.     private $stakeholderTags;
  55.     #[ORM\OneToMany(mappedBy'stakeholder'targetEntityStakeholderSubscription::class, orphanRemovaltrue)]
  56.     private Collection $stakeholderSubscriptions;
  57.     public function __construct()
  58.     {
  59.         $this->stakeholderTags = new ArrayCollection();
  60.         $this->stakeholderSubscriptions = new ArrayCollection();
  61.         $this->token Uuid::v4();
  62.     }
  63.     public function getId(): ?int
  64.     {
  65.         return $this->id;
  66.     }
  67.     public function getAccountingFirm(): ?AccountingFirm
  68.     {
  69.         return $this->accountingFirm;
  70.     }
  71.     public function setAccountingFirm(?AccountingFirm $accountingFirm): self
  72.     {
  73.         $this->accountingFirm $accountingFirm;
  74.         return $this;
  75.     }
  76.     public function getCompanyName(): ?string
  77.     {
  78.         return $this->companyName;
  79.     }
  80.     public function setCompanyName(?string $companyName): self
  81.     {
  82.         $this->companyName $companyName;
  83.         return $this;
  84.     }
  85.     public function getLastname(): ?string
  86.     {
  87.         return $this->lastname;
  88.     }
  89.     public function setLastname(?string $lastname): self
  90.     {
  91.         $this->lastname $lastname;
  92.         return $this;
  93.     }
  94.     public function getFirstname(): ?string
  95.     {
  96.         return $this->firstname;
  97.     }
  98.     public function setFirstname(?string $firstname): self
  99.     {
  100.         $this->firstname $firstname;
  101.         return $this;
  102.     }
  103.     public function getEmail(): ?string
  104.     {
  105.         return $this->email;
  106.     }
  107.     public function setEmail(?string $email): self
  108.     {
  109.         $this->email $email;
  110.         return $this;
  111.     }
  112.     public function getPhone(): ?string
  113.     {
  114.         return $this->phone;
  115.     }
  116.     public function setPhone(?string $phone): self
  117.     {
  118.         $this->phone $phone;
  119.         return $this;
  120.     }
  121.     public function getBirthdayDate(): ?\DateTimeInterface
  122.     {
  123.         return $this->birthdayDate;
  124.     }
  125.     public function setBirthdayDate(?\DateTimeInterface $birthdayDate): self
  126.     {
  127.         $this->birthdayDate $birthdayDate;
  128.         return $this;
  129.     }
  130.     public function getDescription(): ?string
  131.     {
  132.         return $this->description;
  133.     }
  134.     public function setDescription(?string $description): self
  135.     {
  136.         $this->description $description;
  137.         return $this;
  138.     }
  139.     public function getToken(): ?Uuid
  140.     {
  141.         return $this->token;
  142.     }
  143.     public function setToken(Uuid $token): self
  144.     {
  145.         $this->token $token;
  146.         return $this;
  147.     }
  148.     public function getListEmails(): array
  149.     {
  150.         return $this->listEmails;
  151.     }
  152.     public function setListEmails(array $listEmails): self
  153.     {
  154.         $this->listEmails $listEmails;
  155.         return $this;
  156.     }
  157.     public function addAtListIfNotExist(string $emailstring $token): self
  158.     {
  159.         foreach ($this->listEmails as $entry) {
  160.             // Anti-doublon par email OU par token
  161.             if (
  162.                 (isset($entry['email']) && strtolower($entry['email']) === strtolower($email)) ||
  163.                 (isset($entry['token']) && $entry['token'] === $token)
  164.             ) {
  165.                 return $this;
  166.             }
  167.         }
  168.         $this->listEmails[] = [
  169.             'email' => $email,
  170.             'token' => $token,
  171.         ];
  172.         return $this;
  173.     }
  174.     public function getStakeholderCategory(): ?StakeholderCategory
  175.     {
  176.         return $this->stakeholderCategory;
  177.     }
  178.     public function setStakeholderCategory(?StakeholderCategory $stakeholderCategory): self
  179.     {
  180.         $this->stakeholderCategory $stakeholderCategory;
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return Collection<int, StakeholderTag>
  185.      */
  186.     public function getStakeholderTags(): Collection
  187.     {
  188.         return $this->stakeholderTags;
  189.     }
  190.     public function addStakeholderTag(StakeholderTag $stakeholderTag): self
  191.     {
  192.         if (!$this->stakeholderTags->contains($stakeholderTag)) {
  193.             $this->stakeholderTags[] = $stakeholderTag;
  194.         }
  195.         return $this;
  196.     }
  197.     public function removeStakeholderTag(StakeholderTag $stakeholderTag): self
  198.     {
  199.         $this->stakeholderTags->removeElement($stakeholderTag);
  200.         return $this;
  201.     }
  202.     public function isSubscribedToNewsletter(): bool
  203.     {
  204.         foreach ($this->stakeholderSubscriptions as $subscription) {
  205.             if ($subscription->getSubscriptionType()->getSlug() === StakeholderSubscriptionType::NEWSLETTER) {
  206.                 return $subscription->isSubscribed();
  207.             }
  208.         }
  209.         return false;
  210.     }
  211. }