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

Revision 405, 7.7 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: configcategory.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
36/**
37 *
38 *
39 * @package     kernel
40 *
41 * @author      Kazumi Ono  <[email protected]>
42 * @copyright   copyright (c) 2000-2003 XOOPS.org
43 */
44
45
46/**
47 * A category of configs
48 *
49 * @author  Kazumi Ono  <[email protected]>
50 * @copyright   copyright (c) 2000-2003 XOOPS.org
51 *
52 * @package     kernel
53 */
54class XoopsConfigCategory extends XoopsObject
55{
56    /**
57     * Constructor
58     *
59     */
60    function XoopsConfigCategory()
61    {
62        $this->XoopsObject();
63        $this->initVar('confcat_id', XOBJ_DTYPE_INT, null);
64        $this->initVar('confcat_name', XOBJ_DTYPE_OTHER, null);
65        $this->initVar('confcat_order', XOBJ_DTYPE_INT, 0);
66    }
67}
68
69
70/**
71 * XOOPS configuration category handler class. 
72 *
73 * This class is responsible for providing data access mechanisms to the data source
74 * of XOOPS configuration category class objects.
75 *
76 * @author  Kazumi Ono <[email protected]>
77 * @copyright   copyright (c) 2000-2003 XOOPS.org
78 *
79 * @package     kernel
80 * @subpackage  config
81 */
82class XoopsConfigCategoryHandler extends XoopsObjectHandler
83{
84
85    /**
86     * Create a new category
87     *
88     * @param   bool    $isNew  Flag the new object as "new"?
89     *
90     * @return  object  New {@link XoopsConfigCategory}
91     */
92    function &create($isNew = true)
93    {
94        $confcat =& new XoopsConfigCategory();
95        if ($isNew) {
96            $confcat->setNew();
97        }
98        return $confcat;
99    }
100
101    /**
102     * Retrieve a {@link XoopsConfigCategory}
103     *
104     * @param   int $id ID
105     *
106     * @return  object  {@link XoopsConfigCategory}, FALSE on fail
107     */
108    function &get($id)
109    {
110        $ret = false;
111        $id = intval($id);
112        if ($id > 0) {
113            $sql = 'SELECT * FROM '.$this->db->prefix('configcategory').' WHERE confcat_id='.$id;
114            if ($result = $this->db->query($sql)) {
115                $numrows = $this->db->getRowsNum($result);
116                if ($numrows == 1) {
117                    $confcat =& new XoopsConfigCategory();
118                    $confcat->assignVars($this->db->fetchArray($result), false);
119                    $ret =& $confcat;
120                }
121            }
122        }
123        return $ret;
124    }
125
126    /**
127     * Store a {@link XoopsConfigCategory}
128     *
129     * @param   object   &$confcat  {@link XoopsConfigCategory}
130     *
131     * @return  bool    TRUE on success
132     */
133    function insert(&$confcat)
134    {
135        if (strtolower(get_class($confcat)) != 'xoopsconfigcategory') {
136            return false;
137        }
138        if (!$confcat->isDirty()) {
139            return true;
140        }
141        if (!$confcat->cleanVars()) {
142            return false;
143        }
144        foreach ($confcat->cleanVars as $k => $v) {
145            ${$k} = $v;
146        }
147        if ($confcat->isNew()) {
148            $confcat_id = $this->db->genId('configcategory_confcat_id_seq');
149            $sql = sprintf("INSERT INTO %s (confcat_id, confcat_name, confcat_order) VALUES (%u, %s, %u)", $this->db->prefix('configcategory'), $confcat_id, $this->db->quoteString($confcat_name), $confcat_order);
150        } else {
151            $sql = sprintf("UPDATE %s SET confcat_name = %s, confcat_order = %u WHERE confcat_id = %u", $this->db->prefix('configcategory'), $this->db->quoteString($confcat_name), $confcat_order, $confcat_id);
152        }
153        if (!$result = $this->db->query($sql)) {
154            return false;
155        }
156        if (empty($confcat_id)) {
157            $confcat_id = $this->db->getInsertId();
158        }
159        $confcat->assignVar('confcat_id', $confcat_id);
160        return $confcat_id;
161    }
162
163    /**
164     * Delelete a {@link XoopsConfigCategory}
165     *
166     * @param   object  &$confcat   {@link XoopsConfigCategory}
167     *
168     * @return  bool    TRUE on success
169     */
170    function delete(&$confcat)
171    {
172        if (strtolower(get_class($confcat)) != 'xoopsconfigcategory') {
173            return false;
174        }
175        $sql = sprintf("DELETE FROM %s WHERE confcat_id = %u", $this->db->prefix('configcategory'), $configcategory->getVar('confcat_id'));
176        if (!$result = $this->db->query($sql)) {
177            return false;
178        }
179        return true;
180    }
181
182    /**
183     * Get some {@link XoopsConfigCategory}s
184     *
185     * @param   object  $criteria   {@link CriteriaElement}
186     * @param   bool    $id_as_key  Use the IDs as keys to the array?
187     *
188     * @return  array   Array of {@link XoopsConfigCategory}s
189     */
190    function &getObjects($criteria = null, $id_as_key = false)
191    {
192        $ret = array();
193        $limit = $start = 0;
194        $sql = 'SELECT * FROM '.$this->db->prefix('configcategory');
195        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
196            $sql .= ' '.$criteria->renderWhere();
197            $sort = !in_array($criteria->getSort(), array('confcat_id', 'confcat_name', 'confcat_order')) ? 'confcat_order' : $criteria->getSort();
198            $sql .= ' ORDER BY '.$sort.' '.$criteria->getOrder();
199            $limit = $criteria->getLimit();
200            $start = $criteria->getStart();
201        }
202        $result = $this->db->query($sql, $limit, $start);
203        if (!$result) {
204            return $ret;
205        }
206        while ($myrow = $this->db->fetchArray($result)) {
207            $confcat =& new XoopsConfigCategory();
208            $confcat->assignVars($myrow, false);
209            if (!$id_as_key) {
210                $ret[] =& $confcat;
211            } else {
212                $ret[$myrow['confcat_id']] =& $confcat;
213            }
214            unset($confcat);
215        }
216        return $ret;
217    }
218}
219?>
Note: See TracBrowser for help on using the repository browser.