本文整理汇总了PHP中question_state类的典型用法代码示例。如果您正苦于以下问题:PHP question_state类的具体用法?PHP question_state怎么用?PHP question_state使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了question_state类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: feedback
public function feedback(question_attempt $qa, question_display_options $options)
{
// Try to find the last graded step.
$gradedstep = $this->get_graded_step($qa);
if (is_null($gradedstep) || $qa->get_max_mark() == 0 || $options->marks < question_display_options::MARK_AND_MAX) {
return '';
}
// Display the grading details from the last graded state
$mark = new stdClass();
$mark->max = $qa->format_max_mark($options->markdp);
$actualmark = $gradedstep->get_fraction() * $qa->get_max_mark();
$mark->cur = format_float($actualmark, $options->markdp);
$rawmark = $gradedstep->get_behaviour_var('_rawfraction') * $qa->get_max_mark();
$mark->raw = format_float($rawmark, $options->markdp);
// let student know wether the answer was correct
if ($qa->get_state()->is_commented()) {
$class = $qa->get_state()->get_feedback_class();
} else {
$class = question_state::graded_state_for_fraction($gradedstep->get_behaviour_var('_rawfraction'))->get_feedback_class();
}
$gradingdetails = get_string('gradingdetails', 'qbehaviour_adaptive', $mark);
$gradingdetails .= $this->penalty_info($qa, $mark, $options);
$output = '';
$output .= html_writer::tag('div', get_string($class, 'question'), array('class' => 'correctness ' . $class));
$output .= html_writer::tag('div', $gradingdetails, array('class' => 'gradingdetails'));
return $output;
}
示例2: grade_response
public function grade_response(array $response)
{
$fraction = 0;
list($numright, $total) = $this->get_num_parts_right($response);
$numwrong = $this->get_num_selected_choices($response) - $numright;
$numcorrect = $this->get_num_correct_choices();
if ($numwrong == 0 && $numcorrect == $numright) {
$fraction = 1;
}
$state = question_state::graded_state_for_fraction($fraction);
return array($fraction, $state);
}
示例3: correct_response
public function correct_response(question_attempt $qa)
{
$result = "";
$question = $qa->get_question();
if ($question->shownumcorrect) {
foreach ($question->get_order($qa) as $ans_number => $ans_id) {
$answer = $question->answers[$ans_id];
if (question_state::graded_state_for_fraction($answer->fraction) == question_state::$gradedright) {
$result = get_string('correctansweris', 'qtype_multichoice', qtype_omeromultichoice_base_renderer::number_answer($ans_number, $question->answernumbering));
}
}
}
return $result;
}
示例4: get_state_string
public function get_state_string($showcorrectness)
{
$laststep = $this->qa->get_last_step();
if ($laststep->has_behaviour_var('_try')) {
$state = question_state::graded_state_for_fraction($laststep->get_behaviour_var('_rawfraction'));
return $state->default_string(true);
}
$state = $this->qa->get_state();
if ($state == question_state::$todo) {
return get_string('notcomplete', 'qbehaviour_adaptive');
} else {
return parent::get_state_string($showcorrectness);
}
}
示例5: find_right_answer
/**
* Find the corresponding choice id of the first correct answer of a shortanswer question.
* choice is added to the randomsamatch question if it doesn't already exist.
* @param object $wrappedquestion short answer question.
* @return int correct choice id.
*/
public function find_right_answer($wrappedquestion)
{
// We only take into account *one* (the first) correct answer.
while ($answer = array_shift($wrappedquestion->answers)) {
if (!question_state::graded_state_for_fraction($answer->fraction)->is_incorrect()) {
// Store this answer as a choice, only if this is a new one.
$key = array_search($answer->answer, $this->choices);
if ($key === false) {
$key = $answer->id;
$this->choices[$key] = $answer->answer;
}
return $key;
}
}
// We should never get there.
throw new coding_exception('shortanswerquestionwithoutrightanswer', $wrappedquestion->id);
}
示例6: get_correct_answer
public function get_correct_answer() {
foreach ($this->question->get_answers() as $answer) {
$state = question_state::graded_state_for_fraction($answer->fraction);
if ($state == question_state::$gradedright) {
return $answer;
}
}
return null;
}
示例7: load_from_records
/**
* Create a question_attempt_step from records loaded from the database.
* @param Iterator $records Raw records loaded from the database.
* @param int $stepid The id of the records to extract.
* @param string $qtype The question type of which this is an attempt.
* If not given, each record must include a qtype field.
* @return question_attempt_step The newly constructed question_attempt_step.
*/
public static function load_from_records($records, $attemptstepid, $qtype = null)
{
$currentrec = $records->current();
while ($currentrec->attemptstepid != $attemptstepid) {
$records->next();
if (!$records->valid()) {
throw new coding_exception('Question attempt step ' . $attemptstepid . ' not found in the database.');
}
$currentrec = $records->current();
}
$record = $currentrec;
$contextid = null;
$data = array();
while ($currentrec && $currentrec->attemptstepid == $attemptstepid) {
if (!is_null($currentrec->name)) {
$data[$currentrec->name] = $currentrec->value;
}
$records->next();
if ($records->valid()) {
$currentrec = $records->current();
} else {
$currentrec = false;
}
}
$step = new question_attempt_step_read_only($data, $record->timecreated, $record->userid);
$step->state = question_state::get($record->state);
$step->id = $record->attemptstepid;
if (!is_null($record->fraction)) {
$step->fraction = $record->fraction + 0;
}
// This next chunk of code requires getting $contextid and $qtype here.
// Somehow, we need to get that information to this point by modifying
// all the paths by which this method can be called.
// Can we only return files when it's possible? Should there be some kind of warning?
if (is_null($qtype)) {
$qtype = $record->qtype;
}
foreach (question_bank::get_qtype($qtype)->response_file_areas() as $area) {
if (empty($step->data[$area])) {
continue;
}
$step->data[$area] = new question_file_loader($step, $area, $step->data[$area], $record->contextid);
}
return $step;
}
示例8: get_num_correct_choices
protected function get_num_correct_choices($questiondata)
{
$numright = 0;
foreach ($questiondata->options->answers as $answer) {
if (!question_state::graded_state_for_fraction($answer->fraction)->is_incorrect()) {
$numright += 1;
}
}
return $numright;
}
示例9: grade_response
//.........这里部分代码省略.........
$feedback .= "<br>\n";
}
if ($this->feedbacklevel >= FEEDBACK_TIMES_COUNT_OF_TESTS) {
$feedback .= "Tests: " . $numtests . "<br>\n";
$feedback .= "Failures: " . $numfailures . "<br>\n";
$feedback .= "Errors: " . $numerrors . "<br>\n";
$feedback .= "<br>\n";
$feedback .= "<br>\n";
}
if ($this->feedbacklevel == FEEDBACK_ALL_EXCEPT_STACKTRACE) {
$matches = array();
$found = preg_match('@(.*)There (were|was) (\\d*) failure(s?):\\n@s', $output, $matches);
if ($found) {
$feedback .= '<pre>' . htmlspecialchars($matches[1]) . '</pre>';
$feedback .= "<br>\n";
} else {
$feedback .= '<pre>' . htmlspecialchars($output) . '</pre>';
$feedback .= "<br>\n";
}
$feedback .= "<br>\n";
}
// search for common throwables, ordered primary by package, secundary by alphabet
if (strpos($output, 'java.io.IOException') !== false) {
$feedback .= get_string('ioexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.io.FileNotFoundException') !== false) {
$feedback .= get_string('filenotfoundexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.ArrayIndexOutOfBoundsException') !== false) {
$feedback .= get_string('arrayindexoutofboundexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.ClassCastException') !== false) {
$feedback .= get_string('classcastexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.NegativeArraySizeException') !== false) {
$feedback .= get_string('negativearraysizeexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.NullPointerException') !== false) {
$feedback .= get_string('nullpointerexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.OutOfMemoryError') !== false) {
$feedback .= get_string('outofmemoryerror', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.StackOverflowError') !== false) {
$feedback .= get_string('stackoverflowerror', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.StringIndexOutOfBoundsException') !== false) {
$feedback .= get_string('stringindexoutofboundexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.nio.BufferOverflowException') !== false) {
$feedback .= get_string('bufferoverflowexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.nio.BufferUnderflowException') !== false) {
$feedback .= get_string('bufferunderflowexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.security.AccessControlException') !== false) {
$feedback .= get_string('accesscontrolexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
// append feedback phrase (wrong / [partially] corrent answer phrase)
if ($numtests > 0 && $totalerrors == 0) {
$feedback .= get_string('CA', 'qtype_javaunittest');
$feedback .= "<br>\n";
} else {
if ($numtests > 0 && $numtests == $totalerrors) {
$feedback .= get_string('WA', 'qtype_javaunittest');
$feedback .= "<br>\n";
} else {
if ($numtests > 0 && $totalerrors != 0) {
$feedback .= get_string('PCA', 'qtype_javaunittest');
$feedback .= "<br>\n";
}
}
}
}
}
// save feedback
$cur_feedback = $DB->get_record('qtype_javaunittest_feedback', array('questionattemptid' => $this->questionattemptid));
$db_feedback = new stdClass();
$db_feedback->questionattemptid = $this->questionattemptid;
$db_feedback->feedback = $feedback;
if ($cur_feedback) {
$db_feedback->id = $cur_feedback->id;
$DB->update_record('qtype_javaunittest_feedback', $db_feedback);
} else {
$DB->insert_record('qtype_javaunittest_feedback', $db_feedback);
}
return array($fraction, question_state::graded_state_for_fraction($fraction));
}
示例10: grade_response
public function grade_response(array $response)
{
$this->update_current_response($response);
$countcorrect = 0;
$countanswers = 0;
$correctresponse = $this->correctresponse;
$currentresponse = $this->currentresponse;
foreach ($currentresponse as $position => $answerid) {
if ($correctresponse[$position] == $answerid) {
$countcorrect++;
}
$countanswers++;
}
if ($countanswers == 0) {
$fraction = 0;
} else {
$fraction = $countcorrect / $countanswers;
}
return array($fraction, question_state::graded_state_for_fraction($fraction));
}
示例11: grade_response
//.........这里部分代码省略.........
#$feedback .= 'dirroot=' . $CFG->dirroot . '<br/>';
#$feedback .= 'wwwroot=' . $CFG->wwwroot . '<br/>';
$feedback .= '<div style="border:1px solid #000;">';
$feedback .= '<b><font color="blue">Results of Code Audit</font></b>';
$feedback .= '</div><br/>';
$feedback .= '<font color="#0000A0">Value of Code Audit in question grade: <b>' . $weight_style * 100 . '%</b></font><br/>';
$feedback .= '<font color="#0000A0">The first <b>' . $max_errors_style . '</b> errors give bad points</font><br/>';
$feedback .= '<font color="#0000A0">Number of errors made by the student: <b>' . $num_errors_style . '</b></font><br/>';
$feedback .= '<font color="#0000A0">Grade for section Code Audit: <b>' . $fraction_style * $weight_style * 100 . '% / ' . $weight_style * 100 . '%</b></font><br/><br/>';
$feedback .= '<font color="#0000A0"><b>Details of audit hereafter:</b></font><br/>';
$feedback .= '<pre>' . $output_audit . '</pre>';
$feedback .= '<br/>';
$feedback .= '<div style="border:1px solid #000;">';
$feedback .= '<b><font color="blue">Results of Unit Tests</font></b>';
$feedback .= '</div><br/>';
$feedback .= '<font color="#0000A0">Number of evaluated tests: <b>' . $numtests . '</b></font><br/>';
$feedback .= '<font color="#0000A0">Number of observed failures: <b>' . $numfailures . ' / ' . $numtests . '</b></font><br/>';
$feedback .= '<font color="#0000A0">Number of observed errors: <b>' . $numerrors . ' / ' . $numtests . '</b></font><br/>';
$feedback .= '<font color="#0000A0">Grade for section Unit Tests: <b>' . $fraction_code * $weight_unittests * 100 . '% / ' . $weight_unittests * 100 . '%</b></font><br/><br/>';
$feedback .= '<font color="#0000A0"><b>Details of unit tests hereafter:</b></font><br/>';
$feedback .= '<pre>' . $outtext . '</pre>';
$feedback .= "<br>\n";
}
// search for common throwables, by package, by alphabet
if (strpos($output, 'java.io.IOException') !== false) {
$feedback .= get_string('ioexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.io.FileNotFoundException') !== false) {
$feedback .= get_string('filenotfoundexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.ArrayIndexOutOfBoundsException') !== false) {
$feedback .= get_string('arrayindexoutofboundexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.ClassCastException') !== false) {
$feedback .= get_string('classcastexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.NegativeArraySizeException') !== false) {
$feedback .= get_string('negativearraysizeexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.NullPointerException') !== false) {
$feedback .= get_string('nullpointerexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.OutOfMemoryError') !== false) {
$feedback .= get_string('outofmemoryerror', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.StackOverflowError') !== false) {
$feedback .= get_string('stackoverflowerror', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.StringIndexOutOfBoundsException') !== false) {
$feedback .= get_string('stringindexoutofboundexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.nio.BufferOverflowException') !== false) {
$feedback .= get_string('bufferoverflowexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.nio.BufferUnderflowException') !== false) {
$feedback .= get_string('bufferunderflowexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.security.AccessControlException') !== false) {
$feedback .= get_string('accesscontrolexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
// append feedback phrase (wrong / [partially] corrent answer phrase)
if ($numtests > 0 && $totalerrors == 0 && $num_errors_style == 0) {
$feedback .= get_string('CA', 'qtype_javaunittest');
} else {
if ($numtests > 0 && ($totalerrors != 0 || $num_errors_style != 0)) {
$feedback .= get_string('PCA', 'qtype_javaunittest');
} else {
if ($numtest > 0 && ($numtests >= $totalerrors && $num_errors_style >= $max_errors_style)) {
$feedback .= get_string('WA', 'qtype_javaunittest');
}
}
}
$feedback .= "<br>\n";
}
}
// save feedback
$cur_feedback = $DB->get_record('qtype_javaunittest_feedback', array('questionattemptid' => $this->questionattemptid));
$db_feedback = new stdClass();
$db_feedback->questionattemptid = $this->questionattemptid;
$db_feedback->feedback = $feedback;
if ($cur_feedback) {
$db_feedback->id = $cur_feedback->id;
$DB->update_record('qtype_javaunittest_feedback', $db_feedback);
} else {
$DB->insert_record('qtype_javaunittest_feedback', $db_feedback);
}
return array($fraction, question_state::graded_state_for_fraction($fraction));
}
示例12: icon_for_fraction
/**
* Return an appropriate icon (green tick, red cross, etc.) for a grade.
* @param float $fraction grade on a scale 0..1.
* @return string html fragment.
*/
protected function icon_for_fraction($fraction) {
global $OUTPUT;
$feedbackclass = question_state::graded_state_for_fraction($fraction)->get_feedback_class();
return $OUTPUT->pix_icon('i/grade_' . $feedbackclass, get_string($feedbackclass, 'question'),
'moodle', array('class' => 'icon'));
}
示例13: grade_response
public function grade_response(array $response)
{
$response = $this->discard_duplicates($response);
list($right, $total) = $this->get_num_parts_right($response);
$this->fraction = $right / $total;
$grade = array($this->fraction, question_state::graded_state_for_fraction($this->fraction));
return $grade;
}
示例14: icon_for_fraction
/**
* Return an appropriate icon (green tick, red cross, etc.) for a grade.
* @param float $fraction grade on a scale 0..1.
* @return string html fragment.
*/
protected function icon_for_fraction($fraction) {
global $OUTPUT;
$state = question_state::graded_state_for_fraction($fraction);
if ($state == question_state::$gradedright) {
$icon = 'i/tick_green_big';
} else if ($state == question_state::$gradedpartial) {
$icon = 'i/tick_amber_big';
} else {
$icon = 'i/cross_red_big';
}
return $OUTPUT->pix_icon($icon, get_string($state->get_feedback_class(), 'question'),
'moodle', array('class' => 'icon'));
}
示例15: feedback_popup
/**
* Render the feedback pop-up contents.
*
* @param question_graded_automatically $subq the subquestion.
* @param float $fraction the mark the student got. null if this subq was not answered.
* @param string $feedbacktext the feedback text, already processed with format_text etc.
* @param string $rightanswer the right answer, already processed with format_text etc.
* @param question_display_options $options the display options.
* @return string the HTML for the feedback popup.
*/
protected function feedback_popup(question_graded_automatically $subq,
$fraction, $feedbacktext, $rightanswer, question_display_options $options) {
if (!$options->feedback) {
return '';
}
$feedback = array();
if ($options->correctness) {
if (is_null($fraction)) {
$state = question_state::$gaveup;
} else {
$state = question_state::graded_state_for_fraction($fraction);
}
$feedback[] = $state->default_string(true);
}
if ($options->rightanswer) {
$feedback[] = get_string('correctansweris', 'qtype_shortanswer', $rightanswer);
}
$subfraction = '';
if ($options->marks >= question_display_options::MARK_AND_MAX && $subq->maxmark > 0) {
$a = new stdClass();
$a->mark = format_float($fraction * $subq->maxmark, $options->markdp);
$a->max = format_float($subq->maxmark, $options->markdp);
$feedback[] = get_string('markoutofmax', 'question', $a);
}
return html_writer::tag('span', implode('<br />', $feedback),
array('class' => 'feedbackspan accesshide'));
}