0596f80b by Jeff Balicki

working demo

1 parent 3d6cfd71
......@@ -97,12 +97,41 @@ class ApiController extends Controller
public function update()
{
$json = Input::all();
$apiCallId = new pdfModel();
$apiCallId = $apiCallId->addApiCall('1',$json);
//$apiCallId = "3";
$json = json_encode($json);
$json = json_decode($json);
$storagePath = Storage::disk('public')->getDriver()->getAdapter()->getPathPrefix();
foreach ($json->changes as $change) {
if ($change->change_type == 'img') {
$folder = str_replace(' ', '-', $json->pdf[0]->folder); // Replaces all spaces with hyphens.
$folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder);
$fileLocation = $change->fileLocation;
$file = explode('\\', $change->content);
$curl = new Curl();
$curl->download($fileLocation.'/'.end($file), $storagePath . $folder . '/' . end($file));
$curl->close();
}
}
$json = json_encode($json);
// $json = '{"pdf":[{"name":"Sample PDF Document","folder":"Sample","pdfLocation":"http://hotelpodlipou.sk/uploads/files/sample.pdf"}],"changes":[{"label":"none","locationUp":"400","locationRight":90,"pages":"1","content":"logo-sample-text_355-558.jpg","z-index":null,"idstylesPDF":1,"order":"2","style":null,"idchange_typePDF":2,"change_type":"2","fileLocation":"https://image.freepik.com/free-vector/logo-sample-text_355-558.jpg"},{"label":"text style","locationUp":"60","locationRight":290,"pages":"1","content":"519.642.4404 London","z-index":null,"idstylesPDF":2,"order":"1","style":"a:3:{s:11:\"font-family\";s:11:\"TradeGothic\";s:9:\"font-size\";s:2:\"14\";s:10:\"font-color\";s:16:\"cmyk 0 0.6 0.5 0\";}","idchange_typePDF":1,"change_type":"1"}]}';
//$apiCallId = new pdfModel();
// $apiCallId = $apiCallId->addApiCall('1',$json);
$apiCallId = "3";
$pdfId = new pdfModel();
$pdfId = $pdfId->addPdf($apiCallId, $json);
$pdfId = $pdfId->changePdf($apiCallId, $json);
$pdf = new PdfController();
$pdf = $pdf->pdf($pdfId);
$response = $pdf;
......@@ -139,6 +168,8 @@ class ApiController extends Controller
public function getPdf($json)
{
$rows = new pdfModel();
$rows = $rows->getpdf($json)->get();
$response = $rows;
......
......@@ -37,7 +37,9 @@ class FileEntryController extends Controller {
return redirect('fileentry');
}
public function getone($folder, $filename){
public function getImage($folder, $filename){
//$entry = Fileentry::where('filename', '=', $filename)->firstOrFail();
$file = Storage::disk('public')->get($folder.'/'.$filename);
......@@ -46,6 +48,17 @@ class FileEntryController extends Controller {
->header('Content-Type', 'image/jpeg');
}
public function getPDF($folder, $filename){
//$entry = Fileentry::where('filename', '=', $filename)->firstOrFail();
$file = Storage::disk('public')->get($folder.'/'.$filename);
return (new Response($file, 200))
->header('Content-Type','application/pdf');
}
public function get($filename){
$entry = Fileentry::where('filename', '=', $filename)->firstOrFail();
......@@ -55,6 +68,46 @@ class FileEntryController extends Controller {
->header('Content-Type', $entry->mime);
}
public function postUpload(){
$files = Input::file('files');
$json = array(
'files' => array()
);
foreach( $files as $file ):
$filename = $file->getClientOriginalName().".".$file->getClientOriginalExtension();
$json['files'][] = array(
'name' => $filename,
'size' => $file->getSize(),
'type' => $file->getMimeType(),
'url' => '/uploads/files/'.$filename,
'deleteType' => 'DELETE',
'deleteUrl' => self::$route.'/deleteFile/'.$filename,
);
$upload = $file->move( public_path().'/files', $filename );
endforeach;
return Response::json($json);
}
public function getApi($json)
{
$file = Storage::disk('public')->get('js/interface.js');
......
......@@ -23,18 +23,20 @@ use PDFlib;
class PdfController extends Controller
{
public function pdf($id)
public function pdf($pdfId)
{
$rows = new pdfModel();
$rows = $rows->getpdf($id)->get();
$rows = $rows->getpdf($pdfId)->get();
$folder = $rows[0]->folder;
$searchpath = "$folder";
$pdffile = $searchpath.'/'.$rows[0]->file;
$outfile="";
//$outfile="";
$title = "Test Pages";
$storagePath = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix();
$storagePath = Storage::disk('public')->getDriver()->getAdapter()->getPathPrefix();
$outfile = $storagePath.$searchpath."/new_".$rows[0]->file;
$download = 'http://localhost:8888/pdf-customizer/public/fileentry/getPDF/'.$searchpath."/new_".$rows[0]->file;
try {
......@@ -152,12 +154,12 @@ try {
$p->end_document("");
return $outfile;
return $download;
/// To turn on pdf screen out put uncomment below lines and remove the text in $output="" Var
//$buf = $p->get_buffer();
//$len = strlen($buf);
// $buf = $p->get_buffer();
// $len = strlen($buf);
//header("Content-type: application/pdf");
//header("Content-Length: $len");
......
......@@ -11,7 +11,7 @@ class VerifyCsrfToken extends BaseVerifier
*
* @var array
*/
protected $except = [
protected $except = [ 'api/update', 'fileentry/postUpload'
//
];
}
......
......@@ -30,14 +30,16 @@ Route::group(array('prefix' => 'api/v1'), function($json)
});
Route::get('api/update/1', 'ApiController@update');
Route::any('api/update', 'ApiController@update');
Route::any('fileentry/postUpload', 'FileEntryController@postUpload');
Route::get('fileentry/get/{filename}', [
'as' => 'getentry', 'uses' => 'FileEntryController@get']);
Route::get('fileentry', 'FileEntryController@index');
Route::get('fileentry/getone/{folder}/{filename}', 'FileEntryController@getone');
Route::get('fileentry/getImage/{folder}/{filename}', 'FileEntryController@getImage');
Route::get('fileentry/getPDF/{folder}/{filename}', 'FileEntryController@getPDF');
Route::post('fileentry/add',[
'as' => 'addentry', 'uses' => 'FileEntryController@add']);
......
......@@ -18,6 +18,7 @@ class pdfModel extends Model
public function getPdf($id){
$rows = DB::table('PDF')
->join('changesPDF', 'PDF_idPDF', '=', 'idPDF')
->join('stylesPDF', 'stylesPDF_idstylesPDF', '=', 'idstylesPDF')
......@@ -66,6 +67,7 @@ class pdfModel extends Model
$fileName = end($file);
$fileName = explode('.', $fileName);
$pdfId = DB::table('PDF')->insertGetId(
array('name' => $json->pdf[0]->name, 'folder' => $folder, 'file' => end($file), 'apiCallId' => $apiCallId, 'image'=> $fileName[0].'.jpg')
);
......@@ -87,5 +89,49 @@ class pdfModel extends Model
}
public function changePdf($apiCallId, $json){
$json = json_decode($json);
$folder = str_replace(' ', '-', $json->pdf[0]->name); // Replaces all spaces with hyphens.
$folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder);
$pdfLocation = $json->pdf[0]->pdfLocation;
$file = explode('/', $pdfLocation);
$fileName = end($file);
$fileName = explode('.', $fileName);
$pdfId = DB::table('PDF')->insertGetId(
array('name' => $json->pdf[0]->name, 'folder' => $folder, 'file' => end($file), 'apiCallId' => $apiCallId, 'image'=> $fileName[0].'.jpg')
);
foreach($json->changes as $change) {
if ($change->change_type == 'img') {
$content = explode('\\', $change->content);
$content = end($content);
}else{
$content = $change->content;
}
$idstylesPDF = DB::table('stylesPDF')->insertGetId(
array('label' => $change->label, 'style' => 'a:3:{s:11:"font-family";s:11:"TradeGothic";s:9:"font-size";s:2:"14";s:10:"font-color";s:14:"cmyk 0 0 0.5 0";}')
);
$idchangesPDF = DB::table('changesPDF')->insertGetId(
array('PDF_idPDF' => $pdfId, 'change_typePDF_idchange_typePDF' => $change->idchange_typePDF, 'stylesPDF_idstylesPDF' => $idstylesPDF, 'locationUp' => $change->locationUp, 'locationRight' => $change->locationRight, 'pages' => $change->pages, 'content' => $content, 'z-index' => '')
);
}
return $pdfId;
}
}
......
This diff could not be displayed because it is too large.
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type