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 / imageset.php < prev    next >
Encoding:
PHP Script  |  2007-10-19  |  8.3 KB  |  216 lines

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