Passed
Push — master ( edd7fd...017cdc )
by Yannick
15:03 queued 06:38
created

getPendingCorrectionsByExercise()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Repository;
8
9
use Chamilo\CoreBundle\Entity\TrackEExercise;
10
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
11
use Doctrine\Persistence\ManagerRegistry;
12
13
class TrackEExerciseRepository extends ServiceEntityRepository
14
{
15
    public function __construct(ManagerRegistry $registry)
16
    {
17
        parent::__construct($registry, TrackEExercise::class);
18
    }
19
20
    public function delete(TrackEExercise $track): void
21
    {
22
        $this->getEntityManager()->remove($track);
23
        $this->getEntityManager()->flush();
24
    }
25
26
    /**
27
     * Get exercises with pending corrections grouped by exercise ID.
28
     */
29
    public function getPendingCorrectionsByExercise(int $courseId): array
30
    {
31
        $qb = $this->createQueryBuilder('te');
32
33
        $qb->select('IDENTITY(te.quiz) AS exerciseId, COUNT(te.exeId) AS pendingCount')
34
            ->where('te.status = :status')
35
            ->andWhere('te.course = :courseId')
36
            ->setParameter('status', 'incomplete')
37
            ->setParameter('courseId', $courseId)
38
            ->groupBy('te.quiz');
39
40
        return $qb->getQuery()->getResult();
41
    }
42
}
43