[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  // $Id: tplset.php 987 2007-08-13 07:34:08Z phppp $

   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  if (!defined('XOOPS_ROOT_PATH')) {
  32      exit();
  33  }
  34  class XoopsTplset extends XoopsObject
  35  {
  36  
  37  	function XoopsTplset()
  38      {
  39          $this->XoopsObject();
  40          $this->initVar('tplset_id', XOBJ_DTYPE_INT, null, false);
  41          $this->initVar('tplset_name', XOBJ_DTYPE_OTHER, null, false);
  42          $this->initVar('tplset_desc', XOBJ_DTYPE_TXTBOX, null, false, 255);
  43          $this->initVar('tplset_credits', XOBJ_DTYPE_TXTAREA, null, false);
  44          $this->initVar('tplset_created', XOBJ_DTYPE_INT, 0, false);
  45      }
  46  }
  47  
  48  /**

  49  * XOOPS tplset handler class.

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

  51  * of XOOPS tplset class objects.

  52  *

  53  *

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

  55  */
  56  
  57  class XoopsTplsetHandler extends XoopsObjectHandler
  58  {
  59  
  60      function &create($isNew = true)
  61      {
  62          $tplset = new XoopsTplset();
  63          if ($isNew) {
  64              $tplset->setNew();
  65          }
  66          return $tplset;
  67      }
  68  
  69      function &get($id)
  70      {
  71          $tplset = false;
  72          $id = intval($id);
  73          if ($id > 0) {
  74              $sql = 'SELECT * FROM '.$this->db->prefix('tplset').' WHERE tplset_id='.$id;
  75              if (!$result = $this->db->query($sql)) {
  76                  return $tplset;
  77              }
  78              $numrows = $this->db->getRowsNum($result);
  79              if ($numrows == 1) {
  80                  $tplset = new XoopsTplset();
  81                  $tplset->assignVars($this->db->fetchArray($result));
  82              }
  83          }
  84          return $tplset;
  85      }
  86  
  87      function &getByName($tplset_name)
  88      {
  89          $tplset = false;
  90          $tplset_name = trim($tplset_name);
  91          if ($tplset_name != '') {
  92              $sql = 'SELECT * FROM '.$this->db->prefix('tplset').' WHERE tplset_name='.$this->db->quoteString($tplset_name);
  93              if (!$result = $this->db->query($sql)) {
  94                  return $tplset;
  95              }
  96              $numrows = $this->db->getRowsNum($result);
  97              if ($numrows == 1) {
  98                  $tplset = new XoopsTplset();
  99                  $tplset->assignVars($this->db->fetchArray($result));
 100              }
 101          }
 102          return $tplset;
 103      }
 104  
 105      function insert(&$tplset)
 106      {
 107          if (strtolower(get_class($tplset)) != 'xoopstplset') {
 108              return false;
 109          }
 110          if (!$tplset->isDirty()) {
 111              return true;
 112          }
 113          if (!$tplset->cleanVars()) {
 114              return false;
 115          }
 116          foreach ($tplset->cleanVars as $k => $v) {
 117              ${$k} = $v;
 118          }
 119          if ($tplset->isNew()) {
 120              $tplset_id = $this->db->genId('tplset_tplset_id_seq');
 121              $sql = sprintf("INSERT INTO %s (tplset_id, tplset_name, tplset_desc, tplset_credits, tplset_created) VALUES (%u, %s, %s, %s, %u)", $this->db->prefix('tplset'), $tplset_id, $this->db->quoteString($tplset_name), $this->db->quoteString($tplset_desc), $this->db->quoteString($tplset_credits), $tplset_created);
 122          } else {
 123              $sql = sprintf("UPDATE %s SET tplset_name = %s, tplset_desc = %s, tplset_credits = %s, tplset_created = %u WHERE tplset_id = %u", $this->db->prefix('tplset'), $this->db->quoteString($tplset_name), $this->db->quoteString($tplset_desc), $this->db->quoteString($tplset_credits), $tplset_created, $tplset_id);
 124          }
 125          if (!$result = $this->db->query($sql)) {
 126              return false;
 127          }
 128          if (empty($tplset_id)) {
 129              $tplset_id = $this->db->getInsertId();
 130          }
 131          $tplset->assignVar('tplset_id', $tplset_id);
 132          return true;
 133      }
 134  
 135      function delete(&$tplset)
 136      {
 137          if (strtolower(get_class($tplset)) != 'xoopstplset') {
 138              return false;
 139          }
 140          $sql = sprintf("DELETE FROM %s WHERE tplset_id = %u", $this->db->prefix('tplset'), $tplset->getVar('tplset_id'));
 141          if (!$result = $this->db->query($sql)) {
 142              return false;
 143          }
 144          $sql = sprintf("DELETE FROM %s WHERE tplset_name = %s", $this->db->prefix('imgset_tplset_link'), $this->db->quoteString($tplset->getVar('tplset_name')));
 145          $this->db->query($sql);
 146          return true;
 147      }
 148  
 149      function getObjects($criteria = null, $id_as_key = false)
 150      {
 151          $ret = array();
 152          $limit = $start = 0;
 153          $sql = 'SELECT * FROM '.$this->db->prefix('tplset');
 154          if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
 155              $sql .= ' '.$criteria->renderWhere().' ORDER BY tplset_id';
 156              $limit = $criteria->getLimit();
 157              $start = $criteria->getStart();
 158          }
 159          $result = $this->db->query($sql, $limit, $start);
 160          if (!$result) {
 161              return $ret;
 162          }
 163          while ($myrow = $this->db->fetchArray($result)) {
 164              $tplset = new XoopsTplset();
 165              $tplset->assignVars($myrow);
 166              if (!$id_as_key) {
 167                  $ret[] =& $tplset;
 168              } else {
 169                  $ret[$myrow['tplset_id']] =& $tplset;
 170              }
 171              unset($tplset);
 172          }
 173          return $ret;
 174      }
 175  
 176  
 177      function getCount($criteria = null)
 178      {
 179          $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('tplset');
 180          if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
 181              $sql .= ' '.$criteria->renderWhere();
 182          }
 183          if (!$result =& $this->db->query($sql)) {
 184              return 0;
 185          }
 186          list($count) = $this->db->fetchRow($result);
 187          return $count;
 188      }
 189  
 190      function getList($criteria = null)
 191      {
 192          $ret = array();
 193          $tplsets = $this->getObjects($criteria, true);
 194          foreach (array_keys($tplsets) as $i) {
 195              $ret[$tplsets[$i]->getVar('tplset_name')] = $tplsets[$i]->getVar('tplset_name');
 196          }
 197          return $ret;
 198      }
 199  }
 200  ?>


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