PHP Class CRUDlex\MySQLData

Inheritance: extends AbstractData
Datei anzeigen Open project: philiplb/crudlex

Protected Properties

Property Type Description
$database Holds the Doctrine DBAL instance.
$useUUIDs Flag whether to use UUIDs as primary key.

Public Methods

Method Description
__construct ( EntityDefinition $definition, crudlex\FileProcessorInterface $fileProcessor, $database, boolean $useUUIDs ) Constructor.
countBy ( $table, array $params, array $paramsOperators, $excludeDeleted )
create ( Entity $entity )
fetchReferences ( array &$entities = null )
get ( $id )
getIdToNameMap ( $entity, $nameField )
hasManySet ( $field, array $thatIds, $excludeId = null )
listEntries ( array $filter = [], array $filterOperators = [], $skip = null, $amount = null, $sortField = null, $sortAscending = null )
update ( Entity $entity )

Protected Methods

Method Description
addFilter ( Doctrine\DBAL\Query\QueryBuilder $queryBuilder, array $filter, array $filterOperators ) Adds sorting parameters to the query.
addPagination ( Doctrine\DBAL\Query\QueryBuilder $queryBuilder, integer | null $skip, integer | null $amount ) Adds pagination parameters to the query.
addSort ( Doctrine\DBAL\Query\QueryBuilder $queryBuilder, string | null $sortField, boolean | null $sortAscending ) Adds sorting parameters to the query.
deleteChildren ( integer $id, boolean $deleteCascade ) Performs the cascading children deletion.
doDelete ( Entity $entity, $deleteCascade )
enrichWithMany ( array $rows ) : array Fetches to the rows belonging many-to-many entries and adds them to the rows.
enrichWithManyField ( array &$idToData, $manyField ) Enriches the given mapping of entity id to raw entity data with some many-to-many data.
fetchReferencesForField ( array &$entities, string $field ) Adds the id and name of referenced entities to the given entities. The reference field is before the raw id of the referenced entity and after the fetch, it's an array with the keys id and name.
generateUUID ( ) : string | null Generates a new UUID.
getFormFields ( ) : array Gets all form fields including the many-to-many-ones.
getManyFields ( ) : array | string[] Gets the many-to-many fields.
getManyIds ( array $fields, array $params ) : array Gets all possible many-to-many ids existing for this definition.
hasChildren ( integer $id ) : boolean Checks whether the by id given entity still has children referencing it.
saveMany ( Entity $entity ) First, deletes all to the given entity related many-to-many entries from the DB and then writes them again.
setValuesAndParameters ( Entity $entity, Doctrine\DBAL\Query\QueryBuilder $queryBuilder, string $setMethod ) Sets the values and parameters of the upcoming given query according to the entity.

Method Details

__construct() public method

Constructor.
public __construct ( EntityDefinition $definition, crudlex\FileProcessorInterface $fileProcessor, $database, boolean $useUUIDs )
$definition EntityDefinition the entity definition
$fileProcessor crudlex\FileProcessorInterface the file processor to use
$database the Doctrine DBAL instance to use
$useUUIDs boolean flag whether to use UUIDs as primary key

addFilter() protected method

Adds sorting parameters to the query.
protected addFilter ( Doctrine\DBAL\Query\QueryBuilder $queryBuilder, array $filter, array $filterOperators )
$queryBuilder Doctrine\DBAL\Query\QueryBuilder the query
$filter array the filter all resulting entities must fulfill, the keys as field names
$filterOperators array the operators of the filter like "=" defining the full condition of the field

addPagination() protected method

Adds pagination parameters to the query.
protected addPagination ( Doctrine\DBAL\Query\QueryBuilder $queryBuilder, integer | null $skip, integer | null $amount )
$queryBuilder Doctrine\DBAL\Query\QueryBuilder the query
$skip integer | null the rows to skip
$amount integer | null the maximum amount of rows

addSort() protected method

Adds sorting parameters to the query.
protected addSort ( Doctrine\DBAL\Query\QueryBuilder $queryBuilder, string | null $sortField, boolean | null $sortAscending )
$queryBuilder Doctrine\DBAL\Query\QueryBuilder the query
$sortField string | null the sort field
$sortAscending boolean | null true if sort ascending, false if descending

countBy() public method

public countBy ( $table, array $params, array $paramsOperators, $excludeDeleted )
$params array
$paramsOperators array

create() public method

public create ( Entity $entity )
$entity Entity

deleteChildren() protected method

Performs the cascading children deletion.
protected deleteChildren ( integer $id, boolean $deleteCascade )
$id integer the current entities id
$deleteCascade boolean whether to delete children and sub children

doDelete() protected method

protected doDelete ( Entity $entity, $deleteCascade )
$entity Entity

enrichWithMany() protected method

Fetches to the rows belonging many-to-many entries and adds them to the rows.
protected enrichWithMany ( array $rows ) : array
$rows array the rows to enrich
return array the enriched rows

enrichWithManyField() protected method

Enriches the given mapping of entity id to raw entity data with some many-to-many data.
protected enrichWithManyField ( array &$idToData, $manyField )
$idToData array a reference to the map entity id to raw entity data
$manyField the many field to enrich data with

fetchReferences() public method

public fetchReferences ( array &$entities = null )
$entities array

fetchReferencesForField() protected method

Adds the id and name of referenced entities to the given entities. The reference field is before the raw id of the referenced entity and after the fetch, it's an array with the keys id and name.
protected fetchReferencesForField ( array &$entities, string $field )
$entities array
$field string the reference field

generateUUID() protected method

Generates a new UUID.
protected generateUUID ( ) : string | null
return string | null the new UUID or null if this instance isn't configured to do so

get() public method

public get ( $id )

getFormFields() protected method

Gets all form fields including the many-to-many-ones.
protected getFormFields ( ) : array
return array all form fields

getIdToNameMap() public method

public getIdToNameMap ( $entity, $nameField )

getManyFields() protected method

Gets the many-to-many fields.
protected getManyFields ( ) : array | string[]
return array | string[] the many-to-many fields

getManyIds() protected method

Gets all possible many-to-many ids existing for this definition.
protected getManyIds ( array $fields, array $params ) : array
$fields array the many field names to fetch for
$params array the parameters the possible many field values to fetch for
return array an array of this many-to-many ids

hasChildren() protected method

Checks whether the by id given entity still has children referencing it.
protected hasChildren ( integer $id ) : boolean
$id integer the current entities id
return boolean true if the entity still has children

hasManySet() public method

public hasManySet ( $field, array $thatIds, $excludeId = null )
$thatIds array

listEntries() public method

public listEntries ( array $filter = [], array $filterOperators = [], $skip = null, $amount = null, $sortField = null, $sortAscending = null )
$filter array
$filterOperators array

saveMany() protected method

First, deletes all to the given entity related many-to-many entries from the DB and then writes them again.
protected saveMany ( Entity $entity )
$entity Entity the entity to save the many-to-many entries of

setValuesAndParameters() protected method

Sets the values and parameters of the upcoming given query according to the entity.
protected setValuesAndParameters ( Entity $entity, Doctrine\DBAL\Query\QueryBuilder $queryBuilder, string $setMethod )
$entity Entity the entity with its fields and values
$queryBuilder Doctrine\DBAL\Query\QueryBuilder the upcoming query
$setMethod string what method to use on the QueryBuilder: 'setValue' or 'set'

update() public method

public update ( Entity $entity )
$entity Entity

Property Details

$database protected_oe property

Holds the Doctrine DBAL instance.
protected $database

$useUUIDs protected_oe property

Flag whether to use UUIDs as primary key.
protected $useUUIDs