@@ -9213,6 +9213,13 @@ public static function exerciseGridResource(
92139213 // 2. Get query builder from repo.
92149214 $ qb = $ repo ->getResourcesByCourse ($ course , $ session );
92159215
9216+ if (!empty ($ sessionId )) {
9217+ $ qb ->andWhere ('(links.session = :sess OR links.session IS NULL) ' )
9218+ ->setParameter ('sess ' , $ session );
9219+ } else {
9220+ $ qb ->andWhere ('links.session IS NULL ' );
9221+ }
9222+
92169223 if (!empty ($ categoryId )) {
92179224 $ qb ->andWhere ($ qb ->expr ()->eq ('resource.quizCategory ' , $ categoryId ));
92189225 } else {
@@ -9267,12 +9274,8 @@ public static function exerciseGridResource(
92679274 $ qb ->setParameter ('keyword ' , '% ' .$ keyword .'% ' );
92689275 }
92699276
9270- // Only for administrators
92719277 if (!$ is_allowedToEdit ) {
9272- $ qb
9273- ->leftJoin ('resource.resourceNode ' , 'rn ' )
9274- ->leftJoin ('rn.resourceLinks ' , 'rl ' )
9275- ->andWhere ('rl.visibility = :published ' )
9278+ $ qb ->andWhere ('links.visibility = :published ' )
92769279 ->setParameter ('published ' , ResourceLink::VISIBILITY_PUBLISHED );
92779280 }
92789281
@@ -9316,30 +9319,26 @@ public static function exerciseGridResource(
93169319
93179320 $ sessionId = api_get_session_id ();
93189321 $ allowToEditBaseCourse = true ;
9319- $ visibility = $ visibilityInCourse = $ exerciseEntity ->isVisible ($ course );
9320- $ visibilityInSession = false ;
9321- if (!empty ($ sessionId )) {
9322- // If we are in a session, the test is invisible
9323- // in the base course, it is included in a LP
9324- // *and* the setting to show it is *not*
9325- // specifically set to true, then hide it.
9326- if (false === $ visibility ) {
9327- if (!$ visibilitySetting ) {
9328- if ($ exercise ->exercise_was_added_in_lp ) {
9329- continue ;
9330- }
9331- }
9332- }
9333-
9334- $ visibility = $ visibilityInSession = $ exerciseEntity ->isVisible ($ course , $ session );
9322+ $ visibleBase = $ exerciseEntity ->isVisible ($ course );
9323+ $ visibleSess = !empty ($ sessionId ) ? $ exerciseEntity ->isVisible ($ course , $ session ) : null ;
9324+ if ($ visibleSess === true ) {
9325+ $ visibleForStudent = true ;
9326+ } elseif ($ visibleSess === false ) {
9327+ $ visibleForStudent = false ;
9328+ } else {
9329+ $ visibleForStudent = $ visibleBase ;
93359330 }
93369331
9337- // Validation when belongs to a session
9338- $ isBaseCourseExercise = true ;
9339- if (!($ visibilityInCourse && $ visibilityInSession )) {
9340- $ isBaseCourseExercise = false ;
9332+ $ visibleForTeacher = true ;
9333+
9334+ if (!$ is_allowedToEdit && !empty ($ sessionId )) {
9335+ $ visibilitySetting = ('true ' === api_get_setting ('lp.show_hidden_exercise_added_to_lp ' ));
9336+ if (!$ visibleBase && !$ visibilitySetting && $ exercise ->exercise_was_added_in_lp ) {
9337+ continue ;
9338+ }
93419339 }
93429340
9341+ $ isBaseCourseExercise = $ visibleBase && ($ visibleSess === null || $ visibleSess === true );
93439342 if (!empty ($ sessionId ) && $ isBaseCourseExercise ) {
93449343 $ allowToEditBaseCourse = false ;
93459344 }
@@ -9414,10 +9413,7 @@ public static function exerciseGridResource(
94149413 );
94159414 }
94169415
9417- $ style = '' ;
9418- if (!$ visibility ) {
9419- $ style = 'color:grey ' ;
9420- }
9416+ $ style = $ visibleForStudent ? '' : 'color:grey ' ;
94219417
94229418 $ title = $ cut_title ;
94239419
@@ -9710,12 +9706,7 @@ public static function exerciseGridResource(
97109706 $ currentRow ['count_questions ' ] = $ number_of_questions ;
97119707 } else {
97129708 // Student only.
9713- $ visibility = $ exerciseEntity ->isVisible ($ course , null );
9714- if (false === $ visibility && !empty ($ sessionId )) {
9715- $ visibility = $ exerciseEntity ->isVisible ($ course , $ session );
9716- }
9717-
9718- if (false === $ visibility ) {
9709+ if (!$ visibleForStudent ) {
97199710 continue ;
97209711 }
97219712
0 commit comments