dfb40125 by Jeff Balicki

preview after every input

1 parent 2917db69
...@@ -32,9 +32,8 @@ class ApiController extends Controller ...@@ -32,9 +32,8 @@ class ApiController extends Controller
32 { 32 {
33 33
34 34
35 // $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"}]}'; 35 // $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"}]}';
36 36 //$styles = serialize(array("font-family"=>"Barber","font-size"=>"20","font-color"=>"cmyk 0 0 0 0","alignment"=>"left"));
37 //$styles = serialize(array("font-family"=>"Barber","font-size"=>"20","font-color"=>"cmyk 0 0 0 0","alignment"=>"left"));
38 //print_r($styles); 37 //print_r($styles);
39 //die(); 38 //die();
40 $apiCallId = new pdfModel(); 39 $apiCallId = new pdfModel();
...@@ -43,10 +42,6 @@ class ApiController extends Controller ...@@ -43,10 +42,6 @@ class ApiController extends Controller
43 $pdfId = new pdfModel(); 42 $pdfId = new pdfModel();
44 $pdfId = $pdfId->addPdf($apiCallId, $json); 43 $pdfId = $pdfId->addPdf($apiCallId, $json);
45 $json = json_decode($json); 44 $json = json_decode($json);
46
47
48
49
50 $storagePath = Storage::disk('public')->getDriver()->getAdapter()->getPathPrefix(); 45 $storagePath = Storage::disk('public')->getDriver()->getAdapter()->getPathPrefix();
51 $folder = str_replace(' ', '-', $json->pdf[0]->name); // Replaces all spaces with hyphens. 46 $folder = str_replace(' ', '-', $json->pdf[0]->name); // Replaces all spaces with hyphens.
52 $folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder); 47 $folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder);
...@@ -66,10 +61,6 @@ class ApiController extends Controller ...@@ -66,10 +61,6 @@ class ApiController extends Controller
66 $curl->download($pdfLocation, $storagePath . $folder . '/' . $file); 61 $curl->download($pdfLocation, $storagePath . $folder . '/' . $file);
67 $curl->close(); 62 $curl->close();
68 $fileEntry = New FileEntryController(); 63 $fileEntry = New FileEntryController();
69 // echo $storagePath . $folder . '/' . $file;
70 //$fileEntry->addfile( $folder . '/' . $file);
71
72
73 $im = new Imagick(); 64 $im = new Imagick();
74 $im->setResolution(300, 300); //set the resolution of the resulting jpg 65 $im->setResolution(300, 300); //set the resolution of the resulting jpg
75 if (! is_readable($storagePath . $folder . '/' . $file)) { 66 if (! is_readable($storagePath . $folder . '/' . $file)) {
...@@ -92,33 +83,56 @@ class ApiController extends Controller ...@@ -92,33 +83,56 @@ class ApiController extends Controller
92 $curl->close(); 83 $curl->close();
93 84
94 } 85 }
86 }
87 }
88
89
90 public function preview()
91 {
92 $json = Input::all();
93 $json = json_encode($json);
94 $json = json_decode($json);
95 $pdfLocation = $json->pdf[0]->pdfLocation;
96 $cust_id = $json->pdf[0]->custId;
97 $storagePath = Storage::disk('public')->getDriver()->getAdapter()->getPathPrefix();
95 98
96 99 foreach ($json->changes as $change) {
100 if ($change->change_type == 'img') {
101 $folder = str_replace(' ', '-', $json->pdf[0]->folder); // Replaces all spaces with hyphens.
102 $folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder);
103 $fileLocation = $change->fileLocation;
104 $file = explode('\\', $change->content);
105 $file = end($file);
106 $fileClean = str_replace(' ', '-', $file);
107 $curl = new Curl();
108 $curl->download($fileLocation.'/'.$fileClean , $storagePath . $folder . '/' . $fileClean);
109 $curl->close();
110 }
97 } 111 }
98 112
99 } 113 $json = json_encode($json);
114 $apiCallId = "3";
115 $pdfId = new pdfModel();
116 $pdfId = $pdfId->changePdf($apiCallId, $json);
117 $pdf = new PdfController();
118 $pdf = $pdf->pdf($pdfId);
119 $response = $pdfId;
120 $statusCode = 200;
121 return Response::json( $response, $statusCode);
122 }
100 123
101 public function update() 124 public function update()
102 { 125 {
103
104
105 $json = Input::all(); 126 $json = Input::all();
106
107 $json = json_encode($json); 127 $json = json_encode($json);
108 $json = json_decode($json); 128 $json = json_decode($json);
109 129 $pdfLocation = $json->pdf[0]->pdfLocation;
110 $pdfLocation = $json->pdf[0]->pdfLocation;
111 $cust_id = $json->pdf[0]->custId; 130 $cust_id = $json->pdf[0]->custId;
131 $storagePath = Storage::disk('public')->getDriver()->getAdapter()->getPathPrefix();
112 132
113 133 foreach ($json->changes as $change) {
114
115 $storagePath = Storage::disk('public')->getDriver()->getAdapter()->getPathPrefix();
116
117
118 foreach ($json->changes as $change) {
119 if ($change->change_type == 'img') { 134 if ($change->change_type == 'img') {
120 135 $folder = str_replace(' ', '-', $json->pdf[0]->folder); // Replaces all spaces with hyphens.
121 $folder = str_replace(' ', '-', $json->pdf[0]->folder); // Replaces all spaces with hyphens.
122 $folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder); 136 $folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder);
123 $fileLocation = $change->fileLocation; 137 $fileLocation = $change->fileLocation;
124 $file = explode('\\', $change->content); 138 $file = explode('\\', $change->content);
...@@ -127,36 +141,26 @@ class ApiController extends Controller ...@@ -127,36 +141,26 @@ class ApiController extends Controller
127 $curl = new Curl(); 141 $curl = new Curl();
128 $curl->download($fileLocation.'/'.$fileClean , $storagePath . $folder . '/' . $fileClean); 142 $curl->download($fileLocation.'/'.$fileClean , $storagePath . $folder . '/' . $fileClean);
129 $curl->close(); 143 $curl->close();
130 // chmod( $storagePath . $folder . '/' . $fileClean, 0777); 144 }
131
132 }
133 } 145 }
134 146
135 $json = json_encode($json); 147 $json = json_encode($json);
136 // $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"}]}';
137
138 //$apiCallId = new pdfModel(); 148 //$apiCallId = new pdfModel();
139 // $apiCallId = $apiCallId->addApiCall('1',$json); 149 // $apiCallId = $apiCallId->addApiCall('1',$json);
140 $apiCallId = "3"; 150 $apiCallId = "3";
141 $pdfId = new pdfModel(); 151 $pdfId = new pdfModel();
142 $pdfId = $pdfId->changePdf($apiCallId, $json); 152 $pdfId = $pdfId->changePdf($apiCallId, $json);
143
144 $pdf = new PdfController(); 153 $pdf = new PdfController();
145 $pdf = $pdf->pdf($pdfId); 154 $pdf = $pdf->pdf($pdfId);
146 $response = $pdfId; 155 $response = $pdfId;
147 $statusCode = 200; 156 $statusCode = 200;
148 //$UploaqdPdf = new GoogledriveuploadpdfController(); 157
149 //$UploaqdPdf->google_drive_upload($folder, 'new_'.$pdfLocation,$pdfId,$cust_id);
150 return Response::json( $response, $statusCode); 158 return Response::json( $response, $statusCode);
151 159 $UploaqdPdf = new GoogledriveuploadpdfController();
152 160 $UploaqdPdf->google_drive_upload($folder, 'new_'.$pdfLocation,$pdfId,$cust_id);
153
154
155 } 161 }
156 162
157 163 public function getList($json)
158
159 public function getList($json)
160 { 164 {
161 $rows = new pdfModel(); 165 $rows = new pdfModel();
162 $rows = $rows->getList($json)->get(); 166 $rows = $rows->getList($json)->get();
...@@ -170,8 +174,6 @@ class ApiController extends Controller ...@@ -170,8 +174,6 @@ class ApiController extends Controller
170 174
171 public function getPdf($json) 175 public function getPdf($json)
172 { 176 {
173
174
175 $rows = new pdfModel(); 177 $rows = new pdfModel();
176 $rows = $rows->getpdf($json)->get(); 178 $rows = $rows->getpdf($json)->get();
177 $response = $rows; 179 $response = $rows;
...@@ -181,8 +183,6 @@ class ApiController extends Controller ...@@ -181,8 +183,6 @@ class ApiController extends Controller
181 } 183 }
182 public function getPdfPriev($json) 184 public function getPdfPriev($json)
183 { 185 {
184
185
186 $rows = new pdfModel(); 186 $rows = new pdfModel();
187 $rows = $rows->getpdf($json)->get(); 187 $rows = $rows->getpdf($json)->get();
188 $response = $rows; 188 $response = $rows;
...@@ -195,9 +195,7 @@ class ApiController extends Controller ...@@ -195,9 +195,7 @@ class ApiController extends Controller
195 195
196 $rows = new pdfModel(); 196 $rows = new pdfModel();
197 $id = $rows->getpdfid($json)->get(); 197 $id = $rows->getpdfid($json)->get();
198 198 $rows = $rows->getpdf($id[0]->pdfid)->get();
199
200 $rows = $rows->getpdf($id[0]->pdfid)->get();
201 $response = $rows; 199 $response = $rows;
202 $statusCode = 200; 200 $statusCode = 200;
203 //var_dump($rows); 201 //var_dump($rows);
......
...@@ -23,34 +23,29 @@ Route::get('pdf/{id}', 'PdfController@pdf'); ...@@ -23,34 +23,29 @@ Route::get('pdf/{id}', 'PdfController@pdf');
23 23
24 Route::group(array('prefix' => 'api/v1'), function($json) 24 Route::group(array('prefix' => 'api/v1'), function($json)
25 { 25 {
26 26 Route::resource('add', 'ApiController@insert');
27 Route::resource('add', 'ApiController@insert');
28
29 Route::resource('get-list', 'ApiController@getList'); 27 Route::resource('get-list', 'ApiController@getList');
30 Route::resource('get-pdf', 'ApiController@getpdf'); 28 Route::resource('get-pdf', 'ApiController@getpdf');
31 Route::resource('api', 'FileEntryController@getApi'); 29 Route::resource('api', 'FileEntryController@getApi');
32 Route::resource('get-pdf-google', 'ApiController@getpdfgoogle'); 30 Route::resource('get-pdf-google', 'ApiController@getpdfgoogle');
33
34 31
35 }); 32 });
36 33
34
37 Route::any('api/update', 'ApiController@update'); 35 Route::any('api/update', 'ApiController@update');
36 Route::any('api/preview', 'ApiController@preview');
38 Route::post('api/authenticate', 'AuthenticateController@authenticate'); 37 Route::post('api/authenticate', 'AuthenticateController@authenticate');
39 Route::get('api/authenticate/user', 'AuthenticateController@getAuthenticatedUser'); 38 Route::get('api/authenticate/user', 'AuthenticateController@getAuthenticatedUser');
40 39
41 40
42 Route::any('fileentry/postUpload', 'FileEntryController@postUpload');
43
44 Route::get('fileentry/get/{filename}', [
45 'as' => 'getentry', 'uses' => 'FileEntryController@get']);
46
47 41
42 Route::any('fileentry/postUpload', 'FileEntryController@postUpload');
43 Route::get('fileentry/get/{filename}', [ 'as' => 'getentry', 'uses' => 'FileEntryController@get']);
48 Route::get('fileentry', 'FileEntryController@index'); 44 Route::get('fileentry', 'FileEntryController@index');
49 Route::get('fileentry/getImage/{folder}/{filename}', 'FileEntryController@getImage'); 45 Route::get('fileentry/getImage/{folder}/{filename}', 'FileEntryController@getImage');
50 Route::get('fileentry/getPDF/{folder}/{filename}', 'FileEntryController@getPDF'); 46 Route::get('fileentry/getPDF/{folder}/{filename}', 'FileEntryController@getPDF');
47 Route::post('fileentry/add',[ 'as' => 'addentry', 'uses' => 'FileEntryController@add']);
51 48
52 Route::post('fileentry/add',[
53 'as' => 'addentry', 'uses' => 'FileEntryController@add']);
54 49
55 Route::get('api/googlePdfUpload/{folder}/{filename}/{pdfid}/{id}', 'GoogledriveuploadpdfController@google_drive_upload'); 50 Route::get('api/googlePdfUpload/{folder}/{filename}/{pdfid}/{id}', 'GoogledriveuploadpdfController@google_drive_upload');
56 Route::get('auth/google/callback', 'GoogledriveuploadpdfController@google_drive_upload'); 51 Route::get('auth/google/callback', 'GoogledriveuploadpdfController@google_drive_upload');
......