1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
namespace Chamilo\CourseBundle\Entity\Repository; |
6
|
|
|
|
7
|
|
|
use Chamilo\CourseBundle\Entity\CQuizRelQuestion; |
8
|
|
|
use Doctrine\ORM\EntityRepository; |
9
|
|
|
use Doctrine\ORM\NonUniqueResultException; |
10
|
|
|
use Doctrine\ORM\NoResultException; |
11
|
|
|
use Doctrine\ORM\Query\Expr\Join; |
12
|
|
|
|
13
|
|
|
class CQuizQuestionRepository extends EntityRepository |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @throws NonUniqueResultException |
17
|
|
|
* @throws NoResultException |
18
|
|
|
*/ |
19
|
|
|
public function countQuestionsInExercise(int $exerciseId): int |
20
|
|
|
{ |
21
|
|
|
$query = $this->createQueryBuilder('qq') |
22
|
|
|
->select('COUNT(qq)') |
23
|
|
|
->innerJoin(CQuizRelQuestion::class, 'qrq', Join::WITH, 'qq.iid = qrq.questionId') |
24
|
|
|
->where('qrq.exerciceId = :id') |
25
|
|
|
->setParameters(['id' => $exerciseId]) |
26
|
|
|
->getQuery() |
27
|
|
|
; |
28
|
|
|
|
29
|
|
|
return (int) $query->getSingleScalarResult(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @throws NonUniqueResultException |
34
|
|
|
* @throws NoResultException |
35
|
|
|
*/ |
36
|
|
|
public function countEmbeddableQuestionsInExercise(int $exerciseId): int |
37
|
|
|
{ |
38
|
|
|
$query = $this->createQueryBuilder('qq') |
39
|
|
|
->select('COUNT(qq)') |
40
|
|
|
->innerJoin(CQuizRelQuestion::class, 'qrq', Join::WITH, 'qq.iid = qrq.questionId') |
41
|
|
|
->where('qrq.exerciceId = :id AND qq.type IN (:types)') |
42
|
|
|
->setParameters( |
43
|
|
|
[ |
44
|
|
|
'id' => $exerciseId, |
45
|
|
|
'types' => \ExerciseLib::getEmbeddableTypes(), |
46
|
|
|
] |
47
|
|
|
) |
48
|
|
|
->getQuery() |
49
|
|
|
; |
50
|
|
|
|
51
|
|
|
return (int) $query->getSingleScalarResult(); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|