src/Repository/CentroTrabajoRepository.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\CentroTrabajo;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. use  App\Utils\CustomPaginator;
  7. /**
  8.  * @method CentroTrabajo|null find($id, $lockMode = null, $lockVersion = null)
  9.  * @method CentroTrabajo|null findOneBy(array $criteria, array $orderBy = null)
  10.  * @method CentroTrabajo[]    findAll()
  11.  * @method CentroTrabajo[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  12.  */
  13. class CentroTrabajoRepository extends ServiceEntityRepository
  14. {
  15.     public function __construct(ManagerRegistry $registry)
  16.     {
  17.         parent::__construct($registryCentroTrabajo::class);
  18.     }
  19.     // /**
  20.     //  * @return CentroTrabajo[] Returns an array of CentroTrabajo objects
  21.     //  */
  22.     /*
  23.     public function findByExampleField($value)
  24.     {
  25.         return $this->createQueryBuilder('c')
  26.             ->andWhere('c.exampleField = :val')
  27.             ->setParameter('val', $value)
  28.             ->orderBy('c.id', 'ASC')
  29.             ->setMaxResults(10)
  30.             ->getQuery()
  31.             ->getResult()
  32.         ;
  33.     }
  34.     */
  35.     /*
  36.     public function findOneBySomeField($value): ?CentroTrabajo
  37.     {
  38.         return $this->createQueryBuilder('c')
  39.             ->andWhere('c.exampleField = :val')
  40.             ->setParameter('val', $value)
  41.             ->getQuery()
  42.             ->getOneOrNullResult()
  43.         ;
  44.     }
  45.     */
  46.     public function getAllCentros($data$currentPage 1$limit 12$sort$order)
  47.     {
  48.         $parameters = array();
  49.         $query $this->createQueryBuilder('Centro');
  50.         if (isset($data['value']) && $data['value'] != "") {
  51.             $query->andWhere('(
  52.                 Centro.CentroNombre like :where1
  53.             )');
  54.             $parameters[':where1'] = "%" $data['value'] . "%";
  55.         }
  56.         if (isset($data['nombre']) && '' != $data['nombre']) {
  57.             $query->andWhere('(
  58.                 Centro.CentroNombre like :nombre
  59.             )');
  60.             $parameters[':nombre'] = '%' $data['nombre'] . '%';
  61.         }
  62.         if (!empty($parameters)) {
  63.             $query->setParameters($parameters);
  64.         }
  65.         $query->addOrderBy($sort$order);
  66.         $query->getQuery();
  67.         //dd($query->getQuery()->getResult());
  68.         $paginator  = new CustomPaginator($query);
  69.         $result     $paginator->paginate($currentPage$limit);
  70.         if ($result['count'] > && $result['maxPages'] < $result['thisPage']) {
  71.             $result $paginator->paginate(1$limit);
  72.         }
  73.         return $result;
  74.     }
  75. }