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

Clean up code of last pull request

parent d0995edd
Branches
No related tags found
No related merge requests found
...@@ -464,39 +464,46 @@ class block_course_overview_campus extends block_base { ...@@ -464,39 +464,46 @@ class block_course_overview_campus extends block_base {
// Teacher information // Teacher information
if ($coc_config->teachercoursefilter == true || $coc_config->secondrowshowteachername == true) { if ($coc_config->teachercoursefilter == true || $coc_config->secondrowshowteachername == true) {
$now1 = round(time(), -2); // improves db caching
$now2 = $now1;
$statussuspended = 0;
$enrolmentactive = 0;
$extrawhere = 'ue.status = '.$statussuspended.' AND e.status = '.$enrolmentactive.' AND ue.timestart < '.$now1.' AND (ue.timeend = 0 OR ue.timeend > '.$now2.')';
// Get course teachers based on global teacher roles // Get course teachers based on global teacher roles
if (count($teacherroles) > 0) { if (count($teacherroles) > 0) {
// Check if we have to check for suspended teachers
if ($coc_config->teacherroleshidesuspended == 1) {
// Build extra where clause for SQL query
$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.')';
}
// Check if we have to include teacher roles from parent contexts // Check if we have to include teacher roles from parent contexts
// If yes // If yes
if ($coc_config->teacherrolesparent == 1) { if ($coc_config->teacherrolesparent == 1) {
if ($coc_config->teacherroleshidesuspendedteacher == 0) { // also show suspended teachers // If we have to check for suspended teachers
$courseteachers = get_role_users($teacherroles, $context, true, 'ra.id, u.id, u.lastname, u.firstname, r.sortorder', 'u.lastname, u.firstname'); if ($coc_config->teacherroleshidesuspended == 1) {
} else { // hide suspended teachers
$courseteachers = get_role_users($teacherroles, $context, true, 'ra.id, u.id, u.lastname, u.firstname, r.sortorder', 'u.lastname, u.firstname', false, '', '', '', $extrawhere); $courseteachers = get_role_users($teacherroles, $context, true, 'ra.id, u.id, u.lastname, u.firstname, r.sortorder', 'u.lastname, u.firstname', false, '', '', '', $extrawhere);
} }
else {
$courseteachers = get_role_users($teacherroles, $context, true, 'ra.id, u.id, u.lastname, u.firstname, r.sortorder', 'u.lastname, u.firstname');
}
} }
// If no // If no
else if ($coc_config->teacherrolesparent == 2) { else if ($coc_config->teacherrolesparent == 2) {
if ($coc_config->teacherroleshidesuspendedteacher == 0) { // also show suspended teachers // If we have to check for suspended teachers
$courseteachers = get_role_users($teacherroles, $context, false, 'ra.id, u.id, u.lastname, u.firstname, r.sortorder', 'u.lastname, u.firstname'); if ($coc_config->teacherroleshidesuspended == 1) {
} else { // hide suspended teachers
$courseteachers = get_role_users($teacherroles, $context, false, 'ra.id, u.id, u.lastname, u.firstname, r.sortorder', 'u.lastname, u.firstname', false, '', '', '', $extrawhere); $courseteachers = get_role_users($teacherroles, $context, false, 'ra.id, u.id, u.lastname, u.firstname, r.sortorder', 'u.lastname, u.firstname', false, '', '', '', $extrawhere);
} }
else {
$courseteachers = get_role_users($teacherroles, $context, false, 'ra.id, u.id, u.lastname, u.firstname, r.sortorder', '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 ($coc_config->teacherroleshidesuspendedteacher == 0) { // also show suspended teachers // If we have to check for suspended teachers
$courseteachers = get_role_users($teacherroles, $context, has_capability('moodle/course:reviewotherusers', $context), 'ra.id, u.id, u.lastname, u.firstname, r.sortorder', 'u.lastname, u.firstname'); if ($coc_config->teacherroleshidesuspended == 1) {
} else { // hide suspended teachers
$courseteachers = get_role_users($teacherroles, $context, has_capability('moodle/course:reviewotherusers', $context), 'ra.id, u.id, u.lastname, u.firstname, r.sortorder', 'u.lastname, u.firstname', false, '', '', '', $extrawhere); $courseteachers = get_role_users($teacherroles, $context, has_capability('moodle/course:reviewotherusers', $context), 'ra.id, u.id, u.lastname, u.firstname, r.sortorder', 'u.lastname, u.firstname', false, '', '', '', $extrawhere);
} }
else {
$courseteachers = get_role_users($teacherroles, $context, has_capability('moodle/course:reviewotherusers', $context), 'ra.id, u.id, u.lastname, u.firstname, r.sortorder', 'u.lastname, u.firstname');
}
} }
// Should not happen // Should not happen
else { else {
......
...@@ -109,8 +109,8 @@ $string['teachernamestylefullnamedisplay'] = 'Teacher name style according to Mo ...@@ -109,8 +109,8 @@ $string['teachernamestylefullnamedisplay'] = 'Teacher name style according to Mo
$string['teacherrolessettingheading'] = 'Teacher roles'; $string['teacherrolessettingheading'] = 'Teacher roles';
$string['teacherroles'] = 'Teacher roles'; $string['teacherroles'] = 'Teacher roles';
$string['teacherroles_desc'] = 'Define which roles are handled as teacher roles by this plugin<br /><em>This setting is only processed when show teacher name is activated or when the teacher filter is activated or when the priorization of courses in which I teach is activated</em>'; $string['teacherroles_desc'] = 'Define which roles are handled as teacher roles by this plugin<br /><em>This setting is only processed when show teacher name is activated or when the teacher filter is activated or when the priorization of courses in which I teach is activated</em>';
$string['teacherroleshidesuspendedteacher'] = 'Verify active teacher enrolment'; $string['teacherroleshidesuspended'] = 'Hide suspended teachers';
$string['teacherrolessuspendedteacher_desc'] = 'If this option is active, it will check for suspended but enroled teachers and will NOT display them as teachers in the course information. This will cause a little higher load on the database. So just activate if you are sure that you really need this feature.'; $string['teacherroleshidesuspended_desc'] = 'When looking for teachers with the specified teacher roles, do not only check if a teacher has one of the given roles in a course, but also check if his enrolment into the course is active (i.e. the teacher\'s enrolment in the course is not suspended + the current date is within the start and end dates of the teacher\'s enrolment + the enrolment method of the teacher\'s enrolment is enabled in the course). Teachers whose enrolment in a course is not active will not be considered as teacher for this course.<br /><em>This setting is only processed when show teacher name is activated or when the teacher filter is activated.</em><br /><em>Warning: If you enable this setting, the load on the database to create the list of courses will slightly increase due to the necessary additional checks. Thus, enable this setting only if you need to.</em>';
$string['teacherrolesparent'] = 'Include parent context teacher roles'; $string['teacherrolesparent'] = 'Include parent context teacher roles';
$string['teacherrolesparent_desc'] = 'When looking for teachers with the specified teacher roles, include teachers who have their role assigned in parent contexts (course category or system level)<br /><em>This setting is only processed when show teacher name is activated or when the teacher filter is activated.</em><br /><em>Warning: If you set this to "No" or "Depending on the user\'s moodle/course:reviewotherusers capability", the "Prioritize courses in which I teach" function will also be influenced and will not priorize courses where the user has his teacher role assigned in parent contexts.</em>'; $string['teacherrolesparent_desc'] = 'When looking for teachers with the specified teacher roles, include teachers who have their role assigned in parent contexts (course category or system level)<br /><em>This setting is only processed when show teacher name is activated or when the teacher filter is activated.</em><br /><em>Warning: If you set this to "No" or "Depending on the user\'s moodle/course:reviewotherusers capability", the "Prioritize courses in which I teach" function will also be influenced and will not priorize courses where the user has his teacher role assigned in parent contexts.</em>';
$string['teacherrolesparentcapability'] = 'Depending on the user\'s moodle/course:reviewotherusers capability'; $string['teacherrolesparentcapability'] = 'Depending on the user\'s moodle/course:reviewotherusers capability';
......
...@@ -202,8 +202,9 @@ else if ($ADMIN->fulltree) { ...@@ -202,8 +202,9 @@ else if ($ADMIN->fulltree) {
$settingspage->add(new admin_setting_configselect('block_course_overview_campus/teacherrolesparent', get_string('teacherrolesparent', 'block_course_overview_campus'), $settingspage->add(new admin_setting_configselect('block_course_overview_campus/teacherrolesparent', get_string('teacherrolesparent', 'block_course_overview_campus'),
get_string('teacherrolesparent_desc', 'block_course_overview_campus'), $teacherrolesparentmodes[1], $teacherrolesparentmodes)); get_string('teacherrolesparent_desc', 'block_course_overview_campus'), $teacherrolesparentmodes[1], $teacherrolesparentmodes));
$settingspage->add(new admin_setting_configcheckbox('block_course_overview_campus/teacherroleshidesuspendedteacher', get_string('teacherroleshidesuspendedteacher', 'block_course_overview_campus'), $settingspage->add(new admin_setting_configcheckbox('block_course_overview_campus/teacherroleshidesuspended', get_string('teacherroleshidesuspended', 'block_course_overview_campus'),
get_string('teacherrolessuspendedteacher_desc', 'block_course_overview_campus'), 0)); get_string('teacherroleshidesuspended_desc', 'block_course_overview_campus'), 0));
// Add settings page to the admin settings category // Add settings page to the admin settings category
$ADMIN->add('block_course_overview_campus', $settingspage); $ADMIN->add('block_course_overview_campus', $settingspage);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment