function _quiz_update_items in Quiz 7.5
Same name and namespace in other branches
- 8.4 quiz.admin.inc \_quiz_update_items()
- 6.6 quiz.admin.inc \_quiz_update_items()
- 6.4 quiz.admin.inc \_quiz_update_items()
- 7.6 quiz.admin.inc \_quiz_update_items()
- 7 quiz.admin.inc \_quiz_update_items()
- 7.4 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 1069 - Administrator interface for Quiz module.
Code
function _quiz_update_items($quiz, $weight_map, $max_scores, $auto_update_max_scores, $is_new_revision, $refreshes, $stayers, $qnr_ids, $qnr_pids, $compulsories = NULL) {
$questions = array();
foreach ($weight_map as $id => $weight) {
if ($stayers[$id]) {
continue;
}
list($nid, $vid) = explode('-', $id, 2);
$nid = (int) $nid;
$vid = (int) $vid;
$question = new stdClass();
$question->child_nid = $nid;
if (!empty($refreshes[$id])) {
// User marked to update question to latest revision.
$question_node = node_load($nid);
$question->child_vid = $question_node->vid;
}
else {
// Use the provided nid/vid.
$question->child_vid = $vid;
}
if (isset($compulsories)) {
if ($compulsories[$id] == 1) {
$question->question_status = QUIZ_QUESTION_ALWAYS;
}
else {
$question->question_status = QUIZ_QUESTION_RANDOM;
$max_scores[$id] = $quiz->max_score_for_random;
}
}
else {
$question->question_status = QUIZ_QUESTION_ALWAYS;
}
$question->weight = $weight;
$question->max_score = $max_scores[$id];
$question->auto_update_max_score = $auto_update_max_scores[$id];
$question->qnr_pid = $qnr_pids[$id] > 0 ? $qnr_pids[$id] : NULL;
$question->qnr_id = $qnr_ids[$id] > 0 ? $qnr_ids[$id] : NULL;
// Add item as an object in the questions array.
$questions[] = $question;
}
// Save questions.
quiz_set_questions($quiz, $questions, $is_new_revision);
return $questions;
}