XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
imageset.php
1<?php
14
15if (!defined('XOOPS_ROOT_PATH')) {
16 exit();
17}
18
20{
21
22 public function __construct()
23 {
24 parent::__construct();
25 $this->initVar('imgset_id', XOBJ_DTYPE_INT, null, false);
26 $this->initVar('imgset_name', XOBJ_DTYPE_TXTBOX, null, true, 50);
27 $this->initVar('imgset_refid', XOBJ_DTYPE_INT, 0, false);
28 }
29}
30
34
36{
37
38 public function &create($isNew = true)
39 {
40 $imgset =new XoopsImageset();
41 if ($isNew) {
42 $imgset->setNew();
43 }
44 return $imgset;
45 }
46
47 public function &get($id)
48 {
49 $ret = false;
50 if ((int)$id > 0) {
51 $sql = 'SELECT * FROM '.$this->db->prefix('imgset').' WHERE imgset_id='.$id;
52 if ($result = $this->db->query($sql)) {
53 $numrows = $this->db->getRowsNum($result);
54 if (1 == $numrows) {
55 $imgset =new XoopsImageset();
56 $imgset->assignVars($this->db->fetchArray($result));
57 $ret =& $imgset;
58 }
59 }
60 }
61 return $ret;
62 }
63
64 public function insert(&$imgset)
65 {
66 $imgset_name = null;
67 $imgset_refid = null;
68 $imgset_id = null;
69 if ('xoopsimageset' != strtolower(get_class($imgset))) {
70 return false;
71 }
72 if (!$imgset->isDirty()) {
73 return true;
74 }
75 if (!$imgset->cleanVars()) {
76 return false;
77 }
78 foreach ($imgset->cleanVars as $k => $v) {
79 ${$k} = $v;
80 }
81 if ($imgset->isNew()) {
82 $imgset_id = $this->db->genId('imgset_imgset_id_seq');
83 $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);
84 } else {
85 $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);
86 }
87 if (!$result = $this->db->query($sql)) {
88 return false;
89 }
90 if (empty($imgset_id)) {
91 $imgset_id = $this->db->getInsertId();
92 }
93 $imgset->assignVar('imgset_id', $imgset_id);
94 return true;
95 }
96
97 public function delete(&$imgset)
98 {
99 if ('xoopsimageset' != strtolower(get_class($imgset))) {
100 return false;
101 }
102 $sql = sprintf('DELETE FROM %s WHERE imgset_id = %u', $this->db->prefix('imgset'), $imgset->getVar('imgset_id'));
103 if (!$result = $this->db->query($sql)) {
104 return false;
105 }
106 $sql = sprintf('DELETE FROM %s WHERE imgset_id = %u', $this->db->prefix('imgset_tplset_link'), $imgset->getVar('imgset_id'));
107 $this->db->query($sql);
108 return true;
109 }
110
111 public function &getObjects($criteria = null, $id_as_key = false)
112 {
113 $ret = [];
114 $limit = $start = 0;
115 $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';
116 if (isset($criteria) && $criteria instanceof \criteriaelement) {
117 $sql .= ' '.$criteria->renderWhere();
118 $limit = $criteria->getLimit();
119 $start = $criteria->getStart();
120 }
121 $result = $this->db->query($sql, $limit, $start);
122 if (!$result) {
123 return $ret;
124 }
125 while ($myrow = $this->db->fetchArray($result)) {
126 $imgset =new XoopsImageset();
127 $imgset->assignVars($myrow);
128 if (!$id_as_key) {
129 $ret[] =& $imgset;
130 } else {
131 $ret[$myrow['imgset_id']] =& $imgset;
132 }
133 unset($imgset);
134 }
135 return $ret;
136 }
137
138 public function linkThemeset($imgset_id, $tplset_name)
139 {
140 $imgset_id = (int)$imgset_id;
141 $tplset_name = trim($tplset_name);
142 if ($imgset_id <= 0 || '' == $tplset_name) {
143 return false;
144 }
145 if (!$this->unlinkThemeset($imgset_id, $tplset_name)) {
146 return false;
147 }
148 $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));
149 $result = $this->db->query($sql);
150 if (!$result) {
151 return false;
152 }
153 return true;
154 }
155
156 public function unlinkThemeset($imgset_id, $tplset_name)
157 {
158 $imgset_id = (int)$imgset_id;
159 $tplset_name = trim($tplset_name);
160 if ($imgset_id <= 0 || '' == $tplset_name) {
161 return false;
162 }
163 $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));
164 $result = $this->db->query($sql);
165 if (!$result) {
166 return false;
167 }
168 return true;
169 }
170
171 public function &getList($refid = null, $tplset = null)
172 {
173 $criteria = new CriteriaCompo();
174 if (isset($refid)) {
175 $criteria->add(new Criteria('imgset_refid', (int)$refid));
176 }
177 if (isset($tplset)) {
178 $criteria->add(new Criteria('tplset_name', $tplset));
179 }
180 $imgsets =& $this->getObjects($criteria, true);
181 $ret = [];
182 foreach (array_keys($imgsets) as $i) {
183 $ret[$i] = $imgsets[$i]->getVar('imgset_name');
184 }
185 return $ret;
186 }
187}
initVar($key, $data_type, $value=null, $required=false, $maxlength=null, $options='')
Definition object.php:206