Skip to content

Commit

Permalink
Allow solve Matching Draggable answer - refs #7611
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Apr 28, 2015
1 parent 108e619 commit 09c5864
Show file tree
Hide file tree
Showing 7 changed files with 328 additions and 12 deletions.
24 changes: 24 additions & 0 deletions main/css/base.css
Expand Up @@ -5930,3 +5930,27 @@ ul.exercise-draggable-answer li {
.question_options .droppable .gallery .exercise-draggable-answer-option {
margin-bottom: 15px;
}

/*** Matching Draggable answer ***/
.drag_question {
float: left;
min-height: 4em;
width: 100%;
}
.drag_question .window{
box-shadow: 2px 2px 19px #AAA;
cursor: pointer;
min-height: 65px;
padding-top: 25px;
}
.window_left_question {
padding: 10px 25px 10px 10px;
text-align: right;
}
.window_right_question {
padding: 10px 10px 10px 25px;
}

._jsPlumb_endpoint {
z-index: 50;
}
16 changes: 16 additions & 0 deletions main/exercice/answer.class.php
Expand Up @@ -759,4 +759,20 @@ public function duplicate($newQuestionId, $course_info = null)
}
}
}

/**
* Get the necessary JavaScript for some ansers
* @return string
*/
public function getJs() {
//if ($this->questionId == 2)
return "<script>
jsPlumb.ready(function() {
if ($('#drag{$this->questionId}_question').length > 0) {
MatchingDraggable.init('{$this->questionId}');
}
});
</script>";
}

}
2 changes: 1 addition & 1 deletion main/exercice/exercise_show.php
Expand Up @@ -343,7 +343,7 @@ function getFCK(vals,marksid) {
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
} elseif (in_array($answerType, [MATCHING, DRAGGABLE])) {
} elseif (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) {
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
Expand Down
7 changes: 7 additions & 0 deletions main/exercice/exercise_submit.php
Expand Up @@ -50,6 +50,13 @@
$htmlHeadXtra[] = api_get_js('jquery.highlight.js');
}

$htmlHeadXtra[] = '<script src="'
. api_get_path(WEB_PATH) . 'web/assets/jsplumb/dist/js/jquery.jsPlumb-1.7.5-min.js'
. '"></script>';
$htmlHeadXtra[] = '<script src="'
. api_get_path(WEB_PATH) . 'web/assets/xcolor/jquery.xcolor.min.js'
. '"></script>';

//This library is necessary for the time control feature
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/stylesheet/jquery.epiclock.css');
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css');
Expand Down
6 changes: 3 additions & 3 deletions main/inc/lib/display.lib.php
Expand Up @@ -954,7 +954,7 @@ public static function select(
if ($key == 'id') {
$default_id = '';
}
$extra .= $key.'="'.$parameter.'"';
$extra .= $key.'="'.$parameter.'" ';
}
$html .= '<select name="'.$name.'" '.$default_id.' '.$extra.'>';

Expand All @@ -976,13 +976,13 @@ public static function select(
if (is_array($default)) {
foreach($default as $item) {
if ($item == $key) {
$html .= 'selected="selected"';
$html .= ' selected="selected"';
break;
}
}
} else {
if ($default == $key) {
$html .= 'selected="selected"';
$html .= ' selected="selected"';
}
}

Expand Down
137 changes: 129 additions & 8 deletions main/inc/lib/exercise.lib.php
Expand Up @@ -104,13 +104,16 @@ public static function showQuestion(
// on the right side are called answers
$num_suggestions = 0;

if (in_array($answerType, [MATCHING, DRAGGABLE])) {
if (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) {
if ($answerType == DRAGGABLE) {
$s .= '<div class="ui-widget ui-helper-clearfix">
<div class="clearfix">
<ul class="exercise-draggable-answer ui-helper-reset ui-helper-clearfix">';
} else {
$s .= '<table class="table table-hover table-striped">';
$s .= <<<HTML
<div id="drag{$questionId}_question" class="drag_question">
<table class="data_table">
HTML;
}
// Iterate through answers
$x = 1;
Expand Down Expand Up @@ -1002,17 +1005,129 @@ public static function showQuestion(

$s .= '</li>';
}
} elseif ($answerType == MATCHING_DRAGGABLE) {
if ($answerId == 1) {
echo $objAnswerTmp->getJs();
}

if ($answerCorrect != 0) {
$parsed_answer = $answer;
$windowId = "{$questionId}_{$lines_count}";

$s .= <<<HTML
<tr>
<td widht="45%">
<div id="window_{$windowId}" class="window window_left_question window{$questionId}_question">
<strong>$lines_count.</strong> $parsed_answer
</div>
</td>
<td width="10%">
HTML;
$selectedValue = 0;
$questionOptions = [];

foreach ($select_items as $key => $val) {
if ($debug_mark_answer) {
if ($val['id'] == $answerCorrect) {
$selectedValue = $val['id'];
}
}

if (
isset($user_choice[$matching_correct_answer]) &&
$val['id'] == $user_choice[$matching_correct_answer]['answer']
) {
$selectedValue = $val['id'];
}

$questionOptions[$val['id']] = $val['letter'];
}

$s .= Display::select(
"choice[$questionId][$numAnswer]",
$questionOptions,
$selectedValue,
[
'id' => "window_{$windowId}_select",
'class' => 'hidden'
],
false
);

if (!empty($answerCorrect) && !empty($selectedValue)) {
$s .= <<<JAVASCRIPT
<script>
jsPlumb.ready(function() {
jsPlumb.connect({
source: 'window_$windowId',
target: 'window_{$questionId}_{$selectedValue}_answer',
endpoint: ['Blank', {radius: 15}],
anchors: ['RightMiddle', 'LeftMiddle'],
paintStyle: {strokeStyle: '#8A8888', lineWidth: 8},
connector: [
MatchingDraggable.connectorType,
{curvines: MatchingDraggable.curviness}
]
});
});
</script>
JAVASCRIPT;
}

$s .= <<<HTML
</td>
<td width="45%">
HTML;

if (isset($select_items[$lines_count])) {
$s .= <<<HTML
<div id="window_{$windowId}_answer" class="window window_right_question">
<strong>{$select_items[$lines_count]['letter']}.</strong> {$select_items[$lines_count]['answer']}
</div>
HTML;
} else {
$s .= '&nbsp;';
}

$s .= '</td></tr>';

$lines_count++;

if (($lines_count - 1) == $num_suggestions) {
while (isset($select_items[$lines_count])) {
$s .= <<<HTML
<tr>
<td colspan="2"></td>
<td>
<strong>{$select_items[$lines_count]['letter']}</strong>
$select_items[$lines_count]['answer']
</td>
</tr>
HTML;
$lines_count++;
}
}

$matching_correct_answer++;
}
}
} // end for()

if ($show_comment) {
$s .= '</table>';
} else {
if ($answerType == MATCHING || $answerType == UNIQUE_ANSWER_NO_OPTION || $answerType == MULTIPLE_ANSWER_TRUE_FALSE ||
$answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE
) {
} elseif(
in_array(
$answerType,
[
MATCHING,
MATCHING_DRAGGABLE,
UNIQUE_ANSWER_NO_OPTION,
MULTIPLE_ANSWER_TRUE_FALSE,
MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE
]
)
) {
$s .= '</table>';
}
}

if ($answerType == DRAGGABLE) {
Expand Down Expand Up @@ -1042,7 +1157,7 @@ public static function showQuestion(
$s .= '</div></div>';
}

if ($answerType == MATCHING) {
if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) {
$s .= '</div>';
}

Expand Down Expand Up @@ -3106,6 +3221,9 @@ public static function get_number_students_answer_count(
$select_condition = " e.exe_id, answer ";
break;
case MATCHING:
//no break
case MATCHING_DRAGGABLE:
//no break
default:
$answer_condition = " answer = $answer_id AND ";
$select_condition = " DISTINCT exe_user_id ";
Expand Down Expand Up @@ -3161,6 +3279,9 @@ public static function get_number_students_answer_count(
return $good_answers;
break;
case MATCHING:
//no break
case MATCHING_DRAGGABLE:
//no break
default:
$return = Database::num_rows($result);
}
Expand Down

0 comments on commit 09c5864

Please sign in to comment.