src/Entity/Patient.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PatientRepository;
  4. use Boab\CmsBundle\Entity\User;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassPatientRepository::class)]
  9. class Patient extends User implements PatientInterface
  10. {
  11.     const ROLE_DEFAULT 'ROLE_PATIENT';
  12.     const USER_TYPE "patient";
  13.     #[ORM\OneToMany(mappedBy'client'targetEntityAppointment::class)]
  14.     private Collection $appointments;
  15.     #[ORM\OneToMany(mappedBy'createdBy'targetEntityReview::class)]
  16.     private Collection $reviews;
  17.     public function __construct()
  18.     {
  19.         parent::__construct();
  20.         $this->appointments = new ArrayCollection();
  21.         $this->reviews = new ArrayCollection();
  22.     }
  23.     use UserTrait;
  24.     /**
  25.      * Get role
  26.      *
  27.      * @return array
  28.      */
  29.     public function getRoles():array
  30.     {
  31.         return array_unique(array_merge(parent::getRoles(), [self::ROLE_DEFAULT]));
  32.     }
  33.     /**
  34.      * @return Collection<int, Appointment>
  35.      */
  36.     public function getAppointments(): Collection
  37.     {
  38.         return $this->appointments;
  39.     }
  40.     public function addAppointment(Appointment $appointment): self
  41.     {
  42.         if (!$this->appointments->contains($appointment)) {
  43.             $this->appointments->add($appointment);
  44.             $appointment->setClient($this);
  45.         }
  46.         return $this;
  47.     }
  48.     public function removeAppointment(Appointment $appointment): self
  49.     {
  50.         if ($this->appointments->removeElement($appointment)) {
  51.             // set the owning side to null (unless already changed)
  52.             if ($appointment->getClient() === $this) {
  53.                 $appointment->setClient(null);
  54.             }
  55.         }
  56.         return $this;
  57.     }
  58.     /**
  59.      * @return Collection<int, Review>
  60.      */
  61.     public function getReviews(): Collection
  62.     {
  63.         return $this->reviews;
  64.     }
  65.     public function addReview(Review $review): static
  66.     {
  67.         if (!$this->reviews->contains($review)) {
  68.             $this->reviews->add($review);
  69.             $review->setCreatedBy($this);
  70.         }
  71.         return $this;
  72.     }
  73.     public function removeReview(Review $review): static
  74.     {
  75.         if ($this->reviews->removeElement($review)) {
  76.             // set the owning side to null (unless already changed)
  77.             if ($review->getCreatedBy() === $this) {
  78.                 $review->setCreatedBy(null);
  79.             }
  80.         }
  81.         return $this;
  82.     }  
  83.     
  84.     public function getUserType(): string 
  85.     {
  86.         return 'Client';
  87.     } 
  88.     
  89.     public function getWhatsappFormatNumber(): ?string
  90.     {
  91.         $phone_number ltrim($this->whatsappNumber'0');   
  92.         // Prepend '233' if not already present
  93.         if (strpos($phone_number'233') !== 0) {
  94.             $phone_number '233' $phone_number;
  95.         }
  96.         
  97.         return $phone_number;
  98.     }
  99. }