Skip to content

Commit

Permalink
Fix section zero showing after section on single section page. This h…
Browse files Browse the repository at this point in the history
…as caused the removal of 'sectionzeroingrid' setting. If you want this functionality, please upgrade to the M4.4+ version.
  • Loading branch information
gjb2048 committed Sep 23, 2024
1 parent 9a1f647 commit 236571c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 51 deletions.
2 changes: 2 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ History

Version 401.2.5 -
----------------------------
1. Fix section zero showing after section on single section page. This has caused the removal of 'sectionzeroingrid' setting.
If you want this functionality, please upgrade to the M4.4+ version.

Version 401.2.4 - 21/09/2024
----------------------------
Expand Down
21 changes: 10 additions & 11 deletions classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ public function export_for_template(\renderer_base $output) {
$initialsection = '';
$course = $format->get_course();
$currentsectionid = 0;
$coursesettings = $format->get_settings();
$sectionzeronotingrid = ($coursesettings['sectionzeroingrid'] == 1);

if (!empty($sections)) {
// Is first entry section 0?
if ($sections[0]->num === 0) {
if ((!$singlesection) && ($sectionzeronotingrid)) {
// Most formats uses section 0 as a separate section so we remove from the list.
$initialsection = array_shift($sections);
// Most formats uses section 0 as a separate section so we remove from the list.
// M4.3- Has section 0 in the sections for a single section page, ref: get_sections_to_display().
// Also because of the way that section 0 is a number and not an id, then sectionzeronotingrid
// is not possible in this version.
$initialsection = array_shift($sections);
if (!$singlesection) {
$data->initialsection = $initialsection;
}
}
Expand Down Expand Up @@ -126,6 +127,7 @@ public function export_for_template(\renderer_base $output) {
$data->sectionreturn = $singlesection;
$data->maincoursepage = new \moodle_url('/course/view.php', ['id' => $course->id]);
} else {
$coursesettings = $format->get_settings();
$toolbox = \format_grid\toolbox::get_instance();
$coursesectionimages = $DB->get_records('format_grid_image', ['courseid' => $course->id]);
if (!empty($coursesectionimages)) {
Expand Down Expand Up @@ -336,12 +338,9 @@ protected function get_grid_sections(\renderer_base $output, $settings): array {
$numsections = $format->get_last_section_number();
$sectioninfos = $modinfo->get_section_info_all();
$coursesettings = $format->get_settings();
$sectionzeronotingrid = ($coursesettings['sectionzeroingrid'] == 1);
if ($sectionzeronotingrid) {
// Get rid of section 0.
if (!empty($sectioninfos)) {
array_shift($sectioninfos);
}
// Get rid of section 0.
if (!empty($sectioninfos)) {
array_shift($sectioninfos);
}
foreach ($sectioninfos as $thissection) {
// The course/view.php check the section existence but the output can be called from other parts so we need to check it.
Expand Down
6 changes: 0 additions & 6 deletions lang/en/format_grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@
$string['defaultpopup'] = 'Use a popup';
$string['defaultpopup_desc'] = 'Display the section in a popup instead of navigating to a single section page.';

// Section zero.
$string['sectionzeroingrid'] = 'Section zero in grid';
$string['sectionzeroingrid_help'] = 'Place section zero in the grid';
$string['defaultsectionzeroingrid'] = 'Section zero in grid';
$string['defaultsectionzeroingrid_desc'] = 'Place section zero in the grid.';

// Completion.
$string['showcompletion'] = 'Show completion';
$string['showcompletion_help'] = 'Show the completion of the section on the grid';
Expand Down
23 changes: 0 additions & 23 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ public function get_view_url($section, $options = []) {
if ($sectionno != 0 && $usercoursedisplay == COURSE_DISPLAY_MULTIPAGE) {
$url->param('section', $sectionno);
} else {
if (empty($CFG->linkcoursesections) && !empty($options['navigation'])) {
return null;
}
$url->set_anchor('section-'.$sectionno);
}
}
Expand Down Expand Up @@ -415,10 +412,6 @@ public function course_format_options($foreditform = false) {
'default' => 0,
'type' => PARAM_INT,
],
'sectionzeroingrid' => [
'default' => 0,
'type' => PARAM_INT,
],
'showcompletion' => [
'default' => 0,
'type' => PARAM_INT,
Expand Down Expand Up @@ -533,22 +526,6 @@ public function course_format_options($foreditform = false) {
'element_attributes' => [$imageresizemethodvalues],
];

$sectionzeroingridvalues = $this->generate_default_entry(
'sectionzeroingrid',
0,
[
1 => new lang_string('no'),
2 => new lang_string('yes'),
],
);
$courseformatoptionsedit['sectionzeroingrid'] = [
'label' => new lang_string('sectionzeroingrid', 'format_grid'),
'help' => 'sectionzeroingrid',
'help_component' => 'format_grid',
'element_type' => 'select',
'element_attributes' => [$sectionzeroingridvalues],
];

$showcompletionvalues = $this->generate_default_entry(
'showcompletion',
0,
Expand Down
11 changes: 0 additions & 11 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,6 @@
$setting->set_updatedcallback('format_grid::update_displayed_images_callback');
$page->add($setting);

// Section zero in grid.
$name = 'format_grid/defaultsectionzeroingrid';
$title = get_string('defaultsectionzeroingrid', 'format_grid');
$description = get_string('defaultsectionzeroingrid_desc', 'format_grid');
$default = 1;
$choices = [
1 => new lang_string('no'),
2 => new lang_string('yes'),
];
$page->add(new admin_setting_configselect($name, $title, $description, $default, $choices));

// Completion.
$name = 'format_grid/defaultshowcompletion';
$title = get_string('defaultshowcompletion', 'format_grid');
Expand Down

0 comments on commit 236571c

Please sign in to comment.