[ Index ] |
|
Code source de XOOPS 2.0.17.1 |
1 <?php 2 // $Id: avatar.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 XoopsAvatar extends XoopsObject 37 { 38 var $_userCount; 39 40 function XoopsAvatar() 41 { 42 $this->XoopsObject(); 43 $this->initVar('avatar_id', XOBJ_DTYPE_INT, null, false); 44 $this->initVar('avatar_file', XOBJ_DTYPE_OTHER, null, false, 30); 45 $this->initVar('avatar_name', XOBJ_DTYPE_TXTBOX, null, true, 100); 46 $this->initVar('avatar_mimetype', XOBJ_DTYPE_OTHER, null, false); 47 $this->initVar('avatar_created', XOBJ_DTYPE_INT, null, false); 48 $this->initVar('avatar_display', XOBJ_DTYPE_INT, 1, false); 49 $this->initVar('avatar_weight', XOBJ_DTYPE_INT, 0, false); 50 $this->initVar('avatar_type', XOBJ_DTYPE_OTHER, 0, false); 51 } 52 53 function setUserCount($value) 54 { 55 $this->_userCount = intval($value); 56 } 57 58 function getUserCount() 59 { 60 return $this->_userCount; 61 } 62 } 63 64 65 /** 66 * XOOPS avatar handler class. 67 * This class is responsible for providing data access mechanisms to the data source 68 * of XOOPS avatar class objects. 69 * 70 * 71 * @author Kazumi Ono <onokazu@xoops.org> 72 */ 73 74 class XoopsAvatarHandler extends XoopsObjectHandler 75 { 76 77 function &create($isNew = true) 78 { 79 $avatar = new XoopsAvatar(); 80 if ($isNew) { 81 $avatar->setNew(); 82 } 83 return $avatar; 84 } 85 86 function &get($id) 87 { 88 $avatar = false; 89 $id = intval($id); 90 if ($id > 0) { 91 $sql = 'SELECT * FROM '.$this->db->prefix('avatar').' WHERE avatar_id='.$id; 92 if (!$result = $this->db->query($sql)) { 93 return false; 94 } 95 $numrows = $this->db->getRowsNum($result); 96 if ($numrows == 1) { 97 $avatar = new XoopsAvatar(); 98 $avatar->assignVars($this->db->fetchArray($result)); 99 return $avatar; 100 } 101 } 102 return $avatar; 103 } 104 105 function insert(&$avatar) 106 { 107 if (strtolower(get_class($avatar)) != 'xoopsavatar') { 108 return false; 109 } 110 if (!$avatar->isDirty()) { 111 return true; 112 } 113 if (!$avatar->cleanVars()) { 114 return false; 115 } 116 foreach ($avatar->cleanVars as $k => $v) { 117 ${$k} = $v; 118 } 119 if ($avatar->isNew()) { 120 $avatar_id = $this->db->genId('avatar_avatar_id_seq'); 121 $sql = sprintf("INSERT INTO %s (avatar_id, avatar_file, avatar_name, avatar_created, avatar_mimetype, avatar_display, avatar_weight, avatar_type) VALUES (%u, %s, %s, %u, %s, %u, %u, %s)", $this->db->prefix('avatar'), $avatar_id, $this->db->quoteString($avatar_file), $this->db->quoteString($avatar_name), time(), $this->db->quoteString($avatar_mimetype), $avatar_display, $avatar_weight, $this->db->quoteString($avatar_type)); 122 } else { 123 $sql = sprintf("UPDATE %s SET avatar_file = %s, avatar_name = %s, avatar_created = %u, avatar_mimetype= %s, avatar_display = %u, avatar_weight = %u, avatar_type = %s WHERE avatar_id = %u", $this->db->prefix('avatar'), $this->db->quoteString($avatar_file), $this->db->quoteString($avatar_name), $avatar_created, $this->db->quoteString($avatar_mimetype), $avatar_display, $avatar_weight, $this->db->quoteString($avatar_type), $avatar_id); 124 } 125 if (!$result = $this->db->query($sql)) { 126 return false; 127 } 128 if (empty($avatar_id)) { 129 $avatar_id = $this->db->getInsertId(); 130 } 131 $avatar->assignVar('avatar_id', $avatar_id); 132 return true; 133 } 134 135 function delete(&$avatar) 136 { 137 if (strtolower(get_class($avatar)) != 'xoopsavatar') { 138 return false; 139 } 140 $id = $avatar->getVar('avatar_id'); 141 $sql = sprintf("DELETE FROM %s WHERE avatar_id = %u", $this->db->prefix('avatar'), $id); 142 if (!$result = $this->db->query($sql)) { 143 return false; 144 } 145 $sql = sprintf("DELETE FROM %s WHERE avatar_id = %u", $this->db->prefix('avatar_user_link'), $id); 146 $result = $this->db->query($sql); 147 return true; 148 } 149 150 function &getObjects($criteria = null, $id_as_key = false) 151 { 152 $ret = array(); 153 $limit = $start = 0; 154 $sql = 'SELECT a.*, COUNT(u.user_id) AS count FROM '.$this->db->prefix('avatar').' a LEFT JOIN '.$this->db->prefix('avatar_user_link').' u ON u.avatar_id=a.avatar_id'; 155 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 156 $sql .= ' '.$criteria->renderWhere(); 157 $sql .= ' GROUP BY a.avatar_id ORDER BY avatar_weight, avatar_id'; 158 $limit = $criteria->getLimit(); 159 $start = $criteria->getStart(); 160 } 161 $result = $this->db->query($sql, $limit, $start); 162 if (!$result) { 163 return $ret; 164 } 165 while ($myrow = $this->db->fetchArray($result)) { 166 $avatar = new XoopsAvatar(); 167 $avatar->assignVars($myrow); 168 $avatar->setUserCount($myrow['count']); 169 if (!$id_as_key) { 170 $ret[] =& $avatar; 171 } else { 172 $ret[$myrow['avatar_id']] =& $avatar; 173 } 174 unset($avatar); 175 } 176 return $ret; 177 } 178 179 function getCount($criteria = null) 180 { 181 $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('avatar'); 182 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 183 $sql .= ' '.$criteria->renderWhere(); 184 } 185 if (!$result =& $this->db->query($sql)) { 186 return 0; 187 } 188 list($count) = $this->db->fetchRow($result); 189 return $count; 190 } 191 192 function addUser($avatar_id, $user_id){ 193 $avatar_id = intval($avatar_id); 194 $user_id = intval($user_id); 195 if ($avatar_id < 1 || $user_id < 1) { 196 return false; 197 } 198 $sql = sprintf("DELETE FROM %s WHERE user_id = %u", $this->db->prefix('avatar_user_link'), $user_id); 199 $this->db->query($sql); 200 $sql = sprintf("INSERT INTO %s (avatar_id, user_id) VALUES (%u, %u)", $this->db->prefix('avatar_user_link'), $avatar_id, $user_id); 201 if (!$result =& $this->db->query($sql)) { 202 return false; 203 } 204 return true; 205 } 206 207 function getUser(&$avatar){ 208 $ret = array(); 209 if (strtolower(get_class($avatar)) != 'xoopsavatar') { 210 return $ret; 211 } 212 $sql = 'SELECT user_id FROM '.$this->db->prefix('avatar_user_link').' WHERE avatar_id='.$avatar->getVar('avatar_id'); 213 if (!$result = $this->db->query($sql)) { 214 return $ret; 215 } 216 while ($myrow = $this->db->fetchArray($result)) { 217 $ret[] =& $myrow['user_id']; 218 } 219 return $ret; 220 } 221 222 function getList($avatar_type = null, $avatar_display = null) 223 { 224 $criteria = new CriteriaCompo(); 225 if (isset($avatar_type)) { 226 $avatar_type = ($avatar_type == 'C') ? 'C' : 'S'; 227 $criteria->add(new Criteria('avatar_type', $avatar_type)); 228 } 229 if (isset($avatar_display)) { 230 $criteria->add(new Criteria('avatar_display', intval($avatar_display))); 231 } 232 $avatars =& $this->getObjects($criteria, true); 233 $ret = array('blank.gif' => _NONE); 234 foreach (array_keys($avatars) as $i) { 235 $ret[$avatars[$i]->getVar('avatar_file')] = $avatars[$i]->getVar('avatar_name'); 236 } 237 return $ret; 238 } 239 } 240 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Nov 25 11:44:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |