# Class CRUDData

The abstract class for reading and writing data.

#### Direct known subclasses

CRUDlex\CRUDMySQLData
Abstract
Namespace: CRUDlex
Located at CRUDData.php

Methods summary
`abstract protected integer` | # `doDelete( `CRUDlex\CRUDEntity` $entity, boolean $deleteCascade )` Performs the actual deletion. Performs the actual deletion. #### Parameters $entity the id of the entry to delete $deleteCascade whether to delete children and subchildren #### Returns integer true on successful deletion
`protected `CRUDlex\CRUDEntity`` | # `hydrate( array $row )` Creates an `CRUDlex\CRUDEntity` from the raw data array with the field name as keys and field values as values. Creates an `CRUDlex\CRUDEntity` from the raw data array with the field name as keys and field values as values. #### Parameters $row the array with the raw data #### Returns `CRUDlex\CRUDEntity` the entity containing the array data then
`protected boolean` | # `executeEvents( `CRUDlex\CRUDEntity` $entity, string $moment, string $action )` Executes the event chain of an entity. Executes the event chain of an entity. #### Parameters $entity the entity having the event chain to execute $moment the "moment" of the event, can be either "before" or "after" $action the "action" of the event, can be either "create", "update" or "delete" #### Returns boolean true on successful execution of the full chain or false if it broke at any point (and stopped the execution)
`protected` | # `performOnFiles( `CRUDlex\CRUDEntity` $entity, string $entityName, Closure $function )` Executes a function for each file field of this entity. Executes a function for each file field of this entity. #### Parameters $entity the just created entity $entityName the name of the entity as this class here is not aware of it $function the function to perform, takes $entity, $entityName and $field as parameter
`public` | # `pushEvent( string $moment, string $action, anonymous $function )` Adds an event to fire for the given parameters. The event function must have this signature: function (CRUDEntity $entity) and has to return true or false. The events are executed one after another in the added order as long as they return "true". The first event returning "false" will stop the process. Adds an event to fire for the given parameters. The event function must have this signature: function (CRUDEntity $entity) and has to return true or false. The events are executed one after another in the added order as long as they return "true". The first event returning "false" will stop the process. #### Parameters $moment the "moment" of the event, can be either "before" or "after" $action the "action" of the event, can be either "create", "update" or "delete" $function $function the event function to be called if set
`public anonymous` | # `popEvent( string $moment, string $action )` Removes and returns the latest event for the given parameters. Removes and returns the latest event for the given parameters. #### Parameters $moment the "moment" of the event, can be either "before" or "after" $action the "action" of the event, can be either "create", "update" or "delete" #### Returns anonymous function the popped event or null if no event was available.
`abstract public `CRUDlex\CRUDEntity`` | # `get( string $id )` Gets the entity with the given id. Gets the entity with the given id. #### Parameters $id the id #### Returns `CRUDlex\CRUDEntity` the entity belonging to the id or null if not existant
`abstract public `CRUDlex\CRUDEntity[]`` | # `listEntries( array $filter = array(), array $filterOperators = array(), integer $skip = null, integer $amount = null, string $sortField = null, boolean $sortAscending = null )` Gets a list of entities fullfilling the given filter or all if no selection was given. Gets a list of entities fullfilling the given filter or all if no selection was given. #### Parameters $filter the filter all resulting entities must fulfill, the keys as field names $filterOperators the operators of the filter like "=" defining the full condition of the field $skip if given and not null, it specifies the amount of rows to skip $amount if given and not null, it specifies the maximum amount of rows to retrieve $sortField if given and not null, it specifies the field to sort the entries $sortAscending if given and not null, it specifies that the sort order is ascending, descending else #### Returns `CRUDlex\CRUDEntity[]` the entities fulfilling the filter or all if no filter was given
`abstract public boolean` | # `create( `CRUDlex\CRUDEntity` $entity )` Persists the given entity as new entry in the datasource. Persists the given entity as new entry in the datasource. #### Parameters $entity the entity to persist #### Returns boolean true on successful creation
`abstract public` | # `update( `CRUDlex\CRUDEntity` $entity )` Updates an existing entry in the datasource having the same id. Updates an existing entry in the datasource having the same id. #### Parameters $entity the entity with the new data
`public integer` | # `delete( `CRUDlex\CRUDEntity` $entity )` Deletes an entry from the datasource having the given id. Deletes an entry from the datasource having the given id. #### Parameters $entity the id of the entry to delete #### Returns integer returns one of: - CRUDData::DELETION_SUCCESS -> successful deletion - CRUDData::DELETION_FAILED_STILL_REFERENCED -> failed deletion due to existing references - CRUDData::DELETION_FAILED_EVENT -> failed deletion due to a failed before delete event
`abstract public array` | # `getReferences( string $table, string $nameField )` Gets ids and names of a table. Used for building up the dropdown box of reference type fields. Gets ids and names of a table. Used for building up the dropdown box of reference type fields. #### Parameters $table the table $nameField the field defining the name of the rows #### Returns array an array with the ids as key and the names as values
`abstract public integer` | # `countBy( string $table, array $params, array $paramsOperators, boolean $excludeDeleted )` Retrieves the amount of entities in the datasource fulfilling the given parameters. Retrieves the amount of entities in the datasource fulfilling the given parameters. #### Parameters $table the table to count in $params an array with the field names as keys and field values as values $paramsOperators the operators of the parameters like "=" defining the full condition of the field $excludeDeleted false, if soft deleted entries in the datasource should be counted, too #### Returns integer the count fulfilling the given parameters
`abstract public` | # `fetchReferences( array & $entities = null )` Adds the id and name of referenced entities to the given entities. Each 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. Adds the id and name of referenced entities to the given entities. Each 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. #### Parameters $entities $entities the entities to fetch the references for
`public `CRUDlex\CRUDEntityDefinition`` | # `getDefinition( )` Gets the `CRUDlex\CRUDEntityDefinition` instance. Gets the `CRUDlex\CRUDEntityDefinition` instance. #### Returns `CRUDlex\CRUDEntityDefinition` the definition instance
`public `CRUDlex\CRUDEntity`` | # `createEmpty( )` Creates a new, empty entity instance having all fields prefilled with null or the defined value in case of fixed fields. Creates a new, empty entity instance having all fields prefilled with null or the defined value in case of fixed fields. #### Returns `CRUDlex\CRUDEntity` the newly created entity
`public` | # `createFiles( Symfony\Component\HttpFoundation\Request $request, `CRUDlex\CRUDEntity` $entity, string $entityName )` Creates the uploaded files of a newly created entity. Creates the uploaded files of a newly created entity. #### Parameters $request the HTTP request containing the file data $entity the just created entity $entityName the name of the entity as this class here is not aware of it
`public` | # `updateFiles( Symfony\Component\HttpFoundation\Request $request, `CRUDlex\CRUDEntity` $entity, string $entityName )` Updates the uploaded files of an updated entity. Updates the uploaded files of an updated entity. #### Parameters $request the HTTP request containing the file data $entity the updated entity $entityName the name of the entity as this class here is not aware of it
`public` | # `deleteFile( `CRUDlex\CRUDEntity` $entity, string $entityName, string $field )` Deletes a specific file from an existing entity. Deletes a specific file from an existing entity. #### Parameters $entity the entity to delete the file from $entityName the name of the entity as this class here is not aware of it $field the field of the entity containing the file to be deleted
`public` | # `deleteFiles( `CRUDlex\CRUDEntity` $entity, string $entityName )` Deletes all files of an existing entity. Deletes all files of an existing entity. #### Parameters $entity the entity to delete the files from $entityName the name of the entity as this class here is not aware of it
`public Symfony\Component\HttpFoundation\Response` | # `renderFile( `CRUDlex\CRUDEntity` $entity, string $entityName, string $field )` Renders (outputs) a file of an entity. This includes setting headers like the file size, mimetype and name, too. Renders (outputs) a file of an entity. This includes setting headers like the file size, mimetype and name, too. #### Parameters $entity the entity to render the file from $entityName the name of the entity as this class here is not aware of it $field the field of the entity containing the file to be rendered #### Returns Symfony\Component\HttpFoundation\Response the HTTP response, likely to be a streamed one

Constants summary
`integer` | `DELETION_SUCCESS` Return value on successful deletion. Return value on successful deletion. | # `0`
`integer` | `DELETION_FAILED_STILL_REFERENCED` Return value on failed deletion due to existing references. Return value on failed deletion due to existing references. | # `1`
`integer` | `DELETION_FAILED_EVENT` Return value on failed deletion due to a failed before delete event. Return value on failed deletion due to a failed before delete event. | # `2`

Properties summary
`protected` | $definition Holds the `CRUDlex\CRUDEntityDefinition` entity definition. Holds the `CRUDlex\CRUDEntityDefinition` entity definition. | # ``
`protected` | $fileProcessor Holds the `CRUDlex\CRUDFileProcessorInterface` file processor. Holds the `CRUDlex\CRUDFileProcessorInterface` file processor. | # ``
`protected` | $events Holds the events. Holds the events. | # ``