Fix resource visibility when displayed from base course in session course - refs BT#22190

pull/5939/head
Angel Fernando Quiroz Campos 2 days ago
parent 7af133dda2
commit 8bdbc49a4e
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 7
      public/main/lp/learnpath.class.php
  2. 2
      public/main/lp/learnpathList.class.php
  3. 53
      src/CoreBundle/Repository/ResourceRepository.php

@ -3315,10 +3315,13 @@ class learnpath
$visibility = (int) $visibility;
$course = api_get_course_entity();
$session = api_get_session_entity();
if (1 === $visibility) {
$repo->setVisibilityPublished($lp);
$repo->setVisibilityPublished($lp, $course, $session);
} else {
$repo->setVisibilityDraft($lp);
$repo->setVisibilityDraft($lp, $course, $session);
}
return true;

@ -119,7 +119,7 @@ class LearnpathList
$lp->getId(),
$session_id
);*/
$visibility = $lp->isVisible($course);
$visibility = $lp->isVisible($course, $session);
// If option is not true then don't show invisible LP to user
if (false === $ignoreLpVisibility) {

@ -18,6 +18,7 @@ use Chamilo\CoreBundle\Entity\ResourceShowCourseResourcesInSessionInterface;
use Chamilo\CoreBundle\Entity\ResourceType;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Entity\Usergroup;
use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter;
use Chamilo\CoreBundle\Traits\NonResourceRepository;
use Chamilo\CoreBundle\Traits\Repository\RepositoryQueryBuilderTrait;
@ -600,19 +601,28 @@ abstract class ResourceRepository extends ServiceEntityRepository
}
}
public function setVisibilityPublished(AbstractResource $resource): void
{
$this->setLinkVisibility($resource, ResourceLink::VISIBILITY_PUBLISHED);
public function setVisibilityPublished(
AbstractResource $resource,
?Course $course = null,
?Session $session = null,
): void {
$this->setLinkVisibility($resource, ResourceLink::VISIBILITY_PUBLISHED, true, $course, $session);
}
public function setVisibilityDraft(AbstractResource $resource): void
{
$this->setLinkVisibility($resource, ResourceLink::VISIBILITY_DRAFT);
public function setVisibilityDraft(
AbstractResource $resource,
?Course $course = null,
?Session $session = null,
): void {
$this->setLinkVisibility($resource, ResourceLink::VISIBILITY_DRAFT, true, $course, $session);
}
public function setVisibilityPending(AbstractResource $resource): void
{
$this->setLinkVisibility($resource, ResourceLink::VISIBILITY_PENDING);
public function setVisibilityPending(
AbstractResource $resource,
?Course $course = null,
?Session $session = null,
): void {
$this->setLinkVisibility($resource, ResourceLink::VISIBILITY_PENDING, true, $course, $session);
}
public function addResourceNode(
@ -844,8 +854,15 @@ abstract class ResourceRepository extends ServiceEntityRepository
return $qb;
}
private function setLinkVisibility(AbstractResource $resource, int $visibility, bool $recursive = true): bool
{
private function setLinkVisibility(
AbstractResource $resource,
int $visibility,
bool $recursive = true,
?Course $course = null,
?Session $session = null,
?CGroup $group = null,
?User $user = null,
): bool {
$resourceNode = $resource->getResourceNode();
if (null === $resourceNode) {
@ -868,7 +885,19 @@ abstract class ResourceRepository extends ServiceEntityRepository
}
}
$links = $resourceNode->getResourceLinks();
if ($resource instanceof ResourceShowCourseResourcesInSessionInterface) {
$link = $resource->getFirstResourceLinkFromCourseSession($course, $session);
if (!$link) {
$resource->parentResource = $course;
$resource->addCourseLink($course, $session);
}
$link = $resource->getFirstResourceLinkFromCourseSession($course, $session);
$links = [$link];
} else {
$links = $resourceNode->getResourceLinks();
}
/** @var ResourceLink $link */
foreach ($links as $link) {

Loading…
Cancel
Save