[ 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/ -> setting.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 Setting business persistence abstraction.
  20  //
  21  if (defined("_BD_SETTING"))
  22      return;
  23  
  24  define("_BD_SETTING", "1");
  25  
  26  require_once("PEAR.php");
  27  require_once("DB.php");
  28  require_once dirname(__FILE__). "/metier.php";
  29  require_once dirname(__FILE__). "/../../inc_filtres.php";
  30  require_once dirname(__FILE__). "/../../inc_meta.php";
  31  
  32  define("SETTING_ALL_FIELDS", ' set_name, set_value ');
  33  
  34  /**
  35   * BD_setting is a base class for settings of newsletter 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_setting extends BD_metier {
  43  
  44      // {{{ properties
  45  
  46      var $_name;
  47      var $_value;
  48  
  49      // }}}
  50  
  51      // {{{ factory()
  52      function &factory ($dbParameters = null, $dbOptions = null) {
  53          if (file_exists(
  54                  dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/setting_" . $dbParameters->_dbEngine . ".php")
  55              == false) {
  56              include_once(dirname(__FILE__). "/common/setting_common.php");
  57              $classname = "BD_setting_common";
  58          }
  59          else {
  60              include_once(
  61                  dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/subscriber_" . $dbParameters->_dbEngine . ".php");
  62              $classname = "BD_setting_" . $dbParameters->_dbEngine;
  63          }
  64  
  65          if (!class_exists($classname)) {
  66              return PEAR::raiseError("Cannot instanciate class $classname", null, null, null, null, null, false);
  67          }
  68  
  69          $obj = &new $classname;
  70  
  71          $result = $obj->setDbParameters($dbParameters);
  72  
  73          if ($dbOptions != null) {
  74              $obj->setDbOptions($dbOptions);
  75          }
  76  
  77          if (PEAR::isError($result)) {
  78              return $result;
  79          }
  80          else {
  81              return $obj;
  82          }
  83      }
  84  
  85      // }}}
  86  
  87      // {{{ constructor
  88  
  89      /**
  90       * DB_setting constructor.
  91       *
  92       * @access public
  93       */
  94  
  95  	function BD_setting () { }
  96  
  97      // }}}
  98  
  99      // {{{ getName()
 100  
 101  	function getName () {
 102          return $this->_name;
 103      }
 104  
 105      // }}}
 106  
 107      // {{{ setName()
 108  
 109  	function setName ($name) {
 110          $this->_name = $name;
 111      }
 112  
 113      // }}}
 114  
 115      // {{{ getValue()
 116  
 117  	function getValue () {
 118          return stripslashes($this->_value);
 119      }
 120  
 121      // }}}
 122  
 123      // {{{ setValue()
 124  
 125  	function setValue ($value) {
 126          $this->_value = addslashes(corriger_caracteres($value));
 127      }
 128  
 129      // }}}
 130  
 131      // {{{ create()
 132  
 133  	function create () {
 134          $db = &$this->_getDB();
 135  
 136          if (DB::isError($db)) {
 137              return PEAR::raiseError("[" . get_class($this). " DB_setting : create()] " . $db->getMessage(). "", null,
 138                                      null, null,
 139                                      null, null,
 140                                      false);
 141          }
 142  
 143          $string_prefix = $GLOBALS['table_prefix']. "_cm_settings";
 144          $settingId = $db->nextId($string_prefix, true);
 145  
 146          $this->_id = $settingId;
 147  
 148          $query
 149              = 'INSERT INTO ' . $GLOBALS['table_prefix']. '_cm_settings (' . SETTING_ALL_FIELDS . ') VALUES ' . "('" . $this->_name . "', " . "'" . $this->_value . "') ";
 150  
 151          $result = $db->query($query);
 152  
 153          if (DB::isError($result)) {
 154              return PEAR::raiseError("[" . get_class($this). " DB_setting : create()] " . $result->getMessage(). "",
 155                                      null,
 156                                      null,
 157                                      null,
 158                                      null,
 159                                      null,
 160                                      false);
 161          }
 162      }
 163  
 164      // }}}
 165  
 166      // {{{ update()
 167  
 168  	function update () {
 169          $db = &$this->_getDB();
 170  
 171          if (DB::isError($db)) {
 172              return PEAR::raiseError("[" . get_class($this). " DB_setting : update()] " . $db->getMessage(). "", null,
 173                                      null, null,
 174                                      null, null,
 175                                      false);
 176          }
 177  
 178          $query
 179              = "UPDATE " . $GLOBALS['table_prefix']. "_cm_settings SET " . "sub_name = '" . $this->_name . "'" . ", sub_value = '" . $this->_value . "'" . " WHERE sub_id = " . $this->_id;
 180  
 181          //echo '<br>' . $query . '<br>';
 182  
 183          $result = $db->query($query);
 184  
 185          if (DB::isError($result)) {
 186              return PEAR::raiseError("[" . get_class($this). " DB_setting : update()] " . $result->getMessage(). "",
 187                                      null,
 188                                      null,
 189                                      null,
 190                                      null,
 191                                      null,
 192                                      false);
 193          }
 194      }
 195  
 196      // }}}
 197  
 198      // {{{ load()
 199  
 200  	function load ($name) {
 201          $db = &$this->_getDB();
 202  
 203          if (DB::isError($db)) {
 204              return PEAR::raiseError("[" . get_class($this). " DB_setting : load()] " . $db->getMessage(). "", null,
 205                                      null, null,
 206                                      null, null,
 207                                      false);
 208          }
 209  
 210          $query
 211              = "SELECT" . SETTING_ALL_FIELDS . "FROM " . $GLOBALS['table_prefix']. "_cm_settings WHERE set_name = '$name'";
 212          //echo '<br>' . $query .  '<br>';
 213  
 214          $result = $db->query($query);
 215  
 216          if (DB::isError($result)) {
 217              return $result;
 218          }
 219          else {
 220              if ($row = $result->fetchRow()) {
 221                  $this->_fetchData($row);
 222              }
 223              else {
 224                  return PEAR::raiseError(
 225                             "[" . get_class($this). " DB_setting : load($name)] Aucun parametre avec ce nom!", null,
 226                             null, null,
 227                             null, null,
 228                             false);
 229              }
 230              $result->free();
 231          }
 232      }
 233  
 234      // }}}
 235  
 236      // {{{ delete()
 237  
 238  	function delete ($name) {
 239          $db = &$this->_getDB();
 240  
 241          if (DB::isError($db)) {
 242              return PEAR::raiseError("[" . get_class($this). " DB_setting : delete()] " . $db->getMessage(). "", null,
 243                                      null, null,
 244                                      null, null,
 245                                      false);
 246          }
 247  
 248          $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_cm_settings WHERE set_name = '$name'";
 249  
 250          $result = $db->query($query);
 251  
 252          if (DB::isError($result)) {
 253              return PEAR::raiseError("[" . get_class($this). " DB_setting : delete($name)] Aucun parametre avec ce nom!",
 254                                      null,
 255                                      null,
 256                                      null,
 257                                      null,
 258                                      null,
 259                                      false);
 260          }
 261      }
 262  
 263      // }}}
 264  
 265      // {{{ getAllSetting()
 266  
 267      function &getAllSetting () {
 268          $settings = array();
 269          $db = &$this->_getDB();
 270  
 271          if (DB::isError($db)) {
 272              return PEAR::raiseError("[" . get_class($this). " DB_setting : getAllSetting()] " . $db->getMessage(). "",
 273                                      null,
 274                                      null,
 275                                      null,
 276                                      null,
 277                                      null,
 278                                      false);
 279          }
 280  
 281          $query = "SELECT " . SETTING_ALL_FIELDS . " FROM " . $GLOBALS['table_prefix']. "_cm_settings";
 282  
 283          $result = $db->query($query);
 284  
 285          if (DB::isError($result)) {
 286              return PEAR::raiseError(
 287                         "[" . get_class($this). " DB_setting : getAllSetting()] " . $result->getMessage(). "", null,
 288                         null, null,
 289                         null, null,
 290                         false);
 291          }
 292  
 293          while ($row = $result->fetchRow()) {
 294              $resultSetting = &BD_setting::factory($this->getDbParameters(), $this->getDbOptions());
 295              $resultSetting->_fetchData($row);
 296              $settings[] = &$resultSetting;
 297          }
 298  
 299          $result->free();
 300          return $settings;
 301      }
 302  
 303      // }}}
 304  
 305      // {{{ _fetchData()
 306  
 307  	function _fetchData ($row) {
 308          $this->setName($row['set_name']);
 309          $this->setValue($row['set_value']);
 310      }
 311  
 312  // }}}
 313  
 314  }
 315  ?>


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