getRepository(); $className = $repo->getClassName(); $checker = $this->getAuthorizationChecker(); $reflectionClass = $repo->getClassMetadata()->getReflectionClass(); // Check if this resource type requires to load the base course resources when using a session $loadBaseSessionContent = $reflectionClass->hasProperty('loadCourseResourcesInSession'); $type = $this->getResourceType(); $qb = $repo->getEntityManager()->createQueryBuilder() ->select('resource') ->from($className, 'resource') ->innerJoin( ResourceNode::class, 'node', Join::WITH, 'resource.resourceNode = node.id' ) ->innerJoin('node.resourceLinks', 'links') ->where('node.resourceType = :type') ->setParameter('type', $type); $qb ->andWhere('links.course = :course') ->setParameter('course', $course) ; $isAdmin = $checker->isGranted('ROLE_ADMIN') || $checker->isGranted('ROLE_CURRENT_COURSE_TEACHER'); if (false === $isAdmin) { $qb ->andWhere('links.visibility = :visibility') ->setParameter('visibility', ResourceLink::VISIBILITY_PUBLISHED) ; } if (null === $session) { $qb->andWhere('links.session IS NULL'); } else { if ($loadBaseSessionContent) { // Load course base content. $qb->andWhere('links.session = :session OR links.session IS NULL'); $qb->setParameter('session', $session); } else { // Load only session resources. $qb->andWhere('links.session = :session'); $qb->setParameter('session', $session); } } $qb->andWhere('node.parent = :parentNode'); $qb->setParameter('parentNode', $parentNode); $qb->andWhere('links.group IS NULL'); return $qb; } }