[ 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 Dico business persistence abstraction. 20 // 21 22 if (defined("_BD_INDEX_DICO")) 23 return; 24 25 define("_BD_INDEX_DICO", "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_DICO_ALL_FIELDS", " hash, dico "); 33 34 /** 35 * BD_index_dico is a base class for dico 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_dico extends BD_metier { 43 // {{{ properties 44 45 /** 46 * $_hash 47 * @var int 48 * @access private 49 */ 50 var $_hash; 51 52 /** 53 * $_dico 54 * @var String 55 * @access private 56 */ 57 var $_dico; 58 59 // }}} 60 61 // {{{ factory() 62 function &factory ($dbParameters = null, $dbOptions = null) { 63 if (file_exists( 64 dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/index_dico_" . $dbParameters->_dbEngine . ".php") 65 == false) { 66 include_once (dirname(__FILE__). "/common/index_dico_common.php"); 67 $classname = "BD_index_dico_common"; 68 } 69 else { 70 include_once 71 (dirname( 72 __FILE__). "/" . $dbParameters->_dbEngine . "/index_dico_" . $dbParameters->_dbEngine . ".php"); 73 $classname = "BD_index_dico_" . $dbParameters->_dbEngine; 74 } 75 76 if (!class_exists($classname)) { 77 return PEAR::raiseError("Cannot instanciate class $classname", null, null, null, null, null, false); 78 } 79 80 $obj = &new $classname; 81 $result = $obj->setDbParameters($dbParameters); 82 83 if ($dbOptions != null) { 84 $obj->setDbOptions($dbOptions); 85 } 86 87 if (PEAR::isError($result)) { 88 return $result; 89 } 90 else { 91 return $obj; 92 } 93 } 94 95 // }}} 96 97 // {{{ constructor 98 99 /** 100 * DB_index_dico constructor. 101 * 102 * @access public 103 */ 104 105 function BD_index_dico () { } 106 107 // }}} 108 109 // {{{ getHash() 110 111 /** 112 * Returns the hash's value 113 * @return int 114 * @access public 115 */ 116 117 function getHash () { 118 return $this->_hash; 119 } 120 121 // }}} 122 123 // {{{ setHash($hash) 124 125 /** 126 * Sets the hash's value 127 * @param int 128 * @access public 129 */ 130 131 function setHash ($hash) { 132 $this->_hash = corriger_caracteres($hash); 133 } 134 135 // }}} 136 137 // {{{ getDico() 138 139 /** 140 * Returns the character string required 141 * @return String 142 * @access public 143 */ 144 145 function getDico () { 146 return $this->_dico; 147 } 148 149 // }}} 150 151 // {{{ setDico($dico) 152 153 /** 154 * Sets the character string required 155 * @param String 156 * @access public 157 */ 158 159 function setDico ($dico) { 160 $this->_dico = $dico; 161 } 162 163 // }}} 164 165 // {{{ create() 166 167 /** 168 * This method is used to create a new character string required in the database 169 * @access public 170 */ 171 172 function create () { 173 $db = &$this->_getDB(); 174 175 if (DB::isError($db)) { 176 return PEAR::raiseError("[" . get_class($this). " DB_index_dico : create()] " . $db->getMessage(). "", null, 177 null, null, 178 null, null, 179 false); 180 } 181 182 $query 183 = "INSERT INTO " . $GLOBALS['table_prefix']. "_index_dico (" . INDEX_DICO_ALL_FIELDS . ") VALUES " . "('" . $db->quoteString( 184 $this->_hash). "', " . "'" . $db->quoteString( 185 $this->_dico). "')"; 186 187 //echo $query; 188 $result = $db->query($query); 189 190 if (DB::isError($result)) { 191 return $result; 192 } 193 } 194 195 // }}} 196 197 // {{{ load() 198 199 /** 200 * This method is used to load a character string required from the database 201 * @access public 202 * @param String $dico the character string required to load 203 */ 204 205 function load ($dico) { 206 $db = &$this->_getDB(); 207 208 if (DB::isError($db)) { 209 return PEAR::raiseError("[" . get_class($this). " DB_index_dico : load()] " . $db->getMessage(). "", null, 210 null, null, 211 null, null, 212 false); 213 } 214 215 $query 216 = "SELECT" . INDEX_DICO_ALL_FIELDS . "FROM " . $GLOBALS['table_prefix']. "_index_dico WHERE dico = $dico"; 217 218 $result = $db->query($query); 219 220 if (DB::isError($result)) { 221 return $result; 222 } 223 else { 224 if ($row = $result->fetchRow()) { 225 $this->_fetchData($row); 226 } 227 else { 228 return PEAR::raiseError( 229 "[" . get_class( 230 $this). " DB_index_dico : load($dico)] Aucun index de dico ne correspond à cet ID!", 231 null, 232 null, 233 null, 234 null, 235 null, 236 false); 237 } 238 $result->free(); 239 } 240 } 241 242 // }}} 243 244 // {{{ delete() 245 246 /** 247 * This method is used to delete the dictionary 248 * @access public 249 */ 250 251 function delete () { 252 $db = &$this->_getDB(); 253 254 if (DB::isError($db)) { 255 return PEAR::raiseError("[" . get_class($this). " DB_index_dico : delete()] " . $db->getMessage(). "", null, 256 null, null, 257 null, null, 258 false); 259 } 260 261 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_index_dico"; 262 263 $result = $db->query($query); 264 265 if (DB::isError($result)) { 266 return $result; 267 } 268 } 269 270 // }}} 271 272 // {{{ _fetchData() 273 274 /** 275 * This method is used to fetch result set fields into the object fields 276 * @access private 277 * @param int $row the row to fetch 278 */ 279 280 function _fetchData ($row) { 281 $this->setHash($row['hash']); 282 $this->setDico($row['dico']); 283 } 284 285 // }}} 286 287 // {{{ addDico() 288 289 /** 290 * This method is used to add a character string required from the database ignoring the Key value of the table 291 * @access public 292 */ 293 294 function addDico ($mots = array()) { 295 $db = &$this->_getDB(); 296 297 if (DB::isError($db)) { 298 return PEAR::raiseError("[" . get_class($this). " DB_index_dico : addDico()] " . $db->getMessage(). "", 299 null, 300 null, 301 null, 302 null, 303 null, 304 false); 305 } 306 307 while (list(, $monMot) = each($mots)) { 308 $query = "SELECT dico FROM " . $GLOBALS['table_prefix']. "_index_dico WHERE dico='" . $monMot['dico']. "'"; 309 310 //echo "<br><br>$query<br><br>"; 311 312 $result = $db->query($query); 313 314 if (DB::isError($result)) { 315 return PEAR::raiseError( 316 "[" . get_class($this). " DB_index_dico : addDico()] " . $result->getMessage(). "", null, 317 null, null, 318 null, null, 319 false); 320 } 321 if ($result->numRows() == 0) { 322 $query 323 = "INSERT INTO " . $GLOBALS['table_prefix']. "_index_dico (" . INDEX_DICO_ALL_FIELDS . ") VALUES " . "('" . $db->quoteString( 324 $monMot['hash']). "', " . "'" . $db->quoteString( 325 $monMot['dico']). "')"; 326 ; 327 328 //echo "<br><br>$query<br><br>"; 329 330 $result = $db->query($query); 331 if (DB::isError($result)) { 332 return $result; 333 } 334 } 335 } 336 } 337 // }}} 338 339 // {{{ composeResearchInIndex($dico) 340 341 /** 342 * This method is used to compose a research in the dictionary 343 * @access public 344 * @param String $dico the character string required to load 345 */ 346 347 function composeResearchInIndex ($dico) { 348 $hashIds = array(); 349 350 $db = &$this->_getDB(); 351 352 if (DB::isError($db)) { 353 return PEAR::raiseError( 354 "[" . get_class($this). " DB_index_dico : composeResearchInIndex()] " . $db->getMessage(). "", 355 null, 356 null, 357 null, 358 null, 359 null, 360 false); 361 } 362 363 $query = "SELECT hash AS hx FROM " . $GLOBALS['table_prefix']. "_index_dico WHERE " . join(" OR ", $dico); 364 365 $result = $db->query($query); 366 367 if (DB::isError($result)) { 368 return $result; 369 } 370 371 while ($row = $result->fetchRow()) { 372 //echo $row['hx']; 373 //$hashIds[] = "0x".dechex($row['hx'],20); 374 $hashIds[] = "'" . $row['hx']. "'"; 375 } 376 377 $result->free(); 378 379 return $hashIds; 380 } 381 382 // }}} 383 384 // {{{ getDicoFromHash 385 386 /** 387 * 388 * @access public 389 * @param String $hash 390 */ 391 392 function getDicoFromHash ($hash) { 393 $db = &$this->_getDB(); 394 395 if (DB::isError($db)) { 396 return PEAR::raiseError( 397 "[" . get_class($this). " DB_index_dico : getDicoFromHash()] " . $db->getMessage(). "", null, 398 null, null, 399 null, null, 400 false); 401 } 402 403 $query = "SELECT dico FROM " . $GLOBALS['table_prefix']. "_index_dico WHERE hash = '" . $hash . "'"; 404 $result = $db->query($query); 405 $row = $result->fetchRow(); 406 return $row['dico']; 407 } 408 409 // }}} 410 } 411 ?>
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 |