|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
declare(strict_types=1); |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Repository; |
|
8
|
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\AbstractResource; |
|
10
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
11
|
|
|
use Chamilo\CoreBundle\Entity\ResourceLink; |
|
12
|
|
|
use Chamilo\CoreBundle\Entity\Session; |
|
13
|
|
|
use Chamilo\CoreBundle\Entity\User; |
|
14
|
|
|
use Chamilo\CoreBundle\Entity\Usergroup; |
|
15
|
|
|
use Chamilo\CourseBundle\Entity\CGroup; |
|
16
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
17
|
|
|
use Gedmo\Sortable\Entity\Repository\SortableRepository; |
|
18
|
|
|
|
|
19
|
|
|
class ResourceLinkRepository extends SortableRepository |
|
20
|
|
|
{ |
|
21
|
|
|
public function __construct(EntityManagerInterface $em) |
|
22
|
|
|
{ |
|
23
|
|
|
parent::__construct($em, $em->getClassMetadata(ResourceLink::class)); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function remove(ResourceLink $resourceLink): void |
|
27
|
|
|
{ |
|
28
|
|
|
$em = $this->getEntityManager(); |
|
29
|
|
|
|
|
30
|
|
|
// To move the resource link at the end to reorder the list |
|
31
|
|
|
$resourceLink->setDisplayOrder(-1); |
|
32
|
|
|
|
|
33
|
|
|
$em->flush(); |
|
34
|
|
|
// soft delete handled by Gedmo\SoftDeleteable |
|
35
|
|
|
$em->remove($resourceLink); |
|
36
|
|
|
$em->flush(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function removeByResourceInContext( |
|
40
|
|
|
AbstractResource $resource, |
|
41
|
|
|
Course $course, |
|
42
|
|
|
?Session $session = null, |
|
43
|
|
|
?CGroup $group = null, |
|
44
|
|
|
?Usergroup $usergroup = null, |
|
45
|
|
|
?User $user = null, |
|
46
|
|
|
): void { |
|
47
|
|
|
$link = $resource->getResourceNode()->getResourceLinkByContext($course, $session, $group, $usergroup, $user); |
|
48
|
|
|
|
|
49
|
|
|
if ($link) { |
|
50
|
|
|
$this->remove($link); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|