|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\Neighbourhood; |
|
6
|
|
|
use LongitudeOne\Spatial\PHP\Types\Geometry\Point; |
|
7
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
|
8
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @method Neighbourhood|null find($id, $lockMode = null, $lockVersion = null) |
|
12
|
|
|
* @method Neighbourhood|null findOneBy(array $criteria, array $orderBy = null) |
|
13
|
|
|
* @method Neighbourhood[] findAll() |
|
14
|
|
|
* @method Neighbourhood[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
|
15
|
|
|
*/ |
|
16
|
|
|
class NeighbourhoodRepository extends ServiceEntityRepository |
|
17
|
|
|
{ |
|
18
|
|
|
public function __construct(ManagerRegistry $registry) |
|
19
|
|
|
{ |
|
20
|
|
|
parent::__construct($registry, Neighbourhood::class); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function findByLatlng(float $lat, float $lng): ?Neighbourhood |
|
24
|
|
|
{ |
|
25
|
|
|
$point = new Point($lng, $lat); |
|
26
|
|
|
$queryBuilder = $this->createQueryBuilder('n'); |
|
27
|
|
|
|
|
28
|
|
|
/** @var ?Neighbourhood $result */ |
|
29
|
|
|
$result = $queryBuilder |
|
30
|
|
|
->andWhere("st_contains(n.boundingPolygon, :p) = true") |
|
31
|
|
|
->setParameter('p', $point, 'point') |
|
32
|
|
|
->setMaxResults(1) |
|
33
|
|
|
->getQuery() |
|
34
|
|
|
->getOneOrNullResult(); |
|
35
|
|
|
return $result; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
// /** |
|
39
|
|
|
// * @return Neighbourhood[] Returns an array of Neighbourhood objects |
|
40
|
|
|
// */ |
|
41
|
|
|
/* |
|
42
|
|
|
public function findByExampleField($value) |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->createQueryBuilder('n') |
|
45
|
|
|
->andWhere('n.exampleField = :val') |
|
46
|
|
|
->setParameter('val', $value) |
|
47
|
|
|
->orderBy('n.id', 'ASC') |
|
48
|
|
|
->setMaxResults(10) |
|
49
|
|
|
->getQuery() |
|
50
|
|
|
->getResult() |
|
51
|
|
|
; |
|
52
|
|
|
} |
|
53
|
|
|
*/ |
|
54
|
|
|
|
|
55
|
|
|
/* |
|
56
|
|
|
public function findOneBySomeField($value): ?Neighbourhood |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->createQueryBuilder('n') |
|
59
|
|
|
->andWhere('n.exampleField = :val') |
|
60
|
|
|
->setParameter('val', $value) |
|
61
|
|
|
->getQuery() |
|
62
|
|
|
->getOneOrNullResult() |
|
63
|
|
|
; |
|
64
|
|
|
} |
|
65
|
|
|
*/ |
|
66
|
|
|
} |
|
67
|
|
|
|