W3cubDocs

/Symfony 2.7

Symfony\Bridge\Propel1\Form\ChoiceList\ModelChoiceList

class ModelChoiceList extends ObjectChoiceList

A choice list for object choices based on Propel model.

Methods

__construct(string $class, string $labelPath = null, array $choices = null, ModelCriteria $queryObject = null, string $groupPath = null, array|ModelCriteria $preferred = array(), PropertyAccessorInterface $propertyAccessor = null, string $useAsIdentifier = null)

Constructor.

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 $models)

Returns the values corresponding to the given choices.

array getIndicesForChoices(array $models)

Returns the indices corresponding to the given choices.

array getIndicesForValues(array $values)

Returns the indices corresponding to the given values.

string getClass()

Returns the class name of the model.

Details

public __construct(string $class, string $labelPath = null, array $choices = null, ModelCriteria $queryObject = null, string $groupPath = null, array|ModelCriteria $preferred = array(), PropertyAccessorInterface $propertyAccessor = null, string $useAsIdentifier = null)

Constructor.

Parameters

string $class The FQCN of the model class to be loaded.
string $labelPath A property path pointing to the property used for the choice labels.
array $choices An optional array to use, rather than fetching the models.
ModelCriteria $queryObject The query to use retrieving model data from database.
string $groupPath A property path pointing to the property used to group the choices.
array|ModelCriteria $preferred The preferred items of this choice. Either an array if $choices is given, or a ModelCriteria to be merged with the $queryObject.
PropertyAccessorInterface $propertyAccessor The reflection graph for reading property paths.
string $useAsIdentifier a custom unique column (eg slug) to use instead of primary key.

Exceptions

MissingOptionsException In case the class parameter is empty.
InvalidOptionsException In case the query class is not found.

See also

\Symfony\Bridge\Propel1\Form\Type\ModelType How to use the preferred choices.

public array getChoices()

Returns the list of choices

Return Value

array The choices with their indices as keys

public array getValues()

Returns the values for the choices

Return Value

array The values with the corresponding choice indices as keys

public array getPreferredViews()

Returns the choice views of the preferred choices as nested array with the choice groups as top-level keys.

Example:

array( 'Group 1' => array( 10 => ChoiceView object, 20 => ChoiceView object, ), 'Group 2' => array( 30 => ChoiceView object, ), )

Return Value

array A nested array containing the views with the corresponding choice indices as keys on the lowest levels and the choice group names in the keys of the higher levels

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:

array( 'Group 1' => array( 10 => ChoiceView object, 20 => ChoiceView object, ), 'Group 2' => array( 30 => ChoiceView object, ), )

Return Value

array A nested array containing the views with the corresponding choice indices as keys on the lowest levels and the choice group names in the keys of the higher levels

public array getChoicesForValues(array $values)

Returns the choices corresponding to the given values.

The choices can have any data type.

The choices must be returned with the same keys and in the same order as the corresponding values in the given array.

Parameters

array $values An array of choice values. Not existing values in this array are ignored

Return Value

array An array of choices with ascending, 0-based numeric keys

public array getValuesForChoices(array $models)

Returns the values corresponding to the given choices.

The values must be strings.

The values must be returned with the same keys and in the same order as the corresponding choices in the given array.

Parameters

array $models

Return Value

array An array of choice values with ascending, 0-based numeric keys

public array getIndicesForChoices(array $models)

Returns the indices corresponding to the given choices.

The indices must be positive integers or strings accepted by {@link FormConfigBuilder::validateName()}.

The index "placeholder" is internally reserved.

The indices must be returned with the same keys and in the same order as the corresponding choices in the given array.

Parameters

array $models

Return Value

array An array of indices with ascending, 0-based numeric keys

public array getIndicesForValues(array $values)

Returns the indices corresponding to the given values.

The indices must be positive integers or strings accepted by {@link FormConfigBuilder::validateName()}.

The index "placeholder" is internally reserved.

The indices must be returned with the same keys and in the same order as the corresponding values in the given array.

Parameters

array $values An array of choice values. Not existing values in this array are ignored

Return Value

array An array of indices with ascending, 0-based numeric keys

public string getClass()

Returns the class name of the model.

Return Value

string

© 2004–2016 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/2.7/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.html