AUTHORIZATION_ALLOW_ALL
AUTHORIZATION_ALLOW_ALL
A placeholder used to signify that a capability is available to everyone, even if no UserInterface object is supplied to test against.
This class serves as a base for both custom and DB fields in Dewdrop.
It implements the helper callback assignment and permissions management of FieldInterface, leaving the ID/label handling up to the sub-classes (i.e. \Dewdrop\Db\Field and \Dewdrop\Fields\Field). ID/label handling differs quite a lot in the 2 primary types of fields. For DB fields, sane default are available from the DB metadata, whereas for custom fields, all this information must be defined manually.
Note that in the case of custom fields, all capabilities (visibility, sortability, filterability, and editability) are forbidden by default. In DB fields, on the other hand, these capabilities are all enabled by default. Similarly the situation with ID/label handling, we do this because database fields can provide sane default by leveraging information from the schema. Custom fields, though, need to be thought out and configured manually.
To support the storage of the permissions settings for this field, a scheme using arrays is deployed:
1) If the permissions/capability array contains only \Dewdrop\Fields\FieldAbstract::AUTHORIZATION_ALLOW_ALL, it is allowed for everyone.
2) If it contains nothing, it is forbidden for everyone.
3) Otherwise, it will contains one ore more "roles" which can be any value that can be passed along to the UserInterface object to see if the current user can use that capability.
$fieldsSet : \Dewdrop\Fields
The Fields object this field is associated with. This is really only used to enable our streamlined method chaining.
setNote(string $note) : \Dewdrop\Fields\FieldAbstract
Set a note that will be displayed alongside this field when it is used in a UI.
string | $note |
setOptions(array $options) : \Dewdrop\Fields\FieldAbstract
Set multiple options at once on this field using an array of option names and their values.
array | $options |
resetFieldsSet() : \Dewdrop\Fields\FieldAbstract
Can be used to break the association between this field and the set it was originally added to so that it can be associated with a different set.
setFieldsSet(\Dewdrop\Fields $fieldsSet) : \Dewdrop\Fields\FieldAbstract
Set the FieldsSet that contains this FieldAbstract object. Note that once this is set, it cannot be changed without first calling resetFieldsSet().
This is done to ensure that when chaining calls between this field and its containing set, the same set is always used. This avoids inconsistent or unpredictable cases where the field is added to one set but later customized on a derivitive set.
\Dewdrop\Fields | $fieldsSet |
add(mixed $field, string $modelName = null) : mixed
When calling add() on this field, it will delegate the call back up to the associated \Dewdrop\Fields object. This allows for a very fluid method chaining style when defining a large set of fields.
mixed | $field | |
string | $modelName |
setVisible(mixed $visible) : \Dewdrop\Fields\FieldAbstract
Set whether this field should be visible. Can supply either a boolean, in which case true means globally allowed and false means globally forbidden, or an array of roles/capabilities for which it is allowed.
mixed | $visible |
getVisibleSetting() : array
Get the current setting for this field's visibility. Will return an empty array if completely forbidden, an array containing only \Dewdrop\Fields\FieldAbstract::AUTHORIZATION_ALLOW_ALL if completely allowed, or an array containing 1 or more roles if a custom setting is applied.
isVisible(\Dewdrop\Fields\UserInterface $user = null) : boolean
Check to see if this field is visible. If no user is supplied, this method will only return true when the field is visible globally. Otherwise, it will check to see if the user has a matching role/capability.
\Dewdrop\Fields\UserInterface | $user |
allowVisibilityForRole(mixed $role) : \Dewdrop\Fields\FieldAbstract
Enable visibility for a specific role. You can call this multiple times to configure the field for all roles, or call setVisible() once with an array of roles.
mixed | $role |
forbidVisibilityForRole(mixed $role) : \Dewdrop\Fields\FieldAbstract
Forbid visibility for a specific role.
mixed | $role |
setSortable(mixed $sortable) : \Dewdrop\Fields\FieldAbstract
Set whether this field should be sortable. Can supply either a boolean, in which case true means globally allowed and false means globally forbidden, or an array of roles/capabilities for which it is allowed.
mixed | $sortable |
getSortableSetting() : array
Get the current setting for this field's sortability. Will return an empty array if completely forbidden, an array containing only \Dewdrop\Fields\FieldAbstract::AUTHORIZATION_ALLOW_ALL if completely allowed, or an array containing 1 or more roles if a custom setting is applied.
isSortable(\Dewdrop\Fields\UserInterface $user = null) : boolean
Check to see if this field is sortable. If no user is supplied, this method will only return true when the field is visible globally. Otherwise, it will check to see if the user has a matching role/capability.
\Dewdrop\Fields\UserInterface | $user |
allowSortingForRole(mixed $role) : \Dewdrop\Fields\FieldAbstract
Enable sorting for a specific role. You can call this multiple times to configure the field for all roles, or call setSortable() once with an array of roles.
mixed | $role |
forbidSortingForRole(mixed $role) : \Dewdrop\Fields\FieldAbstract
Forbid sorting for a specific role.
mixed | $role |
setFilterable(mixed $filterable) : \Dewdrop\Fields\FieldAbstract
Set whether this field should be filterable. Can supply either a boolean, in which case true means globally allowed and false means globally forbidden, or an array of roles/capabilities for which it is allowed.
mixed | $filterable |
getFilterableSetting() : array
Get the current setting for this field's filterability. Will return an empty array if completely forbidden, an array containing only \Dewdrop\Fields\FieldAbstract::AUTHORIZATION_ALLOW_ALL if completely allowed, or an array containing 1 or more roles if a custom setting is applied.
isFilterable(\Dewdrop\Fields\UserInterface $user = null) : boolean
Check to see if this field is filterable. If no user is supplied, this method will only return true when the field is visible globally. Otherwise, it will check to see if the user has a matching role/capability.
\Dewdrop\Fields\UserInterface | $user |
allowFilteringForRole(mixed $role) : \Dewdrop\Fields\FieldAbstract
Enable filtering for a specific role. You can call this multiple times to configure the field for all roles, or call setFilterable() once with an array of roles.
mixed | $role |
forbidFilteringForRole(mixed $role) : \Dewdrop\Fields\FieldAbstract
Forbid filtering for a specific role.
mixed | $role |
setEditable(mixed $editable) : \Dewdrop\Fields\FieldAbstract
Set whether this field should be editable. Can supply either a boolean, in which case true means globally allowed and false means globally forbidden, or an array of roles/capabilities for which it is allowed.
mixed | $editable |
getEditableSetting() : array
Get the current setting for this field's editability. Will return an empty array if completely forbidden, an array containing only \Dewdrop\Fields\FieldAbstract::AUTHORIZATION_ALLOW_ALL if completely allowed, or an array containing 1 or more roles if a custom setting is applied.
isEditable(\Dewdrop\Fields\UserInterface $user = null) : boolean
Check to see if this field is editable. If no user is supplied, this method will only return true when the field is visible globally. Otherwise, it will check to see if the user has a matching role/capability.
\Dewdrop\Fields\UserInterface | $user |
allowEditingForRole(mixed $role) : \Dewdrop\Fields\FieldAbstract
Enable editing for a specific role. You can call this multiple times to configure the field for all roles, or call setEditable() once with an array of roles.
mixed | $role |
forbidEditingForRole(mixed $role) : \Dewdrop\Fields\FieldAbstract
Forbid editing for a specific role.
mixed | $role |
assignHelperCallback(string $helperName, callable $callable) : \Dewdrop\Fields\FieldAbstract
Assing a custom callback for use with the named field helper.
string | $helperName | |
callable | $callable |
removeHelperCallback(string $helperName) : \Dewdrop\Fields\FieldAbstract
Remove the custom callback with the supplied helper name.
string | $helperName |
allowPermissionForRole(string $permissionProperty, mixed $role) : \Dewdrop\Fields\FieldAbstract
Allow the permission for the specified role.
string | $permissionProperty | |
mixed | $role |
forbidPermissionForRole(string $permissionProperty, mixed $role) : \Dewdrop\Fields\FieldAbstract
Forbid the permission for the specified role.
string | $permissionProperty | |
mixed | $role |
checkPermissionForUser(string $permissionProperty, \Dewdrop\Fields\UserInterface $user = null) : boolean
Check to see if the UserInterface can use the specific capability.
We return true if the capability is available to everyone or if the user has a role allowed for that permission/capability.
string | $permissionProperty | |
\Dewdrop\Fields\UserInterface | $user |
setPermission(string $permissionProperty, mixed $value) : \Dewdrop\Fields\FieldAbstract
Set the permission. If true, it's allowed for everyone. If false, it's forbidden for everyone. Otherwise, we expect an array of roles for which the capability is allowed.
string | $permissionProperty | |
mixed | $value |