Skip to content
Snippets Groups Projects
Commit c3306956 authored by Liam Morland's avatar Liam Morland
Browse files

Issue #3052463: Refactor fillpdf_file_download(): Use 'switch'

parent 4fd14c64
No related branches found
No related tags found
No related merge requests found
......@@ -186,35 +186,38 @@ function fillpdf_file_download($uri) {
$usage = file_usage_list($file);
foreach ($usage['fillpdf'] as $type => $per_id) {
if ($type === 'fillpdf_form') {
// Only people who can manage forms can download the source forms.
if (user_access('administer pdfs')) {
return file_get_content_headers($file);
}
}
if ($type === 'fillpdf_file') {
foreach ($per_id as $id => $count) {
$raw_file_context = fillpdf_file_context_load($id);
if ($raw_file_context) {
// Expand the stored link into a stub context (entities not
// loaded).
$stub_context = fillpdf_link_to_stub_context($raw_file_context);
if ($stub_context['fid']) {
// Expand the stub context (load the entities).
$fillpdf_info = fillpdf_load($stub_context['fid']);
$file_context = fillpdf_load_entities($fillpdf_info, $stub_context['nids'], $stub_context['webforms'], $stub_context['uc_order_ids'], $stub_context['uc_order_product_ids'], $GLOBALS['user'], $stub_context['entity_ids']);
// Check access as if they were filling in the PDF from
// scratch.
if (fillpdf_merge_pdf_access($file_context['nodes'], $file_context['webforms'], $file_context['uc_orders'], $file_context['uc_order_products'])) {
// We don't need to add any special headers.
return file_get_content_headers($file);
switch ($type) {
case 'fillpdf_form':
// Only people who can manage forms can download the source forms.
if (user_access('administer pdfs')) {
return file_get_content_headers($file);
}
break;
case 'fillpdf_file':
foreach ($per_id as $id => $count) {
$raw_file_context = fillpdf_file_context_load($id);
if ($raw_file_context) {
// Expand the stored link into a stub context (entities not
// loaded).
$stub_context = fillpdf_link_to_stub_context($raw_file_context);
if ($stub_context['fid']) {
// Expand the stub context (load the entities).
$fillpdf_info = fillpdf_load($stub_context['fid']);
$file_context = fillpdf_load_entities($fillpdf_info, $stub_context['nids'], $stub_context['webforms'], $stub_context['uc_order_ids'], $stub_context['uc_order_product_ids'], $GLOBALS['user'], $stub_context['entity_ids']);
// Check access as if they were filling in the PDF from
// scratch.
if (fillpdf_merge_pdf_access($file_context['nodes'], $file_context['webforms'], $file_context['uc_orders'], $file_context['uc_order_products'])) {
// We don't need to add any special headers.
return file_get_content_headers($file);
}
}
}
}
}
break;
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment