本文整理汇总了PHP中Doctrine\ORM\Tools\Pagination\Paginator类的典型用法代码示例。如果您正苦于以下问题:PHP Paginator类的具体用法?PHP Paginator怎么用?PHP Paginator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Paginator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getResult
/**
* {@inheritdoc}
*/
public function getResult(QueryBuilder $queryBuilder)
{
$doctrineOrmPaginator = new DoctrineOrmPaginator($queryBuilder);
// Disable output walkers by default (performance)
$doctrineOrmPaginator->setUseOutputWalkers(false);
return new Paginator($doctrineOrmPaginator);
}
示例2: paginationToPaginatorORM
public function paginationToPaginatorORM(\Doctrine\ORM\Tools\Pagination\Paginator $paginator)
{
$this->setTotal($paginator->count());
$this->paginator = $paginator;
$dados = array(self::_TOTAL_RECORDS => $this->getTotalGeral(), self::_RECORDS_FILTERED => $this->getTotalGeral());
$this->outPut = array_merge($this->outPut, $dados);
}
示例3: getGridData
/**
* Realiza a pesquisa paginada
* IMPORTANTE: definir o hydration mode em sua repository (QUERY::HYDRATE_ARRAY), pois afeta a performance
* @return \StdClass
*/
public function getGridData($searchQueryMethod = 'searchQuery', $prepareGridRowsMethod = 'prepareGridRows', $hydration_mode = null)
{
// Busca a query que será utilizada na pesquisa para a grid
$query = $this->getService()->{$searchQueryMethod}($this->getDto());
// pagina a ser retornada
// quantidade de linhas a serem retornadas por página
$rows = $this->getDto()->query->has('rows') ? $this->getDto()->query->get('rows', 20) : $this->getDto()->request->get('rows', 20);
$page = $this->getDto()->query->has('page') ? $this->getDto()->query->get('page', 1) : $this->getDto()->request->get('page', 1);
$rows = $rows >= 1 ? $rows : 20;
//só para evitar divisão por 0
$page = $page >= 1 ? $page : 1;
//só para evitar página negativa
$start = $page * $rows - $rows;
$start = $start >= 0 ? $start : 0;
$query->setFirstResult($start)->setMaxResults($rows);
if ($hydration_mode) {
$query->setHydrationMode($hydration_mode);
}
$pagination = new Paginator($query, true);
// Objeto de resposta
$data = new \StdClass();
$data->count = $pagination->count();
$data->itemsPerPage = $rows;
$data->page = $page;
$data->pageCount = ceil($pagination->count() / $rows);
// linhas da resposta - o método abaixo pode (e provavelmente deve)
// ser implantado de acordo com as necessidades da aplicação
$data->items = $this->{$prepareGridRowsMethod}($pagination);
return $data;
}
示例4: indexAction
/**
* Lists all Viaggio entities.
*
* @Route("/", name="travel")
* @Method("GET")
* @Template("AppBundle:Viaggio:mete-visitate.html.twig")
*/
public function indexAction()
{
$this->denyAccessUnlessGranted('ROLE_USER', null, 'Unable to access this page!');
$em = $this->getDoctrine()->getManager();
$user = $this->container->get('security.context')->getToken()->getUser();
$user_id = $user->getId();
// $entities = $em->getRepository('AppBundle:Viaggio')->findBy(['utente'=>$user, 'salvato'=>true],['id' => 'DESC']);
// Limit per page.
$limit = 4;
$page = $this->getRequest()->query->get("page", 1);
$thisPage = $page;
$query = $em->createQuery("SELECT viaggio, viaggio.id, viaggio.descrizione, viaggio.meta, viaggio.partenza, viaggio.arrivo, viaggio.periodo, viaggio.salvato, user.id\n FROM AppBundle:Viaggio viaggio\n JOIN AppBundle:User user WHERE (viaggio.utente = {$user_id})\n WHERE viaggio.salvato = true\n ORDER BY viaggio.id DESC")->setFirstResult($limit * ($page - 1))->setMaxResults($limit);
// $questo=$query->getResult();
$paginator = new Paginator($query, $fetchJoinCollection = true);
$maxPages = ceil($paginator->count() / $limit);
// $c = count($paginator);
// foreach ($paginator as $post) {
// echo $post->getHeadline() . "\n";
// }
$birthDate = $user->getDataDiNascita();
$age = null;
if ($birthDate != null) {
//explode the date to get month, day and year
$birthDate = explode("-", $birthDate);
//get age from date or birthdate
$age = date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? date("Y") - $birthDate[2] - 1 : date("Y") - $birthDate[2];
}
$ultimaSalvata = $em->getRepository('AppBundle:Viaggio')->findOneBy(array('utente' => $user->getId(), 'salvato' => true), array('id' => 'DESC'));
return array('eta' => $age, 'salvata' => $ultimaSalvata, 'user' => $user, 'maxPages' => $maxPages, 'thisPage' => $thisPage, 'issues' => $paginator->getIterator());
}
示例5: indexAction
/**
* @Route("/{page}", name="vacancy_index", requirements={"page": "\d+"}, defaults={"page" = 1})
*/
public function indexAction($page, Request $request)
{
$page = max(1, $page);
$length = 5;
$start = ($page - 1) * $length;
$filter = new Filter();
$form = $this->createForm(FilterType::class, $filter);
$form->handleRequest($request);
$locale = $this->getParameter('locale');
/** @var EntityManager $em */
$em = $this->getDoctrine()->getManager();
$builder = $em->createQueryBuilder();
$builder->select(['v', 'd', 'vd'])->from('VacancyBundle:Vacancy', 'v')->join('v.department', 'd')->leftJoin('v.descriptions', 'vd')->leftJoin('vd.language', 'l')->andWhere('l.id = :language OR l.name = :locale')->setParameter('language', $filter->getLanguage())->setParameter('locale', $locale);
if ($filter->getDepartment()) {
$builder->andWhere('d.id = :department')->setParameter('department', $filter->getDepartment());
}
$builder->addOrderBy("d.name", 'ASC')->addOrderBy("l.id", 'DESC')->addOrderBy("vd.name", 'ASC')->addGroupBy("v.id, l.id");
// Group by: hax for getting only row of selected language
$builder->setFirstResult($start)->setMaxResults($length);
$paginator = new Paginator($builder);
$filters = [];
foreach ($request->query->getIterator() as $key => $value) {
$filters[$key] = $value;
}
return $this->render('VacancyBundle:vacancy:index.html.twig', ['form' => $form->createView(), 'isValid' => $form->isValid(), 'filter' => $filter, 'data' => $paginator, 'pagination' => ['page' => $page, 'total' => ceil($paginator->count() / $length), 'currentFilters' => $filters]]);
}
示例6: buildQuery
/**
* (non-PHPdoc)
* @see \Neutron\DataGridBundle\DataGrid\DataGridHandlerInterface::buildQuery()
*/
public function buildQuery()
{
$qb = $this->dataGrid->getQueryBuilder();
if (!$qb instanceof QueryBuilder) {
throw new \InvalidArgumentException('Value must be instance of Doctrine\\ORM\\QueryBuilder.');
}
$options = $this->getOptions();
// Is dependant grid ?
if ($this->dataGrid->isDependentGrid()) {
$qb->setParameter('masterGridRowId', $options['masterGridRowId']);
}
// Orders the records
if ($options['orderBy']) {
$qb->addOrderBy($options['orderBy'], $options['sort']);
}
// Applying search filters
if ($options['search'] && !empty($options['filters'])) {
$this->applyFilters($qb, $options['filters']);
}
// dispatch should onQueryBuilderReady event here
if (!$this->dataGrid->isSortableEnabled() && $options['page'] && $options['records']) {
$qb->setMaxResults($options['records']);
$qb->setFirstResult(($options['page'] - 1) * $options['records']);
}
$this->setQuery($qb->getQuery());
// Getting count
$paginator = new Paginator($this->getQuery());
//$paginator->setUseOutputWalkers(false);
$this->setCount($paginator->count());
return $this;
}
示例7: execute
/**
* @return array
* @throws OutOfBoundsException
*/
public function execute()
{
$queryBuilder = $this->getData();
$aliases = [];
$queryBuilder->resetDQLParts(['select', 'orderBy', 'having']);
foreach ($this->getColumns() as $column) {
if ($column instanceof Select) {
$aliases[] = $column->getAlias();
}
}
foreach (array_unique($aliases) as $alias) {
$queryBuilder->addSelect($alias);
}
foreach ($this->getSortConditions() as $column => $sortDirection) {
/** @noinspection PhpParamsInspection */
$queryBuilder->add('orderBy', new OrderBy($column, $sortDirection), true);
}
if (null !== $this->first) {
$queryBuilder->setFirstResult($this->first);
}
if (null !== $this->max) {
$queryBuilder->setMaxResults($this->max);
}
$paginator = new Paginator($queryBuilder);
$this->resultCount = $paginator->count();
$result = $queryBuilder->getQuery()->getResult();
if ($this->resultCount > 0 && empty($result)) {
throw new OutOfBoundsException();
}
return $result;
}
示例8: getListagem
public function getListagem($arrData = array(), $intPage = 1, $intQtdPage = 10)
{
$queryBuilder = $this->_em->createQueryBuilder();
$queryBuilder->select('PessoaFisica')->addSelect('Login.dsLogin')->from('Application\\Entity\\PessoaFisica', 'PessoaFisica')->innerJoin('Application\\Entity\\Login', 'Login', 'with', 'Login.idPessoaFisica = PessoaFisica.idPessoaFisica')->setMaxResults($intQtdPage)->setFirstResult($intPage * ($intPage - 1))->orderBy('PessoaFisica.dsNome', 'asc');
# bind nome
if ($arrData['dsNome']) {
$queryBuilder->andWhere($queryBuilder->expr()->like('PessoaFisica.dsNome', ':dsNome'))->setParameter('dsNome', '%' . $arrData['dsNome'] . '%');
}
# bind cpf
if ($arrData['dsCpf']) {
$queryBuilder->andWhere('PessoaFisica.dsCpf = :dsCpf')->setParameter('dsCpf', Format::clearCpfCnpj($arrData['dsCpf']));
}
# bind dsEmail
if ($arrData['dsEmail']) {
$queryBuilder->andWhere('PessoaFisica.dsEmail = :dsEmail')->setParameter('dsEmail', $arrData['dsEmail']);
}
# bind dsLogin
if ($arrData['dsLogin']) {
$queryBuilder->andWhere('Login.dsLogin = :dsLogin')->setParameter('dsLogin', $arrData['dsLogin']);
}
$query = $queryBuilder->getQuery();
$registerPaginator = new Paginator($query);
$registerPaginator->setUseOutputWalkers(false);
$intCountResult = $registerPaginator->count();
$arrDadosPaginator = array('qtdRegister' => $intCountResult, 'qtdPages' => ceil($intCountResult / $intQtdPage), 'pageActual' => $intPage, 'maxResult' => $intQtdPage, 'register' => $registerPaginator);
return $arrDadosPaginator;
}
示例9: paginateAll
/**
* @param int $offset
* @param int $limit
* @param string|null $status
* @return PaginationResult
*/
public function paginateAll($offset, $limit, $status = null)
{
$queryBuilder = $this->entityRepository->createQueryBuilder('invoice');
$queryBuilder->innerJoin('invoice.client', 'client');
$queryBuilder->setFirstResult($offset);
$queryBuilder->setMaxResults($limit);
$queryBuilder->orderBy('invoice.id', 'desc');
switch ($status) {
case 'paid':
$queryBuilder->andWhere('invoice.payDate IS NOT NULL');
break;
case 'late':
$queryBuilder->andWhere('invoice.payDate IS NULL');
$queryBuilder->andWhere('invoice.dueDate IS NOT NULL');
$queryBuilder->andWhere('invoice.dueDate < :now');
$queryBuilder->setParameter('now', new DateTime());
break;
case 'sent':
$queryBuilder->andWhere('invoice.payDate IS NULL');
$queryBuilder->andWhere('invoice.dueDate IS NULL OR invoice.dueDate >= :now');
$queryBuilder->andWhere('invoice.sendDate IS NOT NULL');
$queryBuilder->setParameter('now', new DateTime());
break;
case 'draft':
$queryBuilder->andWhere('invoice.payDate IS NULL');
$queryBuilder->andWhere('invoice.dueDate IS NULL OR invoice.dueDate >= :now');
$queryBuilder->andWhere('invoice.sendDate IS NULL');
$queryBuilder->setParameter('now', new DateTime());
break;
}
$paginator = new Paginator($queryBuilder->getQuery(), false);
return new PaginationResult($paginator->getIterator(), $paginator->count());
}
示例10: getCount
/**
* Calculates total count of query records
* Notes: this method do not make any modifications of the given query
*
* @param Query|SqlQuery $query
*
* @return integer
*/
public function getCount($query)
{
if ($this->useWalker($query)) {
if (!$query->contains('DISTINCT')) {
$query->setHint(CountWalker::HINT_DISTINCT, false);
}
$paginator = new Paginator($query);
$paginator->setUseOutputWalkers(false);
$result = $paginator->count();
} else {
if ($query instanceof Query) {
$parserResult = QueryUtils::parseQuery($query);
$parameterMappings = $parserResult->getParameterMappings();
list($params, $types) = QueryUtils::processParameterMappings($query, $parameterMappings);
$statement = $query->getEntityManager()->getConnection()->executeQuery('SELECT COUNT(*) FROM (' . $query->getSQL() . ') AS e', $params, $types);
} elseif ($query instanceof SqlQuery) {
$countQuery = clone $query->getQueryBuilder();
$statement = $countQuery->resetQueryParts()->select('COUNT(*)')->from('(' . $query->getSQL() . ')', 'e')->execute();
} else {
throw new \InvalidArgumentException(sprintf('Expected instance of Doctrine\\ORM\\Query or Oro\\Bundle\\EntityBundle\\ORM\\SqlQuery, "%s" given', is_object($query) ? get_class($query) : gettype($query)));
}
$result = $statement->fetchColumn();
}
return $result ? (int) $result : 0;
}
示例11: items
public function items(ItemsEvent $event)
{
if (!class_exists('Doctrine\\ORM\\Tools\\Pagination\\Paginator')) {
return;
}
if (!$event->target instanceof Query) {
return;
}
$event->stopPropagation();
$useOutputWalkers = false;
if (isset($event->options['wrap-queries'])) {
$useOutputWalkers = $event->options['wrap-queries'];
}
$event->target->setFirstResult($event->getOffset())->setMaxResults($event->getLimit())->setHint(CountWalker::HINT_DISTINCT, $event->options['distinct']);
$fetchJoinCollection = true;
if ($event->target->hasHint(self::HINT_FETCH_JOIN_COLLECTION)) {
$fetchJoinCollection = $event->target->getHint(self::HINT_FETCH_JOIN_COLLECTION);
}
$paginator = new Paginator($event->target, $fetchJoinCollection);
$paginator->setUseOutputWalkers($useOutputWalkers);
if (($count = $event->target->getHint(QuerySubscriber::HINT_COUNT)) !== false) {
$event->count = intval($count);
} else {
$event->count = count($paginator);
}
$event->items = iterator_to_array($paginator);
}
示例12: paginate
public function paginate(QueryBuilder $query, $limit, $page)
{
$query->setMaxResults($limit)->setFirstResult($limit * ($page - 1));
$paginator = new Paginator($query->getQuery());
$paginator->setUseOutputWalkers(false);
return $paginator;
}
示例13: setQuery
/**
* Prepare listing instance from Doctrine ORM Query or QueryBuilder.
*
* Sets 'order by' only for QueryBuilder.
*
* @param Query|QueryBuilder
* @param boolean
* @param boolean
* @param boolean
* @return self
* @see Paginator
*/
public function setQuery($query, $fetchJoinCollection = false, $appendLimit = true, $appendOrder = true)
{
if ($query instanceof QueryBuilder) {
$order = $this->order();
if ($appendOrder && $order) {
if (is_array($order)) {
call_user_func_array([$query, 'orderBy'], $order);
} else {
$query->add('orderBy', $order);
}
}
$query = $query->getQuery();
}
if (!$query instanceof Query) {
throw \InvalidArgumentException('Instance of Doctrine\\ORM\\Query or Doctrine\\ORM\\QueryBuilder required!');
}
if ($appendLimit) {
$paginator = new Paginator($query, $fetchJoinCollection);
$this->setCount($paginator->count());
$query->setFirstResult($this->offset())->setMaxResults($this->limit());
$this->setItems($paginator);
} else {
$this->setItems($query->getResult());
}
return $this;
}
示例14: getQueryResult
public function getQueryResult($class, $params)
{
if (!$params instanceof OdataParameters) {
$params = OdataParameters::parse($params);
}
$repository = $this->entityManager->getRepository($class);
$queryBuilder = $repository->createQueryBuilder('X');
$odataBuilder = new OdataQueryBuilderWrapper($queryBuilder);
$odataBuilder->applyOdataParameters($params);
if ($params->inlinecount) {
// $count = $odataBuilder->getInlineCount();
}
$query = $queryBuilder->getQuery();
$inlineCount = null;
$fetchJoinCollection = isset($params->expand);
$fetchCount = $params->inlinecount;
if ($fetchJoinCollection || $fetchCount) {
$paginator = new Paginator($query, $fetchJoinCollection);
$paginator->setUseOutputWalkers(false);
if ($fetchCount) {
$inlineCount = count($paginator);
}
$result = array();
foreach ($paginator as $object) {
$result[] = $object;
}
} else {
$result = $query->getResult();
}
if ($inlineCount !== null) {
return array('Results' => $result, 'InlineCount' => $inlineCount);
}
return $result;
}
示例15: paginate
/**
* @inheritDoc
*/
public function paginate($target, $offset, $limit)
{
$target->setFirstResult($offset)->setMaxResults($limit);
$paginator = new Paginator($target);
$this->total = $paginator->count();
return $paginator->getIterator();
}