From 0ea454c63f3ace3a3b656ec64d5ba69eca064e5b Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Mon, 19 Aug 2024 18:18:45 +0100 Subject: [PATCH] Grid section title / badges - work in progress. --- classes/output/courseformat/content.php | 9 ++++++ lang/en/format_grid.php | 10 +++++++ lib.php | 40 +++++++++++++++++++++++++ settings.php | 22 ++++++++++++++ styles.css | 1 + templates/grid.mustache | 18 ++++++++--- 6 files changed, 96 insertions(+), 4 deletions(-) diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php index f7411ece..8bde3e84 100644 --- a/classes/output/courseformat/content.php +++ b/classes/output/courseformat/content.php @@ -154,6 +154,15 @@ public function export_for_template(\renderer_base $output) { // Justification. $data->gridjustification = $coursesettings['gridjustification']; + // Section title in grid box. + $data->sectiontitleingridbox = ($coursesettings['sectiontitleingridbox'] == 2); + + // Section badge in grid box. + $data->sectionbadgeingridbox = ($coursesettings['sectionbadgeingridbox'] == 2); + + // Title and / org badge? + $data->sectiontitleandorbadgeingridbox = ($data->sectiontitleingridbox || $data->sectionbadgeingridbox); + // Popup. if (!$editing) { $data->popup = false; diff --git a/lang/en/format_grid.php b/lang/en/format_grid.php index a5026cbd..dc0a4c26 100644 --- a/lang/en/format_grid.php +++ b/lang/en/format_grid.php @@ -134,6 +134,16 @@ $string['defaultsectionzeroingrid'] = 'Section zero in grid'; $string['defaultsectionzeroingrid_desc'] = 'Place section zero in the grid.'; +// Grid section title / badges. +$string['sectiontitleingridbox'] = 'Section title in grid box'; +$string['sectiontitleingridbox_help'] = 'Show the section title in the grid box'; +$string['defaultsectiontitleingridbox'] = 'Section title in grid box'; +$string['defaultsectiontitleingridbox_desc'] = 'Show the section title in the grid box.'; +$string['sectionbadgeingridbox'] = 'Section badge in grid box'; +$string['sectionbadgeingridbox_help'] = 'Show the section badge in the grid box'; +$string['defaultsectionbadgeingridbox'] = 'Section badge in grid box'; +$string['defaultsectionbadgeingridbox_desc'] = 'Show the section badge in the grid box.'; + // 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 56f267fb..1d0646cc 100755 --- a/lib.php +++ b/lib.php @@ -424,6 +424,14 @@ public function course_format_options($foreditform = false) { 'default' => 0, 'type' => PARAM_INT, ], + 'sectiontitleingridbox' => [ + 'default' => 0, + 'type' => PARAM_INT, + ], + 'sectionbadgeingridbox' => [ + 'default' => 0, + 'type' => PARAM_INT, + ], 'showcompletion' => [ 'default' => 0, 'type' => PARAM_INT, @@ -554,6 +562,38 @@ public function course_format_options($foreditform = false) { 'element_attributes' => [$sectionzeroingridvalues], ]; + $sectiontitleingridboxvalues = $this->generate_default_entry( + 'sectiontitleingridbox', + 0, + [ + 1 => new lang_string('no'), + 2 => new lang_string('yes'), + ], + ); + $courseformatoptionsedit['sectiontitleingridbox'] = [ + 'label' => new lang_string('sectiontitleingridbox', 'format_grid'), + 'help' => 'sectiontitleingridbox', + 'help_component' => 'format_grid', + 'element_type' => 'select', + 'element_attributes' => [$sectiontitleingridboxvalues], + ]; + + $sectionbadgeingridboxvalues = $this->generate_default_entry( + 'sectionbadgeingridbox', + 0, + [ + 1 => new lang_string('no'), + 2 => new lang_string('yes'), + ], + ); + $courseformatoptionsedit['sectionbadgeingridbox'] = [ + 'label' => new lang_string('sectionbadgeingridbox', 'format_grid'), + 'help' => 'sectionbadgeingridbox', + 'help_component' => 'format_grid', + 'element_type' => 'select', + 'element_attributes' => [$sectionbadgeingridboxvalues], + ]; + $showcompletionvalues = $this->generate_default_entry( 'showcompletion', 0, diff --git a/settings.php b/settings.php index 65606c6d..2d308e5e 100644 --- a/settings.php +++ b/settings.php @@ -158,6 +158,28 @@ ]; $page->add(new admin_setting_configselect($name, $title, $description, $default, $choices)); + // Section title in grid box. + $name = 'format_grid/defaultsectiontitleingridbox'; + $title = get_string('defaultsectiontitleingridbox', 'format_grid'); + $description = get_string('defaultsectiontitleingridbox_desc', 'format_grid'); + $default = 2; + $choices = [ + 1 => new lang_string('no'), + 2 => new lang_string('yes'), + ]; + $page->add(new admin_setting_configselect($name, $title, $description, $default, $choices)); + + // Section badge in grid box. + $name = 'format_grid/defaultsectionbadgeingridbox'; + $title = get_string('defaultsectionbadgeingridbox', 'format_grid'); + $description = get_string('defaultsectionbadgeingridbox_desc', 'format_grid'); + $default = 2; + $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'); diff --git a/styles.css b/styles.css index c543c3e2..d2e01232 100644 --- a/styles.css +++ b/styles.css @@ -61,6 +61,7 @@ } .format-grid .thegrid .grid-section { + border-width: 2px; width: 210px; } diff --git a/templates/grid.mustache b/templates/grid.mustache index 2fa9a06d..8d76279e 100644 --- a/templates/grid.mustache +++ b/templates/grid.mustache @@ -26,6 +26,9 @@ * sectionbreak - There is a section break for this section. * sectionbreakheading - Section break heading. * number - Section number. + * sectiontitleingridbox - Show the section title? + * sectionbadgeingridbox - Show the section bagde if any? + * sectiontitleandorbadgeingridbox - Is the title and or badge in the grid box? * iscurrent - Current section? * sectionurl - Section URL. * sectionname - Section name. @@ -61,6 +64,9 @@ "sectioncompletionmarkup": "" } ], + "sectiontitleingridbox": true, + "sectionbadgeingridbox": true, + "sectiontitleandorbadgeingridbox": true, "showcompletion": true } }} @@ -81,16 +87,20 @@ {{#popup}}
{{/popup}} + {{#sectiontitleandorbadgeingridbox}}
+ {{#sectiontitleingridbox}}

{{{sectionname}}}

- {{#hasbadge}} + {{/sectiontitleingridbox}} + {{#sectionbadgeingridbox}}{{#hasbadge}}
{{$ core_courseformat/local/content/section/badges }} {{> core_courseformat/local/content/section/badges }} {{/ core_courseformat/local/content/section/badges }}
- {{/hasbadge}} + {{/hasbadge}}{{/sectionbadgeingridbox}}
+ {{/sectiontitleandorbadgeingridbox}} {{#imageuri}}
{{imagealttext}} @@ -98,12 +108,12 @@
{{/imageuri}} {{#generatedimageuri}} -
+
{{#sectioncompletionmarkup}}{{{sectioncompletionmarkup}}}{{/sectioncompletionmarkup}}
{{/generatedimageuri}} {{#imageerror}} -
+

{{imageerror}}

{{#sectioncompletionmarkup}}{{{sectioncompletionmarkup}}}{{/sectioncompletionmarkup}}