@@ -268,7 +268,7 @@ public function get_content() {
268268 $ thismod ->subsection = $ this ->handle_subsection ($ module );
269269
270270 foreach ($ thismod ->subsection ->modules as $ key => $ subsectionmodule ) {
271- $ thismod -> subsection -> modules [ $ key ] = $ this ->checkmodule (
271+ $ modulechecked = $ this ->checkmodule (
272272 $ subsectionmodule ,
273273 $ context ,
274274 $ completioninfo ,
@@ -277,8 +277,14 @@ public function get_content() {
277277 $ myactivityid ,
278278 $ thissection ,
279279 );
280+ if ($ modulechecked !== null ) {
281+ $ thismod ->subsection ->modules [$ key ] = $ modulechecked ;
282+ }
283+ }
284+
285+ if ($ thismod ->subsection !== null && !empty ($ thismod ->subsection ->modules )) {
286+ $ thissection ->modules [] = $ thismod ;
280287 }
281- $ thissection ->modules [] = $ thismod ;
282288 } else {
283289 $ modulechecked = $ this ->checkmodule (
284290 $ module ,
@@ -298,7 +304,9 @@ public function get_content() {
298304
299305 $ thissection ->hasmodules = (count ($ thissection ->modules ) > 0 );
300306 // We prevent case of section (mod_subsection) are added at the end ...
301- if ($ thissection ->hasmodules && $ thissection ->uservisible && $ section ->component !== "mod_subsection " ) {
307+ if ($ thissection ->hasmodules
308+ && $ thissection ->uservisible
309+ && $ section ->component !== "mod_subsection " ) {
302310 $ template ->sections [] = $ thissection ;
303311 }
304312 }
@@ -427,7 +435,11 @@ public function handle_subsection($module) {
427435 );
428436 }
429437
430- return $ subsection ;
438+ if ($ subsection ->uservisible ) {
439+ return $ subsection ;
440+ } else {
441+ return null ;
442+ }
431443 }
432444
433445 /**
0 commit comments