XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
imagecategory.php
1<?php
12
13
14if (!defined('XOOPS_ROOT_PATH')) {
15 exit();
16}
17
19{
20 public $_imageCount;
21
22 public function __construct()
23 {
24 parent::__construct();
25 $this->initVar('imgcat_id', XOBJ_DTYPE_INT, null, false);
26 $this->initVar('imgcat_name', XOBJ_DTYPE_TXTBOX, null, true, 100);
27 $this->initVar('imgcat_display', XOBJ_DTYPE_INT, 1, false);
28 $this->initVar('imgcat_weight', XOBJ_DTYPE_INT, 0, false);
29 $this->initVar('imgcat_maxsize', XOBJ_DTYPE_INT, 0, false);
30 $this->initVar('imgcat_maxwidth', XOBJ_DTYPE_INT, 0, false);
31 $this->initVar('imgcat_maxheight', XOBJ_DTYPE_INT, 0, false);
32 $this->initVar('imgcat_type', XOBJ_DTYPE_OTHER, null, false);
33 $this->initVar('imgcat_storetype', XOBJ_DTYPE_OTHER, null, false);
34 }
35
36 public function setImageCount($value)
37 {
38 $this->_imageCount = (int)$value;
39 }
40
41 public function getImageCount()
42 {
43 return $this->_imageCount;
44 }
45}
46
55
57{
58
59 public function &create($isNew = true)
60 {
61 $imgcat =new XoopsImagecategory();
62 if ($isNew) {
63 $imgcat->setNew();
64 }
65 return $imgcat;
66 }
67
68 public function &get($id)
69 {
70 $ret = false;
71 if ((int)$id > 0) {
72 $sql = 'SELECT * FROM '.$this->db->prefix('imagecategory').' WHERE imgcat_id='.$id;
73 if ($result = $this->db->query($sql)) {
74 $numrows = $this->db->getRowsNum($result);
75 if (1 == $numrows) {
76 $imgcat =new XoopsImagecategory();
77 $imgcat->assignVars($this->db->fetchArray($result));
78 $ret =& $imgcat;
79 }
80 }
81 }
82 return $ret;
83 }
84
85 public function insert(&$imgcat)
86 {
87 $imgcat_name = null;
88 $imgcat_display = null;
89 $imgcat_weight = null;
90 $imgcat_maxsize = null;
91 $imgcat_maxwidth = null;
92 $imgcat_maxheight = null;
93 $imgcat_type = null;
94 $imgcat_storetype = null;
95 $imgcat_id = null;
96 if ('xoopsimagecategory' != strtolower(get_class($imgcat))) {
97 return false;
98 }
99 if (!$imgcat->isDirty()) {
100 return true;
101 }
102 if (!$imgcat->cleanVars()) {
103 return false;
104 }
105 foreach ($imgcat->cleanVars as $k => $v) {
106 ${$k} = $v;
107 }
108 if ($imgcat->isNew()) {
109 $imgcat_id = $this->db->genId('imgcat_imgcat_id_seq');
110 $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));
111 } else {
112 $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);
113 }
114 if (!$result = $this->db->query($sql)) {
115 return false;
116 }
117 if (empty($imgcat_id)) {
118 $imgcat_id = $this->db->getInsertId();
119 }
120 $imgcat->assignVar('imgcat_id', $imgcat_id);
121 return true;
122 }
123
124 public function delete(&$imgcat)
125 {
126 if ('xoopsimagecategory' != strtolower(get_class($imgcat))) {
127 return false;
128 }
129 $sql = sprintf('DELETE FROM %s WHERE imgcat_id = %u', $this->db->prefix('imagecategory'), $imgcat->getVar('imgcat_id'));
130 if (!$result = $this->db->query($sql)) {
131 return false;
132 }
133 return true;
134 }
135
136 public function &getObjects($criteria = null, $id_as_key = false)
137 {
138 $ret = [];
139 $limit = $start = 0;
140 $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')";
141 if (isset($criteria) && $criteria instanceof \criteriaelement) {
142 $where = $criteria->render();
143 $sql .= ('' != $where) ? ' AND ' . $where : '';
144 $limit = $criteria->getLimit();
145 $start = $criteria->getStart();
146 }
147 $sql .= ' ORDER BY imgcat_weight, imgcat_id ASC';
148 $result = $this->db->query($sql, $limit, $start);
149 if (!$result) {
150 return $ret;
151 }
152 while ($myrow = $this->db->fetchArray($result)) {
153 $imgcat =new XoopsImagecategory();
154 $imgcat->assignVars($myrow);
155 if (!$id_as_key) {
156 $ret[] =& $imgcat;
157 } else {
158 $ret[$myrow['imgcat_id']] =& $imgcat;
159 }
160 unset($imgcat);
161 }
162 return $ret;
163 }
164
165
166 public function getCount($criteria = null)
167 {
168 $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')";
169 if (isset($criteria) && $criteria instanceof \criteriaelement) {
170 $where = $criteria->render();
171 $sql .= ('' != $where) ? ' AND ' . $where : '';
172 }
173 if (!$result =& $this->db->query($sql)) {
174 return 0;
175 }
176 [$count] = $this->db->fetchRow($result);
177 return $count;
178 }
179
180 public function &getList($groups = [], $perm = 'imgcat_read', $display = null, $storetype = null)
181 {
182 $criteria = new CriteriaCompo();
183 if (is_array($groups) && !empty($groups)) {
184 $criteriaTray = new CriteriaCompo();
185 foreach ($groups as $gid) {
186 $criteriaTray->add(new Criteria('gperm_groupid', $gid), 'OR');
187 }
188 $criteria->add($criteriaTray);
189 if ('imgcat_read' == $perm || 'imgcat_write' == $perm) {
190 $criteria->add(new Criteria('gperm_name', $perm));
191 $criteria->add(new Criteria('gperm_modid', 1));
192 }
193 }
194 if (isset($display)) {
195 $criteria->add(new Criteria('imgcat_display', (int)$display));
196 }
197 if (isset($storetype)) {
198 $criteria->add(new Criteria('imgcat_storetype', $storetype));
199 }
200 $categories =& $this->getObjects($criteria, true);
201 $ret = [];
202 foreach (array_keys($categories) as $i) {
203 $ret[$i] = $categories[$i]->getVar('imgcat_name');
204 }
205 return $ret;
206 }
207}
initVar($key, $data_type, $value=null, $required=false, $maxlength=null, $options='')
Definition object.php:206