| Conditions | 220 |
| Paths | > 20000 |
| Total Lines | 1557 |
| Code Lines | 920 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php |
||
| 35 | public static function showQuestion( |
||
| 36 | $exercise, |
||
| 37 | $questionId, |
||
| 38 | $only_questions = false, |
||
| 39 | $origin = false, |
||
| 40 | $current_item = '', |
||
| 41 | $show_title = true, |
||
| 42 | $freeze = false, |
||
| 43 | $user_choice = [], |
||
| 44 | $show_comment = false, |
||
| 45 | $show_answers = false, |
||
| 46 | $show_icon = false |
||
| 47 | ) { |
||
| 48 | $course_id = empty($exercise->course_id) ? api_get_course_int_id() : $exercise->course_id; |
||
| 49 | $course = api_get_course_info_by_id($course_id); |
||
| 50 | // Change false to true in the following line to enable answer hinting |
||
| 51 | $debug_mark_answer = $show_answers; |
||
| 52 | // Reads question information |
||
| 53 | if (!$objQuestionTmp = Question::read($questionId)) { |
||
| 54 | // Question not found |
||
| 55 | return false; |
||
| 56 | } |
||
| 57 | |||
| 58 | if ($exercise->feedback_type != EXERCISE_FEEDBACK_TYPE_END) { |
||
| 59 | $show_comment = false; |
||
| 60 | } |
||
| 61 | |||
| 62 | $answerType = $objQuestionTmp->selectType(); |
||
| 63 | $pictureName = $objQuestionTmp->getPictureFilename(); |
||
| 64 | $s = ''; |
||
| 65 | if ($answerType != HOT_SPOT && |
||
| 66 | $answerType != HOT_SPOT_DELINEATION && |
||
| 67 | $answerType != ANNOTATION |
||
| 68 | ) { |
||
| 69 | // Question is not a hotspot |
||
| 70 | if (!$only_questions) { |
||
| 71 | $questionDescription = $objQuestionTmp->selectDescription(); |
||
| 72 | if ($show_title) { |
||
| 73 | if ($exercise->display_category_name) { |
||
| 74 | TestCategory::displayCategoryAndTitle($objQuestionTmp->id); |
||
| 75 | } |
||
| 76 | $titleToDisplay = $objQuestionTmp->getTitleToDisplay($current_item); |
||
| 77 | if ($answerType == READING_COMPREHENSION) { |
||
| 78 | // In READING_COMPREHENSION, the title of the question |
||
| 79 | // contains the question itself, which can only be |
||
| 80 | // shown at the end of the given time, so hide for now |
||
| 81 | $titleToDisplay = Display::div( |
||
| 82 | $current_item.'. '.get_lang('ReadingComprehension'), |
||
| 83 | ['class' => 'question_title'] |
||
| 84 | ); |
||
| 85 | } |
||
| 86 | echo $titleToDisplay; |
||
| 87 | } |
||
| 88 | if (!empty($questionDescription) && $answerType != READING_COMPREHENSION) { |
||
| 89 | echo Display::div( |
||
| 90 | $questionDescription, |
||
| 91 | ['class' => 'question_description'] |
||
| 92 | ); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | if (in_array($answerType, [FREE_ANSWER, ORAL_EXPRESSION]) && $freeze) { |
||
| 97 | return ''; |
||
| 98 | } |
||
| 99 | |||
| 100 | echo '<div class="question_options">'; |
||
| 101 | // construction of the Answer object (also gets all answers details) |
||
| 102 | $objAnswerTmp = new Answer($questionId, api_get_course_int_id(), $exercise); |
||
| 103 | $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); |
||
| 104 | $quizQuestionOptions = Question::readQuestionOption( |
||
| 105 | $questionId, |
||
| 106 | $course_id |
||
| 107 | ); |
||
| 108 | |||
| 109 | // For "matching" type here, we need something a little bit special |
||
| 110 | // because the match between the suggestions and the answers cannot be |
||
| 111 | // done easily (suggestions and answers are in the same table), so we |
||
| 112 | // have to go through answers first (elems with "correct" value to 0). |
||
| 113 | $select_items = []; |
||
| 114 | //This will contain the number of answers on the left side. We call them |
||
| 115 | // suggestions here, for the sake of comprehensions, while the ones |
||
| 116 | // on the right side are called answers |
||
| 117 | $num_suggestions = 0; |
||
| 118 | if (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) { |
||
| 119 | if ($answerType == DRAGGABLE) { |
||
| 120 | $isVertical = $objQuestionTmp->extra == 'v'; |
||
| 121 | $s .= ' |
||
| 122 | <div class="col-md-12 ui-widget ui-helper-clearfix"> |
||
| 123 | <div class="clearfix"> |
||
| 124 | <ul class="exercise-draggable-answer '.($isVertical ? '' : 'list-inline').'" |
||
| 125 | id="question-'.$questionId.'" data-question="'.$questionId.'"> |
||
| 126 | '; |
||
| 127 | } else { |
||
| 128 | $s .= '<div id="drag'.$questionId.'_question" class="drag_question"> |
||
| 129 | <table class="data_table">'; |
||
| 130 | } |
||
| 131 | |||
| 132 | // Iterate through answers |
||
| 133 | $x = 1; |
||
| 134 | //mark letters for each answer |
||
| 135 | $letter = 'A'; |
||
| 136 | $answer_matching = []; |
||
| 137 | $cpt1 = []; |
||
| 138 | for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { |
||
| 139 | $answerCorrect = $objAnswerTmp->isCorrect($answerId); |
||
| 140 | $numAnswer = $objAnswerTmp->selectAutoId($answerId); |
||
| 141 | if ($answerCorrect == 0) { |
||
| 142 | // options (A, B, C, ...) that will be put into the list-box |
||
| 143 | // have the "correct" field set to 0 because they are answer |
||
| 144 | $cpt1[$x] = $letter; |
||
| 145 | $answer_matching[$x] = $objAnswerTmp->selectAnswerByAutoId( |
||
| 146 | $numAnswer |
||
| 147 | ); |
||
| 148 | $x++; |
||
| 149 | $letter++; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | $i = 1; |
||
| 154 | $select_items[0]['id'] = 0; |
||
| 155 | $select_items[0]['letter'] = '--'; |
||
| 156 | $select_items[0]['answer'] = ''; |
||
| 157 | foreach ($answer_matching as $id => $value) { |
||
| 158 | $select_items[$i]['id'] = $value['id_auto']; |
||
| 159 | $select_items[$i]['letter'] = $cpt1[$id]; |
||
| 160 | $select_items[$i]['answer'] = $value['answer']; |
||
| 161 | $i++; |
||
| 162 | } |
||
| 163 | |||
| 164 | $user_choice_array_position = []; |
||
| 165 | if (!empty($user_choice)) { |
||
| 166 | foreach ($user_choice as $item) { |
||
| 167 | $user_choice_array_position[$item['position']] = $item['answer']; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | $num_suggestions = ($nbrAnswers - $x) + 1; |
||
| 171 | } elseif ($answerType == FREE_ANSWER) { |
||
| 172 | $fck_content = isset($user_choice[0]) && !empty($user_choice[0]['answer']) ? $user_choice[0]['answer'] : null; |
||
| 173 | $form = new FormValidator('free_choice_'.$questionId); |
||
| 174 | $config = [ |
||
| 175 | 'ToolbarSet' => 'TestFreeAnswer', |
||
| 176 | ]; |
||
| 177 | $form->addHtmlEditor( |
||
| 178 | "choice[".$questionId."]", |
||
| 179 | null, |
||
| 180 | false, |
||
| 181 | false, |
||
| 182 | $config |
||
| 183 | ); |
||
| 184 | $form->setDefaults(["choice[".$questionId."]" => $fck_content]); |
||
| 185 | $s .= $form->returnForm(); |
||
| 186 | } elseif ($answerType == ORAL_EXPRESSION) { |
||
| 187 | // Add nanog |
||
| 188 | if (api_get_setting('enable_record_audio') === 'true') { |
||
| 189 | //@todo pass this as a parameter |
||
| 190 | global $exercise_stat_info, $exerciseId; |
||
| 191 | if (!empty($exercise_stat_info)) { |
||
| 192 | $objQuestionTmp->initFile( |
||
| 193 | api_get_session_id(), |
||
| 194 | api_get_user_id(), |
||
| 195 | $exercise_stat_info['exe_exo_id'], |
||
| 196 | $exercise_stat_info['exe_id'] |
||
| 197 | ); |
||
| 198 | } else { |
||
| 199 | $objQuestionTmp->initFile( |
||
| 200 | api_get_session_id(), |
||
| 201 | api_get_user_id(), |
||
| 202 | $exerciseId, |
||
| 203 | 'temp_exe' |
||
| 204 | ); |
||
| 205 | } |
||
| 206 | |||
| 207 | echo $objQuestionTmp->returnRecorder(); |
||
| 208 | } |
||
| 209 | |||
| 210 | $form = new FormValidator('free_choice_'.$questionId); |
||
| 211 | $config = ['ToolbarSet' => 'TestFreeAnswer']; |
||
| 212 | |||
| 213 | $form->addHtml('<div id="'.'hide_description_'.$questionId.'_options" style="display: none;">'); |
||
| 214 | $form->addHtmlEditor( |
||
| 215 | "choice[".$questionId."]", |
||
| 216 | null, |
||
| 217 | false, |
||
| 218 | false, |
||
| 219 | $config |
||
| 220 | ); |
||
| 221 | $form->addHtml('</div>'); |
||
| 222 | $s .= $form->returnForm(); |
||
| 223 | } |
||
| 224 | |||
| 225 | // Now navigate through the possible answers, using the max number of |
||
| 226 | // answers for the question as a limiter |
||
| 227 | $lines_count = 1; // a counter for matching-type answers |
||
| 228 | if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || |
||
| 229 | $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE |
||
| 230 | ) { |
||
| 231 | $header = Display::tag('th', get_lang('Options')); |
||
| 232 | foreach ($objQuestionTmp->options as $item) { |
||
| 233 | if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) { |
||
| 234 | if (in_array($item, $objQuestionTmp->options)) { |
||
| 235 | $header .= Display::tag('th', get_lang($item)); |
||
| 236 | } else { |
||
| 237 | $header .= Display::tag('th', $item); |
||
| 238 | } |
||
| 239 | } else { |
||
| 240 | $header .= Display::tag('th', $item); |
||
| 241 | } |
||
| 242 | } |
||
| 243 | if ($show_comment) { |
||
| 244 | $header .= Display::tag('th', get_lang('Feedback')); |
||
| 245 | } |
||
| 246 | $s .= '<table class="table table-hover table-striped">'; |
||
| 247 | $s .= Display::tag( |
||
| 248 | 'tr', |
||
| 249 | $header, |
||
| 250 | ['style' => 'text-align:left;'] |
||
| 251 | ); |
||
| 252 | } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) { |
||
| 253 | $header = Display::tag('th', get_lang('Options'), ['width' => '50%']); |
||
| 254 | echo " |
||
| 255 | <script> |
||
| 256 | function RadioValidator(question_id, answer_id) |
||
| 257 | { |
||
| 258 | var ShowAlert = ''; |
||
| 259 | var typeRadioB = ''; |
||
| 260 | var AllFormElements = window.document.getElementById('exercise_form').elements; |
||
| 261 | |||
| 262 | for (i = 0; i < AllFormElements.length; i++) { |
||
| 263 | if (AllFormElements[i].type == 'radio') { |
||
| 264 | var ThisRadio = AllFormElements[i].name; |
||
| 265 | var ThisChecked = 'No'; |
||
| 266 | var AllRadioOptions = document.getElementsByName(ThisRadio); |
||
| 267 | |||
| 268 | for (x = 0; x < AllRadioOptions.length; x++) { |
||
| 269 | if (AllRadioOptions[x].checked && ThisChecked == 'No') { |
||
| 270 | ThisChecked = 'Yes'; |
||
| 271 | break; |
||
| 272 | } |
||
| 273 | } |
||
| 274 | |||
| 275 | var AlreadySearched = ShowAlert.indexOf(ThisRadio); |
||
| 276 | if (ThisChecked == 'No' && AlreadySearched == -1) { |
||
| 277 | ShowAlert = ShowAlert + ThisRadio; |
||
| 278 | } |
||
| 279 | } |
||
| 280 | } |
||
| 281 | if (ShowAlert != '') { |
||
| 282 | |||
| 283 | } else { |
||
| 284 | $('.question-validate-btn').removeAttr('disabled'); |
||
| 285 | } |
||
| 286 | } |
||
| 287 | |||
| 288 | function handleRadioRow(event, question_id, answer_id) { |
||
| 289 | var t = event.target; |
||
| 290 | if (t && t.tagName == 'INPUT') |
||
| 291 | return; |
||
| 292 | while (t && t.tagName != 'TD') { |
||
| 293 | t = t.parentElement; |
||
| 294 | } |
||
| 295 | var r = t.getElementsByTagName('INPUT')[0]; |
||
| 296 | r.click(); |
||
| 297 | RadioValidator(question_id, answer_id); |
||
| 298 | } |
||
| 299 | |||
| 300 | $(document).ready(function() { |
||
| 301 | var ShowAlert = ''; |
||
| 302 | var typeRadioB = ''; |
||
| 303 | var question_id = $('input[name=question_id]').val(); |
||
| 304 | var AllFormElements = window.document.getElementById('exercise_form').elements; |
||
| 305 | |||
| 306 | for (i = 0; i < AllFormElements.length; i++) { |
||
| 307 | if (AllFormElements[i].type == 'radio') { |
||
| 308 | var ThisRadio = AllFormElements[i].name; |
||
| 309 | var ThisChecked = 'No'; |
||
| 310 | var AllRadioOptions = document.getElementsByName(ThisRadio); |
||
| 311 | |||
| 312 | for (x = 0; x < AllRadioOptions.length; x++) { |
||
| 313 | if (AllRadioOptions[x].checked && ThisChecked == 'No') { |
||
| 314 | ThisChecked = \"Yes\"; |
||
| 315 | break; |
||
| 316 | } |
||
| 317 | } |
||
| 318 | |||
| 319 | var AlreadySearched = ShowAlert.indexOf(ThisRadio); |
||
| 320 | if (ThisChecked == 'No' && AlreadySearched == -1) { |
||
| 321 | ShowAlert = ShowAlert + ThisRadio; |
||
| 322 | } |
||
| 323 | } |
||
| 324 | } |
||
| 325 | |||
| 326 | if (ShowAlert != '') { |
||
| 327 | $('.question-validate-btn').attr('disabled', 'disabled'); |
||
| 328 | } else { |
||
| 329 | $('.question-validate-btn').removeAttr('disabled'); |
||
| 330 | } |
||
| 331 | |||
| 332 | }); |
||
| 333 | </script>"; |
||
| 334 | |||
| 335 | foreach ($objQuestionTmp->optionsTitle as $item) { |
||
| 336 | if (in_array($item, $objQuestionTmp->optionsTitle)) { |
||
| 337 | $properties = []; |
||
| 338 | if ($item === 'Answers') { |
||
| 339 | $properties['colspan'] = 2; |
||
| 340 | $properties['style'] = 'background-color: #F56B2A; color: #ffffff;'; |
||
| 341 | } elseif ($item == 'DegreeOfCertaintyThatMyAnswerIsCorrect') { |
||
| 342 | $properties['colspan'] = 6; |
||
| 343 | $properties['style'] = 'background-color: #330066; color: #ffffff;'; |
||
| 344 | } |
||
| 345 | $header .= Display::tag('th', get_lang($item), $properties); |
||
| 346 | } else { |
||
| 347 | $header .= Display::tag('th', $item); |
||
| 348 | } |
||
| 349 | } |
||
| 350 | if ($show_comment) { |
||
| 351 | $header .= Display::tag('th', get_lang('Feedback')); |
||
| 352 | } |
||
| 353 | |||
| 354 | $s .= '<table class="data_table">'; |
||
| 355 | $s .= Display::tag('tr', $header, ['style' => 'text-align:left;']); |
||
| 356 | |||
| 357 | // ajout de la 2eme ligne d'entête pour true/falss et les pourcentages de certitude |
||
| 358 | $header1 = Display::tag('th', ' '); |
||
| 359 | $cpt1 = 0; |
||
| 360 | foreach ($objQuestionTmp->options as $item) { |
||
| 361 | $colorBorder1 = ($cpt1 == (count($objQuestionTmp->options) - 1)) |
||
| 362 | ? '' : 'border-right: solid #FFFFFF 1px;'; |
||
| 363 | if ($item == 'True' || $item == 'False') { |
||
| 364 | $header1 .= Display::tag('th', |
||
| 365 | get_lang($item), |
||
| 366 | ['style' => 'background-color: #F7C9B4; color: black;'.$colorBorder1] |
||
| 367 | ); |
||
| 368 | } else { |
||
| 369 | $header1 .= Display::tag('th', |
||
| 370 | $item, |
||
| 371 | ['style' => 'background-color: #e6e6ff; color: black;padding:5px; '.$colorBorder1]); |
||
| 372 | } |
||
| 373 | $cpt1++; |
||
| 374 | } |
||
| 375 | if ($show_comment) { |
||
| 376 | $header1 .= Display::tag('th', ' '); |
||
| 377 | } |
||
| 378 | |||
| 379 | $s .= Display::tag('tr', $header1); |
||
| 380 | |||
| 381 | // add explanation |
||
| 382 | $header2 = Display::tag('th', ' '); |
||
| 383 | $descriptionList = [ |
||
| 384 | get_lang('DegreeOfCertaintyIDeclareMyIgnorance'), |
||
| 385 | get_lang('DegreeOfCertaintyIAmVeryUnsure'), |
||
| 386 | get_lang('DegreeOfCertaintyIAmUnsure'), |
||
| 387 | get_lang('DegreeOfCertaintyIAmPrettySure'), |
||
| 388 | get_lang('DegreeOfCertaintyIAmSure'), |
||
| 389 | get_lang('DegreeOfCertaintyIAmVerySure'), |
||
| 390 | ]; |
||
| 391 | $counter2 = 0; |
||
| 392 | |||
| 393 | foreach ($objQuestionTmp->options as $item) { |
||
| 394 | if ($item == 'True' || $item == 'False') { |
||
| 395 | $header2 .= Display::tag('td', |
||
| 396 | ' ', |
||
| 397 | ['style' => 'background-color: #F7E1D7; color: black;border-right: solid #FFFFFF 1px;']); |
||
| 398 | } else { |
||
| 399 | $color_border2 = ($counter2 == (count($objQuestionTmp->options) - 1)) ? |
||
| 400 | '' : 'border-right: solid #FFFFFF 1px;font-size:11px;'; |
||
| 401 | $header2 .= Display::tag( |
||
| 402 | 'td', |
||
| 403 | nl2br($descriptionList[$counter2]), |
||
| 404 | ['style' => 'background-color: #EFEFFC; color: black; width: 110px; text-align:center; |
||
| 405 | vertical-align: top; padding:5px; '.$color_border2]); |
||
| 406 | $counter2++; |
||
| 407 | } |
||
| 408 | } |
||
| 409 | if ($show_comment) { |
||
| 410 | $header2 .= Display::tag('th', ' '); |
||
| 411 | } |
||
| 412 | $s .= Display::tag('tr', $header2); |
||
| 413 | } |
||
| 414 | |||
| 415 | if ($show_comment) { |
||
| 416 | if (in_array( |
||
| 417 | $answerType, |
||
| 418 | [ |
||
| 419 | MULTIPLE_ANSWER, |
||
| 420 | MULTIPLE_ANSWER_COMBINATION, |
||
| 421 | UNIQUE_ANSWER, |
||
| 422 | UNIQUE_ANSWER_IMAGE, |
||
| 423 | UNIQUE_ANSWER_NO_OPTION, |
||
| 424 | GLOBAL_MULTIPLE_ANSWER, |
||
| 425 | ] |
||
| 426 | )) { |
||
| 427 | $header = Display::tag('th', get_lang('Options')); |
||
| 428 | if ($exercise->feedback_type == EXERCISE_FEEDBACK_TYPE_END) { |
||
| 429 | $header .= Display::tag('th', get_lang('Feedback')); |
||
| 430 | } |
||
| 431 | $s .= '<table class="table table-hover table-striped">'; |
||
| 432 | $s .= Display::tag( |
||
| 433 | 'tr', |
||
| 434 | $header, |
||
| 435 | ['style' => 'text-align:left;'] |
||
| 436 | ); |
||
| 437 | } |
||
| 438 | } |
||
| 439 | |||
| 440 | $matching_correct_answer = 0; |
||
| 441 | $userChoiceList = []; |
||
| 442 | if (!empty($user_choice)) { |
||
| 443 | foreach ($user_choice as $item) { |
||
| 444 | $userChoiceList[] = $item['answer']; |
||
| 445 | } |
||
| 446 | } |
||
| 447 | |||
| 448 | $hidingClass = ''; |
||
| 449 | if ($answerType == READING_COMPREHENSION) { |
||
| 450 | $objQuestionTmp->processText($objQuestionTmp->selectDescription()); |
||
| 451 | $hidingClass = 'hide-reading-answers'; |
||
| 452 | $s .= Display::div( |
||
| 453 | $objQuestionTmp->selectTitle(), |
||
| 454 | ['class' => 'question_title '.$hidingClass] |
||
| 455 | ); |
||
| 456 | } |
||
| 457 | |||
| 458 | for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { |
||
| 459 | $answer = $objAnswerTmp->selectAnswer($answerId); |
||
| 460 | $answerCorrect = $objAnswerTmp->isCorrect($answerId); |
||
| 461 | $numAnswer = $objAnswerTmp->selectAutoId($answerId); |
||
| 462 | $comment = $objAnswerTmp->selectComment($answerId); |
||
| 463 | $attributes = []; |
||
| 464 | |||
| 465 | switch ($answerType) { |
||
| 466 | case UNIQUE_ANSWER: |
||
| 467 | case UNIQUE_ANSWER_NO_OPTION: |
||
| 468 | case UNIQUE_ANSWER_IMAGE: |
||
| 469 | case READING_COMPREHENSION: |
||
| 470 | $input_id = 'choice-'.$questionId.'-'.$answerId; |
||
| 471 | if (isset($user_choice[0]['answer']) && $user_choice[0]['answer'] == $numAnswer) { |
||
| 472 | $attributes = [ |
||
| 473 | 'id' => $input_id, |
||
| 474 | 'checked' => 1, |
||
| 475 | 'selected' => 1, |
||
| 476 | ]; |
||
| 477 | } else { |
||
| 478 | $attributes = ['id' => $input_id]; |
||
| 479 | } |
||
| 480 | |||
| 481 | if ($debug_mark_answer) { |
||
| 482 | if ($answerCorrect) { |
||
| 483 | $attributes['checked'] = 1; |
||
| 484 | $attributes['selected'] = 1; |
||
| 485 | } |
||
| 486 | } |
||
| 487 | |||
| 488 | if ($show_comment) { |
||
| 489 | $s .= '<tr><td>'; |
||
| 490 | } |
||
| 491 | |||
| 492 | if ($answerType == UNIQUE_ANSWER_IMAGE) { |
||
| 493 | if ($show_comment) { |
||
| 494 | if (empty($comment)) { |
||
| 495 | $s .= '<div id="answer'.$questionId.$numAnswer.'" |
||
| 496 | class="exercise-unique-answer-image" style="text-align: center">'; |
||
| 497 | } else { |
||
| 498 | $s .= '<div id="answer'.$questionId.$numAnswer.'" |
||
| 499 | class="exercise-unique-answer-image col-xs-6 col-sm-12" |
||
| 500 | style="text-align: center">'; |
||
| 501 | } |
||
| 502 | } else { |
||
| 503 | $s .= '<div id="answer'.$questionId.$numAnswer.'" |
||
| 504 | class="exercise-unique-answer-image col-xs-6 col-md-3" |
||
| 505 | style="text-align: center">'; |
||
| 506 | } |
||
| 507 | } |
||
| 508 | |||
| 509 | $answer = Security::remove_XSS($answer, STUDENT); |
||
| 510 | $s .= Display::input( |
||
| 511 | 'hidden', |
||
| 512 | 'choice2['.$questionId.']', |
||
| 513 | '0' |
||
| 514 | ); |
||
| 515 | |||
| 516 | $answer_input = null; |
||
| 517 | $attributes['class'] = 'checkradios'; |
||
| 518 | if ($answerType == UNIQUE_ANSWER_IMAGE) { |
||
| 519 | $attributes['class'] = ''; |
||
| 520 | $attributes['style'] = 'display: none;'; |
||
| 521 | $answer = '<div class="thumbnail">'.$answer.'</div>'; |
||
| 522 | } |
||
| 523 | |||
| 524 | $answer_input .= '<label class="radio '.$hidingClass.'">'; |
||
| 525 | $answer_input .= Display::input( |
||
| 526 | 'radio', |
||
| 527 | 'choice['.$questionId.']', |
||
| 528 | $numAnswer, |
||
| 529 | $attributes |
||
| 530 | ); |
||
| 531 | $answer_input .= $answer; |
||
| 532 | $answer_input .= '</label>'; |
||
| 533 | |||
| 534 | if ($answerType == UNIQUE_ANSWER_IMAGE) { |
||
| 535 | $answer_input .= "</div>"; |
||
| 536 | } |
||
| 537 | |||
| 538 | if ($show_comment) { |
||
| 539 | $s .= $answer_input; |
||
| 540 | $s .= '</td>'; |
||
| 541 | $s .= '<td>'; |
||
| 542 | $s .= $comment; |
||
| 543 | $s .= '</td>'; |
||
| 544 | $s .= '</tr>'; |
||
| 545 | } else { |
||
| 546 | $s .= $answer_input; |
||
| 547 | } |
||
| 548 | break; |
||
| 549 | case MULTIPLE_ANSWER: |
||
| 550 | case MULTIPLE_ANSWER_TRUE_FALSE: |
||
| 551 | case GLOBAL_MULTIPLE_ANSWER: |
||
| 552 | case MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY: |
||
| 553 | $input_id = 'choice-'.$questionId.'-'.$answerId; |
||
| 554 | $answer = Security::remove_XSS($answer, STUDENT); |
||
| 555 | |||
| 556 | if (in_array($numAnswer, $userChoiceList)) { |
||
| 557 | $attributes = [ |
||
| 558 | 'id' => $input_id, |
||
| 559 | 'checked' => 1, |
||
| 560 | 'selected' => 1, |
||
| 561 | ]; |
||
| 562 | } else { |
||
| 563 | $attributes = ['id' => $input_id]; |
||
| 564 | } |
||
| 565 | |||
| 566 | if ($debug_mark_answer) { |
||
| 567 | if ($answerCorrect) { |
||
| 568 | $attributes['checked'] = 1; |
||
| 569 | $attributes['selected'] = 1; |
||
| 570 | } |
||
| 571 | } |
||
| 572 | |||
| 573 | if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) { |
||
| 574 | $s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />'; |
||
| 575 | $attributes['class'] = 'checkradios'; |
||
| 576 | $answer_input = '<label class="checkbox">'; |
||
| 577 | $answer_input .= Display::input( |
||
| 578 | 'checkbox', |
||
| 579 | 'choice['.$questionId.']['.$numAnswer.']', |
||
| 580 | $numAnswer, |
||
| 581 | $attributes |
||
| 582 | ); |
||
| 583 | $answer_input .= $answer; |
||
| 584 | $answer_input .= '</label>'; |
||
| 585 | |||
| 586 | if ($show_comment) { |
||
| 587 | $s .= '<tr><td>'; |
||
| 588 | $s .= $answer_input; |
||
| 589 | $s .= '</td>'; |
||
| 590 | $s .= '<td>'; |
||
| 591 | $s .= $comment; |
||
| 592 | $s .= '</td>'; |
||
| 593 | $s .= '</tr>'; |
||
| 594 | } else { |
||
| 595 | $s .= $answer_input; |
||
| 596 | } |
||
| 597 | } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) { |
||
| 598 | $myChoice = []; |
||
| 599 | if (!empty($userChoiceList)) { |
||
| 600 | foreach ($userChoiceList as $item) { |
||
| 601 | $item = explode(':', $item); |
||
| 602 | $myChoice[$item[0]] = $item[1]; |
||
| 603 | } |
||
| 604 | } |
||
| 605 | |||
| 606 | $s .= '<tr>'; |
||
| 607 | $s .= Display::tag('td', $answer); |
||
| 608 | |||
| 609 | if (!empty($quizQuestionOptions)) { |
||
| 610 | foreach ($quizQuestionOptions as $id => $item) { |
||
| 611 | if (isset($myChoice[$numAnswer]) && $id == $myChoice[$numAnswer]) { |
||
| 612 | $attributes = [ |
||
| 613 | 'checked' => 1, |
||
| 614 | 'selected' => 1, |
||
| 615 | ]; |
||
| 616 | } else { |
||
| 617 | $attributes = []; |
||
| 618 | } |
||
| 619 | |||
| 620 | if ($debug_mark_answer) { |
||
| 621 | if ($id == $answerCorrect) { |
||
| 622 | $attributes['checked'] = 1; |
||
| 623 | $attributes['selected'] = 1; |
||
| 624 | } |
||
| 625 | } |
||
| 626 | $s .= Display::tag( |
||
| 627 | 'td', |
||
| 628 | Display::input( |
||
| 629 | 'radio', |
||
| 630 | 'choice['.$questionId.']['.$numAnswer.']', |
||
| 631 | $id, |
||
| 632 | $attributes |
||
| 633 | ), |
||
| 634 | ['style' => ''] |
||
| 635 | ); |
||
| 636 | } |
||
| 637 | } |
||
| 638 | |||
| 639 | if ($show_comment) { |
||
| 640 | $s .= '<td>'; |
||
| 641 | $s .= $comment; |
||
| 642 | $s .= '</td>'; |
||
| 643 | } |
||
| 644 | $s .= '</tr>'; |
||
| 645 | } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) { |
||
| 646 | $myChoice = []; |
||
| 647 | if (!empty($userChoiceList)) { |
||
| 648 | foreach ($userChoiceList as $item) { |
||
| 649 | $item = explode(':', $item); |
||
| 650 | $myChoice[$item[0]] = $item[1]; |
||
| 651 | } |
||
| 652 | } |
||
| 653 | $myChoiceDegreeCertainty = []; |
||
| 654 | if (!empty($userChoiceList)) { |
||
| 655 | foreach ($userChoiceList as $item) { |
||
| 656 | $item = explode(':', $item); |
||
| 657 | $myChoiceDegreeCertainty[$item[0]] = $item[2]; |
||
| 658 | } |
||
| 659 | } |
||
| 660 | $s .= '<tr>'; |
||
| 661 | $s .= Display::tag('td', $answer); |
||
| 662 | |||
| 663 | if (!empty($quizQuestionOptions)) { |
||
| 664 | foreach ($quizQuestionOptions as $id => $item) { |
||
| 665 | if (isset($myChoice[$numAnswer]) && $id == $myChoice[$numAnswer]) { |
||
| 666 | $attributes = ['checked' => 1, 'selected' => 1]; |
||
| 667 | } else { |
||
| 668 | $attributes = []; |
||
| 669 | } |
||
| 670 | $attributes['onChange'] = 'RadioValidator('.$questionId.', '.$numAnswer.')'; |
||
| 671 | |||
| 672 | // radio button selection |
||
| 673 | if (isset($myChoiceDegreeCertainty[$numAnswer]) && |
||
| 674 | $id == $myChoiceDegreeCertainty[$numAnswer] |
||
| 675 | ) { |
||
| 676 | $attributes1 = ['checked' => 1, 'selected' => 1]; |
||
| 677 | } else { |
||
| 678 | $attributes1 = []; |
||
| 679 | } |
||
| 680 | |||
| 681 | $attributes1['onChange'] = 'RadioValidator('.$questionId.', '.$numAnswer.')'; |
||
| 682 | |||
| 683 | if ($debug_mark_answer) { |
||
| 684 | if ($id == $answerCorrect) { |
||
| 685 | $attributes['checked'] = 1; |
||
| 686 | $attributes['selected'] = 1; |
||
| 687 | } |
||
| 688 | } |
||
| 689 | |||
| 690 | if ($item['name'] == 'True' || $item['name'] == 'False') { |
||
| 691 | $s .= Display::tag('td', |
||
| 692 | Display::input('radio', |
||
| 693 | 'choice['.$questionId.']['.$numAnswer.']', |
||
| 694 | $id, |
||
| 695 | $attributes |
||
| 696 | ), |
||
| 697 | ['style' => 'text-align:center; background-color:#F7E1D7;', |
||
| 698 | 'onclick' => 'handleRadioRow(event, '. |
||
| 699 | $questionId.', '. |
||
| 700 | $numAnswer.')', |
||
| 701 | ] |
||
| 702 | ); |
||
| 703 | } else { |
||
| 704 | $s .= Display::tag('td', |
||
| 705 | Display::input('radio', |
||
| 706 | 'choiceDegreeCertainty['.$questionId.']['.$numAnswer.']', |
||
| 707 | $id, |
||
| 708 | $attributes1 |
||
| 709 | ), |
||
| 710 | ['style' => 'text-align:center; background-color:#EFEFFC;', |
||
| 711 | 'onclick' => 'handleRadioRow(event, '. |
||
| 712 | $questionId.', '. |
||
| 713 | $numAnswer.')', |
||
| 714 | ] |
||
| 715 | ); |
||
| 716 | } |
||
| 717 | } |
||
| 718 | } |
||
| 719 | |||
| 720 | if ($show_comment) { |
||
| 721 | $s .= '<td>'; |
||
| 722 | $s .= $comment; |
||
| 723 | $s .= '</td>'; |
||
| 724 | } |
||
| 725 | $s .= '</tr>'; |
||
| 726 | } |
||
| 727 | break; |
||
| 728 | case MULTIPLE_ANSWER_COMBINATION: |
||
| 729 | // multiple answers |
||
| 730 | $input_id = 'choice-'.$questionId.'-'.$answerId; |
||
| 731 | |||
| 732 | if (in_array($numAnswer, $userChoiceList)) { |
||
| 733 | $attributes = [ |
||
| 734 | 'id' => $input_id, |
||
| 735 | 'checked' => 1, |
||
| 736 | 'selected' => 1, |
||
| 737 | ]; |
||
| 738 | } else { |
||
| 739 | $attributes = ['id' => $input_id]; |
||
| 740 | } |
||
| 741 | |||
| 742 | if ($debug_mark_answer) { |
||
| 743 | if ($answerCorrect) { |
||
| 744 | $attributes['checked'] = 1; |
||
| 745 | $attributes['selected'] = 1; |
||
| 746 | } |
||
| 747 | } |
||
| 748 | |||
| 749 | $answer = Security::remove_XSS($answer, STUDENT); |
||
| 750 | $answer_input = '<input type="hidden" name="choice2['.$questionId.']" value="0" />'; |
||
| 751 | $answer_input .= '<label class="checkbox">'; |
||
| 752 | $answer_input .= Display::input( |
||
| 753 | 'checkbox', |
||
| 754 | 'choice['.$questionId.']['.$numAnswer.']', |
||
| 755 | 1, |
||
| 756 | $attributes |
||
| 757 | ); |
||
| 758 | $answer_input .= $answer; |
||
| 759 | $answer_input .= '</label>'; |
||
| 760 | |||
| 761 | if ($show_comment) { |
||
| 762 | $s .= '<tr>'; |
||
| 763 | $s .= '<td>'; |
||
| 764 | $s .= $answer_input; |
||
| 765 | $s .= '</td>'; |
||
| 766 | $s .= '<td>'; |
||
| 767 | $s .= $comment; |
||
| 768 | $s .= '</td>'; |
||
| 769 | $s .= '</tr>'; |
||
| 770 | } else { |
||
| 771 | $s .= $answer_input; |
||
| 772 | } |
||
| 773 | break; |
||
| 774 | case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE: |
||
| 775 | $s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />'; |
||
| 776 | $myChoice = []; |
||
| 777 | if (!empty($userChoiceList)) { |
||
| 778 | foreach ($userChoiceList as $item) { |
||
| 779 | $item = explode(':', $item); |
||
| 780 | if (isset($item[1]) && isset($item[0])) { |
||
| 781 | $myChoice[$item[0]] = $item[1]; |
||
| 782 | } |
||
| 783 | } |
||
| 784 | } |
||
| 785 | $answer = Security::remove_XSS($answer, STUDENT); |
||
| 786 | $s .= '<tr>'; |
||
| 787 | $s .= Display::tag('td', $answer); |
||
| 788 | foreach ($objQuestionTmp->options as $key => $item) { |
||
| 789 | if (isset($myChoice[$numAnswer]) && $key == $myChoice[$numAnswer]) { |
||
| 790 | $attributes = [ |
||
| 791 | 'checked' => 1, |
||
| 792 | 'selected' => 1, |
||
| 793 | ]; |
||
| 794 | } else { |
||
| 795 | $attributes = []; |
||
| 796 | } |
||
| 797 | |||
| 798 | if ($debug_mark_answer) { |
||
| 799 | if ($key == $answerCorrect) { |
||
| 800 | $attributes['checked'] = 1; |
||
| 801 | $attributes['selected'] = 1; |
||
| 802 | } |
||
| 803 | } |
||
| 804 | $s .= Display::tag( |
||
| 805 | 'td', |
||
| 806 | Display::input( |
||
| 807 | 'radio', |
||
| 808 | 'choice['.$questionId.']['.$numAnswer.']', |
||
| 809 | $key, |
||
| 810 | $attributes |
||
| 811 | ) |
||
| 812 | ); |
||
| 813 | } |
||
| 814 | |||
| 815 | if ($show_comment) { |
||
| 816 | $s .= '<td>'; |
||
| 817 | $s .= $comment; |
||
| 818 | $s .= '</td>'; |
||
| 819 | } |
||
| 820 | $s .= '</tr>'; |
||
| 821 | break; |
||
| 822 | case FILL_IN_BLANKS: |
||
| 823 | // display the question, with field empty, for student to fill it, |
||
| 824 | // or filled to display the answer in the Question preview of the exercise/admin.php page |
||
| 825 | $displayForStudent = true; |
||
| 826 | $listAnswerInfo = FillBlanks::getAnswerInfo($answer); |
||
| 827 | // Correct answers |
||
| 828 | $correctAnswerList = $listAnswerInfo['words']; |
||
| 829 | // Student's answer |
||
| 830 | $studentAnswerList = []; |
||
| 831 | if (isset($user_choice[0]['answer'])) { |
||
| 832 | $arrayStudentAnswer = FillBlanks::getAnswerInfo( |
||
| 833 | $user_choice[0]['answer'], |
||
| 834 | true |
||
| 835 | ); |
||
| 836 | $studentAnswerList = $arrayStudentAnswer['student_answer']; |
||
| 837 | } |
||
| 838 | |||
| 839 | // If the question must be shown with the answer (in page exercise/admin.php) |
||
| 840 | // for teacher preview set the student-answer to the correct answer |
||
| 841 | if ($debug_mark_answer) { |
||
| 842 | $studentAnswerList = $correctAnswerList; |
||
| 843 | $displayForStudent = false; |
||
| 844 | } |
||
| 845 | |||
| 846 | if (!empty($correctAnswerList) && !empty($studentAnswerList)) { |
||
| 847 | $answer = ''; |
||
| 848 | for ($i = 0; $i < count($listAnswerInfo['common_words']) - 1; $i++) { |
||
| 849 | // display the common word |
||
| 850 | $answer .= $listAnswerInfo['common_words'][$i]; |
||
| 851 | // display the blank word |
||
| 852 | $correctItem = $listAnswerInfo['words'][$i]; |
||
| 853 | if (isset($studentAnswerList[$i])) { |
||
| 854 | // If student already started this test and answered this question, |
||
| 855 | // fill the blank with his previous answers |
||
| 856 | // may be "" if student viewed the question, but did not fill the blanks |
||
| 857 | $correctItem = $studentAnswerList[$i]; |
||
| 858 | } |
||
| 859 | $attributes['style'] = 'width:'.$listAnswerInfo['input_size'][$i].'px'; |
||
| 860 | $answer .= FillBlanks::getFillTheBlankHtml( |
||
| 861 | $current_item, |
||
| 862 | $questionId, |
||
| 863 | $correctItem, |
||
| 864 | $attributes, |
||
| 865 | $answer, |
||
| 866 | $listAnswerInfo, |
||
| 867 | $displayForStudent, |
||
| 868 | $i |
||
| 869 | ); |
||
| 870 | } |
||
| 871 | // display the last common word |
||
| 872 | $answer .= $listAnswerInfo['common_words'][$i]; |
||
| 873 | } else { |
||
| 874 | // display empty [input] with the right width for student to fill it |
||
| 875 | $answer = ''; |
||
| 876 | for ($i = 0; $i < count($listAnswerInfo['common_words']) - 1; $i++) { |
||
| 877 | // display the common words |
||
| 878 | $answer .= $listAnswerInfo['common_words'][$i]; |
||
| 879 | // display the blank word |
||
| 880 | $attributes['style'] = 'width:'.$listAnswerInfo['input_size'][$i].'px'; |
||
| 881 | $answer .= FillBlanks::getFillTheBlankHtml( |
||
| 882 | $current_item, |
||
| 883 | $questionId, |
||
| 884 | '', |
||
| 885 | $attributes, |
||
| 886 | $answer, |
||
| 887 | $listAnswerInfo, |
||
| 888 | $displayForStudent, |
||
| 889 | $i |
||
| 890 | ); |
||
| 891 | } |
||
| 892 | // display the last common word |
||
| 893 | $answer .= $listAnswerInfo['common_words'][$i]; |
||
| 894 | } |
||
| 895 | $s .= $answer; |
||
| 896 | break; |
||
| 897 | case CALCULATED_ANSWER: |
||
| 898 | /* |
||
| 899 | * In the CALCULATED_ANSWER test |
||
| 900 | * you mustn't have [ and ] in the textarea |
||
| 901 | * you mustn't have @@ in the textarea |
||
| 902 | * the text to find mustn't be empty or contains only spaces |
||
| 903 | * the text to find mustn't contains HTML tags |
||
| 904 | * the text to find mustn't contains char " |
||
| 905 | */ |
||
| 906 | if ($origin !== null) { |
||
| 907 | global $exe_id; |
||
| 908 | $trackAttempts = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
||
| 909 | $sql = 'SELECT answer FROM '.$trackAttempts.' |
||
| 910 | WHERE exe_id='.$exe_id.' AND question_id='.$questionId; |
||
| 911 | $rsLastAttempt = Database::query($sql); |
||
| 912 | $rowLastAttempt = Database::fetch_array($rsLastAttempt); |
||
| 913 | $answer = $rowLastAttempt['answer']; |
||
| 914 | if (empty($answer)) { |
||
| 915 | $_SESSION['calculatedAnswerId'][$questionId] = mt_rand( |
||
| 916 | 1, |
||
| 917 | $nbrAnswers |
||
| 918 | ); |
||
| 919 | $answer = $objAnswerTmp->selectAnswer( |
||
| 920 | $_SESSION['calculatedAnswerId'][$questionId] |
||
| 921 | ); |
||
| 922 | } |
||
| 923 | } |
||
| 924 | |||
| 925 | list($answer) = explode('@@', $answer); |
||
| 926 | // $correctAnswerList array of array with correct anwsers 0=> [0=>[\p] 1=>[plop]] |
||
| 927 | api_preg_match_all( |
||
| 928 | '/\[[^]]+\]/', |
||
| 929 | $answer, |
||
| 930 | $correctAnswerList |
||
| 931 | ); |
||
| 932 | |||
| 933 | // get student answer to display it if student go back to |
||
| 934 | // previous calculated answer question in a test |
||
| 935 | if (isset($user_choice[0]['answer'])) { |
||
| 936 | api_preg_match_all( |
||
| 937 | '/\[[^]]+\]/', |
||
| 938 | $answer, |
||
| 939 | $studentAnswerList |
||
| 940 | ); |
||
| 941 | $studentAnswerListToClean = $studentAnswerList[0]; |
||
| 942 | $studentAnswerList = []; |
||
| 943 | |||
| 944 | $maxStudents = count($studentAnswerListToClean); |
||
| 945 | for ($i = 0; $i < $maxStudents; $i++) { |
||
| 946 | $answerCorrected = $studentAnswerListToClean[$i]; |
||
| 947 | $answerCorrected = api_preg_replace( |
||
| 948 | '| / <font color="green"><b>.*$|', |
||
| 949 | '', |
||
| 950 | $answerCorrected |
||
| 951 | ); |
||
| 952 | $answerCorrected = api_preg_replace( |
||
| 953 | '/^\[/', |
||
| 954 | '', |
||
| 955 | $answerCorrected |
||
| 956 | ); |
||
| 957 | $answerCorrected = api_preg_replace( |
||
| 958 | '|^<font color="red"><s>|', |
||
| 959 | '', |
||
| 960 | $answerCorrected |
||
| 961 | ); |
||
| 962 | $answerCorrected = api_preg_replace( |
||
| 963 | '|</s></font>$|', |
||
| 964 | '', |
||
| 965 | $answerCorrected |
||
| 966 | ); |
||
| 967 | $answerCorrected = '['.$answerCorrected.']'; |
||
| 968 | $studentAnswerList[] = $answerCorrected; |
||
| 969 | } |
||
| 970 | } |
||
| 971 | |||
| 972 | // If display preview of answer in test view for exaemple, |
||
| 973 | // set the student answer to the correct answers |
||
| 974 | if ($debug_mark_answer) { |
||
| 975 | // contain the rights answers surronded with brackets |
||
| 976 | $studentAnswerList = $correctAnswerList[0]; |
||
| 977 | } |
||
| 978 | |||
| 979 | /* |
||
| 980 | Split the response by bracket |
||
| 981 | tabComments is an array with text surrounding the text to find |
||
| 982 | we add a space before and after the answerQuestion to be sure to |
||
| 983 | have a block of text before and after [xxx] patterns |
||
| 984 | so we have n text to find ([xxx]) and n+1 block of texts before, |
||
| 985 | between and after the text to find |
||
| 986 | */ |
||
| 987 | $tabComments = api_preg_split( |
||
| 988 | '/\[[^]]+\]/', |
||
| 989 | ' '.$answer.' ' |
||
| 990 | ); |
||
| 991 | if (!empty($correctAnswerList) && !empty($studentAnswerList)) { |
||
| 992 | $answer = ''; |
||
| 993 | $i = 0; |
||
| 994 | foreach ($studentAnswerList as $studentItem) { |
||
| 995 | // remove surronding brackets |
||
| 996 | $studentResponse = api_substr( |
||
| 997 | $studentItem, |
||
| 998 | 1, |
||
| 999 | api_strlen($studentItem) - 2 |
||
| 1000 | ); |
||
| 1001 | $size = strlen($studentItem); |
||
| 1002 | $attributes['class'] = self::detectInputAppropriateClass( |
||
| 1003 | $size |
||
| 1004 | ); |
||
| 1005 | |||
| 1006 | $answer .= $tabComments[$i]. |
||
| 1007 | Display::input( |
||
| 1008 | 'text', |
||
| 1009 | "choice[$questionId][]", |
||
| 1010 | $studentResponse, |
||
| 1011 | $attributes |
||
| 1012 | ); |
||
| 1013 | $i++; |
||
| 1014 | } |
||
| 1015 | $answer .= $tabComments[$i]; |
||
| 1016 | } else { |
||
| 1017 | // display exercise with empty input fields |
||
| 1018 | // every [xxx] are replaced with an empty input field |
||
| 1019 | foreach ($correctAnswerList[0] as $item) { |
||
| 1020 | $size = strlen($item); |
||
| 1021 | $attributes['class'] = self::detectInputAppropriateClass( |
||
| 1022 | $size |
||
| 1023 | ); |
||
| 1024 | $answer = str_replace( |
||
| 1025 | $item, |
||
| 1026 | Display::input( |
||
| 1027 | 'text', |
||
| 1028 | "choice[$questionId][]", |
||
| 1029 | '', |
||
| 1030 | $attributes |
||
| 1031 | ), |
||
| 1032 | $answer |
||
| 1033 | ); |
||
| 1034 | } |
||
| 1035 | } |
||
| 1036 | if ($origin !== null) { |
||
| 1037 | $s = $answer; |
||
| 1038 | break; |
||
| 1039 | } else { |
||
| 1040 | $s .= $answer; |
||
| 1041 | } |
||
| 1042 | break; |
||
| 1043 | case MATCHING: |
||
| 1044 | // matching type, showing suggestions and answers |
||
| 1045 | // TODO: replace $answerId by $numAnswer |
||
| 1046 | if ($answerCorrect != 0) { |
||
| 1047 | // only show elements to be answered (not the contents of |
||
| 1048 | // the select boxes, who are correct = 0) |
||
| 1049 | $s .= '<tr><td width="45%" valign="top">'; |
||
| 1050 | $parsed_answer = $answer; |
||
| 1051 | // Left part questions |
||
| 1052 | $s .= '<p class="indent">'.$lines_count.'. '.$parsed_answer.'</p></td>'; |
||
| 1053 | // Middle part (matches selects) |
||
| 1054 | // Id of select is # question + # of option |
||
| 1055 | $s .= '<td width="10%" valign="top" align="center"> |
||
| 1056 | <div class="select-matching"> |
||
| 1057 | <select |
||
| 1058 | id="choice_id_'.$current_item.'_'.$lines_count.'" |
||
| 1059 | name="choice['.$questionId.']['.$numAnswer.']">'; |
||
| 1060 | |||
| 1061 | // fills the list-box |
||
| 1062 | foreach ($select_items as $key => $val) { |
||
| 1063 | // set $debug_mark_answer to true at function start to |
||
| 1064 | // show the correct answer with a suffix '-x' |
||
| 1065 | $selected = ''; |
||
| 1066 | if ($debug_mark_answer) { |
||
| 1067 | if ($val['id'] == $answerCorrect) { |
||
| 1068 | $selected = 'selected="selected"'; |
||
| 1069 | } |
||
| 1070 | } |
||
| 1071 | //$user_choice_array_position |
||
| 1072 | if (isset($user_choice_array_position[$numAnswer]) && |
||
| 1073 | $val['id'] == $user_choice_array_position[$numAnswer] |
||
| 1074 | ) { |
||
| 1075 | $selected = 'selected="selected"'; |
||
| 1076 | } |
||
| 1077 | $s .= '<option value="'.$val['id'].'" '.$selected.'>'.$val['letter'].'</option>'; |
||
| 1078 | } // end foreach() |
||
| 1079 | |||
| 1080 | $s .= '</select></div></td><td width="5%" class="separate"> </td>'; |
||
| 1081 | $s .= '<td width="40%" valign="top" >'; |
||
| 1082 | if (isset($select_items[$lines_count])) { |
||
| 1083 | $s .= '<div class="text-right"> |
||
| 1084 | <p class="indent">'. |
||
| 1085 | $select_items[$lines_count]['letter'].'. '. |
||
| 1086 | $select_items[$lines_count]['answer'].' |
||
| 1087 | </p> |
||
| 1088 | </div>'; |
||
| 1089 | } else { |
||
| 1090 | $s .= ' '; |
||
| 1091 | } |
||
| 1092 | $s .= '</td>'; |
||
| 1093 | $s .= '</tr>'; |
||
| 1094 | $lines_count++; |
||
| 1095 | //if the left side of the "matching" has been completely |
||
| 1096 | // shown but the right side still has values to show... |
||
| 1097 | if (($lines_count - 1) == $num_suggestions) { |
||
| 1098 | // if it remains answers to shown at the right side |
||
| 1099 | while (isset($select_items[$lines_count])) { |
||
| 1100 | $s .= '<tr> |
||
| 1101 | <td colspan="2"></td> |
||
| 1102 | <td valign="top">'; |
||
| 1103 | $s .= '<b>'.$select_items[$lines_count]['letter'].'.</b> '. |
||
| 1104 | $select_items[$lines_count]['answer']; |
||
| 1105 | $s .= "</td> |
||
| 1106 | </tr>"; |
||
| 1107 | $lines_count++; |
||
| 1108 | } // end while() |
||
| 1109 | } // end if() |
||
| 1110 | $matching_correct_answer++; |
||
| 1111 | } |
||
| 1112 | break; |
||
| 1113 | case DRAGGABLE: |
||
| 1114 | if ($answerCorrect) { |
||
| 1115 | $windowId = $questionId.'_'.$lines_count; |
||
| 1116 | $s .= '<li class="touch-items" id="'.$windowId.'">'; |
||
| 1117 | $s .= Display::div( |
||
| 1118 | $answer, |
||
| 1119 | [ |
||
| 1120 | 'id' => "window_$windowId", |
||
| 1121 | 'class' => "window{$questionId}_question_draggable exercise-draggable-answer-option", |
||
| 1122 | ] |
||
| 1123 | ); |
||
| 1124 | |||
| 1125 | $draggableSelectOptions = []; |
||
| 1126 | $selectedValue = 0; |
||
| 1127 | $selectedIndex = 0; |
||
| 1128 | |||
| 1129 | if ($user_choice) { |
||
| 1130 | foreach ($user_choice as $chosen) { |
||
| 1131 | if ($answerCorrect != $chosen['answer']) { |
||
| 1132 | continue; |
||
| 1133 | } |
||
| 1134 | $selectedValue = $chosen['answer']; |
||
| 1135 | } |
||
| 1136 | } |
||
| 1137 | |||
| 1138 | foreach ($select_items as $key => $select_item) { |
||
| 1139 | $draggableSelectOptions[$select_item['id']] = $select_item['letter']; |
||
| 1140 | } |
||
| 1141 | |||
| 1142 | foreach ($draggableSelectOptions as $value => $text) { |
||
| 1143 | if ($value == $selectedValue) { |
||
| 1144 | break; |
||
| 1145 | } |
||
| 1146 | $selectedIndex++; |
||
| 1147 | } |
||
| 1148 | |||
| 1149 | $s .= Display::select( |
||
| 1150 | "choice[$questionId][$numAnswer]", |
||
| 1151 | $draggableSelectOptions, |
||
| 1152 | $selectedValue, |
||
| 1153 | [ |
||
| 1154 | 'id' => "window_{$windowId}_select", |
||
| 1155 | 'class' => 'select_option hidden', |
||
| 1156 | ], |
||
| 1157 | false |
||
| 1158 | ); |
||
| 1159 | |||
| 1160 | if ($selectedValue && $selectedIndex) { |
||
| 1161 | $s .= " |
||
| 1162 | <script> |
||
| 1163 | $(function() { |
||
| 1164 | DraggableAnswer.deleteItem( |
||
| 1165 | $('#{$questionId}_$lines_count'), |
||
| 1166 | $('#drop_{$questionId}_{$selectedIndex}') |
||
| 1167 | ); |
||
| 1168 | }); |
||
| 1169 | </script> |
||
| 1170 | "; |
||
| 1171 | } |
||
| 1172 | |||
| 1173 | if (isset($select_items[$lines_count])) { |
||
| 1174 | $s .= Display::div( |
||
| 1175 | Display::tag( |
||
| 1176 | 'b', |
||
| 1177 | $select_items[$lines_count]['letter'] |
||
| 1178 | ).$select_items[$lines_count]['answer'], |
||
| 1179 | [ |
||
| 1180 | 'id' => "window_{$windowId}_answer", |
||
| 1181 | 'class' => 'hidden', |
||
| 1182 | ] |
||
| 1183 | ); |
||
| 1184 | } else { |
||
| 1185 | $s .= ' '; |
||
| 1186 | } |
||
| 1187 | |||
| 1188 | $lines_count++; |
||
| 1189 | if (($lines_count - 1) == $num_suggestions) { |
||
| 1190 | while (isset($select_items[$lines_count])) { |
||
| 1191 | $s .= Display::tag('b', $select_items[$lines_count]['letter']); |
||
| 1192 | $s .= $select_items[$lines_count]['answer']; |
||
| 1193 | $lines_count++; |
||
| 1194 | } |
||
| 1195 | } |
||
| 1196 | |||
| 1197 | $matching_correct_answer++; |
||
| 1198 | $s .= '</li>'; |
||
| 1199 | } |
||
| 1200 | break; |
||
| 1201 | case MATCHING_DRAGGABLE: |
||
| 1202 | if ($answerId == 1) { |
||
| 1203 | echo $objAnswerTmp->getJs(); |
||
| 1204 | } |
||
| 1205 | if ($answerCorrect != 0) { |
||
| 1206 | $windowId = "{$questionId}_{$lines_count}"; |
||
| 1207 | $s .= <<<HTML |
||
| 1208 | <tr> |
||
| 1209 | <td width="45%"> |
||
| 1210 | <div id="window_{$windowId}" |
||
| 1211 | class="window window_left_question window{$questionId}_question"> |
||
| 1212 | <strong>$lines_count.</strong> |
||
| 1213 | $answer |
||
| 1214 | </div> |
||
| 1215 | </td> |
||
| 1216 | <td width="10%"> |
||
| 1217 | HTML; |
||
| 1218 | |||
| 1219 | $draggableSelectOptions = []; |
||
| 1220 | $selectedValue = 0; |
||
| 1221 | $selectedIndex = 0; |
||
| 1222 | |||
| 1223 | if ($user_choice) { |
||
| 1224 | foreach ($user_choice as $chosen) { |
||
| 1225 | if ($numAnswer == $chosen['position']) { |
||
| 1226 | $selectedValue = $chosen['answer']; |
||
| 1227 | break; |
||
| 1228 | } |
||
| 1229 | } |
||
| 1230 | } |
||
| 1231 | |||
| 1232 | foreach ($select_items as $key => $selectItem) { |
||
| 1233 | $draggableSelectOptions[$selectItem['id']] = $selectItem['letter']; |
||
| 1234 | } |
||
| 1235 | |||
| 1236 | foreach ($draggableSelectOptions as $value => $text) { |
||
| 1237 | if ($value == $selectedValue) { |
||
| 1238 | break; |
||
| 1239 | } |
||
| 1240 | $selectedIndex++; |
||
| 1241 | } |
||
| 1242 | |||
| 1243 | $s .= Display::select( |
||
| 1244 | "choice[$questionId][$numAnswer]", |
||
| 1245 | $draggableSelectOptions, |
||
| 1246 | $selectedValue, |
||
| 1247 | [ |
||
| 1248 | 'id' => "window_{$windowId}_select", |
||
| 1249 | 'class' => 'hidden', |
||
| 1250 | ], |
||
| 1251 | false |
||
| 1252 | ); |
||
| 1253 | |||
| 1254 | if (!empty($answerCorrect) && !empty($selectedValue)) { |
||
| 1255 | // Show connect if is not freeze (question preview) |
||
| 1256 | if (!$freeze) { |
||
| 1257 | $s .= " |
||
| 1258 | <script> |
||
| 1259 | $(document).on('ready', function() { |
||
| 1260 | jsPlumb.ready(function() { |
||
| 1261 | jsPlumb.connect({ |
||
| 1262 | source: 'window_$windowId', |
||
| 1263 | target: 'window_{$questionId}_{$selectedIndex}_answer', |
||
| 1264 | endpoint: ['Blank', {radius: 15}], |
||
| 1265 | anchors: ['RightMiddle', 'LeftMiddle'], |
||
| 1266 | paintStyle: {strokeStyle: '#8A8888', lineWidth: 8}, |
||
| 1267 | connector: [ |
||
| 1268 | MatchingDraggable.connectorType, |
||
| 1269 | {curvines: MatchingDraggable.curviness} |
||
| 1270 | ] |
||
| 1271 | }); |
||
| 1272 | }); |
||
| 1273 | }); |
||
| 1274 | </script> |
||
| 1275 | "; |
||
| 1276 | } |
||
| 1277 | } |
||
| 1278 | |||
| 1279 | $s .= '</td><td width="45%">'; |
||
| 1280 | if (isset($select_items[$lines_count])) { |
||
| 1281 | $s .= <<<HTML |
||
| 1282 | <div id="window_{$windowId}_answer" class="window window_right_question"> |
||
| 1283 | <strong>{$select_items[$lines_count]['letter']}.</strong> |
||
| 1284 | {$select_items[$lines_count]['answer']} |
||
| 1285 | </div> |
||
| 1286 | HTML; |
||
| 1287 | } else { |
||
| 1288 | $s .= ' '; |
||
| 1289 | } |
||
| 1290 | |||
| 1291 | $s .= '</td></tr>'; |
||
| 1292 | $lines_count++; |
||
| 1293 | if (($lines_count - 1) == $num_suggestions) { |
||
| 1294 | while (isset($select_items[$lines_count])) { |
||
| 1295 | $s .= <<<HTML |
||
| 1296 | <tr> |
||
| 1297 | <td colspan="2"></td> |
||
| 1298 | <td> |
||
| 1299 | <strong>{$select_items[$lines_count]['letter']}</strong> |
||
| 1300 | {$select_items[$lines_count]['answer']} |
||
| 1301 | </td> |
||
| 1302 | </tr> |
||
| 1303 | HTML; |
||
| 1304 | $lines_count++; |
||
| 1305 | } |
||
| 1306 | } |
||
| 1307 | $matching_correct_answer++; |
||
| 1308 | } |
||
| 1309 | break; |
||
| 1310 | } |
||
| 1311 | } // end for() |
||
| 1312 | |||
| 1313 | if ($show_comment) { |
||
| 1314 | $s .= '</table>'; |
||
| 1315 | } elseif (in_array( |
||
| 1316 | $answerType, |
||
| 1317 | [ |
||
| 1318 | MATCHING, |
||
| 1319 | MATCHING_DRAGGABLE, |
||
| 1320 | UNIQUE_ANSWER_NO_OPTION, |
||
| 1321 | MULTIPLE_ANSWER_TRUE_FALSE, |
||
| 1322 | MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE, |
||
| 1323 | MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY, |
||
| 1324 | ] |
||
| 1325 | )) { |
||
| 1326 | $s .= '</table>'; |
||
| 1327 | } |
||
| 1328 | |||
| 1329 | if ($answerType == DRAGGABLE) { |
||
| 1330 | $isVertical = $objQuestionTmp->extra == 'v'; |
||
| 1331 | |||
| 1332 | $s .= "</ul>"; |
||
| 1333 | $s .= "</div>"; //clearfix |
||
| 1334 | $counterAnswer = 1; |
||
| 1335 | $s .= $isVertical ? '' : '<div class="row">'; |
||
| 1336 | for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { |
||
| 1337 | $answerCorrect = $objAnswerTmp->isCorrect($answerId); |
||
| 1338 | $windowId = $questionId.'_'.$counterAnswer; |
||
| 1339 | if ($answerCorrect) { |
||
| 1340 | $s .= $isVertical ? '<div class="row">' : ''; |
||
| 1341 | $s .= ' |
||
| 1342 | <div class="'.($isVertical ? 'col-md-12' : 'col-xs-12 col-sm-4 col-md-3 col-lg-2').'"> |
||
| 1343 | <div class="droppable-item"> |
||
| 1344 | <span class="number">'.$counterAnswer.'.</span> |
||
| 1345 | <div id="drop_'.$windowId.'" class="droppable"> </div> |
||
| 1346 | </div> |
||
| 1347 | </div> |
||
| 1348 | '; |
||
| 1349 | $s .= $isVertical ? '</div>' : ''; |
||
| 1350 | $counterAnswer++; |
||
| 1351 | } |
||
| 1352 | } |
||
| 1353 | |||
| 1354 | $s .= $isVertical ? '' : '</div>'; // row |
||
| 1355 | $s .= '</div>'; // col-md-12 ui-widget ui-helper-clearfix |
||
| 1356 | } |
||
| 1357 | |||
| 1358 | if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) { |
||
| 1359 | $s .= '</div>'; //drag_question |
||
| 1360 | } |
||
| 1361 | |||
| 1362 | $s .= '</div>'; //question_options row |
||
| 1363 | |||
| 1364 | // destruction of the Answer object |
||
| 1365 | unset($objAnswerTmp); |
||
| 1366 | // destruction of the Question object |
||
| 1367 | unset($objQuestionTmp); |
||
| 1368 | if ($origin == 'export') { |
||
| 1369 | return $s; |
||
| 1370 | } |
||
| 1371 | echo $s; |
||
| 1372 | } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) { |
||
| 1373 | global $exerciseId, $exe_id; |
||
| 1374 | // Question is a HOT_SPOT |
||
| 1375 | //checking document/images visibility |
||
| 1376 | if (api_is_platform_admin() || api_is_course_admin()) { |
||
| 1377 | $doc_id = $objQuestionTmp->getPictureId(); |
||
| 1378 | if (is_numeric($doc_id)) { |
||
| 1379 | $images_folder_visibility = api_get_item_visibility( |
||
| 1380 | $course, |
||
| 1381 | 'document', |
||
| 1382 | $doc_id, |
||
| 1383 | api_get_session_id() |
||
| 1384 | ); |
||
| 1385 | if (!$images_folder_visibility) { |
||
| 1386 | // Show only to the course/platform admin if the image is set to visibility = false |
||
| 1387 | echo Display::return_message( |
||
| 1388 | get_lang('ChangeTheVisibilityOfTheCurrentImage'), |
||
| 1389 | 'warning' |
||
| 1390 | ); |
||
| 1391 | } |
||
| 1392 | } |
||
| 1393 | } |
||
| 1394 | $questionDescription = $objQuestionTmp->selectDescription(); |
||
| 1395 | |||
| 1396 | // Get the answers, make a list |
||
| 1397 | $objAnswerTmp = new Answer($questionId); |
||
| 1398 | $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); |
||
| 1399 | |||
| 1400 | // get answers of hotpost |
||
| 1401 | $answers_hotspot = []; |
||
| 1402 | for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { |
||
| 1403 | $answers = $objAnswerTmp->selectAnswerByAutoId( |
||
| 1404 | $objAnswerTmp->selectAutoId($answerId) |
||
| 1405 | ); |
||
| 1406 | $answers_hotspot[$answers['id']] = $objAnswerTmp->selectAnswer( |
||
| 1407 | $answerId |
||
| 1408 | ); |
||
| 1409 | } |
||
| 1410 | |||
| 1411 | $answerList = ''; |
||
| 1412 | $hotspotColor = 0; |
||
| 1413 | if ($answerType != HOT_SPOT_DELINEATION) { |
||
| 1414 | $answerList = ' |
||
| 1415 | <div class="well well-sm"> |
||
| 1416 | <h5 class="page-header">'.get_lang('HotspotZones').'</h5> |
||
| 1417 | <ol> |
||
| 1418 | '; |
||
| 1419 | |||
| 1420 | if (!empty($answers_hotspot)) { |
||
| 1421 | Session::write("hotspot_ordered$questionId", array_keys($answers_hotspot)); |
||
| 1422 | foreach ($answers_hotspot as $value) { |
||
| 1423 | $answerList .= '<li>'; |
||
| 1424 | if ($freeze) { |
||
| 1425 | $answerList .= '<span class="hotspot-color-'.$hotspotColor |
||
| 1426 | .' fa fa-square" aria-hidden="true"></span>'.PHP_EOL; |
||
| 1427 | } |
||
| 1428 | $answerList .= $value; |
||
| 1429 | $answerList .= '</li>'; |
||
| 1430 | $hotspotColor++; |
||
| 1431 | } |
||
| 1432 | } |
||
| 1433 | |||
| 1434 | $answerList .= ' |
||
| 1435 | </ul> |
||
| 1436 | </div> |
||
| 1437 | '; |
||
| 1438 | if ($freeze) { |
||
| 1439 | $relPath = api_get_path(WEB_CODE_PATH); |
||
| 1440 | echo " |
||
| 1441 | <div class=\"row\"> |
||
| 1442 | <div class=\"col-sm-9\"> |
||
| 1443 | <div id=\"hotspot-preview-$questionId\"></div> |
||
| 1444 | </div> |
||
| 1445 | <div class=\"col-sm-3\"> |
||
| 1446 | $answerList |
||
| 1447 | </div> |
||
| 1448 | </div> |
||
| 1449 | <script> |
||
| 1450 | new ".($answerType == HOT_SPOT ? "HotspotQuestion" : "DelineationQuestion")."({ |
||
| 1451 | questionId: $questionId, |
||
| 1452 | exerciseId: $exerciseId, |
||
| 1453 | exeId: 0, |
||
| 1454 | selector: '#hotspot-preview-$questionId', |
||
| 1455 | for: 'preview', |
||
| 1456 | relPath: '$relPath' |
||
| 1457 | }); |
||
| 1458 | </script> |
||
| 1459 | "; |
||
| 1460 | |||
| 1461 | return; |
||
| 1462 | } |
||
| 1463 | } |
||
| 1464 | |||
| 1465 | if (!$only_questions) { |
||
| 1466 | if ($show_title) { |
||
| 1467 | if ($exercise->display_category_name) { |
||
| 1468 | TestCategory::displayCategoryAndTitle($objQuestionTmp->id); |
||
| 1469 | } |
||
| 1470 | echo $objQuestionTmp->getTitleToDisplay($current_item); |
||
| 1471 | } |
||
| 1472 | //@todo I need to the get the feedback type |
||
| 1473 | echo <<<HOTSPOT |
||
| 1474 | <input type="hidden" name="hidden_hotspot_id" value="$questionId" /> |
||
| 1475 | <div class="exercise_questions"> |
||
| 1476 | $questionDescription |
||
| 1477 | <div class="row"> |
||
| 1478 | HOTSPOT; |
||
| 1479 | } |
||
| 1480 | |||
| 1481 | $relPath = api_get_path(WEB_CODE_PATH); |
||
| 1482 | $s .= "<div class=\"col-sm-8 col-md-9\"> |
||
| 1483 | <div class=\"hotspot-image\"></div> |
||
| 1484 | <script> |
||
| 1485 | $(document).on('ready', function() { |
||
| 1486 | new ".($answerType == HOT_SPOT_DELINEATION ? 'DelineationQuestion' : 'HotspotQuestion')."({ |
||
| 1487 | questionId: $questionId, |
||
| 1488 | exerciseId: $exe_id, |
||
| 1489 | selector: '#question_div_' + $questionId + ' .hotspot-image', |
||
| 1490 | for: 'user', |
||
| 1491 | relPath: '$relPath' |
||
| 1492 | }); |
||
| 1493 | }); |
||
| 1494 | </script> |
||
| 1495 | </div> |
||
| 1496 | <div class=\"col-sm-4 col-md-3\"> |
||
| 1497 | $answerList |
||
| 1498 | </div> |
||
| 1499 | "; |
||
| 1500 | |||
| 1501 | echo <<<HOTSPOT |
||
| 1502 | $s |
||
| 1503 | </div> |
||
| 1504 | </div> |
||
| 1505 | HOTSPOT; |
||
| 1506 | } elseif ($answerType == ANNOTATION) { |
||
| 1507 | global $exe_id; |
||
| 1508 | $relPath = api_get_path(WEB_CODE_PATH); |
||
| 1509 | if (api_is_platform_admin() || api_is_course_admin()) { |
||
| 1510 | $docId = DocumentManager::get_document_id($course, '/images/'.$pictureName); |
||
| 1511 | if ($docId) { |
||
| 1512 | $images_folder_visibility = api_get_item_visibility( |
||
| 1513 | $course, |
||
| 1514 | 'document', |
||
| 1515 | $docId, |
||
| 1516 | api_get_session_id() |
||
| 1517 | ); |
||
| 1518 | |||
| 1519 | if (!$images_folder_visibility) { |
||
| 1520 | echo Display::return_message(get_lang('ChangeTheVisibilityOfTheCurrentImage'), 'warning'); |
||
| 1521 | } |
||
| 1522 | } |
||
| 1523 | |||
| 1524 | if ($freeze) { |
||
| 1525 | echo Display::img( |
||
| 1526 | api_get_path(WEB_COURSE_PATH).$course['path'].'/document/images/'.$pictureName, |
||
| 1527 | $objQuestionTmp->selectTitle(), |
||
| 1528 | ['width' => '600px'] |
||
| 1529 | ); |
||
| 1530 | |||
| 1531 | return 0; |
||
| 1532 | } |
||
| 1533 | } |
||
| 1534 | |||
| 1535 | if (!$only_questions) { |
||
| 1536 | if ($show_title) { |
||
| 1537 | if ($exercise->display_category_name) { |
||
| 1538 | TestCategory::displayCategoryAndTitle($objQuestionTmp->id); |
||
| 1539 | } |
||
| 1540 | echo $objQuestionTmp->getTitleToDisplay($current_item); |
||
| 1541 | } |
||
| 1542 | echo ' |
||
| 1543 | <input type="hidden" name="hidden_hotspot_id" value="'.$questionId.'" /> |
||
| 1544 | <div class="exercise_questions"> |
||
| 1545 | '.$objQuestionTmp->selectDescription().' |
||
| 1546 | <div class="row"> |
||
| 1547 | <div class="col-sm-8 col-md-9"> |
||
| 1548 | <div id="annotation-canvas-'.$questionId.'" class="annotation-canvas center-block"> |
||
| 1549 | </div> |
||
| 1550 | <script> |
||
| 1551 | AnnotationQuestion({ |
||
| 1552 | questionId: '.$questionId.', |
||
| 1553 | exerciseId: '.$exe_id.', |
||
| 1554 | relPath: \''.$relPath.'\', |
||
| 1555 | courseId: '.$course_id.', |
||
| 1556 | }); |
||
| 1557 | </script> |
||
| 1558 | </div> |
||
| 1559 | <div class="col-sm-4 col-md-3"> |
||
| 1560 | <div class="well well-sm" id="annotation-toolbar-'.$questionId.'"> |
||
| 1561 | <div class="btn-toolbar"> |
||
| 1562 | <div class="btn-group" data-toggle="buttons"> |
||
| 1563 | <label class="btn btn-default active" |
||
| 1564 | aria-label="'.get_lang('AddAnnotationPath').'"> |
||
| 1565 | <input |
||
| 1566 | type="radio" value="0" |
||
| 1567 | name="'.$questionId.'-options" autocomplete="off" checked> |
||
| 1568 | <span class="fa fa-pencil" aria-hidden="true"></span> |
||
| 1569 | </label> |
||
| 1570 | <label class="btn btn-default" |
||
| 1571 | aria-label="'.get_lang('AddAnnotationText').'"> |
||
| 1572 | <input |
||
| 1573 | type="radio" value="1" |
||
| 1574 | name="'.$questionId.'-options" autocomplete="off"> |
||
| 1575 | <span class="fa fa-font fa-fw" aria-hidden="true"></span> |
||
| 1576 | </label> |
||
| 1577 | </div> |
||
| 1578 | </div> |
||
| 1579 | <ul class="list-unstyled"></ul> |
||
| 1580 | </div> |
||
| 1581 | </div> |
||
| 1582 | </div> |
||
| 1583 | </div> |
||
| 1584 | '; |
||
| 1585 | } |
||
| 1586 | $objAnswerTmp = new Answer($questionId); |
||
| 1587 | $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); |
||
| 1588 | unset($objAnswerTmp, $objQuestionTmp); |
||
| 1589 | } |
||
| 1590 | |||
| 1591 | return $nbrAnswers; |
||
| 1592 | } |
||
| 5078 |