124 lines
2.8 KiB
PHP
124 lines
2.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 28/01/2017
|
|
* Time: 14:20
|
|
*/
|
|
class ConvertWord2PDF {
|
|
|
|
private $ci;
|
|
private $pdf;
|
|
private $dossier;
|
|
private $remoteURL;
|
|
private $fileContent;
|
|
private $pdfFileLocation;
|
|
private $dossierFileName;
|
|
private $conversionResult;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->ci = &get_instance();
|
|
|
|
$this->ci->config->load('remote_urls');
|
|
}
|
|
|
|
public function getConversionResult()
|
|
{
|
|
return $this->conversionResult;
|
|
}
|
|
|
|
public function handle( $dossier )
|
|
{
|
|
$this->setDossier( $dossier );
|
|
|
|
$this->setDossierFileName();
|
|
log_message('error', 'voor excists');
|
|
if ( ! $this->checkIfFileExists() ) return $this->conversionResult = FALSE;
|
|
log_message('error', 'file excist');
|
|
$this->setRemoteURL();
|
|
|
|
$this->setFileContent();
|
|
|
|
$this->ci->curlwrapper->handle(
|
|
$this->remoteURL, 'POST', ['filecontents' => $this->fileContent] );
|
|
|
|
$this->setPDF();
|
|
|
|
$this->setPdfFileLocation();
|
|
|
|
$this->checkAndCreatePdfFileLocation();
|
|
|
|
$this->setConversionResult();
|
|
|
|
if ( ! $this->conversionResult ) return;
|
|
|
|
$this->persistPdfFile();
|
|
}
|
|
|
|
private function setDossier( $dossier )
|
|
{
|
|
$this->dossier = $dossier;
|
|
}
|
|
|
|
private function setDossierFileName()
|
|
{
|
|
$this->dossierFileName =
|
|
$this->ci->dossierpath . $this->dossier->subfolder . $this->dossier->new_name;
|
|
}
|
|
|
|
private function checkIfFileExists()
|
|
{
|
|
if ( file_exists( $this->dossierFileName ) ) return TRUE;
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
private function setRemoteURL()
|
|
{
|
|
$this->remoteURL =
|
|
$this->ci->config->item( 'PENSARE_SERVICE_URL' ) .
|
|
$this->ci->config->item( 'WORDPDF' );
|
|
}
|
|
|
|
private function setFileContent()
|
|
{
|
|
$this->fileContent =
|
|
file_get_contents( $this->dossierFileName );
|
|
|
|
$this->fileContent = base64_encode( $this->fileContent );
|
|
}
|
|
|
|
private function setPDF()
|
|
{
|
|
$this->pdf = $this->ci->curlwrapper->getResult();
|
|
}
|
|
|
|
private function setPdfFileLocation()
|
|
{
|
|
$this->pdfFileLocation = $this->ci->pdfpath;
|
|
}
|
|
|
|
private function checkAndCreatePdfFileLocation()
|
|
{
|
|
if ( file_exists( $this->pdfFileLocation ) ) return;
|
|
|
|
mkdir( $this->pdfFileLocation, 0755, TRUE );
|
|
}
|
|
|
|
private function setConversionResult()
|
|
{
|
|
if ( is_null( $this->pdf ) ) return $this->conversionResult = FALSE;
|
|
|
|
if ( ! $this->pdf ) return $this->conversionResult = FALSE;
|
|
|
|
$this->conversionResult = TRUE;
|
|
}
|
|
|
|
private function persistPdfFile()
|
|
{
|
|
file_put_contents(
|
|
$this->pdfFileLocation . $this->dossier->new_name, $this->pdf );
|
|
}
|
|
} |