1: <?php
2:
3: namespace webfilesframework\io\form\formItem;
4:
5: 6: 7: 8: 9: 10:
11: class MCheckboxesFormItem extends MAbstractFormItem
12: {
13:
14: private $possibleValues;
15: private $selectedValues;
16:
17:
18: public function setPossibleValues($possibleValues)
19: {
20: $this->possibleValues = $possibleValues;
21: }
22:
23: public function setSelectedValues($selectedValues)
24: {
25: $this->selectedValues = $selectedValues;
26: }
27:
28: public function getPossibleValues()
29: {
30: return $this->possibleValues;
31: }
32:
33: public function init()
34: {
35: $this->code = "<div style=\"margin-top:4px;\">";
36:
37: if (!empty($this->localizedName)) {
38: $this->code .= $this->localizedName;
39: } else {
40: $this->code .= $this->name;
41: }
42:
43: $this->code = "<div style=\"margin-top:4px; width:600px;\">
44: <label style=\"width:" . $this->getLabelWidth() . "px;display:block;float:left;\">";
45: if (!empty($this->localizedName)) {
46: $this->code .= $this->localizedName;
47: } else {
48: $this->code .= $this->name;
49: }
50: $this->code .= " </label>
51: <div style=\"float:right; width:440px;\">";
52:
53:
54: if (is_array($this->possibleValues)) {
55: foreach ($this->possibleValues as $value) {
56: $this->code .= "<input type=\"checkbox\" id=\"" . $this->name . "_" . $value->getId() . "\" name=\"" . $this->name . "[]\" value=\"" . $value->getId() . "\" data-dojo-type=\"dijit.form.CheckBox\"";
57: if (in_array($value->getId(), $this->selectedValues)) {
58: $this->code .= " checked=\"checked\"";
59: }
60: $this->code .= "/><label for=\"" . $this->name . "_" . $value->getId() . "\">" . $value . "</label><br>";
61: }
62: }
63: $this->code .= " </div>
64: <div style=\"clear:both;\"></div>
65: </div>";
66:
67: }
68:
69: public function getCode()
70: {
71: $this->init();
72: return parent::getCode();
73: }
74:
75: }