src/Repository/DoctorRepository.php line 56

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Appointment;
  4. use App\Entity\Doctor;
  5. use Boab\CmsBundle\Service\Pagination;
  6. use Boab\CmsBundle\Service\PaginationInterface;
  7. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. use Iterator;
  10. /**
  11.  * @extends ServiceEntityRepository<Doctor>
  12.  *
  13.  * @method Doctor|null find($id, $lockMode = null, $lockVersion = null)
  14.  * @method Doctor|null findOneBy(array $criteria, array $orderBy = null)
  15.  * @method Doctor[]    findAll()
  16.  * @method Doctor[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  17.  */
  18. class DoctorRepository extends ServiceEntityRepository
  19. {
  20.     public function __construct(ManagerRegistry $registry, private PaginationInterface $pagination)
  21.     {
  22.         parent::__construct($registryDoctor::class);
  23.     }
  24.     public function save(Doctor $entitybool $flush false): void
  25.     {
  26.         $this->getEntityManager()->persist($entity);
  27.         if ($flush) {
  28.             $this->getEntityManager()->flush();
  29.         }
  30.     }
  31.     public function remove(Doctor $entitybool $flush false): void
  32.     {
  33.         $this->getEntityManager()->remove($entity);
  34.         if ($flush) {
  35.             $this->getEntityManager()->flush();
  36.         }
  37.     }
  38.     public function findAllDoctors()
  39.     {
  40.         $qb $this->createQueryBuilder('d')
  41.             ->orderBy('d.id''ASC')
  42.             ->setMaxResults(10)
  43.             ->getQuery();
  44.         return $this->pagination->paginate($qb);
  45.     }
  46.     public function findAllByLocation(string $latstring $lngint $distance=0$name
  47.     {
  48.         $qb $this->createQueryBuilder('d');
  49.         $qb->select('d''SUM(r.rating) as totalRating''COUNT(r) as numberOfRatings')
  50.             ->leftJoin('d.reviews''r');
  51.             if ($lat && $lng) {
  52.                 $qb->addSelect('
  53.                     (6371 * 
  54.                     ACOS(
  55.                         COS(RADIANS(:lat)) * 
  56.                         COS(RADIANS(d.latitude)) * 
  57.                         COS(RADIANS(d.longitude) - RADIANS(:lng)) + 
  58.                         SIN(RADIANS(:lat)) * 
  59.                         SIN(RADIANS(d.latitude))
  60.                     ))
  61.                     AS HIDDEN distance'
  62.                 );
  63.                 $qb->setParameter('lat'$lat);
  64.                 $qb->setParameter('lng'$lng);                
  65.                 $qb->orderBy('distance');
  66.                 if ($distance 0) {
  67.                     $qb->having('distance <= :distance');
  68.                     $qb->setParameter('distance'$distance);
  69.                 }                
  70.             }
  71.         /*
  72.         $qb->addSelect('
  73.             (6371 * 
  74.             ACOS(
  75.                 COS(RADIANS(:lat)) * 
  76.                 COS(RADIANS(d.latitude)) * 
  77.                 COS(RADIANS(d.longitude) - RADIANS(:lng)) + 
  78.                 SIN(RADIANS(:lat)) * 
  79.                 SIN(RADIANS(d.latitude))
  80.             ))
  81.             AS HIDDEN distance'
  82.         );
  83.         */
  84.         
  85.         if($name){
  86.             $qb->andWhere("CONCAT(d.firstname, ' ', d.lastname) LIKE :name");
  87.             $qb->setParameter('name''%' $name '%');
  88.         }
  89.         
  90.         $qb->groupBy('d');
  91.         
  92.         return $this->pagination->paginate($qb->getQuery());
  93.     } 
  94. }