Fix queries using question instead of questionId - refs BT#19231

pull/4032/head
Angel Fernando Quiroz Campos 3 years ago
parent 9a267dce3c
commit 6bab36da84
  1. 9
      public/main/exercise/hotspot_answers.as.php
  2. 22
      public/main/exercise/matching.class.php

@ -167,18 +167,17 @@ if (!$hideExpectedAnswer) {
$qb = $em->createQueryBuilder();
$qb
->select('a')
->from('ChamiloCourseBundle:CQuizAnswer', 'a');
->from(CQuizAnswer::class, 'a')
->where($qb->expr()->eq('a.cId', $courseId));
if (HOT_SPOT_DELINEATION == $objQuestion->getType()) {
$qb
->where($qb->expr()->eq('a.cId', $courseId))
->andWhere($qb->expr()->eq('a.questionId', $questionId))
->andWhere($qb->expr()->eq('a.question', $questionId))
->andWhere($qb->expr()->neq('a.hotspotType', 'noerror'))
->orderBy('a.id', 'ASC');
} else {
$qb
->where($qb->expr()->eq('a.cId', $courseId))
->andWhere($qb->expr()->eq('a.questionId', $questionId))
->andWhere($qb->expr()->eq('a.question', $questionId))
->orderBy('a.position', 'ASC');
}

@ -2,6 +2,8 @@
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CQuizAnswer;
/**
* Class Matching
* Matching questions type class.
@ -305,20 +307,10 @@ class Matching extends Question
*/
public static function isCorrect($position, $answer, $questionId)
{
$em = Database::getManager();
$count = $em
->createQuery('
SELECT COUNT(a) From ChamiloCourseBundle:CQuizAnswer a
WHERE a.iid = :position AND a.correct = :answer AND a.questionId = :question
')
->setParameters([
'position' => $position,
'answer' => $answer,
'question' => $questionId,
])
->getSingleScalarResult();
return $count ? true : false;
$count = Database::getManager()
->getRepository(CQuizAnswer::class)
->count(['iid' => $position, 'correct' => $answer, 'question' => $questionId]);
return (bool) $count;
}
}

Loading…
Cancel
Save