From 53fb82c036f9f2e5951008230fcd102f35feb149 Mon Sep 17 00:00:00 2001
From: Kathrin Osswald <kathrin.osswald@uni-ulm.de>
Date: Wed, 12 Aug 2020 15:05:53 +0200
Subject: [PATCH] Added capability theme/boost_campus:viewhintinhiddencourse
 for setting showhintcoursehidden.

---
 CHANGES.md                       | 1 +
 classes/output/core_renderer.php | 7 +++++--
 db/access.php                    | 9 +++++++++
 lang/en/theme_boost_campus.php   | 1 +
 version.php                      | 2 +-
 5 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index adc242a..1236076 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -6,6 +6,7 @@ Changes
 
 ### Unreleased
 
+* 2020-08-19 - Added capability theme/boost_campus:viewhintinhiddencourse for setting showhintcoursehidden.
 * 2020-08-14 - Reduced inflationary call to reset theme caches for the settings.
 * 2020-08-12 - Fixed undefined variables notices.
 * 2020-08-11 - Added setting to be able to show a hint for a unrestricted self enrolment in a visible course.
diff --git a/classes/output/core_renderer.php b/classes/output/core_renderer.php
index 477e6bf..63a3575 100644
--- a/classes/output/core_renderer.php
+++ b/classes/output/core_renderer.php
@@ -218,8 +218,11 @@ class core_renderer extends \core_renderer {
         // MODIFICATION START:
         // If the setting showhintcoursehidden is set, the visibility of the course is hidden and
         // a hint for the visibility will be shown.
-        if (get_config('theme_boost_campus', 'showhintcoursehidden') == 'yes' && $COURSE->visible == false &&
-                $this->page->has_set_url() && $this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
+        if (get_config('theme_boost_campus', 'showhintcoursehidden') == 'yes'
+                && has_capability('theme/boost_campus:viewhintinhiddencourse', \context_course::instance($COURSE->id))
+                && $this->page->has_set_url()
+                && $this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)
+                && $COURSE->visible == false) {
             $html .= html_writer::start_tag('div', array('class' => 'course-hidden-infobox alert alert-warning'));
             $html .= html_writer::tag('i', null, array('class' => 'fa fa-exclamation-circle fa-3x fa-pull-left'));
             $html .= get_string('showhintcoursehiddengeneral', 'theme_boost_campus', $COURSE->id);
diff --git a/db/access.php b/db/access.php
index e78d994..2a01a6e 100644
--- a/db/access.php
+++ b/db/access.php
@@ -28,6 +28,15 @@ $capabilities = array(
 
     // Ability to see a hint for unrestricted self enrolment in a visible course.
         'theme/boost_campus:viewhintcourseselfenrol' => array(
+                'captype' => 'read',
+                'contextlevel' => CONTEXT_COURSE,
+                'archetypes' => array(
+                        'teacher' => CAP_ALLOW,
+                        'editingteacher' => CAP_ALLOW,
+                        'manager' => CAP_ALLOW )
+        ),
+    // Ability to see a hint in a hidden course.
+        'theme/boost_campus:viewhintinhiddencourse' => array(
                 'captype' => 'read',
                 'contextlevel' => CONTEXT_COURSE,
                 'archetypes' => array(
diff --git a/lang/en/theme_boost_campus.php b/lang/en/theme_boost_campus.php
index a7c161f..bec69e9 100644
--- a/lang/en/theme_boost_campus.php
+++ b/lang/en/theme_boost_campus.php
@@ -312,3 +312,4 @@ $string['privacy:metadata:request:infobanner_dismissed_no'] = 'Perpetual info ba
 
 // CAPABILITIES.
 $string['boost_campus:viewhintcourseselfenrol'] = 'To be able to see a hint for unrestricted self enrolment in a visible course.';
+$string['boost_campus:viewhintinhiddencourse'] = 'To be able to see a hint in a hidden course.';
diff --git a/version.php b/version.php
index 5274540..eceb765 100644
--- a/version.php
+++ b/version.php
@@ -25,7 +25,7 @@
 defined('MOODLE_INTERNAL') || die();
 
 $plugin->component = 'theme_boost_campus';
-$plugin->version = 2020081200;
+$plugin->version = 2020081201;
 $plugin->release = 'v3.8-r2';
 $plugin->requires = 2019111804;
 $plugin->maturity = MATURITY_STABLE;
-- 
GitLab