src/Repository/Main/MarketingTestimoniesRepository.php line 53

Open in your IDE?
  1. <?php
  2. namespace App\Repository\Main;
  3. use Doctrine\ORM\Tools\Pagination\Paginator;
  4. /**
  5.  * MarketingTestimoniesRepository
  6.  *
  7.  * This class was generated by the Doctrine ORM. Add your own custom
  8.  * repository methods below.
  9.  */
  10. class MarketingTestimoniesRepository extends \Doctrine\ORM\EntityRepository
  11. {
  12.     /**
  13.      * @param int $page
  14.      * @param string $pageSize
  15.      * @param string $locale
  16.      * @return array
  17.      */
  18.     public function getTestimoniesPaginator($page 1$pageSize '5'$locale 'fr')
  19.     {
  20.         $query $this->createQueryBuilder('mt')
  21.             ->where('mt.language = :locale')->setParameter('locale'$locale)
  22.             ->andWhere('mt.testimonyDate < :currentTime')->setParameter('currentTime', (new \DateTime('now'))->format('Y-m-d H:i:s'))
  23.             ->orderBy('mt.testimonyDate''DESC')
  24.             ->getQuery();
  25.         $paginator = new Paginator($query);
  26.         $totalItems count($paginator);
  27.         $paginator
  28.             ->getQuery()
  29.             ->setFirstResult($pageSize * ($page-1)) // set the offset
  30.             ->setMaxResults($pageSize); // set the limit
  31.         return [
  32.             'paginator' => $paginator,
  33.             'totalItems' => $totalItems
  34.         ];
  35.     }
  36.     /**
  37.      * @return array|int|string
  38.      */
  39.     public function getTestimonies($locale)
  40.     {
  41.         $query $this->createQueryBuilder('mt')
  42.             ->where('mt.language = :locale')->setParameter('locale'$locale)
  43.             ->andWhere('mt.testimonyDate < :currentTime')->setParameter('currentTime', (new \DateTime('now'))->format('Y-m-d H:i:s'))
  44.             ->orderBy('mt.testimonyDate''DESC')
  45.             ->getQuery();
  46.         return $query->getResult();
  47.     }
  48.     /**
  49.      * @param string $locale
  50.      * @return array|int|string
  51.      */
  52.     public function getTestimoniesForLocale(string $locale 'fr')
  53.     {
  54.         $query $this->createQueryBuilder('mt')
  55.             ->where('mt.language = :locale')->setParameter('locale'$locale)
  56.             ->orderBy('mt.id''DESC')
  57.             ->getQuery();
  58.         return $query->getResult();
  59.     }
  60. }