Completed
Push — master ( 3742bc...55196a )
by Julito
13:21
created

ResourceRepository::addResourceNodeParent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 2
nop 3
dl 0
loc 23
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Repository;
5
6
use APY\DataGridBundle\Grid\Action\RowAction;
7
use APY\DataGridBundle\Grid\Row;
8
use Chamilo\CoreBundle\Entity\Course;
9
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
10
use Chamilo\CoreBundle\Entity\Resource\ResourceFile;
11
use Chamilo\CoreBundle\Entity\Resource\ResourceLink;
12
use Chamilo\CoreBundle\Entity\Resource\ResourceNode;
13
use Chamilo\CoreBundle\Entity\Resource\ResourceRight;
14
use Chamilo\CoreBundle\Entity\Resource\ResourceType;
15
use Chamilo\CoreBundle\Entity\Session;
16
use Chamilo\CoreBundle\Entity\Tool;
17
use Chamilo\CoreBundle\Entity\Usergroup;
18
use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter;
19
use Chamilo\CoreBundle\ToolChain;
20
use Chamilo\CourseBundle\Entity\CGroupInfo;
21
use Chamilo\UserBundle\Entity\User;
22
use Cocur\Slugify\Slugify;
23
use Cocur\Slugify\SlugifyInterface;
24
use Doctrine\ORM\EntityManager;
25
use Doctrine\ORM\Query\Expr\Join;
26
use Doctrine\ORM\QueryBuilder;
27
use League\Flysystem\FilesystemInterface;
28
use League\Flysystem\MountManager;
29
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
30
use Symfony\Component\Form\FormFactory;
31
use Symfony\Component\Form\FormInterface;
32
use Symfony\Component\HttpFoundation\File\UploadedFile;
33
use Symfony\Component\Routing\RouterInterface;
34
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
35
36
/**
37
 * Class ResourceRepository.
38
 */
39
class ResourceRepository extends EntityRepository
40
{
41
    /**
42
     * @var EntityRepository
43
     */
44
    protected $repository;
45
46
    /**
47
     * @var FilesystemInterface
48
     */
49
    protected $fs;
50
51
    /**
52
     * @var EntityManager
53
     */
54
    protected $entityManager;
55
56
    /**
57
     * The entity class FQN.
58
     *
59
     * @var string
60
     */
61
    protected $className;
62
63
    /** @var RouterInterface */
64
    protected $router;
65
66
    protected $resourceNodeRepository;
67
68
    /**
69
     * @var AuthorizationCheckerInterface
70
     */
71
    protected $authorizationChecker;
72
73
    /**
74
     * @var MountManager
75
     */
76
    protected $mountManager;
77
    protected $slugify;
78
79
    /**
80
     * ResourceRepository constructor.
81
     *
82
     * @param AuthorizationCheckerInterface $authorizationChecker
83
     * @param EntityManager                 $entityManager
84
     * @param MountManager                  $mountManager
85
     * @param RouterInterface               $router
86
     * @param string                        $className
87
     */
88
    public function __construct(
89
        AuthorizationCheckerInterface $authorizationChecker,
90
        EntityManager $entityManager,
91
        MountManager $mountManager,
92
        RouterInterface $router,
93
        SlugifyInterface $slugify,
94
        string $className
95
    ) {
96
        $this->repository = $entityManager->getRepository($className);
97
        // Flysystem mount name is saved in config/packages/oneup_flysystem.yaml @todo add it as a service.
98
        $this->fs = $mountManager->getFilesystem('resources_fs');
99
        $this->mountManager = $mountManager;
100
        $this->router = $router;
101
        //$this->toolChain = $toolChain;
102
        $this->resourceNodeRepository = $entityManager->getRepository('ChamiloCoreBundle:Resource\ResourceNode');
103
        $this->authorizationChecker = $authorizationChecker;
104
        $this->slugify = $slugify;
105
    }
106
107
    /**
108
     * @return AuthorizationCheckerInterface
109
     */
110
    public function getAuthorizationChecker(): AuthorizationCheckerInterface
111
    {
112
        return $this->authorizationChecker;
113
    }
114
115
    /**
116
     * @return mixed
117
     */
118
    public function create()
119
    {
120
        return new $this->className();
121
    }
122
123
    /**
124
     * @return RouterInterface
125
     */
126
    public function getRouter(): RouterInterface
127
    {
128
        return $this->router;
129
    }
130
131
    /**
132
     * @return ResourceNodeRepository
133
     */
134
    public function getResourceNodeRepository()
135
    {
136
        return $this->resourceNodeRepository;
137
    }
138
139
    /**
140
     * @return FilesystemInterface
141
     */
142
    public function getFileSystem()
143
    {
144
        return $this->fs;
145
    }
146
147
    /**
148
     * @return EntityManager
149
     */
150
    public function getEntityManager(): EntityManager
151
    {
152
        return $this->getRepository()->getEntityManager();
153
    }
154
155
    /**
156
     * @return EntityRepository
157
     */
158
    public function getRepository()
159
    {
160
        return $this->repository;
161
    }
162
163
    /**
164
     * @param FormFactory $formFactory
165
     *
166
     * @return FormInterface
167
     */
168
    public function getForm(FormFactory $formFactory, AbstractResource $resource = null)
169
    {
170
        $className = $this->repository->getClassName();
171
        $shortName = (new \ReflectionClass($className))->getShortName();
172
173
        $formType = str_replace('Entity\CDocument', 'Form\\Type', $className).'\\'.$shortName.'Type';
174
175
        if ($resource === null){
176
            $resource = new $className;
177
        }
178
179
        return $formFactory->create($formType, $resource);
180
    }
181
182
    /**
183
     * @param mixed $id
184
     * @param null  $lockMode
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $lockMode is correct as it would always require null to be passed?
Loading history...
185
     * @param null  $lockVersion
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $lockVersion is correct as it would always require null to be passed?
Loading history...
186
     *
187
     * @return AbstractResource|null
188
     */
189
    public function find($id, $lockMode = null, $lockVersion = null): ?AbstractResource
190
    {
191
        return $this->getRepository()->find($id);
192
    }
193
194
    /**
195
     * @return AbstractResource|null
196
     */
197
    public function findOneBy(array $criteria, array $orderBy = null): ?AbstractResource
198
    {
199
        return $this->getRepository()->findOneBy($criteria, $orderBy);
200
    }
201
202
    /**
203
     * @return ResourceFile|null
204
     */
205
    public function addFile(ResourceNode $resourceNode, UploadedFile $file): ?ResourceFile
206
    {
207
        $resourceFile = $resourceNode->getResourceFile();
208
        if (null === $resourceFile) {
209
            $resourceFile = new ResourceFile();
210
        }
211
212
        $em = $this->getEntityManager();
213
214
        $resourceFile->setFile($file);
215
        $resourceFile->setName($resourceNode->getName());
216
        $em->persist($resourceFile);
217
        $resourceNode->setResourceFile($resourceFile);
218
        $em->persist($resourceNode);
219
        $em->flush();
220
221
        return $resourceFile;
222
    }
223
224
    /**
225
     * @param AbstractResource  $resource
226
     * @param User              $creator
227
     * @param ResourceNode|null $parent
228
     *
229
     * @return ResourceNode
230
     */
231
    public function addResourceNodeParent(AbstractResource $resource, User $creator, ResourceNode $parent = null): ResourceNode
232
    {
233
        $em = $this->getEntityManager();
234
235
        $resourceType = $this->getResourceType();
236
        $resourceNode = new ResourceNode();
237
        $resourceNode
238
            ->setName($resource->getResourceName())
239
            ->setCreator($creator)
240
            ->setResourceType($resourceType)
241
        ;
242
243
        if (null !== $parent) {
244
            $resourceNode->setParent($parent);
245
        }
246
247
        $resource->setResourceNode($resourceNode);
248
249
        $em->persist($resourceNode);
250
        $em->persist($resource);
251
        $em->flush();
252
253
        return $resourceNode;
254
    }
255
256
    /**
257
     * @param AbstractResource      $resource
258
     * @param User                  $creator
259
     * @param AbstractResource|null $parent
260
     *
261
     * @return ResourceNode
262
     */
263
    public function addResourceNode(AbstractResource $resource, User $creator, AbstractResource $parent = null): ResourceNode
264
    {
265
        if (null !== $parent) {
266
            $parent = $parent->getResourceNode();
267
        }
268
269
        return $this->addResourceNodeParent($resource, $creator, $parent);
270
    }
271
272
    /**
273
     * @param AbstractResource $resource
274
     * @param int              $visibility
275
     * @param User             $creator
276
     * @param Course           $course
277
     * @param Session|null     $session
278
     * @param CGroupInfo|null  $group
279
     */
280
    public function addResourceToCourse(AbstractResource $resource, int $visibility, User $creator, Course $course, Session $session = null, CGroupInfo $group = null)
281
    {
282
        $node = $this->addResourceNode($resource, $creator, $course);
283
        $this->addResourceNodeToCourse($node, $visibility, $course, $session, $group);
284
    }
285
286
    /**
287
     * @param ResourceNode $resourceNode
288
     * @param int          $visibility
289
     * @param Course       $course
290
     * @param Session      $session
291
     * @param CGroupInfo   $group
292
     */
293
    public function addResourceNodeToCourse(ResourceNode $resourceNode, $visibility, $course, $session, $group): void
294
    {
295
        $visibility = (int) $visibility;
296
        if (empty($visibility)) {
297
            $visibility = ResourceLink::VISIBILITY_PUBLISHED;
298
        }
299
300
        $link = new ResourceLink();
301
        $link
302
            ->setCourse($course)
303
            ->setSession($session)
304
            ->setGroup($group)
305
            //->setUser($toUser)
306
            ->setResourceNode($resourceNode)
307
            ->setVisibility($visibility)
308
        ;
309
310
        $rights = [];
311
        switch ($visibility) {
312
            case ResourceLink::VISIBILITY_PENDING:
313
            case ResourceLink::VISIBILITY_DRAFT:
314
                $editorMask = ResourceNodeVoter::getEditorMask();
315
                $resourceRight = new ResourceRight();
316
                $resourceRight
317
                    ->setMask($editorMask)
318
                    ->setRole(ResourceNodeVoter::ROLE_CURRENT_COURSE_TEACHER)
319
                ;
320
                $rights[] = $resourceRight;
321
                break;
322
        }
323
324
        if (!empty($rights)) {
325
            foreach ($rights as $right) {
326
                $link->addResourceRight($right);
327
            }
328
        }
329
330
        $em = $this->getEntityManager();
331
        $em->persist($link);
332
        $em->flush();
333
    }
334
335
    /**
336
     * @return ResourceType
337
     */
338
    public function getResourceType()
339
    {
340
        $em = $this->getEntityManager();
341
        $entityName = $this->getRepository()->getClassName();
342
343
        return $em->getRepository('ChamiloCoreBundle:Resource\ResourceType')->findOneBy(
344
            ['entityName' => $entityName]
345
        );
346
    }
347
348
    public function addResourceToMe(ResourceNode $resourceNode): ResourceLink
349
    {
350
        $resourceLink = new ResourceLink();
351
        $resourceLink
352
            ->setResourceNode($resourceNode)
353
            ->setPrivate(true);
0 ignored issues
show
Bug introduced by
The method setPrivate() does not exist on Chamilo\CoreBundle\Entity\Resource\ResourceLink. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

353
            ->/** @scrutinizer ignore-call */ setPrivate(true);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
354
355
        $this->getEntityManager()->persist($resourceLink);
356
        $this->getEntityManager()->flush();
357
358
        return $resourceLink;
359
    }
360
361
    public function addResourceToEveryone(ResourceNode $resourceNode, ResourceRight $right): ResourceLink
362
    {
363
        $resourceLink = new ResourceLink();
364
        $resourceLink
365
            ->setResourceNode($resourceNode)
366
            ->addResourceRight($right)
367
        ;
368
369
        $this->getEntityManager()->persist($resourceLink);
370
        $this->getEntityManager()->flush();
371
372
        return $resourceLink;
373
    }
374
375
    public function addResourceToCourse2(ResourceNode $resourceNode, Course $course, ResourceRight $right): ResourceLink
376
    {
377
        $resourceLink = new ResourceLink();
378
        $resourceLink
379
            ->setResourceNode($resourceNode)
380
            ->setCourse($course)
381
            ->addResourceRight($right);
382
        $this->getEntityManager()->persist($resourceLink);
383
        $this->getEntityManager()->flush();
384
385
        return $resourceLink;
386
    }
387
388
    public function addResourceToUser(ResourceNode $resourceNode, User $toUser): ResourceLink
389
    {
390
        $resourceLink = $this->addResourceNodeToUser($resourceNode, $toUser);
391
        $this->getEntityManager()->persist($resourceLink);
392
393
        return $resourceLink;
394
    }
395
396
    public function addResourceNodeToUser(ResourceNode $resourceNode, User $toUser): ResourceLink
397
    {
398
        $resourceLink = new ResourceLink();
399
        $resourceLink
400
            ->setResourceNode($resourceNode)
401
            ->setUser($toUser);
402
403
        return $resourceLink;
404
    }
405
406
    public function addResourceToSession(
407
        ResourceNode $resourceNode,
408
        Course $course,
409
        Session $session,
410
        ResourceRight $right
411
    ) {
412
        $resourceLink = $this->addResourceToCourse(
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $resourceLink is correct as $this->addResourceToCour...eNode, $course, $right) targeting Chamilo\CoreBundle\Repos...::addResourceToCourse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
The call to Chamilo\CoreBundle\Repos...::addResourceToCourse() has too few arguments starting with course. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

412
        /** @scrutinizer ignore-call */ 
413
        $resourceLink = $this->addResourceToCourse(

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
413
            $resourceNode,
414
            $course,
415
            $right
416
        );
417
        $resourceLink->setSession($session);
418
        $this->getEntityManager()->persist($resourceLink);
419
420
        return $resourceLink;
421
    }
422
423
    /**
424
     * @return ResourceLink
425
     */
426
    public function addResourceToCourseGroup(
427
        ResourceNode $resourceNode,
428
        Course $course,
429
        CGroupInfo $group,
430
        ResourceRight $right
431
    ) {
432
        $resourceLink = $this->addResourceToCourse(
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $resourceLink is correct as $this->addResourceToCour...eNode, $course, $right) targeting Chamilo\CoreBundle\Repos...::addResourceToCourse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
The call to Chamilo\CoreBundle\Repos...::addResourceToCourse() has too few arguments starting with course. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

432
        /** @scrutinizer ignore-call */ 
433
        $resourceLink = $this->addResourceToCourse(

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
433
            $resourceNode,
434
            $course,
435
            $right
436
        );
437
        $resourceLink->setGroup($group);
438
        $this->getEntityManager()->persist($resourceLink);
439
440
        return $resourceLink;
441
    }
442
443
    /**
444
     * @return ResourceLink
445
     */
446
    public function addResourceToGroup(
447
        ResourceNode $resourceNode,
448
        Usergroup $group,
449
        ResourceRight $right
450
    ) {
451
        $resourceLink = new ResourceLink();
452
        $resourceLink
453
            ->setResourceNode($resourceNode)
454
            ->setUserGroup($group)
455
            ->addResourceRight($right);
456
457
        return $resourceLink;
458
    }
459
460
    /**
461
     * @param array $userList User id list
462
     */
463
    public function addResourceToUserList(ResourceNode $resourceNode, array $userList)
464
    {
465
        $em = $this->getEntityManager();
466
467
        if (!empty($userList)) {
468
            foreach ($userList as $userId) {
469
                $toUser = $em->getRepository('ChamiloUserBundle:User')->find($userId);
470
471
                $resourceLink = $this->addResourceNodeToUser($resourceNode, $toUser);
472
                $em->persist($resourceLink);
473
            }
474
        }
475
    }
476
477
    /**
478
     * @param Course          $course
479
     * @param Session|null    $session
480
     * @param CGroupInfo|null $group
481
     *
482
     * @return QueryBuilder
483
     */
484
    public function getResourcesByCourse(Course $course, Session $session = null, CGroupInfo $group = null, ResourceNode $parentNode = null)
485
    {
486
        $repo = $this->getRepository();
487
        $className = $repo->getClassName();
488
        $checker = $this->getAuthorizationChecker();
489
490
        // Check if this resource type requires to load the base course resources when using a session
491
        $loadBaseSessionContent = $repo->getClassMetadata()->getReflectionClass()->hasProperty(
492
            'loadCourseResourcesInSession'
493
        );
494
        $type = $this->getResourceType();
495
496
        $qb = $repo->getEntityManager()->createQueryBuilder()
497
            ->select('resource')
498
            ->from($className, 'resource')
499
            ->innerJoin(
500
                ResourceNode::class,
501
                'node',
502
                Join::WITH,
503
                'resource.resourceNode = node.id'
504
            )
505
            ->innerJoin('node.resourceLinks', 'links')
506
            ->where('node.resourceType = :type')
507
            ->andWhere('links.course = :course')
508
            ->setParameters(
509
                [
510
                    'type' => $type,
511
                    'course' => $course,
512
                ]
513
            );
514
515
        $isAdmin = $checker->isGranted('ROLE_ADMIN') ||
516
            $checker->isGranted('ROLE_CURRENT_COURSE_TEACHER');
517
518
        if (false === $isAdmin) {
519
            $qb
520
                ->andWhere('links.visibility = :visibility')
521
                ->setParameter('visibility', ResourceLink::VISIBILITY_PUBLISHED)
522
            ;
523
            // @todo Add start/end visibility restrictrions
524
        }
525
526
        if (null === $session) {
527
            $qb->andWhere('links.session IS NULL');
528
        } else {
529
            if ($loadBaseSessionContent) {
530
                // Load course base content.
531
                $qb->andWhere('links.session = :session OR links.session IS NULL');
532
                $qb->setParameter('session', $session);
533
            } else {
534
                // Load only session resources.
535
                $qb->andWhere('links.session = :session');
536
                $qb->setParameter('session', $session);
537
            }
538
        }
539
540
        if (null !== $parentNode) {
541
            $qb->andWhere('node.parent = :parentNode');
542
            $qb->setParameter('parentNode', $parentNode);
543
        }
544
545
        if (null === $group) {
546
            $qb->andWhere('links.group IS NULL');
547
        }
548
549
        //echo ($qb->getQuery()->getSQL());exit;
550
551
        return $qb;
552
    }
553
554
    /**
555
     * @param RowAction $action
556
     * @param Row       $row
557
     * @param Session   $session
558
     *
559
     * @return RowAction|null
560
     */
561
    public function rowCanBeEdited(RowAction $action, Row $row, Session $session = null): ?RowAction
562
    {
563
        if (null !== $session) {
564
            /** @var AbstractResource $entity */
565
            $entity = $row->getEntity();
566
            $hasSession = $entity->getResourceNode()->hasSession($session);
567
            if ($hasSession->count() > 0) {
568
                return $action;
569
            }
570
571
            return null;
572
        }
573
574
        return $action;
575
    }
576
577
    /**
578
     * @param string $tool
579
     *
580
     * @return Tool|null
581
     */
582
    private function getTool($tool)
0 ignored issues
show
Unused Code introduced by
The method getTool() 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...
583
    {
584
        return $this
585
            ->getEntityManager()
586
            ->getRepository('ChamiloCoreBundle:Tool')
587
            ->findOneBy(['name' => $tool]);
588
    }
589
590
    /**
591
     * Deletes several entities: AbstractResource (Ex: CDocument, CQuiz), ResourceNode,
592
     * ResourceLinks and ResourceFile (including files via Flysystem).
593
     */
594
    public function hardDelete(AbstractResource $resource)
595
    {
596
        $em = $this->getEntityManager();
597
        $em->remove($resource);
598
        $em->flush();
599
    }
600
601
    /**
602
     * Change all links visibility to DELETED.
603
     */
604
    public function softDelete(AbstractResource $resource)
605
    {
606
        $this->setLinkVisibility($resource, ResourceLink::VISIBILITY_DELETED);
607
    }
608
609
    /**
610
     * @param AbstractResource $resource
611
     */
612
    public function setVisibilityPublished(AbstractResource $resource)
613
    {
614
        $this->setLinkVisibility($resource, ResourceLink::VISIBILITY_PUBLISHED);
615
    }
616
617
    /**
618
     * @param AbstractResource $resource
619
     */
620
    public function setVisibilityDraft(AbstractResource $resource)
621
    {
622
        $this->setLinkVisibility($resource, ResourceLink::VISIBILITY_DRAFT);
623
    }
624
625
    /**
626
     * @param AbstractResource $resource
627
     */
628
    public function setVisibilityPending(AbstractResource $resource)
629
    {
630
        $this->setLinkVisibility($resource, ResourceLink::VISIBILITY_PENDING);
631
    }
632
633
    /**
634
     * @param AbstractResource $resource
635
     * @param                  $visibility
636
     * @param bool             $recursive
637
     *
638
     * @return bool
639
     */
640
    private function setLinkVisibility(AbstractResource $resource, $visibility, $recursive = true)
641
    {
642
        $resourceNode = $resource->getResourceNode();
643
644
        if (null === $resourceNode) {
645
            return false;
646
        }
647
648
        $em = $this->getEntityManager();
649
        if ($recursive) {
650
            $children = $resourceNode->getChildren();
651
            if (!empty($children)) {
652
                /** @var ResourceNode $child */
653
                foreach ($children as $child) {
654
                    $criteria = ['resourceNode' => $child];
655
                    $childDocument = $this->getRepository()->findOneBy($criteria);
656
                    if ($childDocument) {
657
                        $this->setLinkVisibility($childDocument, $visibility);
658
                    }
659
                }
660
            }
661
        }
662
663
        $links = $resourceNode->getResourceLinks();
664
665
        if (!empty($links)) {
666
            /** @var ResourceLink $link */
667
            foreach ($links as $link) {
668
                $link->setVisibility($visibility);
669
                if (ResourceLink::VISIBILITY_DRAFT === $visibility) {
670
                    $editorMask = ResourceNodeVoter::getEditorMask();
671
                    $rights = [];
672
                    $resourceRight = new ResourceRight();
673
                    $resourceRight
674
                        ->setMask($editorMask)
675
                        ->setRole(ResourceNodeVoter::ROLE_CURRENT_COURSE_TEACHER)
676
                        ->setResourceLink($link)
677
                    ;
678
                    $rights[] = $resourceRight;
679
680
                    if (!empty($rights)) {
681
                        $link->setResourceRight($rights);
682
                    }
683
                } else {
684
                    $link->setResourceRight([]);
685
                }
686
                $em->merge($link);
687
            }
688
        }
689
        $em->flush();
690
691
        return true;
692
    }
693
}
694