| [ Index ] |
|
Code source de XOOPS 2.0.17.1 |
1 <?php 2 // $Id: configcategory.php 506 2006-05-26 23:10:37Z skalpa $ 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 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 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 <onokazu@xoops.org> 77 * @copyright copyright (c) 2000-2003 XOOPS.org 78 * 79 * @package kernel 80 * @subpackage config 81 */ 82 class 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 $confcat = false; 110 $id = intval($id); 111 if ($id > 0) { 112 $sql = 'SELECT * FROM '.$this->db->prefix('configcategory').' WHERE confcat_id='.$id; 113 if (!$result = $this->db->query($sql)) { 114 return $confcat; 115 } 116 $numrows = $this->db->getRowsNum($result); 117 if ($numrows == 1) { 118 $confcat = new XoopsConfigCategory(); 119 $confcat->assignVars($this->db->fetchArray($result), false); 120 } 121 } 122 return $confcat; 123 } 124 125 /** 126 * Store a {@link XoopsConfigCategory} 127 * 128 * @param object &$confcat {@link XoopsConfigCategory} 129 * 130 * @return bool TRUE on success 131 */ 132 function insert(&$confcat) 133 { 134 if (strtolower(get_class($confcat)) != 'xoopsconfigcategory') { 135 return false; 136 } 137 if (!$confcat->isDirty()) { 138 return true; 139 } 140 if (!$confcat->cleanVars()) { 141 return false; 142 } 143 foreach ($confcat->cleanVars as $k => $v) { 144 ${$k} = $v; 145 } 146 if ($confcat->isNew()) { 147 $confcat_id = $this->db->genId('configcategory_confcat_id_seq'); 148 $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); 149 } else { 150 $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); 151 } 152 if (!$result = $this->db->query($sql)) { 153 return false; 154 } 155 if (empty($confcat_id)) { 156 $confcat_id = $this->db->getInsertId(); 157 } 158 $confcat->assignVar('confcat_id', $confcat_id); 159 return $confcat_id; 160 } 161 162 /** 163 * Delelete a {@link XoopsConfigCategory} 164 * 165 * @param object &$confcat {@link XoopsConfigCategory} 166 * 167 * @return bool TRUE on success 168 */ 169 function delete(&$confcat) 170 { 171 if (strtolower(get_class($confcat)) != 'xoopsconfigcategory') { 172 return false; 173 } 174 $sql = sprintf("DELETE FROM %s WHERE confcat_id = %u", $this->db->prefix('configcategory'), $configcategory->getVar('confcat_id')); 175 if (!$result = $this->db->query($sql)) { 176 return false; 177 } 178 return true; 179 } 180 181 /** 182 * Get some {@link XoopsConfigCategory}s 183 * 184 * @param object $criteria {@link CriteriaElement} 185 * @param bool $id_as_key Use the IDs as keys to the array? 186 * 187 * @return array Array of {@link XoopsConfigCategory}s 188 */ 189 function getObjects($criteria = null, $id_as_key = false) 190 { 191 $ret = array(); 192 $limit = $start = 0; 193 $sql = 'SELECT * FROM '.$this->db->prefix('configcategory'); 194 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 195 $sql .= ' '.$criteria->renderWhere(); 196 $sort = !in_array($criteria->getSort(), array('confcat_id', 'confcat_name', 'confcat_order')) ? 'confcat_order' : $criteria->getSort(); 197 $sql .= ' ORDER BY '.$sort.' '.$criteria->getOrder(); 198 $limit = $criteria->getLimit(); 199 $start = $criteria->getStart(); 200 } 201 $result = $this->db->query($sql, $limit, $start); 202 if (!$result) { 203 return $ret; 204 } 205 while ($myrow = $this->db->fetchArray($result)) { 206 $confcat = new XoopsConfigCategory(); 207 $confcat->assignVars($myrow, false); 208 if (!$id_as_key) { 209 $ret[] =& $confcat; 210 } else { 211 $ret[$myrow['confcat_id']] =& $confcat; 212 } 213 unset($confcat); 214 } 215 return $ret; 216 } 217 } 218 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Nov 25 11:44:32 2007 | par Balluche grâce à PHPXref 0.7 |
|