Skip to content

Commit

Permalink
Add Setting "allow_quiz_show_previous_button_setting" see BT#13001
Browse files Browse the repository at this point in the history
Requires DB change:

ALTER TABLE c_quiz ADD show_previous_button TINYINT(1) DEFAULT 1;
  • Loading branch information
jmontoyaa committed Jun 29, 2017
1 parent 03eb860 commit a55b7b9
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 21 deletions.
124 changes: 103 additions & 21 deletions main/exercise/exercise.class.php
Expand Up @@ -76,6 +76,7 @@ class Exercise
public $sessionId = 0;
public $questionFeedbackEnabled = false;
public $questionTypeWithFeedback;
public $showPreviousButton;

/**
* Constructor of the class
Expand Down Expand Up @@ -121,6 +122,7 @@ public function __construct($courseId = 0)

// ALTER TABLE c_quiz_question ADD COLUMN feedback text;
$this->questionFeedbackEnabled = api_get_configuration_value('allow_quiz_question_feedback');
$this->showPreviousButton = true;
}

/**
Expand All @@ -134,14 +136,14 @@ public function __construct($courseId = 0)
*/
public function read($id, $parseQuestionList = true)
{
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$table_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$table = Database::get_course_table(TABLE_QUIZ_TEST);
$tableLpItem = Database::get_course_table(TABLE_LP_ITEM);

$id = (int) $id;
if (empty($this->course_id)) {
return false;
}
$sql = "SELECT * FROM $TBL_EXERCISES
$sql = "SELECT * FROM $table
WHERE c_id = ".$this->course_id." AND id = ".$id;
$result = Database::query($sql);

Expand Down Expand Up @@ -176,11 +178,16 @@ public function read($id, $parseQuestionList = true)
$this->questionSelectionType = isset($object->question_selection_type) ? $object->question_selection_type : null;
$this->hideQuestionTitle = isset($object->hide_question_title) ? (int) $object->hide_question_title : 0;

if (isset($object->show_previous_button)) {
$this->showPreviousButton = $object->show_previous_button == 1 ? true : false;
}

$sql = "SELECT lp_id, max_score
FROM $table_lp_item
WHERE c_id = {$this->course_id} AND
item_type = '".TOOL_QUIZ."' AND
path = '".$id."'";
FROM $tableLpItem
WHERE
c_id = {$this->course_id} AND
item_type = '".TOOL_QUIZ."' AND
path = '".$id."'";
$result = Database::query($sql);

if (Database::num_rows($result) > 0) {
Expand Down Expand Up @@ -1607,6 +1614,11 @@ public function save($type_e = '')
'question_selection_type' => $this->getQuestionSelectionType(),
'hide_question_title' => $this->getHideQuestionTitle()
];

$allow = api_get_configuration_value('allow_quiz_show_previous_button_setting');
if ($allow === true) {
$paramsExtra['show_previous_button'] = $this->showPreviousButton();
}
}

$params = array_merge($params, $paramsExtra);
Expand Down Expand Up @@ -2163,6 +2175,29 @@ public function createForm($form, $type = 'full')
);
$form->addGroup($group, null, get_lang('HideQuestionTitle'));

$allow = api_get_configuration_value('allow_quiz_show_previous_button_setting');

if ($allow === true) {
// Hide question title.
$group = array(
$form->createElement(
'radio',
'show_previous_button',
null,
get_lang('Yes'),
'1'
),
$form->createElement(
'radio',
'show_previous_button',
null,
get_lang('No'),
'0'
)
);
$form->addGroup($group, null, get_lang('ShowPreviousButton'));
}

// Attempts
$attempt_option = range(0, 10);
$attempt_option[0] = get_lang('Infinite');
Expand All @@ -2176,7 +2211,13 @@ public function createForm($form, $type = 'full')
);

// Exercise time limit
$form->addElement('checkbox', 'activate_start_date_check', null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()'));
$form->addElement(
'checkbox',
'activate_start_date_check',
null,
get_lang('EnableStartTime'),
array('onclick' => 'activate_start_date()')
);

$var = self::selectTimeLimit();

Expand All @@ -2188,7 +2229,13 @@ public function createForm($form, $type = 'full')

$form->addElement('date_time_picker', 'start_time');
$form->addElement('html', '</div>');
$form->addElement('checkbox', 'activate_end_date_check', null, get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()'));
$form->addElement(
'checkbox',
'activate_end_date_check',
null,
get_lang('EnableEndTime'),
array('onclick' => 'activate_end_date()')
);

if (!empty($this->end_time)) {
$form->addElement('html', '<div id="end_date_div" style="display:block;">');
Expand All @@ -2200,7 +2247,12 @@ public function createForm($form, $type = 'full')
$form->addElement('html', '</div>');

$display = 'block';
$form->addElement('checkbox', 'propagate_neg', null, get_lang('PropagateNegativeResults'));
$form->addElement(
'checkbox',
'propagate_neg',
null,
get_lang('PropagateNegativeResults')
);
$form->addCheckBox(
'save_correct_answers',
null,
Expand Down Expand Up @@ -2337,6 +2389,7 @@ public function createForm($form, $type = 'full')
$defaults['pass_percentage'] = $this->selectPassPercentage();
$defaults['question_selection_type'] = $this->getQuestionSelectionType();
$defaults['hide_question_title'] = $this->getHideQuestionTitle();
$defaults['show_previous_button'] = $this->showPreviousButton();

if (!empty($this->start_time)) {
$defaults['activate_start_date_check'] = 1;
Expand Down Expand Up @@ -2372,13 +2425,15 @@ public function createForm($form, $type = 'full')
$defaults['end_button'] = $this->selectEndButton();
$defaults['question_selection_type'] = 1;
$defaults['hide_question_title'] = 0;
$defaults['show_previous_button'] = 1;
$defaults['on_success_message'] = null;
$defaults['on_failed_message'] = null;
}
} else {
$defaults['exerciseTitle'] = $this->selectTitle();
$defaults['exerciseDescription'] = $this->selectDescription();
}

if (api_get_setting('search_enabled') === 'true') {
$defaults['index_document'] = 'checked="checked"';
}
Expand Down Expand Up @@ -2440,6 +2495,7 @@ public function processCreation($form, $type = '')
$this->setQuestionSelectionType($form->getSubmitValue('question_selection_type'));
$this->setScoreTypeModel($form->getSubmitValue('score_type_model'));
$this->setGlobalCategoryId($form->getSubmitValue('global_category_id'));
$this->setShowPreviousButton($form->getSubmitValue('show_previous_button'));

if ($form->getSubmitValue('activate_start_date_check') == 1) {
$start_time = $form->getSubmitValue('start_time');
Expand Down Expand Up @@ -2979,17 +3035,19 @@ public function show_button($question_id, $questionNum, $questions_in_media = ar
$class .= ' question-validate-btn'; // used to select it with jquery
if ($this->type == ONE_PER_PAGE) {
if ($questionNum != 1) {
$prev_question = $questionNum - 2;
$all_button[] = Display::button(
'previous_question_and_save',
get_lang('PreviousQuestion'),
[
'type' => 'button',
'class' => 'btn btn-default',
'data-prev' => $prev_question,
'data-question' => $question_id
]
);
if ($this->showPreviousButton()) {
$prev_question = $questionNum - 2;
$all_button[] = Display::button(
'previous_question_and_save',
get_lang('PreviousQuestion'),
[
'type' => 'button',
'class' => 'btn btn-default',
'data-prev' => $prev_question,
'data-question' => $question_id
]
);
}
}

//Next question
Expand Down Expand Up @@ -7529,4 +7587,28 @@ private function getUnformattedTitle()
{
return strip_tags(api_html_entity_decode($this->title));
}

/**
* @return bool
*/
public function showPreviousButton()
{
$allow = api_get_configuration_value('allow_quiz_show_previous_button_setting');
if ($allow === false) {
return true;
}

return $this->showPreviousButton;
}

/**
* @param bool $showPreviousButton
* @return Exercise
*/
public function setShowPreviousButton($showPreviousButton)
{
$this->showPreviousButton = $showPreviousButton;

return $this;
}
}
3 changes: 3 additions & 0 deletions main/install/configuration.dist.php
Expand Up @@ -497,3 +497,6 @@
'admin2@example.com',
]
];*/
// Add option in exercise to show or hide the "previous" button.
// ALTER TABLE c_quiz ADD show_previous_button TINYINT(1) DEFAULT 1;
//$_configuration['allow_quiz_show_previous_button_setting'] = false;

0 comments on commit a55b7b9

Please sign in to comment.