Gets range values.

@param AjaxChoiceLoaderInterface $choiceLoader The ajax choice loader

@return int[] The startTo and endTo
1136
protected static function getRangeValues(AjaxChoiceLoaderInterface $choiceLoader)
    {
        $startTo = ($choiceLoader->getPageNumber() - 1) * $choiceLoader->getPageSize();
        $startTo = $startTo < 0 ? 0 : $startTo;
        $endTo = $startTo + $choiceLoader->getPageSize();

        if (0 >= $choiceLoader->getPageSize()) {
            $endTo = $choiceLoader->getSize();
        }

        if ($endTo > $choiceLoader->getSize()) {
            $endTo = $choiceLoader->getSize();
        }

        return [$startTo, $endTo];
    }
177552
public function configureOptions (OptionsResolver $resolver)
    {
        $allRoles = $this->roleCollection->getAllAvailableRoles();
        $allRoleKeys = array_keys($allRoles);

        $resolver->setDefaults([
            "roles_with_tags" => [],
            "choices" => function(Options $options) use ($allRoleKeys, $allRoles)
            {
                // if no tags are selected, just return all roles
                if (empty($options["roles_with_tags"]))
                {
                    return array_combine($allRoleKeys, $allRoleKeys);
                }

                // if tags are selected, only use the choices with the given tags
                $choices = [];

                foreach ($allRoles as $roleKey => $role)
                {
                    if (!empty(array_intersect($options["roles_with_tags"], $role->getTags())))
                    {
                        $choices[$roleKey] = $roleKey;
                    }
                }

                return $choices;
            },
            "choices_as_values" => true,
            "choice_label" => function ($choiceValue, $choiceKey, $index) use ($allRoles)
            {
                return $allRoles[$choiceKey]->getTitle();
            },
            "choice_attr" => function ($choiceValue, $choiceKey, $index) use ($allRoles)
            {
                return [
                    "data-role-description" => $allRoles[$choiceKey]->getDescription(),
                ];
            },
        ]);

        $resolver->setAllowedTypes("roles_with_tags", ["array"]);
    }
142448
public function getChoicesAsEmailUsername(array &$choices)
    {
        $ret = [];
        foreach ($choices as $item) {
            $ret[] = sprintf('%s (%s)', $item->getEmail(), $item->getUsername());
        }

        return $ret;
    }
474647
public function getEventRange(array $options = []): array
    {
        $result = [];

        if (empty($options['period'])) {
            return $result;
        }

        //@NOTE: sqlite doesn't support date_format or month functions
        if (!empty($options['period']['start_date'])) {
            $result['start'] = [
                'MONTH(start_date) >=' => date('m', strtotime($options['period']['start_date']))
            ];
        }

        if (!empty($options['period']['end_date'])) {
            $result['end'] = [
                'MONTH(end_date) <=' => date('m', strtotime($options['period']['end_date']))
            ];
        }

        return $result;
    }
999035
private function getRangeWidget()
    {
        if ('selection' === $this->get('rangemode')) {
            // Get all range options.
            $rangeOptions = [];

            foreach (StringUtil::deserialize($this->get('range_selection'), true) as $rangeItem) {
                $rangeOptions[$rangeItem['range']] = $rangeItem['range'] . 'km';
            }

            $rangeWidget = [
                'label'     => [
                    ($this->get('range_label') ?: $this->getAttributeName() . ' Range '),
                    'GET: ' . $this->getParamNameRange()
                ],
                'inputType' => 'select',
                'options'   => $rangeOptions,
                'eval'      => [
                    'colname'            => $this->getColname(),
                    'urlparam'           => $this->getParamNameRange(),
                    'template'           => $this->get('range_template')
                ]
            ];

            return $rangeWidget;
        }

        if ('free' === $this->get('rangemode')) {
            $rangeWidget = [
                'label'     => [
                    ($this->get('range_label') ?: $this->getAttributeName() . ' Range '),
                    'GET: ' . $this->getParamNameRange()
                ],
                'inputType' => 'text',
                'eval'      => [
                    'colname'     => $this->getColname(),
                    'urlparam'    => $this->getParamNameRange(),
                    'template'    => $this->get('range_template'),
                    'placeholder' => $this->get('range_placeholder')
                ]
            ];

            return $rangeWidget;
        }

        return null;
    }
1062055
public function getLoaders()
    {
        $loaders = array();
        foreach ($this->validators as $validator) {
            $loaders[$validator->getName()] = $validator->getLoader();
        }

        return $loaders;
    }
482127
private function getSortFieldChoices(): array
    {
        $choices = [];
        foreach ($this->getSortField() as $label => $value) {
            $choices[$label] = $value;
        }

        return $choices;
    }
627876
public static function getChoices() {
        return [
            self::MARITAL_STATUS_EMPTY    => "choices.marital-status.empty",
            self::MARITAL_STATUS_SINGLE   => "choices.marital-status.single",
            self::MARITAL_STATUS_PACS     => "choices.marital-status.pacs",
            self::MARITAL_STATUS_MARRIED  => "choices.marital-status.married",
            self::MARITAL_STATUS_WIDOWER  => "choices.marital-status.widower",
            self::MARITAL_STATUS_DIVORCED => "choices.marital-status.divorced",
        ];
    }
1092043
public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $choiceList = new AjaxChoiceList(array());
        
        $resolver->setDefaults(array(
            'first_options'  => array(),
            'second_options' => array(),
            'error_bubbling' => false,
            'first_name' => 'first_name',
            'second_name' => 'second_name', 
            'widget' => 'choice',
            'translation_domain' => 'ThraceFormBundle',
            'multiple' => false,
            'choices' => array(),
            'configs' => array(),
        ));
        
        $resolver->setNormalizers(array(
            'first_options' => function (Options $options, $value){
                $value['choices'] = $options->get('choices');
                
                return $value;
            },
            'second_options' => function (Options $options, $value) use ($choiceList){
                $value['choice_list'] = $choiceList;
                $value['multiple'] = $options->get('multiple');
                
                return $value;
            },
            'configs' => function (Options $options, $value){
                $value['first_name'] = $options->get('first_name');
                $value['second_name'] = $options->get('second_name');
                $value['dependent_source'] = $options->get('dependent_source');
                $value['multiple'] = $options->get('multiple');

                return $value;
            },
        ));
        
        $resolver->setRequired(array('dependent_source'));
        
        $resolver->setAllowedValues(array(
            'widget' => array('choice')
        ));
        
        $resolver->setAllowedTypes(array(
            'multiple' => array('bool'),     
            'choices' => array('array'),   
            'dependent_source' => array('string'),   
        ));
    }
559326
public function getFormattedChoices(array $choices, $position, $selected)
    {
        $lines = [];

        foreach ($choices as $index => $choice) {
            $state = in_array($choice, $selected)
                ? self::CHOICE_SELECTED
                : self::CHOICE_NORMAL;

            $cursor = $index === $position
                ? self::CHOICE_HOVERED
                : self::CHOICE_NORMAL;

            // select which style to use
            $line = $this->style[$state][$cursor];

            // add the fancy fish eye symbol to make things prettier
            $choice = '  ' . unicode_to_string('\u25C9') . '  ' . $choice;

            $lines[] = sprintf($line, $this->fitText($this->window->getWidth(), $choice));
        }

        return $lines;
    }
1159006
private function serializeChoices(ChoiceQuestion $choiceQuestion, array $options = [])
    {
        return array_map(function (Choice $choice) use ($options) {
            $choiceData = $this->contentSerializer->serialize($choice, $options);
            // TODO : finish content management. For now the choice id overlaps the content ID.
            $choiceData['id'] = $choice->getUuid();

            return $choiceData;
        }, $choiceQuestion->getChoices()->toArray());
    }
698124
public function getFilterOptionsForDcGeneral()
    {
        if (!$this->isFilterOptionRetrievingPossible(null)) {
            return [];
        }

        $originalLanguage       = $GLOBALS['TL_LANGUAGE'];
        $GLOBALS['TL_LANGUAGE'] = $this->getMetaModel()->getActiveLanguage();

        $filter = $this->getSelectMetaModel()->getEmptyFilter();

        $this->buildFilterRulesForFilterSetting($filter);

        $objItems = $this->getSelectMetaModel()->findByFilter(
            $filter,
            $this->getSortingColumn(),
            0,
            0,
            'ASC',
            [$this->getValueColumn(), $this->getIdColumn()]
        );

        $GLOBALS['TL_LANGUAGE'] = $originalLanguage;

        return $this->convertItemsToFilterOptions($objItems, $this->getValueColumn(), $this->getIdColumn());
    }
1092149
public static function getEntityChoice(SymfonyStyle $helper, $entities, $question = 'Please choose')
    {
        $choice = [];
        foreach ($entities as $entity) {
            $choice[$entity->getId()] = strval($entity);
        }

        if (0 === count($choice)) {
            throw new \RuntimeException('No choices found!');
        }

        $selection = $helper->choice($question, $choice);
        $selectionId = array_search($selection, $choice);

        return CollectionUtility::find($entities, $selectionId);
    }
295562
public function buildChoicesFromSprite()
    {
        $sprite = $this->sprite();

        if (!file_exists($sprite)) {
            return [];
        }

        $spriteString = file_get_contents($sprite);

        try {
            $xml = new SimpleXMLElement($spriteString);

            $choices = [];

            foreach ($xml->symbol as $ident => $node) {
                $id = (string)$node->attributes()->id;

                $choices[$id] = $id;
            }

            return $choices;
        } catch (Exception $e) {
            $this->logger->error('Could not parse sprite. Invalid SVG / XML.');
            return [];
        }
    }
713966
public function choices()
    {
        $choices = [];

        $proto = $this->proto();
        if (!$proto->source()->tableExists()) {
            return $choices;
        }

        $loader = $this->collectionModelLoader();

        $collection = new HierarchicalCollection($loader->load(), false);
        $collection->setPage($loader->page())
                   ->setNumPerPage($loader->numPerPage())
                   ->sortTree();

        return $this->parseChoices($collection);
    }
79799
protected function getOperator($type)
    {
        $choices = [
            DateType::TYPE_NULL => 'equals',
            DateType::TYPE_NOT_NULL => 'notEqual',
            DateType::TYPE_EQUAL => 'equals',
            DateType::TYPE_GREATER_EQUAL => 'gte',
            DateType::TYPE_GREATER_THAN => 'gt',
            DateType::TYPE_LESS_EQUAL => 'lte',
            DateType::TYPE_LESS_THAN => 'lt',
        ];

        return $choices[(int) $type];
    }
328699
public function getFirstSelectedOption()
	{
		foreach ( $this->getOptions() as $option ) {
			if ( $option->isSelected() ) {
				return $option;
			}
		}

		throw new SelectException('No options are selected', SelectException::TYPE_NOT_SELECTED);
	}