Returns HTML to display choices result
@deprecated since 3.2
@param object $choices
@return string
483543
public function display_publish_anonymous_vertical($choices) {
        global $CHOICE_COLUMN_WIDTH;
        debugging(__FUNCTION__.'() is deprecated. Please use mod_choice_renderer::display_publish_anonymous() instead.',
                DEBUG_DEVELOPER);
        return $this->display_publish_anonymous($choices, CHOICE_DISPLAY_HORIZONTAL);
    }
764296
public function choice($question, $choices = array(), $allowedMultiple = false)
    {
        $this->output->writeln($question);

        $this->output->writeln(join(',', $choices));

        $answer = $this->input->getInput();

        $valid = $this->validateChoices($answer, $choices, $allowedMultiple);

        if ($valid !== false) {
            return $valid;
        }

        $this->output->writeln($this->wrongChoiceErrorMessage);

        return false;
    }
588442
public function errors($errors) {
        $html = '';
        foreach ($errors as $error) {
            $html .= $this->output->notification($error);
        }
        return $html;
    }
215611
public static function menu(array $items, $htmlOptions = array(), $depth = 0)
    {
        // todo: consider making this method protected.
        if (!empty($items)) {
            $htmlOptions['role'] = 'menu';
            $output = self::openTag('ul', $htmlOptions);
            foreach ($items as $itemOptions) {
                if (is_string($itemOptions)) {
                    if ($itemOptions == '---') {
                        $output .= self::menuDivider();
                    } else {
                        $output .= $itemOptions;
                    }
                } else {
                    if (TbArray::popValue('visible', $itemOptions, true)  === false) {
                        continue;
                    }
                    // todo: consider removing the support for htmlOptions.
                    $options = TbArray::popValue('htmlOptions', $itemOptions, array());
                    if (!empty($options)) {
                        $itemOptions = TbArray::merge($options, $itemOptions);
                    }
                    $label = TbArray::popValue('label', $itemOptions, '');
                    if (TbArray::popValue('active', $itemOptions, false)) {
                        self::addCssClass('active', $itemOptions);
                    }
                    if (TbArray::popValue('disabled', $itemOptions, false)) {
                        self::addCssClass('disabled', $itemOptions);
                    }
                    if (!isset($itemOptions['linkOptions'])) {
                        $itemOptions['linkOptions'] = array();
                    }
                    $icon = TbArray::popValue('icon', $itemOptions);
                    if (!empty($icon)) {
                        $label = self::icon($icon) . ' ' . $label;
                    }
                    $items = TbArray::popValue('items', $itemOptions, array());
                    $url = TbArray::popValue('url', $itemOptions, false);
                    if (empty($items)) {
                        if (!$url) {
                            $output .= self::menuHeader($label);
                        } else {
                            $itemOptions['linkOptions']['tabindex'] = -1;
                            $output .= self::menuLink($label, $url, $itemOptions);
                        }
                    } else {
                        $output .= self::menuDropdown($label, $url, $items, $itemOptions, $depth);
                    }
                }
            }
            $output .= '</ul>';
            return $output;
        } else {
            return '';
        }
    }
1084342
function renderChoices(choices, pointer) {
  var output = '';

  choices.forEach(function(choice, i) {
    output += '\n  ';

    if (choice.type === 'separator') {
      output += ' ' + choice;
      return;
    }

    var choiceStr = choice.key + ') ' + choice.name;
    if (pointer === choice.key) {
      choiceStr = utils.chalk.cyan(choiceStr);
    }
    output += choiceStr;
  });

  return output;
}
1026870
public function display_publish_anonymous_horizontal($choices) {
        global $CHOICE_COLUMN_HEIGHT;
        debugging(__FUNCTION__.'() is deprecated. Please use mod_choice_renderer::display_publish_anonymous() instead.',
                DEBUG_DEVELOPER);
        return $this->display_publish_anonymous($choices, CHOICE_DISPLAY_VERTICAL);
    }
914832
public function display()
    {
        if (!$this->isVisible()) { //return nothing if it's not visible
            return "";
        }
        $content = Html::get()->link($this->getURL(), $this->getIcon() . $this->translate($this->label), $this->linkHtmlOptions);
        $submenu = "";
        $anySelected = false;
        if (count($this->items)) {
            $this->htmlOptions['class'] = (isset($this->htmlOptions['class']) ? $this->htmlOptions['class'] . ' ' : '') . 'm-menu-dropdown';
            $anySelected = false;
            $anyVisible = false;
            foreach ($this->items as $item) {
                /* @var $item Label */
                $submenu .= $item->display();
                $anySelected = $anySelected || $item->isSelected();
                $anyVisible = $anyVisible || $item->isVisible();
            }
            if ($anyVisible)
                $submenu = Html::get()->tag('ul', $submenu);
            else
                $submenu = "";
            if ($anySelected) {
                if (isset($this->htmlOptions['class'])) {
                    $this->htmlOptions['class'] .= ' selected';
                } else {
                    $this->htmlOptions['class'] = 'selected';
                }
            }
        }

        if ($anySelected || $this->isSelected()) {
            $this->htmlOptions['class'] = isset($this->htmlOptions['class']) ? $this->htmlOptions['class'] . ' selected' : 'selected';
        }

        return Html::get()->tag('li', $content . $submenu, $this->htmlOptions);
    }
1288415
public function getAsHtml($options = [])
    {
        $defaults = [
            'table_id' => null,
            'table_class' => null,
            'translations' => [
                'title' => 'Card',
                'maskedPan' => 'Masked Pan',
                'token' => 'Token'
            ],
        ];

        $options = array_merge($defaults, $options);
        $translations = $options['translations'];

        $html = "<table id='{$options['table_id']}' class='{$options['table_class']}'>";
        $html .= "<tbody><tr><td>" . $translations['maskedPan'] . "</td><td>" . $this->maskedPan . "</td></tr>";
        $html .= "<tr><td>" . $translations['token'] . "</td><td>" . $this->token . "</td></tr></tbody>";
        $html .= "</table>";

        return $html;
    }
28582
public function addChoices($choices)
    {
        if (func_num_args() > 1) {
            $choices = func_get_args();
        }

        foreach ($choices as $key => $value) {
            $label = $choice = $value;

            if (is_array($choice)) {
                $label = array_values($choice)[0];
                $choice = array_keys($choice)[0];
            } else if (is_string($key)) {
                $choice = $key;
                $label = $value;
            }

            $this->addChoice($choice, $label);
        }

        return $this;
    }
186312
protected function renderOptionTags($options)
    {
        $output = '';
        if ($this->hasArgument('prependOptionLabel')) {
            $value = $this->hasArgument('prependOptionValue') ? $this->arguments['prependOptionValue'] : '';
            if ($this->hasArgument('translate')) {
                $label = $this->getTranslatedLabel($value, $this->arguments['prependOptionLabel']);
            } else {
                $label = $this->arguments['prependOptionLabel'];
            }
            $output .= $this->renderOptionTag($value, $label) . chr(10);
        }
        $output .= $this->renderOptionTagsInternal($options);

        return $output;
    }
127932
public function reverseTransform($choices)
    {
        if (!is_string($choices) || '' === trim($choices)) {
            return null;
        }

        $choices = explode(',', $choices);
        $arrayChoice = array();

        foreach ($choices as $choice) {
            $choice = $this->suppressSpecialCharacterHelper->transform($choice, array('_','.'));
            if ('' != $choice) {
                $arrayChoice[$choice] = $choice;
            }
        }

        return $arrayChoice;
    }
1134908
public function getHtml(array $attributes = []): string
    {
        return self::buildTag('option', $this->getLabel(),
            array_merge(
                [
                    'value'    => $this->getValue(),
                    'selected' => $this->isSelected,
                ],
                $attributes)
        );
    }
590086
public function choicesForValue(array $values = []): array
    {
        $choices = $this->choices();
        $selected = [];
        foreach ($values as $value) {
            if (array_key_exists($value, $this->choices)) {
                $selected[$value] = $choices[$value];
            }
        }

        return $selected;
    }
1357798
protected function parseChoices(array $choices)
    {
        $parsed = [];
        foreach ($choices as $choiceIdent => $choice) {
            $choice = $this->parseChoice($choice, (string)$choiceIdent);
            $choiceIdent = $choice['value'];

            $parsed[$choiceIdent] = $choice;
        }

        return $parsed;
    }
19600
protected function parse(array $choices)
    {
        $items = [];

        foreach ($choices as $key => $value) {
            if (is_array($value)) {
                $items[$key] = $this->parse($value);
            } else {
                if (is_int($key)) {
                    $label = ucfirst(str_replace(['-', '_'], ' ', $value));
                } else {
                    $label = $key;
                }

                $items[$label] = $value;
            }
        }

        return $items;
    }
280798
public function display_publish_name_vertical($choices) {
        global $PAGE;
        $html ='';
        $html .= html_writer::tag('h3',format_string(get_string("responses", "choice")));

        $attributes = array('method'=>'POST');
        $attributes['action'] = new moodle_url($PAGE->url);
        $attributes['id'] = 'attemptsform';

        if ($choices->viewresponsecapability) {
            $html .= html_writer::start_tag('form', $attributes);
            $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=> $choices->coursemoduleid));
            $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey()));
            $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode', 'value'=>'overview'));
        }

        $table = new html_table();
        $table->cellpadding = 0;
        $table->cellspacing = 0;
        $table->attributes['class'] = 'results names table table-bordered';
        $table->tablealign = 'center';
        $table->summary = get_string('responsesto', 'choice', format_string($choices->name));
        $table->data = array();

        $count = 0;
        ksort($choices->options);

        $columns = array();
        $celldefault = new html_table_cell();
        $celldefault->attributes['class'] = 'data';

        // This extra cell is needed in order to support accessibility for screenreader. MDL-30816
        $accessiblecell = new html_table_cell();
        $accessiblecell->scope = 'row';
        $accessiblecell->text = get_string('choiceoptions', 'choice');
        $columns['options'][] = $accessiblecell;

        $usernumberheader = clone($celldefault);
        $usernumberheader->header = true;
        $usernumberheader->attributes['class'] = 'header data';
        $usernumberheader->text = get_string('numberofuser', 'choice');
        $columns['usernumber'][] = $usernumberheader;

        $optionsnames = [];
        foreach ($choices->options as $optionid => $options) {
            $celloption = clone($celldefault);
            $cellusernumber = clone($celldefault);
            $cellusernumber->style = 'text-align: center;';

            $celltext = '';
            if ($choices->showunanswered && $optionid == 0) {
                $celltext = get_string('notanswered', 'choice');
            } else if ($optionid > 0) {
                $celltext = format_string($choices->options[$optionid]->text);
            }
            $numberofuser = 0;
            if (!empty($options->user) && count($options->user) > 0) {
                $numberofuser = count($options->user);
            }

            $celloption->text = $celltext;
            $optionsnames[$optionid] = $celltext;
            $cellusernumber->text = $numberofuser;

            $columns['options'][] = $celloption;
            $columns['usernumber'][] = $cellusernumber;
        }

        $table->head = $columns['options'];
        $table->data[] = new html_table_row($columns['usernumber']);

        $columns = array();

        // This extra cell is needed in order to support accessibility for screenreader. MDL-30816
        $accessiblecell = new html_table_cell();
        $accessiblecell->text = get_string('userchoosethisoption', 'choice');
        $accessiblecell->header = true;
        $accessiblecell->scope = 'row';
        $accessiblecell->attributes['class'] = 'header data';
        $columns[] = $accessiblecell;

        foreach ($choices->options as $optionid => $options) {
            $cell = new html_table_cell();
            $cell->attributes['class'] = 'data';

            if ($choices->showunanswered || $optionid > 0) {
                if (!empty($options->user)) {
                    $optionusers = '';
                    foreach ($options->user as $user) {
                        $data = '';
                        if (empty($user->imagealt)) {
                            $user->imagealt = '';
                        }

                        $userfullname = fullname($user, $choices->fullnamecapability);
                        $checkbox = '';
                        if ($choices->viewresponsecapability && $choices->deleterepsonsecapability) {
                            $checkboxid = 'attempt-user' . $user->id . '-option' . $optionid;
                            $checkbox .= html_writer::label($userfullname . ' ' . $optionsnames[$optionid],
                                $checkboxid, false, array('class' => 'accesshide'));
                            if ($optionid > 0) {
                                $checkboxname = 'attemptid[]';
                                $checkboxvalue = $user->answerid;
                            } else {
                                $checkboxname = 'userid[]';
                                $checkboxvalue = $user->id;
                            }
                            $checkbox .= html_writer::checkbox($checkboxname, $checkboxvalue, '', null,
                                array('id' => $checkboxid, 'class' => 'mr-1'));
                        }
                        $userimage = $this->output->user_picture($user, array('courseid' => $choices->courseid, 'link' => false));
                        $profileurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $choices->courseid));
                        $profilelink = html_writer::link($profileurl, $userimage . $userfullname);
                        $data .= html_writer::div($checkbox . $profilelink, 'mb-1');

                        $optionusers .= $data;
                    }
                    $cell->text = $optionusers;
                }
            }
            $columns[] = $cell;
            $count++;
        }
        $row = new html_table_row($columns);
        $table->data[] = $row;

        $html .= html_writer::tag('div', html_writer::table($table), array('class'=>'response'));

        $actiondata = '';
        if ($choices->viewresponsecapability && $choices->deleterepsonsecapability) {
            $selecturl = new moodle_url('#');

            $actiondata .= html_writer::start_div('selectallnone');
            $actiondata .= html_writer::link($selecturl, get_string('selectall'), ['data-select-info' => true]) . ' / ';

            $actiondata .= html_writer::link($selecturl, get_string('deselectall'), ['data-select-info' => false]);

            $actiondata .= html_writer::end_div();

            $actionurl = new moodle_url($PAGE->url, array('sesskey'=>sesskey(), 'action'=>'delete_confirmation()'));
            $actionoptions = array('delete' => get_string('delete'));
            foreach ($choices->options as $optionid => $option) {
                if ($optionid > 0) {
                    $actionoptions['choose_'.$optionid] = get_string('chooseoption', 'choice', $option->text);
                }
            }
            $select = new single_select($actionurl, 'action', $actionoptions, null,
                    array('' => get_string('chooseaction', 'choice')), 'attemptsform');
            $select->set_label(get_string('withselected', 'choice'));

            $PAGE->requires->js_call_amd('mod_choice/select_all_choices', 'init');

            $actiondata .= $this->output->render($select);
        }
        $html .= html_writer::tag('div', $actiondata, array('class'=>'responseaction'));

        if ($choices->viewresponsecapability) {
            $html .= html_writer::end_tag('form');
        }

        return $html;
    }
535801
protected function renderChoices(ChoiceListInterface $list, $currentValue): string
    {
        if (! is_array($currentValue)) {
            $currentValue = [$currentValue];
        }

        $selected = $list->choicesForValue($currentValue);
        $html = [];

        foreach ($list->choices() as $key => $name) {
            $html[] = sprintf(
                '<option %s>%s</option>',
                $this->attributesToString(
                    [
                        'value' => $key,
                        'selected' => isset($selected[$key]),
                    ]
                ),
                $this->escapeHtml($name)
            );
        }

        return implode('', $html);
    }