Completed
Push — master ( 1a5e2c...34133a )
by Julito
08:10
created

ch_multiplechoice::render()   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
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Class ch_multiplechoice.
6
 */
7
class ch_multiplechoice extends survey_question
8
{
9
    /**
10
     * @param array $survey_data
11
     * @param array $formData
12
     *
13
     * @return FormValidator
14
     */
15
    public function createForm($survey_data, $formData)
16
    {
17
        parent::createForm($survey_data, $formData);
18
19
        $options = [
20
            'horizontal' => get_lang('Horizontal'),
21
            'vertical' => get_lang('Vertical'),
22
        ];
23
        $this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options);
24
25
        $formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal';
26
        $this->getForm()->setDefaults($formData);
27
28
        $config = ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120'];
29
        $total = count($formData['answers']);
30
31
        if (is_array($formData['answers'])) {
32
            foreach ($formData['answers'] as $key => $value) {
33
                $this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config);
34
                if ($total > 2) {
35
                    $this->getForm()->addButton("delete_answer[$key]", get_lang('Delete'), 'trash', 'danger');
36
                }
37
            }
38
        }
39
40
        if (isset($formData['answersid']) && !empty($formData['answersid'])) {
41
            foreach ($formData['answersid'] as $value) {
42
                $this->getForm()->addHidden('answersid[]', $value);
43
            }
44
        }
45
46
        parent::addRemoveButtons($formData);
47
    }
48
49
    /**
50
     * @param array $questionData
51
     * @param array $answers
52
     */
53
    public function render(FormValidator $form, $questionData = [], $answers = [])
54
    {
55
        $question = new ch_yesno();
56
        $question->render($form, $questionData, $answers);
57
    }
58
}
59