Skip to content
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

fix for availability in hidden sections #131

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from 1 commit
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
Next Next commit
fix for availability
  • Loading branch information
Syxton committed Dec 16, 2024
commit f2b6446274aaf6c813556ae8ca18ec8746d03134
29 changes: 19 additions & 10 deletions classes/actions.php
Original file line number Diff line number Diff line change
@@ -95,23 +95,32 @@ public static function set_visibility(array $modules, bool $visible, bool $visib
}

foreach ($modules as $cm) {
// Convert boolean to integer.
$visibleint = $visible ? 1 : 0;
$visibleonpageint = $visibleonpage ? 1 : 0;

// Stealth activies, if enabled are stored differently in visible and hidden sections.
Syxton marked this conversation as resolved.
Show resolved Hide resolved
// So we still need to do a little bit of extra work here.
if ($visible && !$visibleonpage) {
// We want to set the visibility to 'available, but hidden', but have to respect the global config and
// the course format config.
// We want to have an available but hidden activity.
// First we need to make sure stealth activities are enabled.
if (empty($CFG->allowstealth)) {
// We silently ignore this course module it must not be set to 'available, but not visible on course page'.
continue;
}
}

// We here also cover the case of a hidden section. In this case moodle only uses the attribute 'visible' to determine,
// if a course module is completely hidden ('visible' => 0) or 'available, but not visible on course page'
// ('visible' => 1). The attribute 'visibleonpage' is being ignored, so we can pass it along anyway.
// Because of this in case of a hidden section both actions ('show' and 'make available') lead to the same result:
// 'available, but not visible on course page'.
// In a hidden section, show and make available are the same thing.
// In a visible section, show has a visibleonpage of 1 and stealth has a visibleonpage of 0.
// Gather more information about the module and where it is located.
$modinfo = get_fast_modinfo($cm->course);
$format = course_get_format($modinfo->get_course());
$cm = $modinfo->get_cm($cm->id);

$visibleint = $visible ? 1 : 0;
$visibleonpageint = $visibleonpage ? 1 : 0;
$allowstealth = $format->allow_stealth_module_visibility($cm, $cm->get_section_info());
$visibleonpageint = ($allowstealth) ? 0 : 1;
Syxton marked this conversation as resolved.
Show resolved Hide resolved
}

// Set visibility.
if (set_coursemodule_visible($cm->id, $visibleint, $visibleonpageint)) {
course_module_updated::create_from_cm(get_coursemodule_from_id(false, $cm->id))->trigger();
}