| 1 | <?php |
|---|
| 2 | // $Id: imagesetimg.php,v 1.3 2006/05/01 02:37:28 onokazu Exp $ |
|---|
| 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 <[email protected]> |
|---|
| 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 | $ret = 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 | $numrows = $this->db->getRowsNum($result); |
|---|
| 77 | if ($numrows == 1) { |
|---|
| 78 | $imgsetimg =& new XoopsImagesetimg(); |
|---|
| 79 | $imgsetimg->assignVars($this->db->fetchArray($result)); |
|---|
| 80 | $ret =& $imgsetimg; |
|---|
| 81 | } |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | return $ret; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | function insert(&$imgsetimg) |
|---|
| 88 | { |
|---|
| 89 | if (strtolower(get_class($imgsetimg)) != 'xoopsimagesetimg') { |
|---|
| 90 | return false; |
|---|
| 91 | } |
|---|
| 92 | if (!$imgsetimg->isDirty()) { |
|---|
| 93 | return true; |
|---|
| 94 | } |
|---|
| 95 | if (!$imgsetimg->cleanVars()) { |
|---|
| 96 | return false; |
|---|
| 97 | } |
|---|
| 98 | foreach ($imgsetimg->cleanVars as $k => $v) { |
|---|
| 99 | ${$k} = $v; |
|---|
| 100 | } |
|---|
| 101 | if ($imgsetimg->isNew()) { |
|---|
| 102 | $imgsetimg_id = $this->db->genId('imgsetimg_imgsetimg_id_seq'); |
|---|
| 103 | $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)); |
|---|
| 104 | } else { |
|---|
| 105 | $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); |
|---|
| 106 | } |
|---|
| 107 | if (!$result = $this->db->query($sql)) { |
|---|
| 108 | return false; |
|---|
| 109 | } |
|---|
| 110 | if (empty($imgsetimg_id)) { |
|---|
| 111 | $imgsetimg_id = $this->db->getInsertId(); |
|---|
| 112 | } |
|---|
| 113 | $imgsetimg->assignVar('imgsetimg_id', $imgsetimg_id); |
|---|
| 114 | return true; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | function delete(&$imgsetimg) |
|---|
| 118 | { |
|---|
| 119 | if (strtolower(get_class($imgsetimg)) != 'xoopsimagesetimg') { |
|---|
| 120 | return false; |
|---|
| 121 | } |
|---|
| 122 | $sql = sprintf("DELETE FROM %s WHERE imgsetimg_id = %u", $this->db->prefix('imgsetimg'), $imgsetimg->getVar('imgsetimg_id')); |
|---|
| 123 | if (!$result = $this->db->query($sql)) { |
|---|
| 124 | return false; |
|---|
| 125 | } |
|---|
| 126 | return true; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | function &getObjects($criteria = null, $id_as_key = false) |
|---|
| 130 | { |
|---|
| 131 | $ret = array(); |
|---|
| 132 | $limit = $start = 0; |
|---|
| 133 | $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'; |
|---|
| 134 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|---|
| 135 | $sql .= ' '.$criteria->renderWhere(); |
|---|
| 136 | $sql .= ' ORDER BY imgsetimg_id '.$criteria->getOrder(); |
|---|
| 137 | $limit = $criteria->getLimit(); |
|---|
| 138 | $start = $criteria->getStart(); |
|---|
| 139 | } |
|---|
| 140 | $result = $this->db->query($sql, $limit, $start); |
|---|
| 141 | if (!$result) { |
|---|
| 142 | return $ret; |
|---|
| 143 | } |
|---|
| 144 | while ($myrow = $this->db->fetchArray($result)) { |
|---|
| 145 | $imgsetimg =& new XoopsImagesetimg(); |
|---|
| 146 | $imgsetimg->assignVars($myrow); |
|---|
| 147 | if (!$id_as_key) { |
|---|
| 148 | $ret[] =& $imgsetimg; |
|---|
| 149 | } else { |
|---|
| 150 | $ret[$myrow['imgsetimg_id']] =& $imgsetimg; |
|---|
| 151 | } |
|---|
| 152 | unset($imgsetimg); |
|---|
| 153 | } |
|---|
| 154 | return $ret; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | function getCount($criteria = null) |
|---|
| 158 | { |
|---|
| 159 | $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'; |
|---|
| 160 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|---|
| 161 | $sql .= ' '.$criteria->renderWhere().' GROUP BY i.imgsetimg_id'; |
|---|
| 162 | } |
|---|
| 163 | if (!$result =& $this->db->query($sql)) { |
|---|
| 164 | return 0; |
|---|
| 165 | } |
|---|
| 166 | list($count) = $this->db->fetchRow($result); |
|---|
| 167 | return $count; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | /** |
|---|
| 171 | * Function-Documentation |
|---|
| 172 | * @param type $imgset_id documentation |
|---|
| 173 | * @param type $id_as_key = false documentation |
|---|
| 174 | * @return type documentation |
|---|
| 175 | * @author Kazumi Ono <[email protected]> |
|---|
| 176 | **/ |
|---|
| 177 | function &getByImageset($imgset_id, $id_as_key = false) |
|---|
| 178 | { |
|---|
| 179 | $ret =& $this->getObjects(new Criteria('imgsetimg_imgset', intval($imgset_id)), $id_as_key); |
|---|
| 180 | return $ret; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | /** |
|---|
| 184 | * Function-Documentation |
|---|
| 185 | * @param type $filename documentation |
|---|
| 186 | * @param type $imgset_id documentation |
|---|
| 187 | * @return type documentation |
|---|
| 188 | * @author Kazumi Ono <[email protected]> |
|---|
| 189 | **/ |
|---|
| 190 | function imageExists($filename, $imgset_id) |
|---|
| 191 | { |
|---|
| 192 | $criteria = new CriteriaCompo(new Criteria('imgsetimg_file', $filename)); |
|---|
| 193 | $criteria->add(new Criteria('imgsetimg_imgset', intval($imgset_id))); |
|---|
| 194 | if ($this->getCount($criteria) > 0) { |
|---|
| 195 | return true; |
|---|
| 196 | } |
|---|
| 197 | return false; |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | ?> |
|---|