source: temp/test-xoops.ec-cube.net/html/kernel/imageset.php @ 405

Revision 405, 7.9 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: imageset.php,v 1.3 2006/05/01 02:37:28 onokazu Exp $
3//  ------------------------------------------------------------------------ //
4//                XOOPS - PHP Content Management System                      //
5//                    Copyright (c) 2000 XOOPS.org                           //
6//                       <http://www.xoops.org/>                             //
7//  ------------------------------------------------------------------------ //
8//  This program is free software; you can redistribute it and/or modify     //
9//  it under the terms of the GNU General Public License as published by     //
10//  the Free Software Foundation; either version 2 of the License, or        //
11//  (at your option) any later version.                                      //
12//                                                                           //
13//  You may not change or alter any portion of this comment or credits       //
14//  of supporting developers from this source code or any supporting         //
15//  source code which is considered copyrighted (c) material of the          //
16//  original comment or credit authors.                                      //
17//                                                                           //
18//  This program is distributed in the hope that it will be useful,          //
19//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21//  GNU General Public License for more details.                             //
22//                                                                           //
23//  You should have received a copy of the GNU General Public License        //
24//  along with this program; if not, write to the Free Software              //
25//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26//  ------------------------------------------------------------------------ //
27// Author: Kazumi Ono (AKA onokazu)                                          //
28// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
29// Project: The XOOPS Project                                                //
30// ------------------------------------------------------------------------- //
31
32if (!defined('XOOPS_ROOT_PATH')) {
33    exit();
34}
35
36class XoopsImageset extends XoopsObject
37{
38
39    function XoopsImageset()
40    {
41        $this->XoopsObject();
42        $this->initVar('imgset_id', XOBJ_DTYPE_INT, null, false);
43        $this->initVar('imgset_name', XOBJ_DTYPE_TXTBOX, null, true, 50);
44        $this->initVar('imgset_refid', XOBJ_DTYPE_INT, 0, false);
45    }
46}
47
48/**
49* XOOPS imageset handler class. 
50* This class is responsible for providing data access mechanisms to the data source
51* of XOOPS imageset class objects.
52*
53*
54* @author  Kazumi Ono <[email protected]>
55*/
56
57class XoopsImagesetHandler extends XoopsObjectHandler
58{
59
60    function &create($isNew = true)
61    {
62        $imgset =& new XoopsImageset();
63        if ($isNew) {
64            $imgset->setNew();
65        }
66        return $imgset;
67    }
68
69    function &get($id)
70    {
71        $ret = false;
72        if (intval($id) > 0) {
73            $sql = 'SELECT * FROM '.$this->db->prefix('imgset').' WHERE imgset_id='.$id;
74            if ($result = $this->db->query($sql)) {
75                $numrows = $this->db->getRowsNum($result);
76                if ($numrows == 1) {
77                    $imgset =& new XoopsImageset();
78                    $imgset->assignVars($this->db->fetchArray($result));
79                    $ret =& $imgset;
80                }
81            }
82        }
83        return $ret;
84    }
85
86    function insert(&$imgset)
87    {
88        if (strtolower(get_class($imgset)) != 'xoopsimageset') {
89            return false;
90        }
91        if (!$imgset->isDirty()) {
92            return true;
93        }
94        if (!$imgset->cleanVars()) {
95            return false;
96        }
97        foreach ($imgset->cleanVars as $k => $v) {
98            ${$k} = $v;
99        }
100        if ($imgset->isNew()) {
101            $imgset_id = $this->db->genId('imgset_imgset_id_seq');
102            $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);
103        } else {
104            $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);
105        }
106        if (!$result = $this->db->query($sql)) {
107            return false;
108        }
109        if (empty($imgset_id)) {
110            $imgset_id = $this->db->getInsertId();
111        }
112        $imgset->assignVar('imgset_id', $imgset_id);
113        return true;
114    }
115
116    function delete(&$imgset)
117    {
118        if (strtolower(get_class($imgset)) != 'xoopsimageset') {
119            return false;
120        }
121        $sql = sprintf("DELETE FROM %s WHERE imgset_id = %u", $this->db->prefix('imgset'), $imgset->getVar('imgset_id'));
122        if (!$result = $this->db->query($sql)) {
123            return false;
124        }
125        $sql = sprintf("DELETE FROM %s WHERE imgset_id = %u", $this->db->prefix('imgset_tplset_link'), $imgset->getVar('imgset_id'));
126        $this->db->query($sql);
127        return true;
128    }
129
130    function &getObjects($criteria = null, $id_as_key = false)
131    {
132        $ret = array();
133        $limit = $start = 0;
134        $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';
135        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
136            $sql .= ' '.$criteria->renderWhere();
137            $limit = $criteria->getLimit();
138            $start = $criteria->getStart();
139        }
140        $result = $this->db->query($sql, $limit, $start);
141        if (!$result) {
142            return $ret;
143        }
144        while ($myrow = $this->db->fetchArray($result)) {
145            $imgset =& new XoopsImageset();
146            $imgset->assignVars($myrow);
147            if (!$id_as_key) {
148                $ret[] =& $imgset;
149            } else {
150                $ret[$myrow['imgset_id']] =& $imgset;
151            }
152            unset($imgset);
153        }
154        return $ret;
155    }
156
157    function linkThemeset($imgset_id, $tplset_name)
158    {
159        $imgset_id = intval($imgset_id);
160        $tplset_name = trim($tplset_name);
161        if ($imgset_id <= 0 || $tplset_name == '') {
162            return false;
163        }
164        if (!$this->unlinkThemeset($imgset_id, $tplset_name)) {
165            return false;
166        }
167        $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));
168        $result = $this->db->query($sql);
169        if (!$result) {
170            return false;
171        }
172        return true;
173    }
174
175    function unlinkThemeset($imgset_id, $tplset_name)
176    {
177        $imgset_id = intval($imgset_id);
178        $tplset_name = trim($tplset_name);
179        if ($imgset_id <= 0 || $tplset_name == '') {
180            return false;
181        }
182        $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));
183        $result = $this->db->query($sql);
184        if (!$result) {
185            return false;
186        }
187        return true;
188    }
189
190    function &getList($refid = null, $tplset = null)
191    {
192        $criteria = new CriteriaCompo();
193        if (isset($refid)) {
194            $criteria->add(new Criteria('imgset_refid', intval($refid)));
195        }
196        if (isset($tplset)) {
197            $criteria->add(new Criteria('tplset_name', $tplset));
198        }
199        $imgsets =& $this->getObjects($criteria, true);
200        $ret = array();
201        foreach (array_keys($imgsets) as $i) {
202            $ret[$i] = $imgsets[$i]->getVar('imgset_name');
203        }
204        return $ret;
205    }
206}
207?>
Note: See TracBrowser for help on using the repository browser.