Completed
Push — master ( d0e06e...1fcdba )
by Julito
09:05
created

HotSpot::return_header()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
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