[ 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 Syndic Articles business persistence abstraction. 20 // 21 22 if (defined("_BD_SYNDIC_ARTICLES")) 23 return; 24 25 define("_BD_SYNDIC_ARTICLES", "1"); 26 27 require_once("PEAR.php"); 28 require_once("DB.php"); 29 require_once dirname(__FILE__). "/metier.php"; 30 31 define("SYNDIC_ARTICLES_ALL_FIELDS", 32 " id_syndic_article, id_syndic, titre, url, date_heure, lesauteurs, maj, statut, descriptif "); 33 34 /** 35 * BD_syndic_articles is a base class for syndic articles 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_syndic_articles extends BD_metier { 43 44 // {{{ properties 45 46 /** 47 * Syndicated Article ID. 48 * @var int 49 * @access private 50 */ 51 var $_syndicArticleId; 52 53 /** 54 * Syndication ID. 55 * @var int 56 * @access private 57 */ 58 var $_syndicId; 59 60 /** 61 * Title of syndicated article. 62 * @var String 63 * @access private 64 */ 65 var $_titre; 66 67 /** 68 * Url of syndicated article. 69 * @var String 70 * @access private 71 */ 72 var $_url; 73 74 /** 75 * Date of syndication. 76 * @var Date 77 * @access private 78 */ 79 var $_date; 80 81 /** 82 * The authors of the syndicated article. 83 * @var String 84 * @access private 85 */ 86 var $_lesAuteurs; 87 88 /** 89 * the syndicated article update date. 90 * @var Date 91 * @access private 92 */ 93 var $_maj; 94 95 /** 96 * Statut of the syndicated article. 97 * @var String 98 * @access private 99 */ 100 var $_statut; 101 102 /** 103 * Description of the syndicated article. 104 * @var String 105 * @access private 106 */ 107 var $_descriptif; 108 109 // }}} 110 111 // {{{ factory() 112 113 /** 114 * This method is a factory static method. It should be used to get any 115 * specific implementation instace of Syndic business data type. 116 * @param BD_parameters DB connection parameters 117 * @access public 118 */ 119 function &factory ($dbParameters, $dbOptions = null) { 120 if (file_exists( 121 dirname( 122 __FILE__). "/" . $dbParameters->_dbEngine . "/syndic_articles_" . $dbParameters->_dbEngine . ".php") 123 == false) { 124 include_once (dirname(__FILE__). "/common/syndic_articles_common.php"); 125 $classname = "BD_syndic_articles_common"; 126 } 127 else { 128 include_once (dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/syndic_articles_" . $dbParameters->_dbEngine . ".php"); 129 $classname = "BD_syndic_articles_" . $dbParameters->_dbEngine; 130 } 131 132 if (!class_exists($classname)) { 133 return PEAR::raiseError("Cannot instanciate class $classname", null, null, null, null, null, false); 134 } 135 136 $obj = &new $classname; 137 $result = $obj->setDbParameters($dbParameters); 138 139 if ($dbOptions != null) { 140 $obj->setDbOptions($dbOptions); 141 } 142 143 if (PEAR::isError($result)) { 144 return $result; 145 } 146 else { 147 return $obj; 148 } 149 } 150 151 // }}} 152 153 // {{{ constructor 154 155 /** 156 * DB_syndic_articles constructor. 157 * 158 * @access public 159 */ 160 161 function BD_syndic_articles () { } 162 163 // }}} 164 165 // {{{ getSyndicArticleId() 166 167 /** 168 * Returns the Syndic Article ID 169 * @return int 170 * @access public 171 */ 172 173 function getSyndicArticleId () { 174 return $this->_syndicArticleId; 175 } 176 177 // }}} 178 179 // {{{ setSyndicArticleId() 180 181 /** 182 * Sets the Syndic Article ID 183 * @param int 184 * @access public 185 */ 186 187 function setSyndicArticleid ($syndicArticleId) { 188 $this->_syndicArticleId = $syndicArticleId; 189 } 190 191 /** 192 * Returns the Syndic ID 193 * @param int 194 * @access public 195 */ 196 197 function getSyndicid ($syndicId) { 198 $this->_syndicId = $syndicId; 199 } 200 201 /** 202 * Sets the Syndic ID 203 * @param int 204 * @access public 205 */ 206 207 function setSyndicid ($syndicId) { 208 $this->_syndicId = $syndicId; 209 } 210 211 // }}} 212 213 // {{{ getTitre() 214 215 /** 216 * Returns the title of the syndic article 217 * @return String 218 * @access public 219 */ 220 221 function getTitre () { 222 return $this->_titre; 223 } 224 225 // }}} 226 227 // {{{ setTitre() 228 229 /** 230 * Sets the title of the syndic article 231 * @param String 232 * @access public 233 */ 234 235 function setTitre ($titre) { 236 $this->_titre = corriger_caracteres($titre); 237 } 238 239 // }}} 240 241 // {{{ getUrl() 242 243 /** 244 * Returns url of the syndicated article 245 * @return String 246 * @access public 247 */ 248 249 function getUrl () { 250 return $this->_url; 251 } 252 253 // }}} 254 255 // {{{ setUrl() 256 257 /** 258 * Sets url of the syndicated article 259 * @param String 260 * @access public 261 */ 262 263 function setUrl ($url) { 264 $this->_url = corriger_caracteres($url); 265 } 266 267 // }}} 268 269 // {{{ getDate() 270 271 /** 272 * Returns the date of syndication 273 * @return Date 274 * @access public 275 */ 276 277 function getDate () { 278 return $this->_date; 279 } 280 281 // }}} 282 283 // {{{ setDate() 284 285 /** 286 * Sets the date of syndication 287 * @param Date 288 * @access public 289 */ 290 291 function setDate ($date) { 292 $this->_date = $date; 293 } 294 295 // }}} 296 297 // {{{ getLesAuteurs() 298 299 /** 300 * Returns the authors of the syndicated article 301 * @return String 302 * @access public 303 */ 304 305 function getLesAuteurs () { 306 return $this->_lesAuteurs; 307 } 308 309 // }}} 310 311 // {{{ setLesAuteurs() 312 313 /** 314 * Sets the authors of the syndicated article 315 * @param String 316 * @access public 317 */ 318 319 function setLesAuteurs ($lesAuteurs) { 320 $this->_lesAuteurs = corriger_caracteres($lesAuteurs); 321 } 322 323 // }}} 324 325 // {{{ getMaj() 326 327 /** 328 * Returns the syndicated article update date 329 * @return Date 330 * @access public 331 */ 332 333 function getMaj () { 334 return $this->_maj; 335 } 336 337 // }}} 338 339 // {{{ setMaj() 340 341 /** 342 * Sets the syndicated article update date 343 * @param Date 344 * @access public 345 */ 346 347 function setMaj ($maj) { 348 $this->_maj = $maj; 349 } 350 351 // }}} 352 353 // {{{ getStatut() 354 355 /** 356 * Returns statut of the syndicated article 357 * @return String 358 * @access public 359 */ 360 361 function getStatut () { 362 return $this->_statut; 363 } 364 365 // }}} 366 367 // {{{ setStatut() 368 369 /** 370 * Sets statut of the syndicated article 371 * @param String 372 * @access public 373 */ 374 375 function setStatut ($statut) { 376 $this->_statut = corriger_caracteres($statut); 377 } 378 379 // }}} 380 381 // {{{ getDescriptif() 382 383 /** 384 * Returns the description of the syndicated article 385 * @return String 386 * @access public 387 */ 388 389 function getDescriptif () { 390 return $this->_descriptif; 391 } 392 393 // }}} 394 395 // {{{ setDescriptif() 396 397 /** 398 * Sets the description of the syndicated article 399 * @param String 400 * @access public 401 */ 402 403 function setDescriptif ($descriptif) { 404 $this->_descriptif = corriger_caracteres($descriptif); 405 } 406 407 // }}} 408 409 // {{{ create() 410 411 /** 412 * This method is used to create a new syndicated article in the database 413 * @access public 414 */ 415 416 function create () { 417 $db = &$this->_getDB(); 418 419 if (DB::isError($db)) { 420 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : create()] " . $db->getMessage(). "", null, null, null, null, null, false); 421 } 422 423 $string_prefix = $GLOBALS['table_prefix']. "_syndic_articles"; 424 $syndicArticleId = $db->nextId($string_prefix, true); 425 426 if (DB::isError($syndicArticleId)) { 427 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : create()] " . $syndicArticleId->getMessage(). "", null, null, null, null, null, false); 428 } 429 430 $this->_syndicArticleId = $syndicArticleId; 431 432 //if ($this->_date == "NOW()") $date = "NOW()"; else $date = "'".$db->quoteString($this->_date)."'"; 433 434 $query = "INSERT INTO " . $GLOBALS['table_prefix']. "_syndic_articles (" . SYNDIC_ARTICLES_ALL_FIELDS . ") VALUES (" . "" . $this->_syndicArticleId . ", " . "" . $this->_syndicId . ", " . "'" . $db->quoteString($this->_titre). "', " . "'" . $db->quoteString($this->_url). "', " . "'" . $db->quoteString($this->_date). "', " . "'" . $db->quoteString($this->_lesAuteurs). "', " . "'" . $db->quoteString($this->_maj). "', " . "'" . $db->quoteString($this->_statut). "', " . "'" . $db->quoteString($this->_descriptif). "')"; 435 436 $result = $db->query($query); 437 438 if (DB::isError($result)) { 439 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : create()] " . $result->getMessage(). "", null, null, null, null, null, false); 440 } 441 } 442 443 // }}} 444 445 // {{{ update() 446 447 /** 448 * This method is used to update a syndicated article in the database 449 * @access public 450 */ 451 452 function update () { 453 $db = &$this->_getDB(); 454 455 if (DB::isError($db)) { 456 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : update()] " . $db->getMessage(). "", null, null, null, null, null, false); 457 } 458 459 $maDate = new Date(); 460 $this->setMaj($maDate->getDate(DATE_FORMAT_ISO)); 461 462 $query = "UPDATE " . $GLOBALS['table_prefix']. "_syndic_articles " . "SET id_syndic_article = " . $this->_syndicArticleId . ", id_syndic = " . $this->_syndicId . ", " . "titre = '" . $db->quoteString($this->_titre). "', url = '" . $db->quoteString($this->_url). "', " . "date_heure = '" . $db->quoteString($this->_date). "', lesAuteurs = '" . $db->quoteString($this->_lesAuteurs). "', " . "maj = '" . $db->quoteString($this->_maj). "', statut = '" . $db->quoteString($this->_statut). "', " . "descriptif = '" . $db->quoteString($this->_descriptif). "' " . "WHERE id_syndic_article = " . $this->_syndicArticleId; 463 464 //echo '<br />' . $query . '<br />'; 465 466 $result = $db->query($query); 467 468 if (DB::isError($result)) { 469 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : update()] " . $result->getMessage(). "", null, null, null, null, null, false); 470 } 471 } 472 473 // }}} 474 475 // {{{ load($idSyndic) 476 477 /** 478 * This method is used to load a syndicated article from the database 479 * @access public 480 * @param int $syndicId ID of syndication to load 481 */ 482 483 function load ($idSyndic) { 484 $db = &$this->_getDB(); 485 486 if (DB::isError($db)) { 487 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : load()] " . $db->getMessage(). "", null, null, null, null, null, false); 488 } 489 490 $query = "SELECT " . SYNDIC_ARTICLES_ALL_FIELDS . " FROM " . $GLOBALS['table_prefix']. "_syndic_articles WHERE id_syndic_article = $idSyndic"; 491 492 //echo '<br />' . $query . '<br />'; 493 494 $result = $db->query($query); 495 496 if (DB::isError($result)) { 497 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : load()] " . $result->getMessage(). "", null, null, null, null, null, false); 498 } 499 else { 500 if ($row = $result->fetchRow()) { 501 $maDate = new Date($row['maj']); 502 $row['maj'] = $maDate->getDate(DATE_FORMAT_TIMESTAMP); 503 504 $this->_fetchData($row); 505 } 506 else { 507 return PEAR::raiseError("[" . get_class($this). " DB_syndic_articles : load($idSyndic)] Aucune syndication d'articles ne correspond pas à cet ID!", null, null, null, null, null, false); 508 } 509 $result->free(); 510 } 511 } 512 513 // }}} 514 515 // {{{ getSyndicArticleForUrl($url, $idSyndic) 516 517 /** 518 * This method is used to get a syndicated article for a specific url and an ID of syndication 519 * @access public 520 * @param String $url url to get 521 * @param int $idSyndic ID of syndication to get 522 */ 523 524 function getSyndicArticleForUrl ($url, $idSyndic) { 525 $syndicArticle = array(); 526 $db = &$this->_getDB(); 527 528 if (DB::isError($db)) { 529 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : getSyndicArticleForUrl()] " . $db->getMessage(). "", null, null, null, null, null, false); 530 } 531 532 $query = "SELECT " . SYNDIC_ARTICLES_ALL_FIELDS . " FROM " . $GLOBALS['table_prefix']. "_syndic_articles WHERE url=\"$url\" AND id_syndic = $idSyndic"; 533 534 $result = $db->query($query); 535 536 if (DB::isError($result)) { 537 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : getSyndicArticleForUrl()] " . $result->getMessage(). "", null, null, null, null, null, false); 538 } 539 else { 540 if ($row = $result->fetchRow()) { 541 $resultSyndicArticle = &BD_syndic_articles::factory($this->getDbParameters(), $this->getDbOptions()); 542 543 $maDate = new Date($row['maj']); 544 $row['maj'] = $maDate->getDate(DATE_FORMAT_TIMESTAMP); 545 546 $resultSyndicArticle->_fetchData($row); 547 $syndicArticle[] = &$resultSyndicArticle; 548 } 549 550 $result->free(); 551 return $syndicArticle; 552 } 553 } 554 555 // }}} 556 557 // {{{ delete() 558 559 /** 560 * This method is used to delete a syndicated article from the database 561 * @access public 562 * @param int $id_syndic ID of syndication to delete 563 */ 564 565 function delete ($id_syndic) { 566 $db = &$this->_getDB(); 567 568 if (DB::isError($db)) { 569 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : delete()] " . $db->getMessage(). "", null, null, null, null, null, false); 570 } 571 572 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_syndic_articles WHERE id_syndic = $id_Syndic"; 573 574 $result = $db->query($query); 575 576 if (DB::isError($result)) { 577 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : delete()] " . $result->getMessage(). "", null, null, null, null, null, false); 578 } 579 } 580 581 // }}} 582 583 // {{{ _fetchData() 584 585 /** 586 * This method is used to fetch result set fields into the object fields 587 * @access private 588 * @param int $row the row to fetch 589 */ 590 591 function _fetchData ($row) { 592 $this->setSyndicArticleId($row['id_syndic_article']); 593 $this->setSyndicId($row['id_syndic']); 594 $this->setTitre($row['titre']); 595 $this->setUrl($row['url']); 596 $this->setdate($row['date_heure']); 597 $this->setLesAuteurs($row['lesauteurs']); 598 $this->setMaj($row['maj']); 599 $this->setStatut($row['statut']); 600 $this->setDescriptif($row['descriptif']); 601 } 602 603 // }}} 604 605 // {{{ howManySyndicArticleIdForStatut($id_syndic) 606 607 /** 608 * This method is used to count the syndicated articles for a specific syndication ID 609 * @access public 610 * @param int $id_syndic ID of syndication to see 611 */ 612 613 function howManySyndicArticleIdForSyndicId ($id_syndic) { 614 $howManySyndicArticleId = 0; 615 $db = &$this->_getDB(); 616 617 if (DB::isError($db)) { 618 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : howManySyndicArticleIdForSyndicId()] " . $db->getMessage(). "", null, null, null, null, null, false); 619 } 620 621 $query = "SELECT COUNT(*) as compte FROM " . $GLOBALS['table_prefix']. "_syndic_articles WHERE id_syndic=$id_syndic"; 622 623 $result = $db->query($query); 624 625 if (DB::isError($result)) { 626 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : howManySyndicArticleIdForSyndicId()] " . $result->getMessage(). "", null, null, null, null, null, false); 627 } 628 629 if ($row = $result->fetchRow()) { 630 $howManySyndicArticleId = intval($row["compte"]); 631 } 632 633 $result->free(); 634 return $howManySyndicArticleId; 635 } 636 637 // }}} 638 639 // {{{ howManySyndicArticleIdForStatut($statut) 640 641 /** 642 * This method is used to count the syndicated articles for a specific statut 643 * @access public 644 * @param String $statut the statut to see 645 */ 646 647 function howManySyndicArticleIdForStatut ($statut) { 648 $howManySyndicArticleId = 0; 649 $db = &$this->_getDB(); 650 651 if (DB::isError($db)) { 652 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : howManySyndicArticleIdForStatut()] " . $db->getMessage(). "", null, null, null, null, null, false); 653 } 654 655 $query = "SELECT COUNT(*) AS compte FROM " . $GLOBALS['table_prefix']. "_syndic_articles WHERE statut='$statut'"; 656 657 $result = $db->query($query); 658 659 if (DB::isError($result)) { 660 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : howManySyndicArticleIdForStatut()] " . $result->getMessage(). "", null, null, null, null, null, false); 661 } 662 663 if ($row = $result->fetchRow()) { 664 $howManySyndicArticleId = intval($row["compte"]); 665 } 666 667 $result->free(); 668 return $howManySyndicArticleId; 669 } 670 671 // }}} 672 673 // {{{ getAllForSyndicId($id_object,$critere) 674 675 /** 676 * This method is used to get all syndicated articles for a specific criteria and an ID of syndication 677 * @access public 678 * @param String $url url to get 679 * @param int $idSyndic ID of syndication to get 680 */ 681 682 function &getAllForSyndicId ($id_object, $critere) { 683 $syndicArticle = array(); 684 $db = &$this->_getDB(); 685 686 if (DB::isError($db)) { 687 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : getAllForSyndicId()] " . $db->getMessage(). "", null, null, null, null, null, false); 688 } 689 690 $query = "SELECT * FROM " . $GLOBALS['table_prefix']. "_syndic_articles WHERE id_syndic=$id_object ORDER BY $critere DESC"; 691 692 //echo $query; 693 694 $queryResult = $db->limitQuery($query, 0, 100); 695 696 if (DB::isError($queryResult)) { 697 return PEAR::raiseError("[" . get_class($this). " DB_syndic_article : getAllForSyndicId()] " . $queryResult->getMessage(). "", null, null, null, null, null, false); 698 } 699 700 while ($row = $queryResult->fetchRow()) { 701 $resultSyndicArticle = &BD_syndic_articles::factory($this->getDbParameters(), $this->getDbOptions()); 702 703 $maDate = new Date($row['maj']); 704 $row['maj'] = $maDate->getDate(DATE_FORMAT_TIMESTAMP); 705 706 $resultSyndicArticle->_fetchData($row); 707 $syndicArticle[] = &$resultSyndicArticle; 708 } 709 710 $queryResult->free(); 711 return $syndicArticle; 712 } 713 714 // }}} 715 716 } 717 ?>
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 |