Passed
Push — master ( f437d8...92f70a )
by Julito
10:14
created

ExerciseShowFunctions::display_calculated_answer()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 38
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 25
nc 4
nop 10
dl 0
loc 38
rs 9.52
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 int    $feedbackType
26
     * @param string $answer
27
     * @param int    $id                           Exercise ID
28
     * @param int    $questionId                   Question ID
29
     * @param int    $resultsDisabled
30
     * @param string $originalStudentAnswer
31
     * @param bool   $showTotalScoreAndUserChoices
32
     */
33
    public static function display_fill_in_blanks_answer(
34
        $feedbackType,
35
        $answer,
36
        $id,
37
        $questionId,
38
        $resultsDisabled,
39
        $originalStudentAnswer = '',
40
        $showTotalScoreAndUserChoices
41
    ) {
42
        $answerHTML = FillBlanks::getHtmlDisplayForAnswer(
43
            $answer,
44
            $feedbackType,
45
            $resultsDisabled,
46
            $showTotalScoreAndUserChoices
47
        );
48
        // ofaj
49
        /*if (strpos($originalStudentAnswer, 'font color') !== false) {
50
            $answerHTML = $originalStudentAnswer;
51
        }*/
52
        if (empty($id)) {
53
            echo '<tr><td>';
54
            echo Security::remove_XSS($answerHTML, COURSEMANAGERLOWSECURITY);
55
            echo '</td></tr>';
56
        } else {
57
            echo '<tr><td>';
58
            echo Security::remove_XSS($answerHTML, COURSEMANAGERLOWSECURITY);
59
            echo '</td>';
60
            echo '</tr>';
61
        }
62
    }
63
64
    /**
65
     * Shows the answer to a calculated question, as HTML.
66
     *
67
     *  @param Exercise $exercise
68
     * @param string    Answer text
69
     * @param int       Exercise ID
70
     * @param int       Question ID
71
     */
72
    public static function display_calculated_answer(
73
        $exercise,
74
        $feedback_type,
75
        $answer,
76
        $id,
77
        $questionId,
78
        $resultsDisabled,
79
        $showTotalScoreAndUserChoices,
80
        $expectedChoice = '',
81
        $choice = '',
82
        $status = ''
83
    ) {
84
        if ($exercise->showExpectedChoice()) {
85
            if (empty($id)) {
86
                echo '<tr><td>'.Security::remove_XSS($answer).'</td>';
87
                echo '<td>'.Security::remove_XSS($choice).'</td>';
88
                echo '<td>'.Security::remove_XSS($expectedChoice).'</td>';
89
                echo '<td>'.Security::remove_XSS($status).'</td>';
90
                echo '</tr>';
91
            } else {
92
                echo '<tr><td>';
93
                echo Security::remove_XSS($answer);
94
                echo '</td><td>';
95
                echo Security::remove_XSS($choice);
96
                echo '</td><td>';
97
                echo Security::remove_XSS($expectedChoice);
98
                echo '</td><td>';
99
                echo Security::remove_XSS($status);
100
                echo '</td>';
101
                echo '</tr>';
102
            }
103
        } else {
104
            if (empty($id)) {
105
                echo '<tr><td>'.Security::remove_XSS($answer).'</td></tr>';
106
            } else {
107
                echo '<tr><td>';
108
                echo Security::remove_XSS($answer);
109
                echo '</tr>';
110
            }
111
        }
112
    }
113
114
    /**
115
     * Shows the answer to a free-answer question, as HTML.
116
     *
117
     * @param string    Answer text
118
     * @param int       Exercise ID
119
     * @param int       Question ID
120
     */
121
    public static function display_free_answer(
122
        $feedback_type,
123
        $answer,
124
        $exe_id,
125
        $questionId,
126
        $questionScore = null,
127
        $resultsDisabled = 0
128
    ) {
129
        $comments = Event::get_comments($exe_id, $questionId);
130
131
        if (!empty($answer)) {
132
            echo '<tr><td>';
133
            echo Security::remove_XSS($answer);
134
            echo '</td></tr>';
135
        }
136
137
        if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
138
            if ($questionScore > 0 || !empty($comments)) {
139
            } else {
140
                echo '<tr>';
141
                echo Display::tag('td', ExerciseLib::getNotCorrectedYetText(), []);
142
                echo '</tr>';
143
            }
144
        }
145
    }
146
147
    /**
148
     * @param $feedback_type
149
     * @param $answer
150
     * @param $id
151
     * @param $questionId
152
     * @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...
153
     * @param int  $resultsDisabled
154
     * @param int  $questionScore
155
     */
156
    public static function display_oral_expression_answer(
157
        $feedback_type,
158
        $answer,
159
        $id,
160
        $questionId,
161
        $fileUrl = null,
162
        $resultsDisabled = 0,
163
        $questionScore = 0
164
    ) {
165
        if (isset($fileUrl)) {
166
            echo '
167
                <tr>
168
                    <td><audio src="'.$fileUrl.'" controls></audio></td>
169
                </tr>
170
            ';
171
        }
172
173
        if (empty($id)) {
174
            echo '<tr>';
175
            if (!empty($answer)) {
176
                echo Display::tag('td', Security::remove_XSS($answer), ['width' => '55%']);
177
            }
178
            echo '</tr>';
179
            if (!$questionScore && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
180
                echo '<tr>';
181
                echo Display::tag('td', ExerciseLib::getNotCorrectedYetText(), ['width' => '45%']);
182
                echo '</tr>';
183
            } else {
184
                echo '<tr><td>&nbsp;</td></tr>';
185
            }
186
        } else {
187
            echo '<tr>';
188
            echo '<td>';
189
            if (!empty($answer)) {
190
                echo Security::remove_XSS($answer);
191
            }
192
            echo '</td>';
193
194
            if (!api_is_allowed_to_edit(null, true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
195
                echo '<td>';
196
                $comm = Event::get_comments($id, $questionId);
197
                echo '</td>';
198
            }
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 ($resultsDisabled == RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER) {
273
                    return '';
274
                }
275
            }
276
            $content .= $status;
277
        }
278
        $content .= '</td>';
279
        if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
280
            $content .= '<td class="text-left" width="60%">';
281
            if ($studentChoice) {
282
                $content .= '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
283
            }
284
            $content .= '</td>';
285
        } else {
286
            $content .= '<td class="text-left" width="60%">&nbsp;</td>';
287
        }
288
        $content .= '</tr>';
289
290
        echo $content;
291
    }
292
293
    /**
294
     * Display the answers to a multiple choice question.
295
     *
296
     * @param Exercise $exercise
297
     * @param int      $feedbackType                 Feedback type
298
     * @param int      $answerType                   Answer type
299
     * @param int      $studentChoice                Student choice
300
     * @param string   $answer                       Textual answer
301
     * @param string   $answerComment                Comment on answer
302
     * @param string   $answerCorrect                Correct answer comment
303
     * @param int      $id                           Exercise ID
304
     * @param int      $questionId                   Question ID
305
     * @param bool     $ans                          Whether to show the answer comment or not
306
     * @param bool     $resultsDisabled
307
     * @param bool     $showTotalScoreAndUserChoices
308
     * @param bool     $export
309
     */
310
    public static function display_unique_or_multiple_answer(
311
        $exercise,
312
        $feedbackType,
313
        $answerType,
314
        $studentChoice,
315
        $answer,
316
        $answerComment,
317
        $answerCorrect,
318
        $id,
319
        $questionId,
320
        $ans,
321
        $resultsDisabled,
322
        $showTotalScoreAndUserChoices,
323
        $export = false
324
    ) {
325
        if ($export) {
326
            $answer = strip_tags_blacklist($answer, ['title', 'head']);
327
            // Fix answers that contains this tags
328
            $tags = [
329
                '<html>',
330
                '</html>',
331
                '<body>',
332
                '</body>',
333
            ];
334
            $answer = str_replace($tags, '', $answer);
335
        }
336
337
        $studentChoiceInt = (int) $studentChoice;
338
        $answerCorrectChoice = (int) $answerCorrect;
339
340
        $hide_expected_answer = false;
341
        switch ($resultsDisabled) {
342
            case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
343
                if ($studentChoiceInt !== $answerCorrectChoice) {
344
                    return '';
345
                }
346
347
                if (!$answerCorrect) {
348
                    return '';
349
                }
350
                break;
351
            case RESULT_DISABLE_SHOW_SCORE_ONLY:
352
                if ($feedbackType == 0) {
353
                    $hide_expected_answer = true;
354
                }
355
                break;
356
            case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
357
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
358
                $hide_expected_answer = true;
359
                if ($showTotalScoreAndUserChoices) {
360
                    $hide_expected_answer = false;
361
                }
362
                break;
363
        }
364
365
        $icon = in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION]) ? 'radio' : 'checkbox';
366
        $icon .= $studentChoice ? '_on' : '_off';
367
        $icon .= '.png';
368
        $iconAnswer = in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION]) ? 'radio' : 'checkbox';
369
        $iconAnswer .= $answerCorrect ? '_on' : '_off';
370
        $iconAnswer .= '.png';
371
372
        echo '<tr>';
373
        echo '<td width="5%">';
374
        echo Display::return_icon($icon, null, null, ICON_SIZE_TINY);
375
        echo '</td><td width="5%">';
376
        if (!$hide_expected_answer) {
377
            echo Display::return_icon($iconAnswer, null, null, ICON_SIZE_TINY);
378
        } else {
379
            echo '-';
380
        }
381
        echo '</td><td width="40%">';
382
        echo $answer;
383
        echo '</td>';
384
385
        if ($exercise->showExpectedChoice()) {
386
            $status = Display::label(get_lang('Incorrect'), 'danger');
387
            if ($studentChoiceInt === $answerCorrectChoice) {
388
                $status = Display::label(get_lang('Correct'), 'success');
389
            }
390
            echo '<td width="20%">';
391
            echo $status;
392
            echo '</td>';
393
        }
394
395
        if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
396
            echo '<td width="20%">';
397
            if ($studentChoice) {
398
                $color = 'black';
399
                if ($answerCorrect) {
400
                    $color = 'green';
401
                }
402
                if ($hide_expected_answer) {
403
                    $color = '';
404
                }
405
406
                $comment = '<span style="font-weight: bold; color: '.$color.';">'.
407
                    Security::remove_XSS($answerComment).
408
                    '</span>';
409
410
                if (!$answerCorrect && $resultsDisabled == RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER) {
411
                    $comment = '';
412
                }
413
                echo $comment;
414
            }
415
            echo '</td>';
416
            if ($ans == 1) {
417
                $comm = Event::get_comments($id, $questionId);
418
            }
419
        } else {
420
            echo '<td>&nbsp;</td>';
421
        }
422
        echo '</tr>';
423
    }
424
425
    /**
426
     * Display the answers to a multiple choice question.
427
     *
428
     * @param Exercise $exercise
429
     * @param int Answer type
430
     * @param int Student choice
431
     * @param string  Textual answer
432
     * @param string  Comment on answer
433
     * @param string  Correct answer comment
434
     * @param int Exercise ID
435
     * @param int Question ID
436
     * @param bool Whether to show the answer comment or not
437
     */
438
    public static function display_multiple_answer_true_false(
439
        $exercise,
440
        $feedbackType,
441
        $answerType,
442
        $studentChoice,
443
        $answer,
444
        $answerComment,
445
        $answerCorrect,
446
        $id,
447
        $questionId,
448
        $ans,
449
        $resultsDisabled,
450
        $showTotalScoreAndUserChoices
451
    ) {
452
        $hide_expected_answer = false;
453
        switch ($resultsDisabled) {
454
            case RESULT_DISABLE_SHOW_SCORE_ONLY:
455
                if ($feedbackType == 0) {
456
                    $hide_expected_answer = true;
457
                }
458
                break;
459
            case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
460
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
461
                $hide_expected_answer = true;
462
                if ($showTotalScoreAndUserChoices) {
463
                    $hide_expected_answer = false;
464
                }
465
                break;
466
        }
467
468
        $content = '<tr><td width="5%">';
469
        $course_id = api_get_course_int_id();
470
        $new_options = Question::readQuestionOption($questionId, $course_id);
471
        // Your choice
472
        if (isset($new_options[$studentChoice])) {
473
            $content .= get_lang($new_options[$studentChoice]['name']);
474
        } else {
475
            $content .= '-';
476
        }
477
        echo '</td><td width="5%">';
478
        // Expected choice
479
        if (!$hide_expected_answer) {
480
            if (isset($new_options[$answerCorrect])) {
481
                $content .= get_lang($new_options[$answerCorrect]['name']);
482
            } else {
483
                $content .= '-';
484
            }
485
        } else {
486
            $content .= '-';
487
        }
488
        $content .= '</td><td width="40%">';
489
        $content .= $answer;
490
        $content .= '</td>';
491
        if ($exercise->showExpectedChoice()) {
492
            $status = Display::label(get_lang('Incorrect'), 'danger');
493
            if (isset($new_options[$studentChoice])) {
494
                if ($studentChoice == $answerCorrect) {
495
                    $status = Display::label(get_lang('Correct'), 'success');
496
                }
497
            }
498
            $content .= '<td width="20%">';
499
            $content .= $status;
500
            $content .= '</td>';
501
        }
502
        if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
503
            if ($resultsDisabled == RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER) {
504
                if ($studentChoice != $answerCorrect) {
505
                    return '';
506
                }
507
            }
508
            $content .= '<td width="20%">';
509
            $color = 'black';
510
            if (isset($new_options[$studentChoice])) {
511
                if ($studentChoice == $answerCorrect) {
512
                    $color = 'green';
513
                }
514
515
                if ($hide_expected_answer) {
516
                    $color = '';
517
                }
518
                $content .= '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
519
            }
520
            $content .= '</td>';
521
        } else {
522
            $content .= '<td>&nbsp;</td>';
523
        }
524
        $content .= '</tr>';
525
526
        echo $content;
527
    }
528
529
    /**
530
     * Display the answers to a multiple choice question.
531
     *
532
     * @param int    $feedbackType
533
     * @param int    $studentChoice
534
     * @param int    $studentChoiceDegree
535
     * @param string $answer
536
     * @param string $answerComment
537
     * @param int    $answerCorrect
538
     * @param int    $questionId
539
     * @param bool   $inResultsDisabled
540
     */
541
    public static function displayMultipleAnswerTrueFalseDegreeCertainty(
542
        $feedbackType,
543
        $studentChoice,
544
        $studentChoiceDegree,
545
        $answer,
546
        $answerComment,
547
        $answerCorrect,
548
        $questionId,
549
        $inResultsDisabled
550
    ) {
551
        $hideExpectedAnswer = false;
552
        if ($feedbackType == 0 && $inResultsDisabled == 2) {
553
            $hideExpectedAnswer = true;
554
        }
555
556
        echo '<tr><td width="5%">';
557
        $question = new MultipleAnswerTrueFalseDegreeCertainty();
558
        $courseId = api_get_course_int_id();
559
        $newOptions = Question::readQuestionOption($questionId, $courseId);
560
561
        //Your choice
562
        if (isset($newOptions[$studentChoice])) {
563
            echo get_lang($newOptions[$studentChoice]['name']);
564
        } else {
565
            echo '-';
566
        }
567
        echo '</td><td width="5%">';
568
569
        // Expected choice
570
        if (!$hideExpectedAnswer) {
571
            if (isset($newOptions[$answerCorrect])) {
572
                echo get_lang($newOptions[$answerCorrect]['name']);
573
            } else {
574
                echo '-';
575
            }
576
        } else {
577
            echo '-';
578
        }
579
580
        echo '</td><td width="20%">';
581
        echo $answer;
582
        echo '</td><td width="5%" style="text-align:center;">';
583
        if (isset($newOptions[$studentChoiceDegree])) {
584
            echo $newOptions[$studentChoiceDegree]['name'];
585
        }
586
        echo '</td>';
587
588
        $degreeInfo = $question->getResponseDegreeInfo(
589
            $studentChoice,
590
            $answerCorrect,
591
            $newOptions[$studentChoiceDegree]['position']
592
        );
593
594
        echo '
595
            <td width="15%">
596
                <div style="text-align:center;color: '.$degreeInfo['color'].';
597
                    background-color: '.$degreeInfo['background-color'].';
598
                    line-height:30px;height:30px;width: 100%;margin:auto;"
599
                    title="'.$degreeInfo['description'].'">'.
600
                    nl2br($degreeInfo['label']).
601
                '</div>
602
            </td>';
603
604
        if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
605
            echo '<td width="20%">';
606
            if (isset($newOptions[$studentChoice])) {
607
                echo '<span style="font-weight: bold; color: black;">'.nl2br($answerComment).'</span>';
608
            }
609
            echo '</td>';
610
        } else {
611
            echo '<td>&nbsp;</td>';
612
        }
613
        echo '</tr>';
614
    }
615
616
    /**
617
     * Display the answers to a multiple choice question.
618
     *
619
     * @param Exercise $exercise
620
     * @param int Answer type
621
     * @param int Student choice
622
     * @param string  Textual answer
623
     * @param string  Comment on answer
624
     * @param string  Correct answer comment
625
     * @param int Exercise ID
626
     * @param int Question ID
627
     * @param bool Whether to show the answer comment or not
628
     */
629
    public static function display_multiple_answer_combination_true_false(
630
        $exercise,
631
        $feedbackType,
632
        $answerType,
633
        $studentChoice,
634
        $answer,
635
        $answerComment,
636
        $answerCorrect,
637
        $id,
638
        $questionId,
639
        $ans,
640
        $resultsDisabled,
641
        $showTotalScoreAndUserChoices
642
    ) {
643
        $hide_expected_answer = false;
644
        switch ($resultsDisabled) {
645
            case RESULT_DISABLE_SHOW_SCORE_ONLY:
646
                if ($feedbackType == 0) {
647
                    $hide_expected_answer = true;
648
                }
649
                break;
650
            case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
651
            case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
652
                $hide_expected_answer = true;
653
                if ($showTotalScoreAndUserChoices) {
654
                    $hide_expected_answer = false;
655
                }
656
                break;
657
        }
658
659
        echo '<tr><td width="5%">';
660
        // Your choice
661
        $question = new MultipleAnswerCombinationTrueFalse();
662
        if (isset($question->options[$studentChoice])) {
663
            echo $question->options[$studentChoice];
664
        } else {
665
            echo $question->options[2];
666
        }
667
        echo '</td><td width="5%">';
668
        // Expected choice
669
        if (!$hide_expected_answer) {
670
            if (isset($question->options[$answerCorrect])) {
671
                echo $question->options[$answerCorrect];
672
            } else {
673
                echo $question->options[2];
674
            }
675
        } else {
676
            echo '-';
677
        }
678
        echo '</td>';
679
        echo '<td width="40%">';
680
        // my answer
681
        echo $answer;
682
        echo '</td>';
683
684
        if ($exercise->showExpectedChoice()) {
685
            $status = '';
686
            if (isset($studentChoice)) {
687
                $status = Display::label(get_lang('Incorrect'), 'danger');
688
                if ($studentChoice == $answerCorrect) {
689
                    $status = Display::label(get_lang('Correct'), 'success');
690
                }
691
            }
692
            echo '<td width="20%">';
693
            echo $status;
694
            echo '</td>';
695
        }
696
697
        if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
698
            echo '<td width="20%">';
699
            //@todo replace this harcoded value
700
            if ($studentChoice) {
701
                $color = "black";
702
                if ($studentChoice == $answerCorrect) {
703
                    $color = "green";
704
                }
705
                if ($hide_expected_answer) {
706
                    $color = '';
707
                }
708
                echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
709
            }
710
            echo '</td>';
711
            if ($ans == 1) {
712
                $comm = Event::get_comments($id, $questionId);
713
            }
714
        } else {
715
            echo '<td>&nbsp;</td>';
716
        }
717
        echo '</tr>';
718
    }
719
720
    /**
721
     * @param $feedbackType
722
     * @param $exe_id
723
     * @param $questionId
724
     * @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...
725
     * @param int  $resultsDisabled
726
     */
727
    public static function displayAnnotationAnswer(
728
        $feedbackType,
729
        $exe_id,
730
        $questionId,
731
        $questionScore = null,
732
        $resultsDisabled = 0
733
    ) {
734
        $comments = Event::get_comments($exe_id, $questionId);
735
        if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
736
            if ($questionScore <= 0 && empty($comments)) {
737
                echo '<br />'.ExerciseLib::getNotCorrectedYetText();
738
            }
739
        }
740
    }
741
}
742