Created
November 25, 2012 21:33
-
-
Save basz/4145477 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function findAround(Point $point, $radius = 1) { | |
| $em = $this->getEntityManager(); | |
| $qb = $em->createQueryBuilder(); | |
| $qb->select('m as marker, (DISTANCE(m.location, POINT_STR(:point))) as distance') | |
| ->from('SndSpecialistLocator\Entity\Marker', 'm') | |
| ->where('DISTANCE(m.location, POINT_STR(:point)) < :distance') | |
| ->setParameter('point', $point) | |
| ->orderBy('distance', 'ASC') | |
| ->setParameter('distance', $radius); | |
| ->setMaxResults(5); | |
| $query = $qb->getQuery(); | |
| $result = $query->execute(); | |
| /** | |
| * Convert the resulting associative array into one only the entity objects | |
| * | |
| * array (size=5) | |
| * 0 => | |
| * array (size=2) | |
| * 'marker' => | |
| * object(SndSpecialistLocator\Entity\Marker)[647] | |
| * protected 'id' => int 43 | |
| * protected 'title' => string 'c5d07acdd47efbe38a6d0bf4ec64f333' (length=32) | |
| * private 'location' => | |
| * object(SndSpecialistLocator\Orm\Point)[636] | |
| * private 'lat' => float 52.2897 | |
| * private 'lng' => float 4.84268 | |
| * 'distance' => string '0.0760756823433058' (length=18) | |
| * 1 => ... | |
| * | |
| * array (size=5) | |
| * 0 => | |
| * object(SndSpecialistLocator\Entity\Marker)[647] | |
| * protected 'id' => int 43 | |
| * protected 'title' => string 'c5d07acdd47efbe38a6d0bf4ec64f333' (length=32) | |
| * private 'location' => | |
| * object(SndSpecialistLocator\Orm\Point)[636] | |
| * private 'lat' => float 52.2897 | |
| * private 'lng' => float 4.84268 | |
| * 1 => ... | |
| * | |
| */ | |
| array_walk($result, function (&$item, $key) | |
| { | |
| $item = $item['marker']; | |
| }); | |
| return $result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment