[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  // $Id: imagecategory.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  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          $imgcat = false;
  89          if (intval($id) > 0) {
  90              $sql = 'SELECT * FROM '.$this->db->prefix('imagecategory').' WHERE imgcat_id='.$id;
  91              if (!$result = $this->db->query($sql)) {
  92                  return $imgcat;
  93              }
  94              $numrows = $this->db->getRowsNum($result);
  95              if ($numrows == 1) {
  96                  $imgcat = new XoopsImagecategory();
  97                  $imgcat->assignVars($this->db->fetchArray($result));
  98              }
  99          }
 100          return $imgcat;
 101      }
 102  
 103      function insert(&$imgcat)
 104      {
 105          if (strtolower(get_class($imgcat)) != 'xoopsimagecategory') {
 106              return false;
 107          }
 108          if (!$imgcat->isDirty()) {
 109              return true;
 110          }
 111          if (!$imgcat->cleanVars()) {
 112              return false;
 113          }
 114          foreach ($imgcat->cleanVars as $k => $v) {
 115              ${$k} = $v;
 116          }
 117          if ($imgcat->isNew()) {
 118              $imgcat_id = $this->db->genId('imgcat_imgcat_id_seq');
 119              $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));
 120          } else {
 121              $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);
 122          }
 123          if (!$result = $this->db->query($sql)) {
 124              return false;
 125          }
 126          if (empty($imgcat_id)) {
 127              $imgcat_id = $this->db->getInsertId();
 128          }
 129          $imgcat->assignVar('imgcat_id', $imgcat_id);
 130          return true;
 131      }
 132  
 133      function delete(&$imgcat)
 134      {
 135          if (strtolower(get_class($imgcat)) != 'xoopsimagecategory') {
 136              return false;
 137          }
 138          $sql = sprintf("DELETE FROM %s WHERE imgcat_id = %u", $this->db->prefix('imagecategory'), $imgcat->getVar('imgcat_id'));
 139          if (!$result = $this->db->query($sql)) {
 140              return false;
 141          }
 142          return true;
 143      }
 144  
 145      function getObjects($criteria = null, $id_as_key = false)
 146      {
 147          $ret = array();
 148          $limit = $start = 0;
 149          $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')";
 150          if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
 151              $where = $criteria->render();
 152              $sql .= ($where != '') ? ' AND '.$where : '';
 153              $limit = $criteria->getLimit();
 154              $start = $criteria->getStart();
 155          }
 156          $sql .= ' ORDER BY imgcat_weight, imgcat_id ASC';
 157          $result = $this->db->query($sql, $limit, $start);
 158          if (!$result) {
 159              return $ret;
 160          }
 161          while ($myrow = $this->db->fetchArray($result)) {
 162              $imgcat = new XoopsImagecategory();
 163              $imgcat->assignVars($myrow);
 164              if (!$id_as_key) {
 165                  $ret[] =& $imgcat;
 166              } else {
 167                  $ret[$myrow['imgcat_id']] =& $imgcat;
 168              }
 169              unset($imgcat);
 170          }
 171          return $ret;
 172      }
 173  
 174  
 175      function getCount($criteria = null)
 176      {
 177          $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')";
 178          if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
 179              $where = $criteria->render();
 180              $sql .= ($where != '') ? ' AND '.$where : '';
 181          }
 182          if (!$result =& $this->db->query($sql)) {
 183              return 0;
 184          }
 185          list($count) = $this->db->fetchRow($result);
 186          return $count;
 187      }
 188  
 189      function getList($groups = array(), $perm = 'imgcat_read', $display = null, $storetype = null)
 190      {
 191          $criteria = new CriteriaCompo();
 192          if (is_array($groups) && !empty($groups)) {
 193              $criteriaTray = new CriteriaCompo();
 194              foreach ($groups as $gid) {
 195                  $criteriaTray->add(new Criteria('gperm_groupid', $gid), 'OR');
 196              }
 197              $criteria->add($criteriaTray);
 198              if ($perm == 'imgcat_read' || $perm == 'imgcat_write') {
 199                  $criteria->add(new Criteria('gperm_name', $perm));
 200                  $criteria->add(new Criteria('gperm_modid', 1));
 201              }
 202          }
 203          if (isset($display)) {
 204              $criteria->add(new Criteria('imgcat_display', intval($display)));
 205          }
 206          if (isset($storetype)) {
 207              $criteria->add(new Criteria('imgcat_storetype', $storetype));
 208          }
 209          $categories =& $this->getObjects($criteria, true);
 210          $ret = array();
 211          foreach (array_keys($categories) as $i) {
 212                  $ret[$i] = $categories[$i]->getVar('imgcat_name');
 213          }
 214          return $ret;
 215      }
 216  }
 217  ?>


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