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
|
|
|
|