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

HotSpot::getLangVariables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 20
rs 9.6666
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
/**
6
 * Class HotSpot.
7
 *
8
 * This class allows to instantiate an object of
9
 * type HotSpot (MULTIPLE CHOICE, UNIQUE ANSWER)
10
 * extending the class question
11
 *
12
 * @author Eric Marguin
13
 */
14
class HotSpot extends Question
15
{
16
    public $typePicture = 'hotspot.png';
17
    public $explanationLangVar = 'Image zones';
18
19
    /**
20
     * HotSpot constructor.
21
     */
22
    public function __construct()
23
    {
24
        parent::__construct();
25
        $this->type = HOT_SPOT;
26
    }
27
28
    public function display()
29
    {
30
    }
31
32
    public function createForm(&$form, $exercise)
33
    {
34
        parent::createForm($form, $exercise);
35
36
        if (!isset($_GET['editQuestion'])) {
37
            $icon = Display::return_icon(
38
                'hotspot.png',
39
                null,
40
                null,
41
                ICON_SIZE_BIG,
42
                false,
43
                true
44
            );
45
            $form->addElement(
46
                'file',
47
                'imageUpload',
48
                [
49
                    '<img src="'.$icon.'" />',
50
                    get_lang('Upload image (jpg, png or gif) to apply hotspots.'),
51
                ]
52
            );
53
54
            // setting the save button here and not in the question class.php
55
            // Saving a question
56
            $form->addButtonSave(get_lang('Go to question'), 'submitQuestion');
57
            $form->addRule(
58
                'imageUpload',
59
                get_lang('Only PNG, JPG or GIF images allowed'),
60
                'filetype',
61
                ['jpg', 'jpeg', 'png', 'gif']
62
            );
63
            $form->addRule('imageUpload', get_lang('Please select an image'), 'uploadedfile');
64
        } else {
65
            // setting the save button here and not in the question class.php
66
            // Editing a question
67
            $form->addButtonUpdate(get_lang('Save the question'), 'submitQuestion');
68
        }
69
    }
70
71
    public function processCreation($form, $exercise)
72
    {
73
        $fileInfo = $form->getSubmitValue('imageUpload');
74
        parent::processCreation($form, $exercise);
75
76
        if (!empty($fileInfo['tmp_name'])) {
77
            $this->save($exercise);
78
        }
79
80
        return false;
81
    }
82
83
    public function createAnswersForm($form)
84
    {
85
        // nothing
86
    }
87
88
    public function processAnswersCreation($form, $exercise)
89
    {
90
        // nothing
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function return_header(Exercise $exercise, $counter = null, $score = [])
97
    {
98
        return parent::return_header($exercise, $counter, $score)
99
            .'<table><tr><td><table class="table">';
100
    }
101
102
    public static function getLangVariables()
103
    {
104
        return [
105
            'Square' => get_lang('Square'),
106
            'Ellipse' => get_lang('Ellipse'),
107
            'Polygon' => get_lang('Polygon'),
108
            'HotspotStatus1' => get_lang('Draw a hotspot'),
109
            'HotspotStatus2Polygon' => get_lang('Use right-click to close the polygon'),
110
            'HotspotStatus2Other' => get_lang('Release the mousebutton to save the hotspot'),
111
            'HotspotStatus3' => get_lang('Hotspot saved'),
112
            'HotspotShowUserPoints' => get_lang('Show/Hide userclicks'),
113
            'ShowHotspots' => get_lang('Show / Hide hotspots'),
114
            'Triesleft' => get_lang('Attempts left'),
115
            'HotspotExerciseFinished' => get_lang('Now click on the button below to validate your answers'),
116
            'NextAnswer' => get_lang('Now click on:'),
117
            'Delineation' => get_lang('Delineation'),
118
            'CloseDelineation' => get_lang('Close delineation'),
119
            'Oar' => get_lang('Area to avoid'),
120
            'ClosePolygon' => get_lang('Close polygon'),
121
            'DelineationStatus1' => get_lang('Use right-click to close the delineation'),
122
        ];
123
    }
124
}
125