src/Repository/CourseQuizQuestionRepository.php line 34

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