1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18:
19: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
20:
21: 22: 23: 24: 25: 26: 27: 28:
29: class XoopsTplset extends XoopsObject
30: {
31: 32: 33:
34: public function __construct()
35: {
36: parent::__construct();
37: $this->initVar('tplset_id', XOBJ_DTYPE_INT, null, false);
38: $this->initVar('tplset_name', XOBJ_DTYPE_OTHER, null, false);
39: $this->initVar('tplset_desc', XOBJ_DTYPE_TXTBOX, null, false, 255);
40: $this->initVar('tplset_credits', XOBJ_DTYPE_TXTAREA, null, false);
41: $this->initVar('tplset_created', XOBJ_DTYPE_INT, 0, false);
42: }
43:
44: 45: 46: 47: 48:
49: public function id($format = 'N')
50: {
51: return $this->getVar('tplset_id', $format);
52: }
53:
54: 55: 56: 57: 58:
59: public function tplset_id($format = '')
60: {
61: return $this->getVar('tplset_id', $format);
62: }
63:
64: 65: 66: 67: 68:
69: public function tplset_name($format = '')
70: {
71: return $this->getVar('tplset_name', $format);
72: }
73:
74: 75: 76: 77: 78:
79: public function tplset_desc($format = '')
80: {
81: return $this->getVar('tplset_desc', $format);
82: }
83:
84: 85: 86: 87: 88:
89: public function tplset_credits($format = '')
90: {
91: return $this->getVar('tplset_credits', $format);
92: }
93:
94: 95: 96: 97: 98:
99: public function tplset_created($format = '')
100: {
101: return $this->getVar('tplset_created', $format);
102: }
103: }
104:
105: 106: 107: 108: 109: 110: 111: 112: 113:
114: class XoopsTplsetHandler extends XoopsObjectHandler
115: {
116: 117: 118: 119: 120: 121: 122:
123: public function create($isNew = true)
124: {
125: $tplset = new XoopsTplset();
126: if ($isNew) {
127: $tplset->setNew();
128: }
129:
130: return $tplset;
131: }
132:
133: 134: 135: 136: 137: 138: 139:
140: public function get($id)
141: {
142: $tplset = false;
143: $id = (int)$id;
144: if ($id > 0) {
145: $sql = 'SELECT * FROM ' . $this->db->prefix('tplset') . ' WHERE tplset_id=' . $id;
146: if (!$result = $this->db->query($sql)) {
147: return $tplset;
148: }
149: $numrows = $this->db->getRowsNum($result);
150: if ($numrows == 1) {
151: $tplset = new XoopsTplset();
152: $tplset->assignVars($this->db->fetchArray($result));
153: }
154: }
155:
156: return $tplset;
157: }
158:
159: 160: 161: 162: 163: 164: 165: 166: 167: 168:
169: public function getByName($tplset_name)
170: {
171: $tplset = false;
172: $tplset_name = trim($tplset_name);
173: if ($tplset_name != '') {
174: $sql = 'SELECT * FROM ' . $this->db->prefix('tplset') . ' WHERE tplset_name=' . $this->db->quoteString($tplset_name);
175: if (!$result = $this->db->query($sql)) {
176: return $tplset;
177: }
178: $numrows = $this->db->getRowsNum($result);
179: if ($numrows == 1) {
180: $tplset = new XoopsTplset();
181: $tplset->assignVars($this->db->fetchArray($result));
182: }
183: }
184:
185: return $tplset;
186: }
187:
188: 189: 190: 191: 192: 193: 194:
195: public function insert(XoopsObject $tplset)
196: {
197: $className = 'XoopsTplset';
198: if (!($tplset instanceof $className)) {
199: return false;
200: }
201: if (!$tplset->isDirty()) {
202: return true;
203: }
204: if (!$tplset->cleanVars()) {
205: return false;
206: }
207: foreach ($tplset->cleanVars as $k => $v) {
208: ${$k} = $v;
209: }
210: if ($tplset->isNew()) {
211: $tplset_id = $this->db->genId('tplset_tplset_id_seq');
212: $sql = sprintf('INSERT INTO %s (tplset_id, tplset_name, tplset_desc, tplset_credits, tplset_created) VALUES (%u, %s, %s, %s, %u)', $this->db->prefix('tplset'), $tplset_id, $this->db->quoteString($tplset_name), $this->db->quoteString($tplset_desc), $this->db->quoteString($tplset_credits), $tplset_created);
213: } else {
214: $sql = sprintf('UPDATE %s SET tplset_name = %s, tplset_desc = %s, tplset_credits = %s, tplset_created = %u WHERE tplset_id = %u', $this->db->prefix('tplset'), $this->db->quoteString($tplset_name), $this->db->quoteString($tplset_desc), $this->db->quoteString($tplset_credits), $tplset_created, $tplset_id);
215: }
216: if (!$result = $this->db->query($sql)) {
217: return false;
218: }
219: if (empty($tplset_id)) {
220: $tplset_id = $this->db->getInsertId();
221: }
222: $tplset->assignVar('tplset_id', $tplset_id);
223:
224: return true;
225: }
226:
227: 228: 229: 230: 231: 232: 233:
234: public function delete(XoopsObject $tplset)
235: {
236: $className = 'XoopsTplset';
237: if (!($tplset instanceof $className)) {
238: return false;
239: }
240: $sql = sprintf('DELETE FROM %s WHERE tplset_id = %u', $this->db->prefix('tplset'), $tplset->getVar('tplset_id'));
241: if (!$result = $this->db->query($sql)) {
242: return false;
243: }
244: $sql = sprintf('DELETE FROM %s WHERE tplset_name = %s', $this->db->prefix('imgset_tplset_link'), $this->db->quoteString($tplset->getVar('tplset_name')));
245: $this->db->query($sql);
246:
247: return true;
248: }
249:
250: 251: 252: 253: 254: 255: 256:
257: public function getObjects(CriteriaElement $criteria = null, $id_as_key = false)
258: {
259: $ret = array();
260: $limit = $start = 0;
261: $sql = 'SELECT * FROM ' . $this->db->prefix('tplset');
262: if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
263: $sql .= ' ' . $criteria->renderWhere() . ' ORDER BY tplset_id';
264: $limit = $criteria->getLimit();
265: $start = $criteria->getStart();
266: }
267: $result = $this->db->query($sql, $limit, $start);
268: if (!$result) {
269: return $ret;
270: }
271: while ($myrow = $this->db->fetchArray($result)) {
272: $tplset = new XoopsTplset();
273: $tplset->assignVars($myrow);
274: if (!$id_as_key) {
275: $ret[] =& $tplset;
276: } else {
277: $ret[$myrow['tplset_id']] =& $tplset;
278: }
279: unset($tplset);
280: }
281:
282: return $ret;
283: }
284:
285: 286: 287: 288: 289: 290:
291: public function getCount(CriteriaElement $criteria = null)
292: {
293: $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('tplset');
294: if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
295: $sql .= ' ' . $criteria->renderWhere();
296: }
297: if (!$result = $this->db->query($sql)) {
298: return 0;
299: }
300: list($count) = $this->db->fetchRow($result);
301:
302: return $count;
303: }
304:
305: 306: 307: 308: 309: 310:
311: public function getList(CriteriaElement $criteria = null)
312: {
313: $ret = array();
314: $tplsets = $this->getObjects($criteria, true);
315: foreach (array_keys($tplsets) as $i) {
316: $temp = $tplsets[$i]->getVar('tplset_name');
317: $ret[$temp] = $temp;
318: }
319:
320: return $ret;
321: }
322: }
323: