function questions_export_submit_drupal in Quiz 6.5
1 call to questions_export_submit_drupal()
- questions_export_form_submit in includes/
questions_export/ questions_export.admin.inc - This generic submit handler calls specific export functions
File
- includes/
questions_export/ questions_export.admin.inc, line 83
Code
function questions_export_submit_drupal($quiz_nid, $export_format) {
ob_start();
$questions = _questions_in_quiz($quiz_nid);
// $questions is an array of quiz question node object
$quiz_title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $quiz_nid));
$glue = $export_format === 'aiken' ? "\n" : ',';
// if the export type is 'aiken' use new line ("\n") else use comma (",") as glue for implode
// iterate through all the questions and generate file content.
foreach ($questions as $question) {
$line = array(
$question->type,
$question->body,
);
switch ($question->type) {
case 'matching':
foreach ($question->answer as $answer) {
$feedback = $answer['feedback'] ? $answer['feedback'] : t('nil');
// use 'nil' when there is no feedback
array_push($line, $answer['question'], $answer['answer'], $feedback);
}
break;
case 'multichoice':
foreach ($question->answers as $answer) {
$feedback = $answer['feedback'] ? $answer['feedback'] : t('nil');
// use 'nil' when there is no feedback
array_push($line, $answer['answer'], $feedback);
$correct_answer = $answer['is_correct'] ? $answer['answer'] : '';
print_r($correct_answer);
}
array_push($line, $correct_answer);
break;
case 'true_false':
$feedback = $question->feedback ? $feedback : t('nil');
// use 'nil' when there is no feedback
array_push($line, $question->correct_answer ? 'true' : 'false', $feedback);
break;
case 'short_answer':
$evaluation = array(
'case sensitive match',
'case insensitive match',
'regular expression match',
'manually score match',
);
array_push($line, $question->correct_answer, $question->maximum_score, $evaluation[$question->correct_answer_evaluation]);
break;
case 'long_answer':
array_push($line, $question->maximum_score);
break;
}
$output .= count($line) > 2 ? implode($glue, $line) . "\n\n" : '';
$line = array();
}
$filename = str_replace(' ', '_', $quiz_title) . '.txt';
$handle = @fopen('sites/default/files/' . $filename, 'w');
fwrite($handle, $output);
fclose($handle);
$headers = array(
'Content-Type: text/plain',
'Content-Disposition: attachment; filename=' . $filename,
);
$filepath = 'sites/default/files/' . $filename;
ob_clean();
file_transfer($filepath, $headers);
ob_end_clean();
}