Quiz: Allow swap multiple answer dropdown to multiple answer - refs BT#20086

pull/4360/head
Angel Fernando Quiroz Campos 3 years ago
parent 1a17ae8517
commit 3cb50ada4c
  1. 2
      main/exercise/MultipleAnswerDropdown.php
  2. 6
      main/exercise/admin.php
  3. 21
      main/exercise/question.class.php

@ -52,7 +52,7 @@ class MultipleAnswerDropdown extends Question
$form->addGroup($buttonGroup);
if (!empty($this->iid) && !$form->isSubmitted()) {
if (!empty($this->iid)) {
$objAnswer = new Answer($this->iid, 0, $exercise, false);
$optionData = array_column(
$objAnswer->getAnswers(),

@ -101,8 +101,10 @@ Event::delete_all_incomplete_attempts(
$objExercise = Session::read('objExercise');
$objQuestion = Session::read('objQuestion');
if (isset($_REQUEST['convertAnswer'])) {
$objQuestion = $objQuestion->swapSimpleAnswerTypes();
if (isset($_REQUEST['convertAnswer']) || isset($_REQUEST['convertAnswerAlt'])) {
$objQuestion = $objQuestion->swapSimpleAnswerTypes(
isset($_REQUEST['convertAnswerAlt']) ? 1 : 0
);
Session::write('objQuestion', $objQuestion);
}
$objAnswer = Session::read('objAnswer');

@ -1821,6 +1821,7 @@ abstract class Question
global $text;
switch ($this->type) {
case UNIQUE_ANSWER:
case MULTIPLE_ANSWER_DROPDOWN:
$buttonGroup = [];
$buttonGroup[] = $form->addButtonSave(
$text,
@ -1856,6 +1857,16 @@ abstract class Question
null,
true
);
$buttonGroup[] = $form->addButton(
'convertAnswerAlt',
get_lang('ConvertToMultipleAnswerDropdown'),
'check-square-o',
'default',
null,
null,
null,
true
);
$form->addGroup($buttonGroup);
break;
}
@ -2550,13 +2561,14 @@ abstract class Question
*
* @return UniqueAnswer|MultipleAnswer
*/
public function swapSimpleAnswerTypes()
public function swapSimpleAnswerTypes($index = 0)
{
$oppositeAnswers = [
UNIQUE_ANSWER => MULTIPLE_ANSWER,
MULTIPLE_ANSWER => UNIQUE_ANSWER,
UNIQUE_ANSWER => [MULTIPLE_ANSWER],
MULTIPLE_ANSWER => [UNIQUE_ANSWER, MULTIPLE_ANSWER_DROPDOWN],
MULTIPLE_ANSWER_DROPDOWN => [MULTIPLE_ANSWER],
];
$this->type = $oppositeAnswers[$this->type];
$this->type = $oppositeAnswers[$this->type][$index];
Database::update(
Database::get_course_table(TABLE_QUIZ_QUESTION),
['type' => $this->type],
@ -2565,6 +2577,7 @@ abstract class Question
$answerClasses = [
UNIQUE_ANSWER => 'UniqueAnswer',
MULTIPLE_ANSWER => 'MultipleAnswer',
MULTIPLE_ANSWER_DROPDOWN => 'MultipleAnswerDropdown',
];
$swappedAnswer = new $answerClasses[$this->type]();
foreach ($this as $key => $value) {

Loading…
Cancel
Save