function quiz_questions_form in Quiz 5
Same name and namespace in other branches
- 8.4 quiz.admin.inc \quiz_questions_form()
- 5.2 quiz.module \quiz_questions_form()
- 6.6 quiz.admin.inc \quiz_questions_form()
- 6.2 quiz.admin.inc \quiz_questions_form()
- 6.3 quiz.admin.inc \quiz_questions_form()
- 6.4 quiz.admin.inc \quiz_questions_form()
- 6.5 quiz.admin.inc \quiz_questions_form()
- 7.6 quiz.admin.inc \quiz_questions_form()
- 7 quiz.admin.inc \quiz_questions_form()
- 7.4 quiz.admin.inc \quiz_questions_form()
- 7.5 quiz.admin.inc \quiz_questions_form()
Handles "Manage questions" tab
Displays form which allows questions to be assigned to the given quiz
Return value
HTML output to create page
1 string reference to 'quiz_questions_form'
File
- ./
quiz.module, line 1063 - Quiz Module
Code
function quiz_questions_form() {
$quiz = node_load(arg(1));
// Set page title
drupal_set_title(check_plain($quiz->title));
// show the number of questions that this quiz currently has
$form['numberofquestions'] = array(
'#prefix' => '<div class="quiz_questions_number">',
'#value' => t('This @quiz consists of %x @question.', array(
'@quiz' => QUIZ_NAME,
'%x' => check_plain($quiz->number_of_questions),
'@question' => format_plural($quiz->number_of_questions, t('question'), t('questions')),
)),
'#suffix' => '</div><br />' . "\n",
);
// Display links to create other questions
$form['additional_questions'] = array(
'#type' => 'fieldset',
'#title' => t('Create additional questions'),
'#theme' => 'additional_questions',
);
foreach (_quiz_get_question_types() as $type) {
$form['additional_questions'][$type] = array(
'#type' => 'markup',
'#value' => l(t($type), 'node/add/' . $type . '/' . $quiz->nid, array(
'title' => t('Go to ' . $type . ' administration'),
)) . ' ',
);
}
// Get questions assigned to this quiz
$questions = _quiz_get_questions();
// Display questions
$form['assigned_questions'] = array(
'#type' => 'fieldset',
'#title' => t('Questions assigned to this @quiz', array(
'@quiz' => QUIZ_NAME,
)),
);
$form['assigned_questions']['questions'] = array(
'#type' => 'markup',
'#value' => theme('quiz_question_table', $questions, $quiz->nid),
);
// Retrieve question list from database
$sql = "SELECT DISTINCT n.nid, n.type, r.body, r.format FROM {node} n, {node_revisions} r WHERE n.nid = r.nid AND n.type IN ('" . implode("','", _quiz_get_question_types()) . "') ";
$result = db_query($sql);
// Create questions array
$questions = array();
while ($node = db_fetch_object($result)) {
$questions[$node->nid] = quiz_node_map($node);
}
$result = db_query('SELECT question_nid, question_status FROM {quiz_questions} WHERE quiz_nid = %d', $quiz->nid);
while ($assigned_question = db_fetch_object($result)) {
if (array_key_exists($assigned_question->question_nid, $questions)) {
$the_question =& $questions[$assigned_question->question_nid];
$the_question->status = $assigned_question->question_status;
}
}
// Display filtered question list
$form['filtered_question_list'] = array(
'#type' => 'fieldset',
'#title' => t('The following questions were found'),
'#theme' => 'quiz_filtered_questions',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['filtered_question_list']['question_status']['#tree'] = TRUE;
while (list($key, $question) = each($questions)) {
$form['filtered_question_list']['question_status'][$question->nid] = array(
'#type' => 'radios',
'#options' => array(
QUESTION_RANDOM => '',
QUESTION_ALWAYS => '',
QUESTION_NEVER => '',
),
'#default_value' => $question->status,
);
$form['filtered_question_list']['question'][$question->nid] = array(
'#type' => 'markup',
'#value' => $question->question,
);
$form['filtered_question_list']['type'][$question->nid] = array(
'#type' => 'markup',
'#value' => $question->type,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit questions'),
);
return $form;
}