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); $form->addGroup($buttonGroup);
if (!empty($this->iid) && !$form->isSubmitted()) { if (!empty($this->iid)) {
$objAnswer = new Answer($this->iid, 0, $exercise, false); $objAnswer = new Answer($this->iid, 0, $exercise, false);
$optionData = array_column( $optionData = array_column(
$objAnswer->getAnswers(), $objAnswer->getAnswers(),

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

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

Loading…
Cancel
Save