Passed
Push — 1.11.x ( 3e2582...775a54 )
by Angel Fernando Quiroz
08:46
created

LogRepository::findByLevelAndExe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 1
b 0
f 0
cc 1
nop 2
nc 1
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\PluginBundle\ExerciseMonitoring\Repository;
6
7
use Chamilo\CoreBundle\Entity\TrackEExercises;
8
use Chamilo\CourseBundle\Entity\CQuizQuestion;
9
use Doctrine\ORM\EntityRepository;
10
use Doctrine\ORM\Query\Expr\Join;
11
use Exercise;
12
13
class LogRepository extends EntityRepository
14
{
15
    public function findByLevelAndExe(int $level, TrackEExercises $exe): array
16
    {
17
        return $this->findBy(
18
            [
19
                'level' => $level,
20
                'exe' => $exe,
21
            ],
22
            ['createdAt' => 'ASC']
23
        );
24
    }
25
26
    public function findSnapshots(Exercise $objExercise, TrackEExercises $trackExe)
27
    {
28
        $qb = $this->createQueryBuilder('l');
29
30
        $qb->select(['l.imageFilename', 'l.createdAt']);
31
32
        if (ONE_PER_PAGE == $objExercise->selectType()) {
33
            $qb
34
                ->addSelect(['qq.question AS log_level'])
35
                ->leftJoin(CQuizQuestion::class, 'qq', Join::WITH, 'l.level = qq.iid');
36
        }
37
38
        $query = $qb
39
            ->andWhere(
40
                $qb->expr()->eq('l.exe', $trackExe->getExeId())
41
            )
42
            ->addOrderBy('l.createdAt')
43
            ->getQuery();
44
45
        return $query->getResult();
46
    }
47
}
48