Skip to content

Commit

Permalink
add a setting to ignore visibility of courses/categories
Browse files Browse the repository at this point in the history
  • Loading branch information
my-curiosity committed Feb 21, 2024
1 parent 8e4c3d7 commit db41680
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 3 additions & 5 deletions block_overviewmyrolesincourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public function get_content() {
global $USER, $OUTPUT;
$foldonstart = $this->config->foldonstart;
// 1. Find all courses a user is enrolled.
$enroledcourses = enrol_get_my_courses();
$enroledcourses = get_config('block_overviewmyrolesincourses', 'defaultskipcoursecapabilitycheck')
? enrol_get_all_users_courses($USER->id)
: enrol_get_my_courses();
$text = '';
if ($enroledcourses) {
// 2. Find all roles that the admin has configured as supported roles for this block.
Expand Down Expand Up @@ -139,10 +141,6 @@ public function get_courses_enroled_with_roleid(
$result = [];
foreach ($enroledcourses as $enroledcourse) {
$coursecontext = context_course::instance($enroledcourse->id);
if ($enroledcourse->visible == 0 && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
// Only show invisible courses if capability moodle/course:viewhiddencourses on this coursecontext.
continue;
}
$showpast = $this->config->showpast;
$showinprogress = $this->config->showinprogress;
$showfuture = $this->config->showfuture;
Expand Down
2 changes: 2 additions & 0 deletions lang/en/block_overviewmyrolesincourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
$string['defaultusetimeranges_desc'] = 'By default show course duration';
$string['defaultusecategories'] = 'Show course category';
$string['defaultusecategories_desc'] = 'By default show course category';
$string['defaultskipcoursecapabilitycheck'] = 'Skip checking capability to view hidden courses/categories';
$string['defaultskipcoursecapabilitycheck_desc'] = 'By default skip checking capability to view hidden courses/categories';
$string['foldonstart'] = 'Fold courselists on start';
$string['future'] = 'future';
$string['inprogress'] = 'in progress';
Expand Down
6 changes: 6 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,10 @@
get_string('defaultusecategories_desc', 'block_overviewmyrolesincourses'),
0
));
$settings->add(new admin_setting_configcheckbox(
'block_overviewmyrolesincourses/defaultskipcoursecapabilitycheck',
get_string('defaultskipcoursecapabilitycheck', 'block_overviewmyrolesincourses'),
get_string('defaultskipcoursecapabilitycheck_desc', 'block_overviewmyrolesincourses'),
0
));
}

0 comments on commit db41680

Please sign in to comment.