Skip to content

Commit

Permalink
Only show a section if it has modules that are visible to the user wh…
Browse files Browse the repository at this point in the history
…en not editing. And a little logic tidy.
  • Loading branch information
gjb2048 committed May 6, 2024
1 parent c4d0b97 commit 81e15d8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 34 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Version 404.0.2 - In development
--------------------------------
1. Fix section zero with a summary is shown when there are no modules.
2. Add flexible modules.
3. Only show a section if it has modules that are visible to the user when not editing.

Version 404.0.1 - 22/04/2024
----------------------------
Expand Down
62 changes: 30 additions & 32 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,9 @@ protected function topcoll_section($section, $course, $onsectionpage, $sectionre
);
}

if ($section->uservisible) {
$sectioncontext['cscml'] = $this->course_section_cmlist($section);
if ($this->courseformat->show_editor()) {
$sectioncontext['cscml'] .= $this->course_section_add_cm_control($course, $section->section, $sectionreturn);
}
$sectioncontext['cscml'] = $this->course_section_cmlist($section);
if ($this->courseformat->show_editor()) {
$sectioncontext['cscml'] .= $this->course_section_add_cm_control($course, $section->section, $sectionreturn);
}

return $this->render_from_template('format_topcoll/section', $sectioncontext);
Expand Down Expand Up @@ -791,7 +789,7 @@ public function multiple_section_page() {
// General section if non-empty.
$thissection = $sections[0];
unset($sections[0]);
if (!empty($modinfo->sections[0]) || $this->userisediting) {
if ($this->courseformat->is_section_visible($thissection)) {
$content .= $this->topcoll_section($thissection, $course, false);
}

Expand Down Expand Up @@ -890,12 +888,12 @@ public function multiple_section_page() {

/* Show the section if the user is permitted to access it, OR if it's not available
but there is some available info text which explains the reason & should display. */
if (($this->tcsettings['layoutstructure'] != 3) || ($this->userisediting)) {
$showsection = ($this->courseformat->is_section_visible($thissection));
} else {
$showsection = (($this->courseformat->is_section_visible($thissection)) && ($nextweekdate <= $timenow));
$showsection = ($this->courseformat->is_section_visible($thissection));
if ($showsection && ($this->tcsettings['layoutstructure'] == 3) && (!$this->userisediting)) {
$showsection = ($nextweekdate <= $timenow);
}
if (($currentsectionfirst == true) && ($showsection == true)) {

if ($currentsectionfirst && $showsection) {
// Show the section if we were meant to and it is the current section:....
$showsection = ($course->marker == $section);
} else if (
Expand All @@ -904,7 +902,27 @@ public function multiple_section_page() {
) {
$showsection = false; // Do not reshow current section.
}
if (!$showsection) {
if ($showsection) {
if ($this->isoldtogglepreference == true) {
$togglestate = substr($this->togglelib->get_toggles(), $section, 1);
if ($togglestate == '1') {
$extrasectioninfo[$thissection->id]->toggle = true;
} else {
$extrasectioninfo[$thissection->id]->toggle = false;
}
} else {
$extrasectioninfo[$thissection->id]->toggle = $this->togglelib->get_toggle_state($thissection->section);
}

if ($this->courseformat->is_section_current($thissection)) {
$this->currentsection = $thissection->section;
$extrasectioninfo[$thissection->id]->toggle = true; // Open current section regardless of toggle state.
$this->togglelib->set_toggle_state($thissection->section, true);
}

$extrasectioninfo[$thissection->id]->isshown = true;
$sectiondisplayarray[] = $thissection;
} else {
// Hidden section message is overridden by 'unavailable' control.
$testhidden = false;
if ($this->tcsettings['layoutstructure'] != 4) {
Expand All @@ -926,26 +944,6 @@ public function multiple_section_page() {
$sectiondisplayarray[] = $thissection;
}
}
} else {
if ($this->isoldtogglepreference == true) {
$togglestate = substr($this->togglelib->get_toggles(), $section, 1);
if ($togglestate == '1') {
$extrasectioninfo[$thissection->id]->toggle = true;
} else {
$extrasectioninfo[$thissection->id]->toggle = false;
}
} else {
$extrasectioninfo[$thissection->id]->toggle = $this->togglelib->get_toggle_state($thissection->section);
}

if ($this->courseformat->is_section_current($thissection)) {
$this->currentsection = $thissection->section;
$extrasectioninfo[$thissection->id]->toggle = true; // Open current section regardless of toggle state.
$this->togglelib->set_toggle_state($thissection->section, true);
}

$extrasectioninfo[$thissection->id]->isshown = true;
$sectiondisplayarray[] = $thissection;
}

if (($this->tcsettings['layoutstructure'] != 3) || ($this->userisediting)) {
Expand Down
28 changes: 27 additions & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,33 @@ public function is_section_visible(section_info $section): bool {
// Don't show.
return false;
}
return parent::is_section_visible($section);
$shown = parent::is_section_visible($section);
if ($shown) {
// Don't show if no modules or all modules unavailable to user.
$showmovehere = ismoving($this->course->id);
if (!$showmovehere) {
global $PAGE;
$context = context_course::instance($this->course->id);
if (!($PAGE->user_is_editing() && has_capability('moodle/course:update', $context))) {
$modshown = false;
$modinfo = get_fast_modinfo($this->course);

if (!empty($modinfo->sections[$section->section])) {
foreach ($modinfo->sections[$section->section] as $modnumber) {
$mod = $modinfo->cms[$modnumber];
if ($mod->is_visible_on_course_page()) {
// At least one is.
$modshown = true;
break;
}
}
}
$shown = $modshown;
}
}
}

return $shown;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion templates/local/content/section/cmlist.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
{{#showmovehere}}
<p>{{movingstr}} (<a href="{{{cancelcopyurl}}}">{{#str}} cancel {{/str}}</a>)</p>
{{/showmovehere}}
<ul class="section m-0 p-0 img-text {{^flexiblemodules}}d-block{{/flexiblemodules}}{{#flexiblemodules}}d-flex{{/flexiblemodules}}" data-for="cmlist">
<ul class="section m-0 p-0 img-text{{#hascms}} {{^flexiblemodules}}d-block{{/flexiblemodules}}{{#flexiblemodules}}d-flex{{/flexiblemodules}}{{/hascms}}" data-for="cmlist">
{{#cms}}
{{#showmovehere}}
<li class="movehere">
Expand Down

0 comments on commit 81e15d8

Please sign in to comment.