From 19fb53386ec3cfa2e60bfac000499314c2c3ce20 Mon Sep 17 00:00:00 2001 From: Anthony DURIF Date: Wed, 11 Nov 2020 13:47:14 +0100 Subject: [PATCH 1/2] Add option to exclude some roles in the block and in progress reports --- lang/en/block_completion_progress.php | 2 ++ overview.php | 9 +++++++-- settings.php | 6 ++++++ version.php | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lang/en/block_completion_progress.php b/lang/en/block_completion_progress.php index 73087016673..026fb81718b 100644 --- a/lang/en/block_completion_progress.php +++ b/lang/en/block_completion_progress.php @@ -99,3 +99,5 @@ $string['why_use_icons'] = 'Why you might want to use icons?'; $string['why_use_icons_help'] = '

You may wish to add tick and cross icons in the Completion Progress to make this block more visually accessible for students with colour-blindness.

It may also make the meaning of the block clearer if you believe colours are not intuitive, either for cultural or personal reasons.

'; $string['wrapafter'] = 'When wrapping, limit rows to'; +$string['roles_to_exclude'] = 'Roles to not display and not use and the block'; +$string['roles_to_exclude_desc'] = 'Roles list to not display or not use in this block and in the overview report. If an user owns one of theses roles the user will not appear in the block informations and his progress will not be displayed.'; diff --git a/overview.php b/overview.php index b0a56567be8..da71f4e5392 100644 --- a/overview.php +++ b/overview.php @@ -168,10 +168,12 @@ class_alias('block_completion_progress\checkbox_toggleall_compat', 'core\output\ } // Output the roles menu. +$rolestoexclude = get_config('block_completion_progress' ,'roles_to_exclude'); $sql = "SELECT DISTINCT r.id, r.name, r.shortname FROM {role} r, {role_assignments} a WHERE a.contextid = :contextid - AND r.id = a.roleid"; + AND r.id = a.roleid + AND r.id not in ($rolestoexclude)"; $params = array('contextid' => $context->id); $roles = role_fix_names($DB->get_records_sql($sql, $params), $context); $rolestodisplay = array(0 => get_string('allparticipants')); @@ -204,8 +206,11 @@ class_alias('block_completion_progress\checkbox_toggleall_compat', 'core\output\ FROM {user} u JOIN {role_assignments} a ON (a.contextid = :contextid AND a.userid = u.id $rolewhere) $groupjoin - LEFT JOIN {user_lastaccess} l ON (l.courseid = :courseid AND l.userid = u.id)"; + LEFT JOIN {user_lastaccess} l ON (l.courseid = :courseid AND l.userid = u.id) + WHERE a.userid not in + (SELECT userid FROM {role_assignments} WHERE contextid = :subcontextid AND roleid IN ($rolestoexclude))"; $params['contextid'] = $context->id; +$params['subcontextid'] = $context->id; $params['courseid'] = $course->id; $userrecords = $DB->get_records_sql($sql, $params); if (get_config('block_completion_progress', 'showinactive') !== "1") { diff --git a/settings.php b/settings.php index 56c2f8cff19..9fa68757116 100644 --- a/settings.php +++ b/settings.php @@ -102,4 +102,10 @@ '', DEFAULT_COMPLETIONPROGRESS_FORCEICONSINBAR) ); + $settings->add(new admin_setting_pickroles( + 'block_completion_progress/roles_to_exclude', + get_string('roles_to_exclude', 'block_completion_progress'), + get_string('roles_to_exclude_desc', 'block_completion_progress'), + null + )); } \ No newline at end of file diff --git a/version.php b/version.php index ac592bc22f5..96144e2c13f 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2020081000; +$plugin->version = 2020111000; $plugin->requires = 2018051700; $plugin->maturity = MATURITY_STABLE; $plugin->release = 'Version for Moodle 3.5 onwards'; From 1e5e9875a37efdbb2cc4c65cdfb5f4cce739d987 Mon Sep 17 00:00:00 2001 From: Anthony DURIF Date: Thu, 12 Nov 2020 13:41:19 +0100 Subject: [PATCH 2/2] Fix sql request if no role selected --- overview.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/overview.php b/overview.php index da71f4e5392..3157df6191e 100644 --- a/overview.php +++ b/overview.php @@ -172,8 +172,10 @@ class_alias('block_completion_progress\checkbox_toggleall_compat', 'core\output\ $sql = "SELECT DISTINCT r.id, r.name, r.shortname FROM {role} r, {role_assignments} a WHERE a.contextid = :contextid - AND r.id = a.roleid - AND r.id not in ($rolestoexclude)"; + AND r.id = a.roleid"; +if ($rolestoexclude != "") { + $sql .= " AND r.id not in ($rolestoexclude)"; +} $params = array('contextid' => $context->id); $roles = role_fix_names($DB->get_records_sql($sql, $params), $context); $rolestodisplay = array(0 => get_string('allparticipants')); @@ -206,9 +208,11 @@ class_alias('block_completion_progress\checkbox_toggleall_compat', 'core\output\ FROM {user} u JOIN {role_assignments} a ON (a.contextid = :contextid AND a.userid = u.id $rolewhere) $groupjoin - LEFT JOIN {user_lastaccess} l ON (l.courseid = :courseid AND l.userid = u.id) - WHERE a.userid not in + LEFT JOIN {user_lastaccess} l ON (l.courseid = :courseid AND l.userid = u.id)"; +if ($rolestoexclude != "") { + $sql .= " WHERE a.userid not in (SELECT userid FROM {role_assignments} WHERE contextid = :subcontextid AND roleid IN ($rolestoexclude))"; +} $params['contextid'] = $context->id; $params['subcontextid'] = $context->id; $params['courseid'] = $course->id;