<?php
namespace App\Repository;
use App\Entity\StageAcademy;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use DateTime;
/**
* @method StageAcademy|null find($id, $lockMode = null, $lockVersion = null)
* @method StageAcademy|null findOneBy(array $criteria, array $orderBy = null)
* @method StageAcademy[] findAll()
* @method StageAcademy[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class StageAcademyRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, StageAcademy::class);
}
public function search(int $page = 1, int $limit = 3, ?string $keywords, ?string $ville)
{
$query = $this->createQueryBuilder('s');
if($keywords && $keywords != '') {
$query->andWhere('LOWER(s.title LIKE) "%'.$keywords.'%" OR LOWER(s.description) LIKE "%'.$keywords.'%"');
}
if($ville && $ville != '') {
$query->andWhere("JSON_GET_TEXT(s.ville,0) LIKE '%".$ville."%'");
}
$query->orderBy('s.ordre', 'ASC');
$query->setMaxResults($limit);
$query->setFirstResult((($page-1)*$limit));
return $query->getQuery()->getResult();
}
}