Admin: Add setting 'disable_clean_exercise_results_for_teachers'

See BT#17196
pull/3293/head
Julio Montoya 6 years ago
parent 9aeed5adcf
commit d775d89ec4
  1. 93
      main/exercise/exercise.class.php
  2. 21
      main/exercise/exercise.php
  3. 66
      main/exercise/exercise_report.php
  4. 3
      main/install/configuration.dist.php

@ -8443,6 +8443,9 @@ class Exercise
$sessionId = 0, $sessionId = 0,
$returnData = false $returnData = false
) { ) {
$allowDelete = Exercise::allowAction('delete');
$allowClean = Exercise::allowAction('clean_results');
$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
@ -8906,32 +8909,39 @@ class Exercise
); );
// Clean exercise // Clean exercise
if ($locked == false) { $clean = '';
$clean = Display::url( if (true === $allowClean) {
Display::return_icon( if (false == $locked) {
'clean.png', $clean = Display::url(
get_lang('CleanStudentResults'), Display::return_icon(
'clean.png',
get_lang('CleanStudentResults'),
'',
ICON_SIZE_SMALL
),
'',
[
'onclick' => "javascript:if(!confirm('".addslashes(
api_htmlentities(
get_lang('AreYouSureToDeleteResults'),
ENT_QUOTES,
$charset
)
)." ".addslashes($row['title'])."?"."')) return false;",
'href' => 'exercise.php?'.api_get_cidreq(
).'&choice=clean_results&sec_token='.$token.'&exerciseId='.$row['id'],
]
);
} else {
$clean = Display::return_icon(
'clean_na.png',
get_lang('ResourceLockedByGradebook'),
'', '',
ICON_SIZE_SMALL ICON_SIZE_SMALL
), );
'', }
[
'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDeleteResults'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;",
'href' => 'exercise.php?'.api_get_cidreq().'&choice=clean_results&sec_token='.$token.'&exerciseId='.$row['id'],
]
);
} else {
$clean = Display::return_icon(
'clean_na.png',
get_lang('ResourceLockedByGradebook'),
'',
ICON_SIZE_SMALL
);
} }
if ($limitTeacherAccess && !api_is_platform_admin()) {
$clean = '';
}
$actions .= $clean; $actions .= $clean;
// Visible / invisible // Visible / invisible
// Check if this exercise was added in a LP // Check if this exercise was added in a LP
@ -10439,4 +10449,43 @@ class Exercise
return $group; return $group;
} }
public static function allowAction($action)
{
if (api_is_platform_admin()) {
return true;
}
$limitTeacherAccess = api_get_configuration_value('limit_exercise_teacher_access');
$disableClean = api_get_configuration_value('disable_clean_exercise_results_for_teachers');
switch ($action) {
case 'delete':
if (api_is_allowed_to_edit(null, true)) {
if ($limitTeacherAccess) {
return false;
}
return true;
}
break;
case 'clean_results':
if (api_is_allowed_to_edit(null, true)) {
if ($limitTeacherAccess) {
return false;
}
if ($disableClean) {
return false;
}
return true;
}
break;
}
return false;
}
} }

@ -24,6 +24,9 @@ api_protect_course_script(true);
$limitTeacherAccess = api_get_configuration_value('limit_exercise_teacher_access'); $limitTeacherAccess = api_get_configuration_value('limit_exercise_teacher_access');
$allowDelete = Exercise::allowAction('delete');
$allowClean = Exercise::allowAction('clean_results');
$check = Security::get_existing_token('get'); $check = Security::get_existing_token('get');
$currentUrl = api_get_self().'?'.api_get_cidreq(); $currentUrl = api_get_self().'?'.api_get_cidreq();
@ -94,7 +97,7 @@ if ($is_allowedToEdit) {
switch ($action) { switch ($action) {
case 'clean_all_test': case 'clean_all_test':
if ($check) { if ($check) {
if ($limitTeacherAccess && !api_is_platform_admin()) { if (false === $allowClean) {
api_not_allowed(true); api_not_allowed(true);
} }
@ -207,7 +210,9 @@ if (!empty($action) && $is_allowedToEdit) {
switch ($action) { switch ($action) {
case 'delete': case 'delete':
$objExerciseTmp->delete(); if ($allowDelete) {
$objExerciseTmp->delete();
}
break; break;
case 'visible': case 'visible':
if ($limitTeacherAccess && !api_is_platform_admin()) { if ($limitTeacherAccess && !api_is_platform_admin()) {
@ -303,9 +308,11 @@ if ($is_allowedToEdit) {
break; break;
case 'delete': case 'delete':
// deletes an exercise // deletes an exercise
$result = $objExerciseTmp->delete(); if ($allowDelete) {
if ($result) { $result = $objExerciseTmp->delete();
Display::addFlash(Display::return_message(get_lang('ExerciseDeleted'), 'confirmation')); if ($result) {
Display::addFlash(Display::return_message(get_lang('ExerciseDeleted'), 'confirmation'));
}
} }
break; break;
case 'enable': case 'enable':
@ -375,7 +382,7 @@ if ($is_allowedToEdit) {
break; break;
case 'clean_results': case 'clean_results':
if ($limitTeacherAccess && !api_is_platform_admin()) { if (false === $allowClean) {
// Teacher change exercise // Teacher change exercise
break; break;
} }
@ -549,7 +556,7 @@ if ($is_allowedToEdit && $origin !== 'learnpath') {
Display::return_icon('import_excel.png', get_lang('ImportExcelQuiz'), '', ICON_SIZE_MEDIUM).'</a>'; Display::return_icon('import_excel.png', get_lang('ImportExcelQuiz'), '', ICON_SIZE_MEDIUM).'</a>';
$cleanAll = null; $cleanAll = null;
if (api_is_platform_admin() || false === $limitTeacherAccess) { if ($allowClean) {
$cleanAll = Display::url( $cleanAll = Display::url(
Display::return_icon( Display::return_icon(
'clean_all.png', 'clean_all.png',

@ -30,6 +30,7 @@ if (api_is_student_boss() && !empty($filter_user)) {
} }
$limitTeacherAccess = api_get_configuration_value('limit_exercise_teacher_access'); $limitTeacherAccess = api_get_configuration_value('limit_exercise_teacher_access');
$allowClean = Exercise::allowAction('clean_results');
if ($limitTeacherAccess && !api_is_platform_admin()) { if ($limitTeacherAccess && !api_is_platform_admin()) {
api_not_allowed(true); api_not_allowed(true);
@ -326,37 +327,40 @@ if ($is_allowedToEdit && $origin != 'learnpath') {
Display::return_icon('reload.png', get_lang('RecalculateResults'), [], ICON_SIZE_MEDIUM), Display::return_icon('reload.png', get_lang('RecalculateResults'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'exercise/recalculate_all.php?'.api_get_cidreq()."&exercise=$exercise_id" api_get_path(WEB_CODE_PATH).'exercise/recalculate_all.php?'.api_get_cidreq()."&exercise=$exercise_id"
); );
// clean result before a selected date icon // clean result before a selected date icon
$actions .= Display::url( if ($allowClean) {
Display::return_icon( $actions .= Display::url(
'clean_before_date.png', Display::return_icon(
get_lang('CleanStudentsResultsBeforeDate'), 'clean_before_date.png',
'', get_lang('CleanStudentsResultsBeforeDate'),
ICON_SIZE_MEDIUM '',
), ICON_SIZE_MEDIUM
'#', ),
['onclick' => 'javascript:display_date_picker()'] '#',
); ['onclick' => 'javascript:display_date_picker()']
// clean result before a selected date datepicker popup );
$actions .= Display::span( // clean result before a selected date datepicker popup
Display::input( $actions .= Display::span(
'input', Display::input(
'datepicker_start', 'input',
get_lang('SelectADateOnTheCalendar'), 'datepicker_start',
[ get_lang('SelectADateOnTheCalendar'),
'onmouseover' => 'datepicker_input_mouseover()', [
'id' => 'datepicker_start', 'onmouseover' => 'datepicker_input_mouseover()',
'onchange' => 'datepicker_input_changed()', 'id' => 'datepicker_start',
'readonly' => 'readonly', 'onchange' => 'datepicker_input_changed()',
] 'readonly' => 'readonly',
). ]
Display::button( ).
'delete', Display::button(
get_lang('Delete'), 'delete',
['onclick' => 'submit_datepicker()'] get_lang('Delete'),
), ['onclick' => 'submit_datepicker()']
['style' => 'display:none', 'id' => 'datepicker_span'] ),
); ['style' => 'display:none', 'id' => 'datepicker_span']
);
}
} }
} else { } else {
$actions .= '<a href="exercise.php">'. $actions .= '<a href="exercise.php">'.
@ -434,7 +438,7 @@ if (($is_allowedToEdit || $is_tutor || api_is_coach()) &&
) { ) {
// ask for the date // ask for the date
$check = Security::check_token('get'); $check = Security::check_token('get');
if ($check) { if ($check && $allowClean) {
$objExerciseTmp = new Exercise(); $objExerciseTmp = new Exercise();
if ($objExerciseTmp->read($exercise_id)) { if ($objExerciseTmp->read($exercise_id)) {
$count = $objExerciseTmp->cleanResults( $count = $objExerciseTmp->cleanResults(

@ -1529,6 +1529,9 @@ $_configuration['auth_password_links'] = [
// ALTER TABLE track_e_attempt_recording ADD COLUMN answer longtext default '' AFTER question_id; // ALTER TABLE track_e_attempt_recording ADD COLUMN answer longtext default '' AFTER question_id;
//$_configuration['quiz_answer_extra_recording'] = false; //$_configuration['quiz_answer_extra_recording'] = false;
// Disable clean results for teachers
// $_configuration['disable_clean_exercise_results_for_teachers'] = true;
// KEEP THIS AT THE END // KEEP THIS AT THE END
// -------- Custom DB changes // -------- Custom DB changes
// Add user activation by confirmation email // Add user activation by confirmation email

Loading…
Cancel
Save