[ 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 Article Historique business persistence abstraction. 20 // $Id$ 21 22 require_once(dirname(__FILE__). "/inc_visite_factory.php"); 23 24 require_once(dirname(__FILE__). "/inc_referer_factory.php"); 25 require_once(dirname(__FILE__). "/inc_auteur_factory.php"); 26 27 require_once dirname(__FILE__). "/metier.php"; 28 require_once dirname(__FILE__). "/../../inc_meta.php"; 29 30 define("ARTICLE_HISTORIQUE_ALL_FIELDS", 31 " id_article_historique, id_article, id_auteur, surtitre, titre, soustitre, descriptif, chapo, texte, ps, extra, date_heure, nom_site, url_site "); 32 33 /** 34 * BD_article_historique is a base class for article historique business 35 * persistence abstraction implementations, and must be inherited by all such. 36 * @package BD 37 * @author Aurelien Vialet <avialet@clever-age.com> 38 * @access public 39 */ 40 41 class BD_article_historique extends BD_metier { 42 43 // {{{ properties 44 45 /** 46 * Article Historique ID 47 * @var int 48 * @access private 49 */ 50 var $_articleHistoriqueId; 51 52 /** 53 * Article ID. 54 * @var int 55 * @access private 56 */ 57 var $_articleId; 58 59 /** 60 * Auteur de la modification. 61 * @var int 62 * @access private 63 */ 64 var $_auteurId; 65 66 /** 67 * Surtitre 68 * @var String 69 * @access private 70 */ 71 var $_surtitre; 72 73 /** 74 * Titre 75 * @var String 76 * @access private 77 */ 78 var $_titre; 79 80 /** 81 * Sous Titre 82 * @var String 83 * @access private 84 */ 85 var $_descriptif; 86 87 /** 88 * Chapo 89 * @var String 90 * @access private 91 */ 92 var $_chapo; 93 94 /** 95 * Texte 96 * @var String 97 * @access private 98 */ 99 var $_texte; 100 101 /** 102 * PS 103 * @var String 104 * @access private 105 */ 106 var $_ps; 107 108 /** 109 * date_heure 110 * @var int 111 * @access private 112 */ 113 var $_date; 114 115 /** 116 * $_extra 117 * @var String 118 * @access private 119 */ 120 var $_extra; 121 122 // }}} 123 124 /** 125 * Site name. 126 * @var String 127 * @access private 128 */ 129 var $_nomSite; 130 131 /** 132 * Site URL. 133 * @var String 134 * @access private 135 */ 136 var $_urlSite; 137 138 // {{{ factory() 139 140 /** 141 * This method is a factory static method. It should be used to get any 142 * specific implementation instace of Article HIstorique business data type. 143 * @param BD_parameters DB connection parameters 144 * @access public 145 */ 146 function &factory ($dbParameters, $dbOptions = null) { 147 if (file_exists(dirname( 148 __FILE__). "/" . $dbParameters->_dbEngine . "/article_historique_" . $dbParameters->_dbEngine . ".php") == false) 149 { 150 include_once(dirname(__FILE__). "/common/article_historique_common.php"); 151 $classname = "BD_article_historique_common"; 152 } 153 else { 154 include_once(dirname( 155 __FILE__). "/" . $dbParameters->_dbEngine . "/article_historique_" . $dbParameters->_dbEngine . ".php"); 156 $classname = "BD_article_historique_" . $dbParameters->_dbEngine; 157 } 158 159 if (!class_exists($classname)) { 160 return PEAR::raiseError("Cannot instanciate class $classname", null, null, null, null, null, false); 161 } 162 163 $obj = &new $classname; 164 $result = $obj->setDbParameters($dbParameters); 165 166 if ($dbOptions != null) { 167 $obj->setDbOptions($dbOptions); 168 } 169 170 if (PEAR::isError($result)) { 171 return $result; 172 } 173 else { 174 return $obj; 175 } 176 } 177 178 // }}} 179 180 // {{{ constructor 181 182 /** 183 * DB_article_historique constructor. 184 * 185 * @access public 186 */ 187 188 function BD_article_historique () { } 189 190 // }}} 191 192 // {{{ getArticleHistoriqueId() 193 function getArticleHistoriqueId () { 194 return $this->_articleHistoriqueId; 195 } 196 197 // }}} 198 199 // {{{ setArticleHistoriqueId() 200 function setArticleHistoriqueId ($articleHistoriqueId) { 201 $this->_articleHistoriqueId = $articleHistoriqueId; 202 } 203 // }}} 204 205 // {{{ getArticleId() 206 207 function getArticleId () { 208 return $this->_articleId; 209 } 210 211 // }}} 212 213 // {{{ setArticleId() 214 215 function setArticleId ($articleId) { 216 $this->_articleId = $articleId; 217 } 218 219 // }}} 220 221 function getAuteurId () { 222 return $this->_auteurId; 223 } 224 225 function setAuteurId ($auteurId) { 226 $this->_auteurId = $auteurId; 227 } 228 229 // {{{ getSurtitre() 230 231 function getSurtitre () { 232 return $this->_surtitre; 233 } 234 235 // }}} 236 237 // {{{ setSurtitre() 238 239 function setSurtitre ($surtitre) { 240 $this->_surtitre = $this->corriger_caracteres($surtitre); 241 } 242 243 // }}} 244 245 // {{{ getTitre() 246 247 function getTitre () { 248 return $this->_titre; 249 } 250 251 // }}} 252 253 // {{{ setTitre() 254 255 function setTitre ($titre) { 256 $this->_titre = $this->corriger_caracteres($titre); 257 } 258 259 // }}} 260 261 // {{{ getSoustitre() 262 263 function getSoustitre () { 264 return $this->_soustitre; 265 } 266 267 // }}} 268 269 // {{{ setSoustitre() 270 271 function setSoustitre ($soustitre) { 272 $this->_soustitre = $this->corriger_caracteres($soustitre); 273 } 274 275 // }}} 276 277 // {{{ getDescriptif() 278 279 function getDescriptif () { 280 return $this->_descriptif; 281 } 282 283 // }}} 284 285 // {{{ setDescriptif() 286 287 function setDescriptif ($descriptif) { 288 $this->_descriptif = $this->corriger_caracteres($descriptif); 289 } 290 291 // }}} 292 293 // {{{ getChapo() 294 295 function getChapo () { 296 return $this->_chapo; 297 } 298 299 // }}} 300 301 // {{{ setChapo() 302 303 function setChapo ($chapo) { 304 $this->_chapo = $this->corriger_caracteres($chapo); 305 } 306 307 // }}} 308 309 // {{{ getTexte() 310 311 function getTexte () { 312 return $this->_texte; 313 } 314 315 // }}} 316 317 // {{{ setTexte() 318 319 function setTexte ($texte) { 320 $this->_texte = $this->corriger_caracteres($texte); 321 } 322 323 // }}} 324 // {{{ getNomSite() 325 326 /** 327 * get Site Name. 328 * @var String 329 * @access private 330 */ 331 332 function getNomSite () { 333 return $this->_nomSite; 334 } 335 336 // }}} 337 338 // {{{ setNomSite() 339 340 /** 341 * Set Site Name. 342 * @var String 343 * @access private 344 */ 345 346 function setNomSite ($nomSite) { 347 $this->_nomSite = $nomSite; 348 } 349 350 // }}} 351 352 // {{{ getUrlSite() 353 354 /** 355 * get Site Url. 356 * @var String 357 * @access private 358 */ 359 360 function getUrlSite () { 361 return $this->_urlSite; 362 } 363 364 // }}} 365 366 // {{{ setUrlSite() 367 368 /** 369 * Set Site Url. 370 * @var String 371 * @access private 372 */ 373 374 function setUrlSite ($urlSite) { 375 $this->_urlSite = $urlSite; 376 } 377 378 // }}} 379 380 // {{{ getPs() 381 382 function getPs () { 383 return $this->_ps; 384 } 385 386 // }}} 387 388 // {{{ setPs() 389 390 function setPs ($ps) { 391 $this->_ps = $this->corriger_caracteres($ps); 392 } 393 394 // }}} 395 396 // {{{ getDate() 397 398 function getDate () { 399 return $this->_date; 400 } 401 402 // }}} 403 404 // {{{ setDate() 405 406 function setDate ($date) { 407 $this->_date = $date; 408 } 409 410 // }}} 411 412 // {{{ getExtra() 413 414 function getExtra () { 415 return $this->_extra; 416 } 417 418 // }}} 419 420 // {{{ setExtra() 421 422 function setExtra ($extra) { 423 $this->_extra = $extra; 424 } 425 426 // }}} 427 428 // {{{ _fetchData() 429 function _fetchData ($row) { 430 $this->setArticleHistoriqueId($row['id_article_historique']); 431 $this->setArticleId($row['id_article']); 432 $this->setSurtitre($row['surtitre']); 433 $this->setTitre($row['titre']); 434 $this->setSoustitre($row['soustitre']); 435 $this->setDescriptif($row['descriptif']); 436 $this->setChapo($row['chapo']); 437 $this->setTexte($row['texte']); 438 $this->setPs($row['ps']); 439 $this->setExtra($row['extra']); 440 $this->setDate($row['date_heure']); 441 $this->setNomSite($row['nom_site']); 442 $this->setUrlSite($row['url_site']); 443 $this->setAuteurId($row['id_auteur']); 444 } 445 446 // }}} 447 448 // {{{ loadFromArticle() 449 function loadFromArticle ($obj) { 450 $obj->load($obj->_articleId); 451 $this->setArticleId($obj->_articleId); 452 $this->setSurtitre($obj->_surtitre); 453 $this->setTitre($obj->_titre); 454 $this->setSoustitre($obj->_soustitre); 455 $this->setDescriptif($obj->_descriptif); 456 $this->setChapo($obj->_chapo); 457 $this->setTexte($obj->_texte); 458 $this->setPs($obj->_ps); 459 $this->setExtra($obj->_extra); 460 //$this->setDate($obj->_date); 461 $this->setNomSite($obj->_nomSite); 462 $this->setUrlSite($obj->_urlSite); 463 $this->setAuteurId($obj->_auteurModif); 464 } 465 466 // }}} 467 468 // {{{ create() 469 function create () { 470 if ($this->exists()) { 471 return false; 472 } 473 474 $db = &$this->_getDB(); 475 476 if (DB::isError($db)) { 477 return PEAR::raiseError("[" . get_class($this). " DB_article : create()] " . $db->getMessage(). "", null, 478 null, null, 479 null, null, 480 false); 481 } 482 483 $string_prefix = $GLOBALS['table_prefix']. "_articles_historique"; 484 485 // date de maintentant 486 $maDate = new Date(); 487 $this->setDate($maDate->getDate(DATE_FORMAT_ISO)); 488 489 $articleHistoriqueId = $db->nextId($string_prefix, true); 490 491 if (DB::isError($articleHistoriqueID)) { 492 return PEAR::raiseError( 493 "[" . get_class($this). " DB_article_historique : create()] " . $articleId->getMessage(). "", 494 null, 495 null, 496 null, 497 null, 498 null, 499 false); 500 } 501 502 $this->_articleHistoriqueId = $articleHistoriqueId; 503 504 $query 505 = "INSERT INTO " . $GLOBALS['table_prefix']. "_articles_historique (" . ARTICLE_HISTORIQUE_ALL_FIELDS . ") VALUES " . "(" . $this->_articleHistoriqueId . ", " . "" . $this->_articleId . ", " . "" . $this->_auteurId . ", " . "'" . $db->quoteString( 506 $this->_surtitre). "', " . "'" . $db->quoteString( 507 $this->_titre). "', " . "'" . $db->quoteString( 508 $this->_soustitre). "', " . "'" . $db->quoteString( 509 $this->_descriptif). "', " . "'" . $db->quoteString( 510 $this->_chapo). "', " . "'" . $db->quoteString( 511 $this->_texte). "', " . "'" . $db->quoteString( 512 $this->_ps). "', " . "'" . $db->quoteString( 513 $this->_extra). "', " . "'" . $db->quoteString( 514 $this->_date). "', " . "'" . $db->quoteString( 515 $this->_nomSite). "', " . "'" . $db->quoteString( 516 $this->_urlSite). "')"; 517 518 $result = $db->query($query); 519 520 if (DB::isError($result)) { 521 return PEAR::raiseError("[" . get_class($this). " DB_article : create()] " . $result->getMessage(). "", 522 null, 523 null, 524 null, 525 null, 526 null, 527 false); 528 } 529 } 530 531 // }}} 532 533 // {{{ exists 534 function exists () { 535 $db = &$this->_getDB(); 536 537 if (DB::isError($db)) { 538 return PEAR::raiseError( 539 "[" . get_class($this). " DB_article_historique : create()] " . $db->getMessage(). "", null, 540 null, null, 541 null, null, 542 false); 543 } 544 545 $query 546 = "SELECT count(*) AS nbHisto FROM " . $GLOBALS['table_prefix']. "_articles_historique " . " WHERE 1=1 " . " AND id_article = " . $this->_articleId . " " . " AND id_auteur = " . $this->_auteurId . " " . " AND surtitre = '" . $db->quoteString( 547 $this->_surtitre). "' " . " AND titre = '" . $db->quoteString( 548 $this->_titre). "' " . " AND soustitre = '" . $db->quoteString( 549 $this->_soustitre). "' " . " AND descriptif = '" . $db->quoteString( 550 $this->_descriptif). "' " . " AND chapo = '" . $db->quoteString( 551 $this->_chapo). "' " . " AND texte = '" . $db->quoteString( 552 $this->_texte). "' " . " AND ps = '" . $db->quoteString( 553 $this->_ps). "' " . " AND extra = '" . $db->quoteString( 554 $this->_extra). "' " . " AND date_heure = '" . $db->quoteString( 555 $this->_date). "' "; 556 $result = $db->query($query); 557 558 if (DB::isError($result)) { 559 return PEAR::raiseError( 560 "[" . get_class($this). " DB_article_historique : exists()] " . $result->getMessage(). "", null, 561 null, null, 562 null, null, 563 false); 564 } 565 else { 566 if ($row = $result->fetchRow()) { 567 $result->free(); 568 if ($row['nbHisto'] > 0) { 569 return true; 570 } 571 else { 572 return false; 573 } 574 } 575 else { 576 return PEAR::raiseError("[" . get_class($this). " DB_article_historique : exists] ", null, null, null, 577 null, null, false); 578 } 579 } 580 } 581 582 // }}} 583 584 // {{{ loadHistoForArticle() 585 function loadHistoForArticle ($idArticle, $idHisto = false) { 586 $db = &$this->_getDB(); 587 588 if (DB::isError($db)) { 589 return PEAR::raiseError( 590 "[" . get_class( 591 $this). " DB_article_historique : loadHistoForArticle()] " . $db->getMessage(). "", 592 null, 593 null, 594 null, 595 null, 596 null, 597 false); 598 } 599 600 $query 601 = "SELECT " . ARTICLE_HISTORIQUE_ALL_FIELDS . "FROM " . $GLOBALS['table_prefix']. "_articles_historique " . "WHERE " . " id_article = " . $idArticle . " ORDER BY id_article_historique desc "; 602 $result = $db->query($query); 603 604 if (DB::isError($result)) { 605 return PEAR::raiseError( 606 "[" . get_class( 607 $this). " DB_article_historique : loadHistoForArticle()] " . $result->getMessage(). "", 608 null, 609 null, 610 null, 611 null, 612 null, 613 false); 614 } 615 else { 616 $aArticles = array(); 617 618 while ($row = $result->fetchRow()) { 619 $currentArticle = &recuperer_instance_article_historique(); 620 $currentArticle->_fetchData($row); 621 $aArticles[] = $currentArticle; 622 } 623 624 $result->free(); 625 return $aArticles; 626 } 627 } 628 629 // }}} 630 631 // {{{ load 632 function load ($idArticleHistorique) { 633 $db = &$this->_getDB(); 634 635 if (DB::isError($db)) { 636 return PEAR::raiseError("[" . get_class($this). " DB_article_historique : load()] " . $db->getMessage(). "", 637 null, 638 null, 639 null, 640 null, 641 null, 642 false); 643 } 644 645 $query 646 = "SELECT " . ARTICLE_HISTORIQUE_ALL_FIELDS . "FROM " . $GLOBALS['table_prefix']. "_articles_historique " . "WHERE " . " id_article_historique = " . $idArticleHistorique; 647 $result = $db->query($query); 648 649 if (DB::isError($result)) { 650 return PEAR::raiseError( 651 "[" . get_class($this). " DB_article_historique : load()] " . $result->getMessage(). "", null, 652 null, null, 653 null, null, 654 false); 655 } 656 else { 657 $aArticles = array(); 658 $row = $result->fetchRow(); 659 $this->_fetchData($row); 660 $result->free(); 661 } 662 } 663 664 // }}} 665 666 // {{{ purgeHisto 667 function purgeHisto ($articleHisto) { 668 $db = &$this->_getDB(); 669 670 if (DB::isError($db)) { 671 return PEAR::raiseError( 672 "[" . get_class($this). " DB_article_historique : purgeHisto()] " . $db->getMessage(). "", null, 673 null, null, 674 null, null, 675 false); 676 } 677 678 $query 679 = "DELETE FROM " . $GLOBALS['table_prefix']. "_articles_historique " . "WHERE id_article_historique IN ("; 680 681 while (list(, $val) = each($articleHisto)) { 682 $query .= $val . ","; 683 } 684 685 $query .= "-10 )"; 686 $result = $db->query($query); 687 688 if (DB::isError($result)) { 689 return PEAR::raiseError( 690 "[" . get_class($this). " DB_article_historique : purgeHisto()] " . $result->getMessage(). "", 691 null, 692 null, 693 null, 694 null, 695 null, 696 false); 697 } 698 } 699 700 // }}} 701 702 /** Renvoie la représentation littérale de l'objet 703 * @return string 704 * @todo Splitter ca dans un système de renderers (avec pattern visitor et tout et tout, 705 * mais en attendant... 706 */ 707 function toString () { 708 $str = array(); 709 $str[] = $this->getSurtitre() ? $this->_formatData($this->getSurtitre(), 'surtitre') : ''; 710 $str[] = $this->getTitre() ? $this->_formatData($this->getTitre(), 'titre') : ''; 711 $str[] = $this->getDescriptif() ? $this->_formatData($this->getDescriptif(), 'descriptif') : ''; 712 $str[] = $this->getSoustitre() ? $this->_formatData($this->getSoustitre(), 'soustitre') : ''; 713 // TODO : site 714 $str[] = $this->getChapo() ? $this->_formatData($this->getChapo(), 'chapo') : ''; 715 $str[] = $this->getTexte() ? propre($this->_formatData($this->getTexte(), 'texte')) : ''; 716 $str[] = $this->getPs() ? $this->_formatData($this->getPs(), 'ps') : ''; 717 // TODO : extras 718 719 return implode("\n", $str); 720 } 721 722 /** Formatte les données en fonction de leur type. 723 * @param string $data 724 * @param string $type 725 * @return string 726 * @todo C'est moche ! 727 */ 728 function _formatData ($data, $type) { 729 $patterns = array('texte' => '%s', 730 'surtitre' => '<p><font face="arial,helvetica" size="3"><b>%s</b></font></p>', 731 'soustitre' => '<p><font face="arial,helvetica" size="3"><b>%s</b></font></p>', 732 'titre' => 733 '<p><span style="border-bottom: 1px dashed rgb(56, 116, 176);"><font color="#3874b0" face="Verdana,Arial,Sans,sans-serif" size="4"><b>%s</b></font></span></p>', 734 'descriptif' => 735 '<div style="border: 1px dashed rgb(170, 170, 170); padding: 5px; background-color: rgb(228, 228, 228);"><font face="Verdana,Arial,Sans,sans-serif" size="2"><strong class="spip">Descriptif : </strong>%s</font></div>', 736 'site' => 737 '<p><font face="Verdana,Arial,Sans,sans-serif" size="2"><strong class="spip">Lien hypertexte : </strong>%s</font></p>', 738 'chapo' => '<p><strong>%s</strong></p>', 739 'ps' => 740 '<p><font size="2" face="Verdana,Arial,Sans,sans-serif"><strong>PS : </strong> %s</font></p>'); 741 742 if (!isset($patterns[$type])) { 743 $type = 'texte'; 744 } 745 746 ; 747 return sprintf($patterns[$type], $data); 748 } 749 } 750 ?>
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 |