function _quiz_add_hidden_questions in Quiz 8.4
Same name and namespace in other branches
- 6.4 quiz.admin.inc \_quiz_add_hidden_questions()
- 7 quiz.admin.inc \_quiz_add_hidden_questions()
- 7.4 quiz.admin.inc \_quiz_add_hidden_questions()
Adds all information about the hidden questions to the questions array.
Hidden questions are used to avoid unnecessary ajax calls.
Parameters
$questions: The questions already added to the question list(array)
$hidden_questions: The questions added to the browser(array)
$form_state: FAPI form_state(array)
$quiz: The quiz node
See also
quiz_questions_form
1 call to _quiz_add_hidden_questions()
- quiz_questions_form in ./
quiz.admin.inc - Handles "manage questions" tab.
File
- ./
quiz.admin.inc, line 755 - Administrator interface for Quiz module.
Code
function _quiz_add_hidden_questions(&$questions, &$hidden_questions, &$form_state, &$quiz) {
$cur_questions = array();
$vids = array();
foreach ($hidden_questions as $key => $id) {
$cur_question = new stdClass();
$matches = array();
// Find nid and vid
preg_match('/([0-9]+)-([0-9]+)/', $id, $matches);
$nid = $matches[1];
$vid = $matches[2];
// If a question already exists in the $questions array we won't add a new one...
$continue = FALSE;
foreach ($questions as $question) {
if ($question->vid == $vid) {
$continue = TRUE;
break;
}
}
if (!is_numeric($nid) || !is_numeric($vid) || $continue) {
continue;
}
$cur_question->nid = $nid;
$vids[] = $cur_question->vid = $vid;
$cur_question->weight = 0;
$cur_question->question_status = $quiz->randomization == 2 ? QUESTION_RANDOM : QUESTION_ALWAYS;
$cur_question->staying = isset($form_state['values']['stayers'][$id]) ? $form_state['values']['stayers'][$id] === '1' : FALSE;
$cur_questions[$cur_question->nid] = $cur_question;
}
if (count($vids) > 0) {
// We fetch the rest of the information for each question and adds node access security
$res = db_select('node', 'n');
$res
->fields('n', array(
'nid',
'type',
));
$res
->fields('r', array(
'title',
));
$res
->fields('p', array(
'max_score',
));
$res
->addField('n', 'vid', 'latest_vid');
$res
->join('node_field_revision', 'r', 'n.nid = r.nid');
$res
->join('quiz_question_properties', 'p', 'r.vid = p.vid');
$res
->condition('r.vid', $vids, 'in');
// TODO: Don't user db_fetch_object
foreach ($res
->execute() as $res_o) {
$cur_questions[$res_o->nid]->type = $res_o->type;
$cur_questions[$res_o->nid]->title = $res_o->title;
$cur_questions[$res_o->nid]->max_score = $res_o->type == 'scale' ? 0 : $res_o->max_score;
$cur_questions[$res_o->nid]->latest_vid = $res_o->latest_vid;
$questions[] = $cur_questions[$res_o->nid];
}
}
}