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. 20
      public/main/exercise/matching.class.php

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

@ -2,6 +2,8 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CQuizAnswer;
/** /**
* Class Matching * Class Matching
* Matching questions type class. * Matching questions type class.
@ -305,20 +307,10 @@ class Matching extends Question
*/ */
public static function isCorrect($position, $answer, $questionId) public static function isCorrect($position, $answer, $questionId)
{ {
$em = Database::getManager(); $count = Database::getManager()
->getRepository(CQuizAnswer::class)
$count = $em ->count(['iid' => $position, 'correct' => $answer, 'question' => $questionId]);
->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; return (bool) $count;
} }
} }

Loading…
Cancel
Save