38 public function &
create($isNew =
true)
47 public function &
get($id)
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);
56 $imgset->assignVars($this->db->fetchArray($result));
69 if (
'xoopsimageset' != strtolower(get_class($imgset))) {
72 if (!$imgset->isDirty()) {
75 if (!$imgset->cleanVars()) {
78 foreach ($imgset->cleanVars as $k => $v) {
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);
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);
87 if (!$result = $this->db->query($sql)) {
90 if (empty($imgset_id)) {
91 $imgset_id = $this->db->getInsertId();
93 $imgset->assignVar(
'imgset_id', $imgset_id);
97 public function delete(&$imgset)
99 if (
'xoopsimageset' != strtolower(get_class($imgset))) {
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)) {
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);
111 public function &getObjects($criteria =
null, $id_as_key =
false)
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();
121 $result = $this->db->query($sql, $limit, $start);
125 while ($myrow = $this->db->fetchArray($result)) {
126 $imgset =
new XoopsImageset();
127 $imgset->assignVars($myrow);
131 $ret[$myrow[
'imgset_id']] =& $imgset;
138 public function linkThemeset($imgset_id, $tplset_name)
140 $imgset_id = (int)$imgset_id;
141 $tplset_name = trim($tplset_name);
142 if ($imgset_id <= 0 ||
'' == $tplset_name) {
145 if (!$this->unlinkThemeset($imgset_id, $tplset_name)) {
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);
156 public function unlinkThemeset($imgset_id, $tplset_name)
158 $imgset_id = (int)$imgset_id;
159 $tplset_name = trim($tplset_name);
160 if ($imgset_id <= 0 ||
'' == $tplset_name) {
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);
171 public function &getList($refid =
null, $tplset =
null)
173 $criteria =
new CriteriaCompo();
175 $criteria->add(
new Criteria(
'imgset_refid', (
int)$refid));
177 if (isset($tplset)) {
178 $criteria->add(
new Criteria(
'tplset_name', $tplset));
180 $imgsets =& $this->getObjects($criteria,
true);
182 foreach (array_keys($imgsets) as $i) {
183 $ret[$i] = $imgsets[$i]->getVar(
'imgset_name');