/**
  * {@inheritdoc}
  */
 public function getResult(QueryBuilder $queryBuilder)
 {
     $doctrineOrmPaginator = new DoctrineOrmPaginator($queryBuilder);
     // Disable output walkers by default (performance)
     $doctrineOrmPaginator->setUseOutputWalkers(false);
     return new Paginator($doctrineOrmPaginator);
 }
Exemplo n.º 2
0
 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);
 }
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * 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());
 }
Exemplo n.º 5
0
 /**
  * @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]]);
 }
Exemplo n.º 6
0
 /**
  * (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;
 }
 /**
  * @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;
 }
 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;
 }
Exemplo n.º 9
0
 /**
  * @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());
 }
Exemplo n.º 10
0
 /**
  * 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;
 }
Exemplo n.º 11
0
 /**
  * Required by interface IteratorAggregate.
  *
  * {@inheritdoc}
  */
 public function getIterator()
 {
     $query = $this->paginator->getQuery();
     $query->setFirstResult(null);
     $query->setMaxResults(null);
     return $this->paginator;
 }
Exemplo n.º 12
0
 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);
 }
Exemplo n.º 13
0
 public function paginate(QueryBuilder $query, $limit, $page)
 {
     $query->setMaxResults($limit)->setFirstResult($limit * ($page - 1));
     $paginator = new Paginator($query->getQuery());
     $paginator->setUseOutputWalkers(false);
     return $paginator;
 }
Exemplo n.º 14
0
 /**
  * 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;
 }
Exemplo n.º 15
0
 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;
 }
Exemplo n.º 16
0
 /**
  * @inheritDoc
  */
 public function paginate($target, $offset, $limit)
 {
     $target->setFirstResult($offset)->setMaxResults($limit);
     $paginator = new Paginator($target);
     $this->total = $paginator->count();
     return $paginator->getIterator();
 }
 /**
  * @param string $collector
  * @param int    $page
  * @param int    $maxItemPerPage
  *
  * @return Paginator
  */
 public function findByCollector($collector, $page, $maxItemPerPage)
 {
     $query = $this->createQueryBuilder('c')->where('c.collector = :collector')->setParameter('collector', $collector)->getQuery();
     $paginator = new Paginator($query);
     $paginator->getQuery()->setFirstResult($maxItemPerPage * ($page - 1))->setMaxResults($maxItemPerPage);
     return $paginator;
 }
Exemplo n.º 18
0
 /**
  * Paginator Helper
  * Pass through a query object, current page & limit
  * the offset is calculated from the page and limit
  * returns an `Paginator` instance, which you can call the following on:
  * $paginator->getIterator()->count() # Total fetched (ie: `5` posts)
  * $paginator->count() # Count of ALL posts (ie: `20` posts)
  * $paginator->getIterator() # ArrayIterator
  * 
  * @param Doctrine\ORM\Query $dql
  *            DQL Query Object
  * @param integer $page
  *            Current page (defaults to 1)
  * @param integer $limit
  *            The total number per page (defaults to 5)
  * @return \Doctrine\ORM\Tools\Pagination\Paginator
  */
 public function paginate($dql, $page = 1, $limit = 15)
 {
     $paginator = new Paginator($dql);
     $paginator->getQuery()->setFirstResult($limit * ($page - 1))->setMaxResults($limit);
     // Limit
     return $paginator;
 }
Exemplo n.º 19
0
 public function buildCount($query)
 {
     // Getting count
     $paginator = new Paginator($this->getQuery());
     //$paginator->setUseOutputWalkers(false);
     $this->setCount($paginator->count());
     return $this;
 }
 /**
  * Get the latest moderation actions
  *
  * @param  integer  $offset
  * @param  integer  $limit
  *
  * @return Paginator
  */
 public function getLatestModerations($offset, $limit)
 {
     $queryBuilder = $this->createQueryBuilder('mo')->select(array('mo', 'u', 'f', 'm', 't', 'b'))->join('mo.user', 'u')->leftJoin('mo.flag', 'f')->leftJoin('mo.message', 'm')->leftJoin('mo.topic', 't')->leftJoin('mo.board', 'b')->orderBy('mo.id', 'DESC');
     $query = $queryBuilder->getQuery();
     $query->setFirstResult($offset)->setMaxResults($limit);
     $paginator = new Paginator($query, false);
     return $paginator->setUseOutputWalkers(false);
 }
Exemplo n.º 21
0
 public function __construct(DoctrineOrmPaginator $paginator)
 {
     $this->paginator = $paginator;
     $query = $paginator->getQuery();
     $this->firstResult = $query->getFirstResult();
     $this->maxResults = $query->getMaxResults();
     $this->totalItems = count($paginator);
 }
 public function paginate($dql, $offset = 1, $limit = 10)
 {
     if ($limit > 100 || $limit <= 0) {
         $limit = 100;
     }
     $paginator = new Paginator($dql, false);
     $paginator->getQuery()->setMaxResults($limit)->setFirstResult(($offset - 1) * $limit);
     return $paginator;
 }
Exemplo n.º 23
0
 public function getLatestTopicsByBoard(BoardInterface $board, $offset, $limit, $isDeleted)
 {
     $queryBuilder = $this->createQueryBuilder('t')->select(array('t'))->where('t.board = :board')->setParameter('board', $board)->addOrderBy('t.isPinned', 'DESC')->addOrderBy('t.lastMessageDate', 'DESC');
     if ($isDeleted !== null) {
         $queryBuilder->andWhere('t.isDeleted = :isDeleted')->setParameter('isDeleted', $isDeleted);
     }
     $query = $queryBuilder->getQuery()->setFirstResult($offset)->setMaxResults($limit);
     $paginator = new Paginator($query, false);
     return $paginator->setUseOutputWalkers(false);
 }
Exemplo n.º 24
0
 public function getTotalCount() : int
 {
     $queryBuilder = $this->getQueryBuilder();
     $query = $queryBuilder->getQuery();
     $query->useQueryCache(true);
     $query->useResultCache(true);
     $paginator = new Paginator($query, true);
     $paginator->setUseOutputWalkers(false);
     return $paginator->count();
 }
 public function getListagem($arrData = array(), $intPage = 1, $intQtdPage = 10)
 {
     $queryBuilder = $this->_em->createQueryBuilder();
     $queryBuilder->select('Empreendimento')->from('Application\\Entity\\Empreendimento', 'Empreendimento')->innerJoin('Application\\Entity\\Municipio', 'Municipio', 'with', 'Municipio.idMunicipio = Empreendimento.idMunicipio')->innerJoin('Application\\Entity\\Estado', 'Estado', 'with', 'Estado.idEstado = Municipio.idEstado')->setMaxResults($intQtdPage)->setFirstResult($intPage * ($intPage - 1))->orderBy('Empreendimento.dsEmpreendimento', 'asc');
     $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;
 }
Exemplo n.º 26
0
 public function listCompanies($page = 1, $pageSize = 20)
 {
     $query = $this->em->createQuery('SELECT c, cls FROM SSEICSSBundle:Company c LEFT JOIN c.class cls ORDER BY c.id ASC');
     $paginator = new Paginator($query);
     $paginator->setUseOutputWalkers(false);
     $totalRecruits = count($paginator);
     $pagesCount = ceil($totalRecruits / $pageSize);
     $paginator->getQuery()->setFirstResult($pageSize * ($page - 1))->setMaxResults($pageSize);
     $list = $query->getArrayResult();
     return ["totalRecruits" => $totalRecruits, "currentPage" => $page, "pagesCount" => $pagesCount, "list" => $list];
 }
Exemplo n.º 27
0
 /**
  * @return Job
  */
 public function findAllPublishedOrderedByRecentlyActive(JobSearchFormTypeData $data, $currentPage = 1, $limit = 5)
 {
     $query = $this->findAllPublishedOrderedByRecentlyActiveQ($data);
     // Paginator
     $paginator = new Paginator($query);
     $rowsCountTotal = $paginator->count();
     $data = $query->setFirstResult($limit * ($currentPage - 1))->setMaxResults($limit)->execute();
     // ->getOneOrNullResult()
     $rowsCountThisPage = count($data);
     return ['limit' => $limit, 'currentPage' => $currentPage, 'maxPages' => ceil($rowsCountTotal / $limit), 'rowsCountTotal' => $rowsCountTotal, 'rowsCountThisPage' => $rowsCountThisPage, 'data' => $data];
 }
Exemplo n.º 28
0
 public function findAllStartsWith($letter, $page, $per_page)
 {
     $query = $this->joinQuery();
     if ($letter != 'ALL') {
         $query->where('s.name LIKE :letter')->setParameter('letter', "{$letter}%");
     }
     $query->orderBy('s.name', 'ASC')->addOrderBy('p.name', 'ASC')->addOrderBy('i.imageName', 'ASC');
     $paginator = new Paginator($query, $fetchJoinCollection = true);
     $paginator->getQuery()->setFirstResult(($page - 1) * $per_page)->setMaxResults($per_page);
     return $paginator;
 }
Exemplo n.º 29
0
 /**
  * @param $params
  *
  * @return mixed
  */
 public function findWithJoins($params)
 {
     $queryBuilder = $this->createQueryBuilder('h')->select('h, s, t, lc, cer, pm, hp, tr')->leftJoin('h.services', 's')->leftJoin('h.thematics', 't')->leftJoin('h.linkedCities', 'lc')->leftJoin('h.certificates', 'cer')->leftJoin('h.paymentMethods', 'pm')->leftJoin('h.hotelPois', 'hp')->leftJoin('h.transports', 'tr');
     $i = 0;
     foreach ($params as $key => $value) {
         $queryBuilder->andWhere("h.{$key} = :param_{$i}")->setParameter("param_{$i}", $value);
         $i++;
     }
     $query = $queryBuilder->setMaxResults(1)->getQuery();
     $results = new Paginator($query, $fetchJoin = true);
     return $results->getIterator()->current();
 }
Exemplo n.º 30
0
 /**
  * {@inheritdoc}
  */
 public function getTotalRows(QueryBuilder $queryBuilder, ColumnCollection $columns)
 {
     $builder = clone $queryBuilder;
     $having = $builder->getDQLPart('having');
     if (is_object($having)) {
         $this->replaceHaving($having, $columns, $builder);
     }
     $query = $builder->getQuery();
     $paginator = new Paginator($query, true);
     $paginator->setUseOutputWalkers(false);
     return $paginator->count();
 }