[ 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 Index Rubrique business persistence abstraction. 20 // 21 22 if (defined("_BD_INDEX_RUBRIQUES")) 23 return; 24 25 define("_BD_INDEX_RUBRIQUES", "1"); 26 27 require_once("PEAR.php"); 28 require_once("DB.php"); 29 require_once dirname(__FILE__). "/metier.php"; 30 require_once dirname(__FILE__). "/../../inc_filtres.php"; 31 32 define("INDEX_RUBRIQUES_ALL_FIELDS", " hash, points, id_rubrique "); 33 34 /** 35 * BD_index_rubriques is a base class for rubrique business persistence abstraction implementations, and must be 36 * inherited by all such. 37 * @package BD 38 * @author Antoine Angénieux <aangenieux@clever-age.com> 39 * @author Erwan Le Bescond <elebescond@clever-age.com> 40 * @access public 41 */ 42 class BD_index_rubriques extends BD_metier { 43 // {{{ properties 44 45 /** 46 * $_hash 47 * @var int 48 * @access private 49 */ 50 var $_hash; 51 52 /** 53 * $_points 54 * @var int 55 * @access private 56 */ 57 var $_points; 58 59 /** 60 * $_rubriqueId 61 * @var int 62 * @access private 63 */ 64 var $_rubriqueId; 65 66 // }}} 67 68 // {{{ factory() 69 function &factory ($dbParameters = null, $dbOptions = null) { 70 if (file_exists( 71 dirname( 72 __FILE__). "/" . $dbParameters->_dbEngine . "/index_rubriques_" . $dbParameters->_dbEngine . ".php") 73 == false) { 74 include_once (dirname(__FILE__). "/common/index_rubriques_common.php"); 75 $classname = "BD_index_rubriques_common"; 76 } 77 else { 78 include_once (dirname( 79 __FILE__). "/" . $dbParameters->_dbEngine . "/index_rubriques_" . $dbParameters->_dbEngine . ".php"); 80 $classname = "BD_index_rubriques_" . $dbParameters->_dbEngine; 81 } 82 83 if (!class_exists($classname)) { 84 return PEAR::raiseError("Cannot instanciate class $classname", null, null, null, null, null, false); 85 } 86 87 $obj = &new $classname; 88 $result = $obj->setDbParameters($dbParameters); 89 90 if ($dbOptions != null) { 91 $obj->setDbOptions($dbOptions); 92 } 93 94 if (PEAR::isError($result)) { 95 return $result; 96 } 97 else { 98 return $obj; 99 } 100 } 101 102 // }}} 103 104 // {{{ constructor 105 106 /** 107 * DB_index_rubriques constructor. 108 * 109 * @access public 110 */ 111 112 function BD_index_rubriques () { } 113 114 // }}} 115 116 // {{{ getHash() 117 118 /** 119 * Returns the hash's value 120 * @return int 121 * @access public 122 */ 123 124 function getHash () { 125 return $this->_hash; 126 } 127 128 // }}} 129 130 // {{{ setHash() 131 132 function setHash ($hash) { 133 $this->_hash = corriger_caracteres($hash); 134 } 135 136 // }}} 137 138 // {{{ getPoints() 139 140 /** 141 * Returns the points' value 142 * @return int 143 * @access public 144 */ 145 146 function getPoints () { 147 return $this->_points; 148 } 149 150 // }}} 151 152 // {{{ setPoints() 153 154 /** 155 * Sets the points' value 156 * @param int 157 * @access public 158 */ 159 160 function setPoints ($points) { 161 $this->_points = $points; 162 } 163 164 // }}} 165 166 // {{{ getRubriqueId() 167 168 /** 169 * Returns the heading ID 170 * @return int 171 * @access public 172 */ 173 174 function getRubriqueId () { 175 return $this->_rubriqueId; 176 } 177 178 // }}} 179 180 // {{{ setRubriqueId() 181 182 /** 183 * Sets the heading ID 184 * @param int 185 * @access public 186 */ 187 188 function setRubriqueId ($rubriqueId) { 189 $this->_rubriqueId = $rubriqueId; 190 } 191 192 // }}} 193 194 // {{{ create() 195 196 /** 197 * This method is used to create a new index of headings in the database 198 * @access public 199 */ 200 201 function create () { 202 $db = &$this->_getDB(); 203 204 if (DB::isError($db)) { 205 return PEAR::raiseError("[" . get_class($this). " DB_index_rubriques : create()] " . $db->getMessage(). "", 206 null, 207 null, 208 null, 209 null, 210 null, 211 false); 212 } 213 214 $query 215 = "INSERT INTO " . $GLOBALS['table_prefix']. "_index_rubriques (" . INDEX_RUBRIQUES_ALL_FIELDS . ") VALUES " . "('" . $db->quoteString( 216 $this->_hash). "', " . $this->_points . ", " . $this->_rubriqueId . ")"; 217 218 //echo "<br>".$query."<br>"; 219 220 $result = $db->query($query); 221 222 if (DB::isError($result)) { 223 return PEAR::raiseError( 224 "[" . get_class($this). " DB_index_rubriques : create()] " . $result->getMessage(). "", null, 225 null, null, 226 null, null, 227 false); 228 } 229 } 230 231 // }}} 232 233 // {{{ load() 234 235 /** 236 * This method is used to load an index of headings from the database 237 * @access public 238 * @param int $rubriqueId ID of heading to load 239 */ 240 241 function load ($rubriqueId) { 242 $db = &$this->_getDB(); 243 244 if (DB::isError($db)) { 245 return PEAR::raiseError("[" . get_class($this). " DB_index_rubriques : load()] " . $db->getMessage(). "", 246 null, 247 null, 248 null, 249 null, 250 null, 251 false); 252 } 253 254 $query 255 = "SELECT" . INDEX_RUBRIQUES_ALL_FIELDS . "FROM " . $GLOBALS['table_prefix']. "_index_rubriques WHERE rubriqueId = $rubriqueId"; 256 257 $result = $db->query($query); 258 259 if (DB::isError($result)) { 260 return PEAR::raiseError( 261 "[" . get_class($this). " DB_index_rubriques : load()] " . $result->getMessage(). "", null, null, 262 null, null, null, 263 false); 264 } 265 else { 266 if ($row = $result->fetchRow()) { 267 $this->_fetchData($row); 268 } 269 else { 270 return PEAR::raiseError( 271 "[" . get_class( 272 $this). " DB_index_rubriques : load($rubriqueId)] Aucun index de rubriques ne correspond à cet ID!", 273 null, 274 null, 275 null, 276 null, 277 null, 278 false); 279 } 280 $result->free(); 281 } 282 } 283 284 // }}} 285 286 // {{{ delete() 287 288 /** 289 * This method is used to delete the index of headings 290 * @access public 291 */ 292 293 function delete () { 294 $db = &$this->_getDB(); 295 296 if (DB::isError($db)) { 297 return PEAR::raiseError("[" . get_class($this). " DB_index_rubriques : delete()] " . $db->getMessage(). "", 298 null, 299 null, 300 null, 301 null, 302 null, 303 false); 304 } 305 306 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_index_rubriques"; 307 308 $result = $db->query($query); 309 310 if (DB::isError($result)) { 311 return PEAR::raiseError( 312 "[" . get_class($this). " DB_index_rubriques : delete()] " . $result->getMessage(). "", null, 313 null, null, 314 null, null, 315 false); 316 } 317 } 318 319 // }}} 320 321 // {{{ deleteIndexRubriqueForRubriqueId($id_objet) 322 323 /** 324 * This method is used to delete an index of headings from the database 325 * @access public 326 * @param int $id_objet ID of heading to delete 327 */ 328 329 function deleteIndexRubriqueForRubriqueId ($id_objet) { 330 $db = &$this->_getDB(); 331 332 if (DB::isError($db)) { 333 return PEAR::raiseError( 334 "[" . get_class( 335 $this). " DB_index_rubriques : deleteIndexRubriqueForRubriqueId()] " . $db->getMessage(). "", 336 null, 337 null, 338 null, 339 null, 340 null, 341 false); 342 } 343 344 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_index_rubriques WHERE id_rubrique = $id_objet"; 345 346 $result = $db->query($query); 347 348 if (DB::isError($result)) { 349 return PEAR::raiseError( 350 "[" . get_class( 351 $this). " DB_index_rubriques : deleteIndexRubriqueForRubriqueId()] " . $result->getMessage(). "", 352 null, 353 null, 354 null, 355 null, 356 null, 357 false); 358 } 359 } 360 361 // }}} 362 363 // {{{ _fetchData() 364 365 /** 366 * This method is used to fetch result set fields into the object fields 367 * @access private 368 * @param int $row the row to fetch 369 */ 370 371 function _fetchData ($row) { 372 $this->setHash($row['hash']); 373 $this->setPoints($row['points']); 374 $this->setRubriqueId($row['id_rubrique']); 375 } 376 377 // }}} 378 379 // {{{ howManyIndexRubriqueForRubriqueId($id_objet) 380 381 /** 382 * This method is used to count how many index of headings exist for a heading's ID 383 * @access public 384 * @param int $id_objet ID of heading to see 385 */ 386 387 function howManyIndexrubriqueForRubriqueId ($id_objet) { 388 if ((!isset($id_objet)) || ($id_objet < 0)) 389 return 0; 390 391 $howManyIndexRubriqueForRubriqueId = 0; 392 $db = &$this->_getDB(); 393 394 if (DB::isError($db)) { 395 return PEAR::raiseError( 396 "[" . get_class( 397 $this). " DB_index_rubriques : howManyIndexrubriqueForRubriqueId()] " . $db->getMessage(). "", 398 null, 399 null, 400 null, 401 null, 402 null, 403 false); 404 } 405 406 $query 407 = "SELECT COUNT(*) as compteur FROM " . $GLOBALS['table_prefix']. "_index_rubriques WHERE id_rubrique = $id_objet"; 408 409 $result = $db->query($query); 410 411 if (DB::isError($result)) { 412 return PEAR::raiseError( 413 "[" . get_class( 414 $this). " DB_index_rubriques : howManyIndexrubriqueForRubriqueId()] " . $result->getMessage(). "", 415 null, 416 null, 417 null, 418 null, 419 null, 420 false); 421 } 422 423 if ($row = $result->fetchRow()) { 424 $howManyIndexRubriqueForRubriqueId = intval($row["compteur"]); 425 } 426 427 $result->free(); 428 return $howManyIndexRubriqueForRubriqueId; 429 } 430 431 // }}} 432 } 433 ?>
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 |