Passed
Push — master ( ca27a7...8ba864 )
by
unknown
17:12 queued 08:14
created

Ims2Question::createAnswersForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
/**
6
 * @author Claro Team <[email protected]>
7
 * @author Yannick Warnier <[email protected]> -
8
 * updated ImsAnswerHotspot to match QTI norms
9
 */
10
class Ims2Question extends Question
11
{
12
    /**
13
     * Create the proper Answer handler.
14
     * Messages/strings in code must be English.
15
     */
16
    public function setAnswer()
17
    {
18
        $questionId = 0;
19
20
        if (method_exists($this, 'getIid')) {
21
            $questionId = (int) $this->getIid();
22
        } elseif (property_exists($this, 'iid')) {
23
            $questionId = (int) $this->iid;
24
        } elseif (property_exists($this, 'id')) {
25
            $questionId = (int) $this->id;
26
        }
27
28
        // Avoid null IDs: use 0 as safe fallback (some flows set the ID later).
29
        if ($questionId < 0) {
30
            $questionId = 0;
31
        }
32
33
        switch ($this->type) {
34
            case TF:
35
            case MCUA:
36
            case MCMA:
37
                $answer = new ImsAnswerMultipleChoice($questionId);
38
                break;
39
40
            case FIB:
41
                $answer = new ImsAnswerFillInBlanks($questionId);
42
                break;
43
44
            case MATCHING:
45
            case MATCHING_DRAGGABLE:
46
                $answer = new ImsAnswerMatching($questionId);
47
                break;
48
49
            case FREE_ANSWER:
50
                $answer = new ImsAnswerFree($questionId);
51
                break;
52
53
            case HOT_SPOT:
54
                $answer = new ImsAnswerHotspot($questionId);
55
                break;
56
57
            default:
58
                $answer = null;
59
        }
60
61
        // If the parent Question class expects an internal property, keep it.
62
        if (property_exists($this, 'answer')) {
63
            $this->answer = $answer;
64
        }
65
66
        return $answer;
67
    }
68
69
    public function createAnswersForm($form)
70
    {
71
        return true;
72
    }
73
74
    public function processAnswersCreation($form, $exercise)
75
    {
76
        return true;
77
    }
78
}
79