function _quiz_add_questions_to_form in Quiz 7.6
Same name and namespace in other branches
- 8.4 quiz.admin.inc \_quiz_add_questions_to_form()
- 6.4 quiz.admin.inc \_quiz_add_questions_to_form()
- 7 quiz.admin.inc \_quiz_add_questions_to_form()
- 7.4 quiz.admin.inc \_quiz_add_questions_to_form()
- 7.5 quiz.admin.inc \_quiz_add_questions_to_form()
Adds the questions in the $questions array to the form
Parameters
$form: FAPI form(array)
$questions: The questions to be added to the question list(array)
$quiz: The quiz node(object)
$question_types: array of all available question types
1 call to _quiz_add_questions_to_form()
- quiz_questions_form in ./
quiz.admin.inc - Handles "manage questions" tab.
File
- ./
quiz.admin.inc, line 869 - Administrator interface for Quiz module.
Code
function _quiz_add_questions_to_form(&$form, &$questions, &$quiz, &$question_types) {
$form['question_list']['weights'] = array(
'#tree' => TRUE,
);
$form['question_list']['qnr_ids'] = array(
'#tree' => TRUE,
);
$form['question_list']['qnr_pids'] = array(
'#tree' => TRUE,
);
$form['question_list']['max_scores'] = array(
'#tree' => TRUE,
);
$form['question_list']['auto_update_max_scores'] = array(
'#tree' => TRUE,
);
$form['question_list']['stayers'] = array(
'#tree' => TRUE,
);
$form['question_list']['revision'] = array(
'#tree' => TRUE,
);
if ($quiz->randomization == 2) {
$form['question_list']['compulsories'] = array(
'#tree' => TRUE,
);
}
foreach ($questions as $question) {
// @todo replace entire form with usage of question instance
$question_node = node_load($question->nid, $question->vid);
$instance = _quiz_question_get_instance($question_node);
$fieldset = 'question_list';
$id = $question->nid . '-' . $question->vid;
$form[$fieldset]['weights'][$id] = array(
'#type' => 'textfield',
'#size' => 3,
'#maxlength' => 4,
'#default_value' => isset($question->weight) ? $question->weight : 0,
);
$form[$fieldset]['qnr_pids'][$id] = array(
'#type' => 'textfield',
'#size' => 3,
'#maxlength' => 4,
'#default_value' => $question->qnr_pid,
);
$form[$fieldset]['qnr_ids'][$id] = array(
'#type' => 'textfield',
'#size' => 3,
'#maxlength' => 4,
'#default_value' => $question->qnr_id,
);
// Quiz directions don't have scoring...
$form[$fieldset]['max_scores'][$id] = array(
'#type' => $instance
->isGraded() ? 'textfield' : 'hidden',
'#size' => 2,
'#maxlength' => 2,
'#disabled' => isset($question->auto_update_max_score) ? $question->auto_update_max_score : FALSE,
'#default_value' => isset($question->max_score) ? $question->max_score : 0,
'#states' => array(
'disabled' => array(
"#edit-auto-update-max-scores-{$id}" => array(
'checked' => TRUE,
),
),
),
);
$form[$fieldset]['auto_update_max_scores'][$id] = array(
'#type' => $instance
->isGraded() ? 'checkbox' : 'hidden',
'#default_value' => isset($question->auto_update_max_score) ? $question->auto_update_max_score : 0,
);
// Add checkboxes to remove questions in js disabled browsers...
$form[$fieldset]['stayers'][$id] = array(
'#type' => 'checkbox',
'#default_value' => 0,
'#attributes' => array(
'class' => array(
'q-staying',
),
),
);
//Add checkboxes to mark compulsory questions for randomized quizzes.
if ($quiz->randomization == 2) {
$form[$fieldset]['compulsories'][$id] = array(
'#type' => 'checkbox',
'#default_value' => isset($question->question_status) ? $question->question_status == QUIZ_QUESTION_ALWAYS ? 1 : 0 : 0,
'#attributes' => array(
'class' => array(
'q-compulsory',
),
),
);
}
if (user_access('view quiz question outside of a quiz')) {
$link_options = array(
'attributes' => array(
'class' => array(
'handle-changes',
),
),
);
$question_titles = l($question->title, 'node/' . $question->nid, $link_options);
}
else {
$question_titles = check_plain($question->title);
}
$form[$fieldset]['titles'][$id] = array(
'#markup' => $question_titles,
);
$form[$fieldset]['types'][$id] = array(
'#markup' => $question_types[$question->type]['name'],
'#question_type' => $question->type,
);
$form[$fieldset]['view_links'][$id] = array(
'#markup' => l(t('Edit'), 'node/' . $question->nid . '/edit', array(
'query' => drupal_get_destination(),
'attributes' => array(
'class' => array(
'handle-changes',
),
),
)),
'#access' => node_access('update', node_load($question->nid, $question->vid)),
);
// For js enabled browsers questions are removed by pressing a remove link
$form[$fieldset]['remove_links'][$id] = array(
'#markup' => '<a href="#" class="rem-link">' . t('Remove') . '</a>',
);
// Add a checkbox to update to the latest revision of the question
if ($question->vid == $question->latest_vid) {
$update_cell = array(
'#markup' => t('<em>Up to date</em>'),
);
}
else {
$update_cell = array(
'#type' => 'checkbox',
'#title' => l(t('Latest'), 'node/' . $question->nid . '/revisions/' . $question->latest_vid . '/view') . ' of ' . l(t('revisions'), 'node/' . $question->nid . '/revisions'),
);
}
$form[$fieldset]['revision'][$id] = $update_cell;
}
}