Skip to content

Commit

Permalink
Add flexible modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Apr 28, 2024
1 parent d6bd951 commit c4d0b97
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 13 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------------------
Expand Down
6 changes: 6 additions & 0 deletions classes/output/courseformat/content/cm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
18 changes: 18 additions & 0 deletions classes/output/courseformat/content/section/cmitem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 3 additions & 0 deletions classes/output/courseformat/content/section/cmlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
7 changes: 7 additions & 0 deletions lang/en/format_topcoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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.<br>Horizontal - Sections go left to right.<br>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.";

Expand Down
23 changes: 23 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'] = [
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
7 changes: 6 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
68 changes: 58 additions & 10 deletions templates/local/content/section/cmlist.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<a class=\"aalink\" href=\"#\"><span class=\"instancename\">Forum example</span></a>",
"hasname": "true"
},
"id": 3,
"module": "forum",
"extraclasses": "newmessages"
}
},
{
"cmitem": {
"cmformat": {
"cmname": "<a class=\"aalink\" href=\"#\"><span class=\"instancename\">Assign example</span></a>",
"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}}
<p>{{movingstr}} (<a href="{{{cancelcopyurl}}}">{{#str}} cancel {{/str}}</a>)</p>
{{/showmovehere}}
<ul class="section m-0 p-0 img-text {{^flexiblemodules}}d-block{{/flexiblemodules}}{{#flexiblemodules}}d-flex{{/flexiblemodules}}" data-for="cmlist">
{{#cms}}
{{#showmovehere}}
<li class="movehere">
<a href="{{{moveurl}}}" title="{{strmovefull}}" class="movehere"></a>
</li>
{{/showmovehere}}
{{#cmitem}}
{{$ core_courseformat/local/content/section/cmitem}}
{{> format_topcoll/local/content/section/cmitem }}
{{/ core_courseformat/local/content/section/cmitem}}
{{/cmitem}}
{{/cms}}
{{#showmovehere}}
<li class="movehere">
<a href="{{{movetosectionurl}}}" title="{{strmovefull}}" class="movehere"></a>
</li>
{{/showmovehere}}
</ul>
5 changes: 3 additions & 2 deletions tests/courseformatrenderer_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit c4d0b97

Please sign in to comment.