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:
32: if (!defined('XOOPS_ROOT_PATH')) {
33: exit();
34: }
35:
36: class XoopsImagecategory extends XoopsObject
37: {
38: var $_imageCount;
39:
40: function XoopsImagecategory()
41: {
42: $this->XoopsObject();
43: $this->initVar('imgcat_id', XOBJ_DTYPE_INT, null, false);
44: $this->initVar('imgcat_name', XOBJ_DTYPE_TXTBOX, null, true, 100);
45: $this->initVar('imgcat_display', XOBJ_DTYPE_INT, 1, false);
46: $this->initVar('imgcat_weight', XOBJ_DTYPE_INT, 0, false);
47: $this->initVar('imgcat_maxsize', XOBJ_DTYPE_INT, 0, false);
48: $this->initVar('imgcat_maxwidth', XOBJ_DTYPE_INT, 0, false);
49: $this->initVar('imgcat_maxheight', XOBJ_DTYPE_INT, 0, false);
50: $this->initVar('imgcat_type', XOBJ_DTYPE_OTHER, null, false);
51: $this->initVar('imgcat_storetype', XOBJ_DTYPE_OTHER, null, false);
52: }
53:
54: function setImageCount($value)
55: {
56: $this->_imageCount = (int)$value;
57: }
58:
59: function getImageCount()
60: {
61: return $this->_imageCount;
62: }
63: }
64:
65: 66: 67: 68: 69: 70: 71: 72:
73:
74: class XoopsImagecategoryHandler extends XoopsObjectHandler
75: {
76:
77: function &create($isNew = true)
78: {
79: $imgcat =new XoopsImagecategory();
80: if ($isNew) {
81: $imgcat->setNew();
82: }
83: return $imgcat;
84: }
85:
86: function &get($id)
87: {
88: $ret = false;
89: if ((int)$id > 0) {
90: $sql = 'SELECT * FROM '.$this->db->prefix('imagecategory').' WHERE imgcat_id='.$id;
91: if ($result = $this->db->query($sql)) {
92: $numrows = $this->db->getRowsNum($result);
93: if ($numrows == 1) {
94: $imgcat =new XoopsImagecategory();
95: $imgcat->assignVars($this->db->fetchArray($result));
96: $ret =& $imgcat;
97: }
98: }
99: }
100: return $ret;
101: }
102:
103: function insert(&$imgcat)
104: {
105: if (strtolower(get_class($imgcat)) != 'xoopsimagecategory') {
106: return false;
107: }
108: if (!$imgcat->isDirty()) {
109: return true;
110: }
111: if (!$imgcat->cleanVars()) {
112: return false;
113: }
114: foreach ($imgcat->cleanVars as $k => $v) {
115: ${$k} = $v;
116: }
117: if ($imgcat->isNew()) {
118: $imgcat_id = $this->db->genId('imgcat_imgcat_id_seq');
119: $sql = sprintf("INSERT INTO %s (imgcat_id, imgcat_name, imgcat_display, imgcat_weight, imgcat_maxsize, imgcat_maxwidth, imgcat_maxheight, imgcat_type, imgcat_storetype) VALUES (%u, %s, %u, %u, %u, %u, %u, %s, %s)", $this->db->prefix('imagecategory'), $imgcat_id, $this->db->quoteString($imgcat_name), $imgcat_display, $imgcat_weight, $imgcat_maxsize, $imgcat_maxwidth, $imgcat_maxheight, $this->db->quoteString($imgcat_type), $this->db->quoteString($imgcat_storetype));
120: } else {
121: $sql = sprintf("UPDATE %s SET imgcat_name = %s, imgcat_display = %u, imgcat_weight = %u, imgcat_maxsize = %u, imgcat_maxwidth = %u, imgcat_maxheight = %u, imgcat_type = %s WHERE imgcat_id = %u", $this->db->prefix('imagecategory'), $this->db->quoteString($imgcat_name), $imgcat_display, $imgcat_weight, $imgcat_maxsize, $imgcat_maxwidth, $imgcat_maxheight, $this->db->quoteString($imgcat_type), $imgcat_id);
122: }
123: if (!$result = $this->db->query($sql)) {
124: return false;
125: }
126: if (empty($imgcat_id)) {
127: $imgcat_id = $this->db->getInsertId();
128: }
129: $imgcat->assignVar('imgcat_id', $imgcat_id);
130: return true;
131: }
132:
133: function delete(&$imgcat)
134: {
135: if (strtolower(get_class($imgcat)) != 'xoopsimagecategory') {
136: return false;
137: }
138: $sql = sprintf("DELETE FROM %s WHERE imgcat_id = %u", $this->db->prefix('imagecategory'), $imgcat->getVar('imgcat_id'));
139: if (!$result = $this->db->query($sql)) {
140: return false;
141: }
142: return true;
143: }
144:
145: function &getObjects($criteria = null, $id_as_key = false)
146: {
147: $ret = array();
148: $limit = $start = 0;
149: $sql = 'SELECT DISTINCT c.* FROM '.$this->db->prefix('imagecategory').' c LEFT JOIN '.$this->db->prefix('group_permission')." l ON l.gperm_itemid=c.imgcat_id WHERE (l.gperm_name = 'imgcat_read' OR l.gperm_name = 'imgcat_write')";
150: if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
151: $where = $criteria->render();
152: $sql .= ($where != '') ? ' AND '.$where : '';
153: $limit = $criteria->getLimit();
154: $start = $criteria->getStart();
155: }
156: $sql .= ' ORDER BY imgcat_weight, imgcat_id ASC';
157: $result = $this->db->query($sql, $limit, $start);
158: if (!$result) {
159: return $ret;
160: }
161: while ($myrow = $this->db->fetchArray($result)) {
162: $imgcat =new XoopsImagecategory();
163: $imgcat->assignVars($myrow);
164: if (!$id_as_key) {
165: $ret[] =& $imgcat;
166: } else {
167: $ret[$myrow['imgcat_id']] =& $imgcat;
168: }
169: unset($imgcat);
170: }
171: return $ret;
172: }
173:
174:
175: function getCount($criteria = null)
176: {
177: $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('imagecategory').' i LEFT JOIN '.$this->db->prefix('group_permission')." l ON l.gperm_itemid=i.imgcat_id WHERE (l.gperm_name = 'imgcat_read' OR l.gperm_name = 'imgcat_write')";
178: if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
179: $where = $criteria->render();
180: $sql .= ($where != '') ? ' AND '.$where : '';
181: }
182: if (!$result =& $this->db->query($sql)) {
183: return 0;
184: }
185: list($count) = $this->db->fetchRow($result);
186: return $count;
187: }
188:
189: function &getList($groups = array(), $perm = 'imgcat_read', $display = null, $storetype = null)
190: {
191: $criteria = new CriteriaCompo();
192: if (is_array($groups) && !empty($groups)) {
193: $criteriaTray = new CriteriaCompo();
194: foreach ($groups as $gid) {
195: $criteriaTray->add(new Criteria('gperm_groupid', $gid), 'OR');
196: }
197: $criteria->add($criteriaTray);
198: if ($perm == 'imgcat_read' || $perm == 'imgcat_write') {
199: $criteria->add(new Criteria('gperm_name', $perm));
200: $criteria->add(new Criteria('gperm_modid', 1));
201: }
202: }
203: if (isset($display)) {
204: $criteria->add(new Criteria('imgcat_display', (int)$display));
205: }
206: if (isset($storetype)) {
207: $criteria->add(new Criteria('imgcat_storetype', $storetype));
208: }
209: $categories =& $this->getObjects($criteria, true);
210: $ret = array();
211: foreach (array_keys($categories) as $i) {
212: $ret[$i] = $categories[$i]->getVar('imgcat_name');
213: }
214: return $ret;
215: }
216: }
217: ?>
218: