function _quiz_get_questions_from_form_state in Quiz 7
Same name and namespace in other branches
- 8.4 quiz.admin.inc \_quiz_get_questions_from_form_state()
- 6.4 quiz.admin.inc \_quiz_get_questions_from_form_state()
- 7.4 quiz.admin.inc \_quiz_get_questions_from_form_state()
Returns the questions that was in the question list when the form was submitted using ajax.
Parameters
$form_state: FAPI form_state(array)
Return value
$questions Array of questions as objects
1 call to _quiz_get_questions_from_form_state()
- quiz_questions_form in ./
quiz.admin.inc - Handles "manage questions" tab.
File
- ./
quiz.admin.inc, line 976 - Administrator interface for Quiz module.
Code
function _quiz_get_questions_from_form_state(&$form_state, &$questions_to_add) {
$questions = array();
// We first store all data from the post in a temporary array.
// Then we fetch more data for each question from the database.
$cur_questions = array();
$vids = array();
foreach ($form_state['post']['weights'] as $id => $value) {
$cur_question = new stdClass();
// Find nid and vid
$matches = array();
preg_match('/([0-9]+)-([0-9]+)/', $id, $matches);
$cur_question->nid = $matches[1];
if (!is_numeric($matches[2])) {
continue;
}
$vids[] = $cur_question->vid = $matches[2];
$cur_question->max_score = intval($form_state['post']['max_scores'][$id]);
$cur_question->weight = intval($value);
$cur_question->staying = $form_state['post']['stayers'][$id] === '1';
$cur_question->question_status = QUESTION_ALWAYS;
if ($cur_question->staying == TRUE) {
$questions_to_add[] = $id;
}
$cur_questions[$cur_question->nid] = $cur_question;
}
$query = db_select('node_revision', 'r');
$table_alias = $query
->join('node', 'n', 'n.nid = r.nid');
$res = $query
->addField('n', 'nid')
->addTag('node_access')
->addField('n', 'type')
->addField('n', 'vid', 'latest_vid')
->addField('r', 'title')
->condition('r.vid', $vids, 'IN')
->execute();
// TODO: Don't use db_fetch_object
while ($res_o = db_fetch_object($res)) {
$cur_questions[$res_o->nid]->type = $res_o->type;
$cur_questions[$res_o->nid]->title = check_plain($res_o->title);
$cur_questions[$res_o->nid]->latest_vid = $res_o->latest_vid;
$questions[] = $cur_questions[$res_o->nid];
}
return $questions;
}