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

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