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 / imagesetimg.php < prev    next >
Encoding:
PHP Script  |  2007-10-19  |  8.4 KB  |  207 lines

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