Skip to content

Commit ede41ee

Browse files
committed
refactor: replace is_streamgraph with vis_type
1 parent f920871 commit ede41ee

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

server/services/getPDF.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
$filename = library\CommUtils::getParameter($_GET, "filename");
1616
$service = library\CommUtils::getParameter($_GET, "service");
1717
$pdf_urls = library\CommUtils::getParameter($_GET, "pdf_urls");
18-
$vis_id = library\CommUtils::getParameter($_GET, "vis_id");
1918
$paper_id = library\CommUtils::getParameter($_GET, "paper_id");
20-
$is_streamgraph = strtolower(library\CommUtils::getParameter($_GET, "vis_type")) === 'timeline';
19+
$vis_id = library\CommUtils::getParameter($_GET, "vis_id");
20+
$vis_type = library\CommUtils::getParameter($_GET, "vis_type");
21+
2122
$images_path = $ini_array["general"]["images_path"];
2223

2324
if (isServiceWithPDFList($service)) {
24-
handleMultiPdfService($vis_id, $paper_id, $images_path, $filename, $is_streamgraph);
25+
handleMultiPdfService($vis_id, $paper_id, $images_path, $filename, $vis_type);
2526
} else {
26-
handleSingleUrlService($vis_id, $paper_id, $url, $images_path, $filename, $is_streamgraph);
27+
handleSingleUrlService($vis_id, $paper_id, $url, $images_path, $filename, $vis_type);
2728
}
2829

2930
library\CommUtils::echoOrCallback(json_encode(array("status" => "success", "file" => $filename)), $_GET);
@@ -37,9 +38,9 @@ function handleMultiPdfService(
3738
string $paper_id,
3839
string $images_path,
3940
string $filename,
40-
bool $is_streamgraph
41+
string $vis_type
4142
): void {
42-
$valid_pdf_urls = getValidURLs($vis_id, $paper_id, $is_streamgraph);
43+
$valid_pdf_urls = getValidURLs($vis_id, $paper_id, $vis_type);
4344
$filtered_urls_string = implode(";", $valid_pdf_urls);
4445
$pdf_link = getPDFLinkForBASE($filtered_urls_string);
4546

@@ -56,9 +57,9 @@ function handleSingleUrlService(
5657
string $url,
5758
string $images_path,
5859
string $filename,
59-
bool $is_streamgraph
60+
string $vis_type
6061
): void {
61-
$valid_pdf_urls = getValidURLs($vis_id, $paper_id, $is_streamgraph);
62+
$valid_pdf_urls = getValidURLs($vis_id, $paper_id, $vis_type);
6263

6364
$decoded_input_url = urldecode($url);
6465
$normalized_valid_urls = array_map('urldecode', $valid_pdf_urls);
@@ -70,14 +71,14 @@ function handleSingleUrlService(
7071
getPDFAndDownload($decoded_input_url, $images_path, $filename);
7172
}
7273

73-
function getValidURLs(string $vis_id, string $paper_id, bool $is_streamgraph) {
74+
function getValidURLs(string $vis_id, string $paper_id, string $vis_type) {
7475
$revision_data = fetchLatestRevision($vis_id);
7576

7677
if (!$revision_data) {
7778
returnError("There are no revision data for such visualization id");
7879
}
7980

80-
$valid_pdf_urls = extractValidPdfUrls($revision_data, $paper_id, $is_streamgraph);
81+
$valid_pdf_urls = extractValidPdfUrls($revision_data, $paper_id, $vis_type);
8182

8283
if (empty($valid_pdf_urls)) {
8384
returnError("There are no valid PDF URLs from revision");
@@ -104,14 +105,14 @@ function fetchLatestRevision(string $vis_id): ?array {
104105
return $revision_data;
105106
}
106107

107-
function extractValidPdfUrls(array $revision_data, string $paper_id, bool $is_streamgraph): array {
108+
function extractValidPdfUrls(array $revision_data, string $paper_id, string $vis_type): array {
108109
$valid_urls = [];
109110

110111
$inner_data = json_decode($revision_data["data"], true);
111112
$documents_raw = $inner_data["documents"] ?? null;
112113
$documents = json_decode($documents_raw, true);
113114

114-
if ($is_streamgraph) {
115+
if (strtolower($vis_type) == 'timeline') {
115116
$inner_data = json_decode($inner_data["data"]);
116117
$documents_raw = json_encode($inner_data);
117118
$documents = json_decode($documents_raw, true);

0 commit comments

Comments
 (0)