From 4c3191aa8632169aa35db07e38282f53cc0a93ed Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sun, 11 Dec 2016 03:54:01 +0300 Subject: [PATCH] Autocomplete items count. --- .../Bundle/PointToolsBundle/Controller/MainController.php | 5 ++++- .../PointToolsBundle/Resources/views/Main/index.html.twig | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Skobkin/Bundle/PointToolsBundle/Controller/MainController.php b/src/Skobkin/Bundle/PointToolsBundle/Controller/MainController.php index 4197fec..119c4bf 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Controller/MainController.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Controller/MainController.php @@ -11,6 +11,8 @@ use Symfony\Component\HttpFoundation\Request; class MainController extends Controller { + const AJAX_AUTOCOMPLETE_SIZE = 10; + public function indexAction(Request $request) { /** @var EntityManager $em */ @@ -39,6 +41,7 @@ class MainController extends Controller return $this->render('SkobkinPointToolsBundle:Main:index.html.twig', [ 'form' => $form->createView(), + 'autocomplete_size' => self::AJAX_AUTOCOMPLETE_SIZE, 'users_count' => $em->getRepository('SkobkinPointToolsBundle:User')->getUsersCount(), 'subscribers_count' => $em->getRepository('SkobkinPointToolsBundle:Subscription')->getUserSubscribersCountById($this->container->getParameter('point_id')), 'events_count' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getLastDayEventsCount(), @@ -52,7 +55,7 @@ class MainController extends Controller $result = []; - foreach ($em->getRepository('SkobkinPointToolsBundle:User')->findUsersLikeLogin($login) as $user) { + foreach ($em->getRepository('SkobkinPointToolsBundle:User')->findUsersLikeLogin($login, self::AJAX_AUTOCOMPLETE_SIZE) as $user) { $result[] = [ 'login' => $user->getLogin(), 'name' => $user->getName(), diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/Main/index.html.twig b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/Main/index.html.twig index 4b72317..4336d65 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/Main/index.html.twig +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/Main/index.html.twig @@ -23,6 +23,7 @@ $field.typeahead({ minLength: 2, + items: {{ autocomplete_size|e('js') }}, delay: 500, autoSelect: true, source: function (query, processCallback) {