Skip to content

Commit 54e83de

Browse files
committed
remove complexity and duplicated code
1 parent 877925e commit 54e83de

3 files changed

+19
-67
lines changed

locallib.php

+17-21
Original file line numberDiff line numberDiff line change
@@ -47,39 +47,35 @@ function theme_boost_union_get_course_related_hints() {
4747
&& $PAGE->has_set_url()
4848
&& $COURSE->visible == false) {
4949

50-
// The hint will only be shown when the course is viewed.
50+
// Initialize hint text.
51+
$hintcoursehiddentext = '';
52+
53+
// The general hint will only be shown when the course is viewed.
5154
if ($PAGE->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
5255
// Prepare template context.
53-
$templatecontext = ['courseid' => $COURSE->id];
54-
55-
// If the user has the capability to change the course settings, an additional link to the course settings is shown.
56-
if (has_capability('moodle/course:update', context_course::instance($COURSE->id))) {
57-
$templatecontext['showcoursesettingslink'] = true;
58-
} else {
59-
$templatecontext['showcoursesettingslink'] = false;
60-
}
61-
62-
// Render template and add it to HTML code.
63-
$html .= $OUTPUT->render_from_template('theme_boost_union/course-hint-hidden', $templatecontext);
56+
$hintcoursehiddentext = get_string('showhintcoursehiddengeneral', 'theme_boost_union');
6457
}
6558

6659
// If the setting showhintcoursehiddennotifications is set too and we view a forum (e.g. announcement) within a hidden
6760
// course a hint will be shown that no notifications via forums will be sent out to students.
6861
if (get_config('theme_boost_union', 'showhintforumnotifications') == THEME_BOOST_UNION_SETTING_SELECT_YES
6962
&& $PAGE->url->compare(new moodle_url('/mod/forum/view.php'), URL_MATCH_BASE)) {
7063

71-
// Prepare template context.
72-
$templatecontext = ['courseid' => $COURSE->id];
64+
$hintcoursehiddentext = get_string('showhintforumnotifications', 'theme_boost_union');
65+
}
7366

74-
// If the user has the capability to change the course settings, an additional link to the course settings is shown.
75-
if (has_capability('moodle/course:update', context_course::instance($COURSE->id))) {
76-
$templatecontext['showcoursesettingslink'] = true;
77-
} else {
78-
$templatecontext['showcoursesettingslink'] = false;
79-
}
67+
// If we show any kind of hint for the hidden course, construct the hint html item via mustache.
68+
if ($hintcoursehiddentext) {
69+
// Prepare the templates context.
70+
$templatecontext = [
71+
'courseid' => $COURSE->id,
72+
'hintcoursehiddentext' => $hintcoursehiddentext,
73+
// If the user has the capability to change the course settings, an additional link to the course settings is shown.
74+
'showcoursesettingslink' => has_capability('moodle/course:update', context_course::instance($COURSE->id)),
75+
];
8076

8177
// Render template and add it to HTML code.
82-
$html .= $OUTPUT->render_from_template('theme_boost_union/course-hint-hidden-forum-notifications', $templatecontext);
78+
$html .= $OUTPUT->render_from_template('theme_boost_union/course-hint-hidden', $templatecontext);
8379
}
8480
}
8581

templates/course-hint-hidden-forum-notifications.mustache

-44
This file was deleted.

templates/course-hint-hidden.mustache

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
2222
Context variables required for this template:
2323
* courseid - The course ID
24-
* showhintcoursehiddengeneral - The info text shown on hidden courses below the course title,
24+
* hintcoursehiddentext - The info text shown on hidden courses,
2525
* showcoursesettingslink - The fact if a link to the course settings should be shown or not
2626
2727
Example context (json):
@@ -35,7 +35,7 @@
3535
<div class="media">
3636
<div class="mr-3 icon-size-5"><i class="fa fa-exclamation-circle fa-3x"></i></div>
3737
<div class="media-body align-self-center">
38-
{{#str}} showhintcoursehiddengeneral, theme_boost_union {{/str}}
38+
{{{hintcoursehiddentext}}}
3939
{{#showcoursesettingslink}}
4040
<br>{{#str}} showhintcoursehiddensettingslink, theme_boost_union, { "url": "{{config.wwwroot}}/course/edit.php?id={{courseid}}" } {{/str}}
4141
{{/showcoursesettingslink}}

0 commit comments

Comments
 (0)