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