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: | |
18: | |
19: | |
20: | public function __construct($id, $delimiter = '') { |
21: | parent::__construct($id); |
22: | $this->delimiter = $delimiter; |
23: | } |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | public function AddRadio($value, $caption, $attributes = array()) { |
32: | $this->list[] = array('value' => $value, 'caption' => $caption, 'attributes' => $attributes); |
33: | } |
34: | |
35: | |
36: | |
37: | |
38: | |
39: | public function setChecked($value) { |
40: | $this->selectedvalue = $value; |
41: | } |
42: | |
43: | |
44: | |
45: | |
46: | |
47: | public function getChecked() { |
48: | return $this->selectedvalue; |
49: | } |
50: | |
51: | |
52: | |
53: | |
54: | public function RenderImpl() { |
55: | |
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: | |
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: | |