Skip to content

Commit

Permalink
Show warning if there is a stealth section with content, related to #196
Browse files Browse the repository at this point in the history
.
  • Loading branch information
gjb2048 committed Dec 2, 2023
1 parent 64c19d2 commit d45d841
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Version 403.1.1 - TBR
thanks to @Syxton(Matt Davidson).
2. Fix 'Sections showing beyond the number set in the settings', related to #196.
3. Improved backup and restore logic.
4. Show warning if there is a stealth section with content, related to #196.

Version 403.1.0 - 15/10/2023
----------------------------
Expand Down
25 changes: 23 additions & 2 deletions classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,26 @@ class content extends content_base {
*/
protected $hasaddsection = false;

/**
* @var int Are there stealth sections with content?
*/
protected $hassteathwithcontent = 0;

/**
* Get the template name.
*
* @param renderer_base $output typically, the renderer that's calling this method.
* @return string Mustache template name.
*/
public function get_template_name(\renderer_base $renderer): string {
return 'format_grid/local/content';
}

/**
* Export this data so it can be used as the context for a mustache template (core/inplace_editable).
*
* @param renderer_base $output typically, the renderer that's calling this function
* @return stdClass data context for a Mustache template
* @param renderer_base $output typically, the renderer that's calling this method.
* @return stdClass data context for a Mustache template.
*/
public function export_for_template(\renderer_base $output) {
global $DB, $PAGE;
Expand Down Expand Up @@ -258,6 +269,13 @@ public function export_for_template(\renderer_base $output) {
}
}

if ($this->hassteathwithcontent) {
$context = \context_course::instance($course->id);
if (has_capability('moodle/course:update', $context)) {
$data->stealthwarning = get_string('stealthwarning', 'format_grid', $this->hassteathwithcontent);
}
}

if ($this->hasaddsection) {
$addsection = new $this->addsectionclass($format);
$data->numsections = $addsection->export_for_template($output);
Expand Down Expand Up @@ -309,6 +327,9 @@ protected function get_grid_sections(\renderer_base $output, $settings): array {
}

if ($thissection->section > $numsections) {
if (!empty($modinfo->sections[$thissection->section])) {
$this->hassteathwithcontent++;
}
continue;
}

Expand Down
1 change: 1 addition & 0 deletions lang/en/format_grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
$string['settings'] = 'Settings';
$string['settingssettings'] = 'Settings settings';
$string['settingssettingsdesc'] = 'Grid format settings';
$string['stealthwarning'] = 'Warning: Course has {$a} orphaned section(s) with content.';
$string['love'] = 'love';
$string['versioninfo'] = 'Release {$a->release}, version {$a->version} on Moodle {$a->moodle}. Made with {$a->love} in Great Britain.';
$string['versionalpha'] = 'Alpha version - Almost certainly contains bugs. This is a development version for developers \'only\'! Don\'t even think of installing on a production server!';
Expand Down
3 changes: 3 additions & 0 deletions templates/local/content.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@
{{#hasheaderimages}}
{{> format_grid/coursestyles }}
{{/hasheaderimages}}
{{#stealthwarning}}
<div class="p-3 mb-3 bg-warning text-white">{{stealthwarning}}</div>
{{/stealthwarning}}
<ul class="{{format}}" data-for="course_sectionlist">
{{#initialsection}}
{{$ core_courseformat/local/content/section }}
Expand Down

0 comments on commit d45d841

Please sign in to comment.