Exercise: Added configuration to show or hide the question number in exercises - refs BT#18450

pull/3825/head
Carlos Alvarado 5 years ago
parent a6bf491dd9
commit 312d370af4
No known key found for this signature in database
GPG Key ID: B612DB1EE6658FBB
  1. 78
      main/exercise/exercise.class.php
  2. 44
      main/exercise/question.class.php
  3. 4
      main/install/configuration.dist.php

@ -90,6 +90,7 @@ class Exercise
public $autolaunch;
public $exerciseCategoryId;
public $pageResultConfiguration;
public $hideQuestionNumber;
public $preventBackwards;
public $currentQuestion;
public $hideComment;
@ -137,6 +138,7 @@ class Exercise
$this->notifications = [];
$this->exerciseCategoryId = null;
$this->pageResultConfiguration;
$this->hideQuestionNumber = 0;
$this->preventBackwards = 0;
$this->hideComment = false;
$this->hideNoAnswer = false;
@ -225,6 +227,10 @@ class Exercise
$this->pageResultConfiguration = $object->page_result_configuration;
}
if (!empty($object->hide_question_number)) {
$this->hideQuestionNumber = $object->hide_question_number;
}
if (isset($object->show_previous_button)) {
$this->showPreviousButton = $object->show_previous_button == 1 ? true : false;
}
@ -1676,6 +1682,11 @@ class Exercise
}
}
$showHideConfiguration = api_get_configuration_value('hide_question_number');
if ($showHideConfiguration ) {
$paramsExtra['hide_question_number'] = $this->hideQuestionNumber;
}
$params = array_merge($params, $paramsExtra);
Database::update(
@ -1769,6 +1780,10 @@ class Exercise
if ($pageConfig && !empty($this->pageResultConfiguration)) {
$params['page_result_configuration'] = $this->pageResultConfiguration;
}
$showHideConfiguration = api_get_configuration_value('hide_question_number');
if ( $showHideConfiguration ) {
$params['hide_question_number'] = $this->hideQuestionNumber;
}
$this->id = $this->iId = Database::insert($TBL_EXERCISES, $params);
@ -2217,6 +2232,14 @@ class Exercise
];
$form->addGroup($group, null, get_lang('ResultsConfigurationPage'));
}
$showHide = api_get_configuration_value('hide_question_number');
if ( $showHideConfiguration ) {
$group = [
$form->createElement('radio', 'hide_question_number', null, get_lang('Yes'), '1'),
$form->createElement('radio', 'hide_question_number', null, get_lang('No'), '0'),
];
$form->addGroup($group, null, get_lang('HideQuestionNumber'));
}
$displayMatrix = 'none';
$displayRandom = 'none';
@ -2600,6 +2623,7 @@ class Exercise
}
$this->setPageResultConfigurationDefaults($defaults);
$this->setHideQuestionNumberDefaults($defaults);
$form->setDefaults($defaults);
// Freeze some elements.
@ -2769,6 +2793,7 @@ class Exercise
$this->setNotifications($form->getSubmitValue('notifications'));
$this->setExerciseCategoryId($form->getSubmitValue('exercise_category_id'));
$this->setPageResultConfiguration($form->getSubmitValues());
$this->setHideShowQuestionNumber($form->getSubmitValue('hide_question_number'));
$this->preventBackwards = (int) $form->getSubmitValue('prevent_backwards');
$this->start_time = null;
@ -8339,6 +8364,31 @@ class Exercise
}
}
/**
* Set the value to hide or show the question number
*
* @param int $value
*/
public function setHideShowQuestionNumber($value = 0){
$showHideConfiguration = api_get_configuration_value('hide_question_number');
if ($showHideConfiguration) {
$this->hideQuestionNumber = (int) $value ;
}
}
/**
* Gets the value to hide or show the question number. If it does not exist, it is set to 0
*
* @return int
*/
public function getHideShowQuestionNumber(){
$showHideConfiguration = api_get_configuration_value('hide_question_number');
if ($showHideConfiguration) {
return (int) $this->hideQuestionNumber;
}
return 0;
}
/**
* @param array $values
*/
@ -8370,6 +8420,19 @@ class Exercise
}
}
/**
* Sets the value to show or hide the question number in the default settings of the forms
*
* @param array $defaults
*/
public function setHideQuestionNumberDefaults(&$defaults)
{
$configuration = $this->getHideQuestionNumberConfiguration();
if (!empty($configuration) && !empty($defaults)) {
$defaults = array_merge($defaults, $configuration);
}
}
/**
* @return array
*/
@ -8386,6 +8449,21 @@ class Exercise
return [];
}
/**
* Get the value to show or hide the question number in the default settings of the forms
*
* @return array
*/
public function getHideQuestionNumberConfiguration()
{
$pageConfig = api_get_configuration_value('hide_question_number');
if ($pageConfig) {
return ['hide_question_number'=>$this->hideQuestionNumber];
}
return [];
}
/**
* @param string $attribute
*

@ -253,7 +253,12 @@ abstract class Question
}
$title .= $showQuestionTitleHtml ? '' : '<strong>';
$title .= $itemNumber.'. '.$this->selectTitle();
$checkIfShowNumberQuestion = $this->getShowHideConfiguration();
if ($checkIfShowNumberQuestion != 1) {
$title .= $itemNumber.'. ';
}
$title .= $this->selectTitle();
$title .= $showQuestionTitleHtml ? '' : '</strong>';
return Display::div(
@ -262,6 +267,43 @@ abstract class Question
);
}
/**
* Gets the respective value to show or hide the number of a question in the exam.
* If the field does not exist in the database, it will return 0.
*
* @return int
*/
public function getShowHideConfiguration()
{
$tblQuiz = Database::get_course_table(TABLE_QUIZ_TEST);
$tblQuizRelQuestion = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$showHideConfiguration = api_get_configuration_value('hide_question_number');
if (!$showHideConfiguration) return 0;
// Check if the field exist
$checkFieldSql = "SHOW COLUMNS FROM $tblQuiz WHERE Field = 'hide_question_number'";
$res = Database::query($checkFieldSql);
$result = Database::store_result($res);
if (count($result) != 0) {
$sql = "
SELECT
q.hide_question_number AS `active`
FROM
$tblQuiz as q
INNER JOIN $tblQuizRelQuestion AS qrq ON qrq.exercice_id = q.id
WHERE qrq.question_id = ".$this->id;
$res = Database::query($sql);
$result = Database::store_result($res);
if (is_array($result) &&
isset($result[0]) &&
isset($result[0]['active'])
) {
return (int)$result[0]['active'];
}
}
return 0;
}
/**
* returns the question description.
*

@ -1304,6 +1304,10 @@ $_configuration['required_extra_fields_in_profile'] = [
// ALTER TABLE c_quiz ADD page_result_configuration LONGTEXT DEFAULT NULL COMMENT '(DC2Type:array)';
//$_configuration['allow_quiz_results_page_config'] = false;
// Allows you to show or hide the number of the question in the exercises
// ALTER TABLE `c_quiz` ADD COLUMN `hide_question_number` int(0) NULL DEFAULT 0 COMMENT 'Show/Hide question number in quiz' ;
//$_configuration['hide_question_number'] = false;
// Allow multiple options for the exercise "save answer" option
// ALTER TABLE c_quiz MODIFY COLUMN save_correct_answers INT NULL DEFAULT NULL;
//$_configuration['allow_quiz_save_correct_options'] = false;

Loading…
Cancel
Save