Paginate the given query.

@param  \Illuminate\Database\Eloquent\Builder|null $builder
@param  array $options

@return LengthAwarePaginator
342484
public function paginate($builder = null, $options = [])
    {
		$options = array_merge(['pageName' => 'page', 'columns' => ['*'],
            'perPage' => null, 'page' => null
        ], $options);

        return $this->getModel()
        	->paginate(
        		$options['perPage'], $options['columns'], $options['pageName'], $options['page']
        	);
    }
742844
protected function getManyFrom(Builder $query, QueryBuilder $builder): LengthAwarePaginator
    {
        $query = $query->with(self::$loadRelations);

        if ($builder->hasRelation('translations')) {
            if (!$builder->getFilter('translations.language_code')) {
                throw new InvalidArgumentException('Language code is required');
            }
            $query->join('block_translations as t', 'blocks.id', '=', 't.block_id');
            $builder->applyRelationFilters('translations', 't', $query);
            $builder->applyRelationSorts('translations', 't', $query);
        }

        if ($builder->hasFilter('type') || $builder->hasSort('type')) {
            $query->join('block_types as bt', 'blocks.type_id', '=', 'bt.id');
            optional($builder->getFilter('type'))->apply($query, 'bt', 'name');
            optional($builder->getSort('type'))->apply($query, 'bt', 'name');
        }

        $builder->applyFilters($query, 'blocks');
        $builder->applySorts($query, 'blocks');

        $count = clone $query->getQuery();

        $results = $query->limit($builder->getPageSize())
            ->offset($builder->getPageSize() * ($builder->getPage() - 1))
            ->get(['blocks.*']);

        return new LengthAwarePaginator(
            $results,
            $count->select('blocks.id')->count(),
            $builder->getPageSize(),
            $builder->getPage()
        );
    }
550836
public function getPaginator( $where        = null,
                                  $order        = null,
                                  $columns      = null,
                                  $joins        = null,
                                  $quantifier   = null )
    {
        $joins = array_merge( (array) $joins, array(
            'subdomain' => array(
                'where'     => static::$tableName . '.subdomainId = subdomain.id',
                'columns'   => array( 'subdomain' ),
                'type'      => Select::JOIN_LEFT,
            ),
            'paragraph_content' => array(
                'table'     => array( 'paragraph_content' => 'paragraph' ),
                'where'     => static::$tableName . '.contentId = paragraph_content.id',
                'columns'   => array( 'contentName' => 'name' ),
                'type'      => Select::JOIN_LEFT,
            ),
        ) );

        return parent::getPaginator( $where, $order, $columns, $joins, $quantifier );
    }
1151856
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
            $view = $event->getData();
            $form = $event->getForm();

            $this->isNew = !$view || null === $view->getId();

            if ($this->isNew) {
                $getAllTemplateWithoutMe = function (EntityRepository $tr) {
                    return $tr->getAll()->getInstance();
                };
            } else {
                $getAllTemplateWithoutMe = function (EntityRepository $tr) use ($view) {
                    return $tr->getAll()
                        ->getInstance()
                        ->andWhere('template.id != :templateId')
                        ->setParameter('templateId', $view->getId());
                };
            }
            if (!$form->has('template')) {
                $form->add('template', null, [
                    'label'        => 'form.view.type.template.label',
                    'choice_label' => function ($view) {
                        return $view->getName();
                    },
                    'required'      => !$view instanceof Template || $view instanceof BusinessTemplate,
                    'query_builder' => $getAllTemplateWithoutMe,
                ]);
            }

            //If view is an Article BEP, we do not allow to choose parent because it will be set automatically
            if (!$view instanceof ArticleTemplate && ClassUtils::getClass($view) != 'Victoire\Bundle\TemplateBundle\Entity\Template') {
                if (!$view || null === $view->getId()) {
                    $getAllPageWithoutMe = function (EntityRepository $repo) {
                        return $repo->getAll()->getInstance();
                    };
                } else {
                    $getAllPageWithoutMe = function (EntityRepository $repo) use ($view) {
                        return $repo->getAll()
                            ->getInstance()
                            ->andWhere('view.id != :pageId')
                            ->setParameter('pageId', $view->getId());
                    };
                }

                $form->add('parent', null, [
                        'class'         => 'Victoire\Bundle\PageBundle\Entity\BasePage',
                        'label'         => 'form.view.type.parent.label',
                        'query_builder' => $getAllPageWithoutMe,
                        'required'      => true,
                    ]
                );
            }

            if ($view instanceof BasePage) {
                $translationOptions = [
                    'fields' => [
                        'name' => [
                            'label' => 'form.view.type.name.label',
                        ],
                    ],
                ];
                if ($view->getId() && !$view->isHomepage()) {
                    $translationOptions['fields']['slug'] = [
                        'label'      => 'form.page.type.slug.label',
                        'field_type' => UrlvalidatedType::class,
                    ];
                }
                $form->add('translations', TranslationsType::class, $translationOptions);
            }
        });

        if ($this->authorizationChecker->isGranted('ROLE_VICTOIRE_DEVELOPER')) {
            $builder->add('roles', TextType::class, [
                'label'          => 'form.page.type.roles.label',
                'vic_help_block' => 'form.page.type.roles.help_block',
            ]);
        }
    }
90898
protected function performSearch(Builder $builder, array $options = [])
    {
        $index = $builder->index ?: $builder->model->searchableAs();
        $limit = $builder->limit ?: 10000;
        $this->tnt->selectIndex("{$index}.index");

        $this->builder = $builder;
        $this->tnt->asYouType = $builder->model->asYouType ?: false;

        if ($builder->callback) {
            return call_user_func(
                $builder->callback,
                $this->tnt,
                $builder->query,
                $options
            );
        }
        if (isset($this->tnt->config['searchBoolean']) ? $this->tnt->config['searchBoolean'] : false) {
            return $this->tnt->searchBoolean($builder->query, $limit);
        } else {
            return $this->tnt->search($builder->query, $limit);
        }
    }
1103816
public function paginate($perPage = 25, $currentPage = null, array $options = [])
    {
        $currentPage = $this->getPageFromInput($currentPage, $options);
        $offset      = ($currentPage - 1) * $perPage;
        $total       = $this->count();
        $entries     = $this->get()->slice($offset, $perPage)->all();

        return new LengthAwarePaginator($entries, $total, $perPage, $currentPage, $options);
    }
126129
public function paginate(Builder $builder, $perPage, $page)
    {
        $results = $this->performSearch($builder);

        if ($builder->limit) {
            $results['hits'] = $builder->limit;
        }

        $filtered = $this->discardIdsFromResultSetByConstraints($builder, $results['ids']);

        $results['hits'] = $filtered->count();

        $chunks = array_chunk($filtered->toArray(), $perPage);

        if (empty($chunks)) {
            return $results;
        }

        if (array_key_exists($page - 1, $chunks)) {
            $results['ids'] = $chunks[$page - 1];
        } else {
            $results['ids'] = end($chunks);
        }

        return $results;
    }
198738
public function search(FinderItem $finder = null): LengthAwarePaginator
    {
        if ($finder) {
            $this->query = $finder($this->query);
        }

        return $this->query->paginate();
    }
826357
protected function getPaginator4QueryBuilder(QueryBuilder $queryBuilder, int $count, int $page = 1): ?Paginator
    {
        if (!$queryBuilder) {
            return null;
        }

        $paginator = new Paginator(
            new DoctrineAdapter\SimpleQueryDoctrine($count, $queryBuilder->getQuery())
        );
        $paginator->setDefaultItemCountPerPage(25);
        $paginator->setCurrentPageNumber($page);

        return $paginator;
    }
907043
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($builder, $options) {
                if (empty($options['templates'])) {
                    return;
                }
                $event->getForm()->add('_template', ChoiceType::class, array(
                    'required' => true,
                    'choices' => $options['templates'],
                ));
            })
        ;
    }
327021
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $viewToIdTransformer = new ViewToIdTransformer($this->entityManager);

        $builder
            ->add($builder
                ->create('blog', HiddenType::class, ['label' => 'form.article.blog.label'])
                ->addModelTransformer($viewToIdTransformer))
            ->add('template')
            ->add('promoted', CheckboxType::class, [
                'label'    => 'form.article.type.promoted.label',
                'required' => false,
            ])
            ->add('tags', TagsType::class, [
                'required' => false,
                'multiple' => true,
            ])
            ->add('author', null, [
                'label'         => 'form.article.type.author.label',
                'required'      => true,
                'query_builder' => function (EntityRepository $er) {
                    return $er->createQueryBuilder('user')
                        ->where('user.roles LIKE :roles')
                        ->setParameter('roles', '%ROLE_VICTOIRE%');
                },
            ])
            ->remove('visibleOnFront');

        $builder->get('blog')->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
            $data = $event->getData();
            $parent = $event->getForm()->getParent();
            $this->manageCategories($data, $parent);
            $this->manageTemplate($data, $parent);
            $this->manageLocales($data, $parent);
        });

        $builder->get('blog')->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
            $data = $event->getData();
            $parent = $event->getForm()->getParent();
            $this->manageCategories($data, $parent);
            $this->manageLocales($data, $parent);
        });

        $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
            $data = $event->getData();
            $form = $event->getForm();
            $this->manageTags($data, $form);
        });
        $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
            $form = $event->getForm();
            $data = $form->getData();
            $this->manageTags($data, $form);
        });
    }
800969
public function paginate(Builder $builder, $perPage, $page)
    {
        $builder->limit = $perPage;
        $builder->offset = ($perPage * $page) - $perPage;

        return $this->search($builder);
    }
1015658
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        parent::buildForm($builder, $options);

        $builder->add('layout', ChoiceType::class, [
            'label'   => 'form.template.type.layout.label',
            'choices' => array_flip($options['layouts']),
        ]);

        $builder->add('translations', TranslationsType::class, [
            'fields' => [
                'name' => [
                    'label' => 'form.view.type.name.label',
                ],
            ],
        ]);

        $builder->remove('roles');
    }
528291
protected function paginate($collection, $options = array(), $dataRenderer = null)
    {
        return (new Paginator())->paginate($collection, $options, $dataRenderer);
    }
44577
protected function performSearch(Builder $builder, array $options = [])
    {
        if ($builder->callback) {
            return call_user_func(
                $builder->callback,
                ElasticClient::getFacadeRoot(),
                $builder->query,
                $options
            );
        }

        $results = [];

        $this
            ->buildSearchQueryPayloadCollection($builder, $options)
            ->each(function ($payload) use (&$results) {
                $results = ElasticClient::search($payload);

                $results['_payload'] = $payload;

                if ($this->getTotalCount($results) > 0) {
                    return false;
                }
            });

        return $results;
    }
359263
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $categories = $this->filterQueryHandler->handle($options['widget'], BlogCategory::class);

        //getAll categories
        $categoryQb = $this->getEntityManager()->getRepository('VictoireBlogBundle:BlogCategory')->getAll();
        //getAll published articles
        $articleQb = $this->getEntityManager()->getRepository('VictoireBlogBundle:Article')->getAll(true);

        //get Listing
        $listing = $options['widget']->getListing();

        $mode = $listing->getMode();
        switch ($mode) {
            case 'query':
                //filter with listingQuery
                $articleQb->filterWithListingQuery($listing->getQuery());
                break;
        }
        $categoryQb->filterByArticles($articleQb->getInstance('article'));
        $categories = $categoryQb->getInstance('c_category')->getQuery()->getResult();

        //the blank value
        $categoriesChoices = [];

        foreach ($categories as $category) {
            $categoriesChoices[$category->getTitle()] = $category->getId();
        }

        $data = null;
        if ($this->getRequest()->query->has('filter') && array_key_exists('category_filter', $this->getRequest()->query->get('filter'))) {
            if ($options['multiple']) {
                $data = [];
                foreach ($this->getRequest()->query->get('filter')['category_filter']['category'] as $id => $selectedCategory) {
                    $data[$id] = $selectedCategory;
                }
            } else {
                $data = $this->getRequest()->query->get('filter')['category_filter']['category'];
            }
        }

        $builder
            ->add(
                'category',
                ChoiceType::class,
                [
                    'label'       => false,
                    'choices'     => $categoriesChoices,
                    'required'    => false,
                    'expanded'    => true,
                    'multiple'    => $options['multiple'],
                    'placeholder' => $this->translator->trans('blog.category_filter.empty_value.label'),
                    'data'        => $data,
                ]
            );
    }
1367352
protected function performSearch(Builder $builder, array $options = [])
    {
        $params = [
            'index' => $this->index,
            'type' => $builder->index ?: $builder->model->searchableAs(),
            'body' => [
                'query' => [
                    'bool' => [
                        'must' => [['query_string' => [ 'query' => "*{$builder->query}*"]]]
                    ]
                ]
            ]
        ];

        if ($sort = $this->sort($builder)) {
            $params['body']['sort'] = $sort;
        }

        if (isset($options['from'])) {
            $params['body']['from'] = $options['from'];
        }

        if (isset($options['size'])) {
            $params['body']['size'] = $options['size'];
        }

        if (isset($options['numericFilters']) && count($options['numericFilters'])) {
            $params['body']['query']['bool']['must'] = array_merge($params['body']['query']['bool']['must'],
                $options['numericFilters']);
        }

        if ($builder->callback) {
            return call_user_func(
                $builder->callback,
                $this->elastic,
                $builder->query,
                $params
            );
        }

        return $this->elastic->search($params);
    }