src/Repository/Fuel/FuelStationsRepository.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Repository\Fuel;
  3. use App\Entity\Fuel\FuelStations;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7.  * @method FuelStations|null find($id, $lockMode = null, $lockVersion = null)
  8.  * @method FuelStations|null findOneBy(array $criteria, array $orderBy = null)
  9.  * @method FuelStations[]    findAll()
  10.  * @method FuelStations[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11.  */
  12. class FuelStationsRepository extends ServiceEntityRepository
  13. {
  14.     public function __construct(ManagerRegistry $registry)
  15.     {
  16.         parent::__construct($registryFuelStations::class);
  17.     }
  18.     /**
  19.     * Returns a station identified by Name/Alias or Phone Formatted/Simp from FuelStations
  20.     * SELECT * FROM `fuel_stations` WHERE (`name` like 'Exxon%' OR `name` like 'Express Mart%^') 
  21.     * AND (`phone` = '(843) 626-8878' OR `phone` = '843-626-8878')
  22.     */
  23.     public function identifyOne($title$alias ''$fphone$simp): ?FuelStations
  24.     {
  25.         return $this->createQueryBuilder('s')
  26.         ->andWhere('(s.name like :title OR s.name like :alias)')
  27.         ->andWhere('(s.phone = :fphone OR s.phone = :simp)')
  28.         ->setParameter('title'$title.'%')
  29.         ->setParameter('alias'$alias.'%')
  30.         ->setParameter('fphone'$fphone)
  31.         ->setParameter('simp'$simp)
  32.         ->orderBy('s.id''DESC')
  33.         ->setMaxResults(1)
  34.         ->getQuery()
  35.         ->getOneOrNullResult()
  36.         ;
  37.     }
  38.     /**
  39.     * Returns a station identified by Name/Alias or Address
  40.     */
  41.     public function identifyTwo($title$alias ''$address): ?FuelStations
  42.     {
  43.         $aparts explode(','trim($address));
  44.         $parts explode(' 'trim($aparts[0]));
  45.         foreach ($parts as $k => $part) {
  46.             if (strlen($part) <= 1) {
  47.                 unset($parts[$k]);
  48.             }
  49.         }
  50.         $saddress implode(' '$parts);
  51.         $address $aparts[0];
  52.         return $this->createQueryBuilder('s')
  53.         ->andWhere('(s.name like :title OR s.name like :alias)')
  54.         ->andWhere('(s.address = :address OR s.address = :saddress)')
  55.         ->setParameter('title'$title.'%')
  56.         ->setParameter('alias'$alias.'%')
  57.         ->setParameter('address'$address)
  58.         ->setParameter('saddress'$saddress)
  59.         ->orderBy('s.id''DESC')
  60.         ->setMaxResults(1)
  61.         ->getQuery()
  62.         ->getOneOrNullResult()
  63.         ;
  64.     }
  65.     /**
  66.     * Returns a station identified by Name/Alias or Address
  67.     */
  68.     public function identifyThree($title$alias ''$lat$lng): ?FuelStations
  69.     {
  70.         return $this->createQueryBuilder('s')
  71.         ->andWhere('(s.name like :title OR s.name like :alias)')
  72.         ->andWhere('(s.lat like :lat OR s.lng like :lng)')
  73.         ->setParameter('title'$title.'%')
  74.         ->setParameter('alias'$alias.'%')
  75.         ->setParameter('lat'$lat.'%')
  76.         ->setParameter('lng'$lng.'%')
  77.         ->orderBy('s.id''DESC')
  78.         ->setMaxResults(1)
  79.         ->getQuery()
  80.         ->getOneOrNullResult()
  81.         ;
  82.     }
  83.     /**
  84.     * Returns a station identified by Name/Alias or Address
  85.     */
  86.     public function identifyFour($title$alias ''$lat$lng): ?FuelStations
  87.     {
  88.         $title preg_split('/[\s,]+/'$title2);
  89.         $alias preg_split('/[\s,]+/'$alias2);
  90.         
  91.         if(isset($title[1])) {
  92.             $title $title[0].' '.$title[1];
  93.         } else {
  94.             $title $title[0];
  95.         }
  96.         if(isset($alias[1])) {
  97.             $alias $alias[0].' '.$alias[1];
  98.         } else {
  99.             $alias $alias[0];
  100.         }
  101.         return $this->createQueryBuilder('s')
  102.         ->andWhere('(s.name like :title OR s.name like :alias)')
  103.         ->andWhere('(s.lat like :lat OR s.lng like :lng)')
  104.         ->setParameter('title'$title.'%')
  105.         ->setParameter('alias'$alias.'%')
  106.         ->setParameter('lat'$lat.'%')
  107.         ->setParameter('lng'$lng.'%')
  108.         ->orderBy('s.id''DESC')
  109.         ->setMaxResults(1)
  110.         ->getQuery()
  111.         ->getOneOrNullResult()
  112.         ;
  113.     }
  114.     public function stationsByGeoHrs($lat,$lng,$rad 5$hrlimit 72) {
  115.         $updated date('Y-m-d G:i:s'strtotime('-'.$hrlimit.' hours'));
  116.         return $listings $this->createQueryBuilder('b')
  117.             ->addSelect('(3959 * acos(cos(radians(:lat)) * cos(radians( b.lat )) * cos(radians( b.lng ) - radians( :lng )) + sin(radians( :lat )) * sin(radians( b.lat )))) AS distance')
  118.             ->andWhere('b.modified < :hrlimit')
  119.             ->setParameter('hrlimit'$updated)
  120.             ->setParameter('lat'$lat)
  121.             ->setParameter('lng'$lng)
  122.             ->setParameter('rad'$rad)
  123.             ->having('distance < :rad')
  124.             ->orderBy('distance''ASC')
  125.             ->setMaxResults(5000)
  126.             ->getQuery()
  127.             ->getScalarResult()
  128.         ;
  129.     }
  130.     // /**
  131.     //  * @return FuelStations[] Returns an array of FuelStations objects
  132.     //  */
  133.     /*
  134.     public function findByExampleField($value)
  135.     {
  136.         return $this->createQueryBuilder('f')
  137.             ->andWhere('f.exampleField = :val')
  138.             ->setParameter('val', $value)
  139.             ->orderBy('f.id', 'ASC')
  140.             ->setMaxResults(10)
  141.             ->getQuery()
  142.             ->getResult()
  143.         ;
  144.     }
  145.     */
  146.     /*
  147.     public function findOneBySomeField($value): ?FuelStations
  148.     {
  149.         return $this->createQueryBuilder('f')
  150.             ->andWhere('f.exampleField = :val')
  151.             ->setParameter('val', $value)
  152.             ->getQuery()
  153.             ->getOneOrNullResult()
  154.         ;
  155.     }
  156.     */
  157. }