Skip to content

Instantly share code, notes, and snippets.

@helderjs
Created September 30, 2013 23:40
Show Gist options
  • Save helderjs/6771914 to your computer and use it in GitHub Desktop.
Save helderjs/6771914 to your computer and use it in GitHub Desktop.
/**
* @Route("/state/searchbyuser", name="state_search_by_user"
* @Method("GET")
*/
public function searchByUser()
{
$request = $this->getRequest();
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
$query = $em->execute('
SELECT
partial s.{id, name}, g
FROM Ciwwic\AppBundle\Entity\State s
JOIN Ciwwic\AppBundle\Entity\GroupRegion gr WITH gr.region = s.id
JOIN gr.group g
WHERE gr.type = :region_type
AND g.user = :user
AND s.name LIKE :q
')
->setParameters(
array(
'q' => $request->query->get('q') . '%',
'region_type' => 2,
'user_id' => $user,
)
)
->setMaxResults(5);
return new JsonResponse($query->getArrayResult());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment