芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/public_html/cepali/question/type/shortanswer/renderer.php
. /** * Short answer question renderer class. * * @package qtype * @subpackage shortanswer * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); /** * Generates the output for short answer questions. * * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class qtype_shortanswer_renderer extends qtype_renderer { public function formulation_and_controls(question_attempt $qa, question_display_options $options) { $question = $qa->get_question(); $currentanswer = $qa->get_last_qt_var('answer'); $inputname = $qa->get_qt_field_name('answer'); $inputattributes = array( 'type' => 'text', 'name' => $inputname, 'value' => $currentanswer, 'id' => $inputname, 'size' => 80, 'class' => 'form-control d-inline', ); if ($options->readonly) { $inputattributes['readonly'] = 'readonly'; } $feedbackimg = ''; if ($options->correctness) { $answer = $question->get_matching_answer(array('answer' => $currentanswer)); if ($answer) { $fraction = $answer->fraction; } else { $fraction = 0; } $inputattributes['class'] .= ' ' . $this->feedback_class($fraction); $feedbackimg = $this->feedback_image($fraction); } $questiontext = $question->format_questiontext($qa); $placeholder = false; if (preg_match('/_____+/', $questiontext, $matches)) { $placeholder = $matches[0]; $inputattributes['size'] = round(strlen($placeholder) * 1.1); } $input = html_writer::empty_tag('input', $inputattributes) . $feedbackimg; if ($placeholder) { $inputinplace = html_writer::tag('label', get_string('answer'), array('for' => $inputattributes['id'], 'class' => 'accesshide')); $inputinplace .= $input; $questiontext = substr_replace($questiontext, $inputinplace, strpos($questiontext, $placeholder), strlen($placeholder)); } $result = html_writer::tag('div', $questiontext, array('class' => 'qtext')); if (!$placeholder) { $result .= html_writer::start_tag('div', array('class' => 'ablock form-inline')); $result .= html_writer::tag('label', get_string('answer', 'qtype_shortanswer', html_writer::tag('span', $input, array('class' => 'answer'))), array('for' => $inputattributes['id'])); $result .= html_writer::end_tag('div'); } if ($qa->get_state() == question_state::$invalid) { $result .= html_writer::nonempty_tag('div', $question->get_validation_error(array('answer' => $currentanswer)), array('class' => 'validationerror')); } return $result; } public function specific_feedback(question_attempt $qa) { $question = $qa->get_question(); $answer = $question->get_matching_answer(array('answer' => $qa->get_last_qt_var('answer'))); if (!$answer || !$answer->feedback) { return ''; } return $question->format_text($answer->feedback, $answer->feedbackformat, $qa, 'question', 'answerfeedback', $answer->id); } public function correct_response(question_attempt $qa) { $question = $qa->get_question(); $answer = $question->get_matching_answer($question->get_correct_response()); if (!$answer) { return ''; } return get_string('correctansweris', 'qtype_shortanswer', s($question->clean_response($answer->answer))); } }