You are here

function short_answer_edit_score in Quiz 8.4

Same name and namespace in other branches
  1. 6.6 question_types/short_answer/short_answer.admin.inc \short_answer_edit_score()
  2. 6.3 question_types/short_answer/short_answer.admin.inc \short_answer_edit_score()
  3. 6.4 question_types/short_answer/short_answer.admin.inc \short_answer_edit_score()
  4. 6.5 question_types/short_answer/short_answer.admin.inc \short_answer_edit_score()
  5. 7.6 question_types/short_answer/short_answer.admin.inc \short_answer_edit_score()
  6. 7 question_types/short_answer/short_answer.admin.inc \short_answer_edit_score()
  7. 7.4 question_types/short_answer/short_answer.admin.inc \short_answer_edit_score()

Page handler for displaying a scoring form. This function is called directly from the menu router. It generates a form for scoring a quiz.

Parameters

$vid: The VID of the question and answer to load.

$rid: The result ID of the answer to load.

Return value

Text to display.

1 call to short_answer_edit_score()
ShortAnswerController::scoreShortAnswerPages in question_types/short_answer/lib/Drupal/short_answer/Controller/ShortAnswerController.php

File

question_types/short_answer/short_answer.admin.inc, line 33
short_answer.admin

Code

function short_answer_edit_score($vid, $rid) {
  $nid = db_query('SELECT nid FROM {node_revision} WHERE vid = :vid', array(
    ':vid' => $vid,
  ))
    ->fetchField();
  if (!$nid) {
    throw new NotFoundHttpException();
  }
  $node = node_load($nid, $vid);
  if (!$node || $node
    ->getType() != 'short_answer') {
    throw new NotFoundHttpException();
  }
  $answer = (object) short_answer_get_answer($node
    ->id(), $node
    ->getRevisionId(), $rid);
  if (!$answer) {
    throw new NotFoundHttpException();
  }
  if ($node->max_score > 0) {
    $answer->rel_score = round($answer->score * $answer->rel_max_score / $node->max_score);
  }
  else {
    $answer->rel_score = 0;
  }
  drupal_set_title(t('Score answer to "@title"', array(
    '@title' => $node
      ->getTitle(),
  )), PASS_THROUGH);
  return drupal_get_form('short_answer_score_form', $node, $answer);
}