diff --git a/main/inc/lib/StudentFollowPage.php b/main/inc/lib/StudentFollowPage.php index 3eb83e3671..feb5196bb7 100644 --- a/main/inc/lib/StudentFollowPage.php +++ b/main/inc/lib/StudentFollowPage.php @@ -25,11 +25,29 @@ class StudentFollowPage $itemProperty = $itemRepo->findByUserSuscribedToItem( 'learnpath', $lpInfo['iid'], - api_get_user_entity($studentId), - api_get_course_entity($courseId), - api_get_session_entity($sessionId) + $studentId, + $courseId, + $sessionId ); + if (null === $itemProperty) { + $userGroups = GroupManager::getAllGroupPerUserSubscription($studentId, $courseId); + + foreach ($userGroups as $groupInfo) { + $itemProperty = $itemRepo->findByGroupSuscribedToLp( + 'learnpath', + $lpInfo['iid'], + $groupInfo['iid'], + $courseId, + $sessionId + ); + + if (null !== $itemProperty) { + break; + } + } + } + if (null === $itemProperty) { return '-'; } diff --git a/src/Chamilo/CoreBundle/Entity/Repository/ItemPropertyRepository.php b/src/Chamilo/CoreBundle/Entity/Repository/ItemPropertyRepository.php index 8699ebff27..7f171b1aaa 100644 --- a/src/Chamilo/CoreBundle/Entity/Repository/ItemPropertyRepository.php +++ b/src/Chamilo/CoreBundle/Entity/Repository/ItemPropertyRepository.php @@ -47,19 +47,38 @@ class ItemPropertyRepository extends EntityRepository public function findByUserSuscribedToItem( $tool, $itemId, - User $user, - Course $course, - Session $session = null, - Group $group = null + int $userId, + int $courseId, + int $sessionId = null ): ?CItemProperty { $criteria = [ 'tool' => $tool, 'lasteditType' => 'LearnpathSubscription', 'ref' => $itemId, - 'toUser' => $user, - 'course' => $course, - 'session' => $session, - 'group' => $group, + 'toUser' => $userId, + 'course' => $courseId, + 'session' => $sessionId ?: null, + 'group' => null, + ]; + + return $this->findOneBy($criteria); + } + + public function findByGroupSuscribedToLp( + $tool, + $lpId, + int $groupId, + int $courseId, + int $sessionId = 0 + ): ?CItemProperty { + $criteria = [ + 'tool' => $tool, + 'lasteditType' => 'LearnpathSubscription', + 'ref' => $lpId, + 'toUser' => null, + 'course' => $courseId, + 'session' => $sessionId ?: null, + 'group' => $groupId, ]; return $this->findOneBy($criteria);