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