You are here

function _quiz_update_items in Quiz 7

Same name and namespace in other branches
  1. 8.4 quiz.admin.inc \_quiz_update_items()
  2. 6.6 quiz.admin.inc \_quiz_update_items()
  3. 6.4 quiz.admin.inc \_quiz_update_items()
  4. 7.6 quiz.admin.inc \_quiz_update_items()
  5. 7.4 quiz.admin.inc \_quiz_update_items()
  6. 7.5 quiz.admin.inc \_quiz_update_items()

Update a quiz set of items with new weights and membership

Parameters

$quiz: The quiz node

$weight_map: Weights for each question(determines the order in which the question will be taken by the quiz taker)

$max_scores: Array of max scores for each question

$is_new_revision: Array of boolean values determining if the question is to be updated to the newest revision

$refreshes: True if we are creating a new revision of the quiz

$stayers: Questions added to the quiz

$compulsories: Array of boolean values determining if the question is compulsory or not.

Return value

array set of questions after updating

1 call to _quiz_update_items()
quiz_questions_form_submit in ./quiz.admin.inc
Submit function for quiz_questions.

File

./quiz.admin.inc, line 1605
Administrator interface for Quiz module.

Code

function _quiz_update_items($quiz, $weight_map, $max_scores, $is_new_revision, $refreshes, $stayers, $compulsories = NULL) {
  $questions = array();
  foreach ($weight_map as $id => $weight) {

    // Do not add hidden questions to $questions
    if ($stayers[$id] == 0) {
      continue;
    }
    list($nid, $vid) = explode('-', $id, 2);
    $nid = (int) $nid;
    $vid = (int) $vid;
    $question = new stdClass();
    $question->nid = $nid;
    $question->vid = $vid;
    if (isset($compulsories)) {
      if ($compulsories[$id] == 1) {
        $question->state = QUESTION_ALWAYS;
      }
      else {
        $question->state = QUESTION_RANDOM;
        $max_scores[$id] = $quiz->max_score_for_random;
      }
    }
    else {
      $question->state = QUESTION_ALWAYS;
    }
    $question->weight = $weight;
    $question->max_score = $max_scores[$id];
    $question->refresh = isset($refreshes[$id]) && $refreshes[$id] == 1;

    // Add item as an object in the questions array.
    $questions[] = $question;
  }

  // Save questions.
  quiz_set_questions($quiz, $questions, $is_new_revision);
  return $questions;
}