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 / configcategory.php < prev    next >
Encoding:
PHP Script  |  2007-10-19  |  8.1 KB  |  225 lines

  1. <?php
  2. // $Id: configcategory.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.  
  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. /**
  47.  * A category of configs
  48.  *
  49.  * @author    Kazumi Ono    <onokazu@xoops.org>
  50.  * @copyright    copyright (c) 2000-2003 XOOPS.org
  51.  *
  52.  * @package     kernel
  53.  */
  54. class XoopsConfigCategory extends XoopsObject
  55. {
  56.     /**
  57.      * Constructor
  58.      *
  59.      */
  60.     function XoopsConfigCategory()
  61.     {
  62.         $this->XoopsObject();
  63.         $this->initVar('confcat_id', XOBJ_DTYPE_INT, null);
  64.         $this->initVar('confcat_name', XOBJ_DTYPE_OTHER, null);
  65.         $this->initVar('confcat_order', XOBJ_DTYPE_INT, 0);
  66.     }
  67. }
  68.  
  69.  
  70. /**
  71.  * XOOPS configuration category handler class.
  72.  *
  73.  * This class is responsible for providing data access mechanisms to the data source
  74.  * of XOOPS configuration category class objects.
  75.  *
  76.  * @author  Kazumi Ono <onokazu@xoops.org>
  77.  * @copyright    copyright (c) 2000-2003 XOOPS.org
  78.  *
  79.  * @package     kernel
  80.  * @subpackage  config
  81.  */
  82. class XoopsConfigCategoryHandler extends XoopsObjectHandler
  83. {
  84.  
  85.     /**
  86.      * Create a new category
  87.      *
  88.      * @param    bool    $isNew  Flag the new object as "new"?
  89.      *
  90.      * @return    object  New {@link XoopsConfigCategory}
  91.      */
  92.     function &create($isNew = true)
  93.     {
  94.         $confcat = new XoopsConfigCategory();
  95.         if ($isNew) {
  96.             $confcat->setNew();
  97.         }
  98.         return $confcat;
  99.     }
  100.  
  101.     /**
  102.      * Retrieve a {@link XoopsConfigCategory}
  103.      *
  104.      * @param    int $id ID
  105.      *
  106.      * @return    object  {@link XoopsConfigCategory}, FALSE on fail
  107.      */
  108.     function &get($id) {
  109.         $confcat = false;
  110.         $id = intval($id);
  111.         if ($id > 0) {
  112.             $sql = 'SELECT * FROM '.$this->db->prefix('configcategory').' WHERE confcat_id='.$id;
  113.             if (!$result = $this->db->query($sql)) {
  114.                 return $confcat;
  115.             }
  116.             $numrows = $this->db->getRowsNum($result);
  117.             if ($numrows == 1) {
  118.                 $confcat = new XoopsConfigCategory();
  119.                 $confcat->assignVars($this->db->fetchArray($result), false);
  120.             }
  121.         }
  122.         return $confcat;
  123.     }
  124.  
  125.     /**
  126.      * Store a {@link XoopsConfigCategory}
  127.      *
  128.      * @param    object   &$confcat  {@link XoopsConfigCategory}
  129.      *
  130.      * @return    bool    TRUE on success
  131.      */
  132.     function insert(&$confcat)
  133.     {
  134.         /**
  135.         * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
  136.         */
  137.         if (!is_a($confcat, 'xoopsconfigcategory')) {
  138.             return false;
  139.         }
  140.         if (!$confcat->isDirty()) {
  141.             return true;
  142.         }
  143.         if (!$confcat->cleanVars()) {
  144.             return false;
  145.         }
  146.         foreach ($confcat->cleanVars as $k => $v) {
  147.             ${$k} = $v;
  148.         }
  149.         if ($confcat->isNew()) {
  150.             $confcat_id = $this->db->genId('configcategory_confcat_id_seq');
  151.             $sql = sprintf("INSERT INTO %s (confcat_id, confcat_name, confcat_order) VALUES (%u, %s, %u)", $this->db->prefix('configcategory'), $confcat_id, $this->db->quoteString($confcat_name), $confcat_order);
  152.         } else {
  153.             $sql = sprintf("UPDATE %s SET confcat_name = %s, confcat_order = %u WHERE confcat_id = %u", $this->db->prefix('configcategory'), $this->db->quoteString($confcat_name), $confcat_order, $confcat_id);
  154.         }
  155.         if (!$result = $this->db->query($sql)) {
  156.             return false;
  157.         }
  158.         if (empty($confcat_id)) {
  159.             $confcat_id = $this->db->getInsertId();
  160.         }
  161.         $confcat->assignVar('confcat_id', $confcat_id);
  162.         return $confcat_id;
  163.     }
  164.  
  165.     /**
  166.      * Delelete a {@link XoopsConfigCategory}
  167.      *
  168.      * @param    object  &$confcat   {@link XoopsConfigCategory}
  169.      *
  170.      * @return    bool    TRUE on success
  171.      */
  172.     function delete(&$confcat)
  173.     {
  174.         /**
  175.         * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
  176.         */
  177.         if (!is_a($confcat, 'xoopsconfigcategory')) {
  178.             return false;
  179.         }
  180.  
  181.         $sql = sprintf("DELETE FROM %s WHERE confcat_id = %u", $this->db->prefix('configcategory'), $configcategory->getVar('confcat_id'));
  182.         if (!$result = $this->db->query($sql)) {
  183.             return false;
  184.         }
  185.         return true;
  186.     }
  187.  
  188.     /**
  189.      * Get some {@link XoopsConfigCategory}s
  190.      *
  191.      * @param    object  $criteria   {@link CriteriaElement}
  192.      * @param    bool    $id_as_key  Use the IDs as keys to the array?
  193.      *
  194.      * @return    array   Array of {@link XoopsConfigCategory}s
  195.      */
  196.     function getObjects($criteria = null, $id_as_key = false)
  197.     {
  198.         $ret = array();
  199.         $limit = $start = 0;
  200.         $sql = 'SELECT * FROM '.$this->db->prefix('configcategory');
  201.         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
  202.             $sql .= ' '.$criteria->renderWhere();
  203.             $sort = !in_array($criteria->getSort(), array('confcat_id', 'confcat_name', 'confcat_order')) ? 'confcat_order' : $criteria->getSort();
  204.             $sql .= ' ORDER BY '.$sort.' '.$criteria->getOrder();
  205.             $limit = $criteria->getLimit();
  206.             $start = $criteria->getStart();
  207.         }
  208.         $result = $this->db->query($sql, $limit, $start);
  209.         if (!$result) {
  210.             return $ret;
  211.         }
  212.         while ($myrow = $this->db->fetchArray($result)) {
  213.             $confcat = new XoopsConfigCategory();
  214.             $confcat->assignVars($myrow, false);
  215.             if (!$id_as_key) {
  216.                 $ret[] =& $confcat;
  217.             } else {
  218.                 $ret[$myrow['confcat_id']] =& $confcat;
  219.             }
  220.             unset($confcat);
  221.         }
  222.         return $ret;
  223.     }
  224. }
  225. ?>