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