Passolution
This commit is contained in:
parent
f79806ffe8
commit
06fc3ba919
31 changed files with 337 additions and 119 deletions
|
|
@ -2,6 +2,7 @@
|
|||
namespace App\Services;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Storage;
|
||||
|
||||
class Passolution
|
||||
{
|
||||
|
|
@ -21,8 +22,16 @@ class Passolution
|
|||
private $enr;
|
||||
private $agency;
|
||||
|
||||
private $htmlText = "";
|
||||
private $pdfPath = [];
|
||||
|
||||
public function __construct()
|
||||
private $pdf_dir = "";
|
||||
private $pdf_path = "";
|
||||
private $pdf_name = "";
|
||||
|
||||
public $additionalContent = "";
|
||||
|
||||
public function __construct($data = [])
|
||||
{
|
||||
//User-ID of the travel agency to which the data is forwarded
|
||||
$this->aid = "sterntours@passolution.de";
|
||||
|
|
@ -44,7 +53,10 @@ class Passolution
|
|||
$this->enr = 123123;
|
||||
//Agency number of the travel agency to which the data is forwarded
|
||||
$this->agency = 1000;
|
||||
$this->fill();
|
||||
|
||||
$this->pdf_dir = 'pdf/passolution/';
|
||||
|
||||
$this->fill($data);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -57,11 +69,11 @@ class Passolution
|
|||
//Country-Code of the destination
|
||||
$this->destco = isset($data['destco']) ? $data['destco'] : 'de';
|
||||
//Travel dates in format DD-MM-YYYY
|
||||
$this->tdat = isset($data['tdat']) ? $data['tdat'] : '20-12-2020';
|
||||
$this->tdat = isset($data['tdat']) ? $data['tdat'] : date("d-m-Y");
|
||||
|
||||
}
|
||||
|
||||
public function read()
|
||||
public function read($create = false, $return = true)
|
||||
{
|
||||
|
||||
$url = "https://api01.passolution.de/condition/search.php";
|
||||
|
|
@ -94,47 +106,122 @@ class Passolution
|
|||
if(isset($body->status) && $body->status !== 200){
|
||||
return isset($body->message) ? $body->message : '';
|
||||
}
|
||||
$text = "";
|
||||
$this->htmlText = "";
|
||||
if(is_array($body->response)){
|
||||
foreach ($body->response as $response){
|
||||
$text .= "<p><strong>".$response->additionalContent."</strong></p>";
|
||||
$this->htmlText .= "<p><strong>".$response->additionalContent."</strong></p>";
|
||||
$this->additionalContent = trim(substr($response->additionalContent, (strpos($response->additionalContent, "/")+1)));
|
||||
|
||||
$text .= "<h2>".$response->entry->response->headline."</h2>";
|
||||
$text .= "<p>".$response->entry->response->content."</p>";
|
||||
$this->htmlText .= "<h2>".$response->entry->response->headline."</h2>";
|
||||
$this->htmlText .= "<p>".$response->entry->response->content."</p>";
|
||||
|
||||
$text .= "<h2>".$response->visa->response->headline."</h2>";
|
||||
$text .= "<p>".$response->visa->response->content."</p>";
|
||||
$this->htmlText .= "<h2>".$response->visa->response->headline."</h2>";
|
||||
$this->htmlText .= "<p>".$response->visa->response->content."</p>";
|
||||
|
||||
$text .= "<h2>".$response->transitvisa->response->headline."</h2>";
|
||||
$text .= "<p>".$response->transitvisa->response->content."</p>";
|
||||
$this->htmlText .= "<h2>".$response->transitvisa->response->headline."</h2>";
|
||||
$this->htmlText .= "<p>".$response->transitvisa->response->content."</p>";
|
||||
|
||||
$text .= "<h2>".$response->inoculation->response->headline."</h2>";
|
||||
$text .= "<p>".$response->inoculation->response->content."</p>";
|
||||
$this->htmlText .= "<h2>".$response->inoculation->response->headline."</h2>";
|
||||
$this->htmlText .= "<p>".$response->inoculation->response->content."</p>";
|
||||
}
|
||||
}else{
|
||||
$text .= "<p><strong>".$body->response->additionalContent."</strong></p>";
|
||||
$this->htmlText .= "<p><strong>".$body->response->additionalContent."</strong></p>";
|
||||
$this->additionalContent = trim(substr($body->response->additionalContent, (strpos($body->response->additionalContent, "/") +1)));
|
||||
|
||||
$text .= "<h2>".$body->response->entry->headline."</h2>";
|
||||
$text .= "<p>".$body->response->entry->content."</p>";
|
||||
$this->htmlText .= "<h2>".$body->response->entry->headline."</h2>";
|
||||
$this->htmlText .= "<p>".$body->response->entry->content."</p>";
|
||||
|
||||
$text .= "<h2>".$body->response->visa->headline."</h2>";
|
||||
$text .= "<p>".$body->response->visa->content."</p>";
|
||||
$this->htmlText .= "<h2>".$body->response->visa->headline."</h2>";
|
||||
$this->htmlText .= "<p>".$body->response->visa->content."</p>";
|
||||
|
||||
$text .= "<h2>".$body->response->transitvisa->headline."</h2>";
|
||||
$text .= "<p>".$body->response->transitvisa->content."</p>";
|
||||
$this->htmlText .= "<h2>".$body->response->transitvisa->headline."</h2>";
|
||||
$this->htmlText .= "<p>".$body->response->transitvisa->content."</p>";
|
||||
|
||||
$text .= "<h2>".$body->response->inoculation->headline."</h2>";
|
||||
$text .= "<p>".$body->response->inoculation->content."</p>";
|
||||
$this->htmlText .= "<h2>".$body->response->inoculation->headline."</h2>";
|
||||
$this->htmlText .= "<p>".$body->response->inoculation->content."</p>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return nl2br($text);
|
||||
if($create){
|
||||
$this->createPDF();
|
||||
}
|
||||
return nl2br($this->htmlText);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function createPDF(){
|
||||
|
||||
$this->createPDFName();
|
||||
$this->storagePath();
|
||||
|
||||
$this->onlyCreatePDF();
|
||||
|
||||
$this->pdfPath = [
|
||||
'filename' => $this->pdf_name,
|
||||
'disk' => Storage::disk('public')->path( $this->pdf_dir.$this->pdf_name ),
|
||||
'url' => Storage::disk('public')->url($this->pdf_dir.$this->pdf_name)
|
||||
];
|
||||
return $this->pdfPath;
|
||||
}
|
||||
|
||||
public function onlyCreatePDF(){
|
||||
$pdf_file = new CreatePDF('pdf.passolution');
|
||||
$pdf_file->create(['contents' => $this->htmlText], $this->pdf_name, 'save', $this->pdf_path.$this->pdf_dir);
|
||||
}
|
||||
|
||||
public function findOrCreatePDF($create = false){
|
||||
|
||||
$this->createPDFName();
|
||||
$this->storagePath();
|
||||
$bool = Storage::disk('public')->exists( $this->pdf_dir.$this->pdf_name );
|
||||
if(!$bool && $create){
|
||||
$this->read();
|
||||
$this->onlyCreatePDF();
|
||||
$bool = true;
|
||||
}
|
||||
|
||||
if($bool){
|
||||
$this->pdfPath = [
|
||||
'filename' => $this->pdf_name,
|
||||
'disk' => Storage::disk('public')->path( $this->pdf_dir.$this->pdf_name ),
|
||||
'url' => Storage::disk('public')->url($this->pdf_dir.$this->pdf_name),
|
||||
'size' => Storage::disk('public')->size($this->pdf_dir.$this->pdf_name),
|
||||
'date' => Storage::disk('public')->lastModified($this->pdf_dir.$this->pdf_name),
|
||||
];
|
||||
}
|
||||
|
||||
return $this->pdfPath;
|
||||
}
|
||||
|
||||
public function getPdfPath($key = null){
|
||||
if($key !== null && is_array($key)){
|
||||
$ret = [];
|
||||
foreach ($key as $k){
|
||||
if(isset($this->pdfPath[$k])){
|
||||
$ret[$k] = $this->pdfPath[$k];
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
if($key !== null && isset($this->pdfPath[$key])){
|
||||
return $this->pdfPath[$key];
|
||||
}
|
||||
|
||||
return $this->pdfPath;
|
||||
}
|
||||
|
||||
public function createPDFName(){
|
||||
$this->pdf_name = "Einreisebestimmungen_".$this->lang."_".$this->nat."-".$this->destco.".pdf";
|
||||
}
|
||||
|
||||
public function storagePath(){
|
||||
|
||||
if(!Storage::disk('public')->exists( $this->pdf_dir )){
|
||||
Storage::disk('public')->makeDirectory($this->pdf_dir); //creates directory
|
||||
}
|
||||
$this->pdf_path = Storage::disk('public')->getAdapter()->getPathPrefix();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue