Created
November 30, 2012 21:25
-
-
Save basz/4178741 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 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