[ 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_breves.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 Breve business persistence abstraction.
  20  //
  21  
  22  if (defined("_BD_INDEX_BREVES"))
  23      return;
  24  
  25  define("_BD_INDEX_BREVES", "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_BREVES_ALL_FIELDS", " hash, points, id_breve ");
  33  
  34  /**
  35   * BD_index_breves is a base class for breve 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_breves 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       * $_breveId
  61       * @var     int
  62       * @access  private
  63       */
  64      var $_breveId;
  65  
  66      // }}}
  67  
  68      // {{{ factory()
  69      function &factory ($dbParameters = null, $dbOptions = null) {
  70          if (file_exists(dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/index_breves_" . $dbParameters->_dbEngine . ".php") == false) {
  71              include_once(dirname(__FILE__). "/common/index_breves_common.php");
  72              $classname = "BD_index_breves_common";
  73          }
  74          else {
  75              include_once(dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/index_breves_" . $dbParameters->_dbEngine . ".php");
  76              $classname = "BD_index_breves_" . $dbParameters->_dbEngine;
  77          }
  78  
  79          if (!class_exists($classname)) {
  80              return PEAR::raiseError("Cannot instanciate class $classname", null, null, null, null, null, false);
  81          }
  82  
  83          $obj = &new $classname;
  84          $result = $obj->setDbParameters($dbParameters);
  85  
  86          if ($dbOptions != null) {
  87              $obj->setDbOptions($dbOptions);
  88          }
  89  
  90          if (PEAR::isError($result)) {
  91              return $result;
  92          }
  93          else {
  94              return $obj;
  95          }
  96      }
  97  
  98      // }}}
  99  
 100      // {{{ constructor
 101  
 102      /**
 103       * DB_index_breves constructor.
 104       *
 105       * @access public
 106       */
 107  
 108  	function BD_index_breves () { }
 109  
 110      // }}}
 111  
 112      // {{{ getHash()
 113  
 114      /**
 115       * Returns the hash's value
 116       * @return  int
 117       * @access  public
 118       */
 119  
 120  	function getHash () {
 121          return $this->_hash;
 122      }
 123  
 124      // }}}
 125  
 126      // {{{ setHash()
 127  
 128      /**
 129       * Sets the hash's value
 130       * @param  int
 131       * @access  public
 132       */
 133  
 134  	function setHash ($hash) {
 135          $this->_hash = corriger_caracteres($hash);
 136      }
 137  
 138      // }}}
 139  
 140      // {{{ getPoints()
 141  
 142      /**
 143       * Returns the points' value
 144       * @return  int
 145       * @access  public
 146       */
 147  
 148  	function getPoints () {
 149          return $this->_points;
 150      }
 151  
 152      // }}}
 153  
 154      // {{{ setPoints()
 155  
 156      /**
 157       * Sets the points' value
 158       * @param  int
 159       * @access  public
 160       */
 161  
 162  	function setPoints ($points) {
 163          $this->_points = $points;
 164      }
 165  
 166      // }}}
 167  
 168      // {{{ getBreveId()
 169  
 170      /**
 171       * Returns the breve ID
 172       * @return  int
 173       * @access  public
 174       */
 175  
 176  	function getBreveId () {
 177          return $this->_breveId;
 178      }
 179  
 180      // }}}
 181  
 182      // {{{ setBreveId()
 183  
 184      /**
 185       * Sets the breve ID
 186       * @param  Date
 187       * @access  public
 188       */
 189  
 190  	function setBreveId ($breveId) {
 191          $this->_breveId = $breveId;
 192      }
 193  
 194      // }}}
 195  
 196      // {{{ create()
 197  
 198      /**
 199       * This method is used to create a new index of breve in the database
 200       * @access public
 201       */
 202  
 203  	function create () {
 204          $db = &$this->_getDB();
 205  
 206          if (DB::isError($db)) {
 207              return PEAR::raiseError("[" . get_class($this). " DB_index_breves : create()] " . $db->getMessage(). "", null, null, null, null, null, false);
 208          }
 209  
 210          $query = "INSERT INTO " . $GLOBALS['table_prefix']. "_index_breves (" . INDEX_BREVES_ALL_FIELDS . ") VALUES " . "('" . $db->quoteString($this->_hash). "', " . $this->_points . ", " . $this->_breveId . ")";
 211  
 212          $result = $db->query($query);
 213  
 214          if (DB::isError($result)) {
 215              return PEAR::raiseError("[" . get_class($this). " DB_index_breves : create()] " . $result->getMessage(). "", null, null, null, null, null, false);
 216          }
 217      }
 218  
 219      // }}}
 220  
 221      // {{{ load()
 222  
 223      /**
 224       * This method is used to load an index of breve from the database
 225       * @access  public
 226       * @param   int $breveId ID of breve to load
 227       */
 228  
 229  	function load ($breveId) {
 230          $db = &$this->_getDB();
 231  
 232          if (DB::isError($db)) {
 233              return PEAR::raiseError("[" . get_class($this). " DB_index_breves : load()] " . $db->getMessage(). "", null, null, null, null, null, false);
 234          }
 235  
 236          $query = "SELECT" . INDEX_BREVES_ALL_FIELDS . "FROM " . $GLOBALS['table_prefix']. "_index_breves WHERE breveId = $breveId";
 237  
 238          $result = $db->query($query);
 239  
 240          if (DB::isError($result)) {
 241              return PEAR::raiseError("[" . get_class($this). " DB_index_breves : load()] " . $result->getMessage(). "", null, null, null, null, null, false);
 242          }
 243          else {
 244              if ($row = $result->fetchRow()) {
 245                  $this->_fetchData($row);
 246              }
 247              else {
 248                  return PEAR::raiseError("[" . get_class($this). " DB_index_breves : load($breveId)] Aucun index de breves ne correspond à cet ID!", null, null, null, null, null, false);
 249              }
 250              $result->free();
 251          }
 252      }
 253  
 254      // }}}
 255  
 256      // {{{ delete()
 257  
 258      /**
 259       * This method is used to delete the index of breve
 260       * @access  public
 261       */
 262  
 263  	function delete () {
 264          $db = &$this->_getDB();
 265  
 266          if (DB::isError($db)) {
 267              return PEAR::raiseError("[" . get_class($this). " DB_index_breves : delete()] " . $db->getMessage(). "", null, null, null, null, null, false);
 268          }
 269  
 270          $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_index_breves";
 271  
 272          $result = $db->query($query);
 273  
 274          if (DB::isError($result)) {
 275              return PEAR::raiseError("[" . get_class($this). " DB_index_breves : delete()] " . $result->getMessage(). "", null, null, null, null, null, false);
 276          }
 277      }
 278  
 279      // }}}
 280  
 281      // {{{ deleteIndexBreveForBreveId($id_objet)
 282  
 283      /**
 284       * This method is used to delete an index of breve from the database
 285       * @access  public
 286       * @param   int $id_objet ID of breve to delete
 287       */
 288  
 289  	function deleteIndexBreveForBreveId ($id_objet) {
 290          $db = &$this->_getDB();
 291  
 292          if (DB::isError($db)) {
 293              return PEAR::raiseError("[" . get_class($this). " DB_index_breves : deleteIndexBreveForBreveId()] " . $db->getMessage(). "", null, null, null, null, null, false);
 294          }
 295  
 296          $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_index_breves WHERE id_breve = $id_objet";
 297  
 298          $result = $db->query($query);
 299  
 300          if (DB::isError($result)) {
 301              return PEAR::raiseError("[" . get_class($this). " DB_index_breves : deleteIndexBreveForBreveId()] " . $result->getMessage(). "", null, null, null, null, null, false);
 302          }
 303      }
 304  
 305      // }}}
 306  
 307      // {{{ _fetchData()
 308  
 309      /**
 310       * This method is used to fetch result set fields into the object fields
 311       * @access  private
 312       * @param   int $row the row to fetch
 313       */
 314  
 315  	function _fetchData ($row) {
 316          $this->setHash($row['hash']);
 317          $this->setPoints($row['points']);
 318          $this->setBreveId($row['id_breve']);
 319      }
 320  
 321      // }}}
 322  
 323      // {{{ howManyIndexBreveForBreveId($id_objet)
 324  
 325      /**
 326       * This method is used to count how many index of breve exist for a breve's ID
 327       * @access  public
 328       * @param   int $id_objet ID of syndication to see
 329       */
 330  
 331  	function howManyIndexBreveForBreveId ($id_objet) {
 332          if ((!isset($id_objet)) || ($id_objet < 0))
 333              return 0;
 334  
 335          $howManyIndexBreveForBreveId = 0;
 336          $db = &$this->_getDB();
 337  
 338          if (DB::isError($db)) {
 339              return PEAR::raiseError("[" . get_class($this). " DB_index_breves : howManyIndexBreveForBreveId()] " . $db->getMessage(). "", null, null, null, null, null, false);
 340          }
 341  
 342          $query = "SELECT COUNT(*) as compteur FROM " . $GLOBALS['table_prefix']. "_index_breves WHERE id_breve = $id_objet";
 343  
 344          $result = $db->query($query);
 345  
 346          if (DB::isError($result)) {
 347              return PEAR::raiseError("[" . get_class($this). " DB_index_breves : howManyIndexBreveForBreveId()] " . $result->getMessage(). "", null, null, null, null, null, false);
 348          }
 349  
 350          if ($row = $result->fetchRow()) {
 351              $howManyIndexBreveForBreveId = intval($row["compteur"]);
 352          }
 353  
 354          $result->free();
 355          return $howManyIndexBreveForBreveId;
 356      }
 357  
 358  // }}}
 359  }
 360  ?>


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