Class Facets
Class for creating a facets argument, used for check-box navigation. It also has support
for parsing and toggling facet values, so it can be used to keep track of
selection changes.
Example:
$f = (new Facets('color', 'yellow', 'blue'))->add('brand', 'nike');
$panelArguments = new ArgMap();
$panelArguments['facets'] = $f;
If it is convenient for your scenario you can serialize the current selected values by converting it to string
and store them in the browser. When a check-box is clicked, deserialize it afterwards like this:
$f = Facets::parse($facetsString);
Then update it with the last click and send a new request:
$f = $f->toggle($clickedAttribute, $clickedValue);
$panelArguments['facets'] = $f;
Note that Facets are immutable and all methods return new Facets objects.
Methods summary
public
|
#
__construct( attribute $attribute = null, values $values = null )
Create a new empty Facets, or if provided, with the given attribute and values.
Create a new empty Facets, or if provided, with the given attribute and values.
Parameters
- $attribute
- the attribute name
- $values
- an indexed array of values, or one or more strings.
Throws
|
public
Apptus\ESales\Connector\Facets
|
#
add( attribute $attribute, values $values )
Return a new Facets with the given attribute and values added.
Return a new Facets with the given attribute and values added.
Parameters
- $attribute
- the attribute name
- $values
- an indexed array of values, or one or more strings.
Returns
Throws
|
public
Apptus\ESales\Connector\Facets
|
#
toggle( attribute $attribute, value $value )
Toggle the given attribute and value.
Toggle the given attribute and value.
Parameters
- $attribute
- the attribute to toggle
- $value
- the value for the given attribute to toggle
Returns
Throws
|
public
Apptus\ESales\Connector\Facets
|
#
addRange( attribute $attribute, min $min, min $max )
Return a new Facets with the given attribute range added. If a range of the
current attribute already existed, it will replace the existing one. Note that
facet ranges are inclusive.
Return a new Facets with the given attribute range added. If a range of the
current attribute already existed, it will replace the existing one. Note that
facet ranges are inclusive.
Parameters
- $attribute
- the attribute
- $min
- the min value of the range
- $max
- the max value of the range
Returns
Throws
|
public
Apptus\ESales\Connector\Facets
|
#
remove( attribute $attribute )
Return a new Facets with the given attribute removed.
Return a new Facets with the given attribute removed.
Parameters
Returns
Throws
|
public static
Apptus\ESales\Connector\Facets
|
#
parse( source $source )
Create a Facets object from the source string.
Create a Facets object from the source string.
Parameters
- $source
- the string to parse
Returns
|
public
string
|
#
__toString( )
Builds and returns a string on the facet argument format.
Builds and returns a string on the facet argument format.
Returns
string a string on the facet argument format
|