[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 <?php 2 /***************************************************** 3 * This file is part of Agora, web based content management system. 4 * 5 * Agora is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 2 of the License. 8 * 9 * Agora is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details (file "COPYING"). 13 * 14 * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière. 15 * List of authors detailed in "copyright_fr.html" file. 16 * E-mail : agora@sig.premier-ministre.gouv.fr 17 * Web site : http://www.agora.gouv.fr 18 *****************************************************/ 19 // Base class for profil business persistence abstraction. 20 // 21 22 if (defined("_BD_PROFIL")) 23 return; 24 25 define("_BD_PROFIL", "1"); 26 27 require_once dirname(__FILE__). "/metier.php"; 28 29 define("PROFIL_ALL_FIELDS", " poids, intitule "); 30 31 /** 32 * BD_profil is a base class for profil business persistence abstraction implementations, and must be 33 * inherited by all such. 34 * @package BD 35 * @author Antoine Angénieux <aangenieux@clever-age.com> 36 * @author Erwan Le Bescond <elebescond@clever-age.com> 37 * @access public 38 */ 39 class BD_profil extends BD_metier { 40 // {{{ properties 41 42 /** 43 * Poids. 44 * @var Int 45 * @access private 46 */ 47 var $_poids; 48 49 /** 50 * Intitule. 51 * @var String 52 * @access private 53 */ 54 var $_intitule; 55 56 // {{{ factory() 57 function &factory ($dbParameters = null, $dbOptions = null) { 58 if (file_exists( 59 dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/profil_" . $dbParameters->_dbEngine . ".php") 60 == false) { 61 include_once (dirname(__FILE__). "/common/profil_common.php"); 62 $classname = "BD_profil_common"; 63 } 64 else { 65 include_once 66 (dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/profil_" . $dbParameters->_dbEngine . ".php"); 67 $classname = "BD_profil_" . $dbParameters->_dbEngine; 68 } 69 70 if (!class_exists($classname)) { 71 return PEAR::raiseError("Cannot instanciate class $classname", null, null, null, null, null, false); 72 } 73 74 $obj = &new $classname; 75 $result = $obj->setDbParameters($dbParameters); 76 77 if ($dbOptions != null) { 78 $obj->setDbOptions($dbOptions); 79 } 80 81 if (PEAR::isError($result)) { 82 return $result; 83 } 84 else { 85 return $obj; 86 } 87 } 88 89 // }}} 90 91 // {{{ constructor 92 93 /** 94 * DB_profil constructor. 95 * 96 * @access public 97 */ 98 99 function BD_profil () { } 100 101 // }}} 102 103 // {{{ getPoids() 104 105 function getPoids () { 106 return $this->_poids; 107 } 108 109 // }}} 110 111 // {{{ setPoids() 112 113 function setPoids ($poids) { 114 $this->_poids = $this->corriger_caracteres($poids); 115 } 116 117 // }}} 118 119 // {{{ getIntitule() 120 121 function getIntitule () { 122 return $this->_intitule; 123 } 124 125 // }}} 126 127 // {{{ setIntitue() 128 129 function setIntitule ($intitule) { 130 $this->_intitule = $this->corriger_caracteres($intitule); 131 } 132 133 // }}} 134 135 // {{{ create() 136 137 function create () { 138 $db = &$this->_getDB(); 139 140 if (DB::isError($db)) { 141 return PEAR::raiseError("[" . get_class($this). " DB_profil : create()] " . $db->getMessage(). "", null, 142 null, null, 143 null, null, 144 false); 145 } 146 147 $query 148 = "INSERT INTO " . $GLOBALS['table_prefix']. "_profils (" . PROFIL_ALL_FIELDS . ") VALUES " . "(" . $this->_poids . ", " . "'" . $db->quoteString( 149 $this->_intitule). "') "; 150 151 $result = $db->query($query); 152 153 if (DB::isError($result)) { 154 return PEAR::raiseError("[" . get_class($this). " DB_profil : create()] " . $result->getMessage(). "", null, 155 null, null, 156 null, null, 157 false); 158 } 159 } 160 161 // }}} 162 163 // {{{ delete() 164 165 function delete ($poids) { 166 $db = &$this->_getDB(); 167 168 if (DB::isError($db)) { 169 return PEAR::raiseError("[" . get_class($this). " DB_profil : delete()] " . $db->getMessage(). "", null, 170 null, null, 171 null, null, 172 false); 173 } 174 175 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_profils WHERE poids = $poids"; 176 177 $result = $db->query($query); 178 179 if (DB::isError($result)) { 180 return PEAR::raiseError("[" . get_class($this). " DB_profil : delete()] " . $result->getMessage(). "", null, 181 null, null, 182 null, null, 183 false); 184 } 185 } 186 187 // }}} 188 189 // {{{ update() 190 191 function update () { 192 $db = &$this->_getDB(); 193 194 if (DB::isError($db)) { 195 return PEAR::raiseError("[" . get_class($this). " DB_profil : update()] " . $db->getMessage(). "", null, 196 null, null, 197 null, null, 198 false); 199 } 200 201 $query 202 = "UPDATE " . $GLOBALS['table_prefix']. "_profils " . "SET poids = " . $this->_poids . ", " . "intitule = '" . $db->quoteString( 203 $this->_intitule). "' " . "WHERE poids = " . $this->_poids; 204 205 $result = $db->query($query); 206 207 if (DB::isError($result)) { 208 return PEAR::raiseError("[" . get_class($this). " DB_profil : update()] " . $result->getMessage(). "", null, 209 null, null, 210 null, null, 211 false); 212 } 213 } 214 215 // }}} 216 217 // {{{ load() 218 219 function load ($poids) { 220 $db = &$this->_getDB(); 221 222 if (DB::isError($db)) { 223 return PEAR::raiseError("[" . get_class($this). " DB_profil : load()] " . $db->getMessage(). "", null, null, 224 null, null, null, 225 false); 226 } 227 228 $query = 'SELECT' . PROFIL_ALL_FIELDS . 'FROM ' . $GLOBALS['table_prefix']. '_profils WHERE poids =' . $poids; 229 230 //echo '<br />' . $query . '<br />'; 231 232 $result = $db->query($query); 233 234 if (DB::isError($result)) { 235 return PEAR::raiseError("[" . get_class($this). " DB_profil : load()] " . $result->getMessage(). "", null, 236 null, null, 237 null, null, 238 false); 239 } 240 else { 241 if ($row = $result->fetchRow()) { 242 $this->_fetchData($row); 243 } 244 else { 245 return PEAR::raiseError( 246 "[" . get_class( 247 $this). " Db_profil : load(" . $poids . ")] Aucune action ne correspond pas à ce nom!", 248 null, 249 null, 250 null, 251 null, 252 null, 253 false); 254 } 255 $result->free(); 256 } 257 } 258 259 // }}} 260 261 // {{{ _fetchData() 262 263 function _fetchData ($row) { 264 $this->setPoids($row['poids']); 265 $this->setIntitule($row['intitule']); 266 } 267 268 // }}} 269 270 // {{{ getAllProfils() 271 272 function &getAllProfils () { 273 $profils = array(); 274 $db = &$this->_getDB(); 275 276 if (DB::isError($db)) { 277 return PEAR::raiseError("[" . get_class($this). " DB_profil : getAllProfils()] " . $db->getMessage(). "", 278 null, 279 null, 280 null, 281 null, 282 null, 283 false); 284 } 285 286 $query = "SELECT " . PROFIL_ALL_FIELDS . " FROM " . $GLOBALS['table_prefix']. "_profils"; 287 288 //echo $query .'<br />'; 289 290 $result = $db->query($query); 291 292 if (DB::isError($result)) { 293 return PEAR::raiseError( 294 "[" . get_class($this). " DB_profil : getAllProfils()] " . $result->getMessage(). "", null, null, 295 null, null, null, 296 false); 297 } 298 299 while ($row = $result->fetchRow()) { 300 $resultProfil = &BD_profil::factory($this->getDbParameters(), $this->getDbOptions()); 301 $resultProfil->_fetchData($row); 302 $profils[] = &$resultProfil; 303 } 304 305 $result->free(); 306 return $profils; 307 } 308 309 // }}} 310 311 // {{{ getProfilForIntitule($intitule) 312 313 function &getProfilForIntitule ($intitule) { 314 $db = &$this->_getDB(); 315 316 if (DB::isError($db)) { 317 return PEAR::raiseError( 318 "[" . get_class($this). " DB_profil : getProfilForIntitule()] " . $db->getMessage(). "", null, 319 null, null, 320 null, null, 321 false); 322 } 323 324 $query 325 = "SELECT " . PROFIL_ALL_FIELDS . " FROM " . $GLOBALS['table_prefix']. "_profils WHERE intitule='$intitule'"; 326 327 //echo '<br>' . $query . '<br>'; 328 $result = $db->query($query); 329 330 if (DB::isError($result)) { 331 return PEAR::raiseError( 332 "[" . get_class($this). " DB_profil : getProfilForIntitule()] " . $result->getMessage(). "", 333 null, 334 null, 335 null, 336 null, 337 null, 338 false); 339 } 340 341 if ($row = $result->fetchRow()) { 342 $resultProfil = &BD_profil::factory($this->getDbParameters(), $this->getDbOptions()); 343 $resultProfil->_fetchData($row); 344 } 345 346 $result->free(); 347 return $resultProfil; 348 } 349 350 // }}} 351 352 // {{{ getSumOfPoids($intitule) 353 354 function &getSumOfPoids () { 355 $db = &$this->_getDB(); 356 357 if (DB::isError($db)) { 358 return PEAR::raiseError("[" . get_class($this). " DB_profil : getSumOfPoids()] " . $db->getMessage(). "", null, null, null, null, null, false); 359 } 360 361 $query = "SELECT SUM(poids) as sum FROM " . $GLOBALS['table_prefix']. "_profils"; 362 363 //echo '<br>' . $query . '<br>'; 364 $result = $db->query($query); 365 366 if (DB::isError($result)) { 367 return PEAR::raiseError("[" . get_class($this). " DB_profil : getSumOfPoids()] " . $result->getMessage(). "", null, null, null, null, null, false); 368 } 369 370 if ($row = $result->fetchRow()) { 371 return $row['sum']; 372 } 373 374 $result->free(); 375 return 0; 376 } 377 378 // }}} 379 380 } 381 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |