1: <?php
2:
3: namespace Zippy\Html\Form;
4:
5: /**
6: * Выводит список радиокнопок
7: */
8: class RadioList extends HtmlFormDataElement
9: {
10: public $delimiter = " ";
11: public $list = array();
12: protected $event;
13: public $selectedvalue = -1;
14:
15: /**
16: * Конструктор
17: * @param string ID компонента
18: * @param string Разделитель между кнопками
19: */
20: public function __construct($id, $delimiter = '') {
21: parent::__construct($id);
22: $this->delimiter = $delimiter;
23: }
24:
25: /**
26: * Добавить кнопку в список
27: * @param int Значение
28: * @param string Текст возле кнопки
29: * @param array Список аттрибутов
30: */
31: public function AddRadio($value, $caption, $attributes = array()) {
32: $this->list[] = array('value' => $value, 'caption' => $caption, 'attributes' => $attributes);
33: }
34:
35: /**
36: * Устанавливает значение
37: * @param mixed значение
38: */
39: public function setChecked($value) {
40: $this->selectedvalue = $value;
41: }
42:
43: /**
44: * Возвращает значение
45: * @param mixed Номер в списке
46: */
47: public function getChecked() {
48: return $this->selectedvalue;
49: }
50:
51: /**
52: * @see HtmlComponent
53: */
54: public function RenderImpl() {
55: // $url = $this->owner->getURLNode()."::".$this->id ;
56:
57: $out = "";
58: foreach ($this->list as $item) {
59:
60: $attributes = "";
61: foreach ($item['attributes'] as $key => $value) {
62: $attributes = $attributes . $key . "=\"{$value}\" ";
63: }
64: $checked = $item['value'] === $this->selectedvalue ? ' checked="on"' : '';
65: $out = $out . "<nobr><input style=\"border:none;\" type=\"radio\" name=\"{$this->id}\" {$checked} value=\"{$item['value']}\" />{$item['caption']}</nobr>";
66: $out .= $this->delimiter;
67: }
68: $out = substr($out, 0, strlen($out) - strlen($this->delimiter));
69:
70: $this->getTag()->html($out);
71: }
72:
73: /**
74: * @see SubmitDataRequest
75: */
76: public function getRequestData() {
77:
78: $this->selectedvalue = isset($_REQUEST[$this->id]) ? $_REQUEST[$this->id] : -1;
79: }
80:
81: public function clean() {
82: $this->setValue(0);
83: }
84:
85: }
86: