src/Entity/Customer.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Repository\CustomerRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Ksante\CoreBundle\Entity\Channel;
  10. use Ksante\CoreBundle\Entity\Traits\TimestampableTrait;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14.  * @ORM\Entity(repositoryClass=CustomerRepository::class)
  15.  *
  16.  * @ORM\Table(
  17.  *     name="ksante_customer",
  18.  *     uniqueConstraints={
  19.  *
  20.  *        @ORM\UniqueConstraint(name="customer_for_channel",
  21.  *            columns={"email", "channel_id", "external_id"})
  22.  *     })
  23.  *
  24.  * @ORM\HasLifecycleCallbacks()
  25.  *
  26.  * @ApiResource(normalizationContext={"groups"={"CustomerGroup"}})
  27.  */
  28. class Customer
  29. {
  30.     use TimestampableTrait;
  31.     /**
  32.      * @ORM\Id
  33.      *
  34.      * @ORM\GeneratedValue
  35.      *
  36.      * @ORM\Column(type="integer")
  37.      *
  38.      * @Groups({"CustomerGroup"})
  39.      */
  40.     private $id;
  41.     /**
  42.      * @ORM\Column(type="string", nullable=false)
  43.      *
  44.      * @Groups({"customer:read", "CustomerGroup","read", "write", "create", "front-read"})
  45.      */
  46.     private string $externalId;
  47.     /**
  48.      * @ORM\Column(type="string")
  49.      *
  50.      * @Groups({"CustomerGroup", "write", "create"})
  51.      *
  52.      * @Assert\NotBlank
  53.      */
  54.     private ?string $firstName null;
  55.     /**
  56.      * @ORM\Column(type="string")
  57.      *
  58.      * @Groups({"CustomerGroup","write", "create"})
  59.      */
  60.     private ?string $lastName null;
  61.     /**
  62.      * @ORM\Column(type="string")
  63.      *
  64.      * @Groups({"CustomerGroup","write", "create"})
  65.      *
  66.      * @Assert\Email
  67.      *
  68.      * @Assert\NotBlank
  69.      */
  70.     private ?string $email null;
  71.     /**
  72.      * @ORM\Column(type="string", nullable=true)
  73.      *
  74.      * @Groups({"CustomerGroup","write", "create"})
  75.      */
  76.     private ?string $phoneNumber null;
  77.     /**
  78.      * @ORM\Column(type="string", nullable=true)
  79.      *
  80.      * @Groups({"CustomerGroup","write", "create"})
  81.      */
  82.     private string $activity;
  83.     /**
  84.      * @ORM\OneToMany(targetEntity=AppointmentResume::class, mappedBy="customer")
  85.      */
  86.     private Collection $appointmentsResume;
  87.     /**
  88.      * @ORM\Column(type="integer", options={"default"=0})
  89.      *
  90.      * @Groups({"CustomerGroup", "write", "create"})
  91.      */
  92.     private int $appointmentCredit 0;
  93.     /**
  94.      * @ORM\Column(type="integer", options={"default"=0})
  95.      *
  96.      * @Groups({"CustomerGroup", "write", "create"})
  97.      */
  98.     private int $pastAppointments 0;
  99.     /**
  100.      * @ORM\Column(type="integer", options={"default"=0})
  101.      *
  102.      * @Groups({"CustomerGroup", "write", "create"})
  103.      */
  104.     private int $cancelledAppointments 0;
  105.     /**
  106.      * @ORM\ManyToOne(targetEntity=Diet::class, inversedBy="customers")
  107.      *
  108.      * @ORM\JoinColumn(nullable=true , referencedColumnName="id", onDelete="SET NULL")
  109.      *
  110.      * @Groups({"CustomerGroup","read", "write", "create"})
  111.      */
  112.     private ?Diet $diet null;
  113.     /**
  114.      * @ORM\ManyToOne(targetEntity=Channel::class)
  115.      *
  116.      * @ORM\JoinColumn(nullable=true , referencedColumnName="id")
  117.      *
  118.      * @Groups({"CustomerGroup", "write", "create","front-read"})
  119.      */
  120.     private Channel $channel;
  121.     /**
  122.      * @ORM\OneToMany(targetEntity=Appointment::class, mappedBy="customer")
  123.      */
  124.     private Collection $appointments;
  125.     public function __construct()
  126.     {
  127.         $this->appointments = new ArrayCollection();
  128.         $this->appointmentsResume = new ArrayCollection();
  129.     }
  130.     public function getId(): ?int
  131.     {
  132.         return $this->id;
  133.     }
  134.     public function getChannel(): Channel
  135.     {
  136.         return $this->channel;
  137.     }
  138.     public function setChannel(Channel $channel): self
  139.     {
  140.         $this->channel $channel;
  141.         return $this;
  142.     }
  143.     public function getExternalId(): string
  144.     {
  145.         return $this->externalId;
  146.     }
  147.     public function setExternalId(string $externalId): self
  148.     {
  149.         $this->externalId $externalId;
  150.         return $this;
  151.     }
  152.     public function getFirstName(): ?string
  153.     {
  154.         return $this->firstName;
  155.     }
  156.     public function setFirstName(string $firstName): self
  157.     {
  158.         $this->firstName $firstName;
  159.         return $this;
  160.     }
  161.     public function getLastName(): ?string
  162.     {
  163.         return $this->lastName;
  164.     }
  165.     public function setLastName(string $lastName): self
  166.     {
  167.         $this->lastName $lastName;
  168.         return $this;
  169.     }
  170.     public function getEmail(): ?string
  171.     {
  172.         return $this->email;
  173.     }
  174.     public function setEmail(string $email): self
  175.     {
  176.         $this->email $email;
  177.         return $this;
  178.     }
  179.     public function getPhone(): ?string
  180.     {
  181.         return $this->phoneNumber;
  182.     }
  183.     public function setPhone(?string $phone): self
  184.     {
  185.         $this->phoneNumber $phone;
  186.         return $this;
  187.     }
  188.     public function getActivity(): ?string
  189.     {
  190.         return $this->activity;
  191.     }
  192.     public function setActivity(string $activity): self
  193.     {
  194.         $this->activity $activity;
  195.         return $this;
  196.     }
  197.     public function getAppointmentCredit(): ?int
  198.     {
  199.         return $this->appointmentCredit;
  200.     }
  201.     public function setAppointmentCredit(?int $appointmentCredit): self
  202.     {
  203.         $this->appointmentCredit $appointmentCredit;
  204.         return $this;
  205.     }
  206.     public function incrementAppointmentCredit(): void
  207.     {
  208.         ++$this->appointmentCredit;
  209.     }
  210.     public function getPastAppointments(): ?int
  211.     {
  212.         return $this->pastAppointments;
  213.     }
  214.     public function setPastAppointments(?int $pastAppointments): self
  215.     {
  216.         $this->pastAppointments $pastAppointments;
  217.         return $this;
  218.     }
  219.     public function getCancelledAppointments(): ?int
  220.     {
  221.         return $this->cancelledAppointments;
  222.     }
  223.     public function setCancelledAppointments(int $cancelledAppointments): self
  224.     {
  225.         $this->cancelledAppointments $cancelledAppointments;
  226.         return $this;
  227.     }
  228.     public function getDiet(): ?Diet
  229.     {
  230.         return $this->diet;
  231.     }
  232.     public function setDiet(?Diet $diet): self
  233.     {
  234.         $this->diet $diet;
  235.         return $this;
  236.     }
  237.     public function hasDiet(): bool
  238.     {
  239.         return null === $this->diet false true;
  240.     }
  241.     /**
  242.      * @return Appointment[]|Collection
  243.      */
  244.     public function getAppointments(): Collection
  245.     {
  246.         return $this->appointments;
  247.     }
  248.     public function addAppointment(Appointment $appointment): self
  249.     {
  250.         if (!$this->appointments->contains($appointment)) {
  251.             $this->appointments[] = $appointment;
  252.             $appointment->setCustomer($this);
  253.         }
  254.         return $this;
  255.     }
  256.     public function removeAppointment(Appointment $appointment): self
  257.     {
  258.         if ($this->appointments->removeElement($appointment)) {
  259.             // set the owning side to null (unless already changed)
  260.             if ($appointment->getCustomer() === $this) {
  261.                 $appointment->setCustomer(null);
  262.             }
  263.         }
  264.         return $this;
  265.     }
  266.     /**
  267.      * @return AppointmentResume[]|Collection
  268.      */
  269.     public function getAppointmentsResume(): Collection
  270.     {
  271.         return $this->appointments;
  272.     }
  273.     public function addAppointmentResume(AppointmentResume $appointmentResume): self
  274.     {
  275.         if ($this->appointmentsResume->contains($appointmentResume)) {
  276.             return $this;
  277.         }
  278.         $this->appointmentsResume[] = $appointmentResume;
  279.         $appointmentResume->setCustomer($this);
  280.         return $this;
  281.     }
  282.     public function removeAppointmentResume(AppointmentResume $appointmentResume): self
  283.     {
  284.         if ($this->appointmentsResume->removeElement($appointmentResume)) {
  285.             // set the owning side to null (unless already changed)
  286.             if ($appointmentResume->getCustomer() === $this) {
  287.                 $appointmentResume->setCustomer(null);
  288.             }
  289.         }
  290.         return $this;
  291.     }
  292.     public function getLastAppointment(Channel $channel)
  293.     {
  294.         foreach ($this->getAppointments() as $appointment) {
  295.             if (Appointment::STATUS_PRE_BOOK == $appointment->getStatus() && $appointment->getChannel() === $channel) {
  296.                 return $appointment;
  297.             }
  298.         }
  299.         return null;
  300.     }
  301. }