Passed
Pull Request — master (#5063)
by Angel Fernando Quiroz
06:57
created

CToolExtension::applyToCollection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 5
dl 0
loc 21
rs 9.9332
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\DataProvider\Extension;
8
9
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
10
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
11
use ApiPlatform\Metadata\Operation;
12
use Chamilo\CoreBundle\Entity\ResourceLink;
13
use Chamilo\CoreBundle\Traits\ControllerTrait;
14
use Chamilo\CoreBundle\Traits\CourseControllerTrait;
15
use Chamilo\CourseBundle\Entity\CTool;
16
use Doctrine\ORM\QueryBuilder;
17
18
class CToolExtension implements QueryCollectionExtensionInterface
19
{
20
    use ControllerTrait;
21
    use CourseControllerTrait;
22
23
    public function applyToCollection(
24
        QueryBuilder $queryBuilder,
25
        QueryNameGeneratorInterface $queryNameGenerator,
26
        string $resourceClass,
27
        Operation $operation = null,
28
        array $context = []
29
    ): void {
30
        if (CTool::class !== $resourceClass) {
31
            return;
32
        }
33
34
        $alias = $queryBuilder->getRootAliases()[0];
35
36
        $queryBuilder
37
            ->innerJoin("$alias.resourceNode", 'resource_node')
38
            ->innerJoin('resource_node.resourceLinks', 'resource_links')
39
            ->andWhere(
40
                $queryBuilder->expr()->notIn("$alias.name", ['course_tool', 'course_homepage'])
41
            )
42
            ->andWhere('resource_links.visibility != :visibility_deleted')
43
            ->setParameter('visibility_deleted', ResourceLink::VISIBILITY_DELETED)
44
        ;
45
    }
46
}
47