| Total Complexity | 8 |
| Total Lines | 71 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class Export |
||
| 10 | { |
||
| 11 | |||
| 12 | public function export(Builder $query, $ext = 'xls') |
||
| 13 | { |
||
| 14 | // Create new export |
||
| 15 | $export = new ModelExport; |
||
| 16 | |||
| 17 | $export->type = $ext; |
||
| 18 | $export->query = $query->getModel(); |
||
| 19 | |||
| 20 | $export->save(); |
||
| 21 | |||
| 22 | ExportJob::dispatch( $export )->onQueue( 'exporting' ); |
||
| 23 | |||
| 24 | return $export; |
||
| 25 | } |
||
| 26 | |||
| 27 | |||
| 28 | |||
| 29 | public function showExportStatus($id) |
||
| 30 | { |
||
| 31 | // Map export instance |
||
| 32 | $export = ModelExport::findOrFail( $id ); |
||
|
|
|||
| 33 | |||
| 34 | return view( 'importexport::export.progress', compact( 'id' ) ); |
||
| 35 | } |
||
| 36 | |||
| 37 | |||
| 38 | /** |
||
| 39 | * Return export progress |
||
| 40 | * |
||
| 41 | * @param int $id |
||
| 42 | * @return \Illuminate\Http\Response json |
||
| 43 | */ |
||
| 44 | public function returnExportProgress($id) |
||
| 45 | { |
||
| 46 | // Map export instance |
||
| 47 | $export = ModelExport::findOrFail( $id ); |
||
| 48 | |||
| 49 | $data['status'] = 200; |
||
| 50 | |||
| 51 | if ( $export->result_rows > 0 ) { |
||
| 52 | |||
| 53 | $data['progress'] = round( ( $export->row_processed / $export->result_rows ) * 100 ); |
||
| 54 | |||
| 55 | } else { |
||
| 56 | |||
| 57 | $data['progress'] = 0; |
||
| 58 | |||
| 59 | } |
||
| 60 | |||
| 61 | // If progress completed return successful imported rows count |
||
| 62 | if ( $data['progress'] == 100 ) { |
||
| 63 | $data['exported'] = route( 'ladybirdweb.export.download', $export->id ); |
||
| 64 | } |
||
| 65 | |||
| 66 | return response()->json( $data ); |
||
| 67 | } |
||
| 68 | |||
| 69 | |||
| 70 | public function downloadExportedFile($id) |
||
| 80 | } |
||
| 81 | } |
||
| 82 |