Returns HTML to display choices result
@param object $choices
@param bool $forcepublish
@return string
762210
public function display_result($choices, $forcepublish = false) {
        if (empty($forcepublish)) { //allow the publish setting to be overridden
            $forcepublish = $choices->publish;
        }

        $displaylayout = $choices->display;

        if ($forcepublish) {  //CHOICE_PUBLISH_NAMES
            return $this->display_publish_name_vertical($choices);
        } else {
            return $this->display_publish_anonymous($choices, $displaylayout);
        }
    }
167510
protected function getChoice($contentId)
    {
        $choices = array();
        $content = $this->contentRepository->findOneByContentId($contentId);
        $choices[$content->getContentId()] = $content->getName();

        return $choices;
    }
116967
public function toString($forcePair = false)
    {
        $content = $this->content;

        $content = $content . $this->hint;

        return HtmlBuilder::create($this->name, $content, $this->attribs, $forcePair);
    }
930024
public static function get_choice_results($choiceid) {
        global $USER, $PAGE;

        $params = self::validate_parameters(self::get_choice_results_parameters(), array('choiceid' => $choiceid));

        if (!$choice = choice_get_choice($params['choiceid'])) {
            throw new moodle_exception("invalidcoursemodule", "error");
        }
        list($course, $cm) = get_course_and_cm_from_instance($choice, 'choice');

        $context = context_module::instance($cm->id);
        self::validate_context($context);

        $groupmode = groups_get_activity_groupmode($cm);
        // Check if we have to include responses from inactive users.
        $onlyactive = $choice->includeinactive ? false : true;
        $users = choice_get_response_data($choice, $cm, $groupmode, $onlyactive);
        // Show those who haven't answered the question.
        if (!empty($choice->showunanswered)) {
            $choice->option[0] = get_string('notanswered', 'choice');
            $choice->maxanswers[0] = 0;
        }
        $results = prepare_choice_show_results($choice, $course, $cm, $users);

        $options = array();
        $fullnamecap = has_capability('moodle/site:viewfullnames', $context);
        foreach ($results->options as $optionid => $option) {

            $userresponses = array();
            $numberofuser = 0;
            $percentageamount = 0;
            if (property_exists($option, 'user') and
                (has_capability('mod/choice:readresponses', $context) or choice_can_view_results($choice))) {
                $numberofuser = count($option->user);
                $percentageamount = ((float)$numberofuser / (float)$results->numberofuser) * 100.0;
                if ($choice->publish) {
                    foreach ($option->user as $userresponse) {
                        $response = array();
                        $response['userid'] = $userresponse->id;
                        $response['fullname'] = fullname($userresponse, $fullnamecap);

                        $userpicture = new user_picture($userresponse);
                        $userpicture->size = 1; // Size f1.
                        $response['profileimageurl'] = $userpicture->get_url($PAGE)->out(false);

                        // Add optional properties.
                        foreach (array('answerid', 'timemodified') as $field) {
                            if (property_exists($userresponse, 'answerid')) {
                                $response[$field] = $userresponse->$field;
                            }
                        }
                        $userresponses[] = $response;
                    }
                }
            }

            $options[] = array('id'               => $optionid,
                               'text'             => external_format_string($option->text, $context->id),
                               'maxanswer'        => $option->maxanswer,
                               'userresponses'    => $userresponses,
                               'numberofuser'     => $numberofuser,
                               'percentageamount' => $percentageamount
                              );
        }

        $warnings = array();
        return array(
            'options' => $options,
            'warnings' => $warnings
        );
    }
36037
public function openForm($htmlOptions)
    {
        $r = '<form ';
        foreach ($htmlOptions as $k => $v)
            $r .= "$k = '$v' ";

        return $r . '>' . ((isset($htmlOptions['method']) && 'post' == strtolower($htmlOptions['method'])) ? $this->hiddenInput(WebApp::get()->request()->getCsrfKey(), WebApp::get()->request()->getCsrfValue()) : '');
    }
1114665
public function drawWindow($title, $choices, $position, $answers)
    {
        $this->window->clearScreen();

        $this->output->writeln($this->getTitle($title));
        $this->output->writeln("");

        $lines = $this->getFormattedChoices($choices, $position, $answers);

        foreach ($lines as $line) {
            $this->output->writeln($line);
        }

        return $this;
    }
733642
public function listing($forceUpdate = false)
    {
        if (empty($this->groups) || $forceUpdate) {
            $this->all();
        }
        $ret = [];
        foreach ($this->groups['groups'] as $e) {
            $ret[$e['name']] = (int) $e['id'];
        }

        return $ret;
    }
1030108
function renderChoices(choices, pointer) {
  var output = '';
  var separatorOffset = 0;

  choices.forEach(function(choice, i) {
    if (choice.type === 'separator') {
      separatorOffset++;
      output += ' ' + choice + '\n';
      return;
    }

    if (choice.disabled) {
      separatorOffset++;
      output += ' - ' + choice.name;
      output += ' (' + (typeof choice.disabled === 'string' ? choice.disabled : 'Disabled') + ')';
    } else {
      var isSelected = (i - separatorOffset === pointer);
      output += isSelected ? utils.chalk.cyan(utils.figures.pointer) : ' ';
      output += getCheckbox(choice.checked) + ' ' + choice.name;
    }

    output += '\n';
  });

  return output.replace(/\n$/, '');
}
180851
function renderChoices(choices, pointer) {
  var output = '';
  var separatorOffset = 0;

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

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

    var index = i - separatorOffset;
    var display = (index + 1) + ') ' + choice.name;
    if (index === pointer) {
      display = utils.chalk.cyan(display);
    }
    output += display;
  });

  return output;
}
1371374
protected function filter($result, $choices)
    {
        foreach ($choices as $key => $regex) {
            if ($result->is($key) and stripos($key, 'generic') === false) {
                return $key;
            }
        }

        return null;
    }
550263
public function load_choices() {
        if (is_array($this->choices)) {
            return true;
        }
        $this->choices = array(FRONTPAGENEWS          => get_string('frontpagenews'),
            FRONTPAGEALLCOURSELIST => get_string('frontpagecourselist'),
            FRONTPAGEENROLLEDCOURSELIST => get_string('frontpageenrolledcourselist'),
            FRONTPAGECATEGORYNAMES => get_string('frontpagecategorynames'),
            FRONTPAGECATEGORYCOMBO => get_string('frontpagecategorycombo'),
            FRONTPAGECOURSESEARCH  => get_string('frontpagecoursesearch'),
            'none'                 => get_string('none'));
        if ($this->name === 'frontpage') {
            unset($this->choices[FRONTPAGEENROLLEDCOURSELIST]);
        }
        return true;
    }
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;
    }
371722
private function prepareOptions($options, $forceOptions = [])
    {
        $optionString = '';

        foreach ($forceOptions as $option => $value) {
            if (is_numeric($option)) {
                $options[$value] = null;
            } else {
                $options[$option] = $value;
            }
        }

        foreach ($options as $option => $value) {

            if (is_null($value)) {
                $optionString .= ' ' . $option;
            } else {
                $optionString .= ' ' . $option . '=' . $value;
            }
        }

        return $optionString;
    }
662716
public static function generateRetrieveAllEntitiesRequest( $entityFilters = null, $showUnpublished = false ) {
        /* If no entityFilters are supplied, assume "All" */
        if ( $entityFilters == null ) {
            $entityFilters = 'Entity Attributes Privileges Relationships';
        }
        /* Generate the RetrieveAllEntitiesRequest message */
        $retrieveEntityRequestDOM = new DOMDocument();
        $executeNode              = $retrieveEntityRequestDOM->appendChild( $retrieveEntityRequestDOM->createElementNS( 'http://schemas.microsoft.com/xrm/2011/Contracts/Services', 'Execute' ) );
        $requestNode              = $executeNode->appendChild( $retrieveEntityRequestDOM->createElement( 'request' ) );
        $requestNode->setAttributeNS( 'http://www.w3.org/2001/XMLSchema-instance', 'i:type', 'b:RetrieveAllEntitiesRequest' );
        $requestNode->setAttributeNS( 'http://www.w3.org/2000/xmlns/', 'xmlns:b', 'http://schemas.microsoft.com/xrm/2011/Contracts' );
        $parametersNode = $requestNode->appendChild( $retrieveEntityRequestDOM->createElement( 'b:Parameters' ) );
        $parametersNode->setAttributeNS( 'http://www.w3.org/2000/xmlns/', 'xmlns:c', 'http://schemas.datacontract.org/2004/07/System.Collections.Generic' );
        /* EntityFilters */
        $keyValuePairNode1 = $parametersNode->appendChild( $retrieveEntityRequestDOM->createElement( 'b:KeyValuePairOfstringanyType' ) );
        $keyValuePairNode1->appendChild( $retrieveEntityRequestDOM->createElement( 'c:key', 'EntityFilters' ) );
        $valueNode1 = $keyValuePairNode1->appendChild( $retrieveEntityRequestDOM->createElement( 'c:value', $entityFilters ) );
        $valueNode1->setAttribute( 'i:type', 'd:EntityFilters' );
        $valueNode1->setAttributeNS( 'http://www.w3.org/2000/xmlns/', 'xmlns:d', 'http://schemas.microsoft.com/xrm/2011/Metadata' );
        /* RetrieveAsIfPublished */
        $keyValuePairNode3 = $parametersNode->appendChild( $retrieveEntityRequestDOM->createElement( 'b:KeyValuePairOfstringanyType' ) );
        $keyValuePairNode3->appendChild( $retrieveEntityRequestDOM->createElement( 'c:key', 'RetrieveAsIfPublished' ) );
        $valueNode3 = $keyValuePairNode3->appendChild( $retrieveEntityRequestDOM->createElement( 'c:value', ( $showUnpublished ? 'true' : 'false' ) ) );
        $valueNode3->setAttribute( 'i:type', 'd:boolean' );
        $valueNode3->setAttributeNS( 'http://www.w3.org/2000/xmlns/', 'xmlns:d', 'http://www.w3.org/2001/XMLSchema' );
        /* Request ID and Name */
        $requestNode->appendChild( $retrieveEntityRequestDOM->createElement( 'b:RequestId' ) )->setAttribute( 'i:nil', 'true' );
        $requestNode->appendChild( $retrieveEntityRequestDOM->createElement( 'b:RequestName', 'RetrieveAllEntities' ) );

        /* Return the DOMNode */

        return $executeNode;
    }
1141900
protected function promptForProviderOrTag()
    {
        $choice = $this->choice(
            "Which provider or tag's files would you like to publish?",
            $choices = $this->publishableChoices()
        );

        if ($choice == $choices[0] || is_null($choice)) {
            return;
        }

        $this->parseChoice($choice);
    }
232939
private function addOptionToSelect($selected, $fighter, $html): string
    {
        if ($fighter != null) {
            $select = $selected != null && $selected->id == $fighter->id ? ' selected' : '';
            $html .= '<option' . $select
                . ' value='
                . ($fighter->id ?? '')
                . '>'
                . $fighter->name
                . '</option>';
        }

        return $html;
    }
1269669
protected function getRevisionList(
        $published = false,
        $limit = 10
    ) {
        $revisions = $this->findRevisionList->__invoke(
            $this->currentSite->getSiteId(),
            $this->page->getName(),
            $this->page->getPageType(),
            $published,
            $limit
        );

        return $revisions;
    }