Passed
Push — master ( 5db41b...b5271b )
by Julito
10:05
created

ExerciseShowFunctions::display_free_answer()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 6
nop 6
dl 0
loc 22
rs 9.6111
c 0
b 0
f 0
1
<?php
2
/* See license terms in /license.txt */
3
4
class ExerciseShowFunctions
5
{
6
    /**
7
     * Shows the answer to a fill-in-the-blanks question, as HTML.
8
     *
9
     * @param Exercise $exercise
10
     * @param int      $feedbackType
11
     * @param string   $answer
12
     * @param int      $id                           Exercise ID
13
     * @param int      $questionId                   Question ID
14
     * @param int      $resultsDisabled
15
     * @param string   $originalStudentAnswer
16
     * @param bool     $showTotalScoreAndUserChoices
17
     */
18
    public static function display_fill_in_blanks_answer(
19
        $exercise,
20
        $feedbackType,
21
        $answer,
22
        $id,
23
        $questionId,
24
        $resultsDisabled,
25
        $originalStudentAnswer = '',
26
        $showTotalScoreAndUserChoices
27
    ) {
28
        $answerHTML = FillBlanks::getHtmlDisplayForAnswer(
29
            $answer,
30
            $feedbackType,
31
            $resultsDisabled,
32
            $showTotalScoreAndUserChoices
33
        );
34
35
        if (empty($id)) {
36
            echo '<tr><td>';
37
            echo Security::remove_XSS($answerHTML, COURSEMANAGERLOWSECURITY);
38
            echo '</td></tr>';
39
        } else {
40
            echo '<tr><td>';
41
            echo Security::remove_XSS($answerHTML, COURSEMANAGERLOWSECURITY);
42
            echo '</td>';
43
            echo '</tr>';
44
        }
45
    }
46
47
    /**
48
     * Shows the answer to a calculated question, as HTML.
49
     *
50
     *  @param Exercise $exercise
51
     * @param string    Answer text
52
     * @param int       Exercise ID
53
     * @param int       Question ID
54
     */
55
    public static function display_calculated_answer(
56
        $exercise,
57
        $feedback_type,
58
        $answer,
59
        $id,
60
        $questionId,
61
        $resultsDisabled,
62
        $showTotalScoreAndUserChoices,
63
        $expectedChoice = '',
64
        $choice = '',
65
        $status = ''
66
    ) {
67
        if ($exercise->showExpectedChoice()) {
68
            if (empty($id)) {
69
                echo '<tr><td>'.Security::remove_XSS($answer).'</td>';
70
                echo '<td>'.Security::remove_XSS($choice).'</td>';
71
                if ($exercise->showExpectedChoiceColumn()) {
72
                    echo '<td>'.Security::remove_XSS($expectedChoice).'</td>';
73
                }
74
75
                echo '<td>'.Security::remove_XSS($status).'</td>';
76
                echo '</tr>';
77
            } else {
78
                echo '<tr><td>';
79
                echo Security::remove_XSS($answer);
80
                echo '</td><td>';
81
                echo Security::remove_XSS($choice);
82
                echo '</td>';
83
                if ($exercise->showExpectedChoiceColumn()) {
84
                    echo '<td>';
85
                    echo Security::remove_XSS($expectedChoice);
86
                    echo '</td>';
87
                }
88
                echo '<td>';
89
                echo Security::remove_XSS($status);
90
                echo '</td>';
91
                echo '</tr>';
92
            }
93
        } else {
94
            if (empty($id)) {
95
                echo '<tr><td>'.Security::remove_XSS($answer).'</td></tr>';
96
            } else {
97
                echo '<tr><td>';
98
                echo Security::remove_XSS($answer);
99
                echo '</tr>';
100
            }
101
        }
102
    }
103
104
    /**
105
     * Shows the answer to a free-answer question, as HTML.
106
     *
107
     * @param string    Answer text
108
     * @param int       Exercise ID
109
     * @param int       Question ID
110
     */
111
    public static function display_free_answer(
112
        $feedback_type,
113
        $answer,
114
        $exe_id,
115
        $questionId,
116
        $questionScore = null,
117
        $resultsDisabled = 0
118
    ) {
119
        $comments = Event::get_comments($exe_id, $questionId);
0 ignored issues
show
Bug introduced by
The method get_comments() does not exist on Event. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

119
        /** @scrutinizer ignore-call */ 
120
        $comments = Event::get_comments($exe_id, $questionId);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
120
121
        if (!empty($answer)) {
122
            echo '<tr><td>';
123
            echo Security::remove_XSS($answer);
124
            echo '</td></tr>';
125
        }
126
127
        if (EXERCISE_FEEDBACK_TYPE_EXAM != $feedback_type) {
128
            if ($questionScore > 0 || !empty($comments)) {
129
            } else {
130
                echo '<tr>';
131
                echo Display::tag('td', ExerciseLib::getNotCorrectedYetText());
132
                echo '</tr>';
133
            }
134
        }
135
    }
136
137
    /**
138
     * @param $feedback_type
139
     * @param $answer
140
     * @param $id
141
     * @param $questionId
142
     * @param null $fileUrl
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fileUrl is correct as it would always require null to be passed?
Loading history...
143
     * @param int  $resultsDisabled
144
     * @param int  $questionScore
145
     */
146
    public static function display_oral_expression_answer(
147
        $feedback_type,
148
        $answer,
149
        $id,
150
        $questionId,
151
        $fileUrl = null,
152
        $resultsDisabled = 0,
153
        $questionScore = 0
154
    ) {
155
        if (isset($fileUrl)) {
156
            echo '
157
                <tr>
158
                    <td><audio src="'.$fileUrl.'" controls></audio></td>
159
                </tr>
160
            ';
161
        }
162
163
        if (empty($id)) {
164
            echo '<tr>';
165
            if (!empty($answer)) {
166
                echo Display::tag('td', Security::remove_XSS($answer), ['width' => '55%']);
167
            }
168
            echo '</tr>';
169
            if (!$questionScore && EXERCISE_FEEDBACK_TYPE_EXAM != $feedback_type) {
170
                echo '<tr>';
171
                echo Display::tag('td', ExerciseLib::getNotCorrectedYetText(), ['width' => '45%']);
172
                echo '</tr>';
173
            } else {
174
                echo '<tr><td>&nbsp;</td></tr>';
175
            }
176
        } else {
177
            echo '<tr>';
178
            echo '<td>';
179
            if (!empty($answer)) {
180
                echo Security::remove_XSS($answer);
181
            }
182
            echo '</td>';
183
            echo '</tr>';
184
        }
185
    }
186
187
    /**
188
     * Displays the answer to a hotspot question.
189
     *
190
     * @param int    $feedback_type
191
     * @param int    $answerId
192
     * @param string $answer
193
     * @param string $studentChoice
194
     * @param string $answerComment
195
     * @param int    $resultsDisabled
196
     * @param int    $orderColor
197
     * @param bool   $showTotalScoreAndUserChoices
198
     */
199
    public static function display_hotspot_answer(
200
        $exercise,
201
        $feedback_type,
202
        $answerId,
203
        $answer,
204
        $studentChoice,
205
        $answerComment,
206
        $resultsDisabled,
207
        $orderColor,
208
        $showTotalScoreAndUserChoices
209
    ) {
210
        $hide_expected_answer = false;
211
        switch ($resultsDisabled) {
212
            case RESULT_DISABLE_SHOW_SCORE_ONLY:
213
                if (0 == $feedback_type) {
214
                    $hide_expected_answer = true;
215
                }
216
                break;
217
            case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
218
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
219
                $hide_expected_answer = true;
220
                if ($showTotalScoreAndUserChoices) {
221
                    $hide_expected_answer = false;
222
                }
223
                break;
224
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK:
225
                $hide_expected_answer = true;
226
                if ($showTotalScoreAndUserChoices) {
227
                    $hide_expected_answer = false;
228
                }
229
                if (false === $showTotalScoreAndUserChoices && empty($studentChoice)) {
230
                    return '';
231
                }
232
                break;
233
        }
234
235
        if (!$hide_expected_answer
236
            && !$studentChoice
237
            && in_array($resultsDisabled, [RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER])
238
        ) {
239
            return;
240
        }
241
242
        $hotspotColors = [
243
            '', // $i starts from 1 on next loop (ugly fix)
244
            '#4271B5',
245
            '#FE8E16',
246
            '#45C7F0',
247
            '#BCD631',
248
            '#D63173',
249
            '#D7D7D7',
250
            '#90AFDD',
251
            '#AF8640',
252
            '#4F9242',
253
            '#F4EB24',
254
            '#ED2024',
255
            '#3B3B3B',
256
            '#F7BDE2',
257
        ];
258
259
        $content = '<tr>';
260
        $content .= '<td class="text-center" width="5%">';
261
        $content .= '<span class="fa fa-square fa-fw fa-2x" aria-hidden="true" style="color:'.
262
            $hotspotColors[$orderColor].'"></span>';
263
        $content .= '</td>';
264
        $content .= '<td class="text-left" width="25%">';
265
        $content .= "$answerId - $answer";
266
        $content .= '</td>';
267
        if (false === $exercise->hideComment) {
268
        $content .= '<td class="text-left" width="10%">';
269
        if (!$hide_expected_answer) {
270
            $status = Display::label(get_lang('Incorrect'), 'danger');
271
            if ($studentChoice) {
272
                $status = Display::label(get_lang('Correct'), 'success');
273
            }
274
            $content .= $status;
275
            } else {
276
                $content .= '&nbsp;';
277
        }
278
        $content .= '</td>';
279
        if (EXERCISE_FEEDBACK_TYPE_EXAM != $feedback_type) {
280
            $content .= '<td class="text-left" width="60%">';
281
            if ($studentChoice) {
282
                $content .= '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
283
                } else {
284
                    $content .= '&nbsp;';
285
            }
286
            $content .= '</td>';
287
        } else {
288
            $content .= '<td class="text-left" width="60%">&nbsp;</td>';
289
        }
290
        }
291
        $content .= '</tr>';
292
293
        echo $content;
294
    }
295
296
    /**
297
     * Display the answers to a multiple choice question.
298
     *
299
     * @param Exercise $exercise
300
     * @param int      $feedbackType                 Feedback type
301
     * @param int      $answerType                   Answer type
302
     * @param int      $studentChoice                Student choice
303
     * @param string   $answer                       Textual answer
304
     * @param string   $answerComment                Comment on answer
305
     * @param string   $answerCorrect                Correct answer comment
306
     * @param int      $id                           Exercise ID
307
     * @param int      $questionId                   Question ID
308
     * @param bool     $ans                          Whether to show the answer comment or not
309
     * @param bool     $resultsDisabled
310
     * @param bool     $showTotalScoreAndUserChoices
311
     * @param bool     $export
312
     */
313
    public static function display_unique_or_multiple_answer(
314
        $exercise,
315
        $feedbackType,
316
        $answerType,
317
        $studentChoice,
318
        $answer,
319
        $answerComment,
320
        $answerCorrect,
321
        $id,
322
        $questionId,
323
        $ans,
324
        $resultsDisabled,
325
        $showTotalScoreAndUserChoices,
326
        $export = false
327
    ) {
328
        if (true === $exercise->hideNoAnswer && empty($studentChoice)) {
329
            return '';
330
        }
331
        if ($export) {
332
            $answer = strip_tags_blacklist($answer, ['title', 'head']);
333
            // Fix answers that contains this tags
334
            $tags = [
335
                '<html>',
336
                '</html>',
337
                '<body>',
338
                '</body>',
339
            ];
340
            $answer = str_replace($tags, '', $answer);
341
        }
342
343
        $studentChoiceInt = (int) $studentChoice;
344
        $answerCorrectChoice = (int) $answerCorrect;
345
        $hide_expected_answer = false;
346
        $showComment = false;
347
        switch ($resultsDisabled) {
348
            case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
349
                $hide_expected_answer = true;
350
                $showComment = true;
351
                if (!$answerCorrect && empty($studentChoice)) {
352
                    return '';
353
                }
354
                break;
355
            case RESULT_DISABLE_SHOW_SCORE_ONLY:
356
                if (0 == $feedbackType) {
357
                    $hide_expected_answer = true;
358
                }
359
                break;
360
            case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
361
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
362
                $hide_expected_answer = true;
363
                if ($showTotalScoreAndUserChoices) {
364
                    $hide_expected_answer = false;
365
                }
366
                break;
367
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK:
368
                if (false === $showTotalScoreAndUserChoices && empty($studentChoiceInt)) {
369
                    return '';
370
                }
371
                break;
372
        }
373
374
        $icon = in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION]) ? 'radio' : 'checkbox';
375
        $icon .= $studentChoice ? '_on' : '_off';
376
        $icon .= '.png';
377
        $iconAnswer = in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION]) ? 'radio' : 'checkbox';
378
        $iconAnswer .= $answerCorrect ? '_on' : '_off';
379
        $iconAnswer .= '.png';
380
381
        $studentChoiceClass = '';
382
        if (in_array(
383
            $resultsDisabled,
384
            [
385
                RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
386
                RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
387
            ]
388
        )
389
        ) {
390
            if ($answerCorrect) {
391
                $studentChoiceClass = 'success';
392
            }
393
        }
394
395
        echo '<tr class="'.$studentChoiceClass.'">';
396
397
        echo '<td width="5%">';
398
        echo Display::return_icon($icon, null, null, ICON_SIZE_TINY);
399
        echo '</td>';
400
        if ($exercise->showExpectedChoiceColumn()) {
401
            if (false === $hide_expected_answer) {
402
                echo '<td width="5%">';
403
                echo Display::return_icon($iconAnswer, null, null, ICON_SIZE_TINY);
404
                echo '</td>';
405
            } else {
406
                echo '<td width="5%">';
407
                echo '-';
408
                echo '</td>';
409
            }
410
        }
411
412
        echo '<td width="40%">';
413
        echo $answer;
414
        echo '</td>';
415
416
        if ($exercise->showExpectedChoice()) {
417
            $status = Display::label(get_lang('Incorrect'), 'danger');
418
            if ($answerCorrect || ($answerCorrect && $studentChoiceInt === $answerCorrectChoice)) {
419
                $status = Display::label(get_lang('Correct'), 'success');
420
            }
421
            echo '<td width="20%">';
422
            // Show only status for the selected student answer BT#16256
423
            if ($studentChoice) {
424
                echo $status;
425
            }
426
427
            echo '</td>';
428
        }
429
430
        if (EXERCISE_FEEDBACK_TYPE_EXAM != $feedbackType) {
431
            $showComment = true;
432
        }
433
434
        if (false === $exercise->hideComment) {
435
        if ($showComment) {
436
            echo '<td width="20%">';
437
            $color = 'black';
438
            if ($answerCorrect) {
439
                $color = 'green';
440
            }
441
            if ($hide_expected_answer) {
442
                $color = '';
443
            }
444
            $comment = '<span style="font-weight: bold; color: '.$color.';">'.
445
                Security::remove_XSS($answerComment).
446
                '</span>';
447
            echo $comment;
448
            echo '</td>';
449
        } else {
450
            echo '<td>&nbsp;</td>';
451
        }
452
        }
453
454
        echo '</tr>';
455
    }
456
457
    /**
458
     * Display the answers to a multiple choice question.
459
     *
460
     * @param Exercise $exercise
461
     * @param int Answer type
462
     * @param int Student choice
463
     * @param string  Textual answer
464
     * @param string  Comment on answer
465
     * @param string  Correct answer comment
466
     * @param int Exercise ID
467
     * @param int Question ID
468
     * @param bool Whether to show the answer comment or not
469
     */
470
    public static function display_multiple_answer_true_false(
471
        $exercise,
472
        $feedbackType,
473
        $answerType,
474
        $studentChoice,
475
        $answer,
476
        $answerComment,
477
        $answerCorrect,
478
        $id,
479
        $questionId,
480
        $ans,
481
        $resultsDisabled,
482
        $showTotalScoreAndUserChoices
483
    ) {
484
        $hide_expected_answer = false;
485
        $hideStudentChoice = false;
486
        switch ($resultsDisabled) {
487
            //case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING:
488
            case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
489
                $hideStudentChoice = false;
490
                $hide_expected_answer = true;
491
                break;
492
            case RESULT_DISABLE_SHOW_SCORE_ONLY:
493
                if (0 == $feedbackType) {
494
                    $hide_expected_answer = true;
495
                }
496
                break;
497
            case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
498
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
499
                $hide_expected_answer = true;
500
                if ($showTotalScoreAndUserChoices) {
501
                    $hide_expected_answer = false;
502
                }
503
                break;
504
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK:
505
                if (false === $showTotalScoreAndUserChoices && empty($studentChoice)) {
506
                    return '';
507
                }
508
                break;
509
        }
510
511
        $content = '<tr>';
512
        if (false === $hideStudentChoice) {
513
            $content .= '<td width="5%">';
514
            $course_id = api_get_course_int_id();
515
            $new_options = Question::readQuestionOption($questionId, $course_id);
516
            // Your choice
517
            if (isset($new_options[$studentChoice])) {
518
                $content .= get_lang($new_options[$studentChoice]['name']);
519
            } else {
520
                $content .= '-';
521
            }
522
            $content .= '</td>';
523
        }
524
525
        // Expected choice
526
        if ($exercise->showExpectedChoiceColumn()) {
527
            if (!$hide_expected_answer) {
528
                $content .= '<td width="5%">';
529
                if (isset($new_options[$answerCorrect])) {
530
                    $content .= get_lang($new_options[$answerCorrect]['name']);
531
                } else {
532
                    $content .= '-';
533
                }
534
                $content .= '</td>';
535
            }
536
        }
537
538
        $content .= '<td width="40%">';
539
        $content .= $answer;
540
        $content .= '</td>';
541
542
        if ($exercise->showExpectedChoice()) {
543
            $status = Display::label(get_lang('Incorrect'), 'danger');
544
            if (isset($new_options[$studentChoice])) {
545
                if ($studentChoice == $answerCorrect) {
546
                    $status = Display::label(get_lang('Correct'), 'success');
547
                }
548
            }
549
            $content .= '<td width="20%">';
550
            $content .= $status;
551
            $content .= '</td>';
552
        }
553
554
        if (false === $exercise->hideComment) {
555
        if (EXERCISE_FEEDBACK_TYPE_EXAM != $feedbackType) {
556
            $content .= '<td width="20%">';
557
            $color = 'black';
558
            if (isset($new_options[$studentChoice]) || in_array(
559
                    $exercise->results_disabled,
560
                    [
561
                        RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
562
                        RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
563
                    ]
564
                )
565
            ) {
566
                if ($studentChoice == $answerCorrect) {
567
                    $color = 'green';
568
                }
569
570
                if ($hide_expected_answer) {
571
                    $color = '';
572
                }
573
                $content .= '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
574
            }
575
            $content .= '</td>';
576
        }
577
        }
578
        $content .= '</tr>';
579
580
        echo $content;
581
    }
582
583
    /**
584
     * Display the answers to a multiple choice question.
585
     *
586
     * @param Exercise $exercise
587
     * @param int      $feedbackType
588
     * @param int      $studentChoice
589
     * @param int      $studentChoiceDegree
590
     * @param string   $answer
591
     * @param string   $answerComment
592
     * @param int      $answerCorrect
593
     * @param int      $questionId
594
     * @param bool     $inResultsDisabled
595
     */
596
    public static function displayMultipleAnswerTrueFalseDegreeCertainty(
597
        $exercise,
598
        $feedbackType,
599
        $studentChoice,
600
        $studentChoiceDegree,
601
        $answer,
602
        $answerComment,
603
        $answerCorrect,
604
        $questionId,
605
        $inResultsDisabled
606
    ) {
607
        $hideExpectedAnswer = false;
608
        if (0 == $feedbackType && 2 == $inResultsDisabled) {
609
            $hideExpectedAnswer = true;
610
        }
611
612
        echo '<tr><td width="5%">';
613
        $question = new MultipleAnswerTrueFalseDegreeCertainty();
614
        $courseId = api_get_course_int_id();
615
        $newOptions = Question::readQuestionOption($questionId, $courseId);
616
617
        // Your choice
618
        if (isset($newOptions[$studentChoice])) {
619
            echo get_lang($newOptions[$studentChoice]['name']);
620
        } else {
621
            echo '-';
622
        }
623
        echo '</td>';
624
625
        // Expected choice
626
        if ($exercise->showExpectedChoiceColumn()) {
627
            echo '<td width="5%">';
628
            if (!$hideExpectedAnswer) {
629
                if (isset($newOptions[$answerCorrect])) {
630
                    echo get_lang($newOptions[$answerCorrect]['name']);
631
                } else {
632
                    echo '-';
633
                }
634
            } else {
635
                echo '-';
636
            }
637
            echo '</td>';
638
        }
639
640
        echo '<td width="20%">';
641
        echo $answer;
642
        echo '</td><td width="5%" style="text-align:center;">';
643
        if (isset($newOptions[$studentChoiceDegree])) {
644
            echo $newOptions[$studentChoiceDegree]['name'];
645
        }
646
        echo '</td>';
647
648
        $position = isset($newOptions[$studentChoiceDegree]) ? $newOptions[$studentChoiceDegree]['position'] : '';
649
        $degreeInfo = $question->getResponseDegreeInfo(
650
            $studentChoice,
651
            $answerCorrect,
652
            $position
653
        );
654
655
        $degreeInfo['color'] = isset($degreeInfo['color']) ? $degreeInfo['color'] : '';
656
        $degreeInfo['background-color'] = isset($degreeInfo['background-color']) ? $degreeInfo['background-color'] : '';
657
        $degreeInfo['description'] = isset($degreeInfo['description']) ? $degreeInfo['description'] : '';
658
        $degreeInfo['label'] = isset($degreeInfo['label']) ? $degreeInfo['label'] : '';
659
660
        echo '
661
            <td width="15%">
662
                <div style="text-align:center;color: '.$degreeInfo['color'].';
663
                    background-color: '.$degreeInfo['background-color'].';
664
                    line-height:30px;height:30px;width: 100%;margin:auto;"
665
                    title="'.$degreeInfo['description'].'">'.
666
                    nl2br($degreeInfo['label']).
667
                '</div>
668
            </td>';
669
670
        if (false === $exercise->hideComment) {
671
        if (EXERCISE_FEEDBACK_TYPE_EXAM != $feedbackType) {
672
            echo '<td width="20%">';
673
            if (isset($newOptions[$studentChoice])) {
674
                echo '<span style="font-weight: bold; color: black;">'.nl2br($answerComment).'</span>';
675
            }
676
            echo '</td>';
677
        } else {
678
            echo '<td>&nbsp;</td>';
679
        }
680
        }
681
        echo '</tr>';
682
    }
683
684
    /**
685
     * Display the answers to a multiple choice question.
686
     *
687
     * @param Exercise $exercise
688
     * @param int Answer type
689
     * @param int Student choice
690
     * @param string  Textual answer
691
     * @param string  Comment on answer
692
     * @param string  Correct answer comment
693
     * @param int Exercise ID
694
     * @param int Question ID
695
     * @param bool Whether to show the answer comment or not
696
     */
697
    public static function display_multiple_answer_combination_true_false(
698
        $exercise,
699
        $feedbackType,
700
        $answerType,
701
        $studentChoice,
702
        $answer,
703
        $answerComment,
704
        $answerCorrect,
705
        $id,
706
        $questionId,
707
        $ans,
708
        $resultsDisabled,
709
        $showTotalScoreAndUserChoices
710
    ) {
711
        $hide_expected_answer = false;
712
        $hideStudentChoice = false;
713
        switch ($resultsDisabled) {
714
            case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING:
715
            case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
716
                $hideStudentChoice = true;
717
                $hide_expected_answer = true;
718
                break;
719
            case RESULT_DISABLE_SHOW_SCORE_ONLY:
720
                if (0 == $feedbackType) {
721
                    $hide_expected_answer = true;
722
                }
723
                break;
724
            case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
725
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
726
                $hide_expected_answer = true;
727
                if ($showTotalScoreAndUserChoices) {
728
                    $hide_expected_answer = false;
729
                }
730
                break;
731
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK:
732
                if (false === $showTotalScoreAndUserChoices && empty($studentChoice)) {
733
                    return '';
734
                }
735
                break;
736
        }
737
738
        echo '<tr>';
739
740
        if (false === $hideStudentChoice) {
741
            echo '<td width="5%">';
742
            // Your choice
743
            $question = new MultipleAnswerCombinationTrueFalse();
744
            if (isset($question->options[$studentChoice])) {
745
                echo $question->options[$studentChoice];
746
            } else {
747
                echo $question->options[2];
748
            }
749
            echo '</td>';
750
        }
751
752
        // Expected choice
753
        if ($exercise->showExpectedChoiceColumn()) {
754
            if (!$hide_expected_answer) {
755
                echo '<td width="5%">';
756
                if (isset($question->options[$answerCorrect])) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $question does not seem to be defined for all execution paths leading up to this point.
Loading history...
757
                    echo $question->options[$answerCorrect];
758
                } else {
759
                    echo $question->options[2];
760
                }
761
                echo '</td>';
762
            }
763
        }
764
765
        echo '<td width="40%">';
766
        echo $answer;
767
        echo '</td>';
768
769
        if ($exercise->showExpectedChoice()) {
770
            $status = '';
771
            if (isset($studentChoice)) {
772
                $status = Display::label(get_lang('Incorrect'), 'danger');
773
                if ($studentChoice == $answerCorrect) {
774
                    $status = Display::label(get_lang('Correct'), 'success');
775
                }
776
            }
777
            echo '<td width="20%">';
778
            echo $status;
779
            echo '</td>';
780
        }
781
782
        if (false === $exercise->hideComment) {
783
        if (EXERCISE_FEEDBACK_TYPE_EXAM != $feedbackType) {
784
            echo '<td width="20%">';
785
            //@todo replace this harcoded value
786
                if ($studentChoice || in_array(
787
                        $resultsDisabled,
788
                        [
789
                RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
790
                RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
791
                        ]
792
                    )
793
            ) {
794
                $color = 'black';
795
                if ($studentChoice == $answerCorrect) {
796
                    $color = 'green';
797
                }
798
                if ($hide_expected_answer) {
799
                    $color = '';
800
                }
801
                echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
802
            }
803
            echo '</td>';
804
        } else {
805
            echo '<td>&nbsp;</td>';
806
            }
807
        }
808
        echo '</tr>';
809
    }
810
811
    /**
812
     * @param int  $feedbackType
813
     * @param int  $exeId
814
     * @param int  $questionId
815
     * @param null $questionScore
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $questionScore is correct as it would always require null to be passed?
Loading history...
816
     * @param int  $resultsDisabled
817
     */
818
    public static function displayAnnotationAnswer(
819
        $feedbackType,
820
        $exeId,
821
        $questionId,
822
        $questionScore = null,
823
        $resultsDisabled = 0
824
    ) {
825
        $comments = Event::get_comments($exeId, $questionId);
826
        if (EXERCISE_FEEDBACK_TYPE_EXAM != $feedbackType) {
827
            if ($questionScore <= 0 && empty($comments)) {
828
                echo '<br />'.ExerciseLib::getNotCorrectedYetText();
829
            }
830
        }
831
    }
832
}
833