CRUDlex\EntityDefinition¶
-
class
EntityDefinition
¶ The class for defining a single entity.
-
property
table
¶ protected string
The table where the data is stored.
-
property
fields
¶ protected array
Holds all fields in the same structure as in the CRUD YAML file.
-
property
label
¶ protected string
The label for the entity.
-
property
localeLabels
¶ protected array
The labels of the entity in the locales.
-
property
children
¶ protected array
An array with the children referencing the entity. All entries are arrays with three referencing elements: table, fieldName, entity
-
property
standardFieldLabels
¶ protected array
Labels for the fields “id”, “created_at” and “updated_at”.
-
property
listFields
¶ protected array
An array containing the fields which should appear in the list view of the entity.
-
property
childrenLabelFields
¶ protected array
The fields used to display the children on the details page of an entity. The keys are the entity names as in the CRUD YAML and the values are the field names.
-
property
deleteCascade
¶ protected bool
Whether to delete its children when an instance is deleted.
-
property
pageSize
¶ protected int
The amount of items to display per page on the listview.
-
property
filter
¶ protected array
The fields offering to be filtered.
-
property
service
¶ protected Service
Holds the service.
-
property
locale
¶ protected string
Holds the locale.
-
property
initialSortField
¶ protected string
Holds the initial sort field.
-
property
initialSortAscending
¶ protected bool
Holds the initial sort order.
-
property
hardDeletion
¶ protected bool
Holds whether hard deletion is activated.
protected string
Holds if the entity must be displayed grouped in the nav bar.
-
property
optimisticLocking
¶ protected bool
Holds whether optimistic locking is switched on.
-
getFilteredFieldNames
($exclude)¶ Gets the field names exluding the given ones.
Parameters: - $exclude (string[]) – the field names to exclude
Returns: array all field names excluding the given ones
-
checkFieldNames
($reference, $fieldNames)¶ Checks whether the given field names are declared and existing.
Parameters: - $reference (string) – a hint towards the source of an invalid field name
- $fieldNames (array) – the field names to check
-
__construct
($table, $fields, $label, $localeLabels, $standardFieldLabels, Service $service)¶ Constructor.
Parameters: - $table (string) – the table of the entity
- $fields (array) – the field structure just like the CRUD YAML
- $label (string) – the label of the entity
- $localeLabels (array) – the labels of the entity in the locales
- $standardFieldLabels (array) – labels for the fields “id”, “created_at” and “updated_at”
- $service (Service) – The current service provider
-
getFieldNames
($includeMany = false)¶ Gets all field names, including the implicit ones like “id” or “created_at”.
Parameters: - $includeMany (boolean) – whether to include the many fields as well
Returns: string[] the field names
-
setListFields
($listFields)¶ Sets the field names to be used in the listview.
Parameters: - $listFields (array) – the field names to be used in the listview
-
getListFields
()¶ Gets the field names to be used in the listview. If they were not specified, all public field names are returned.
Returns: array the field names to be used in the listview
-
getChildrenLabelFields
()¶ Gets the fields used to display the children on the details page of an entity. The keys are the entity names as in the CRUD YAML and the values are the field names.
Returns: array the fields used to display the children on the details page
-
setChildrenLabelFields
($childrenLabelFields)¶ Sets the fields used to display the children on the details page of an entity. The keys are the entity names as in the CRUD YAML and the values are the field names.
Parameters: - $childrenLabelFields (array) – the fields used to display the children on the details page
-
isDeleteCascade
()¶ Gets whether to delete its children when an instance is deleted.
Returns: boolean true if so
-
setDeleteCascade
($deleteCascade)¶ Sets whether to delete its children when an instance is deleted.
Parameters: - $deleteCascade (boolean) – whether to delete its children when an instance is deleted
-
getPageSize
()¶ Gets the amount of items to display per page on the listview.
Returns: integer the amount of items to display per page on the listview
-
setPageSize
($pageSize)¶ Sets the amount of items to display per page on the listview.
Parameters: - $pageSize (integer) – the amount of items to display per page on the listview
-
getFilter
()¶ Gets the fields offering a filter.
Returns: array the fields to filter
-
setFilter
($filter)¶ Sets the fields offering a filter.
Parameters: - $filter (array) – the fields to filter
-
getService
()¶ Gets the service.
Returns: Service the service provider
-
getPublicFieldNames
()¶ Gets the public field names. The internal fields “version” and “deleted_at” are filtered.
Returns: array the public field names
-
getEditableFieldNames
()¶ Gets the field names which are editable. Not editable are fields like the id or the created_at.
Returns: array the editable field names
-
getReadOnlyFields
()¶ Gets the read only field names like the id or the created_at.
Returns: string[] the read only field names
-
getType
($fieldName)¶ Gets the type of a field.
Parameters: - $fieldName (string) – the field name
Returns: string the type or null on invalid field name
-
setType
($fieldName, $value)¶ Sets the type of a field.
Parameters: - $fieldName (string) – the field name
- $value (string) – the new field type
-
getFieldLabel
($fieldName)¶ Gets the label of a field.
Parameters: - $fieldName (string) – the field name
Returns: string the label of the field or the field name if no label is set in the CRUD YAML
-
setFieldLabel
($fieldName, $value)¶ Gets the label of a field.
Parameters: - $fieldName (string) – the field name
- $value (string) – the new label of the field
-
getTable
()¶ Gets the table where the data is stored.
Returns: string the table where the data is stored
-
setTable
($table)¶ Sets the table where the data is stored.
Parameters: - $table (string) – the new table where the data is stored
-
getLabel
()¶ Gets the label for the entity.
Returns: string the label for the entity
-
setLabel
($label)¶ Sets the label for the entity.
Parameters: - $label (string) – the new label for the entity
-
addChild
($table, $fieldName, $entity)¶ Adds a child to this definition in case the other definition has a reference to this one.
Parameters: - $table (string) – the table of the referencing definition
- $fieldName (string) – the field name of the referencing definition
- $entity (string) – the entity of the referencing definition
-
getChildren
()¶ Gets the referencing children to this definition.
Returns: array an array with the children referencing the entity. All entries are arrays with three referencing elements: table, fieldName, entity
-
setStandardFieldLabels
($standardFieldLabels)¶ Sets the labels for the fields “id”, “created_at” and “updated_at”.
Parameters: - $standardFieldLabels (array) – labels for the fields “id”, “created_at” and “updated_at”
-
setLocale
($locale)¶ Sets the locale to be used.
Parameters: - $locale (string) – the locale to be used.
-
getLocale
()¶ Gets the locale to be used.
Returns: null|string the locale to be used.
-
setInitialSortField
($initialSortField)¶ Sets the initial sort field.
Parameters: - $initialSortField (string) – the new initial sort field
-
getInitialSortField
()¶ Gets the initial sort field.
Returns: string the initial sort field
-
setInitialSortAscending
($initialSortAscending)¶ Sets whether the initial sort order is ascending.
Parameters: - $initialSortAscending (boolean) – the initial sort order, true if ascending
-
isInitialSortAscending
()¶ Gets whether the initial sort order is ascending.
Returns: boolean the initial sort order, true if ascending
-
setHardDeletion
($hardDeletion)¶ Sets the hard deletion state.
Parameters: - $hardDeletion (boolean) – the hard deletion state
-
isHardDeletion
()¶ Gets the hard deletion state.
Returns: boolean the hard deletion state
Gets the navigation bar group where the entity belongs.
Returns: string the navigation bar group where the entity belongs
Sets the navigation bar group where the entity belongs.
Parameters: - $navBarGroup (string) – the navigation bar group where the entity belongs
-
hasOptimisticLocking
()¶ Returns whether optimistic locking via the version field is activated.
Returns: boolean true if optimistic locking is activated
-
setOptimisticLocking
($optimisticLocking)¶ Sets whether optimistic locking via the version field is activated.
Parameters: - $optimisticLocking (boolean) – true if optimistic locking is activated
-
getSubTypeField
($fieldName, $subType, $key)¶ Gets a sub field of an field.
Parameters: - $fieldName (string) – the field name of the sub type
- $subType (string) – the sub type like “reference” or “many”
- $key (string) – the key of the value
Returns: string the value of the sub field
-
getField
($name, $key, $default = null)¶ Gets the value of a field key.
Parameters: - $name (string) – the name of the field
- $key (string) – the value of the key
- $default (mixed) – the default value to return if nothing is found
Returns: mixed the value of the field key or null if not existing
-
setField
($name, $key, $value)¶ Sets the value of a field key. If the field or the key in the field don’t exist, they get created.
Parameters: - $name (string) – the name of the field
- $key (string) – the value of the key
- $value (mixed) – the new value
-
property