1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19:
20:
21: use Xoops\Core\Database\Connection;
22: use Xoops\Core\Kernel\XoopsObject;
23: use Xoops\Core\Kernel\XoopsPersistableObjectHandler;
24:
25: 26: 27: 28:
29: class UserconfigsItem extends XoopsObject
30: {
31:
32: 33: 34: 35: 36: 37:
38: private $_confOptions = array();
39:
40: 41: 42:
43: public function __construct()
44: {
45: $this->initVar('conf_id', XOBJ_DTYPE_INT, null, false);
46: $this->initVar('conf_modid', XOBJ_DTYPE_INT, null, false);
47: $this->initVar('conf_uid', XOBJ_DTYPE_INT, null, false);
48: $this->initVar('conf_name', XOBJ_DTYPE_OTHER);
49: $this->initVar('conf_title', XOBJ_DTYPE_TXTBOX);
50: $this->initVar('conf_value', XOBJ_DTYPE_TXTAREA);
51: $this->initVar('conf_desc', XOBJ_DTYPE_OTHER);
52: $this->initVar('conf_formtype', XOBJ_DTYPE_OTHER);
53: $this->initVar('conf_valuetype', XOBJ_DTYPE_OTHER);
54: $this->initVar('conf_order', XOBJ_DTYPE_INT);
55: }
56:
57: 58: 59: 60:
61: public function id($format = 'n')
62: {
63: return $this->getVar('conf_id', $format);
64: }
65:
66: 67: 68: 69:
70: public function conf_id($format = '')
71: {
72: return $this->getVar('conf_id', $format);
73: }
74:
75: 76: 77: 78:
79: public function conf_modid($format = '')
80: {
81: return $this->getVar('conf_modid', $format);
82: }
83:
84: 85: 86: 87:
88: public function conf_uid($format = '')
89: {
90: return $this->getVar('conf_uid', $format);
91: }
92:
93: 94: 95: 96:
97: public function conf_name($format = '')
98: {
99: return $this->getVar('conf_name', $format);
100: }
101:
102: 103: 104: 105:
106: public function conf_title($format = '')
107: {
108: return $this->getVar('conf_title', $format);
109: }
110:
111: 112: 113: 114:
115: public function conf_value($format = '')
116: {
117: return $this->getVar('conf_value', $format);
118: }
119:
120: 121: 122: 123:
124: public function conf_desc($format = '')
125: {
126: return $this->getVar('conf_desc', $format);
127: }
128:
129: 130: 131: 132:
133: public function conf_formtype($format = '')
134: {
135: return $this->getVar('conf_formtype', $format);
136: }
137:
138: 139: 140: 141:
142: public function conf_valuetype($format = '')
143: {
144: return $this->getVar('conf_valuetype', $format);
145: }
146:
147: 148: 149: 150:
151: public function conf_order($format = '')
152: {
153: return $this->getVar('conf_order', $format);
154: }
155:
156: 157: 158: 159: 160:
161: public function getConfValueForOutput()
162: {
163: switch ($this->getVar('conf_valuetype')) {
164: case 'int':
165: return (int)($this->getVar('conf_value', 'n'));
166: break;
167: case 'array':
168: $value = @unserialize($this->getVar('conf_value', 'n'));
169: return $value ? $value : array();
170: case 'float':
171: $value = $this->getVar('conf_value', 'n');
172: return (float)$value;
173: break;
174: case 'textarea':
175: return $this->getVar('conf_value');
176: default:
177: return $this->getVar('conf_value', 'n');
178: break;
179: }
180: }
181:
182: 183: 184: 185: 186:
187: public function setConfValueForInput(&$value)
188: {
189: switch ($this->getVar('conf_valuetype')) {
190: case 'array':
191: if (!is_array($value)) {
192: $value = explode('|', trim($value));
193: }
194: $this->setVar('conf_value', serialize($value));
195: break;
196: case 'text':
197: $this->setVar('conf_value', trim($value));
198: break;
199: default:
200: $this->setVar('conf_value', $value);
201: break;
202: }
203: }
204:
205: 206: 207: 208: 209:
210: public function setConfOptions($option)
211: {
212: if (is_array($option)) {
213: $count = count($option);
214: for ($i = 0; $i < $count; ++$i) {
215: $this->setConfOptions($option[$i]);
216: }
217: } else {
218: if (is_object($option)) {
219: $this->_confOptions[] = $option;
220: }
221: }
222: }
223:
224: 225: 226: 227: 228:
229: public function getConfOptions()
230: {
231: return $this->_confOptions;
232: }
233:
234: 235: 236: 237: 238:
239: public function clearConfOptions()
240: {
241: $this->_confOptions = array();
242: }
243: }
244:
245: class UserconfigsItemHandler extends XoopsPersistableObjectHandler
246: {
247: 248: 249: 250: 251:
252: public function __construct(Connection $db = null)
253: {
254: parent::__construct($db, 'userconfigs_item', 'UserconfigsItem', 'conf_id', 'conf_name');
255: }
256: }
257: