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 @@