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