$columns
$columns : \Alddesign\Crudkit\Classes\array<SQLColumn>
Definition of a database table.
Examples for usage are provided in the documentation for CrudkitServiceProvider. Important: all methods marked with "@stackable" (like the constructor and all set methods) can be used like this
$page = new TableDesriptor(...)
->addColumn(...)
->setSoftDeleteColumn(...)
->...
...easy
__construct(string $name, array<mixed,string> $primaryKeyColumns, boolean $hasAutoincrementKey = false)
Constructor
| string | $name | Name of the table (as defined in the database) |
| array<mixed,string> | $primaryKeyColumns | String array of column names, which define the primary key of this table, or at least identify a single record. Remember: if no column is a PK, every column is a PK! |
| boolean | $hasAutoincrementKey | (default = false) Set this to TRUE if you have a column like and integer ID, which will be generated (MySQL Auto increment, MSSQL identity) |
getAllColumns(boolean $namesOnly = false) : array<mixed,string>|array
Returns an array of this tables columns, including extended information from Doctrine DBAL.
Make sure to call fetchAllColumns() at least once before calling this method.
| boolean | $namesOnly | (default = FALSE) TRUE = retruns string[] array with the column names, FALSE = return and array of SQLColumn[] objects |
getColumns(boolean $namesOnly = false) : array<mixed,string>|array<mixed,\Alddesign\Crudkit\Classes\SQLColumn>
Returns an array of this tables columns
| boolean | $namesOnly | (default = FALSE) TRUE = retruns string[] array with the column names, FALSE = return and array of SQLColumn[] objects |
getPrimaryKeyColumns(boolean $namesOnly = false) : array<mixed,string>|array<mixed,\Alddesign\Crudkit\Classes\SQLColumn>
Returns an array of this tables primary key columns
| boolean | $namesOnly | (default = FALSE) TRUE = retruns string[] array with the column names, FALSE = return and array of SQLColumn[] objects |
getManyToOneColumnValues( $record = array(), \Alddesign\Crudkit\Classes\bool $onlyCurrentValue = false) : array
Returns values for each many-to-one column of this table (values from related tables)
['column-name-1' => ['value-1', 'value-2'], 'column-name-2' => [...]]
| $record | ||
| \Alddesign\Crudkit\Classes\bool | $onlyCurrentValue |
addColumn(string $name, string $label, string $type, array $options = array())
Adds a sql column to this table.
You dont need to add every column that exists in the table, only those you need.
| string | $name | The name of the column like its defined in the Database |
| string | $label | The label to display the column on UI. |
| string | $type | The datatype - for details see SQLColumn Class doc |
| array | $options | (optional) - for details see SQLColumn Class doc |
defineManyToOneColumn(string $name, string $toTableName, string $columnName, array $secondaryColumnNames = array(), string $page = '', array $filterDefinitions = array(), boolean $manualInput = false) : \Alddesign\Crudkit\Classes\TableDescriptor
Example: book.author_id is a many to one column. Related table.field is author.id Example code: see CrudkitServiceProvider doc
| string | $name | Name of the column to defines as many to one |
| string | $toTableName | Related table name |
| string | $columnName | A column from the related table |
| array | $secondaryColumnNames | Secondary clolumn names from the related table. These are shown to the user when selecting the value (more = slower) |
| string | $page | A drilldown page if you want to display this relation as a link |
| array | $filterDefinitions | Additional filters to limit the relation |
| boolean | $manualInput | Allows the user to input custom data manually (without checking) |
defineManyToOneColumnAjax(string $name, string $toTableName, string $columnName, array $secondaryColumnNames = array(), string $page = '', array $filterDefinitions = array(), boolean $manualInput = false, \Alddesign\Crudkit\Classes\AjaxOptions|null $ajaxOptions = null) : \Alddesign\Crudkit\Classes\TableDescriptor
See defineManyToOneColumn() - same, but rendered as an ajax selectbox (search for values).
| string | $name | Name of the column to defines as many to one |
| string | $toTableName | Related table name |
| string | $columnName | A column from the related table |
| array | $secondaryColumnNames | Secondary clolumn names from the related table. These are shown to the user when selecting the value (more = slower) |
| string | $page | A drilldown page if you want to display this relation as a link |
| array | $filterDefinitions | Additional filters to limit the relation |
| boolean | $manualInput | Allows the user to input custom data manually (without checking) |
| \Alddesign\Crudkit\Classes\AjaxOptions|null | $ajaxOptions | additional options to control the ajax behavior |
defineCustomColumnAjax(string $name, callable $onLoadCallback, callable $onSearchCallback, \Alddesign\Crudkit\Classes\AjaxOptions $ajaxOptions = null) : \Alddesign\Crudkit\Classes\TableDescriptor
Defines a column where you can handle what is displayed, and what the user can enter via ajax select search. Be carefull - you have to take care of the data!
//Example for $result object if success (Json encoded):
{type : "result", data : {results : [{'id' : '23', 'text' => 'Joe Smith', 'img' => 'base64imageData'}, {id : '...'}]}}
//Example for $result object if error (Json encoded):
{type : "error", message : "404 not found" data : "some error data which will be logged by the Javascript console..."}
//Helper methods in DataProcessor class:
DataProcessor::getAjaxErrorResult();
DataProcessor::getAjaxResult();
| string | $name | Name of the existing column. Cannot be a many to one column. |
| callable | $onLoadCallback | Callback function for preparing the data which is displayed in the field. Params are: &$value, &$text, $record, $table, $page, $column. You can change &$value and &$text as you wish. $value already holds the fields current value (after select). $text is an additionl info text |
| callable | $onSearchCallback | Callback function for when the user begins to type for searching data. Params are: &$results, $input, $table, $page, $column. You have to populate $results (see example above); |
| \Alddesign\Crudkit\Classes\AjaxOptions | $ajaxOptions |
setSoftDeleteColumn(string $name, mixed $deleted = true, $notDeleted = false)
Defines a column as an indicator if the record is deleted or not.
Important: the soft delete column must not be added as normal column to the table, cause this will make things hard (espcially for users) When a soft delete column is defined, and a user deletes a record on the webpage, the record wont be deleted. Only thing happen is that the value of the soft delete column will be changed, and crudkit wont display this record anymore. - Cool, isnt it?
| string | $name | The name of the column |
| mixed | $deleted | (default = FALSE) The value of this column that indicates the record is NOT delteted |
| $notDeleted |
setColumnPosition( $columnName, $where, $referenceColumnName)
Sets the position of a column (display order)
$table->setColumnPosition('name', 'after', 'id'); //easy
| $columnName | Defines the column to be set to a specific position. |
|
| $where | Is either 'before' or 'after' |
|
| $referenceColumnName | Before or after this Column the $columnName will be placed |
readRecord(array<mixed,string> $primaryKeyValues, array<mixed,\Alddesign\Crudkit\Classes\Filter> $filters = array(), \Alddesign\Crudkit\Classes\bool $formatDateAndTime = true, $formatBool = true, $formatDec = true, $formatBinary = true, $throwErrorIfNotFound = true) : array
Reads a record from the DB
| array<mixed,string> | $primaryKeyValues | |
| array<mixed,\Alddesign\Crudkit\Classes\Filter> | $filters | |
| \Alddesign\Crudkit\Classes\bool | $formatDateAndTime | |
| $formatBool | ||
| $formatDec | ||
| $formatBinary | ||
| $throwErrorIfNotFound |
Record data as array
getCustomAjaxValues( $record, \Alddesign\Crudkit\Classes\PageDescriptor $page)
| $record | ||
| \Alddesign\Crudkit\Classes\PageDescriptor | $page |
readRecords(integer $pageNumber = 1, string $searchColumnName = '', string $searchText = '', array<mixed,\Alddesign\Crudkit\Classes\Filter> $filters = array(), boolean $trimText = true, boolean $formatDateAndTime = true, boolean $formatBool = true, boolean $formatDec = true, boolean $formatBinary = true, integer $itemsPerPage = -1) : array
Reads multiple records from the DB
| integer | $pageNumber | Pagination offset |
| string | $searchColumnName | The column name to apply the $searchText (if existing) |
| string | $searchText | The search text (if existing) |
| array<mixed,\Alddesign\Crudkit\Classes\Filter> | $filters | |
| boolean | $trimText | Trim text >50 chars |
| boolean | $formatDateAndTime | |
| boolean | $formatBool | |
| boolean | $formatDec | |
| boolean | $formatBinary | |
| integer | $itemsPerPage |