Skip to content
Snippets Groups Projects
Commit cd37128e authored by Alexander Bias's avatar Alexander Bias
Browse files

Adapt Davo's patch to the existing code style

parent 52cce3d8
Branches
Tags
No related merge requests found
...@@ -470,7 +470,6 @@ class block_course_overview_campus extends block_base { ...@@ -470,7 +470,6 @@ class block_course_overview_campus extends block_base {
} }
// Teacher information // Teacher information
$courseteachers = [];
if ($coc_config->teachercoursefilter == true || $coc_config->secondrowshowteachername == true) { if ($coc_config->teachercoursefilter == true || $coc_config->secondrowshowteachername == true) {
// Get course teachers based on global teacher roles // Get course teachers based on global teacher roles
...@@ -478,14 +477,16 @@ class block_course_overview_campus extends block_base { ...@@ -478,14 +477,16 @@ class block_course_overview_campus extends block_base {
// Get all user name fields for SQL query in a proper way // Get all user name fields for SQL query in a proper way
$allnames = get_all_user_name_fields(true, 'u'); $allnames = get_all_user_name_fields(true, 'u');
$teacherfields = 'ra.id AS raid, u.id, '.$allnames.', r.sortorder'; $teacherfields = 'ra.id AS raid, u.id, '.$allnames.', r.sortorder'; // Moodle would complain about two columns called id with a "Did you remember to make the first column something unique in your call to get_records? Duplicate value 'xxx' found in column 'id'." debug message. That's why we alias one column to a name different than id.
$teachersortfields = 'u.lastname, u.firstname';
// Check if we have to check for suspended teachers // Check if we have to check for suspended teachers
$extrawhere = '';
if ($coc_config->teacherroleshidesuspended == 1) { if ($coc_config->teacherroleshidesuspended == 1) {
// Build extra where clause for SQL query // Build extra where clause for SQL query
$now = round(time(), -2); // improves db caching $now = round(time(), -2); // improves db caching
$extrawhere = 'ue.status = '.ENROL_USER_ACTIVE.' AND e.status = '.ENROL_INSTANCE_ENABLED.' AND ue.timestart < '.$now.' AND (ue.timeend = 0 OR ue.timeend > '.$now.')'; $extrawhere = 'ue.status = '.ENROL_USER_ACTIVE.' AND e.status = '.ENROL_INSTANCE_ENABLED.' AND ue.timestart < '.$now.' AND (ue.timeend = 0 OR ue.timeend > '.$now.')';
} else {
$extrawhere = '';
} }
// Check if we have to include teacher roles from parent contexts // Check if we have to include teacher roles from parent contexts
...@@ -493,56 +494,42 @@ class block_course_overview_campus extends block_base { ...@@ -493,56 +494,42 @@ class block_course_overview_campus extends block_base {
if ($coc_config->teacherrolesparent == 1) { if ($coc_config->teacherrolesparent == 1) {
// If we have to check for suspended teachers // If we have to check for suspended teachers
if ($coc_config->teacherroleshidesuspended == 1) { if ($coc_config->teacherroleshidesuspended == 1) {
$courseteachers = get_role_users($teacherroles, $context, true, $teacherfields, $courseteachers = get_role_users($teacherroles, $context, true, $teacherfields, $teachersortfields, false, '', '', '', $extrawhere);
'u.lastname, u.firstname', false, '', '', '', $extrawhere);
} }
else { else {
$courseteachers = get_role_users($teacherroles, $context, true, $teacherfields, $courseteachers = get_role_users($teacherroles, $context, true, $teacherfields, $teachersortfields);
'u.lastname, u.firstname');
} }
} }
// If no // If no
else if ($coc_config->teacherrolesparent == 2) { else if ($coc_config->teacherrolesparent == 2) {
// If we have to check for suspended teachers // If we have to check for suspended teachers
if ($coc_config->teacherroleshidesuspended == 1) { if ($coc_config->teacherroleshidesuspended == 1) {
$courseteachers = get_role_users($teacherroles, $context, false, $teacherfields, $courseteachers = get_role_users($teacherroles, $context, false, $teacherfields, $teachersortfields, false, '', '', '', $extrawhere);
'u.lastname, u.firstname', false, '', '', '', $extrawhere);
} }
else { else {
$courseteachers = get_role_users($teacherroles, $context, false, $teacherfields, $courseteachers = get_role_users($teacherroles, $context, false, $teacherfields, $teachersortfields);
'u.lastname, u.firstname');
} }
} }
// If depending on moodle/course:reviewotherusers capability // If depending on moodle/course:reviewotherusers capability
else if ($coc_config->teacherrolesparent == 3) { else if ($coc_config->teacherrolesparent == 3) {
// If we have to check for suspended teachers // If we have to check for suspended teachers
$reviewothers = has_capability('moodle/course:reviewotherusers', $context); $hasreviewotherscapability = has_capability('moodle/course:reviewotherusers', $context);
if ($coc_config->teacherroleshidesuspended == 1) { if ($coc_config->teacherroleshidesuspended == 1) {
$courseteachers = get_role_users($teacherroles, $context, $reviewothers, $teacherfields, $courseteachers = get_role_users($teacherroles, $context, $hasreviewotherscapability, $teacherfields, $teachersortfields, false, '', '', '', $extrawhere);
'u.lastname, u.firstname', false, '', '', '', $extrawhere);
} }
else { else {
$courseteachers = get_role_users($teacherroles, $context, $reviewothers, $teacherfields, $courseteachers = get_role_users($teacherroles, $context, $hasreviewotherscapability, $teacherfields, $teachersortfields);
'u.lastname, u.firstname');
} }
} }
// Should not happen // Should not happen
else { else {
$courseteachers = get_role_users($teacherroles, $context, true, $teacherfields, $courseteachers = get_role_users($teacherroles, $context, true, $teacherfields, $teachersortfields);
'u.lastname, u.firstname');
} }
} }
else { else {
$courseteachers = array(); $courseteachers = array();
} }
// Adjust $courseteachers to be indexed by userid (removing duplicates).
$tmp = $courseteachers;
$courseteachers = [];
foreach ($tmp as $teacher) {
$courseteachers[$teacher->id] = $teacher;
}
// Remember course teachers for later use // Remember course teachers for later use
$c->teachers = $courseteachers; $c->teachers = $courseteachers;
} }
......
...@@ -252,6 +252,15 @@ function block_course_overview_campus_get_teachername_string($teachers) { ...@@ -252,6 +252,15 @@ function block_course_overview_campus_get_teachername_string($teachers) {
return ''; return '';
} }
// The array may contain duplicates as a teacher might have more than one role
// We could run a fancy duplicate elimination now, but we will only rewrite the array in reverse order indexed by userid,
// this way existing teachers will be eliminated by their own duplicate with higher relevance
$teacherstmp = $teachers;
$teachers = [];
foreach (array_reverse($teacherstmp) as $teacher) {
$teachers[$teacher->id] = $teacher;
}
// Get all teachers' names as an array according the teacher name style setting // Get all teachers' names as an array according the teacher name style setting
$teachernames = array_map(function($obj) { $teachernames = array_map(function($obj) {
global $coc_config; global $coc_config;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment