1: | <?php |
2: | |
3: | namespace Zippy\Html\Form; |
4: | |
5: | |
6: | |
7: | |
8: | class CheckBoxList extends HtmlFormDataElement |
9: | { |
10: | public $delimiter = " "; |
11: | public $list = array(); |
12: | protected $event; |
13: | public $selectedvalue; |
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: | public function RenderImpl() { |
29: | |
30: | |
31: | $out = ""; |
32: | foreach ($this->list as $id => $item) { |
33: | |
34: | $attributes = ""; |
35: | foreach ($item['attributes'] as $key => $value) { |
36: | $attributes = $attributes . $key . "=\"{$value}\" "; |
37: | } |
38: | $checked = $item['value'] === true ? ' checked="on"' : ''; |
39: | |
40: | $out .= $this->RenderItem($this->id . '::' . $id, $checked, $item['caption'], $attributes, $this->delimiter); |
41: | } |
42: | $out = substr($out, 0, strlen($out) - strlen($this->delimiter)); |
43: | |
44: | $this->getTag()->html($out); |
45: | } |
46: | |
47: | |
48: | |
49: | |
50: | |
51: | |
52: | |
53: | |
54: | |
55: | |
56: | public function RenderItem($name, $checked, $caption = "", $attr = "", $delimiter = "") { |
57: | return "<nobr><input type=\"checkbox\" name=\"{$name}\" {$attr} {$checked} /> {$caption}</nobr>{$delimiter}"; |
58: | } |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | |
66: | |
67: | public function AddCheckBox($itemid, $value, $caption, $attributes = array()) { |
68: | $this->list[$itemid] = array('value' => $value, 'caption' => $caption, 'attributes' => $attributes); |
69: | } |
70: | |
71: | |
72: | |
73: | |
74: | public function getRequestData() { |
75: | foreach ($this->list as $id => $item) { |
76: | $this->list[$id]['value'] = isset($_REQUEST[$this->id . '::' . $id]); |
77: | } |
78: | } |
79: | |
80: | |
81: | |
82: | |
83: | |
84: | |
85: | public function setChecked($id, $state) { |
86: | $this->list[$id]['value'] = $state; |
87: | } |
88: | |
89: | |
90: | |
91: | |
92: | |
93: | public function setAllChecked($state) { |
94: | foreach ($this->list as $id => $item) { |
95: | $this->list[$id]['value'] = $state; |
96: | } |
97: | } |
98: | |
99: | |
100: | |
101: | |
102: | |
103: | public function isChecked($id) { |
104: | return $this->list[$id]['value']; |
105: | } |
106: | |
107: | |
108: | |
109: | |
110: | |
111: | public function getCheckedList() { |
112: | $ids = array(); |
113: | foreach ($this->list as $id => $item) { |
114: | if ($this->list[$id]['value'] === true) { |
115: | $ids[] = $id; |
116: | } |
117: | } |
118: | return $ids; |
119: | } |
120: | |
121: | |
122: | public function clean() { |
123: | $this->setAllChecked(false); |
124: | } |
125: | } |
126: | |