src/Entity/Customer.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  6. use ApiPlatform\Metadata\ApiFilter;
  7. use App\Filter\SearchFilter;
  8. use App\Repository\CustomerRepository;
  9. use DateTimeImmutable;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Gedmo\Mapping\Annotation as Gedmo;
  14. use JetBrains\PhpStorm\Pure;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. #[ORM\Entity(repositoryClassCustomerRepository::class)]
  17. #[ApiResource(
  18.     denormalizationContext: ['groups' => ['customer']],
  19.     normalizationContext: ['groups' => ['customer']],
  20.     security"is_granted('ROLE_ADMIN')",
  21. )]
  22. #[ApiFilter(OrderFilter::class)]
  23. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  24. #[ApiFilter(SearchFilter::class, properties: ['email''firstName''lastName''phoneNumber''ponds.address1''ponds.postcode'])]
  25. class Customer
  26. {
  27.     #[ORM\Id]
  28.     #[ORM\GeneratedValue]
  29.     #[ORM\Column(type'integer')]
  30.     #[Groups(['customer''messageLog''schedule'])]
  31.     private int $id;
  32.     #[ORM\Column(type'string'length255nullabletrue)]
  33.     #[Groups(['customer''messageLog''schedule'])]
  34.     private ?string $email;
  35.     #[ORM\Column(type'string'length255)]
  36.     #[Groups(['customer''messageLog''schedule''job''pond''serviceCampaignRecipient'])]
  37.     private string $firstName;
  38.     #[ORM\Column(type'string'length255nullabletrue)]
  39.     #[Groups(['customer''messageLog''schedule''job''pond''serviceCampaignRecipient'])]
  40.     private ?string $lastName null;
  41.     #[ORM\Column(type'string'length255)]
  42.     #[Groups(['customer''messageLog''schedule''serviceCampaignRecipient'])]
  43.     private string $phoneNumber;
  44.     #[ORM\Column(options: ["default" => 0])]
  45.     #[ApiProperty(attributes: ["openapi_context" => ["type" => "boolean""default" => "false"]])]
  46.     #[Groups(['customer''messageLog'])]
  47.     private bool $consentToMarketing false;
  48.     #[ORM\Column(type'integer'length1options: ["default" => 0])]
  49.     #[Groups(['customer''messageLog''schedule'])]
  50.     private int $communicationPreference;
  51.     #[ORM\Column(type'text'nullabletrue)]
  52.     #[Groups(['customer''schedule'])]
  53.     private ?string $notes;
  54.     #[ORM\OneToMany(mappedBy'customer'targetEntityPond::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  55.     #[Groups('customer')]
  56.     private Collection $ponds;
  57.     #[ORM\OneToMany(mappedBy'customer'targetEntityMessageLog::class)]
  58.     #[Groups('customer')]
  59.     private Collection $messageLogs;
  60.     #[Gedmo\Timestampable(on'create')]
  61.     #[ORM\Column(type'datetime_immutable')]
  62.     private DateTimeImmutable $createdAt;
  63.     #[Gedmo\Timestampable]
  64.     #[ORM\Column(type'datetime_immutable')]
  65.     private DateTimeImmutable $updatedAt;
  66.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  67.     private ?DateTimeImmutable $deletedAt;
  68.     #[Pure] public function __construct()
  69.     {
  70.         $this->ponds = new ArrayCollection();
  71.         $this->messageLogs = new ArrayCollection();
  72.     }
  73.     public function getId(): int
  74.     {
  75.         return $this->id;
  76.     }
  77.     public function getEmail(): ?string
  78.     {
  79.         return $this->email;
  80.     }
  81.     public function setEmail(?string $email): self
  82.     {
  83.         $this->email $email;
  84.         return $this;
  85.     }
  86.     public function getFirstName(): string
  87.     {
  88.         return $this->firstName;
  89.     }
  90.     public function setFirstName(string $firstName): self
  91.     {
  92.         $this->firstName $firstName;
  93.         return $this;
  94.     }
  95.     public function getLastName(): ?string
  96.     {
  97.         return $this->lastName;
  98.     }
  99.     public function setLastName(?string $lastName): self
  100.     {
  101.         $this->lastName $lastName;
  102.         return $this;
  103.     }
  104.     public function getPhoneNumber(): string
  105.     {
  106.         return $this->phoneNumber;
  107.     }
  108.     public function setPhoneNumber(string $phoneNumber): self
  109.     {
  110.         $this->phoneNumber $phoneNumber;
  111.         return $this;
  112.     }
  113.     public function hasConsentToMarketing(): bool
  114.     {
  115.         return $this->consentToMarketing;
  116.     }
  117.     public function setConsentToMarketing(int $consentToMarketing): self
  118.     {
  119.         $this->consentToMarketing $consentToMarketing;
  120.         return $this;
  121.     }
  122.     public function getCommunicationPreference(): int
  123.     {
  124.         return $this->communicationPreference;
  125.     }
  126.     public function setCommunicationPreference(int $communicationPreference): self
  127.     {
  128.         $this->communicationPreference $communicationPreference;
  129.         return $this;
  130.     }
  131.     public function getNotes(): ?string
  132.     {
  133.         return $this->notes;
  134.     }
  135.     public function setNotes(?string $notes): void
  136.     {
  137.         $this->notes $notes;
  138.     }
  139.     public function getPonds(): Collection
  140.     {
  141.         return $this->ponds;
  142.     }
  143.     public function addPond(Pond $pond): self
  144.     {
  145.         if (!$this->ponds->contains($pond)) {
  146.             $this->ponds[] = $pond;
  147.             $pond->setCustomer($this);
  148.         }
  149.         return $this;
  150.     }
  151.     public function removePond(Pond $pond): self
  152.     {
  153.         $this->ponds->removeElement($pond);
  154.         return $this;
  155.     }
  156.     public function getMessageLogs(): Collection
  157.     {
  158.         return $this->messageLogs;
  159.     }
  160.     public function addMessageLog(MessageLog $messageLog): self
  161.     {
  162.         if (!$this->messageLogs->contains($messageLog)) {
  163.             $this->messageLogs[] = $messageLog;
  164.             $messageLog->setCustomer($this);
  165.         }
  166.         return $this;
  167.     }
  168.     public function removeMessageLog(MessageLog $messageLog): self
  169.     {
  170.         if ($this->messageLogs->removeElement($messageLog)) {
  171.             // set the owning side to null (unless already changed)
  172.             if ($messageLog->getCustomer() === $this) {
  173.                 $messageLog->setCustomer(null);
  174.             }
  175.         }
  176.         return $this;
  177.     }
  178.     public function getCreatedAt(): DateTimeImmutable
  179.     {
  180.         return $this->createdAt;
  181.     }
  182.     public function getUpdatedAt(): DateTimeImmutable
  183.     {
  184.         return $this->updatedAt;
  185.     }
  186.     public function getDeletedAt(): ?DateTimeImmutable
  187.     {
  188.         return $this->deletedAt;
  189.     }
  190. }