ILIAS  release_8 Revision v8.24
class.ilXMLResultSet.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3/*
4 +-----------------------------------------------------------------------------+
5 | ILIAS open source |
6 +-----------------------------------------------------------------------------+
7 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
8 | |
9 | This program is free software; you can redistribute it and/or |
10 | modify it under the terms of the GNU General Public License |
11 | as published by the Free Software Foundation; either version 2 |
12 | of the License, or (at your option) any later version. |
13 | |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | GNU General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU General Public License |
20 | along with this program; if not, write to the Free Software |
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22 +-----------------------------------------------------------------------------+
23*/
24
25include_once './webservice/soap/classes/class.ilXMLResultSetColumn.php';
26include_once './webservice/soap/classes/class.ilXMLResultSetRow.php';
27
35{
36 private array $colspecs = [];
37 private array $rows = [];
38
39 public function getColumnName(int $index) : ?string
40 {
41 if ($index < 0 || $index > count($this->colspecs)) {
42 return null;
43 }
44 return $this->colspecs[$index] instanceof ilXMLResultSetColumn ? $this->colspecs[$index]->getName() : null;
45 }
46
50 public function addColumn(string $columnname) : void
51 {
52 $this->colspecs[] = new ilXMLResultSetColumn(count($this->colspecs), $columnname);
53 }
54
58 public function getIndexForColumn(string $columnname) : int
59 {
60 $idx = 0;
61 foreach ($this->colspecs as $colspec) {
62 if (strcasecmp($columnname, $colspec->getName()) === 0) {
63 return $idx;
64 }
65 $idx++;
66 }
67 return -1;
68 }
69
73 public function hasColumn(string $columnname) : bool
74 {
75 return $this->getIndexForColumn($columnname) !== -1;
76 }
77
82 public function getColSpecs() : array
83 {
84 return $this->colspecs;
85 }
86
91 public function getRows() : array
92 {
93 return $this->rows;
94 }
95
96 public function addRow(ilXMLResultSetRow $row) : void
97 {
98 $this->rows[] = $row;
99 }
100
108 public function setArray(array $array) : void
109 {
110 $this->addArray($array, true);
111 }
112
122 public function addArray(array $array, bool $overwrite = false) : void
123 {
124 if ($overwrite) {
125 $this->clear();
126 }
127 foreach ($array as $row) {
128 if ($overwrite) {
129 // add column names from first row
130 $columnNames = array_keys($row);
131 foreach ($columnNames as $columnName) {
132 $this->addColumn($columnName);
133 }
134 $overwrite = false;
135 }
136 $xmlRow = new ilXMLResultSetRow();
137 $xmlRow->setValues($row);
138 $this->addRow($xmlRow);
139 }
140 }
141
142 public function clear() : void
143 {
144 $this->rows = array();
145 $this->colspecs = array();
146 }
147
148 public function getColumnCount() : int
149 {
150 return count($this->colspecs);
151 }
152
153 public function getRowCount() : int
154 {
155 return count($this->rows);
156 }
157
161 public function getRow($idx) : ilXMLResultSetRow
162 {
163 if ($idx < 0 || $idx >= $this->getRowCount()) {
164 throw new DomainException("Index too small or too big: " . $idx);
165 }
166 return $this->rows[$idx];
167 }
168
175 public function getValue(int $rowIdx, $colIdx) : string
176 {
177 $row = $this->getRow($rowIdx);
178
179 if (!is_numeric($colIdx)) {
180 $colIdx = $this->getIndexForColumn($colIdx);
181 }
182 return $row->getValue($colIdx);
183 }
184}
Column Class for XMLResultSet.
Row Class for XMLResultSet.
setArray(array $array)
Clear table value and sets them based on array.
addColumn(string $columnname)
create a new column with columnname and attach it to column list
getRow($idx)
return row for index idx
getColumnName(int $index)
getIndexForColumn(string $columnname)
return index for column name
getRows()
return array of ilXMLResultSetRow
addRow(ilXMLResultSetRow $row)
addArray(array $array, bool $overwrite=false)
Add table values.
getValue(int $rowIdx, $colIdx)
return column value at colidx and rowidx
getColSpecs()
return array of ilXMLResultSetColumn
hasColumn(string $columnname)
has column name
$index
Definition: metadata.php:145