Drupal 7批处理并打印

时间:2018-07-13 08:13:51

标签: drupal drupal-7

我正在Drupal 7上运行批处理(在表单内)以收集并存储在变量中。 批处理完成后,我想启动一个函数,该函数使用所有数据创建一个xls文件。

function questionnaire_export_finished($success, $results, $operations) {

// The 'success' parameter means no fatal PHP errors were detected. All
// other error management should be handled using 'results'.
if ($success) {
    format_plural(count($results), 'One post processed.', '@count posts processed.');
    _questionnaire_export_generate_report($results);
}
else {
    $message = t('Finished with an error.');
}
drupal_set_message($message);

}

如果我dpm $ results变量一切正常,

当我启动函数_questionnaire_export_generate_report($ results)时(到目前为止,我还没有使用实际结果数据修改该函数)

_questionnaire_export_generate_report($export_data) {
if (empty($export_data)) {
    exit();
}

$header = array('first_name', 'last_name', 'about_info');

// Create a array having xls information to print. It could be get from database.

$xls_data_to_print = array(
    '0'=>array(
        'first_name'=> 'John',
        'last_name'=> 'Rawal',
        'about_info'=> 'He is a great player.',
    ),

    '1'=>array(
        'first_name'=> 'John1',
        'last_name'=> 'Rawal1',
        'about_info'=> 'He is a great player1.',
    ),

);
$xls_content_row = "";
foreach($xls_data_to_print as $xls_ky => $xls_val){
    // Write a code here to generate XLS file with required details.
    // Use $xls_val->title OR $xls_val['title'] depending array type.
    $rows = array();
    $rows[]= $xls_val['first_name'];
    $rows[]= $xls_val['last_name'];
    $rows[]= $xls_val['about_info'];

    $xls_content_row .= implode("\t", array_values($rows)) . "\r\n";
}
$xls_content_header = implode("\t", array_values($header));
$xls_content = $xls_content_header."\n".$xls_content_row;
$filename = 'Xls_data_list_' . date("d_m_Y") . '.xls';
header("Content-type: text/plain; charset=UTF-8");
header("Content-Disposition: attachment; filename=" . $filename);
header("Content-Type: application/vnd.ms-excel");
header("Pragma: no-cache");
header("Expires: 0");
print $xls_content;
exit();

}

文件将按我的要求打印,但是批处理进度条仍在运行,并且批处理没有完成。

如果我放置“返回”;而不是'exit();'批处理完成但文件未打印。

我该怎么做才能完成批处理?

0 个答案:

没有答案