CRUDlex\AbstractData¶
-
class
AbstractData
¶ The abstract class for reading and writing data.
-
constant
DELETION_SUCCESS
¶ Return value on successful deletion.
-
constant
DELETION_FAILED_STILL_REFERENCED
¶ Return value on failed deletion due to existing references.
-
constant
DELETION_FAILED_EVENT
¶ Return value on failed deletion due to a failed before delete event.
-
property
definition
¶ protected EntityDefinition
Holds the entity definition.
-
property
filesystem
¶ protected FilesystemInterface
Holds the filesystem.
-
property
events
¶ protected EntityEvents
Holds the events.
-
doDelete
(Entity $entity, $deleteCascade)¶ Performs the actual deletion.
Parameters: - $entity (Entity) – the id of the entry to delete
- $deleteCascade (boolean) – whether to delete children and subchildren
Returns: integer true on successful deletion
-
hydrate
($row)¶ Creates an Entity from the raw data array with the field name as keys and field values as values.
Parameters: - $row (array) – the array with the raw data
Returns: Entity the entity containing the array data then
-
enrichEntityWithMetaData
($id, Entity $entity)¶ Enriches an entity with metadata: id, version, created_at, updated_at
Parameters: - $id (mixed) – the id of the entity to enrich
- $entity (Entity) – the entity to enrich
-
getManyFields
()¶ Gets the many-to-many fields.
Returns: array|string[] the many-to-many fields
-
getFormFields
()¶ Gets all form fields including the many-to-many-ones.
Returns: array all form fields
-
deleteChildren
($id, $deleteCascade)¶ Performs the cascading children deletion.
Parameters: - $id (integer) – the current entities id
- $deleteCascade (boolean) – whether to delete children and sub children
Returns: integer returns one of: - AbstractData::DELETION_SUCCESS -> successful deletion - AbstractData::DELETION_FAILED_STILL_REFERENCED -> failed deletion due to existing references - AbstractData::DELETION_FAILED_EVENT -> failed deletion due to a failed before delete event
-
getReferenceIds
($entities, $field)¶ Gets an array of reference ids for the given entities.
Parameters: - $entities (array) – the entities to extract the ids
- $field (string) – the reference field
Returns: array the extracted ids
-
doCreate
(Entity $entity)¶ Performs the persistence of the given entity as new entry in the datasource.
Parameters: - $entity (Entity) – the entity to persist
Returns: boolean true on successful creation
-
doUpdate
(Entity $entity)¶ Performs the updates of an existing entry in the datasource having the same id.
Parameters: - $entity (Entity) – the entity with the new data
Returns: boolean true on successful update
-
getEvents
()¶ Gets the events instance.
Returns: EntityEvents the events instance
-
get
($id)¶ Gets the entity with the given id.
Parameters: - $id (string) – the id
Returns: Entity the entity belonging to the id or null if not existant
-
listEntries
($filter = [], $filterOperators = [], $skip = null, $amount = null, $sortField = null, $sortAscending = null)¶ Gets a list of entities fullfilling the given filter or all if no selection was given.
Parameters: - $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
- $skip (integer|null) – if given and not null, it specifies the amount of rows to skip
- $amount (integer|null) – if given and not null, it specifies the maximum amount of rows to retrieve
- $sortField (string|null) – if given and not null, it specifies the field to sort the entries
- $sortAscending (boolean|null) – if given and not null, it specifies that the sort order is ascending, descending else
Returns: Entity[] the entities fulfilling the filter or all if no filter was given
-
create
(Entity $entity)¶ Persists the given entity as new entry in the datasource.
Parameters: - $entity (Entity) – the entity to persist
Returns: boolean true on successful creation
-
update
(Entity $entity)¶ Updates an existing entry in the datasource having the same id.
Parameters: - $entity (Entity) – the entity with the new data
Returns: boolean true on successful update
-
delete
($entity)¶ Deletes an entry from the datasource.
Parameters: - $entity (Entity) – the entity to delete
Returns: integer returns one of: - AbstractData::DELETION_SUCCESS -> successful deletion - AbstractData::DELETION_FAILED_STILL_REFERENCED -> failed deletion due to existing references - AbstractData::DELETION_FAILED_EVENT -> failed deletion due to a failed before delete event
-
getIdToNameMap
($entity, $nameField)¶ Gets ids and names of a table. Used for building up the dropdown box of reference type fields for example.
Parameters: - $entity (string) – the entity
- $nameField (string) – the field defining the name of the rows
Returns: array an array with the ids as key and the names as values
-
countBy
($table, $params, $paramsOperators, $excludeDeleted)¶ Retrieves the amount of entities in the datasource fulfilling the given parameters.
Parameters: - $table (string) – the table to count in
- $params (array) – an array with the field names as keys and field values as values
- $paramsOperators (array) – the operators of the parameters like “=” defining the full condition of the field
- $excludeDeleted (boolean) – false, if soft deleted entries in the datasource should be counted, too
Returns: integer the count fulfilling the given parameters
-
hasManySet
($field, $thatIds, $excludeId = null)¶ Checks whether a given set of ids is assigned to any entity exactly like it is given (no subset, no superset).
Parameters: - $field (string) – the many field
- $thatIds (array) – the id set to check
- $excludeId (string|null) – one optional own id to exclude from the check
Returns: boolean true if the set of ids exists for an entity
-
getDefinition
()¶ Gets the EntityDefinition instance.
Returns: EntityDefinition the definition instance
-
createEmpty
()¶ Creates a new, empty entity instance having all fields prefilled with null or the defined value in case of fixed fields.
Returns: Entity the newly created entity
-
constant