Courses: Fix sticky courses

pull/4161/head
Julio 3 years ago
parent 26d3e7f034
commit 8bf2dd17d3
  1. 30
      src/CoreBundle/DataProvider/Extension/CourseExtension.php
  2. 2
      src/CoreBundle/Entity/CourseRelUser.php

@ -55,37 +55,15 @@ final class CourseExtension implements QueryCollectionExtensionInterface
throw new AccessDeniedException('Access Denied.'); throw new AccessDeniedException('Access Denied.');
} }
$request = $this->requestStack->getCurrentRequest();
$rootAlias = $queryBuilder->getRootAliases()[0]; $rootAlias = $queryBuilder->getRootAliases()[0];
$queryBuilder $queryBuilder
->innerJoin("$rootAlias.resourceNode", 'node') ->andWhere(sprintf('%s.visibility <> :visibility_hidden', $rootAlias))
->innerJoin('node.resourceLinks', 'links') ->setParameter('visibility_hidden', Course::HIDDEN)
; ;
// Do not show deleted resources.
$queryBuilder $queryBuilder
->andWhere('links.visibility != :visibilityDeleted') ->andWhere(sprintf('%s.visibility <> :visibility_closed', $rootAlias))
->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED) ->setParameter('visibility_closed', Course::CLOSED)
;
$allowDraft =
$this->security->isGranted('ROLE_ADMIN') ||
$this->security->isGranted('ROLE_CURRENT_COURSE_TEACHER')
; ;
if (!$allowDraft) {
$queryBuilder
->andWhere('links.visibility != :visibilityDraft')
->setParameter('visibilityDraft', ResourceLink::VISIBILITY_DRAFT)
;
}
/*$queryBuilder->
andWhere('node.creator = :current_user')
;*/
//$queryBuilder->andWhere(sprintf('%s.node.creator = :current_user', $rootAlias));
//$queryBuilder->setParameter('current_user', $user->getId());
} }
} }

@ -81,7 +81,7 @@ class CourseRelUser
* @ORM\JoinColumn(name="user_id", referencedColumnName="id") * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/ */
#[MaxDepth(1)] #[MaxDepth(1)]
#[Groups(['course:read', 'user:read'])] #[Groups(['course:read', 'user:read', 'course_rel_user:read'])]
protected User $user; protected User $user;
/** /**

Loading…
Cancel
Save