\Dewdrop\Fields\FilterGroups

Filter a set of fields into a \Dewdrop\Fields\GroupedFields object.

Components that understand the additional APIs provided by \Dewdrop\Fields\GroupedFields object provides can then display their fields in user-defined groups, while components that are unaware of those APIs can continue using it just like a normal \Dewdrop\Fields object that is sorted in a particular order.

Summary

Methods
Properties
Constants
__construct()
getConfigForFields()
load()
save()
deleteCurrentSettings()
apply()
No public properties found
UNGROUPED
saveUngroupedList()
saveGroups()
saveFields()
No protected properties found
N/A
No private methods found
$componentName
$dbAdapter
$loadedDbData
N/A

Constants

UNGROUPED

UNGROUPED

A constant to help clarify that group zero is always index zero.

Properties

$componentName

$componentName : string

The fully qualified component name to use when storing sorting and grouping preferences in the DB.

Type

string

$dbAdapter

$dbAdapter : \Dewdrop\Db\Adapter

The DB adapter that can be used for loading and saving preferences.

Type

\Dewdrop\Db\Adapter

$loadedDbData

$loadedDbData : array

A variable where we can store the data loaded from the DB so that we do not have to query for it multiple times on a single request.

Type

array

Methods

__construct()

__construct(string  $componentName, \Dewdrop\Db\Adapter  $dbAdapter) 

Provide a component name and DB adpater that can be used when saving and loading preferences frmo the database.

Parameters

string $componentName
\Dewdrop\Db\Adapter $dbAdapter

getConfigForFields()

getConfigForFields(\Dewdrop\Fields  $fields) : array

Get an array representation of the current preferences. This is typically used by a UI/form designed to allow the user to modify the grouping and sorting preferences for a component. The resulting array will be in the following format:

array(
    'title'    => 'Group Title',
    'caption' => 'Group caption explaining what it is.  Usually only on unsorted group.',
    'fields'  => array(
        array(
            'id'    => 'products:name',
            'label' => 'Name'
        ),
        array(
            'id'    => 'products:price',
            'label' => 'Price'
        )
    )
)

Parameters

\Dewdrop\Fields $fields

Returns

array

load()

load() : array

Load the current preferences for this component from the database. The information will be returned in this format:

array(
    array(
        'field_id'    => 'products:name',
        'group_title' => 'My Field Group',
        'group_id'    => 2
    )
)

The fields and groups will be sorted when returned from this method, so can iterate over it without having to first sort it.

Returns

array

save()

save(array  $groupConfig) : \Dewdrop\Fields\Filter\Groups

Save the supplied configuration to the database. We expect the info to be provided in this format:

array(
    array(
        'title' => 'My Group Title',
        'fields' => array(
            array('id' => 'products:name'),
            array('id' => 'products:price')
        )
    )
)

Parameters

array $groupConfig

Returns

\Dewdrop\Fields\Filter\Groups

deleteCurrentSettings()

deleteCurrentSettings() : void

Delete any existing settings from the database. Done inside a transaction while saving new settings.

apply()

apply(\Dewdrop\Fields  $currentFields) : \Dewdrop\Fields\GroupedFields

Apply the filter to the supplied set of fields. In return, you'll end up with a \Dewdrop\Fields\GroupedFields object that reflects the sort order and grouping preferences contained in this filter. You can use that object either as a normal \Dewdrop\Fields object or you can call getGroups() on it to get the fields back in their assigned groups.

Parameters

\Dewdrop\Fields $currentFields

Returns

\Dewdrop\Fields\GroupedFields

saveUngroupedList()

saveUngroupedList(array  $groupConfig) : void

If there is only one group in the supplied config, we know that is the "ungrouped" set of fields, which is always included. So, we can save all those fields with a null group ID.

Parameters

array $groupConfig

saveGroups()

saveGroups(array  $groupConfig) : void

Save multiple groups of fields to the database.

Parameters

array $groupConfig

saveFields()

saveFields(array  $fields, integer  $groupId) : void

Save the fields to the DB using the supplied group ID, which can be null in the case of un-grouped fields.

Parameters

array $fields
integer $groupId