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 / imagecategory.php < prev    next >
Encoding:
PHP Script  |  2007-10-19  |  9.4 KB  |  226 lines

  1. <?php
  2. // $Id: imagecategory.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. class XoopsImagecategory extends XoopsObject
  37. {
  38.     var $_imageCount;
  39.  
  40.     function XoopsImagecategory()
  41.     {
  42.         $this->XoopsObject();
  43.         $this->initVar('imgcat_id', XOBJ_DTYPE_INT, null, false);
  44.         $this->initVar('imgcat_name', XOBJ_DTYPE_TXTBOX, null, true, 100);
  45.         $this->initVar('imgcat_display', XOBJ_DTYPE_INT, 1, false);
  46.         $this->initVar('imgcat_weight', XOBJ_DTYPE_INT, 0, false);
  47.         $this->initVar('imgcat_maxsize', XOBJ_DTYPE_INT, 0, false);
  48.         $this->initVar('imgcat_maxwidth', XOBJ_DTYPE_INT, 0, false);
  49.         $this->initVar('imgcat_maxheight', XOBJ_DTYPE_INT, 0, false);
  50.         $this->initVar('imgcat_type', XOBJ_DTYPE_OTHER, null, false);
  51.         $this->initVar('imgcat_storetype', XOBJ_DTYPE_OTHER, null, false);
  52.     }
  53.  
  54.     function setImageCount($value)
  55.     {
  56.         $this->_imageCount = intval($value);
  57.     }
  58.  
  59.     function getImageCount()
  60.     {
  61.         return $this->_imageCount;
  62.     }
  63. }
  64.  
  65. /**
  66. * XOOPS image caetgory handler class.
  67. * This class is responsible for providing data access mechanisms to the data source
  68. * of XOOPS image category class objects.
  69. *
  70. *
  71. * @author  Kazumi Ono <onokazu@xoops.org>
  72. */
  73.  
  74. class XoopsImagecategoryHandler extends XoopsObjectHandler
  75. {
  76.  
  77.     function &create($isNew = true)
  78.     {
  79.         $imgcat = new XoopsImagecategory();
  80.         if ($isNew) {
  81.             $imgcat->setNew();
  82.         }
  83.         return $imgcat;
  84.     }
  85.  
  86.     function &get($id)
  87.     {
  88.       $id = intval($id);
  89.       $imgcat = false;
  90.         if ($id > 0) {
  91.             $sql = 'SELECT * FROM '.$this->db->prefix('imagecategory').' WHERE imgcat_id='.$id;
  92.             if (!$result = $this->db->query($sql)) {
  93.                 return $imgcat;
  94.             }
  95.             $numrows = $this->db->getRowsNum($result);
  96.             if ($numrows == 1) {
  97.                 $imgcat = new XoopsImagecategory();
  98.                 $imgcat->assignVars($this->db->fetchArray($result));
  99.             }
  100.         }
  101.         return $imgcat;
  102.     }
  103.  
  104.     function insert(&$imgcat)
  105.     {
  106.         /**
  107.         * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
  108.         */
  109.         if (!is_a($imgcat, 'xoopsimagecategory')) {
  110.             return false;
  111.         }
  112.  
  113.         if (!$imgcat->isDirty()) {
  114.             return true;
  115.         }
  116.         if (!$imgcat->cleanVars()) {
  117.             return false;
  118.         }
  119.         foreach ($imgcat->cleanVars as $k => $v) {
  120.             ${$k} = $v;
  121.         }
  122.         if ($imgcat->isNew()) {
  123.             $imgcat_id = $this->db->genId('imgcat_imgcat_id_seq');
  124.             $sql = sprintf("INSERT INTO %s (imgcat_id, imgcat_name, imgcat_display, imgcat_weight, imgcat_maxsize, imgcat_maxwidth, imgcat_maxheight, imgcat_type, imgcat_storetype) VALUES (%u, %s, %u, %u, %u, %u, %u, %s, %s)", $this->db->prefix('imagecategory'), $imgcat_id, $this->db->quoteString($imgcat_name), $imgcat_display, $imgcat_weight, $imgcat_maxsize, $imgcat_maxwidth, $imgcat_maxheight, $this->db->quoteString($imgcat_type), $this->db->quoteString($imgcat_storetype));
  125.         } else {
  126.             $sql = sprintf("UPDATE %s SET imgcat_name = %s, imgcat_display = %u, imgcat_weight = %u, imgcat_maxsize = %u, imgcat_maxwidth = %u, imgcat_maxheight = %u, imgcat_type = %s WHERE imgcat_id = %u", $this->db->prefix('imagecategory'), $this->db->quoteString($imgcat_name), $imgcat_display, $imgcat_weight, $imgcat_maxsize, $imgcat_maxwidth, $imgcat_maxheight, $this->db->quoteString($imgcat_type), $imgcat_id);
  127.         }
  128.         if (!$result = $this->db->query($sql)) {
  129.             return false;
  130.         }
  131.         if (empty($imgcat_id)) {
  132.             $imgcat_id = $this->db->getInsertId();
  133.         }
  134.         $imgcat->assignVar('imgcat_id', $imgcat_id);
  135.         return true;
  136.     }
  137.  
  138.     function delete(&$imgcat)
  139.     {
  140.         /**
  141.         * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
  142.         */
  143.         if (!is_a($imgcat, 'xoopsimagecategory')) {
  144.             return false;
  145.         }
  146.  
  147.         $sql = sprintf("DELETE FROM %s WHERE imgcat_id = %u", $this->db->prefix('imagecategory'), $imgcat->getVar('imgcat_id'));
  148.         if (!$result = $this->db->query($sql)) {
  149.             return false;
  150.         }
  151.         return true;
  152.     }
  153.  
  154.     function getObjects($criteria = null, $id_as_key = false)
  155.     {
  156.         $ret = array();
  157.         $limit = $start = 0;
  158.         $sql = 'SELECT DISTINCT c.* FROM '.$this->db->prefix('imagecategory').' c LEFT JOIN '.$this->db->prefix('group_permission')." l ON l.gperm_itemid=c.imgcat_id WHERE (l.gperm_name = 'imgcat_read' OR l.gperm_name = 'imgcat_write')";
  159.         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
  160.             $where = $criteria->render();
  161.             $sql .= ($where != '') ? ' AND '.$where : '';
  162.             $limit = $criteria->getLimit();
  163.             $start = $criteria->getStart();
  164.         }
  165.         $sql .= ' ORDER BY imgcat_weight, imgcat_id ASC';
  166.         $result = $this->db->query($sql, $limit, $start);
  167.         if (!$result) {
  168.             return $ret;
  169.         }
  170.         while ($myrow = $this->db->fetchArray($result)) {
  171.             $imgcat = new XoopsImagecategory();
  172.             $imgcat->assignVars($myrow);
  173.             if (!$id_as_key) {
  174.                 $ret[] =& $imgcat;
  175.             } else {
  176.                 $ret[$myrow['imgcat_id']] =& $imgcat;
  177.             }
  178.             unset($imgcat);
  179.         }
  180.         return $ret;
  181.     }
  182.  
  183.  
  184.     function getCount($criteria = null)
  185.     {
  186.         $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('imagecategory').' i LEFT JOIN '.$this->db->prefix('group_permission')." l ON l.gperm_itemid=i.imgcat_id WHERE (l.gperm_name = 'imgcat_read' OR l.gperm_name = 'imgcat_write')";
  187.         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
  188.             $where = $criteria->render();
  189.             $sql .= ($where != '') ? ' AND '.$where : '';
  190.         }
  191.         if (!$result =& $this->db->query($sql)) {
  192.             return 0;
  193.         }
  194.         list($count) = $this->db->fetchRow($result);
  195.         return $count;
  196.     }
  197.  
  198.     function getList($groups = array(), $perm = 'imgcat_read', $display = null, $storetype = null)
  199.     {
  200.         $criteria = new CriteriaCompo();
  201.         if (is_array($groups) && !empty($groups)) {
  202.             $criteriaTray = new CriteriaCompo();
  203.             foreach ($groups as $gid) {
  204.                 $criteriaTray->add(new Criteria('gperm_groupid', $gid), 'OR');
  205.             }
  206.             $criteria->add($criteriaTray);
  207.             if ($perm == 'imgcat_read' || $perm == 'imgcat_write') {
  208.                 $criteria->add(new Criteria('gperm_name', $perm));
  209.                 $criteria->add(new Criteria('gperm_modid', 1));
  210.             }
  211.         }
  212.         if (isset($display)) {
  213.             $criteria->add(new Criteria('imgcat_display', intval($display)));
  214.         }
  215.         if (isset($storetype)) {
  216.             $criteria->add(new Criteria('imgcat_storetype', $storetype));
  217.         }
  218.         $categories =& $this->getObjects($criteria, true);
  219.         $ret = array();
  220.         foreach (array_keys($categories) as $i) {
  221.                 $ret[$i] = $categories[$i]->getVar('imgcat_name');
  222.         }
  223.         return $ret;
  224.     }
  225. }
  226. ?>