src/Repository/Law/LawRepository.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Repository\Law;
  3. use App\Entity\Law\Law;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7.  * @method Law|null find($id, $lockMode = null, $lockVersion = null)
  8.  * @method Law|null findOneBy(array $criteria, array $orderBy = null)
  9.  * @method Law[]    findAll()
  10.  * @method Law[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11.  */
  12. class LawRepository extends ServiceEntityRepository
  13. {
  14.     public function __construct(ManagerRegistry $registry)
  15.     {
  16.         parent::__construct($registryLaw::class);
  17.     }
  18.     /**
  19.      * @param string $localeCode: The request's locale
  20.      * @return Law[] Returns an array of Law objects
  21.      */
  22.     public function findLawsQuery($section$keyword)
  23.     {
  24.         $qb $this->createQueryBuilder('l')
  25.             ->select('l.id''l.author''l.date''l.image.name as image''l.title''l.link''l.fileDetails.name as pdf''l.description''l.createdAt''s.name as section''s.nameEng as sectionEng')
  26.             ->innerJoin('l.section''s')
  27.             ->orderBy('l.createdAt''DESC')
  28.         ;
  29.         if ($keyword) {
  30.             $qb->andWhere('(l.title LIKE :keyword OR l.author LIKE :keyword OR l.description LIKE :keyword OR s.name LIKE :keyword)')
  31.                 ->setParameter('keyword''%' $keyword '%');
  32.         } elseif ($section) {
  33.             $qb->andWhere('s.id = :id')->setParameter('id'$section->getId());
  34.         }
  35.         return $qb->getQuery();
  36.     }
  37.     public function findRecent($limit 10)
  38.     {
  39.         return $this->createQueryBuilder('l')
  40.             ->orderBy('l.createdAt''DESC')
  41.             ->setMaxResults($limit)
  42.             ->getQuery()
  43.             ->getResult()
  44.         ;
  45.     }
  46. }