Passed
Push — master ( 7dd8b7...258428 )
by Julito
07:42
created

CLpRepository   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getLink() 0 12 2
A createLp() 0 14 2
A addNotDeletedQueryBuilder() 0 7 1
A __construct() 0 3 1
A findAllByCourse() 0 19 1
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CourseBundle\Repository;
8
9
use Chamilo\CoreBundle\Entity\Course;
10
use Chamilo\CoreBundle\Entity\ResourceInterface;
11
use Chamilo\CoreBundle\Entity\Session;
12
use Chamilo\CoreBundle\Repository\ResourceRepository;
13
use Chamilo\CoreBundle\Repository\ResourceWithLinkInterface;
14
use Chamilo\CourseBundle\Entity\CLp;
15
use Chamilo\CourseBundle\Entity\CLpItem;
16
use Doctrine\ORM\QueryBuilder;
17
use Doctrine\Persistence\ManagerRegistry;
18
use Exception;
19
use Symfony\Component\Routing\RouterInterface;
20
21
final class CLpRepository extends ResourceRepository implements ResourceWithLinkInterface
22
{
23
    public function __construct(ManagerRegistry $registry)
24
    {
25
        parent::__construct($registry, CLp::class);
26
    }
27
28
    public function createLp(CLp $lp): void
29
    {
30
        if (null !== $lp->getResourceNode()) {
31
            throw new Exception('Lp should not have a resource node during creation');
32
        }
33
34
        $lpItem = (new CLpItem())
35
            ->setTitle('root')
36
            ->setPath('root')
37
            ->setLp($lp)
38
            ->setItemType('root')
39
        ;
40
        $lp->getItems()->add($lpItem);
41
        $this->create($lp);
42
    }
43
44
    public function findAllByCourse(
45
        Course $course,
46
        Session $session = null,
47
        ?string $title = null,
48
        ?int $active = null,
49
        bool $onlyPublished = true,
50
        ?int $categoryId = null
51
    ): QueryBuilder {
52
        $qb = $this->getResourcesByCourse($course, $session);
53
54
        /*if ($onlyPublished) {
55
            $this->addDateFilterQueryBuilder(new DateTime(), $qb);
56
        }*/
57
        //$this->addCategoryQueryBuilder($categoryId, $qb);
58
        //$this->addActiveQueryBuilder($active, $qb);
59
        //$this->addNotDeletedQueryBuilder($qb);
60
        $this->addTitleQueryBuilder($title, $qb);
61
62
        return $qb;
63
    }
64
65
    public function getLink(ResourceInterface $resource, RouterInterface $router, array $extraParams = []): string
66
    {
67
        $params = [
68
            'lp_id' => $resource->getResourceIdentifier(),
69
            'name' => 'lp/lp_controller.php',
70
            'action' => 'view',
71
        ];
72
        if (!empty($extraParams)) {
73
            $params = array_merge($params, $extraParams);
74
        }
75
76
        return $router->generate('legacy_main', $params);
77
    }
78
79
    private function addNotDeletedQueryBuilder(QueryBuilder $qb = null): QueryBuilder
0 ignored issues
show
Unused Code introduced by
The method addNotDeletedQueryBuilder() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
80
    {
81
        $qb = $this->getOrCreateQueryBuilder($qb);
82
83
        $qb->andWhere('resource.active <> -1');
84
85
        return $qb;
86
    }
87
}
88