Exemplo n.º 1
0
 public function summarise_response(array $response)
 {
     if (isset($response['answer'])) {
         return question_utils::to_plain_text($response['answer'], $response['answerformat'], array('para' => false));
     } else {
         return null;
     }
 }
Exemplo n.º 2
0
 /**
  * Convert the question text to plain text, so it can safely be displayed
  * during import to let the user see roughly what is going on.
  */
 protected function format_question_text($question)
 {
     return question_utils::to_plain_text($question->questiontext, $question->questiontextformat);
 }
Exemplo n.º 3
0
/**
 * Creates a textual representation of a question for display.
 *
 * @param object $question A question object from the database questions table
 * @param bool $showicon If true, show the question's icon with the question. False by default.
 * @param bool $showquestiontext If true (default), show question text after question name.
 *       If false, show only question name.
 * @param bool $return If true (default), return the output. If false, print it.
 */
function quiz_question_tostring($question, $showicon = false, $showquestiontext = true, $return = true)
{
    global $COURSE;
    $result = '';
    $result .= '<span class="questionname">';
    if ($showicon) {
        $result .= print_question_icon($question, true);
        echo ' ';
    }
    $result .= shorten_text(format_string($question->name), 200) . '</span>';
    if ($showquestiontext) {
        $questiontext = question_utils::to_plain_text($question->questiontext, $question->questiontextformat, array('noclean' => true, 'para' => false));
        $questiontext = shorten_text($questiontext, 200);
        $result .= '<span class="questiontext">';
        if (!empty($questiontext)) {
            $result .= s($questiontext);
        } else {
            $result .= '<span class="error">';
            $result .= get_string('questiontextisempty', 'quiz');
            $result .= '</span>';
        }
        $result .= '</span>';
    }
    if ($return) {
        return $result;
    } else {
        echo $result;
    }
}
Exemplo n.º 4
0
/**
 * Creates a textual representation of a question for display.
 *
 * @param object $question A question object from the database questions table
 * @param bool $showicon If true, show the question's icon with the question. False by default.
 * @param bool $showquestiontext If true (default), show question text after question name.
 *       If false, show only question name.
 * @return string
 */
function quiz_question_tostring($question, $showicon = false, $showquestiontext = true)
{
    $result = '';
    $name = shorten_text(format_string($question->name), 200);
    if ($showicon) {
        $name .= print_question_icon($question) . ' ' . $name;
    }
    $result .= html_writer::span($name, 'questionname');
    if ($showquestiontext) {
        $questiontext = question_utils::to_plain_text($question->questiontext, $question->questiontextformat, array('noclean' => true, 'para' => false));
        $questiontext = shorten_text($questiontext, 200);
        if ($questiontext) {
            $result .= ' ' . html_writer::span(s($questiontext), 'questiontext');
        }
    }
    return $result;
}
 /**
  * Convert some part of the question text to plain text. This might be used,
  * for example, by get_response_summary().
  * @param string $text The HTML to reduce to plain text.
  * @param int $format the FORMAT_... constant.
  * @return string the equivalent plain text.
  */
 public function html_to_text($text, $format)
 {
     return question_utils::to_plain_text($text, $format);
 }
Exemplo n.º 6
0
/**
 * Creates a textual representation of a question for display.
 *
 * @param object $question A question object from the database questions table
 * @param bool $showicon If true, show the question's icon with the question. False by default.
 * @param bool $showquestiontext If true (default), show question text after question name.
 *       If false, show only question name.
 * @param bool $return If true (default), return the output. If false, print it.
 */
function offlinequiz_question_tostring($question, $showicon = false, $showquestiontext = true, $return = true, $shorttitle = false)
{
    global $COURSE;
    $result = '';
    $formatoptions = new stdClass();
    $formatoptions->noclean = true;
    $formatoptions->para = false;
    $questiontext = strip_tags(question_utils::to_plain_text($question->questiontext, $question->questiontextformat, array('noclean' => true, 'para' => false)));
    $questiontitle = strip_tags(format_text($question->name, $question->questiontextformat, $formatoptions, $COURSE->id));
    $result .= '<span class="questionname" title="' . $questiontitle . '">';
    if ($shorttitle && strlen($questiontitle) > 25) {
        $questiontitle = shorten_text($questiontitle, 25, false, '...');
    }
    if ($showicon) {
        $result .= print_question_icon($question, true);
        echo ' ';
    }
    if ($shorttitle) {
        $result .= $questiontitle;
    } else {
        $result .= shorten_text(format_string($question->name), 200) . '</span>';
    }
    if ($showquestiontext) {
        $result .= '<span class="questiontext" title="' . $questiontext . '">';
        $questiontext = shorten_text($questiontext, 200);
        if (!empty($questiontext)) {
            $result .= $questiontext;
        } else {
            $result .= '<span class="error">';
            $result .= get_string('questiontextisempty', 'offlinequiz');
            $result .= '</span>';
        }
        $result .= '</span>';
    }
    if ($return) {
        return $result;
    } else {
        echo $result;
    }
}
 public function get_possible_responses($questiondata)
 {
     if ($questiondata->options->single) {
         $responses = array();
         foreach ($questiondata->options->answers as $aid => $answer) {
             $responses[$aid] = new question_possible_response(question_utils::to_plain_text($answer->answer, $answer->answerformat), $answer->fraction);
         }
         $responses[null] = question_possible_response::no_response();
         return array($questiondata->id => $responses);
     } else {
         $parts = array();
         foreach ($questiondata->options->answers as $aid => $answer) {
             $parts[$aid] = array($aid => new question_possible_response(question_utils::to_plain_text($answer->answer, $answer->answerformat), $answer->fraction));
         }
         return $parts;
     }
 }
Exemplo n.º 8
0
 /**
  * Updating output to include a graph of multiple choice answer possibilities
  * with the percentage of students that answered that option
  *
  * @param \mod_activequiz\activequiz_question $question The realtime quiz question
  * @param array                               $attempts An array of \mod_activequiz\activequiz_attempt classes
  * @param string                              $output The current output from getting the results
  * @return string Return the updated output to be passed to the client
  */
 public function modify_questionresults_duringquiz($question, $attempts, $output)
 {
     global $DB;
     // store the possible answersid as the key of the array, and then a count
     //  for the number of times it was answered
     $answers = array();
     $dbanswers = array();
     foreach ($attempts as $attempt) {
         /** @var \mod_activequiz\activequiz_attempt $attempt */
         // only count attempts where they have "responded"
         if ($attempt->responded == 0) {
             continue;
         }
         $quba = $attempt->get_quba();
         $slot = $attempt->get_question_slot($question);
         $qa = $quba->get_question_attempt($slot);
         // now get question definition
         $questiondef = $qa->get_question();
         // if dbanswers is empty get them from the question definition (as this will be the same for all attempts for this slot
         // also save a db query
         if (empty($dbanswers)) {
             $dbanswers = $questiondef->answers;
         }
         // single and multi answers are handled differently for steps
         if ($questiondef instanceof \qtype_multichoice_single_question) {
             $this->update_answers_single($answers, $qa, $questiondef);
         } else {
             if ($questiondef instanceof \qtype_multichoice_multi_question) {
                 $this->update_answers_multi($answers, $qa, $questiondef);
             } else {
             }
         }
     }
     $xaxis = array();
     foreach ($dbanswers as $dbanswer) {
         $xaxis[$dbanswer->id] = \question_utils::to_plain_text($dbanswer->answer, $dbanswer->answerformat);
     }
     $newoutput = $this->add_chart($output, $xaxis, $answers);
     return $newoutput;
 }
Exemplo n.º 9
0
 /**
  * @param object $question question data.
  * @return string HTML of question text, ready for display.
  */
 protected function render_question_text_plain($question, $showimages = true)
 {
     global $OUTPUT;
     if ($showimages) {
         $text = question_rewrite_question_preview_urls($question->questiontext, $question->id, $question->contextid, 'question', 'questiontext', $question->id, $this->context->id, 'quiz_statistics');
     } else {
         $text = $question->questiontext;
     }
     $questiontext = question_utils::to_plain_text($text, $question->questiontextformat, array('noclean' => true, 'para' => false, 'overflowdiv' => true));
     return '&nbsp;&nbsp;&nbsp;' . $questiontext;
 }