diff --git a/Changes.md b/Changes.md index 97e3fa4e..f9394495 100644 --- a/Changes.md +++ b/Changes.md @@ -4,6 +4,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. Version 404.0.1 - 22/04/2024 ---------------------------- diff --git a/classes/output/courseformat/content/cm.php b/classes/output/courseformat/content/cm.php index 86c47e18..b127cdbb 100644 --- a/classes/output/courseformat/content/cm.php +++ b/classes/output/courseformat/content/cm.php @@ -61,6 +61,12 @@ public function export_for_template(\renderer_base $output): \stdClass { } } + $tcsettings = $this->format->get_settings(); + if ($tcsettings['flexiblemodules'] == 2) { + // Turn off indentation. + $data->indent = 0; + } + return $data; } diff --git a/classes/output/courseformat/content/section/cmitem.php b/classes/output/courseformat/content/section/cmitem.php index ef519983..f4fc8393 100644 --- a/classes/output/courseformat/content/section/cmitem.php +++ b/classes/output/courseformat/content/section/cmitem.php @@ -43,4 +43,22 @@ class cmitem extends \core_courseformat\output\local\content\section\cmitem { public function get_template_name(\renderer_base $renderer): string { return 'format_topcoll/local/content/section/cmitem'; } + + /** + * Export this data so it can be used as the context for a mustache template. + * + * @param renderer_base $output typically, the renderer that's calling this function + * @return stdClass data context for a mustache template + */ + public function export_for_template(\renderer_base $output): \stdClass { + $context = parent::export_for_template($output); + + $tcsettings = $this->format->get_settings(); + if ($tcsettings['flexiblemodules'] == 2) { + // Turn off indentation. + $context->indent = 0; + } + + return $context; + } } diff --git a/classes/output/courseformat/content/section/cmlist.php b/classes/output/courseformat/content/section/cmlist.php index e0722c44..50ede312 100644 --- a/classes/output/courseformat/content/section/cmlist.php +++ b/classes/output/courseformat/content/section/cmlist.php @@ -59,6 +59,9 @@ public function export_for_template(\renderer_base $output): \stdClass { $data->num = $this->section->section ?? '0'; $data->sectionreturn = $this->format->get_sectionnum(); + $tcsettings = $this->format->get_settings(); + $data->flexiblemodules = ($tcsettings['flexiblemodules'] == 2); + return $data; } } diff --git a/lang/en/format_topcoll.php b/lang/en/format_topcoll.php index 6db00cc3..bf5a16fb 100644 --- a/lang/en/format_topcoll.php +++ b/lang/en/format_topcoll.php @@ -187,6 +187,10 @@ $string['columnhorizontal'] = 'Horizontal'; $string['columnvertical'] = 'Vertical'; +// Flexible modules. +$string['setflexiblemodules'] = 'Flexible modules'; +$string['setflexiblemodules_help'] = 'Use flexible modules?'; + // MDL-34917 - implemented in M2.5 but needs to be here to support M2.4- versions. $string['maincoursepage'] = 'Main course page'; @@ -291,6 +295,9 @@ $string['defaultlayoutcolumnorientation'] = 'Column orientation'; $string['defaultlayoutcolumnorientation_desc'] = 'The default column orientation: Dynamic - Number sections per \'row\' adjust to window size, \'Column\' setting not currently used.
Horizontal - Sections go left to right.
Vertical - Sections go top to bottom.'; +$string['defaultflexiblemodules'] = 'Flexible modules'; +$string['defaultflexiblemodules_desc'] = 'Use flexible modules?'; + $string['defaulttgfgcolour'] = 'Toggle foreground colour'; $string['defaulttgfgcolour_desc'] = "Toggle foreground colour in hexidecimal RGB."; diff --git a/lib.php b/lib.php index ed20cf30..d98eaad7 100644 --- a/lib.php +++ b/lib.php @@ -581,6 +581,10 @@ public function course_format_options($foreditform = false) { 'default' => 0, 'type' => PARAM_INT, ], + 'flexiblemodules' => [ + 'default' => 0, + 'type' => PARAM_INT, + ], 'toggleallenabled' => [ 'default' => 0, 'type' => PARAM_INT, @@ -814,6 +818,21 @@ public function course_format_options($foreditform = false) { 'element_type' => 'select', 'element_attributes' => [$layoutcolumnsvalues], ]; + $flexiblemodulesvalues = $this->generate_default_entry( + 'flexiblemodules', + 0, + [ + 1 => new lang_string('no'), + 2 => new lang_string('yes'), + ] + ); + $courseformatoptionsedit['flexiblemodules'] = [ + 'label' => new lang_string('setflexiblemodules', 'format_topcoll'), + 'help' => 'setflexiblemodules', + 'help_component' => 'format_topcoll', + 'element_type' => 'select', + 'element_attributes' => [$flexiblemodulesvalues], + ]; $toggleallenabledvalues = $this->generate_default_entry( 'toggleallenabled', 0, @@ -898,6 +917,8 @@ public function course_format_options($foreditform = false) { 'label' => 0, 'element_type' => 'hidden', ]; $courseformatoptionsedit['layoutcolumnorientation'] = [ 'label' => 0, 'element_type' => 'hidden', ]; + $courseformatoptionsedit['flexiblemodules'] = [ + 'label' => 0, 'element_type' => 'hidden', ]; $courseformatoptionsedit['toggleallenabled'] = [ 'label' => 0, 'element_type' => 'hidden', ]; $courseformatoptionsedit['viewsinglesectionenabled'] = [ @@ -1688,6 +1709,7 @@ public function reset_topcoll_setting( $updatedata['layoutstructure'] = 0; $updatedata['layoutcolumns'] = 0; $updatedata['layoutcolumnorientation'] = 0; + $updatedata['flexiblemodules'] = 0; $updatedata['toggleallenabled'] = 0; $updatedata['viewsinglesectionenabled'] = 0; $updatedata['toggleiconposition'] = 0; @@ -1780,6 +1802,7 @@ public function restore_topcoll_setting( // Defaults taken from 'settings.php'. $data['displayinstructions'] = 0; $data['layoutcolumnorientation'] = 0; + $data['flexiblemodules'] = 0; $data['toggleallenabled'] = 0; $data['viewsinglesectionenabled'] = 0; $data['showsectionsummary'] = 0; diff --git a/settings.php b/settings.php index f3da3498..9c0365c7 100644 --- a/settings.php +++ b/settings.php @@ -191,6 +191,17 @@ ]; $page->add(new admin_setting_configselect($name, $title, $description, $default, $choices)); + /* Flexible modules - 1 = no, 2 = yes. */ + $name = 'format_topcoll/defaultflexiblemodules'; + $title = get_string('defaultflexiblemodules', 'format_topcoll'); + $description = get_string('defaultflexiblemodules_desc', 'format_topcoll'); + $default = 1; + $choices = [ + 1 => new lang_string('no'), // No. + 2 => new lang_string('yes'), // Yes. + ]; + $page->add(new admin_setting_configselect($name, $title, $description, $default, $choices)); + /* Toggle all enabled - 1 = no, 2 = yes. */ $name = 'format_topcoll/defaulttoggleallenabled'; $title = get_string('defaulttoggleallenabled', 'format_topcoll'); diff --git a/styles.css b/styles.css index f1273503..bf652079 100644 --- a/styles.css +++ b/styles.css @@ -675,10 +675,15 @@ body.format-topcoll.editing.dir-rtl .ctopics .section .activity .mod-indent-oute padding-right: 32px; } -body.format-topcoll .ctopics .section { +body.format-topcoll .ctopics .section { margin: 1em 0; } +body.format-topcoll .ctopics .section .d-flex { + flex-wrap: wrap; + justify-content: space-between; +} + body.format-topcoll .course-content ul.ctopics li.section .summary { margin-left: 0; } diff --git a/templates/local/content/section/cmlist.mustache b/templates/local/content/section/cmlist.mustache index 9ed273ef..73bddbe5 100644 --- a/templates/local/content/section/cmlist.mustache +++ b/templates/local/content/section/cmlist.mustache @@ -18,14 +18,62 @@ {{! @template format_topcoll/local/content/section/cmlist - Include the core content/section/cmlist template. - See core file for example context. -}} - -{{< core_courseformat/local/content/section/cmlist }} + Displays the course module list inside a course section. - {{$ core_courseformat/local/content/section/cmitem}} - {{> format_topcoll/local/content/section/cmitem }} - {{/ core_courseformat/local/content/section/cmitem}} - -{{/ core_courseformat/local/content/section/cmlist }} + Example context (json): + { + "cms": [ + { + "cmitem": { + "cmformat": { + "cmname": "Forum example", + "hasname": "true" + }, + "id": 3, + "module": "forum", + "extraclasses": "newmessages" + } + }, + { + "cmitem": { + "cmformat": { + "cmname": "Assign example", + "hasname": "true" + }, + "id": 4, + "module": "assign", + "extraclasses": "" + } + } + ], + "hascms": true, + "flexiblemodules": false, + "showmovehere": true, + "movingstr": "Moving this activity: folder example", + "cancelcopyurl": "#", + "movetosectionurl": "#", + "strmovefull": "Move 'folder example' to this location" + } +}} +{{#showmovehere}} +

{{movingstr}} ({{#str}} cancel {{/str}})

+{{/showmovehere}} + \ No newline at end of file diff --git a/tests/courseformatrenderer_test.php b/tests/courseformatrenderer_test.php index 4cf9e3f4..ff2d0e6d 100644 --- a/tests/courseformatrenderer_test.php +++ b/tests/courseformatrenderer_test.php @@ -90,8 +90,8 @@ protected static function get_property($obj, $name) { /** * Init. */ - protected function init($numsections = 1, $layoutcolumnorientation = 2, $toggleallenabled = 2, - $viewsinglesectionenabled = 2): void { + protected function init($numsections = 1, $layoutcolumnorientation = 2, $flexiblemodules = 1, + $toggleallenabled = 2, $viewsinglesectionenabled = 2): void { $this->resetAfterTest(true); set_config('theme', 'boost'); @@ -126,6 +126,7 @@ protected function init($numsections = 1, $layoutcolumnorientation = 2, $togglea self::set_property($this->outputus, 'output', $this->ouroutput); $tcsettings = $this->courseformat->get_settings(); $tcsettings['layoutcolumnorientation'] = $layoutcolumnorientation; + $tcsettings['flexiblemodules'] = $flexiblemodules; $tcsettings['toggleallenabled'] = $toggleallenabled; $tcsettings['viewsinglesectionenabled'] = $viewsinglesectionenabled; $tcsettings['toggleiconset'] = 'arrow';