1: <?php
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31: if (!defined('XOOPS_ROOT_PATH')) {
32: exit();
33: }
34: class XoopsTplset extends XoopsObject
35: {
36:
37: function XoopsTplset()
38: {
39: static $initVars;
40: if (isset($initVars)) {
41: $this->vars = $initVars;
42: return;
43: }
44: $this->XoopsObject();
45: $this->initVar('tplset_id', XOBJ_DTYPE_INT, null, false);
46: $this->initVar('tplset_name', XOBJ_DTYPE_OTHER, null, false);
47: $this->initVar('tplset_desc', XOBJ_DTYPE_TXTBOX, null, false, 255);
48: $this->initVar('tplset_credits', XOBJ_DTYPE_TXTAREA, null, false);
49: $this->initVar('tplset_created', XOBJ_DTYPE_INT, 0, false);
50: $initVars = $this->vars;
51: }
52: }
53:
54: 55: 56: 57: 58: 59: 60: 61:
62:
63: class XoopsTplsetHandler extends XoopsObjectHandler
64: {
65:
66: function &create($isNew = true)
67: {
68: $tplset =new XoopsTplset();
69: if ($isNew) {
70: $tplset->setNew();
71: }
72: return $tplset;
73: }
74:
75: function &get($id)
76: {
77: $ret = false;
78: $id = (int)$id;
79: if ($id > 0) {
80: $sql = 'SELECT * FROM '.$this->db->prefix('tplset').' WHERE tplset_id='.$id;
81: if ($result = $this->db->query($sql)) {
82: $numrows = $this->db->getRowsNum($result);
83: if ($numrows == 1) {
84: $tplset = new XoopsTplset();
85: $tplset->assignVars($this->db->fetchArray($result));
86: $ret =& $tplset;
87: }
88: }
89: }
90: return $ret;
91: }
92:
93: function &getByName($tplset_name)
94: {
95: $ret = false;
96: $tplset_name = trim($tplset_name);
97: if ($tplset_name != '') {
98: $sql = 'SELECT * FROM '.$this->db->prefix('tplset').' WHERE tplset_name='.$this->db->quoteString($tplset_name);
99: if ($result = $this->db->query($sql)) {
100: $numrows = $this->db->getRowsNum($result);
101: if ($numrows == 1) {
102: $tplset =new XoopsTplset();
103: $tplset->assignVars($this->db->fetchArray($result));
104: $ret =& $tplset;
105: }
106: }
107: }
108: return $ret;
109: }
110:
111: function insert(&$tplset)
112: {
113: if (strtolower(get_class($tplset)) != 'xoopstplset') {
114: return false;
115: }
116: if (!$tplset->isDirty()) {
117: return true;
118: }
119: if (!$tplset->cleanVars()) {
120: return false;
121: }
122: foreach ($tplset->cleanVars as $k => $v) {
123: ${$k} = $v;
124: }
125: if ($tplset->isNew()) {
126: $tplset_id = $this->db->genId('tplset_tplset_id_seq');
127: $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);
128: } else {
129: $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);
130: }
131: if (!$result = $this->db->query($sql)) {
132: return false;
133: }
134: if (empty($tplset_id)) {
135: $tplset_id = $this->db->getInsertId();
136: }
137: $tplset->assignVar('tplset_id', $tplset_id);
138: return true;
139: }
140:
141: function delete(&$tplset)
142: {
143: if (strtolower(get_class($tplset)) != 'xoopstplset') {
144: return false;
145: }
146: $sql = sprintf("DELETE FROM %s WHERE tplset_id = %u", $this->db->prefix('tplset'), $tplset->getVar('tplset_id'));
147: if (!$result = $this->db->query($sql)) {
148: return false;
149: }
150: $sql = sprintf("DELETE FROM %s WHERE tplset_name = %s", $this->db->prefix('imgset_tplset_link'), $this->db->quoteString($tplset->getVar('tplset_name')));
151: $this->db->query($sql);
152: return true;
153: }
154:
155: function &getObjects($criteria = null, $id_as_key = false)
156: {
157: $ret = array();
158: $limit = $start = 0;
159: $sql = 'SELECT * FROM '.$this->db->prefix('tplset');
160: if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
161: $sql .= ' '.$criteria->renderWhere().' ORDER BY tplset_id';
162: $limit = $criteria->getLimit();
163: $start = $criteria->getStart();
164: }
165: $result = $this->db->query($sql, $limit, $start);
166: if (!$result) {
167: return $ret;
168: }
169: while ($myrow = $this->db->fetchArray($result)) {
170: $tplset =new XoopsTplset();
171: $tplset->assignVars($myrow);
172: if (!$id_as_key) {
173: $ret[] =& $tplset;
174: } else {
175: $ret[$myrow['tplset_id']] =& $tplset;
176: }
177: unset($tplset);
178: }
179: return $ret;
180: }
181:
182:
183: function getCount($criteria = null)
184: {
185: $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('tplset');
186: if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
187: $sql .= ' '.$criteria->renderWhere();
188: }
189: if (!$result =& $this->db->query($sql)) {
190: return 0;
191: }
192: list($count) = $this->db->fetchRow($result);
193: return $count;
194: }
195:
196: function &getList($criteria = null)
197: {
198: $ret = array();
199: $tplsets =& $this->getObjects($criteria, true);
200: foreach ($tplsets as $tpl) {
201: $name = $tpl->getVar('tplset_name');
202: $ret[$name] = $name;
203: }
204: return $ret;
205: }
206: }
207: ?>
208: