Admin: add config setting "quiz_prevent_backwards_move" #3100

Requires DB change.
Exercises: Prevent going back to previous questions
pull/3103/head
Julio 6 years ago
parent 841eae7c6f
commit 9486bad7f2
  1. 33
      main/exercise/exercise.class.php
  2. 4
      main/exercise/exercise_admin.php
  3. 15
      main/exercise/exercise_submit.php
  4. 4
      main/install/configuration.dist.php

@ -89,6 +89,7 @@ class Exercise
public $autolaunch;
public $exerciseCategoryId;
public $pageResultConfiguration;
public $preventBackwards;
/**
* Constructor of the class.
@ -129,6 +130,7 @@ class Exercise
$this->notifications = [];
$this->exerciseCategoryId = null;
$this->pageResultConfiguration;
$this->preventBackwards = 0;
if (!empty($courseId)) {
$courseInfo = api_get_course_info_by_id($courseId);
@ -201,6 +203,7 @@ class Exercise
$this->hideQuestionTitle = isset($object->hide_question_title) ? (int) $object->hide_question_title : 0;
$this->autolaunch = isset($object->autolaunch) ? (int) $object->autolaunch : 0;
$this->exerciseCategoryId = isset($object->exercise_category_id) ? (int) $object->exercise_category_id : null;
$this->preventBackwards = isset($object->prevent_backwards) ? (int) $object->prevent_backwards : 0;
$this->notifications = [];
if (!empty($object->notifications)) {
@ -1588,6 +1591,10 @@ class Exercise
$paramsExtra['show_previous_button'] = $this->showPreviousButton();
}
if (api_get_configuration_value('quiz_prevent_backwards_move')) {
$paramsExtra['prevent_backwards'] = $this->getPreventBackwards();
}
$allow = api_get_configuration_value('allow_exercise_categories');
if ($allow === true) {
if (!empty($this->getExerciseCategoryId())) {
@ -1678,6 +1685,10 @@ class Exercise
}
}
if (api_get_configuration_value('quiz_prevent_backwards_move')) {
$params['prevent_backwards'] = $this->getPreventBackwards();
}
$allow = api_get_configuration_value('allow_quiz_show_previous_button_setting');
if ($allow === true) {
$params['show_previous_button'] = $this->showPreviousButton();
@ -2372,6 +2383,14 @@ class Exercise
get_lang('UpdateTitleInLps')
);
if (api_get_configuration_value('quiz_prevent_backwards_move')) {
$form->addCheckBox(
'prevent_backwards',
null,
get_lang('QuizPreventBackwards')
);
}
$defaults = [];
if (api_get_setting('search_enabled') === 'true') {
require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
@ -2451,6 +2470,7 @@ class Exercise
$defaults['hide_question_title'] = $this->getHideQuestionTitle();
$defaults['show_previous_button'] = $this->showPreviousButton();
$defaults['exercise_category_id'] = $this->getExerciseCategoryId();
$defaults['prevent_backwards'] = $this->getPreventBackwards();
if (!empty($this->start_time)) {
$defaults['activate_start_date_check'] = 1;
@ -2632,6 +2652,7 @@ class Exercise
$this->setNotifications($form->getSubmitValue('notifications'));
$this->setExerciseCategoryId($form->getSubmitValue('exercise_category_id'));
$this->setPageResultConfiguration($form->getSubmitValues());
$this->preventBackwards = (int) $form->getSubmitValue('prevent_backwards');
$this->start_time = null;
if ($form->getSubmitValue('activate_start_date_check') == 1) {
@ -3224,7 +3245,7 @@ class Exercise
}
}
if ($showPreview) {
if ($showPreview && 0 === $this->getPreventBackwards()) {
$buttonList[] = Display::button(
'previous_question_and_save',
get_lang('PreviousQuestion'),
@ -7941,6 +7962,16 @@ class Exercise
return $this->showPreviousButton;
}
public function getPreventBackwards()
{
$allow = api_get_configuration_value('quiz_prevent_backwards_move');
if ($allow === false) {
return 0;
}
return (int) $this->preventBackwards;
}
/**
* @return int
*/

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
@ -7,9 +8,6 @@ use ChamiloSession as Session;
* Exercise administration
* This script allows to manage an exercise. It is included from
* the script admin.php.
*
* @package chamilo.exercise
*
* @author Olivier Brouckaert, Julio Montoya
*/
require_once __DIR__.'/../inc/global.inc.php';

@ -43,7 +43,7 @@ $sessionId = api_get_session_id();
$glossaryExtraTools = api_get_setting('show_glossary_in_extra_tools');
$showGlossary = in_array($glossaryExtraTools, ['true', 'exercise', 'exercise_and_lp']);
if ($origin == 'learnpath') {
if ($origin === 'learnpath') {
$showGlossary = in_array($glossaryExtraTools, ['true', 'lp', 'exercise_and_lp']);
}
if ($showGlossary) {
@ -122,7 +122,7 @@ if (api_is_allowed_to_edit(null, true) &&
// 1. Loading the $objExercise variable
/** @var \Exercise $exerciseInSession */
$exerciseInSession = Session::read('objExercise');
if (!isset($exerciseInSession) || isset($exerciseInSession) && ($exerciseInSession->id != $_GET['exerciseId'])) {
if (empty($exerciseInSession) || (!empty($exerciseInSession) && ($exerciseInSession->id != $_GET['exerciseId']))) {
// Construction of Exercise
$objExercise = new Exercise($courseId);
Session::write('firstTime', true);
@ -159,6 +159,8 @@ if (!isset($objExercise) && isset($exerciseInSession)) {
$objExercise = $exerciseInSession;
}
$exerciseInSession = Session::read('objExercise');
//3. $objExercise is not set, then return to the exercise list
if (!is_object($objExercise)) {
if ($debug) {
@ -1406,6 +1408,15 @@ if (!empty($error)) {
break;
}
}
if (1 === $exerciseInSession->getPreventBackwards()) {
if (isset($attempt_list[$questionId])) {
echo Display::return_message(get_lang('AlreadyAnswered'));
$i++;
break;
}
}
}
}

@ -1391,6 +1391,10 @@ ALTER TABLE notification_event ADD COLUMN event_id INT NULL;
// Show online user only to Administrators
//$_configuration['whoisonline_only_for_admin'] = false;
// Prevent going back to previous questions
// ALTER TABLE c_quiz ADD COLUMN prevent_backwards INT DEFAULT 0;
//$_configuration['quiz_prevent_backwards_move'] = false;
// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email

Loading…
Cancel
Save