1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
19:
20: 21: 22: 23: 24: 25: 26: 27:
28: class XoopsConfigOption extends XoopsObject
29: {
30: 31: 32:
33: public function __construct()
34: {
35: parent::__construct();
36: $this->initVar('confop_id', XOBJ_DTYPE_INT, null);
37: $this->initVar('confop_name', XOBJ_DTYPE_TXTBOX, null, true, 255);
38: $this->initVar('confop_value', XOBJ_DTYPE_TXTBOX, null, true, 255);
39: $this->initVar('conf_id', XOBJ_DTYPE_INT, 0);
40: }
41:
42: 43: 44: 45: 46:
47: public function id($format = 'N')
48: {
49: return $this->getVar('confop_id', $format);
50: }
51:
52: 53: 54: 55: 56:
57: public function confop_id($format = '')
58: {
59: return $this->getVar('confop_id', $format);
60: }
61:
62: 63: 64: 65: 66:
67: public function confop_name($format = '')
68: {
69: return $this->getVar('confop_name', $format);
70: }
71:
72: 73: 74: 75: 76:
77: public function confop_value($format = '')
78: {
79: return $this->getVar('confop_value', $format);
80: }
81:
82: 83: 84: 85: 86:
87: public function conf_id($format = '')
88: {
89: return $this->getVar('conf_id', $format);
90: }
91: }
92:
93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103:
104: class XoopsConfigOptionHandler extends XoopsObjectHandler
105: {
106: 107: 108: 109: 110: 111: 112:
113: public function create($isNew = true)
114: {
115: $confoption = new XoopsConfigOption();
116: if ($isNew) {
117: $confoption->setNew();
118: }
119:
120: return $confoption;
121: }
122:
123: 124: 125: 126: 127: 128: 129:
130: public function get($id)
131: {
132: $confoption = false;
133: $id = (int)$id;
134: if ($id > 0) {
135: $sql = 'SELECT * FROM ' . $this->db->prefix('configoption') . ' WHERE confop_id=' . $id;
136: if (!$result = $this->db->query($sql)) {
137: return $confoption;
138: }
139: $numrows = $this->db->getRowsNum($result);
140: if ($numrows == 1) {
141: $confoption = new XoopsConfigOption();
142: $confoption->assignVars($this->db->fetchArray($result));
143: }
144: }
145:
146: return $confoption;
147: }
148:
149: 150: 151: 152: 153: 154: 155:
156: public function insert(XoopsObject $confoption)
157: {
158: $className = 'XoopsConfigOption';
159: if (!($confoption instanceof $className)) {
160: return false;
161: }
162: if (!$confoption->isDirty()) {
163: return true;
164: }
165: if (!$confoption->cleanVars()) {
166: return false;
167: }
168:
169: $confop_id = $confoption->getVar('confop_id');
170: $confop_name = $confoption->getVar('confop_name');
171: $confop_value = $confoption->getVar('confop_value');
172: $conf_id = $confoption->getVar('conf_id');
173:
174: if ($confoption->isNew()) {
175: $confop_id = $this->db->genId('configoption_confop_id_seq');
176: $sql = sprintf(
177: 'INSERT INTO %s (confop_id, confop_name, confop_value, conf_id) VALUES (%u, %s, %s, %u)',
178: $this->db->prefix('configoption'),
179: $confop_id,
180: $this->db->quote($confop_name),
181: $this->db->quote($confop_value),
182: $conf_id
183: );
184: } else {
185: $sql = sprintf(
186: 'UPDATE %s SET confop_name = %s, confop_value = %s WHERE confop_id = %u',
187: $this->db->prefix('configoption'),
188: $this->db->quote($confop_name),
189: $this->db->quote($confop_value),
190: $confop_id
191: );
192: }
193: if (!$result = $this->db->query($sql)) {
194: return false;
195: }
196: if (empty($confop_id)) {
197: $confop_id = $this->db->getInsertId();
198: }
199: $confoption->assignVar('confop_id', $confop_id);
200:
201: return $confop_id;
202: }
203:
204: 205: 206: 207: 208: 209: 210:
211: public function delete(XoopsObject $confoption)
212: {
213: $className = 'XoopsConfigOption';
214: if (!($confoption instanceof $className)) {
215: return false;
216: }
217: $sql = sprintf('DELETE FROM %s WHERE confop_id = %u', $this->db->prefix('configoption'), $confoption->getVar('confop_id'));
218: if (!$result = $this->db->query($sql)) {
219: return false;
220: }
221:
222: return true;
223: }
224:
225: 226: 227: 228: 229: 230: 231: 232:
233: public function getObjects(CriteriaElement $criteria = null, $id_as_key = false)
234: {
235: $ret = array();
236: $limit = $start = 0;
237: $sql = 'SELECT * FROM ' . $this->db->prefix('configoption');
238: if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
239: $sql .= ' ' . $criteria->renderWhere() . ' ORDER BY confop_id ' . $criteria->getOrder();
240: $limit = $criteria->getLimit();
241: $start = $criteria->getStart();
242: }
243: $result = $this->db->query($sql, $limit, $start);
244: if (!$result) {
245: return $ret;
246: }
247: while ($myrow = $this->db->fetchArray($result)) {
248: $confoption = new XoopsConfigOption();
249: $confoption->assignVars($myrow);
250: if (!$id_as_key) {
251: $ret[] =& $confoption;
252: } else {
253: $ret[$myrow['confop_id']] = &$confoption;
254: }
255: unset($confoption);
256: }
257:
258: return $ret;
259: }
260: }
261: