Passed
Push — master ( 6f8cb0...cccadf )
by Julito
09:47
created

ch_multiplechoice   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createForm() 0 25 5
A render() 0 4 1
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
        if (is_array($formData['answers'])) {
31
            foreach ($formData['answers'] as $key => $value) {
32
                $this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config);
33
                if ($total > 2) {
34
                    $this->getForm()->addButton("delete_answer[$key]", get_lang('Delete'), 'trash', 'danger');
35
                }
36
            }
37
        }
38
39
        parent::addRemoveButtons($formData);
40
    }
41
42
    /**
43
     * @param FormValidator $form
44
     * @param array         $questionData
45
     * @param array         $answers
46
     */
47
    public function render(FormValidator $form, $questionData = [], $answers = [])
48
    {
49
        $question = new ch_yesno();
50
        $question->render($form, $questionData, $answers);
51
    }
52
}
53