From b5951c2d3464262b18722ee391eeac55f0e54c0b Mon Sep 17 00:00:00 2001 From: aslan Date: Thu, 14 Mar 2024 16:12:44 +0300 Subject: [PATCH] add import xls --- app/Exports/DirectionsExport.php | 98 +++++++++++++++++++ .../admin/Catalog/DirectionController.php | 7 ++ app/Models/Direction.php | 5 + .../admin/catalog/direction/index.blade.php | 7 +- routes/admin.php | 2 +- 5 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 app/Exports/DirectionsExport.php diff --git a/app/Exports/DirectionsExport.php b/app/Exports/DirectionsExport.php new file mode 100644 index 0000000..073faa8 --- /dev/null +++ b/app/Exports/DirectionsExport.php @@ -0,0 +1,98 @@ +code, + $row->name, + $row->department->name, + $row->educationLevel->name, + $row->educationForm->name, + $row->budget_places, + $row->quota, + $row->paid_places, + $row->cost_paid_place, + $row->period, + implode("; ", $row->directionProfiles), + implode("; ", $row->egeCompulsory), + implode("; ", $row->egeOptional), + implode("; ", $row->spo), + implode("; ", $row->magistracy), + ] +// $row->entranceExaminations->name, + ]; + } + + public function prepareRows($rows) + { + return $rows->transform(function ($direction) { + $profilesNames = []; + foreach ($direction->directionProfiles as $profile) { + $profilesNames[] = $profile->name; + } + $direction->directionProfiles = $profilesNames; + + $egeCompulsory = []; + $egeOptional = []; + $spo = []; + $magistracy = []; + foreach ($direction->entranceExaminations as $examination) { + $subject = $examination->subject->name; + $scores = $examination->scores; + if ($examination->examinationType->name === 'ЕГЭ') { + if ($examination->subjectType->name === 'Обязательные') { + $egeCompulsory[] = "{$subject} ({$scores})"; + } elseif ($examination->subjectType->name === 'Предметы по выбору') { + $egeOptional[] = "{$subject} ({$scores})"; + } + } elseif ($examination->examinationType->name === 'СПО') { + $spo[] = "{$subject} ({$scores})"; + } elseif ($examination->examinationType->name === 'магитсратура') { + $magistracy[] = "{$subject} ({$scores})"; + } + } + $direction->egeCompulsory = $egeCompulsory; + $direction->egeOptional = $egeOptional; + $direction->spo = $spo; + $direction->magistracy = $magistracy; + return $direction; + }); + } +} diff --git a/app/Http/Controllers/admin/Catalog/DirectionController.php b/app/Http/Controllers/admin/Catalog/DirectionController.php index cffcc65..10f6d9a 100644 --- a/app/Http/Controllers/admin/Catalog/DirectionController.php +++ b/app/Http/Controllers/admin/Catalog/DirectionController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\admin\Catalog; use App\Enums\ExaminationTypeEnum; +use App\Exports\DirectionsExport; use App\Helpers\SlugHelper; use App\Http\Controllers\Controller; use App\Http\Requests\admin\Catalog\StoreDirectionRequest; @@ -23,6 +24,7 @@ use Illuminate\Foundation\Application; use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; +use Maatwebsite\Excel\Facades\Excel; class DirectionController extends Controller { @@ -303,4 +305,9 @@ class DirectionController extends Controller return redirect()->route('directions.index'); } + + public function exportXls() + { + return Excel::download(new DirectionsExport(), 'directions.xlsx'); + } } diff --git a/app/Models/Direction.php b/app/Models/Direction.php index c0c618a..f6a0804 100644 --- a/app/Models/Direction.php +++ b/app/Models/Direction.php @@ -20,6 +20,11 @@ class Direction extends Model 'position', 'slug', 'code', + 'budget_places', + 'quota', + 'paid_places', + 'cost_paid_place', + 'period', ]; public function department(): BelongsTo diff --git a/resources/views/admin/catalog/direction/index.blade.php b/resources/views/admin/catalog/direction/index.blade.php index 967c784..f5e652c 100644 --- a/resources/views/admin/catalog/direction/index.blade.php +++ b/resources/views/admin/catalog/direction/index.blade.php @@ -3,7 +3,10 @@

Направления


- Создать Направление +

@@ -28,7 +31,7 @@

@foreach($direction->directionProfiles as $directionProfile) - {{ $directionProfile->name }} + {{ $directionProfile->name }}
@endforeach

diff --git a/routes/admin.php b/routes/admin.php index e3fe115..6b0583c 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -18,7 +18,7 @@ use Rap2hpoutre\LaravelLogViewer\LogViewerController; Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () { Route::get('/logs', [LogViewerController::class, 'index']); - Route::get('/exportExcel', [LogViewerController::class, 'index']); + Route::get('/export_excel', [DirectionController::class, 'exportXls'])->name('export_excel'); Route::get('/dashboard', function () { return view('admin');