59 public function &
create($isNew =
true)
68 public function &
get($id)
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);
77 $imgcat->assignVars($this->db->fetchArray($result));
88 $imgcat_display =
null;
89 $imgcat_weight =
null;
90 $imgcat_maxsize =
null;
91 $imgcat_maxwidth =
null;
92 $imgcat_maxheight =
null;
94 $imgcat_storetype =
null;
96 if (
'xoopsimagecategory' != strtolower(get_class($imgcat))) {
99 if (!$imgcat->isDirty()) {
102 if (!$imgcat->cleanVars()) {
105 foreach ($imgcat->cleanVars as $k => $v) {
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));
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);
114 if (!$result = $this->db->query($sql)) {
117 if (empty($imgcat_id)) {
118 $imgcat_id = $this->db->getInsertId();
120 $imgcat->assignVar(
'imgcat_id', $imgcat_id);
124 public function delete(&$imgcat)
126 if (
'xoopsimagecategory' != strtolower(get_class($imgcat))) {
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)) {
136 public function &getObjects($criteria =
null, $id_as_key =
false)
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();
147 $sql .=
' ORDER BY imgcat_weight, imgcat_id ASC';
148 $result = $this->db->query($sql, $limit, $start);
152 while ($myrow = $this->db->fetchArray($result)) {
153 $imgcat =
new XoopsImagecategory();
154 $imgcat->assignVars($myrow);
158 $ret[$myrow[
'imgcat_id']] =& $imgcat;
166 public function getCount($criteria =
null)
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 :
'';
173 if (!$result =& $this->db->query($sql)) {
176 [$count] = $this->db->fetchRow($result);
180 public function &getList($groups = [], $perm =
'imgcat_read', $display =
null, $storetype =
null)
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');
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));
194 if (isset($display)) {
195 $criteria->add(
new Criteria(
'imgcat_display', (
int)$display));
197 if (isset($storetype)) {
198 $criteria->add(
new Criteria(
'imgcat_storetype', $storetype));
200 $categories =& $this->getObjects($criteria,
true);
202 foreach (array_keys($categories) as $i) {
203 $ret[$i] = $categories[$i]->getVar(
'imgcat_name');