src/Repository/CourseContentRepository.php line 54

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\CourseContent;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7.  * @method CourseContent|null find($id, $lockMode = null, $lockVersion = null)
  8.  * @method CourseContent|null findOneBy(array $criteria, array $orderBy = null)
  9.  * @method CourseContent[]    findAll()
  10.  * @method CourseContent[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11.  */
  12. class CourseContentRepository extends ServiceEntityRepository
  13. {
  14.     public function __construct(ManagerRegistry $registry)
  15.     {
  16.         parent::__construct($registryCourseContent::class);
  17.     }
  18.     public function findByPage($page$resultsPerPage$order 'ASC'$orderBy ""$keyword ""$course "")
  19.     {
  20.         $keyword filter_var($keywordFILTER_SANITIZE_STRING);
  21.         $order filter_var($orderFILTER_SANITIZE_STRING);
  22.         $orderBy filter_var($orderByFILTER_SANITIZE_STRING);
  23.         try {
  24.             $query $this->createQueryBuilder('c')
  25.                 ->leftJoin('c.course''co')
  26.                 ->setMaxResults($resultsPerPage)
  27.                 ->setFirstResult(($page 1) * $resultsPerPage);
  28.             if ($keyword !== "") {
  29.                 $query->andWhere('c.title LIKE :val')->setParameter('val''%' $keyword '%');
  30.             }
  31.             if($course !== ""){
  32.                 $query->andWhere('co.id = :coid')->setParameter('coid'$course);
  33.             }
  34.             if ($orderBy === "") {
  35.                 $query->orderBy('c.id''ASC');
  36.             } else {
  37.                 $query->orderBy("c." $orderBy$order);
  38.             }
  39.             return $query->getQuery()->getResult();
  40.         } catch (\Exception $exception) {
  41.             return [];
  42.         }
  43.     }
  44.     public function countByPage($keyword ""$course)
  45.     {
  46.         $keyword filter_var($keywordFILTER_SANITIZE_STRING);
  47.         try {
  48.             $query $this->createQueryBuilder('c')
  49.                 ->leftJoin('c.course''co')
  50.                 ->select('count(distinct(c.id))');
  51.             if ($keyword !== "") {
  52.                 $query->andWhere('c.title LIKE :val ')->setParameter('val''%' $keyword '%');
  53.             }
  54.             if($course !== ""){
  55.                 $query->andWhere('co.id = :coid')->setParameter('coid'$course);
  56.             }
  57.             return $query->getQuery()->getSingleScalarResult();
  58.         } catch (\Exception $exception) {
  59.             return [];
  60.         }
  61.     }
  62.     // /**
  63.     //  * @return CourseContent[] Returns an array of CourseContent objects
  64.     //  */
  65.     /*
  66.     public function findByExampleField($value)
  67.     {
  68.         return $this->createQueryBuilder('c')
  69.             ->andWhere('c.exampleField = :val')
  70.             ->setParameter('val', $value)
  71.             ->orderBy('c.id', 'ASC')
  72.             ->setMaxResults(10)
  73.             ->getQuery()
  74.             ->getResult()
  75.         ;
  76.     }
  77.     */
  78.     /*
  79.     public function findOneBySomeField($value): ?CourseContent
  80.     {
  81.         return $this->createQueryBuilder('c')
  82.             ->andWhere('c.exampleField = :val')
  83.             ->setParameter('val', $value)
  84.             ->getQuery()
  85.             ->getOneOrNullResult()
  86.         ;
  87.     }
  88.     */
  89. }