Passed
Push — master ( 447a4c...2f567c )
by Julito
09:40
created

ExerciseShowFunctions::display_calculated_answer()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 45
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 29
nc 6
nop 10
dl 0
loc 45
rs 8.8337
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

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
2
/* See license terms in /license.txt */
3
/**
4
 * EVENTS LIBRARY.
5
 *
6
 * This is the events library for Chamilo.
7
 * Functions of this library are used to record informations when some kind
8
 * of event occur. Each event has his own types of informations then each event
9
 * use its own function.
10
 *
11
 * @package chamilo.library
12
 *
13
 * @todo convert queries to use Database API
14
 */
15
/**
16
 * Class.
17
 *
18
 * @package chamilo.library
19
 */
20
class ExerciseShowFunctions
21
{
22
    /**
23
     * Shows the answer to a fill-in-the-blanks question, as HTML.
24
     *
25
     * @param Exercise $exercise
26
     * @param int      $feedbackType
27
     * @param string   $answer
28
     * @param int      $id                           Exercise ID
29
     * @param int      $questionId                   Question ID
30
     * @param int      $resultsDisabled
31
     * @param string   $originalStudentAnswer
32
     * @param bool     $showTotalScoreAndUserChoices
33
     */
34
    public static function display_fill_in_blanks_answer(
35
        $exercise,
36
        $feedbackType,
37
        $answer,
38
        $id,
39
        $questionId,
40
        $resultsDisabled,
41
        $originalStudentAnswer = '',
42
        $showTotalScoreAndUserChoices
43
    ) {
44
        $answerHTML = FillBlanks::getHtmlDisplayForAnswer(
45
            $answer,
46
            $feedbackType,
47
            $resultsDisabled,
48
            $showTotalScoreAndUserChoices
49
        );
50
51
        if (empty($id)) {
52
            echo '<tr><td>';
53
            echo Security::remove_XSS($answerHTML, COURSEMANAGERLOWSECURITY);
54
            echo '</td></tr>';
55
        } else {
56
            echo '<tr><td>';
57
            echo Security::remove_XSS($answerHTML, COURSEMANAGERLOWSECURITY);
58
            echo '</td>';
59
            echo '</tr>';
60
        }
61
    }
62
63
    /**
64
     * Shows the answer to a calculated question, as HTML.
65
     *
66
     *  @param Exercise $exercise
67
     * @param string    Answer text
68
     * @param int       Exercise ID
69
     * @param int       Question ID
70
     */
71
    public static function display_calculated_answer(
72
        $exercise,
73
        $feedback_type,
74
        $answer,
75
        $id,
76
        $questionId,
77
        $resultsDisabled,
78
        $showTotalScoreAndUserChoices,
79
        $expectedChoice = '',
80
        $choice = '',
81
        $status = ''
82
    ) {
83
        if ($exercise->showExpectedChoice()) {
84
            if (empty($id)) {
85
                echo '<tr><td>'.Security::remove_XSS($answer).'</td>';
86
                echo '<td>'.Security::remove_XSS($choice).'</td>';
87
                if ($exercise->showExpectedChoiceColumn()) {
88
                    echo '<td>'.Security::remove_XSS($expectedChoice).'</td>';
89
                }
90
91
                echo '<td>'.Security::remove_XSS($status).'</td>';
92
                echo '</tr>';
93
            } else {
94
                echo '<tr><td>';
95
                echo Security::remove_XSS($answer);
96
                echo '</td><td>';
97
                echo Security::remove_XSS($choice);
98
                echo '</td>';
99
                if ($exercise->showExpectedChoiceColumn()) {
100
                    echo '<td>';
101
                    echo Security::remove_XSS($expectedChoice);
102
                    echo '</td>';
103
                }
104
                echo '<td>';
105
                echo Security::remove_XSS($status);
106
                echo '</td>';
107
                echo '</tr>';
108
            }
109
        } else {
110
            if (empty($id)) {
111
                echo '<tr><td>'.Security::remove_XSS($answer).'</td></tr>';
112
            } else {
113
                echo '<tr><td>';
114
                echo Security::remove_XSS($answer);
115
                echo '</tr>';
116
            }
117
        }
118
    }
119
120
    /**
121
     * Shows the answer to a free-answer question, as HTML.
122
     *
123
     * @param string    Answer text
124
     * @param int       Exercise ID
125
     * @param int       Question ID
126
     */
127
    public static function display_free_answer(
128
        $feedback_type,
129
        $answer,
130
        $exe_id,
131
        $questionId,
132
        $questionScore = null,
133
        $resultsDisabled = 0
134
    ) {
135
        $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

135
        /** @scrutinizer ignore-call */ 
136
        $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...
136
137
        if (!empty($answer)) {
138
            echo '<tr><td>';
139
            echo Security::remove_XSS($answer);
140
            echo '</td></tr>';
141
        }
142
143
        if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
144
            if ($questionScore > 0 || !empty($comments)) {
145
            } else {
146
                echo '<tr>';
147
                echo Display::tag('td', ExerciseLib::getNotCorrectedYetText());
148
                echo '</tr>';
149
            }
150
        }
151
    }
152
153
    /**
154
     * @param $feedback_type
155
     * @param $answer
156
     * @param $id
157
     * @param $questionId
158
     * @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...
159
     * @param int  $resultsDisabled
160
     * @param int  $questionScore
161
     */
162
    public static function display_oral_expression_answer(
163
        $feedback_type,
164
        $answer,
165
        $id,
166
        $questionId,
167
        $fileUrl = null,
168
        $resultsDisabled = 0,
169
        $questionScore = 0
170
    ) {
171
        if (isset($fileUrl)) {
172
            echo '
173
                <tr>
174
                    <td><audio src="'.$fileUrl.'" controls></audio></td>
175
                </tr>
176
            ';
177
        }
178
179
        if (empty($id)) {
180
            echo '<tr>';
181
            if (!empty($answer)) {
182
                echo Display::tag('td', Security::remove_XSS($answer), ['width' => '55%']);
183
            }
184
            echo '</tr>';
185
            if (!$questionScore && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
186
                echo '<tr>';
187
                echo Display::tag('td', ExerciseLib::getNotCorrectedYetText(), ['width' => '45%']);
188
                echo '</tr>';
189
            } else {
190
                echo '<tr><td>&nbsp;</td></tr>';
191
            }
192
        } else {
193
            echo '<tr>';
194
            echo '<td>';
195
            if (!empty($answer)) {
196
                echo Security::remove_XSS($answer);
197
            }
198
            echo '</td>';
199
            echo '</tr>';
200
        }
201
    }
202
203
    /**
204
     * Displays the answer to a hotspot question.
205
     *
206
     * @param int    $feedback_type
207
     * @param int    $answerId
208
     * @param string $answer
209
     * @param string $studentChoice
210
     * @param string $answerComment
211
     * @param int    $resultsDisabled
212
     * @param int    $orderColor
213
     * @param bool   $showTotalScoreAndUserChoices
214
     */
215
    public static function display_hotspot_answer(
216
        $feedback_type,
217
        $answerId,
218
        $answer,
219
        $studentChoice,
220
        $answerComment,
221
        $resultsDisabled,
222
        $orderColor,
223
        $showTotalScoreAndUserChoices
224
    ) {
225
        $hide_expected_answer = false;
226
        switch ($resultsDisabled) {
227
            case RESULT_DISABLE_SHOW_SCORE_ONLY:
228
                if ($feedback_type == 0) {
229
                    $hide_expected_answer = true;
230
                }
231
                break;
232
            case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
233
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
234
                $hide_expected_answer = true;
235
                if ($showTotalScoreAndUserChoices) {
236
                    $hide_expected_answer = false;
237
                }
238
                break;
239
        }
240
241
        $hotspot_colors = [
242
            '', // $i starts from 1 on next loop (ugly fix)
243
            '#4271B5',
244
            '#FE8E16',
245
            '#45C7F0',
246
            '#BCD631',
247
            '#D63173',
248
            '#D7D7D7',
249
            '#90AFDD',
250
            '#AF8640',
251
            '#4F9242',
252
            '#F4EB24',
253
            '#ED2024',
254
            '#3B3B3B',
255
            '#F7BDE2',
256
        ];
257
258
        $content = '<table class="data_table"><tr>';
259
        $content .= '<td class="text-center" width="5%">';
260
        $content .= '<span class="fa fa-square fa-fw fa-2x" aria-hidden="true" style="color:'.
261
            $hotspot_colors[$orderColor].'"></span>';
262
        $content .= '</td>';
263
        $content .= '<td class="text-left" width="25%">';
264
        $content .= "$answerId - $answer";
265
        $content .= '</td>';
266
        $content .= '<td class="text-left" width="10%">';
267
        if (!$hide_expected_answer) {
268
            $status = Display::label(get_lang('Incorrect'), 'danger');
269
            if ($studentChoice) {
270
                $status = Display::label(get_lang('Correct'), 'success');
271
            } else {
272
                if (in_array($resultsDisabled, [
273
                    RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
274
                ])
275
                ) {
276
                    return '';
277
                }
278
            }
279
            $content .= $status;
280
        }
281
        $content .= '</td>';
282
        if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
283
            $content .= '<td class="text-left" width="60%">';
284
            if ($studentChoice) {
285
                $content .= '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
286
            }
287
            $content .= '</td>';
288
        } else {
289
            $content .= '<td class="text-left" width="60%">&nbsp;</td>';
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 ($export) {
329
            $answer = strip_tags_blacklist($answer, ['title', 'head']);
330
            // Fix answers that contains this tags
331
            $tags = [
332
                '<html>',
333
                '</html>',
334
                '<body>',
335
                '</body>',
336
            ];
337
            $answer = str_replace($tags, '', $answer);
338
        }
339
340
        $studentChoiceInt = (int) $studentChoice;
341
        $answerCorrectChoice = (int) $answerCorrect;
342
        $hideStudentChoice = false;
343
        $hide_expected_answer = false;
344
345
        $status = '';
346
        if ($exercise->showExpectedChoice()) {
347
            $status = Display::label(get_lang('Incorrect'), 'danger');
348
            if ($answerCorrect || ($answerCorrect && $studentChoiceInt === $answerCorrectChoice)) {
349
                $status = Display::label(get_lang('Correct'), 'success');
350
            }
351
        }
352
353
        $showComment = false;
354
        switch ($resultsDisabled) {
355
            case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
356
                $hideStudentChoice = false;
357
                $hide_expected_answer = true;
358
                $status = Display::label(get_lang('Correct'), 'success');
359
                $showComment = true;
360
                if (!$answerCorrect && empty($studentChoice)) {
361
                    return '';
362
                }
363
                break;
364
            case RESULT_DISABLE_SHOW_SCORE_ONLY:
365
                if ($feedbackType == 0) {
366
                    $hide_expected_answer = true;
367
                }
368
                break;
369
            case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
370
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
371
                $hide_expected_answer = true;
372
                if ($showTotalScoreAndUserChoices) {
373
                    $hide_expected_answer = false;
374
                }
375
                break;
376
        }
377
378
        $icon = in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION]) ? 'radio' : 'checkbox';
379
        $icon .= $studentChoice ? '_on' : '_off';
380
        $icon .= '.png';
381
        $iconAnswer = in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION]) ? 'radio' : 'checkbox';
382
        $iconAnswer .= $answerCorrect ? '_on' : '_off';
383
        $iconAnswer .= '.png';
384
385
        $studentChoiceClass = '';
386
        if (in_array(
387
            $resultsDisabled,
388
            [
389
                RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
390
                RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
391
            ]
392
        )
393
        ) {
394
            if ($answerCorrect) {
395
                $studentChoiceClass = 'success';
396
            }
397
        }
398
399
        echo '<tr class="'.$studentChoiceClass.'">';
400
        if ($hideStudentChoice === false) {
401
            echo '<td width="5%">';
402
            echo Display::return_icon($icon, null, null, ICON_SIZE_TINY);
403
            echo '</td>';
404
        }
405
406
        if (!$hide_expected_answer) {
407
            if ($exercise->showExpectedChoiceColumn()) {
408
                echo '<td width="5%">';
409
                echo Display::return_icon($iconAnswer, null, null, ICON_SIZE_TINY);
410
                echo '</td>';
411
            }
412
        }
413
414
        echo '<td width="40%">';
415
        echo $answer;
416
        echo '</td>';
417
418
        if ($exercise->showExpectedChoice()) {
419
            echo '<td width="20%">';
420
            echo $status;
421
            echo '</td>';
422
        }
423
424
        if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
425
            $showComment = true;
426
        }
427
428
        if ($showComment) {
429
            echo '<td width="20%">';
430
            $color = 'black';
431
            if ($answerCorrect) {
432
                $color = 'green';
433
            }
434
            if ($hide_expected_answer) {
435
                $color = '';
436
            }
437
            $comment = '<span style="font-weight: bold; color: '.$color.';">'.
438
                Security::remove_XSS($answerComment).
439
                '</span>';
440
            echo $comment;
441
            echo '</td>';
442
        } else {
443
            echo '<td>&nbsp;</td>';
444
        }
445
446
        echo '</tr>';
447
    }
448
449
    /**
450
     * Display the answers to a multiple choice question.
451
     *
452
     * @param Exercise $exercise
453
     * @param int Answer type
454
     * @param int Student choice
455
     * @param string  Textual answer
456
     * @param string  Comment on answer
457
     * @param string  Correct answer comment
458
     * @param int Exercise ID
459
     * @param int Question ID
460
     * @param bool Whether to show the answer comment or not
461
     */
462
    public static function display_multiple_answer_true_false(
463
        $exercise,
464
        $feedbackType,
465
        $answerType,
466
        $studentChoice,
467
        $answer,
468
        $answerComment,
469
        $answerCorrect,
470
        $id,
471
        $questionId,
472
        $ans,
473
        $resultsDisabled,
474
        $showTotalScoreAndUserChoices
475
    ) {
476
        $hide_expected_answer = false;
477
        $hideStudentChoice = false;
478
        switch ($resultsDisabled) {
479
            //case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING:
480
            case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
481
                $hideStudentChoice = false;
482
                $hide_expected_answer = true;
483
                break;
484
            case RESULT_DISABLE_SHOW_SCORE_ONLY:
485
                if ($feedbackType == 0) {
486
                    $hide_expected_answer = true;
487
                }
488
                break;
489
            case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
490
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
491
                $hide_expected_answer = true;
492
                if ($showTotalScoreAndUserChoices) {
493
                    $hide_expected_answer = false;
494
                }
495
                break;
496
        }
497
498
        $content = '<tr>';
499
        if ($hideStudentChoice === false) {
500
            $content .= '<td width="5%">';
501
            $course_id = api_get_course_int_id();
502
            $new_options = Question::readQuestionOption($questionId, $course_id);
503
            // Your choice
504
            if (isset($new_options[$studentChoice])) {
505
                $content .= get_lang($new_options[$studentChoice]['name']);
506
            } else {
507
                $content .= '-';
508
            }
509
            $content .= '</td>';
510
        }
511
512
        // Expected choice
513
        if (!$hide_expected_answer) {
514
            if ($exercise->showExpectedChoiceColumn()) {
515
                $content .= '<td width="5%">';
516
                if (isset($new_options[$answerCorrect])) {
517
                    $content .= get_lang($new_options[$answerCorrect]['name']);
518
                } else {
519
                    $content .= '-';
520
                }
521
                $content .= '</td>';
522
            }
523
        }
524
525
        $content .= '<td width="40%">';
526
        $content .= $answer;
527
        $content .= '</td>';
528
529
        if ($exercise->showExpectedChoice()) {
530
            $status = Display::label(get_lang('Incorrect'), 'danger');
531
            if (isset($new_options[$studentChoice])) {
532
                if ($studentChoice == $answerCorrect) {
533
                    $status = Display::label(get_lang('Correct'), 'success');
534
                }
535
            }
536
            $content .= '<td width="20%">';
537
            $content .= $status;
538
            $content .= '</td>';
539
        }
540
541
        if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
542
            $content .= '<td width="20%">';
543
            $color = 'black';
544
            if (isset($new_options[$studentChoice]) || in_array(
545
                    $exercise->results_disabled,
546
                    [
547
                        RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
548
                        RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
549
                    ]
550
                )
551
            ) {
552
                if ($studentChoice == $answerCorrect) {
553
                    $color = 'green';
554
                }
555
556
                if ($hide_expected_answer) {
557
                    $color = '';
558
                }
559
                $content .= '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
560
            }
561
            $content .= '</td>';
562
        }
563
        $content .= '</tr>';
564
565
        echo $content;
566
    }
567
568
    /**
569
     * Display the answers to a multiple choice question.
570
     *
571
     * @param Exercise $exercise
572
     * @param int      $feedbackType
573
     * @param int      $studentChoice
574
     * @param int      $studentChoiceDegree
575
     * @param string   $answer
576
     * @param string   $answerComment
577
     * @param int      $answerCorrect
578
     * @param int      $questionId
579
     * @param bool     $inResultsDisabled
580
     */
581
    public static function displayMultipleAnswerTrueFalseDegreeCertainty(
582
        $exercise,
583
        $feedbackType,
584
        $studentChoice,
585
        $studentChoiceDegree,
586
        $answer,
587
        $answerComment,
588
        $answerCorrect,
589
        $questionId,
590
        $inResultsDisabled
591
    ) {
592
        $hideExpectedAnswer = false;
593
        if ($feedbackType == 0 && $inResultsDisabled == 2) {
594
            $hideExpectedAnswer = true;
595
        }
596
597
        echo '<tr><td width="5%">';
598
        $question = new MultipleAnswerTrueFalseDegreeCertainty();
599
        $courseId = api_get_course_int_id();
600
        $newOptions = Question::readQuestionOption($questionId, $courseId);
601
602
        // Your choice
603
        if (isset($newOptions[$studentChoice])) {
604
            echo get_lang($newOptions[$studentChoice]['name']);
605
        } else {
606
            echo '-';
607
        }
608
        echo '</td>';
609
610
        // Expected choice
611
        if ($exercise->showExpectedChoiceColumn()) {
612
            echo '<td width="5%">';
613
            if (!$hideExpectedAnswer) {
614
                if (isset($newOptions[$answerCorrect])) {
615
                    echo get_lang($newOptions[$answerCorrect]['name']);
616
                } else {
617
                    echo '-';
618
                }
619
            } else {
620
                echo '-';
621
            }
622
            echo '</td>';
623
        }
624
625
        echo '<td width="20%">';
626
        echo $answer;
627
        echo '</td><td width="5%" style="text-align:center;">';
628
        if (isset($newOptions[$studentChoiceDegree])) {
629
            echo $newOptions[$studentChoiceDegree]['name'];
630
        }
631
        echo '</td>';
632
633
        $position = isset($newOptions[$studentChoiceDegree]) ? $newOptions[$studentChoiceDegree]['position'] : '';
634
        $degreeInfo = $question->getResponseDegreeInfo(
635
            $studentChoice,
636
            $answerCorrect,
637
            $position
0 ignored issues
show
Bug introduced by
It seems like $position can also be of type string; however, parameter $studentDegreeChoicePosition of MultipleAnswerTrueFalseD...getResponseDegreeInfo() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

637
            /** @scrutinizer ignore-type */ $position
Loading history...
638
        );
639
640
        $degreeInfo['color'] = isset($degreeInfo['color']) ? $degreeInfo['color'] : '';
641
        $degreeInfo['background-color'] = isset($degreeInfo['background-color']) ? $degreeInfo['background-color'] : '';
642
        $degreeInfo['description'] = isset($degreeInfo['description']) ? $degreeInfo['description'] : '';
643
        $degreeInfo['label'] = isset($degreeInfo['label']) ? $degreeInfo['label'] : '';
644
645
        echo '
646
            <td width="15%">
647
                <div style="text-align:center;color: '.$degreeInfo['color'].';
648
                    background-color: '.$degreeInfo['background-color'].';
649
                    line-height:30px;height:30px;width: 100%;margin:auto;"
650
                    title="'.$degreeInfo['description'].'">'.
651
                    nl2br($degreeInfo['label']).
652
                '</div>
653
            </td>';
654
655
        if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
656
            echo '<td width="20%">';
657
            if (isset($newOptions[$studentChoice])) {
658
                echo '<span style="font-weight: bold; color: black;">'.nl2br($answerComment).'</span>';
659
            }
660
            echo '</td>';
661
        } else {
662
            echo '<td>&nbsp;</td>';
663
        }
664
        echo '</tr>';
665
    }
666
667
    /**
668
     * Display the answers to a multiple choice question.
669
     *
670
     * @param Exercise $exercise
671
     * @param int Answer type
672
     * @param int Student choice
673
     * @param string  Textual answer
674
     * @param string  Comment on answer
675
     * @param string  Correct answer comment
676
     * @param int Exercise ID
677
     * @param int Question ID
678
     * @param bool Whether to show the answer comment or not
679
     */
680
    public static function display_multiple_answer_combination_true_false(
681
        $exercise,
682
        $feedbackType,
683
        $answerType,
684
        $studentChoice,
685
        $answer,
686
        $answerComment,
687
        $answerCorrect,
688
        $id,
689
        $questionId,
690
        $ans,
691
        $resultsDisabled,
692
        $showTotalScoreAndUserChoices
693
    ) {
694
        $hide_expected_answer = false;
695
        $hideStudentChoice = false;
696
        switch ($resultsDisabled) {
697
            case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING:
698
            case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
699
                $hideStudentChoice = true;
700
                $hide_expected_answer = true;
701
                break;
702
            case RESULT_DISABLE_SHOW_SCORE_ONLY:
703
                if ($feedbackType == 0) {
704
                    $hide_expected_answer = true;
705
                }
706
                break;
707
            case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
708
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
709
                $hide_expected_answer = true;
710
                if ($showTotalScoreAndUserChoices) {
711
                    $hide_expected_answer = false;
712
                }
713
                break;
714
        }
715
716
        echo '<tr>';
717
718
        if ($hideStudentChoice === false) {
719
            echo '<td width="5%">';
720
            // Your choice
721
            $question = new MultipleAnswerCombinationTrueFalse();
722
            if (isset($question->options[$studentChoice])) {
723
                echo $question->options[$studentChoice];
724
            } else {
725
                echo $question->options[2];
726
            }
727
            echo '</td>';
728
        }
729
730
        // Expected choice
731
        if ($exercise->showExpectedChoiceColumn()) {
732
            if (!$hide_expected_answer) {
733
                echo '<td width="5%">';
734
                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...
735
                    echo $question->options[$answerCorrect];
736
                } else {
737
                    echo $question->options[2];
738
                }
739
                echo '</td>';
740
            }
741
        }
742
743
        echo '<td width="40%">';
744
        echo $answer;
745
        echo '</td>';
746
747
        if ($exercise->showExpectedChoice()) {
748
            $status = '';
749
            if (isset($studentChoice)) {
750
                $status = Display::label(get_lang('Incorrect'), 'danger');
751
                if ($studentChoice == $answerCorrect) {
752
                    $status = Display::label(get_lang('Correct'), 'success');
753
                }
754
            }
755
            echo '<td width="20%">';
756
            echo $status;
757
            echo '</td>';
758
        }
759
760
        if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
761
            echo '<td width="20%">';
762
            //@todo replace this harcoded value
763
            if ($studentChoice || in_array($resultsDisabled, [
764
                RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
765
                RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
766
            ])
767
            ) {
768
                $color = 'black';
769
                if ($studentChoice == $answerCorrect) {
770
                    $color = 'green';
771
                }
772
                if ($hide_expected_answer) {
773
                    $color = '';
774
                }
775
                echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
776
            }
777
            echo '</td>';
778
        } else {
779
            echo '<td>&nbsp;</td>';
780
        }
781
        echo '</tr>';
782
    }
783
784
    /**
785
     * @param int  $feedbackType
786
     * @param int  $exeId
787
     * @param int  $questionId
788
     * @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...
789
     * @param int  $resultsDisabled
790
     */
791
    public static function displayAnnotationAnswer(
792
        $feedbackType,
793
        $exeId,
794
        $questionId,
795
        $questionScore = null,
796
        $resultsDisabled = 0
797
    ) {
798
        $comments = Event::get_comments($exeId, $questionId);
799
        if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
800
            if ($questionScore <= 0 && empty($comments)) {
801
                echo '<br />'.ExerciseLib::getNotCorrectedYetText();
802
            }
803
        }
804
    }
805
}
806