Use DQL to get questions by category - refs #8079

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent c165f721c1
commit 70b667c9e8
  1. 40
      main/exercice/TestCategory.php

@ -443,26 +443,32 @@ class TestCategory
*/ */
public static function getQuestionsByCat($exerciseId) public static function getQuestionsByCat($exerciseId)
{ {
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $em = Database::getManager();
$TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); $qb = $em->createQueryBuilder();
$exerciseId = intval($exerciseId); $res = $qb
$sql = "SELECT qrc.question_id, qrc.category_id ->select('qrc.questionId', 'qrc.categoryId')
FROM $TBL_QUESTION_REL_CATEGORY qrc, $TBL_EXERCISE_QUESTION eq ->from('ChamiloCourseBundle:CQuizQuestionRelCategory', 'qrc')
WHERE ->innerJoin(
exercice_id=$exerciseId AND 'ChamiloCourseBundle:CQuizRelQuestion',
eq.question_id=qrc.question_id AND 'eq',
eq.c_id=".api_get_course_int_id()." AND Doctrine\ORM\Query\Expr\Join::WITH,
eq.c_id=qrc.c_id 'qrc.questionId = eq.questionId AND qrc.cId = eq.cId'
ORDER BY category_id, question_id"; )
$res = Database::query($sql); ->where(
$qb->expr()->eq('eq.exerciceId', $exerciseId)
)
->andWhere(
$qb->expr()->eq('eq.cId', api_get_course_int_id())
)
->getQuery()
->getResult();
$list = array(); $list = array();
while ($data = Database::fetch_array($res)) { foreach ($res as $data) {
if (!isset($list[$data['category_id']])) { if (!isset($list[$data['categoryId']])) {
$list[$data['category_id']] = array(); $list[$data['categoryId']] = array();
} }
$list[$data['category_id']][] = $data['question_id']; $list[$data['categoryId']][] = $data['questionId'];
} }
return $list; return $list;
} }

Loading…
Cancel
Save