From 1f68292b9065b2ffcf3aa44434db51bc056bb42f Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Thu, 4 May 2017 18:09:31 -0500 Subject: [PATCH] Add option to display draggable question like with vertical orientation - refs BT#12625 --- app/Resources/public/css/base.css | 4 +++- main/exercise/Draggable.php | 10 +++++++++ main/exercise/exercise.class.php | 2 +- main/inc/lib/exercise.lib.php | 35 +++++++++++++++++-------------- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/app/Resources/public/css/base.css b/app/Resources/public/css/base.css index b27704f13f..b243435761 100644 --- a/app/Resources/public/css/base.css +++ b/app/Resources/public/css/base.css @@ -4191,9 +4191,11 @@ ul.holder li.bit-box{ min-height: 2em; min-width: 100%; } +ul.exercise-draggable-answer.list-inline li { + float: left; +} ul.exercise-draggable-answer li { cursor: move; - float: left; margin: 0 20px 20px 0; padding: 5px 20px; text-align: center; diff --git a/main/exercise/Draggable.php b/main/exercise/Draggable.php index f5ea77177e..9b0fe78f11 100644 --- a/main/exercise/Draggable.php +++ b/main/exercise/Draggable.php @@ -52,6 +52,8 @@ class Draggable extends Question $nb_options++; } } else if (!empty($this->id)) { + $defaults['orientation'] = in_array($this->extra, ['h', 'v']) ? $this->extra : 'h'; + $answer = new Answer($this->id); $answer->read(); @@ -76,6 +78,7 @@ class Draggable extends Question $defaults['matches[2]'] = '2'; $defaults['option[1]'] = get_lang('DefaultMatchingOptA'); $defaults['option[2]'] = get_lang('DefaultMatchingOptB'); + $defaults['orientation'] = 'h'; } for ($i = 1; $i <= $nb_matches; ++$i) { @@ -85,6 +88,12 @@ class Draggable extends Question $form->addElement('hidden', 'nb_matches', $nb_matches); $form->addElement('hidden', 'nb_options', $nb_options); + $form->addRadio( + 'orientation', + get_lang('Orientation'), + ['h' => get_lang('Horizontal'), 'v' => get_lang('Vertical')] + ); + // DISPLAY MATCHES $html = ' @@ -168,6 +177,7 @@ class Draggable extends Question */ public function processAnswersCreation($form) { + $this->extra = $form->exportValue('orientation'); $nb_matches = $form->getSubmitValue('nb_matches'); $this->weighting = 0; $position = 0; diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index e721c42821..6ed78505ca 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -3199,7 +3199,7 @@ class Exercise $totalScore = 0; // Extra information of the question - if (!empty($extra)) { + if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE && !empty($extra)) { $extra = explode(':', $extra); if ($debug) { error_log(print_r($extra, 1)); diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 21536bb64f..b88ca279c5 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -113,9 +113,11 @@ class ExerciseLib $num_suggestions = 0; if (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) { if ($answerType == DRAGGABLE) { + $isVertical = $objQuestionTmp->extra == 'v'; + $s .= '
-
    '; +
      '; } else { $s .= '
'; @@ -1097,31 +1099,32 @@ HTML; } if ($answerType == DRAGGABLE) { + $isVertical = $objQuestionTmp->extra == 'v'; + $s .= ""; $s .= ""; //clearfix $counterAnswer = 1; - $s .= '
'; + + $s .= $isVertical ? '' : '
'; + for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { $answerCorrect = $objAnswerTmp->isCorrect($answerId); $windowId = $questionId . '_' . $counterAnswer; if ($answerCorrect) { - $s .= Display::div( - Display::div( - ' ', - [ - 'id' => "drop_$windowId", - 'class' => 'droppable', - ] - ), - [ - 'class' => 'col-md-3', - ] - ); + $s .= $isVertical ? '
' : ''; + $s .= ' +
+
 
+
+ '; + $s .= $isVertical ? '
' : ''; + $counterAnswer++; } } - $s .= '
'; // row - $s .= '
'; // col-md-12 + + $s .= $isVertical ? '' : '
'; // row +// $s .= ''; // col-md-12 $s .= ''; // col-md-12 ui-widget ui-helper-clearfix }