Completed
Push — master ( 3681fe...d1b22d )
by Julito
12:24
created

CQuizRepository::deleteAllByCourse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 14
rs 10
c 1
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CourseBundle\Repository;
6
7
use Chamilo\CoreBundle\Entity\ResourceInterface;
8
use Chamilo\CoreBundle\Repository\ResourceRepository;
9
use Chamilo\CoreBundle\Repository\ResourceWithLinkInterface;
10
use Chamilo\CourseBundle\Entity\CQuiz;
11
use Symfony\Component\Routing\RouterInterface;
12
13
/**
14
 * Class CQuizRepository.
15
 */
16
final class CQuizRepository extends ResourceRepository implements ResourceWithLinkInterface
17
{
18
    public function getLink(ResourceInterface $resource, RouterInterface $router, $extraParams = []): string
19
    {
20
        $params = ['name' => 'exercise/overview.php', 'exerciseId' => $resource->getResourceIdentifier()];
21
        if (!empty($extraParams)) {
22
            $params = array_merge($params, $extraParams);
23
        }
24
25
        return $router->generate('legacy_main', $params);
26
    }
27
28
    public function deleteAllByCourse($course)
29
    {
30
        $qb = $this->getResourcesByCourse($course);
31
        $resources = $qb->getQuery()->getResult();
32
33
        /** @var CQuiz $quiz */
34
        foreach ($resources as $quiz) {
35
            $questions = $quiz->getQuestions();
36
            foreach ($questions as $question) {
37
                //$this->getEntityManager()->remove($question);
38
            }
39
            $this->getEntityManager()->remove($quiz);
40
        }
41
        $this->getEntityManager()->flush();
42
    }
43
}
44