From 71cffbb26bcae6a00bae16f436395b85fc2dcd28 Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Thu, 23 May 2024 12:35:19 +0100 Subject: [PATCH] Add 'sectionzeroingrid' course and 'defaultsectionzeroingrid' site settings to state if section zero should be in the grid. --- Changes.md | 1 + classes/output/courseformat/content.php | 15 ++++++++------- lang/en/format_grid.php | 6 ++++++ lib.php | 20 ++++++++++++++++++++ settings.php | 11 +++++++++++ 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Changes.md b/Changes.md index 68eaa4f9..3e91338a 100644 --- a/Changes.md +++ b/Changes.md @@ -7,6 +7,7 @@ Version 404.0.2 - TBR 2. Section navigation visibility improvements. 3. Fix display of section zero on a single section page. 4. Fix 'Unable to update defaultimageresizemethod setting' - #211. +5. Add 'sectionzeroingrid' course and 'defaultsectionzeroingrid' site settings to state if section zero should be in the grid. Version 404.0.1 - 22/04/2024 ---------------------------- diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php index 07ca16af..413962f3 100644 --- a/classes/output/courseformat/content.php +++ b/classes/output/courseformat/content.php @@ -89,12 +89,13 @@ public function export_for_template(\renderer_base $output) { $initialsection = ''; $course = $format->get_course(); $currentsectionid = 0; - $sectionzeroingrid = true; + $coursesettings = $format->get_settings(); + $sectionzeronotingrid = ($coursesettings['sectionzeroingrid'] == 1); if (!empty($sections)) { // Is first entry section 0? if ($sections[0]->num === 0) { - if ((!$singlesectionid) && (!$sectionzeroingrid)) { + if ((!$singlesectionid) && ($sectionzeronotingrid)) { // Most formats uses section 0 as a separate section so we remove from the list. $initialsection = array_shift($sections); $data->initialsection = $initialsection; @@ -126,7 +127,6 @@ public function export_for_template(\renderer_base $output) { $data->sectionreturn = $singlesectionno; $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)) { @@ -227,8 +227,8 @@ public function export_for_template(\renderer_base $output) { } else { // Section link. $sectionimages[$section->id]->sectionurl = new \moodle_url( - '/course/view.php', - ['id' => $course->id, 'section' => $section->num] + '/course/section.php', + ['id' => $section->id] ); $sectionimages[$section->id]->sectionurl = $sectionimages[$section->id]->sectionurl->out(false); @@ -326,8 +326,9 @@ protected function get_grid_sections(\renderer_base $output, $settings): array { $numsections = $format->get_last_section_number(); $sectioninfos = $modinfo->get_section_info_all(); - $sectionzeroingrid = true; - if (!$sectionzeroingrid) { + $coursesettings = $format->get_settings(); + $sectionzeronotingrid = ($coursesettings['sectionzeroingrid'] == 1); + if ($sectionzeronotingrid) { // Get rid of section 0. if (!empty($sectioninfos)) { array_shift($sectioninfos); diff --git a/lang/en/format_grid.php b/lang/en/format_grid.php index b44be0d7..a5026cbd 100644 --- a/lang/en/format_grid.php +++ b/lang/en/format_grid.php @@ -128,6 +128,12 @@ $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'; diff --git a/lib.php b/lib.php index aa917498..b247db8a 100755 --- a/lib.php +++ b/lib.php @@ -408,6 +408,10 @@ public function course_format_options($foreditform = false) { 'default' => 0, 'type' => PARAM_INT, ], + 'sectionzeroingrid' => [ + 'default' => 0, + 'type' => PARAM_INT, + ], 'showcompletion' => [ 'default' => 0, 'type' => PARAM_INT, @@ -522,6 +526,22 @@ 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, diff --git a/settings.php b/settings.php index 381829e4..65606c6d 100644 --- a/settings.php +++ b/settings.php @@ -147,6 +147,17 @@ $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');