[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/kernel/ -> configoption.php (source)

   1  <?php
   2  // $Id: configoption.php 506 2006-05-26 23:10:37Z skalpa $

   3  //  ------------------------------------------------------------------------ //

   4  //                XOOPS - PHP Content Management System                      //

   5  //                    Copyright (c) 2000 XOOPS.org                           //

   6  //                       <http://www.xoops.org/>                             //

   7  //  ------------------------------------------------------------------------ //

   8  //  This program is free software; you can redistribute it and/or modify     //

   9  //  it under the terms of the GNU General Public License as published by     //

  10  //  the Free Software Foundation; either version 2 of the License, or        //

  11  //  (at your option) any later version.                                      //

  12  //                                                                           //

  13  //  You may not change or alter any portion of this comment or credits       //

  14  //  of supporting developers from this source code or any supporting         //

  15  //  source code which is considered copyrighted (c) material of the          //

  16  //  original comment or credit authors.                                      //

  17  //                                                                           //

  18  //  This program is distributed in the hope that it will be useful,          //

  19  //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //

  20  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //

  21  //  GNU General Public License for more details.                             //

  22  //                                                                           //

  23  //  You should have received a copy of the GNU General Public License        //

  24  //  along with this program; if not, write to the Free Software              //

  25  //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //

  26  //  ------------------------------------------------------------------------ //

  27  // Author: Kazumi Ono (AKA onokazu)                                          //

  28  // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //

  29  // Project: The XOOPS Project                                                //

  30  // ------------------------------------------------------------------------- //

  31  
  32  if (!defined('XOOPS_ROOT_PATH')) {
  33      exit();
  34  }
  35  
  36  /**

  37   * 

  38   * 

  39   * @package     kernel

  40   * 

  41   * @author        Kazumi Ono    <onokazu@xoops.org>

  42   * @copyright    copyright (c) 2000-2003 XOOPS.org

  43   */
  44  
  45  /**

  46   * A Config-Option

  47   * 

  48   * @author    Kazumi Ono    <onokazu@xoops.org>

  49   * @copyright    copyright (c) 2000-2003 XOOPS.org

  50   * 

  51   * @package     kernel

  52   */
  53  class XoopsConfigOption extends XoopsObject
  54  {
  55      /**

  56       * Constructor

  57       */
  58      function XoopsConfigOption()
  59      {
  60          $this->XoopsObject();
  61          $this->initVar('confop_id', XOBJ_DTYPE_INT, null);
  62          $this->initVar('confop_name', XOBJ_DTYPE_TXTBOX, null, true, 255);
  63          $this->initVar('confop_value', XOBJ_DTYPE_TXTBOX, null, true, 255);
  64          $this->initVar('conf_id', XOBJ_DTYPE_INT, 0);
  65      }
  66  }
  67  
  68  /**

  69   * XOOPS configuration option handler class.  

  70   * This class is responsible for providing data access mechanisms to the data source 

  71   * of XOOPS configuration option class objects.

  72   *

  73   * @copyright    copyright (c) 2000-2003 XOOPS.org

  74   * @author  Kazumi Ono <onokazu@xoops.org>

  75   * 

  76   * @package     kernel

  77   * @subpackage  config

  78  */
  79  class XoopsConfigOptionHandler extends XoopsObjectHandler
  80  {
  81  
  82      /**

  83       * Create a new option

  84       * 

  85       * @param    bool    $isNew  Flag the option as "new"?

  86       * 

  87       * @return    object  {@link XoopsConfigOption} 

  88       */
  89      function &create($isNew = true)
  90      {
  91          $confoption = new XoopsConfigOption();
  92          if ($isNew) {
  93              $confoption->setNew();
  94          }
  95          return $confoption;
  96      }
  97  
  98      /**

  99       * Get an option from the database

 100       * 

 101       * @param    int $id ID of the option

 102       * 

 103       * @return    object  reference to the {@link XoopsConfigOption}, FALSE on fail

 104       */
 105      function &get($id)
 106      {
 107          $confoption = false;
 108          $id = intval($id);
 109          if ($id > 0) {
 110              $sql = 'SELECT * FROM '.$this->db->prefix('configoption').' WHERE confop_id='.$id;
 111              if (!$result = $this->db->query($sql)) {
 112                  return $confoption;
 113              }
 114              $numrows = $this->db->getRowsNum($result);
 115              if ($numrows == 1) {
 116                  $confoption = new XoopsConfigOption();
 117                  $confoption->assignVars($this->db->fetchArray($result));
 118              }
 119          }
 120          return $confoption;
 121      }
 122  
 123      /**

 124       * Insert a new option in the database

 125       * 

 126       * @param    object  &$confoption    reference to a {@link XoopsConfigOption} 

 127       * @return    bool    TRUE if successfull.

 128       */
 129      function insert(&$confoption)
 130      {
 131          if (strtolower(get_class($confoption)) != 'xoopsconfigoption') {
 132              return false;
 133          }
 134          if (!$confoption->isDirty()) {
 135              return true;
 136          }
 137          if (!$confoption->cleanVars()) {
 138              return false;
 139          }
 140          foreach ($confoption->cleanVars as $k => $v) {
 141              ${$k} = $v;
 142          }
 143          if ($confoption->isNew()) {
 144              $confop_id = $this->db->genId('configoption_confop_id_seq');
 145              $sql = sprintf("INSERT INTO %s (confop_id, confop_name, confop_value, conf_id) VALUES (%u, %s, %s, %u)", $this->db->prefix('configoption'), $confop_id, $this->db->quoteString($confop_name), $this->db->quoteString($confop_value), $conf_id);
 146          } else {
 147              $sql = sprintf("UPDATE %s SET confop_name = %s, confop_value = %s WHERE confop_id = %u", $this->db->prefix('configoption'), $this->db->quoteString($confop_name), $this->db->quoteString($confop_value), $confop_id);
 148          }
 149          if (!$result = $this->db->query($sql)) {
 150              return false;
 151          }
 152          if (empty($confop_id)) {
 153              $confop_id = $this->db->getInsertId();
 154          }
 155          $confoption->assignVar('confop_id', $confop_id);
 156          return $confop_id;
 157      }
 158  
 159      /**

 160       * Delete an option

 161       * 

 162       * @param    object  &$confoption    reference to a {@link XoopsConfigOption} 

 163       * @return    bool    TRUE if successful

 164       */
 165      function delete(&$confoption)
 166      {
 167          if (strtolower(get_class($confoption)) != 'xoopsconfigoption') {
 168              return false;
 169          }
 170          $sql = sprintf("DELETE FROM %s WHERE confop_id = %u", $this->db->prefix('configoption'), $confoption->getVar('confop_id'));
 171          if (!$result = $this->db->query($sql)) {
 172              return false;
 173          }
 174          return true;
 175      }
 176  
 177      /**

 178       * Get some {@link XoopsConfigOption}s 

 179       * 

 180       * @param    object  $criteria   {@link CriteriaElement} 

 181       * @param    bool    $id_as_key  Use the IDs as array-keys?

 182       * 

 183       * @return    array   Array of {@link XoopsConfigOption}s 

 184       */
 185      function getObjects($criteria = null, $id_as_key = false)
 186      {
 187          $ret = array();
 188          $limit = $start = 0;
 189          $sql = 'SELECT * FROM '.$this->db->prefix('configoption');
 190          if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
 191              $sql .= ' '.$criteria->renderWhere().' ORDER BY confop_id '.$criteria->getOrder();
 192              $limit = $criteria->getLimit();
 193              $start = $criteria->getStart();
 194          }
 195          $result = $this->db->query($sql, $limit, $start);
 196          if (!$result) {
 197              return $ret;
 198          }
 199          while ($myrow = $this->db->fetchArray($result)) {
 200              $confoption = new XoopsConfigOption();
 201              $confoption->assignVars($myrow);
 202              if (!$id_as_key) {
 203                  $ret[] =& $confoption;
 204              } else {
 205                  $ret[$myrow['confop_id']] =& $confoption;
 206              }
 207              unset($confoption);
 208          }
 209          return $ret;
 210      }
 211  }
 212  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics