home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / kernel / tplset.php < prev    next >
Encoding:
PHP Script  |  2007-10-19  |  8.2 KB  |  207 lines

  1. <?php
  2. // $Id: tplset.php 1102 2007-10-19 02:55:52Z dugris $
  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.         /**
  108.         * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
  109.         */
  110.         if (!is_a($tplset, 'xoopstplset')) {
  111.             return false;
  112.         }
  113.         if (!$tplset->isDirty()) {
  114.             return true;
  115.         }
  116.         if (!$tplset->cleanVars()) {
  117.             return false;
  118.         }
  119.         foreach ($tplset->cleanVars as $k => $v) {
  120.             ${$k} = $v;
  121.         }
  122.         if ($tplset->isNew()) {
  123.             $tplset_id = $this->db->genId('tplset_tplset_id_seq');
  124.             $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);
  125.         } else {
  126.             $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);
  127.         }
  128.         if (!$result = $this->db->query($sql)) {
  129.             return false;
  130.         }
  131.         if (empty($tplset_id)) {
  132.             $tplset_id = $this->db->getInsertId();
  133.         }
  134.         $tplset->assignVar('tplset_id', $tplset_id);
  135.         return true;
  136.     }
  137.  
  138.     function delete(&$tplset)
  139.     {
  140.         /**
  141.         * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
  142.         */
  143.         if (!is_a($tplset, 'xoopstplset')) {
  144.             return false;
  145.         }
  146.  
  147.         $sql = sprintf("DELETE FROM %s WHERE tplset_id = %u", $this->db->prefix('tplset'), $tplset->getVar('tplset_id'));
  148.         if (!$result = $this->db->query($sql)) {
  149.             return false;
  150.         }
  151.         $sql = sprintf("DELETE FROM %s WHERE tplset_name = %s", $this->db->prefix('imgset_tplset_link'), $this->db->quoteString($tplset->getVar('tplset_name')));
  152.         $this->db->query($sql);
  153.         return true;
  154.     }
  155.  
  156.     function getObjects($criteria = null, $id_as_key = false)
  157.     {
  158.         $ret = array();
  159.         $limit = $start = 0;
  160.         $sql = 'SELECT * FROM '.$this->db->prefix('tplset');
  161.         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
  162.             $sql .= ' '.$criteria->renderWhere().' ORDER BY tplset_id';
  163.             $limit = $criteria->getLimit();
  164.             $start = $criteria->getStart();
  165.         }
  166.         $result = $this->db->query($sql, $limit, $start);
  167.         if (!$result) {
  168.             return $ret;
  169.         }
  170.         while ($myrow = $this->db->fetchArray($result)) {
  171.             $tplset = new XoopsTplset();
  172.             $tplset->assignVars($myrow);
  173.             if (!$id_as_key) {
  174.                 $ret[] =& $tplset;
  175.             } else {
  176.                 $ret[$myrow['tplset_id']] =& $tplset;
  177.             }
  178.             unset($tplset);
  179.         }
  180.         return $ret;
  181.     }
  182.  
  183.  
  184.     function getCount($criteria = null)
  185.     {
  186.         $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('tplset');
  187.         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
  188.             $sql .= ' '.$criteria->renderWhere();
  189.         }
  190.         if (!$result =& $this->db->query($sql)) {
  191.             return 0;
  192.         }
  193.         list($count) = $this->db->fetchRow($result);
  194.         return $count;
  195.     }
  196.  
  197.     function getList($criteria = null)
  198.     {
  199.         $ret = array();
  200.         $tplsets = $this->getObjects($criteria, true);
  201.         foreach (array_keys($tplsets) as $i) {
  202.             $ret[$tplsets[$i]->getVar('tplset_name')] = $tplsets[$i]->getVar('tplset_name');
  203.         }
  204.         return $ret;
  205.     }
  206. }
  207. ?>