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

Revision 405, 7.9 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: tplset.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// ------------------------------------------------------------------------- //
31if (!defined('XOOPS_ROOT_PATH')) {
32    exit();
33}
34class XoopsTplset extends XoopsObject
35{
36
37    function XoopsTplset()
38    {
39        $this->XoopsObject();
40        $this->initVar('tplset_id', XOBJ_DTYPE_INT, null, false);
41        $this->initVar('tplset_name', XOBJ_DTYPE_OTHER, null, false);
42        $this->initVar('tplset_desc', XOBJ_DTYPE_TXTBOX, null, false, 255);
43        $this->initVar('tplset_credits', XOBJ_DTYPE_TXTAREA, null, false);
44        $this->initVar('tplset_created', XOBJ_DTYPE_INT, 0, false);
45    }
46}
47
48/**
49* XOOPS tplset handler class.
50* This class is responsible for providing data access mechanisms to the data source
51* of XOOPS tplset class objects.
52*
53*
54* @author  Kazumi Ono <[email protected]>
55*/
56
57class XoopsTplsetHandler extends XoopsObjectHandler
58{
59
60    function &create($isNew = true)
61    {
62        $tplset =& new XoopsTplset();
63        if ($isNew) {
64            $tplset->setNew();
65        }
66        return $tplset;
67    }
68
69    function &get($id)
70    {
71        $ret = false;
72        $id = intval($id);
73        if ($id > 0) {
74            $sql = 'SELECT * FROM '.$this->db->prefix('tplset').' WHERE tplset_id='.$id;
75            if ($result = $this->db->query($sql)) {
76                $numrows = $this->db->getRowsNum($result);
77                if ($numrows == 1) {
78                    $tplset = new XoopsTplset();
79                    $tplset->assignVars($this->db->fetchArray($result));
80                    $ret =& $tplset;
81                }
82            }
83        }
84        return $ret;
85    }
86
87    function &getByName($tplset_name)
88    {
89        $ret = false;
90        $tplset_name = trim($tplset_name);
91        if ($tplset_name != '') {
92            $sql = 'SELECT * FROM '.$this->db->prefix('tplset').' WHERE tplset_name='.$this->db->quoteString($tplset_name);
93            if ($result = $this->db->query($sql)) {
94                $numrows = $this->db->getRowsNum($result);
95                if ($numrows == 1) {
96                    $tplset =& new XoopsTplset();
97                    $tplset->assignVars($this->db->fetchArray($result));
98                    $ret =& $tplset;
99                }
100            }
101        }
102        return $ret;
103    }
104
105    function insert(&$tplset)
106    {
107        if (strtolower(get_class($tplset)) != 'xoopstplset') {
108            return false;
109        }
110        if (!$tplset->isDirty()) {
111            return true;
112        }
113        if (!$tplset->cleanVars()) {
114            return false;
115        }
116        foreach ($tplset->cleanVars as $k => $v) {
117            ${$k} = $v;
118        }
119        if ($tplset->isNew()) {
120            $tplset_id = $this->db->genId('tplset_tplset_id_seq');
121            $sql = sprintf("INSERT INTO %s (tplset_id, tplset_name, tplset_desc, tplset_credits, tplset_created) VALUES (%u, %s, %s, %s, %u)", $this->db->prefix('tplset'), $tplset_id, $this->db->quoteString($tplset_name), $this->db->quoteString($tplset_desc), $this->db->quoteString($tplset_credits), $tplset_created);
122        } else {
123            $sql = sprintf("UPDATE %s SET tplset_name = %s, tplset_desc = %s, tplset_credits = %s, tplset_created = %u WHERE tplset_id = %u", $this->db->prefix('tplset'), $this->db->quoteString($tplset_name), $this->db->quoteString($tplset_desc), $this->db->quoteString($tplset_credits), $tplset_created, $tplset_id);
124        }
125        if (!$result = $this->db->query($sql)) {
126            return false;
127        }
128        if (empty($tplset_id)) {
129            $tplset_id = $this->db->getInsertId();
130        }
131        $tplset->assignVar('tplset_id', $tplset_id);
132        return true;
133    }
134
135    function delete(&$tplset)
136    {
137        if (strtolower(get_class($tplset)) != 'xoopstplset') {
138            return false;
139        }
140        $sql = sprintf("DELETE FROM %s WHERE tplset_id = %u", $this->db->prefix('tplset'), $tplset->getVar('tplset_id'));
141        if (!$result = $this->db->query($sql)) {
142            return false;
143        }
144        $sql = sprintf("DELETE FROM %s WHERE tplset_name = %s", $this->db->prefix('imgset_tplset_link'), $this->db->quoteString($tplset->getVar('tplset_name')));
145        $this->db->query($sql);
146        return true;
147    }
148
149    function &getObjects($criteria = null, $id_as_key = false)
150    {
151        $ret = array();
152        $limit = $start = 0;
153        $sql = 'SELECT * FROM '.$this->db->prefix('tplset');
154        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
155            $sql .= ' '.$criteria->renderWhere().' ORDER BY tplset_id';
156            $limit = $criteria->getLimit();
157            $start = $criteria->getStart();
158        }
159        $result = $this->db->query($sql, $limit, $start);
160        if (!$result) {
161            return $ret;
162        }
163        while ($myrow = $this->db->fetchArray($result)) {
164            $tplset =& new XoopsTplset();
165            $tplset->assignVars($myrow);
166            if (!$id_as_key) {
167                $ret[] =& $tplset;
168            } else {
169                $ret[$myrow['tplset_id']] =& $tplset;
170            }
171            unset($tplset);
172        }
173        return $ret;
174    }
175
176
177    function getCount($criteria = null)
178    {
179        $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('tplset');
180        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
181            $sql .= ' '.$criteria->renderWhere();
182        }
183        if (!$result =& $this->db->query($sql)) {
184            return 0;
185        }
186        list($count) = $this->db->fetchRow($result);
187        return $count;
188    }
189
190    function &getList($criteria = null)
191    {
192        $ret = array();
193        $tplsets =& $this->getObjects($criteria, true);
194        foreach (array_keys($tplsets) as $i) {
195            $ret[$tplsets[$i]->getVar('tplset_name')] = $tplsets[$i]->getVar('tplset_name');
196        }
197        return $ret;
198    }
199}
200?>
Note: See TracBrowser for help on using the repository browser.