Passed
Pull Request — 1.11.x (#4272)
by Angel Fernando Quiroz
09:53
created

CQuizQuestionRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 17
c 1
b 0
f 0
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A countQuestionsInExercise() 0 11 1
A countEmbeddableQuestionsInExercise() 0 16 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