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