|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
+use App\Jobs\GenerateDocxJob;
|
|
|
use App\Models\Product;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
@@ -12,8 +13,6 @@ class ExportController extends Controller
|
|
|
$ids = json_decode($request->ids,true);
|
|
|
$products = Product::query()->whereIn('id', $ids)->orderBy('series', 'asc')->get();
|
|
|
|
|
|
- $my_template = new \PhpOffice\PhpWord\TemplateProcessor(storage_path('templates/template_maf.docx'));
|
|
|
-
|
|
|
$vars_for_template = [];
|
|
|
$i = 1;
|
|
|
foreach ($products as $product){
|
|
|
@@ -36,8 +35,6 @@ class ExportController extends Controller
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
$vars_for_template = array_merge($vars_for_template, [
|
|
|
'series#' . $i => $product->series,
|
|
|
'product_group#' .$i => $product->product_group,
|
|
|
@@ -51,35 +48,15 @@ class ExportController extends Controller
|
|
|
$i++;
|
|
|
}
|
|
|
|
|
|
-// dd($vars_for_template);
|
|
|
- $my_template->cloneBlock('product_block', count($products), true, true, $vars_for_template);
|
|
|
-
|
|
|
- foreach ($vars_for_template as $k => $v){
|
|
|
- $file = public_path() . '/' . env('IMAGES_PATH') . '/' . $v;
|
|
|
- if(str_starts_with($k, 'image') && file_exists($file) && $v !== ''){
|
|
|
- $my_template->setImageValue($k, ['path' => $file, 'width' => 270, 'height' => 180]);
|
|
|
- } else {
|
|
|
- $my_template->setValue($k, $v);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-// dd($vars_for_template);
|
|
|
+ // prepared vars - run job
|
|
|
|
|
|
+ $filename = 'export_' . date('YmdHis') . '.docx';
|
|
|
+ $job = GenerateDocxJob::dispatch($vars_for_template, count($products), $filename);
|
|
|
|
|
|
+ Log::notice('Created job. Execution time: ' . microtime(true) - LARAVEL_START);
|
|
|
|
|
|
- $file = 'Наш_Двор_' . date('YmdHis') . '.docx';
|
|
|
- header("Content-Description: File Transfer");
|
|
|
- header('Content-Disposition: attachment; filename="' . $file . '"');
|
|
|
- header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
|
|
|
- header('Content-Transfer-Encoding: binary');
|
|
|
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
|
|
- header('Expires: 0');
|
|
|
- ob_clean();
|
|
|
- $my_template->saveAs("php://output");
|
|
|
- Log::notice('Execution time: ' . microtime(true) - LARAVEL_START);
|
|
|
+ $data['filename'] = $filename;
|
|
|
+ return view('products.wait', $data);
|
|
|
|
|
|
- exit();
|
|
|
}
|
|
|
}
|