RadioSelect::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 5
1
<?php
2
3
namespace fieldwork\components;
4
5
class RadioSelect extends Field
6
{
7
8
    private $options;
9
10
    public function __construct ($slug, $label, array $options = array(), $value = '', $storeValueLocally = 0)
11
    {
12
        parent::__construct($slug, $label, $value, $storeValueLocally);
13
        $this->options = $options;
14
    }
15
16
    public function getClasses ()
17
    {
18
        return array_merge(
19
            parent::getClasses(), array('radios')
20
        );
21
    }
22
23
    public function getHTML ($showLabel = true)
24
    {
25
        $r = "<div id=\"". $this->getId() . "\" class=\"radios-group\"><div class=\"radios-label\">" . $this->getLabel() . "</div>";
26
        foreach ($this->options as $v => $l) {
27
            $r .= "<div class=\"radio-option\"><input type=\"radio\" id=\"" . $this->getGlobalSlug() . "-" . $v . "\" name=\"" . $this->getName() . "\" value=\"" . $v . "\" " . ($v == $this->getValue() ? "checked" : "") . "><label for=\"" . $this->getGlobalSlug() . "-" . $v . "\">" . $l . "</label></div>";
28
        }
29
        $r .= "</div>";
30
        return $r;
31
    }
32
33
}