ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilXMLResultSet.php
Go to the documentation of this file.
1 <?php
2  /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22  */
23 
24 
34 include_once './webservice/soap/classes/class.ilXMLResultSetColumn.php';
35 include_once './webservice/soap/classes/class.ilXMLResultSetRow.php';
36 
38 {
39  private $colspecs = array();
40  private $rows = array();
41 
42  function getColumnName ($index) {
43  if (is_numeric($index) && ($index < 0 || $index > count($this->colspecs)))
44  {
45  return null;
46  }
47  return $this->colspecs[$index] instanceof ilXMLResultSetColumn ? $this->colspecs[$index]->getName() : null;
48  }
49 
55  function addColumn($columnname)
56  {
57  $this->colspecs [count($this->colspecs)] = new ilXMLResultSetColumn (count($this->colspecs), $columnname);
58  }
59 
66  function getIndexForColumn ($columnname) {
67  $idx = 0;
68  foreach ($this->colspecs as $colspec) {
69  if (strcasecmp($columnname, $colspec->getName()) == 0)
70  return $idx;
71  $idx++;
72  }
73  return -1;
74  }
75 
76 
83  function hasColumn ($columnname) {
84  return $this->getIndexForColumn($columnname) != -1;
85  }
86 
92  function getColSpecs ()
93  {
94  return $this->colspecs;
95  }
96 
102  function getRows ()
103  {
104  return $this->rows;
105  }
106 
112  function addRow (&$row)
113  {
114  $this->rows [] = $row;
115  }
116 
117 
128  function setArray ($array)
129  {
130  $this->addArray($array, true);
131  }
132 
144  function addArray ($array, $overwrite = false) {
145  if ($overwrite) {
146  $this->clear();
147  }
148  foreach ($array as $row) {
149  if ($overwrite)
150  {
151  // add column names from first row
152  $columnNames = array_keys($row);
153  foreach ($columnNames as $columnName)
154  {
155  $this->addColumn($columnName);
156  }
157  $overwrite = false;
158  }
159  $xmlRow = new ilXMLResultSetRow();
160  $xmlRow->setValues ($row);
161  $this->addRow($xmlRow);
162  }
163  }
164 
169  function clear () {
170  $this->rows = array();
171  $this->colspecs = array();
172  }
173 
179  function getColumnCount () {
180  return count($this->colspecs);
181  }
182 
188  function getRowCount () {
189  return count($this->rows);
190  }
191 
197  function getRow ($idx) {
198  if ($idx < 0 || $idx >= $this->getRowCount())
199  throw new Exception ("Index too small or too big!");
200  return $this->rows[$idx];
201  }
202 
210  function getValue ($rowIdx, $colIdx) {
211  $row = $this->getRow($rowIdx);
212 
213  if (!is_numeric($colIdx))
214  $colIdx = $this->getIndexForColumn($colIdx);
215 
216  return $row->getValue ($colIdx);
217  }
218 }
219 ?>
addRow(&$row)
add row object
setArray($array)
Clear table value and sets them based on array.
getValue($rowIdx, $colIdx)
return column value at colidx and rowidx
clear()
Clear resultset (colspecs and row values)
getColumnCount()
return column count
getColSpecs()
return array of ilXMLResultSetColumn
addArray($array, $overwrite=false)
Add table values.
getRow($idx)
return row for index idx
hasColumn($columnname)
has column name
Create styles array
The data for the language used.
Remove unnecessary rows
getRowCount()
return row count
addColumn($columnname)
create a new column with columnname and attach it to column list
getIndexForColumn($columnname)
return index for column name
getRows()
return array of ilXMLResultSetRow