ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public function getColumnName($index)
43  {
44  if (is_numeric($index) && ($index < 0 || $index > count($this->colspecs))) {
45  return null;
46  }
47  return $this->colspecs[$index] instanceof ilXMLResultSetColumn ? $this->colspecs[$index]->getName() : null;
48  }
49 
55  public function addColumn($columnname)
56  {
57  $this->colspecs [count($this->colspecs)] = new ilXMLResultSetColumn(count($this->colspecs), $columnname);
58  }
59 
66  public function getIndexForColumn($columnname)
67  {
68  $idx = 0;
69  foreach ($this->colspecs as $colspec) {
70  if (strcasecmp($columnname, $colspec->getName()) == 0) {
71  return $idx;
72  }
73  $idx++;
74  }
75  return -1;
76  }
77 
78 
85  public function hasColumn($columnname)
86  {
87  return $this->getIndexForColumn($columnname) != -1;
88  }
89 
95  public function getColSpecs()
96  {
97  return $this->colspecs;
98  }
99 
105  public function getRows()
106  {
107  return $this->rows;
108  }
109 
115  public function addRow(&$row)
116  {
117  $this->rows [] = $row;
118  }
119 
120 
131  public function setArray($array)
132  {
133  $this->addArray($array, true);
134  }
135 
147  public function addArray($array, $overwrite = false)
148  {
149  if ($overwrite) {
150  $this->clear();
151  }
152  foreach ($array as $row) {
153  if ($overwrite) {
154  // add column names from first row
155  $columnNames = array_keys($row);
156  foreach ($columnNames as $columnName) {
157  $this->addColumn($columnName);
158  }
159  $overwrite = false;
160  }
161  $xmlRow = new ilXMLResultSetRow();
162  $xmlRow->setValues($row);
163  $this->addRow($xmlRow);
164  }
165  }
166 
171  public function clear()
172  {
173  $this->rows = array();
174  $this->colspecs = array();
175  }
176 
182  public function getColumnCount()
183  {
184  return count($this->colspecs);
185  }
186 
192  public function getRowCount()
193  {
194  return count($this->rows);
195  }
196 
202  public function getRow($idx)
203  {
204  if ($idx < 0 || $idx >= $this->getRowCount()) {
205  throw new Exception("Index too small or too big!");
206  }
207  return $this->rows[$idx];
208  }
209 
217  public function getValue($rowIdx, $colIdx)
218  {
219  $row = $this->getRow($rowIdx);
220 
221  if (!is_numeric($colIdx)) {
222  $colIdx = $this->getIndexForColumn($colIdx);
223  }
224 
225  return $row->getValue($colIdx);
226  }
227 }
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
$index
Definition: metadata.php:60
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
$row
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