CQuizQuestionRepository.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Entity\Repository;
  3. use Doctrine\ORM\EntityRepository;
  4. use Doctrine\Common\Collections\Criteria;
  5. /**
  6. * CQuizQuestion
  7. *
  8. */
  9. class CQuizQuestionRepository extends EntityRepository
  10. {
  11. /**
  12. * Get all questions per category
  13. *
  14. * @param int $categoryId
  15. * @return \Doctrine\ORM\QueryBuilder
  16. */
  17. public function getQuestionsByCategory($categoryId)
  18. {
  19. // Setting alias for this class "q" = CQuizQuestion.
  20. $qb = $this->createQueryBuilder('q');
  21. // Select all question information.
  22. $qb->select('q');
  23. // Inner join with the table c_quiz_question_rel_category.
  24. $qb->innerJoin('q.quizQuestionRelCategoryList', 'c');
  25. // Inner join with question extra fields.
  26. //$qb->innerJoin('q.extraFields', 'e');
  27. $wherePart = $qb->expr()->andx();
  28. $wherePart->add($qb->expr()->eq('c.categoryId', $categoryId));
  29. $qb->where($wherePart);
  30. //echo $qb->getQuery()->getSQL()."<br>";
  31. return $qb;
  32. }
  33. }