ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilXMLResultSet Class Reference
+ Collaboration diagram for ilXMLResultSet:

Public Member Functions

 getColumnName (int $index)
 
 addColumn (string $columnname)
 create a new column with columnname and attach it to column list More...
 
 getIndexForColumn (string $columnname)
 return index for column name More...
 
 hasColumn (string $columnname)
 has column name More...
 
 getColSpecs ()
 return array of ilXMLResultSetColumn More...
 
 getRows ()
 return array of ilXMLResultSetRow More...
 
 addRow (ilXMLResultSetRow $row)
 
 setArray (array $array)
 Clear table value and sets them based on array. More...
 
 addArray (array $array, bool $overwrite=false)
 Add table values. More...
 
 clear ()
 
 getColumnCount ()
 
 getRowCount ()
 
 getRow ($idx)
 return row for index idx More...
 
 getValue (int $rowIdx, $colIdx)
 return column value at colidx and rowidx More...
 

Private Attributes

array $colspecs = []
 
array $rows = []
 

Detailed Description

Definition at line 34 of file class.ilXMLResultSet.php.

Member Function Documentation

◆ addArray()

ilXMLResultSet::addArray ( array  $array,
bool  $overwrite = false 
)

Add table values.

Exspects a 2-dimension array. Column indeces of second dimensions in first row are column names. e.g. array (array("first" => "val1_1", "second" => "val1_2), array ("first" => "val2_1", "second" => "val2_2")) results in Table first second val1_1 va11_2 val2_1 val2_2

Parameters
array$array2 dimensional array
bool$overwriteif false, column names won't be changed, rows will be added,true: result set will be reset to null and data will be added.

Definition at line 122 of file class.ilXMLResultSet.php.

References addColumn(), addRow(), and clear().

Referenced by setArray().

122  : 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  }
Row Class for XMLResultSet.
addColumn(string $columnname)
create a new column with columnname and attach it to column list
addRow(ilXMLResultSetRow $row)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addColumn()

ilXMLResultSet::addColumn ( string  $columnname)

create a new column with columnname and attach it to column list

Definition at line 50 of file class.ilXMLResultSet.php.

Referenced by addArray().

50  : void
51  {
52  $this->colspecs[] = new ilXMLResultSetColumn(count($this->colspecs), $columnname);
53  }
Column Class for XMLResultSet.
+ Here is the caller graph for this function:

◆ addRow()

ilXMLResultSet::addRow ( ilXMLResultSetRow  $row)

Definition at line 96 of file class.ilXMLResultSet.php.

Referenced by addArray().

96  : void
97  {
98  $this->rows[] = $row;
99  }
+ Here is the caller graph for this function:

◆ clear()

ilXMLResultSet::clear ( )

Definition at line 142 of file class.ilXMLResultSet.php.

Referenced by addArray().

142  : void
143  {
144  $this->rows = array();
145  $this->colspecs = array();
146  }
+ Here is the caller graph for this function:

◆ getColSpecs()

ilXMLResultSet::getColSpecs ( )

return array of ilXMLResultSetColumn

Returns
ilXMLResultSetColumn[]

Definition at line 82 of file class.ilXMLResultSet.php.

References $colspecs.

82  : array
83  {
84  return $this->colspecs;
85  }

◆ getColumnCount()

ilXMLResultSet::getColumnCount ( )

Definition at line 148 of file class.ilXMLResultSet.php.

148  : int
149  {
150  return count($this->colspecs);
151  }

◆ getColumnName()

ilXMLResultSet::getColumnName ( int  $index)

Definition at line 39 of file class.ilXMLResultSet.php.

References $index, and ilXMLResultSetColumn\getName().

39  : ?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  }
$index
Definition: metadata.php:145
Column Class for XMLResultSet.
+ Here is the call graph for this function:

◆ getIndexForColumn()

ilXMLResultSet::getIndexForColumn ( string  $columnname)

return index for column name

Definition at line 58 of file class.ilXMLResultSet.php.

Referenced by getValue(), and hasColumn().

58  : 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  }
+ Here is the caller graph for this function:

◆ getRow()

ilXMLResultSet::getRow (   $idx)

return row for index idx

Definition at line 161 of file class.ilXMLResultSet.php.

References getRowCount().

Referenced by getValue().

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  }
Row Class for XMLResultSet.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRowCount()

ilXMLResultSet::getRowCount ( )

Definition at line 153 of file class.ilXMLResultSet.php.

Referenced by getRow().

153  : int
154  {
155  return count($this->rows);
156  }
+ Here is the caller graph for this function:

◆ getRows()

ilXMLResultSet::getRows ( )

return array of ilXMLResultSetRow

Returns
ilXMLResultSetRow[]

Definition at line 91 of file class.ilXMLResultSet.php.

References $rows.

91  : array
92  {
93  return $this->rows;
94  }

◆ getValue()

ilXMLResultSet::getValue ( int  $rowIdx,
  $colIdx 
)

return column value at colidx and rowidx

Parameters
int$rowIdx
int | string$colIdx
Returns
string

Definition at line 175 of file class.ilXMLResultSet.php.

References getIndexForColumn(), and getRow().

175  : 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  }
getRow($idx)
return row for index idx
getIndexForColumn(string $columnname)
return index for column name
+ Here is the call graph for this function:

◆ hasColumn()

ilXMLResultSet::hasColumn ( string  $columnname)

has column name

Definition at line 73 of file class.ilXMLResultSet.php.

References getIndexForColumn().

73  : bool
74  {
75  return $this->getIndexForColumn($columnname) !== -1;
76  }
getIndexForColumn(string $columnname)
return index for column name
+ Here is the call graph for this function:

◆ setArray()

ilXMLResultSet::setArray ( array  $array)

Clear table value and sets them based on array.

Exspects a 2-dimension array. Column indeces of second dimensions in first row are column names. e.g. array (array("first" => "val1_1", "second" => "val1_2), array ("first" => "val2_1", "second" => "val2_2")) results in Table first second val1_1 va11_2 val2_1 val2_2

Definition at line 108 of file class.ilXMLResultSet.php.

References addArray().

108  : void
109  {
110  $this->addArray($array, true);
111  }
addArray(array $array, bool $overwrite=false)
Add table values.
+ Here is the call graph for this function:

Field Documentation

◆ $colspecs

array ilXMLResultSet::$colspecs = []
private

Definition at line 36 of file class.ilXMLResultSet.php.

Referenced by getColSpecs().

◆ $rows

array ilXMLResultSet::$rows = []
private

Definition at line 37 of file class.ilXMLResultSet.php.

Referenced by getRows().


The documentation for this class was generated from the following file: