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