erroneous behavior of the knp paginator bundle

0

I have two queries dql which I am paging with the knp paginator bundle. One for a generic search and another for the advanced search.

public function returnGenericSearchData(Request $request)
{
    $em = $this->em;
    $container = $this->container;
    $query = $em->createQuery(
        'SELECT u ,p FROM App\Entity\DisplayableComponent u JOIN u.images  p 
                  WHERE (u.name LIKE :text OR 
                  u.nombre LIKE :text OR
                  u.descripcion LIKE :text OR
                  u.description LIKE :text OR
                  u.municipio LIKE :text OR
                  u.provincia LIKE :text) 
                  AND 
                  (u NOT INSTANCE OF App\Entity\Habitacion AND u NOT INSTANCE OF App\Entity\Activity)
                  AND u.active = TRUE 
                  ORDER BY u.valoracion DESC'
    )->setParameters(['text'=>'%'.$request->get('searchText').'%',
        ]);
    $paginator = $container->get('knp_paginator');
    $results = $paginator->paginate(
        $query,
        $request->query->getInt('page', 1),
        $request->query->getInt('limit', 6)
    );
    return ($results);
}

public function returnAdvancedSearchData(Request $request){
    $lugar=$request->get('lugar');
    $cant=$request->get('cantidadP');
    $entrada=new \DateTime($request->get('fechaEntrada'));
    $salida=new \DateTime($request->get('fechaSalida'));        
    $dias=$entrada->diff($salida)->days;
    $em = $this->em;
    $container = $this->container;
    $query = $em->createQuery(
        'SELECT u ,p FROM App\Entity\DisplayableComponent u JOIN u.images  p 
                  WHERE (u.name LIKE :lugar OR 
                  u.nombre LIKE :lugar OR                      
                  u.municipio LIKE :lugar OR
                  u.provincia LIKE :lugar) 
                  AND 
                  (u NOT INSTANCE OF App\Entity\Habitacion AND u NOT INSTANCE OF App\Entity\Activity)
                  AND u.active = TRUE 
                  AND u.capacidad >= :cant
                  AND u.duracion < :dias
                  ORDER BY u.valoracion DESC'
    )->setParameters([
        'lugar'=>'%'.$lugar.'%',
        'cant'=>$cant,
        'dias'=>$dias,
    ]);
    $paginator = $container->get('knp_paginator');
    $results = $paginator->paginate(
        $query,
        $request->query->getInt('page', 1),
        $request->query->getInt('limit', 6)
    );
    return ($results);
}

I did a test for both searches and in both cases the total of results is 10, in the case of the advanced search works well, shows 6 results on the first page and 4 on the second. But in the case of the advanced search when changing to the second page it changes the totalCount to 0, it does not show anything. I do not even know how to trace this to look for the problem. Thanks in advance for your reply.

    
asked by Armando Rodríguez Acosta 13.11.2018 в 16:25
source

0 answers