ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
34include_once './webservice/soap/classes/class.ilXMLResultSetColumn.php';
35include_once './webservice/soap/classes/class.ilXMLResultSetRow.php';
36
38{
39 private $colspecs = array();
40 private $rows = array();
41
42
43 function ilXMLResultSet ()
44 {
45 }
46
47 function getColumnName ($index) {
48 if (is_numeric($index) && ($index < 0 || $index > count($this->colspecs)))
49 {
50 return null;
51 }
52 return $this->colspecs[$index] instanceof ilXMLResultSetColumn ? $this->colspecs[$index]->getName() : null;
53 }
54
60 function addColumn($columnname)
61 {
62 $this->colspecs [count($this->colspecs)] = new ilXMLResultSetColumn (count($this->colspecs), $columnname);
63 }
64
71 function getIndexForColumn ($columnname) {
72 $idx = 0;
73 foreach ($this->colspecs as $colspec) {
74 if (strcasecmp($columnname, $colspec->getName()) == 0)
75 return $idx;
76 $idx++;
77 }
78 return -1;
79 }
80
81
88 function hasColumn ($columnname) {
89 return $this->getIndexForColumn($columnname) != -1;
90 }
91
97 function getColSpecs ()
98 {
99 return $this->colspecs;
100 }
101
107 function getRows ()
108 {
109 return $this->rows;
110 }
111
117 function addRow (&$row)
118 {
119 $this->rows [] = $row;
120 }
121
122
133 function setArray ($array)
134 {
135 $this->addArray($array, true);
136 }
137
149 function addArray ($array, $overwrite = false) {
150 if ($overwrite) {
151 $this->clear();
152 }
153 foreach ($array as $row) {
154 if ($overwrite)
155 {
156 // add column names from first row
157 $columnNames = array_keys($row);
158 foreach ($columnNames as $columnName)
159 {
160 $this->addColumn($columnName);
161 }
162 $overwrite = false;
163 }
164 $xmlRow = new ilXMLResultSetRow();
165 $xmlRow->setValues ($row);
166 $this->addRow($xmlRow);
167 }
168 }
169
174 function clear () {
175 $this->rows = array();
176 $this->colspecs = array();
177 }
178
184 function getColumnCount () {
185 return count($this->colspecs);
186 }
187
193 function getRowCount () {
194 return count($this->rows);
195 }
196
202 function getRow ($idx) {
203 if ($idx < 0 || $idx >= $this->getRowCount())
204 throw new Exception ("Index too small or too big!");
205 return $this->rows[$idx];
206 }
207
215 function getValue ($rowIdx, $colIdx) {
216 $row = $this->getRow($rowIdx);
217
218 if (!is_numeric($colIdx))
219 $colIdx = $this->getIndexForColumn($colIdx);
220
221 return $row->getValue ($colIdx);
222 }
223}
224?>
hasColumn($columnname)
has column name
addRow(&$row)
add row object
getValue($rowIdx, $colIdx)
return column value at colidx and rowidx
getRowCount()
return row count
clear()
Clear resultset (colspecs and row values)
getRow($idx)
return row for index idx
getColumnCount()
return column count
getRows()
return array of ilXMLResultSetRow
setArray($array)
Clear table value and sets them based on array.
addColumn($columnname)
create a new column with columnname and attach it to column list
addArray($array, $overwrite=false)
Add table values.
getColSpecs()
return array of ilXMLResultSetColumn
getIndexForColumn($columnname)
return index for column name