Course: Remove obsolete 'Allow tests auto-launch' parameter and simplify logic - refs BT#22104

pull/5996/head
Christian Beeznest 9 months ago
parent e3176390bb
commit 2f2a83ab8a
  1. 27
      assets/vue/router/index.js
  2. 34
      public/main/exercise/exercise.class.php
  3. 88
      src/CoreBundle/Controller/CourseController.php
  4. 1
      src/CoreBundle/Controller/PlatformConfigurationController.php
  5. 5
      src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php
  6. 2
      src/CoreBundle/Settings/ExerciseSettingsSchema.php

@ -140,25 +140,20 @@ const router = createRouter({
}
// Exercise auto-launch
const platformConfigStore = usePlatformConfig()
const isExerciseAutoLaunchEnabled =
"true" === platformConfigStore.getSetting("exercise.allow_exercise_auto_launch")
if (isExerciseAutoLaunchEnabled) {
const exerciseAutoLaunch = parseInt(courseSettingsStore.getSetting("enable_exercise_auto_launch"), 10) || 0
if (exerciseAutoLaunch === 2) {
const exerciseAutoLaunch = parseInt(courseSettingsStore.getSetting("enable_exercise_auto_launch"), 10) || 0
if (exerciseAutoLaunch === 2) {
sessionStorage.setItem(autoLaunchKey, "true")
window.location.href =
`/main/exercise/exercise.php?cid=${courseId}` + (sessionId ? `&sid=${sessionId}` : "")
return false
} else if (exerciseAutoLaunch === 1) {
const exerciseId = await courseService.getAutoLaunchExerciseId(courseId, sessionId)
if (exerciseId) {
sessionStorage.setItem(autoLaunchKey, "true")
window.location.href =
`/main/exercise/exercise.php?cid=${courseId}` + (sessionId ? `&sid=${sessionId}` : "")
`/main/exercise/overview.php?exerciseId=${exerciseId}&cid=${courseId}` +
(sessionId ? `&sid=${sessionId}` : "")
return false
} else if (exerciseAutoLaunch === 1) {
const exerciseId = await courseService.getAutoLaunchExerciseId(courseId, sessionId)
if (exerciseId) {
sessionStorage.setItem(autoLaunchKey, "true")
window.location.href =
`/main/exercise/overview.php?exerciseId=${exerciseId}&cid=${courseId}` +
(sessionId ? `&sid=${sessionId}` : "")
return false
}
}
}

@ -8810,12 +8810,6 @@ class Exercise
$keyword = Database::escape_string($keyword);
$learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : null;
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) $_REQUEST['learnpath_item_id'] : null;
$autoLaunchAvailable = false;
if (1 == api_get_course_setting('enable_exercise_auto_launch') &&
('true' === api_get_setting('exercise.allow_exercise_auto_launch'))
) {
$autoLaunchAvailable = true;
}
$courseId = $course->getId();
$tableRows = [];
@ -9067,21 +9061,19 @@ class Exercise
}
// Auto launch
if ($autoLaunchAvailable) {
$autoLaunch = $exercise->getAutoLaunch();
if (empty($autoLaunch)) {
$actions .= Display::url(
Display::getMdiIcon('rocket-launch', 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Enable')),
'exercise.php?'.api_get_cidreq(
).'&action=enable_launch&sec_token='.$token.'&exerciseId='.$exerciseId
);
} else {
$actions .= Display::url(
Display::getMdiIcon('rocket-launch', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Disable')),
'exercise.php?'.api_get_cidreq(
).'&action=disable_launch&sec_token='.$token.'&exerciseId='.$exerciseId
);
}
$autoLaunch = $exercise->getAutoLaunch();
if (empty($autoLaunch)) {
$actions .= Display::url(
Display::getMdiIcon('rocket-launch', 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Enable')),
'exercise.php?'.api_get_cidreq(
).'&action=enable_launch&sec_token='.$token.'&exerciseId='.$exerciseId
);
} else {
$actions .= Display::url(
Display::getMdiIcon('rocket-launch', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Disable')),
'exercise.php?'.api_get_cidreq(
).'&action=disable_launch&sec_token='.$token.'&exerciseId='.$exerciseId
);
}
// Export

@ -894,59 +894,57 @@ class CourseController extends ToolBaseController
}
}
if ('true' === api_get_setting('exercise.allow_exercise_auto_launch')) {
$exerciseAutoLaunch = (int) api_get_course_setting('enable_exercise_auto_launch');
if (2 === $exerciseAutoLaunch) {
if ($allowAutoLaunchForCourseAdmins) {
if (empty($autoLaunchWarning)) {
$autoLaunchWarning = get_lang(
'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToTheExerciseList'
);
}
} else {
// Redirecting to the document
$url = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq();
header(\sprintf('Location: %s', $url));
exit;
$exerciseAutoLaunch = (int) api_get_course_setting('enable_exercise_auto_launch');
if (2 === $exerciseAutoLaunch) {
if ($allowAutoLaunchForCourseAdmins) {
if (empty($autoLaunchWarning)) {
$autoLaunchWarning = get_lang(
'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToTheExerciseList'
);
}
} elseif (1 === $exerciseAutoLaunch) {
if ($allowAutoLaunchForCourseAdmins) {
if (empty($autoLaunchWarning)) {
$autoLaunchWarning = get_lang(
'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise'
);
}
} else {
// Redirecting to an exercise
$table = Database::get_course_table(TABLE_QUIZ_TEST);
$condition = '';
if (!empty($session_id)) {
$condition = api_get_session_condition($session_id);
$sql = "SELECT iid FROM {$table}
WHERE c_id = {$course_id} AND autolaunch = 1 {$condition}
LIMIT 1";
$result = Database::query($sql);
// If we found nothing in the session we just called the session_id = 0 autolaunch
if (0 === Database::num_rows($result)) {
$condition = '';
}
}
} else {
// Redirecting to the document
$url = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq();
header(\sprintf('Location: %s', $url));
exit;
}
} elseif (1 === $exerciseAutoLaunch) {
if ($allowAutoLaunchForCourseAdmins) {
if (empty($autoLaunchWarning)) {
$autoLaunchWarning = get_lang(
'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise'
);
}
} else {
// Redirecting to an exercise
$table = Database::get_course_table(TABLE_QUIZ_TEST);
$condition = '';
if (!empty($session_id)) {
$condition = api_get_session_condition($session_id);
$sql = "SELECT iid FROM {$table}
WHERE c_id = {$course_id} AND autolaunch = 1 {$condition}
LIMIT 1";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$row = Database::fetch_array($result);
$exerciseId = $row['iid'];
$url = api_get_path(WEB_CODE_PATH).
'exercise/overview.php?exerciseId='.$exerciseId.'&'.api_get_cidreq();
header(\sprintf('Location: %s', $url));
exit;
// If we found nothing in the session we just called the session_id = 0 autolaunch
if (0 === Database::num_rows($result)) {
$condition = '';
}
}
$sql = "SELECT iid FROM {$table}
WHERE c_id = {$course_id} AND autolaunch = 1 {$condition}
LIMIT 1";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$row = Database::fetch_array($result);
$exerciseId = $row['iid'];
$url = api_get_path(WEB_CODE_PATH).
'exercise/overview.php?exerciseId='.$exerciseId.'&'.api_get_cidreq();
header(\sprintf('Location: %s', $url));
exit;
}
}
}

@ -91,7 +91,6 @@ class PlatformConfigurationController extends AbstractController
'document.students_download_folders',
'social.hide_social_groups_block',
'course.show_course_duration',
'exercise.allow_exercise_auto_launch',
];
$user = $this->userHelper->getCurrent();

@ -2403,11 +2403,6 @@ class SettingsCurrentFixtures extends Fixture implements FixtureGroupInterface
'title' => 'Allow teachers to edit tests in learning paths',
'comment' => 'By default, Chamilo prevents you from editing tests that are included inside a learning path. This is to avoid changes that would affect learners (past and future) differently regarding the results and/or progress in the learning path. This option allows teachers to bypass this restriction.',
],
[
'name' => 'allow_exercise_auto_launch',
'title' => 'Allow tests auto-launch',
'comment' => 'The auto-launch feature allows the teacher to set an exercise to open immediately upon accessing the course homepage. Enable this option and click on the rocket icon in the list of tests to enable.',
],
[
'name' => 'allow_exercise_categories',
'title' => 'Enable test categories',

@ -44,7 +44,6 @@ class ExerciseSettingsSchema extends AbstractSettingsSchema
'hide_free_question_score' => 'false',
'hide_user_info_in_quiz_result' => 'false',
'exercise_attempts_report_show_username' => 'false',
'allow_exercise_auto_launch' => 'false',
'disable_clean_exercise_results_for_teachers' => 'true',
'show_exercise_question_certainty_ribbon_result' => 'false',
'quiz_results_answers_report' => 'false',
@ -121,7 +120,6 @@ class ExerciseSettingsSchema extends AbstractSettingsSchema
->add('hide_free_question_score', YesNoType::class)
->add('hide_user_info_in_quiz_result', YesNoType::class)
->add('exercise_attempts_report_show_username', YesNoType::class)
->add('allow_exercise_auto_launch', YesNoType::class)
->add('disable_clean_exercise_results_for_teachers', YesNoType::class)
->add('show_exercise_question_certainty_ribbon_result', YesNoType::class)
->add('quiz_results_answers_report', YesNoType::class)

Loading…
Cancel
Save