[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Agora1-4/ecrire/include/bd/ -> index_articles.php (source)

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


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7