[ 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/ -> action.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 Action business persistence abstraction.
  20  //
  21  
  22  if (defined("_BD_ACTION"))
  23      return;
  24  
  25  define("_BD_ACTION", "1");
  26  
  27  require_once dirname(__FILE__). "/metier.php";
  28  require_once dirname(__FILE__). "/../../inc_filtres.php";
  29  define("ACTION_ALL_FIELDS", " action, poids ");
  30  
  31  /**
  32   * BD_action is a base class for action business persistence abstraction implementations, and must be
  33   * inherited by all such.
  34   * @package    BD
  35   * @author  Antoine Angénieux <aangenieux@clever-age.com>
  36   * @author     Erwan Le Bescond <elebescond@clever-age.com>
  37   * @access    public
  38   */
  39  class BD_action extends BD_metier {
  40      // {{{ properties
  41  
  42      /**
  43      * Name.
  44      * @var     String
  45      * @access  private
  46      */
  47      var $_action;
  48  
  49      /**
  50      * Poids.
  51      * @var     Int
  52      * @access  private
  53      */
  54      var $_poids;
  55  
  56      // {{{ factory()
  57      function &factory ($dbParameters = null, $dbOptions = null) {
  58          if (file_exists(dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/action_" . $dbParameters->_dbEngine . ".php") == false) {
  59              include_once (dirname(__FILE__). "/common/action_common.php");
  60              $classname = "BD_action_common";
  61          }
  62          else {
  63              include_once (dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/action_" . $dbParameters->_dbEngine . ".php");
  64              $classname = "BD_action_" . $dbParameters->_dbEngine;
  65          }
  66  
  67          if (!class_exists($classname)) {
  68              return PEAR::raiseError("Cannot instanciate class $classname", null, null, null, null, null, false);
  69          }
  70  
  71          $obj = &new $classname;
  72          $result = $obj->setDbParameters($dbParameters);
  73  
  74          if ($dbOptions != null) {
  75              $obj->setDbOptions($dbOptions);
  76          }
  77  
  78          if (PEAR::isError($result)) {
  79              return $result;
  80          }
  81          else {
  82              return $obj;
  83          }
  84      }
  85  
  86      // }}}
  87  
  88      // {{{ constructor
  89  
  90      /**
  91       * DB_action constructor.
  92       *
  93       * @access public
  94       */
  95  
  96  	function BD_action () { }
  97  
  98      // }}}
  99  
 100      // {{{ getAction()
 101  
 102  	function getAction () {
 103          return $this->_action;
 104      }
 105  
 106      // }}}
 107  
 108      // {{{ setAction()
 109  
 110  	function setAction ($action) {
 111          $this->_action = corriger_caracteres($action);
 112      }
 113  
 114      // }}}
 115  
 116      // {{{ getPoids()
 117  
 118  	function getPoids () {
 119          return $this->_poids;
 120      }
 121  
 122      // }}}
 123  
 124      // {{{ setPoids()
 125  
 126  	function setPoids ($poids) {
 127          $this->_poids = corriger_caracteres($poids);
 128      }
 129  
 130      // }}}
 131  
 132      // {{{ create()
 133  
 134  	function create () {
 135          $db = &$this->_getDB();
 136  
 137          if (DB::isError($db)) {
 138              return PEAR::raiseError("[" . get_class($this). " DB_action : create()] " . $db->getMessage(). "", null, null, null, null, null, false);
 139          }
 140  
 141          $query = "INSERT INTO " . $GLOBALS['table_prefix']. "_actions (" . ACTION_ALL_FIELDS . ") VALUES " . "('" . $db->quoteString($this->_action). "', " . $this->_poids . ")";
 142  
 143          $result = $db->query($query);
 144  
 145          if (DB::isError($result)) {
 146              return PEAR::raiseError("[" . get_class($this). " DB_action : create()] " . $result->getMessage(). "", null, null, null, null, null, false);
 147          }
 148      }
 149  
 150      // }}}
 151  
 152      // {{{ delete()
 153  
 154  	function delete ($action) {
 155          $db = &$this->_getDB();
 156  
 157          if (DB::isError($db)) {
 158              return PEAR::raiseError("[" . get_class($this). " DB_action : delete()] " . $db->getMessage(). "", null, null, null, null, null, false);
 159          }
 160  
 161          $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_actions WHERE action = $action";
 162  
 163          $result = $db->query($query);
 164  
 165          if (DB::isError($result)) {
 166              return PEAR::raiseError("[" . get_class($this). " DB_action : delete()] " . $result->getMessage(). "", null, null, null, null, null, false);
 167          }
 168      }
 169  
 170      // }}}
 171  
 172      // {{{ update()
 173  
 174  	function update () {
 175          $db = &$this->_getDB();
 176  
 177          if (DB::isError($db)) {
 178              return PEAR::raiseError("[" . get_class($this). " DB_action : update()] " . $db->getMessage(). "", null, null, null, null, null, false);
 179          }
 180  
 181          $query = "UPDATE " . $GLOBALS['table_prefix']. "_actions " . "SET action = '" . $db->quoteString($this->_action). "', " . "poids = " . $this->_poids . " " . "WHERE action = " . $this->_action;
 182  
 183          $result = $db->query($query);
 184  
 185          if (DB::isError($result)) {
 186              return PEAR::raiseError("[" . get_class($this). " DB_action : update()] " . $result->getMessage(). "", null, null, null, null, null, false);
 187          }
 188      }
 189  
 190      // }}}
 191  
 192      // {{{ load()
 193  
 194  	function load ($action) {
 195          $db = &$this->_getDB();
 196  
 197          if (DB::isError($db)) {
 198              return PEAR::raiseError("[" . get_class($this). " DB_action : load()] " . $db->getMessage(). "", null, null, null, null, null, false);
 199          }
 200  
 201          $query = "SELECT" . ACTION_ALL_FIELDS . "FROM " . $GLOBALS['table_prefix']. "_actions WHERE action = '$action'";
 202          //echo $query;
 203  
 204          $result = $db->query($query);
 205  
 206          if (DB::isError($result)) {
 207              return PEAR::raiseError("[" . get_class($this). " DB_action : load()] " . $result->getMessage(). "", null, null, null, null, null, false);
 208          }
 209          else {
 210              if ($row = $result->fetchRow()) {
 211                  $this->_fetchData($row);
 212              }
 213              else {
 214                  return PEAR::raiseError("[" . get_class($this). " Db_action : load(" . $action . ")] Aucune action ne correspond pas à ce nom!", null, null, null, null, null, false);
 215              }
 216              $result->free();
 217          }
 218      }
 219  
 220      // }}}
 221  
 222      // {{{ _fetchData()
 223  
 224  	function _fetchData ($row) {
 225          $this->setAction($row['action']);
 226          $this->setPoids($row['poids']);
 227      }
 228  
 229      // }}}
 230  
 231      // {{{ getAllAction()
 232  
 233      function &getAllAction () {
 234          $actions = array();
 235          $db = &$this->_getDB();
 236  
 237          if (DB::isError($db)) {
 238              return PEAR::raiseError("[" . get_class($this). " DB_action : getAllAction()] " . $db->getMessage(). "", null, null, null, null, null, false);
 239          }
 240  
 241          $query = "SELECT " . ACTION_ALL_FIELDS . " FROM " . $GLOBALS['table_prefix']. "_actions";
 242  
 243          $result = $db->query($query);
 244  
 245          if (DB::isError($result)) {
 246              return PEAR::raiseError("[" . get_class($this). " DB_action : getAllAction()] " . $result->getMessage(). "", null, null, null, null, null, false);
 247          }
 248  
 249          while ($row = $result->fetchRow()) {
 250              $resultAction = &BD_action::factory($this->getDbParameters(), $this->getDbOptions());
 251              $resultAction->_fetchData($row);
 252              $actions[] = &$resultAction;
 253          }
 254  
 255          $result->free();
 256          return $actions;
 257      }
 258  
 259      // }}}
 260  
 261      // {{{ getProfilForAction($action)
 262  
 263      function &getProfilForAction ($action) {
 264          $db = &$this->_getDB();
 265  
 266          if (DB::isError($db)) {
 267              return PEAR::raiseError("[" . get_class($this). " DB_action : getProfilForAction()] " . $db->getMessage(). "", null, null, null, null, null, false);
 268          }
 269  
 270          $query = "SELECT " . ACTION_ALL_FIELDS . " FROM " . $GLOBALS['table_prefix']. "_actions WHERE action=" . $action;
 271  
 272          $result = $db->query($query);
 273  
 274          if (DB::isError($result)) {
 275              return PEAR::raiseError("[" . get_class($this). " DB_action : getProfilForAction()] " . $result->getMessage(). "", null, null, null, null, null, false);
 276          }
 277  
 278          if ($row = $result->fetchRow()) {
 279              $resultAction = &BD_action::factory($this->getDbParameters(), $this->getDbOptions());
 280              $resultAction->_fetchData($row);
 281          }
 282  
 283          $result->free();
 284          return $resultAction;
 285      }
 286  
 287      // }}}
 288  
 289      // {{{ getActionForProfilisTrue($action)
 290  
 291      function &getActionForProfilisTrue ($profil) {
 292          $db = &$this->_getDB();
 293  
 294          if (DB::isError($db)) {
 295              return PEAR::raiseError("[" . get_class($this). " DB_action : getActionForProfilisTrue()] " . $db->getMessage(). "", null, null, null, null, null, false);
 296          }
 297  
 298          $query = 'SELECT ' . ACTION_ALL_FIELDS . ' FROM ' . $GLOBALS['table_prefix']. '_actions WHERE poids<=' . $profil . ' ORDER BY action ASC';
 299          //echo $query."\n";
 300          $query = $this->_traiteQuery($query);
 301          $result = $db->query($query);
 302  
 303          if (DB::isError($result)) {
 304              return PEAR::raiseError("[" . get_class($this). " DB_action : getActionForProfilisTrue()] " . $result->getMessage(). "", null, null, null, null, null, false);
 305          }
 306  
 307          while ($row = $result->fetchRow()) {
 308              $resultAction = &BD_action::factory($this->getDbParameters(), $this->getDbOptions());
 309              $resultAction->_fetchData($row);
 310              $actions[] = $row;
 311          }
 312  
 313          $result->free();
 314          return $actions;
 315      }
 316  
 317      // }}}
 318      /**GCH
 319      **/
 320      // {{{ getActionForProfilisFalse($action)
 321      function &getActionForProfilisFalse ($profil) {
 322          $db = &$this->_getDB();
 323  
 324          if (DB::isError($db)) {
 325              return PEAR::raiseError("[" . get_class($this). " DB_action : getActionForProfilisFalse()] " . $db->getMessage(). "", null, null, null, null, null, false);
 326          }
 327  
 328          $query = 'SELECT ' . ACTION_ALL_FIELDS . ' FROM ' . $GLOBALS['table_prefix']. '_actions WHERE poids>' . $profil . ' ORDER BY action ASC';
 329          //echo $query."\n";
 330          $query = $this->_traiteQuery($query);
 331          $result = $db->query($query);
 332  
 333          if (DB::isError($result)) {
 334              return PEAR::raiseError("[" . get_class($this). " DB_action : getActionForProfilisFalse()] " . $result->getMessage(). "", null, null, null, null, null, false);
 335          }
 336  
 337          while ($row = $result->fetchRow()) {
 338              $resultAction = &BD_action::factory($this->getDbParameters(), $this->getDbOptions());
 339              $resultAction->_fetchData($row);
 340              $actions[] = $row;
 341          }
 342  
 343          $result->free();
 344          return $actions;
 345      }
 346  // }}}
 347  
 348  }
 349  ?>


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