XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
formselect.php
1<?php
13
14if (!defined('XOOPS_ROOT_PATH')) {
15 exit();
16}
17
18class XoopsFormSelect extends XoopsFormElement
19{
20
26 public $_options = [];
27
33 public $_multiple = false;
34
40 public $_size;
41
47 public $_value = [];
48
58 public function __construct($caption, $name, $value=null, $size=1, $multiple=false)
59 {
60 $this->setCaption($caption);
61 $this->setName($name);
62 $this->_multiple = $multiple;
63 $this->_size = (int)$size;
64 if (isset($value)) {
65 $this->setValue($value);
66 }
67 }
68
74 public function isMultiple()
75 {
76 return $this->_multiple;
77 }
78
84 public function getSize()
85 {
86 return $this->_size;
87 }
88
94 public function getValue()
95 {
96 return $this->_value;
97 }
98
104 public function setValue($value)
105 {
106 if (is_array($value)) {
107 foreach ($value as $v) {
108 $this->_value[] = $v;
109 }
110 } else {
111 $this->_value[] = $value;
112 }
113 }
114
121 public function addOption($value, $name= '')
122 {
123 if ($name !== '') {
124 $this->_options[$value] = $name;
125 } else {
126 $this->_options[$value] = $value;
127 }
128 }
129
135 public function addOptionArray($options)
136 {
137 if (is_array($options)) {
138 foreach ($options as $k=>$v) {
139 $this->addOption($k, $v);
140 }
141 }
142 }
143
149 public function getOptions()
150 {
151 return $this->_options;
152 }
153
159 public function render()
160 {
161 $root =& XCube_Root::getSingleton();
162 $renderSystem =& $root->getRenderSystem(XOOPSFORM_DEPENDENCE_RENDER_SYSTEM);
163
164 $renderTarget =& $renderSystem->createRenderTarget('main');
165
166 $renderTarget->setAttribute('legacy_module', 'legacy');
167 $renderTarget->setTemplateName('legacy_xoopsform_select.html');
168 $renderTarget->setAttribute('element', $this);
169
170 $renderSystem->render($renderTarget);
171
172 return $renderTarget->getResult();
173 }
174}
setCaption($caption)
addOption($value, $name='')
__construct($caption, $name, $value=null, $size=1, $multiple=false)
addOptionArray($options)