src/Entity/ClinicalManager/ClinicalManager.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\ClinicalManager;
  4. use App\Entity\Customer\Customer;
  5. use App\Entity\Doctor\Doctor;
  6. use App\Entity\Order\Order;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Timestampable\Traits\TimestampableEntity;
  11. use Sylius\Component\Resource\Model\ResourceInterface;
  12. use function array_unique;
  13. use function array_values;
  14. use function in_array;
  15. #[ORM\Table(name'app_clinical_manager')]
  16. #[ORM\Entity]
  17. class ClinicalManager implements ResourceInterface
  18. {
  19.     use TimestampableEntity;
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column(type'integer')]
  23.     private int|null $id null;
  24.     #[ORM\Column(name'requires_validation_by_clinical_manager'type'boolean'options: ['default' => false])]
  25.     private bool $requiresValidationByClinicalManager false;
  26.     #[ORM\OneToOne(mappedBy'clinicalManager'targetEntityCustomer::class)]
  27.     private Customer $customer;
  28.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'attachedClinicalManagers')]
  29.     #[ORM\JoinColumn(name'attached_clinical_manager_id'nullabletrueonDelete'SET NULL')]
  30.     private ClinicalManager|null $attachedClinicalManager null;
  31.     #[ORM\OneToMany(mappedBy'attachedClinicalManager'targetEntityself::class, cascade: ['all'], orphanRemovaltrue)]
  32.     private Collection $attachedClinicalManagers;
  33.     #[ORM\OneToMany(mappedBy'clinicalManagerWhoValidated'targetEntityOrder::class, cascade: ['all'], orphanRemovaltrue)]
  34.     private Collection $validatedOrders;
  35.     #[ORM\OneToMany(mappedBy'attachedClinicalManager'targetEntityDoctor::class, cascade: ['all'], orphanRemovaltrue)]
  36.     private Collection $attachedDoctors;
  37.     public function __construct()
  38.     {
  39.         $this->validatedOrders = new ArrayCollection();
  40.         $this->attachedDoctors = new ArrayCollection();
  41.         $this->attachedClinicalManagers = new ArrayCollection();
  42.     }
  43.     public function getId(): int|null
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getCustomer(): Customer
  48.     {
  49.         return $this->customer;
  50.     }
  51.     public function setCustomer(Customer $customer): void
  52.     {
  53.         $this->customer $customer;
  54.     }
  55.     public function getAttachedClinicalManager(): ClinicalManager|null
  56.     {
  57.         return $this->attachedClinicalManager;
  58.     }
  59.     public function setAttachedClinicalManager(ClinicalManager|null $attachedClinicalManager): void
  60.     {
  61.         $this->attachedClinicalManager $attachedClinicalManager;
  62.     }
  63.     /** @return Collection<array-key, Order> */
  64.     public function getValidatedOrders(): Collection
  65.     {
  66.         return $this->validatedOrders;
  67.     }
  68.     /** @param Collection<array-key, Order> $validatedOrders */
  69.     public function setValidatedOrders(Collection $validatedOrders): void
  70.     {
  71.         $this->validatedOrders $validatedOrders;
  72.     }
  73.     public function addValidatedOrder(Order $order): self
  74.     {
  75.         if (! $this->validatedOrders->contains($order)) {
  76.             $this->validatedOrders[] = $order;
  77.         }
  78.         return $this;
  79.     }
  80.     public function removeValidatedOrder(Order $order): self
  81.     {
  82.         $this->validatedOrders->removeElement($order);
  83.         return $this;
  84.     }
  85.     public function isRequiresValidationByClinicalManager(): bool
  86.     {
  87.         return $this->requiresValidationByClinicalManager;
  88.     }
  89.     public function setRequiresValidationByClinicalManager(bool $requiresValidationByClinicalManager): void
  90.     {
  91.         $this->requiresValidationByClinicalManager $requiresValidationByClinicalManager;
  92.     }
  93.     /** @return Collection<array-key, Doctor> */
  94.     public function getAttachedDoctors(): Collection
  95.     {
  96.         return $this->attachedDoctors;
  97.     }
  98.     /** @param Collection<array-key, Doctor> $attachedDoctors */
  99.     public function setAttachedDoctors(Collection $attachedDoctors): void
  100.     {
  101.         $this->attachedDoctors $attachedDoctors;
  102.     }
  103.     public function addAttachedDoctor(Doctor $doctor): self
  104.     {
  105.         if (! $this->attachedDoctors->contains($doctor)) {
  106.             $this->attachedDoctors[] = $doctor;
  107.             $doctor->setAttachedClinicalManager($this);
  108.         }
  109.         return $this;
  110.     }
  111.     public function removeAttachedDoctor(Doctor $doctor): self
  112.     {
  113.         $this->attachedDoctors->removeElement($doctor);
  114.         return $this;
  115.     }
  116.     /** @return Collection<array-key, self> */
  117.     public function getAttachedClinicalManagers(): Collection
  118.     {
  119.         return $this->attachedClinicalManagers;
  120.     }
  121.     /** @param Collection<array-key, self> $clinicalManagers */
  122.     public function setAttachedClinicalManagers(Collection $clinicalManagers): void
  123.     {
  124.         $this->attachedClinicalManagers $clinicalManagers;
  125.     }
  126.     public function addAttachedClinicalManager(self $clinicalManager): self
  127.     {
  128.         if (! $this->attachedClinicalManagers->contains($clinicalManager)) {
  129.             $this->attachedClinicalManagers[] = $clinicalManager;
  130.             $clinicalManager->setAttachedClinicalManager($this);
  131.         }
  132.         return $this;
  133.     }
  134.     public function removeAttachedClinicalManager(self $clinicalManager): self
  135.     {
  136.         $this->attachedClinicalManagers->removeElement($clinicalManager);
  137.         return $this;
  138.     }
  139.     /** @return array<int|null> */
  140.     public function getAttachedClinicalManagerIdsRecursively(array $ids = []): array
  141.     {
  142.         // This method also adds the ID of the current clinical manager
  143.         $ids[] = $this->getId();
  144.         // Return the id of the clinical manager in the case where it is attached to itself to not having an infinite loop
  145.         if ($this->attachedClinicalManager?->getId() === $this->getId()) {
  146.             return $ids;
  147.         }
  148.         $ids[] = $this->getId();
  149.         foreach ($this->getAttachedClinicalManagers() as $attachedClinicalManager) {
  150.             if (in_array($attachedClinicalManager->getId(), $idstrue)) {
  151.                 continue;
  152.             }
  153.             $ids[] = $attachedClinicalManager->getId();
  154.             $ids $attachedClinicalManager->getAttachedClinicalManagerIdsRecursively($ids);
  155.         }
  156.         return array_values(array_unique($ids));
  157.     }
  158. }