\Dewdrop\Fields\FilterVisibility

This filter will allow certain fields, which would otherwise be visible based upon their actual definition/permissions, to be excluded in certain contexts. The most common use of this filter is to allow a user to select which particular columns they'd like to be visible in a listing table.

Summary

Methods
Properties
Constants
__construct()
setDefaultFields()
setUser()
getUser()
canBeFilteredByUser()
save()
load()
apply()
No public properties found
No constants found
deleteExistingValuesForSave()
selectForLoad()
getUserReferenceValues()
$defaultFields
$selections
$componentName
$dbAdapter
$dbTableName
$user
N/A
No private methods found
No private properties found
N/A

Properties

$defaultFields

$defaultFields : array

The fields (by ID) that should be included by default.

Type

array

$selections

$selections : array

The selections the user has made (stored in dewdrop_visible_fields).

Type

array

$componentName

$componentName : string

The component name that should be used when storing user selections.

Type

string

$dbAdapter

$dbAdapter : \Dewdrop\Db\Adapter

The DB adapter used for DB access.

Type

\Dewdrop\Db\Adapter

$dbTableName

$dbTableName : string

The name of the DB table where user selections are stored.

Type

string

$user

$user : \Dewdrop\Db\Row

A DB row representing the currently logged-in user.

Type

\Dewdrop\Db\Row

Methods

__construct()

__construct(string  $componentName, \Dewdrop\Db\Adapter  $dbAdapter, string  $dbTableName = 'dewdrop_visible_fields') 

Provide the information needed to store selections in the database.

Typically, you won't need to specify the database table name, except in testing.

Parameters

string $componentName
\Dewdrop\Db\Adapter $dbAdapter
string $dbTableName

setDefaultFields()

setDefaultFields(array|\Dewdrop\Fields  $defaultFields) : \Dewdrop\Fields\Filter\Visibility

Set the fields that should be displayed by default (if no user selections have been made). Your array can contain either FieldInterface objects or string IDs for those fields.

Parameters

array|\Dewdrop\Fields $defaultFields

Returns

\Dewdrop\Fields\Filter\Visibility

setUser()

setUser(\Dewdrop\Db\Row  $user) : $this

Set the logged-in user that can be used when saving/loading per-user settings.

Parameters

\Dewdrop\Db\Row $user

Returns

$this

getUser()

getUser() : \Dewdrop\Db\Row

Get the logged-in user row object for use when loading and saving per-user filter settings. Will attempt to retrieve this from Pimple if not set explicitly.

Returns

\Dewdrop\Db\Row

canBeFilteredByUser()

canBeFilteredByUser() : boolean

Detect whether this filter can be restricted to per-user settings or only supports global settings.

Returns

boolean

save()

save(\Dewdrop\Fields  $fields, array  $selections, boolean  $applyToAllUsers = false) : void

Save the user's visible field selections back to the database. We expect the selections array to just contain field IDs. Only those that match IDs of fields in the supplied Fields object will be saved.

Parameters

\Dewdrop\Fields $fields
array $selections
boolean $applyToAllUsers

load()

load() : array

Load the current selections from the database. Will return an array of field IDs.

Returns

array

apply()

apply(\Dewdrop\Fields  $fields) : \Dewdrop\Fields

Apply the field to the supplied set of fields. If after filtering no fields are left, we'll return the full set of fields as a fallback.

If no preferences are saved to the DB, we will use either pre-defined defaults (@see setDefaults()) or the first 4 fields.

Parameters

\Dewdrop\Fields $fields

Returns

\Dewdrop\Fields

deleteExistingValuesForSave()

deleteExistingValuesForSave(boolean  $applyToAllUsers) 

While saving, delete existing values. If the new values will be limited to the logged-in user, we only delete any settings specific to that user. Otherwise, we also delete any current values not specific to a user.

Parameters

boolean $applyToAllUsers

selectForLoad()

selectForLoad() : \Dewdrop\Db\Select

Create a Select object for use when loading filter settings from the DB.

Returns

\Dewdrop\Db\Select

getUserReferenceValues()

getUserReferenceValues() : array

Get the values for any foreign keys in the DB table that reference the user object's table. Allows the filter to be applied on a per-user basis.

Returns

array