[ Index ] |
|
Code source de Dotclear 1.2.5 |
1 <?php 2 # ***** BEGIN LICENSE BLOCK ***** 3 # This file is part of DotClear. 4 # Copyright (c) 2004 Olivier Meunier and contributors. All rights 5 # reserved. 6 # 7 # DotClear is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # DotClear is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with DotClear; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 # 21 # ***** END LICENSE BLOCK ***** 22 23 /** 24 @class recordset 25 26 Cette classe permet de manipuler des données entrées dans un tableaux multilignes 27 et multicolonnes. La classe ''connection'' renvoie des recordsets comme résultat 28 de requêtes. 29 30 @param array arry_data Tableau contenant les données 31 @param integer int_index Emplacement du curseur 32 @param integer int_row_count Nombre d'enregistrements 33 @param integer int_col_count Nombre de colonnes 34 @param integer fetch_index Indice de déplacement utilisé localement 35 */ 36 37 class recordset 38 { 39 var $arry_data; 40 var $int_index; 41 42 var $int_row_count; 43 var $int_col_count; 44 var $fetch_index; 45 46 /** @doc 47 === Méthodes === */ 48 49 /** 50 @function recordset 51 52 '''Constructeur'''. Cette méthode initialise le recordset. $data est un 53 tableau de plusieurs lignes et colones. 54 55 Par exemple : 56 57 {{{ 58 #!php 59 <?php 60 $d = array( 61 array('f1' => 'v01', 'f2' => 'v02'), 62 array('f1' => 'v11', 'f2' => 'v12'), 63 array('f1' => 'v21', 'f2' => 'v22') 64 ); 65 $rs = new recordset($d); 66 67 while ($rs->fetch()) { 68 echo $rs->f('f1').' - '.$rs->f('f2').'<br />'; 69 } 70 ?> 71 }}} 72 73 74 @param array data Tableau contenant les données 75 */ 76 function recordset($data) 77 { 78 $this->int_index = 0; 79 $this->fetch_index = NULL; 80 81 if(is_array($data)) 82 { 83 $this->arry_data = $data; 84 85 $this->int_row_count = count($this->arry_data); 86 87 if ($this->int_row_count == 0) 88 { 89 $this->int_col_count = 0; 90 } 91 else 92 { 93 $this->int_col_count = count($this->arry_data[0]); 94 } 95 } 96 } 97 98 /** 99 @function field 100 101 Renvoie la valeur d'un champ donné, pour la ligne courante. 102 103 @param mixed c Nom ou numéro du champ 104 @return string 105 */ 106 function field($c) 107 { 108 if(!empty($this->arry_data)) 109 { 110 if(is_integer($c)) 111 { 112 $T = array_values($this->arry_data[$this->int_index]); 113 return (isset($T[($c)])) ? $T[($c)] : false; 114 } 115 else 116 { 117 $c = strtolower($c); 118 if(isset($this->arry_data[$this->int_index][$c])) 119 { 120 if (!is_array($this->arry_data[$this->int_index][$c])) { 121 return trim($this->arry_data[$this->int_index][$c]); 122 } else { 123 return $this->arry_data[$this->int_index][$c]; 124 } 125 } 126 else 127 { 128 return false; 129 } 130 } 131 } 132 } 133 134 /** 135 @function f 136 137 Alias de la méthode ''field''. 138 139 @param mixed c Nom ou numéro du champ 140 @return string 141 */ 142 function f($c) 143 { 144 return $this->field($c); 145 } 146 147 /** 148 @function setField 149 150 Change la valeur d'un champ donné à la ligne courante. 151 152 @param string c Nom du champ 153 @param string v Valeur du champ 154 */ 155 function setField($c,$v) 156 { 157 $c = strtolower($c); 158 $this->arry_data[$this->int_index][$c] = $v; 159 } 160 161 /** 162 @function moveStart 163 164 Remet le curseur à la première ligne des données et renvoie vrai. 165 166 @return boolean 167 */ 168 function moveStart() 169 { 170 $this->int_index = 0; 171 return true; 172 } 173 174 /** 175 @function moveEnd 176 177 Positionne le curseur à la dernière ligne des données et renvoie vrai. 178 179 @return boolean 180 */ 181 function moveEnd() 182 { 183 $this->int_index = ($this->int_row_count-1); 184 return true; 185 } 186 187 /** 188 @function moveNext 189 190 Déplace le curseur d'un cran si possible et renvoie vrai. Si le curseur 191 est à la fin du tableau, renvoie false. 192 193 @return boolean 194 */ 195 function moveNext() 196 { 197 if (!empty($this->arry_data) && !$this->EOF()) { 198 $this->int_index++; 199 return true; 200 } else { 201 return false; 202 } 203 } 204 205 /** 206 @function movePrev 207 208 Déplace le curseur d'un cran dans le sens inverse si possible et renvoie 209 vrai. Si le curseur est au début du tableau, renvoie false. 210 211 @return boolean 212 */ 213 function movePrev() 214 { 215 if (!empty($this->arry_data) && $this->int_index > 0) { 216 $this->int_index--; 217 return true; 218 } else { 219 return false; 220 } 221 } 222 223 /** 224 @function move 225 226 Positionne le curseur à l'indice donné par $index. Si l'indice n'existe 227 pas, renvoie false. 228 229 @param integer index Indice 230 @return boolean 231 */ 232 function move($index) 233 { 234 if (!empty($this->arry_data) && $this->int_index >= 0 && $index < $this->int_row_count) { 235 $this->int_index = $index; 236 return true; 237 } else { 238 return false; 239 } 240 } 241 242 /** 243 @function fetch 244 245 Déplace le cuseur d'un cran et renvoie vrai tant que celui ci n'est pas 246 positionné à la fin du tableau. La fonction démarre toujours du premier 247 élément du tableau. Elle a pour vocation à être utilisée dans une boucle 248 de type while (voir le premier exemple). 249 250 @return boolean 251 */ 252 function fetch() 253 { 254 if ($this->fetch_index === NULL) { 255 $this->fetch_index = 0; 256 $this->int_index = -1; 257 } 258 259 if ($this->fetch_index+1 > $this->int_row_count) { 260 $this->fetch_index = NULL; 261 $this->int_index = 0; 262 return false; 263 } 264 265 $this->fetch_index++; 266 $this->int_index++; 267 268 return true; 269 } 270 271 /** 272 @function BOF 273 274 Indique si le curseur est au début du tableau. 275 276 @return boolean 277 */ 278 function BOF() 279 { 280 return ($this->int_index == -1 || $this->int_row_count == 0); 281 } 282 283 /** 284 @function EOF 285 286 Indique si le curseur est à la fin du tableau. 287 288 @return boolean 289 */ 290 function EOF() 291 { 292 return ($this->int_index == $this->int_row_count); 293 } 294 295 /** 296 @function isEmpty 297 298 Indique si le tableau de données est vide. 299 300 @return boolean 301 */ 302 function isEmpty() 303 { 304 return ($this->int_row_count == 0); 305 } 306 307 /** 308 @function getData 309 310 Renvoie le tableau de données. 311 312 @return array 313 */ 314 function getData() 315 { 316 return $this->arry_data; 317 } 318 319 /** 320 @function nbRow 321 322 Renvoie le nombre de lignes du tableau. 323 324 @return integer 325 */ 326 function nbRow() 327 { 328 return $this->int_row_count; 329 } 330 } 331 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Feb 23 21:40:15 2007 | par Balluche grâce à PHPXref 0.7 |