Passed
Push — master ( 193096...d89cdc )
by Julito
07:30
created

CLpRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 15
c 1
b 1
f 0
dl 0
loc 49
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getLink() 0 12 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 Doctrine\ORM\QueryBuilder;
16
use Doctrine\Persistence\ManagerRegistry;
17
use Symfony\Component\Routing\RouterInterface;
18
19
final class CLpRepository extends ResourceRepository implements ResourceWithLinkInterface
20
{
21
    public function __construct(ManagerRegistry $registry)
22
    {
23
        parent::__construct($registry, CLp::class);
24
    }
25
26
    public function findAllByCourse(
27
        Course $course,
28
        Session $session = null,
29
        ?string $title = null,
30
        ?int $active = null,
31
        bool $onlyPublished = true,
32
        ?int $categoryId = null
33
    ): QueryBuilder {
34
        $qb = $this->getResourcesByCourse($course, $session);
35
36
        /*if ($onlyPublished) {
37
            $this->addDateFilterQueryBuilder(new DateTime(), $qb);
38
        }*/
39
        //$this->addCategoryQueryBuilder($categoryId, $qb);
40
        //$this->addActiveQueryBuilder($active, $qb);
41
        //$this->addNotDeletedQueryBuilder($qb);
42
        $this->addTitleQueryBuilder($title, $qb);
43
44
        return $qb;
45
    }
46
47
    public function getLink(ResourceInterface $resource, RouterInterface $router, array $extraParams = []): string
48
    {
49
        $params = [
50
            'lp_id' => $resource->getResourceIdentifier(),
51
            'name' => 'lp/lp_controller.php',
52
            'action' => 'view',
53
        ];
54
        if (!empty($extraParams)) {
55
            $params = array_merge($params, $extraParams);
56
        }
57
58
        return $router->generate('legacy_main', $params);
59
    }
60
61
    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...
62
    {
63
        $qb = $this->getOrCreateQueryBuilder($qb);
64
65
        $qb->andWhere('resource.active <> -1');
66
67
        return $qb;
68
    }
69
}
70