1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Forms\Controls;
9:
10: use Nette;
11: use Nette\Utils\Html;
12:
13:
14: 15: 16: 17: 18: 19: 20: 21:
22: class RadioList extends ChoiceControl
23: {
24:
25: protected $separator;
26:
27:
28: protected $container;
29:
30:
31: 32: 33: 34:
35: public function __construct($label = NULL, array $items = NULL)
36: {
37: parent::__construct($label, $items);
38: $this->control->type = 'radio';
39: $this->container = Html::el();
40: $this->separator = Html::el('br');
41: }
42:
43:
44: 45: 46: 47:
48: public function getValue($raw = FALSE)
49: {
50: if ($raw) {
51: trigger_error(__METHOD__ . '(TRUE) is deprecated; use getRawValue() instead.', E_USER_DEPRECATED);
52: return $this->getRawValue();
53: }
54: return parent::getValue();
55: }
56:
57:
58: 59: 60: 61:
62: public function getSeparatorPrototype()
63: {
64: return $this->separator;
65: }
66:
67:
68: 69: 70: 71:
72: public function getContainerPrototype()
73: {
74: return $this->container;
75: }
76:
77:
78: 79: 80: 81:
82: public function getControl($key = NULL)
83: {
84: if ($key !== NULL) {
85: trigger_error(sprintf('Partial %s() is deprecated; use getControlPart() instead.', __METHOD__), E_USER_DEPRECATED);
86: return $this->getControlPart($key);
87: }
88:
89: $input = parent::getControl();
90: $ids = array();
91: foreach ($this->getItems() as $value => $label) {
92: $ids[$value] = $input->id . '-' . $value;
93: }
94:
95: return $this->container->setHtml(
96: Nette\Forms\Helpers::createInputList(
97: $this->translate($this->getItems()),
98: array_merge($input->attrs, array(
99: 'id:' => $ids,
100: 'checked?' => $this->value,
101: 'disabled:' => $this->disabled,
102: 'data-nette-rules:' => array(key($ids) => $input->attrs['data-nette-rules']),
103: )),
104: array('for:' => $ids),
105: $this->separator
106: )
107: );
108: }
109:
110:
111: 112: 113: 114: 115:
116: public function getLabel($caption = NULL, $key = NULL)
117: {
118: if ($key !== NULL) {
119: trigger_error(sprintf('Partial %s() is deprecated; use getLabelPart() instead.', __METHOD__), E_USER_DEPRECATED);
120: return $this->getLabelPart($key);
121: }
122: return parent::getLabel($caption)->for(NULL);
123: }
124:
125:
126: 127: 128:
129: public function getControlPart($key)
130: {
131: return parent::getControl()->addAttributes(array(
132: 'id' => $this->getHtmlId() . '-' . $key,
133: 'checked' => in_array($key, (array) $this->value, TRUE),
134: 'disabled' => is_array($this->disabled) ? isset($this->disabled[$key]) : $this->disabled,
135: 'value' => $key,
136: ));
137: }
138:
139:
140: 141: 142:
143: public function getLabelPart($key)
144: {
145: return parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key);
146: }
147:
148: }
149: