Skip to content

Instantly share code, notes, and snippets.

@basz
Created November 30, 2012 21:25
Show Gist options
  • Select an option

  • Save basz/4178741 to your computer and use it in GitHub Desktop.

Select an option

Save basz/4178741 to your computer and use it in GitHub Desktop.
public function fetchQuery(\Zend\Http\PhpEnvironment\Request $request = null) {
$qb = $this->_em->createQueryBuilder();
$qb->select('entity, contact, address')
->from('SndAdmin\Entity\Dealer', 'entity')
->leftJoin('entity.contact', 'contact' )
->leftJoin('entity.shippingAddress', 'address' );
if (isset($options['offset'])) {
$qb->setFirstResult( $options['offset'] );
}
if ($request && $request->getQuery()->search) {
$qb->where( 'entity.companyName LIKE :search OR contact.name LIKE :search')
->setParameter('search', "%" . $request->getQuery()->search . "%");
}
return $qb->getQuery();
}
/** return the dealer that have a shipping address which have a geoLocation set */
public function getAroundAddress(\SndSpecialistLocator\Orm\Point $point, $radius = 1, $maxResults = null)
{
$qb = $this->_em->createQueryBuilder();
$qb->select('dealer, address, (DISTANCE(address.geoPoint, POINT_STR(:point))) AS HIDDEN distance')
->from('SndAdmin\Entity\Dealer', 'dealer')
->leftJoin('dealer.shippingAddress', 'address')
->where('DISTANCE(address.geoPoint, POINT_STR(:point)) < :distance')
//->where('address.geoPoint IS NOT null')
->setParameter('point', $point)
->orderBy('distance', 'ASC')
->setParameter('distance', $radius);
if (is_numeric($maxResults)) {
$qb->setMaxResults($maxResults);
}
$query = $qb->getQuery();
return $query->getResult();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment