initial commit
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Pensare Software.
|
||||
* User: Theo Weijmer
|
||||
* Date: 28/01/2017
|
||||
* Time: 14:00
|
||||
*/
|
||||
class ConvertToPdf {
|
||||
|
||||
private $ci;
|
||||
private $dossier;
|
||||
private $wordExtensions = ['.DOC', '.DOCX'];
|
||||
private $pdfExtensions = ['.PDF'];
|
||||
private $excelExtensions = ['.XLS', '.XSLX'];
|
||||
private $word;
|
||||
private $pdf;
|
||||
private $excel;
|
||||
private $conversionStatus;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->ci = &get_instance();
|
||||
|
||||
$this->ci->load->library( 'services/curl/CurlWrapper' );
|
||||
$this->ci->load->library( 'services/ConvertWord2PDF' );
|
||||
|
||||
$this->ci->load->config('conversionentities');
|
||||
}
|
||||
|
||||
public function getConversionStatus()
|
||||
{
|
||||
return $this->conversionStatus;
|
||||
}
|
||||
|
||||
public function handle( $dossier )
|
||||
{
|
||||
$this->setDossier( $dossier );
|
||||
|
||||
$this->setUploadType();
|
||||
|
||||
$this->convertContent();
|
||||
|
||||
$this->setNonConversion();
|
||||
}
|
||||
|
||||
private function setdossier( $dossier )
|
||||
{
|
||||
$this->dossier = $dossier;
|
||||
}
|
||||
|
||||
private function setUploadType()
|
||||
{
|
||||
$this->setWord();
|
||||
|
||||
$this->setPDF();
|
||||
|
||||
$this->setExcel();
|
||||
}
|
||||
|
||||
private function setWord()
|
||||
{
|
||||
if ( in_array( strtoupper( $this->dossier->extension ), $this->wordExtensions ) )
|
||||
return $this->word = TRUE;
|
||||
|
||||
$this->word = FALSE;
|
||||
}
|
||||
|
||||
private function setPDF()
|
||||
{
|
||||
if ( in_array( strtoupper( $this->dossier->extension ), $this->pdfExtensions ) )
|
||||
return $this->pdf = TRUE;
|
||||
|
||||
$this->pdf = FALSE;
|
||||
}
|
||||
|
||||
private function setExcel()
|
||||
{
|
||||
if ( in_array( strtoupper( $this->dossier->extension ), $this->excelExtensions ) )
|
||||
return $this->excel = TRUE;
|
||||
|
||||
$this->excel = FALSE;
|
||||
}
|
||||
|
||||
private function convertContent()
|
||||
{
|
||||
$this->convertWord();
|
||||
|
||||
$this->convertPDF();
|
||||
|
||||
$this->convertExcel();
|
||||
}
|
||||
|
||||
private function convertWord()
|
||||
{
|
||||
if ( ! $this->word ) return;
|
||||
|
||||
$this->ci->convertword2pdf->handle( $this->dossier );
|
||||
|
||||
if ( ! $this->ci->convertword2pdf->getConversionResult() )
|
||||
return $this->conversionStatus = $this->ci->config->item('failedconversion');
|
||||
|
||||
$this->conversionStatus = $this->ci->config->item('wordpdfconversionsuccess');
|
||||
}
|
||||
|
||||
private function convertPDF()
|
||||
{
|
||||
if ( ! $this->pdf ) return;
|
||||
|
||||
$this->conversionStatus = $this->ci->config->item('ispdfdocument');
|
||||
}
|
||||
|
||||
private function convertExcel()
|
||||
{
|
||||
if ( ! $this->excel ) return;
|
||||
|
||||
$this->conversionStatus = $this->ci->config->item('nonconversion');
|
||||
}
|
||||
|
||||
private function setNonConversion()
|
||||
{
|
||||
if ( $this->word ) return;
|
||||
if ( $this->pdf ) return;
|
||||
if ( $this->excel ) return;
|
||||
|
||||
$this->conversionStatus = $this->ci->config->item('nonconversion');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?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 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Pensare Software.
|
||||
* User: Theo Weijmer
|
||||
* Date: 27/11/2016
|
||||
* Time: 16:00
|
||||
*/
|
||||
class CurlWrapper {
|
||||
|
||||
private $curl;
|
||||
private $remoteURL;
|
||||
private $method;
|
||||
private $data;
|
||||
private $result;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
public function handle( $remoteURL, $method = 'POST', $data = [] )
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$this->setRemoteURL( $remoteURL );
|
||||
|
||||
$this->setMethod( $method );
|
||||
|
||||
$this->setData( $data );
|
||||
|
||||
$this->setCurlOptions();
|
||||
|
||||
$this->performRemoteCall();
|
||||
|
||||
$this->closeCurl();
|
||||
|
||||
// echo $this->result;
|
||||
}
|
||||
|
||||
private function initialize()
|
||||
{
|
||||
$this->curl = curl_init();
|
||||
}
|
||||
|
||||
private function setRemoteURL( $remoteURL )
|
||||
{
|
||||
$this->remoteURL = $remoteURL;
|
||||
}
|
||||
|
||||
private function setMethod( $method )
|
||||
{
|
||||
$this->method = $method;
|
||||
}
|
||||
|
||||
private function setData( $data )
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
private function setCurlOptions()
|
||||
{
|
||||
curl_setopt_array( $this->curl, [
|
||||
CURLOPT_RETURNTRANSFER => 1,
|
||||
CURLOPT_URL => $this->remoteURL,
|
||||
CURLOPT_POST => $this->method == 'POST' ? TRUE : FALSE,
|
||||
CURLOPT_POSTFIELDS => $this->data
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
private function performRemoteCall()
|
||||
{
|
||||
$this->result = curl_exec( $this->curl );
|
||||
}
|
||||
|
||||
private function closeCurl()
|
||||
{
|
||||
curl_close( $this->curl );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Pensare Software.
|
||||
* User: Theo Weijmer
|
||||
* Date: 12/02/2017
|
||||
* Time: 10:09
|
||||
*/
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class GuzzleWrapper {
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user