XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
formcheckbox.php
1<?php
12
13if (!defined('XOOPS_ROOT_PATH')) {
14 exit();
15}
16
17class XoopsFormCheckBox extends XoopsFormElement
18{
19
25 public $_options = [];
26
32 public $_value = [];
33
41 public function __construct($caption, $name, $value = null)
42 {
43 $this->setCaption($caption);
44 $this->setName($name);
45 if (isset($value)) {
46 $this->setValue($value);
47 }
48 }
49 public function XoopsFormCheckBox($caption, $name, $value = null)
50 {
51 return self::__construct($caption, $name, $value);
52 }
53
59 public function getValue()
60 {
61 return $this->_value;
62 }
63
69 public function setValue($value)
70 {
71 $this->_value = [];
72 if (is_array($value)) {
73 foreach ($value as $v) {
74 $this->_value[] = $v;
75 }
76 } else {
77 $this->_value[] = $value;
78 }
79 }
80
87 public function addOption($value, $name= '')
88 {
89 if ('' != $name) {
90 $this->_options[$value] = $name;
91 } else {
92 $this->_options[$value] = $value;
93 }
94 }
95
101 public function addOptionArray($options)
102 {
103 if (is_array($options)) {
104 foreach ($options as $k=>$v) {
105 $this->addOption($k, $v);
106 }
107 }
108 }
109
115 public function getOptions()
116 {
117 return $this->_options;
118 }
119
125 public function render()
126 {
127 $root =& XCube_Root::getSingleton();
128 $renderSystem =& $root->getRenderSystem(XOOPSFORM_DEPENDENCE_RENDER_SYSTEM);
129
130 $renderTarget =& $renderSystem->createRenderTarget('main');
131
132 if (count($this->getOptions()) > 1 && '[]' != substr($this->getName(), -2, 2)) {
133 $newname = $this->getName() . '[]';
134 $this->setName($newname);
135 }
136
137 $renderTarget->setAttribute('legacy_module', 'legacy');
138 $renderTarget->setTemplateName('legacy_xoopsform_checkbox.html');
139 $renderTarget->setAttribute('element', $this);
140
141 $renderSystem->render($renderTarget);
142
143 return $renderTarget->getResult();
144 }
145}
addOption($value, $name='')
addOptionArray($options)
__construct($caption, $name, $value=null)
setCaption($caption)
getName($encode=true)