<?php
namespace App\Repository\Main;
use Doctrine\ORM\Tools\Pagination\Paginator;
/**
* MarketingTestimoniesRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class MarketingTestimoniesRepository extends \Doctrine\ORM\EntityRepository
{
/**
* @param int $page
* @param string $pageSize
* @param string $locale
* @return array
*/
public function getTestimoniesPaginator($page = 1, $pageSize = '5', $locale = 'fr')
{
$query = $this->createQueryBuilder('mt')
->where('mt.language = :locale')->setParameter('locale', $locale)
->andWhere('mt.testimonyDate < :currentTime')->setParameter('currentTime', (new \DateTime('now'))->format('Y-m-d H:i:s'))
->orderBy('mt.testimonyDate', 'DESC')
->getQuery();
$paginator = new Paginator($query);
$totalItems = count($paginator);
$paginator
->getQuery()
->setFirstResult($pageSize * ($page-1)) // set the offset
->setMaxResults($pageSize); // set the limit
return [
'paginator' => $paginator,
'totalItems' => $totalItems
];
}
/**
* @return array|int|string
*/
public function getTestimonies($locale)
{
$query = $this->createQueryBuilder('mt')
->where('mt.language = :locale')->setParameter('locale', $locale)
->andWhere('mt.testimonyDate < :currentTime')->setParameter('currentTime', (new \DateTime('now'))->format('Y-m-d H:i:s'))
->orderBy('mt.testimonyDate', 'DESC')
->getQuery();
return $query->getResult();
}
/**
* @param string $locale
* @return array|int|string
*/
public function getTestimoniesForLocale(string $locale = 'fr')
{
$query = $this->createQueryBuilder('mt')
->where('mt.language = :locale')->setParameter('locale', $locale)
->orderBy('mt.id', 'DESC')
->getQuery();
return $query->getResult();
}
}