1: <?php
2:
3: namespace Zippy\Html\Form;
4:
5: use Zippy\Binding\ArrayPropertyBinding;
6: use Zippy\Interfaces\Binding;
7:
8: /**
9: * Компонент тэга &lt;select multiple=&quot;on&quot; &gt; для загрузки файла
10: */
11: class MultipleChoice extends HtmlFormDataElement
12: {
13: private $optionlist;
14:
15: /**
16: * Конструкт
17: * @param mixed ID
18: * @param mixed Модель данных
19: */
20: public function __construct($id, $data=array(), $optionlist=array()) {
21: parent::__construct($id);
22: $this->setValue($data);
23: $this->optionlist = $optionlist;
24: }
25:
26: /**
27: * @see HtmlComponent
28: */
29: public function RenderImpl() {
30: // $this->checkInForm();
31: $this->setResponseData();
32: $this->setAttribute("name", $this->id . "[]");
33: $this->setAttribute("multiple", "On");
34: }
35:
36: private function setResponseData() {
37:
38: $list = $this->optionlist instanceof Binding ? $this->optionlist->getValue() : $this->optionlist;
39:
40: foreach ($list as $key => $value) {
41: $option = "<option value=\"{$key}\" ";
42: $v = $this->getValue();
43: $array = array_values($this->getValue());
44: if (in_array($key, array_values($this->getValue()))) {
45: $option .= " selected ";
46: }
47: $option .= ">{$value}</option>";
48: $this->getTag()->append($option);
49: }
50: }
51:
52: /**
53: * @see SubmitDataRequest
54: */
55: public function getRequestData() {
56: if (is_array($_REQUEST[$this->id])) {
57: $this->setValue($_REQUEST[$this->id]);
58: } else {
59: $this->setValue(array());
60: }
61: }
62:
63: /**
64: * Возвразает массив списка комбобокса
65: *
66: */
67: public function getOptionList() {
68: return $list = $this->optionlist instanceof Binding ? $this->optionlist->getValue() : $this->optionlist;
69: }
70:
71: public function clean() {
72: $this->setValue(array());
73: }
74: }
75: