Example #1
0
 protected function findGroupsWithinRangeAndDistance()
 {
     $lat = $this->params()->fromQuery('latitude', null);
     $lon = $this->params()->fromQuery('longitude', null);
     $distance = $this->params()->fromQuery('distance', null);
     $number = $this->params()->fromQuery('count', null);
     if (!$lat || !$lon) {
         return array();
     }
     /** @var \Doctrine\ORM\EntityManager $em */
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     DistanceFrom::setLatitudeField('latitude');
     DistanceFrom::setLongitudeField('longitude');
     DistanceFrom::setRadius(6367);
     $em->getConfiguration()->addCustomNumericFunction('DISTANCEFROM', 'Phpug\\ORM\\Query\\AST\\Functions\\DistanceFrom');
     $qs = 'SELECT p, DISTANCEFROM(' . (double) $lat . ',' . (double) $lon . ') AS distance FROM \\Phpug\\Entity\\Usergroup p WHERE p.state = 1 ';
     if ($distance) {
         $qs .= ' AND DISTANCEFROM(' . (double) $lat . ',' . (double) $lon . ') <= ' . (double) $distance;
     }
     $qs .= ' ORDER BY distance';
     $query = $em->createQuery($qs);
     if ($number) {
         $query->setMaxResults($number);
     }
     $res = array();
     foreach ($query->getResult() as $result) {
         $res[] = $result[0]->getShortname();
     }
     return $res;
 }
 protected function findGroupsWithinRangeAndDistance($lat, $lon, $distance = null, $number = null)
 {
     /** @var \Doctrine\ORM\EntityManager $em */
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     DistanceFrom::setLatitudeField('latitude');
     DistanceFrom::setLongitudeField('longitude');
     DistanceFrom::setRadius(6367);
     $em->getConfiguration()->addCustomNumericFunction('DISTANCEFROM', 'Phpug\\ORM\\Query\\AST\\Functions\\DistanceFrom');
     $qs = 'SELECT p, DISTANCEFROM(' . (double) $lat . ',' . (double) $lon . ') AS distance FROM \\Phpug\\Entity\\Usergroup p WHERE p.state = 1 ';
     if ($distance) {
         $qs .= ' AND DISTANCEFROM(' . (double) $lat . ',' . (double) $lon . ') <= ' . (double) $distance;
     }
     $qs .= ' ORDER BY distance';
     $query = $em->createQuery($qs);
     if ($number) {
         $query->setMaxResults($number);
     }
     return $query->getResult();
 }