Skip to content

Commit

Permalink
Modernized RO::downloadInFormat():
Browse files Browse the repository at this point in the history
lang optinon added
sign option added
  • Loading branch information
Vitexus committed Nov 29, 2023
1 parent ab6b9e6 commit 902077f
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/AbraFlexi/RO.php
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,7 @@ public function getInFormat(
$sign = false
) {
$response = null;
$formatBackup = $this->format;
if ($this->setFormat($format)) {
$urlParams = [];
switch ($format) {
Expand All @@ -2777,6 +2778,7 @@ public function getInFormat(
) {
$response = $this->lastCurlResponse;
}
$this->setFormat($formatBackup);
}
return $response;
}
Expand All @@ -2785,35 +2787,24 @@ public function getInFormat(
* Uloží dokument v daném formátu do složky v systému souborů
* Save document in given format to directory in filesystem
*
* @param string $format pdf/csv/xml/json/ ...
* @param string $destDir where to put file (prefix)
* @param string $reportName Template used to generate PDF
* @param string $format pdf/csv/xml/json/ ...
* @param string $destDir where to put file (prefix)
* @param string $reportName Template used to generate PDF
* @param string $lang Requested Language
* @param boolean $sign download digital signed
*
* @return string|null filename downloaded or none
*/
public function downloadInFormat(
string $format,
$destDir = './',
$reportName = null
$reportName = null,
$lang = null,
$sign = false
) {
$fileOnDisk = null;
$formatBackup = $this->format;
if ($this->setFormat($format)) {
$downloadTo = $destDir . $this->getEvidence() . '_' . $this->getMyKey() . '.' . $format;
if (
($this->doCurlRequest(empty($reportName) ? $this->apiURL : \Ease\Functions::addUrlParams(
$this->apiURL,
['report-name' => $reportName]
), 'GET') == 200) && (file_put_contents(
$downloadTo,
$this->lastCurlResponse
) !== false)
) {
$fileOnDisk = $downloadTo;
}
$this->setFormat($formatBackup);
}
return $fileOnDisk;
$downloaded = $this->getInFormat($format, $reportName, $lang, $sign);
return file_put_contents($downloadTo, $downloaded) ? $downloadTo : null;
}

/**
Expand Down

0 comments on commit 902077f

Please sign in to comment.