CSV data abstraction
| package | Default |
|---|
__construct(integer $rows,mixed $columns): \org\turbocommons\src\main\php\model\TableObject
Columns can be labeled with a textual name which can be used to access them anytime (data can be also accessed via numeric row and column indexes).
integerThe number of rows for the created table (Rows can be added or modified anytime later).
mixedThe number of columns to create or an array of strings containing the column labels for all of the columns that will be created (Columns can be added or modified anytime later).
\org\turbocommons\src\main\php\model\TableObjectThe constructed TableObject
addColumns(integer $number,array $names = array(),integer $at = -1): boolean
| Throws |
|
|---|
integerThe number of columns that will be added to the table
arrayOptionally we can list all the labels to define for the new columns that will be added
integerDefines the column index where the new columns will be inserted. Old columns that are located at the insertion point will not be deleted, they will be moved to the Right. By default all the new columns will be appended at the end of the table unless a positive value is specified here.
booleanTrue if the operation was successful
addRows(integer $number,integer $at = -1): boolean
| Throws |
|
|---|
integerThe number of rows that will be added to the table
integerDefines the row index where the new rows will be inserted. Old rows that are located at the insertion point will not be deleted, they will be moved down. By default all the new rows will be appended at the bottom of the table unless a positive value is specified here.
booleanTrue if the operation was successful
countCells(): integer
integerThe total number of cells on the table
countColumns(): integer
integerThe total number of columns on the table
countRows(): integer
integerThe total number of rows on the table
getCell(integer $row,mixed $column): mixed
integerAn integer containing the index for the row that we want to retrieve
mixedAn integer or a string containing the index or label for the column that we want to retrieve
mixedThe value for the cell located at the specified row and column or null if no data is defined for it
getColumn(mixed $column): array
mixedAn integer or a string containing the index or label for the column that we want to retrieve
arrayAll the table elements that belong to the required column
getColumnIndex(string $name): integer
| Throws |
|
|---|
stringThe label for an existing column
integerThe numeric index that is related to the given column label
getColumnName(integer $columnIndex): string
integera numeric column index
stringThe column label for the specified numeric index
getColumnNames(): array
If the table contains columns but no names are defined, a list with empty strings will be returned
arrayA list of strings with the column names
getRow(integer $row): array
integerAn integer containing the index for the row that we want to retrieve
arrayAll the table elements that belong to the required row
isCSV(mixed $value): boolean
mixedObject to test for valid CSV data. Accepted values are: Strings containing CSV data or CSVObject elements
booleanTrue if the received object represent valid CSV data. False otherwise.
isEqualTo(mixed $csv): boolean
mixedA valid string or CSVObject to compare with the current one
booleantrue if the two CSV elements are considered equal, false if not
removeColumn(mixed $column): void
mixedAn integer or a string containing the index or label for the column that we want to delete
removeRow(integer $row): void
integerAn integer containing the index for the row that we want to delete
setCell(integer $row,mixed $column,mixed $value): mixed
integerAn integer containing the index for the row that we want to set
mixedAn integer or a string containing the index or label for the column that we want to set
mixedThe value we want to set to the specified cell. Any type is allowed, and different cells can contain values of different types.
mixedThe assigned value after beign stored into the table cell
setColumn(mixed $column,array $data): void
| Throws |
|
|---|
mixedAn integer or a string containing the index or label for the column that we want to fill
arrayAn array with all the values that will be assigned to the table rows on the specified column. Array length must match rows number
setColumnName(mixed $column,string $name): boolean
| Throws |
|
|---|
mixedAn integer or a string containing the index or label for the column to which we want to assign a label
stringThe new label that will be assigned to the specified column
booleanTrue if the column name was correctly assigned
setColumnNames(array $names): array
| Throws |
|
|---|
arrayList of names that will be applied to the table columns. It must have the same number of items and in the same order as the table columns.
arrayThe list of column names after beign assigned
setRow(integer $row,array $data): void
| Throws |
|
|---|
integerAn integer containing the index for the row that we want to set
arrayAn array with all the values that will be assigned to the table row. Array length must match columns number
toString(string $delimiter = ',',string $enclosure = '"'): string
The output of this method is ready to be stored on a physical .csv file.
stringThe character that is used as the csv delimiter. ',' is set by default
stringThe character that is used to escape fields when special characters are found
stringA valid csv string ready to be stored on a .csv file