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