Passed
Pull Request — 1.11.x (#4272)
by Angel Fernando Quiroz
16:11 queued 05:16
created

countQuestionsInExercise()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nop 1
nc 1
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