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