\Alddesign\Crudkit\ClassesTableDescriptor

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

Summary

Methods
Properties
Constants
__construct()
getName()
getHasAutoincrementKey()
getSoftDeleteColumn()
getSoftDeletedValue()
getSoftNotDeletedValue()
hasColumn()
getAllColumns()
getColumns()
getPrimaryKeyColumns()
getManyToOneColumnValues()
addColumn()
setOrderBy()
defineManyToOneColumn()
defineManyToOneColumnAjax()
defineCustomColumnAjax()
setSoftDeleteColumn()
setColumnPosition()
readRecord()
getCustomAjaxValues()
readRecords()
getEmptyRecord()
deleteRecord()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$columns
$cacheTTLSeconds
N/A

Properties

$columns

$columns : \Alddesign\Crudkit\Classes\array<SQLColumn>

Type

\Alddesign\Crudkit\Classes\array

$cacheTTLSeconds

$cacheTTLSeconds : integer

Type

integer — The lifetime of the cache. The cache is usede to store the Doctrine\DBAL results of all DB columns

Methods

__construct()

__construct(string  $name, array<mixed,string>  $primaryKeyColumns, boolean  $hasAutoincrementKey = false) 

Constructor

Parameters

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)

getName()

getName() : string

Returns

string —

Name of the table (as defined in the database)

getHasAutoincrementKey()

getHasAutoincrementKey() : boolean

Returns

boolean

getSoftDeleteColumn()

getSoftDeleteColumn() : string

Returns

string —

Name of the soft delte column (soft delete is a pseudo delete)

getSoftDeletedValue()

getSoftDeletedValue() : mixed

Returns

mixed —

Value of the soft delete Column that indicates that the record IS deleted

getSoftNotDeletedValue()

getSoftNotDeletedValue() : mixed

Returns

mixed —

Value of the soft delete Column that indicates that the record is NOT deleted.

hasColumn()

hasColumn(string  $columnName) : boolean

Checks if a column with a specific name exists in this table.

Parameters

string $columnName

The name of the column to check

Returns

boolean

getAllColumns()

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.

Parameters

boolean $namesOnly

(default = FALSE) TRUE = retruns string[] array with the column names, FALSE = return and array of SQLColumn[] objects

Returns

array<mixed,string>|array

getColumns()

getColumns(boolean  $namesOnly = false) : array<mixed,string>|array<mixed,\Alddesign\Crudkit\Classes\SQLColumn>

Returns an array of this tables columns

Parameters

boolean $namesOnly

(default = FALSE) TRUE = retruns string[] array with the column names, FALSE = return and array of SQLColumn[] objects

Returns

array<mixed,string>|array<mixed,\Alddesign\Crudkit\Classes\SQLColumn>

getPrimaryKeyColumns()

getPrimaryKeyColumns(boolean  $namesOnly = false) : array<mixed,string>|array<mixed,\Alddesign\Crudkit\Classes\SQLColumn>

Returns an array of this tables primary key columns

Parameters

boolean $namesOnly

(default = FALSE) TRUE = retruns string[] array with the column names, FALSE = return and array of SQLColumn[] objects

Returns

array<mixed,string>|array<mixed,\Alddesign\Crudkit\Classes\SQLColumn>

getManyToOneColumnValues()

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' => [...]]

Parameters

$record
\Alddesign\Crudkit\Classes\bool $onlyCurrentValue

Returns

array

addColumn()

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.

Parameters

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

setOrderBy()

setOrderBy(\Alddesign\Crudkit\Classes\string  $columnName, \Alddesign\Crudkit\Classes\string  $direction = 'asc') 

Parameters

\Alddesign\Crudkit\Classes\string $columnName
\Alddesign\Crudkit\Classes\string $direction

defineManyToOneColumn()

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

Parameters

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)

Returns

\Alddesign\Crudkit\Classes\TableDescriptor

defineManyToOneColumnAjax()

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).

Parameters

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

Returns

\Alddesign\Crudkit\Classes\TableDescriptor

defineCustomColumnAjax()

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();

Parameters

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

Returns

\Alddesign\Crudkit\Classes\TableDescriptor

setSoftDeleteColumn()

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?

Parameters

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()

setColumnPosition(  $columnName,   $where,   $referenceColumnName) 

Sets the position of a column (display order)

$table->setColumnPosition('name', 'after', 'id'); //easy

Parameters

$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()

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

Parameters

array<mixed,string> $primaryKeyValues
array<mixed,\Alddesign\Crudkit\Classes\Filter> $filters
\Alddesign\Crudkit\Classes\bool $formatDateAndTime
$formatBool
$formatDec
$formatBinary
$throwErrorIfNotFound

Returns

array —

Record data as array

readRecords()

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

Parameters

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

Returns

array

getEmptyRecord()

getEmptyRecord(boolean  $setDbDefaultValues = true, boolean  $allColumns = false) : array

Parameters

boolean $setDbDefaultValues

Set the default values which are definded in the Database

boolean $allColumns

Get all columns or just those definded in CRUDKit

Returns

array

deleteRecord()

deleteRecord(array  $primaryKeyValues) 

Parameters

array $primaryKeyValues