[ Index ]
 

Code source de Plume CMS 1.2.2

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/manager/extinc/ -> class.recordset.php (source)

   1  <?php
   2  /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
   3  /*
   4  # ***** BEGIN LICENSE BLOCK *****
   5  # Version: MPL 1.1/GPL 2.0/LGPL 2.1
   6  #
   7  # The contents of this file are subject to the Mozilla Public License Version
   8  # 1.1 (the "License"); you may not use this file except in compliance with
   9  # the License. You may obtain a copy of the License at
  10  # http://www.mozilla.org/MPL/
  11  #
  12  # Software distributed under the License is distributed on an "AS IS" basis,
  13  # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14  # for the specific language governing rights and limitations under the
  15  # License.
  16  #
  17  # The Original Code is DotClear Weblog.
  18  #
  19  # The Initial Developer of the Original Code is
  20  # Olivier Meunier.
  21  # Portions created by the Initial Developer are Copyright (C) 2003
  22  # the Initial Developer. All Rights Reserved.
  23  #
  24  # Contributor(s):
  25  #    Loïc d'Anterroches
  26  #
  27  # Alternatively, the contents of this file may be used under the terms of
  28  # either the GNU General Public License Version 2 or later (the "GPL"), or
  29  # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  30  # in which case the provisions of the GPL or the LGPL are applicable instead
  31  # of those above. If you wish to allow use of your version of this file only
  32  # under the terms of either the GPL or the LGPL, and not to allow others to
  33  # use your version of this file under the terms of the MPL, indicate your
  34  # decision by deleting the provisions above and replace them with the notice
  35  # and other provisions required by the GPL or the LGPL. If you do not delete
  36  # the provisions above, a recipient may use your version of this file under
  37  # the terms of any one of the MPL, the GPL or the LGPL.
  38  #
  39  # ***** END LICENSE BLOCK ***** */
  40  
  41  require_once dirname(__FILE__).'/../inc/class.l10n.php';
  42  
  43  class recordset extends CError
  44  {
  45      var $arry_data=array(); // tableau contenant les données
  46      var $int_index; //index pour parcourir les enregistrements
  47      // les enregistrements commencent à l'index 0
  48          
  49      var $int_row_count=0; // nombre d'enregistrements
  50      var $int_col_count=0; // nombre de colonnes
  51      var $int_row_count_total=0; // Nombre d'enregistrements a l'initialisation
  52          
  53      function recordset($data='')
  54      {
  55          $this->int_index = 0;
  56      
  57          if (is_array($data)) {
  58              $this->arry_data = $data;
  59              $this->int_row_count = count($this->arry_data);
  60              $this->int_row_count_total = $this->int_row_count;
  61          
  62              if ($this->int_row_count == 0) {
  63                  $this->int_col_count = 0;
  64              } else {
  65                  $this->int_col_count = count($this->arry_data[0]);
  66              }
  67          }
  68      }
  69      
  70      function f($c)
  71      {
  72          if (!empty($this->arry_data)) {
  73              if (is_integer($c)) {
  74                  $T = array_values($this->arry_data[$this->int_index]);
  75                  return (isset($T[($c)])) ? $T[($c)] : false;
  76              } else {
  77                  $c = strtolower($c);
  78                  if (isset($this->arry_data[$this->int_index][$c])) {
  79                      if (!is_array($this->arry_data[$this->int_index][$c])) {
  80                          return trim($this->arry_data[$this->int_index][$c]);
  81                      } else {
  82                          return $this->arry_data[$this->int_index][$c];
  83                      }
  84                  } else {
  85                      return false;
  86                  }
  87              }
  88          }
  89      }
  90  
  91      /**
  92       * Insert a new record at the end.
  93       * Set the cursor at the newly created position.
  94       *
  95       * @return int New index
  96       */
  97      function insert()
  98      {
  99          $this->arry_data[$this->int_row_count] = array();
 100          $this->int_row_count += 1; 
 101          $this->moveEnd();
 102          return ($this->int_row_count-1);
 103      }
 104  
 105  
 106      function field($c)
 107      {
 108          return $this->f($c);
 109      }
 110          
 111      function setField($c,$v)
 112      {
 113          $c = strtolower($c);
 114          $this->arry_data[$this->int_index][$c] = $v;
 115      }
 116          
 117      function moveStart()
 118      {
 119          $this->int_index = 0;
 120          return true;
 121      }
 122          
 123      function moveEnd()
 124      {
 125          $this->int_index = ($this->int_row_count-1);
 126          return true;
 127      }
 128      
 129      function moveNext()
 130      {
 131          if (!empty($this->arry_data) && !$this->EOF()) {
 132              $this->int_index++;
 133              return true;
 134          } else {
 135              return false;
 136          }
 137      }
 138          
 139      function movePrev()
 140      {
 141          if (!empty($this->arry_data) && $this->int_index > 0) {
 142              $this->int_index--;
 143              return true;
 144          } else {
 145              return false;
 146          }
 147      }
 148          
 149      function move($index)
 150      {
 151          if (!empty($this->arry_data) 
 152              && $this->int_index >= 0 
 153              && $index < $this->int_row_count) {
 154              $this->int_index = $index;
 155              return true;
 156          } else {
 157              return false;
 158          }
 159      }
 160          
 161      function BOF()
 162      {
 163          return ($this->int_index == -1 || $this->int_row_count == 0);
 164      }
 165          
 166      function EOF()
 167      {
 168          return ($this->int_index == $this->int_row_count);
 169      }
 170          
 171      function isEmpty()
 172      {
 173          return ($this->int_row_count == 0);
 174      }
 175          
 176      // Donner le tableau de données
 177      function getData()
 178      {
 179          return $this->arry_data;
 180      }
 181  
 182      /**
 183       * Get the current row of data.
 184       */
 185      function getRow()
 186      {
 187          if (!$this->BOF() && !$this->EOF()) {
 188              return $this->arry_data[$this->int_index];
 189          }
 190          return false;
 191      }
 192  
 193      // Nombre de lignes
 194      function nbRow()
 195      {
 196          return $this->int_row_count;
 197      }
 198      
 199      // Nombre de lignes a l'initialisation
 200      function nbRowTotal()
 201      {
 202          return $this->int_row_count_total;
 203      }    
 204      
 205  
 206      /**
 207       * Get ids of resources with a prefix or not.
 208       *
 209       * @return array ids
 210       * @param  string key for ids
 211       * @param  string prefix for ids ('')
 212       */
 213      function getIDs($key, $str='')
 214      {
 215          $res = array();
 216          foreach ($this->arry_data as $k => $v) {
 217              $res[] = $str.$v[$key];
 218          }
 219          return $res;
 220      }
 221  
 222      
 223      function getIndex()
 224      {
 225          return $this->int_index;                 
 226      }
 227  }
 228  ?>


Généré le : Mon Nov 26 11:57:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics