Skip to content

Internal: Fix missing course association in CourseRelUser #5704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/CoreBundle/DataProvider/Extension/CourseRelUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Chamilo\CoreBundle\Entity\CourseRelUser;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\ServiceHelper\AccessUrlHelper;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
Expand All @@ -21,7 +22,8 @@ final class CourseRelUserExtension implements QueryCollectionExtensionInterface
{
public function __construct(
private readonly Security $security,
private readonly AccessUrlHelper $accessUrlHelper
private readonly AccessUrlHelper $accessUrlHelper,
private readonly EntityManagerInterface $entityManager
) {}

public function applyToCollection(
Expand All @@ -45,11 +47,14 @@ public function applyToCollection(
->andWhere('url_rel.url = :access_url_id')
->setParameter('access_url_id', $accessUrl->getId());
} else {
$queryBuilder
->innerJoin("$rootAlias.course", 'c')
->innerJoin('c.urls', 'url_rel')
->andWhere('url_rel.url = :access_url_id')
->setParameter('access_url_id', $accessUrl->getId());
$metaData = $this->entityManager->getClassMetadata($resourceClass);
if ($metaData->hasAssociation('course')) {
$queryBuilder
->innerJoin("$rootAlias.course", 'c')
->innerJoin('c.urls', 'url_rel')
->andWhere('url_rel.url = :access_url_id')
->setParameter('access_url_id', $accessUrl->getId());
}
}
}

Expand Down
Loading