class ChoiceList implements ChoiceListInterface
A choice list for choices of arbitrary data types.
Choices and labels are passed in two arrays. The indices of the choices
and the labels should match. Choices may also be given as hierarchy of
unlimited depth by creating nested arrays. The title of the sub-hierarchy
can be stored in the array key pointing to the nested array. The topmost
level of the hierarchy may also be a \Traversable.
<code>
$choices = array(true, false);
$labels = array('Agree', 'Disagree');
$choiceList = new ChoiceList($choices, $labels);
</code>
Methods
|
__construct(array|Traversable $choices, array $labels, array $preferredChoices = array())
Creates a new choice list. |
||
| array |
getChoices()
Returns the list of choices |
|
| array |
getValues()
Returns the values for the choices |
|
| array |
getPreferredViews()
Returns the choice views of the preferred choices as nested array with the choice groups as top-level keys. |
|
| array |
getRemainingViews()
Returns the choice views of the choices that are not preferred as nested array with the choice groups as top-level keys. |
|
| array |
getChoicesForValues(array $values)
Returns the choices corresponding to the given values. |
|
| array |
getValuesForChoices(array $choices)
Returns the values corresponding to the given choices. |
|
| array |
getIndicesForChoices(array $choices)
Returns the indices corresponding to the given choices. |
|
| array |
getIndicesForValues(array $values)
Returns the indices corresponding to the given values. |
Details
at line 84
public
__construct(array|Traversable $choices, array $labels, array $preferredChoices = array())
Creates a new choice list.
at line 121
public array
getChoices()
Returns the list of choices
at line 129
public array
getValues()
Returns the values for the choices
at line 137
public array
getPreferredViews()
Returns the choice views of the preferred choices as nested array with the choice groups as top-level keys.
Example:
<source>
array(
'Group 1' => array(
10 => ChoiceView object,
20 => ChoiceView object,
),
'Group 2' => array(
30 => ChoiceView object,
),
)
</source>
at line 145
public array
getRemainingViews()
Returns the choice views of the choices that are not preferred as nested array with the choice groups as top-level keys.
Example:
<source>
array(
'Group 1' => array(
10 => ChoiceView object,
20 => ChoiceView object,
),
'Group 2' => array(
30 => ChoiceView object,
),
)
</source>
at line 153
public array
getChoicesForValues(array $values)
Returns the choices corresponding to the given values.
at line 177
public array
getValuesForChoices(array $choices)
Returns the values corresponding to the given choices.
at line 201
public array
getIndicesForChoices(array $choices)
Returns the indices corresponding to the given choices.
at line 225
public array
getIndicesForValues(array $values)
Returns the indices corresponding to the given values.