Roman_applicant-site/app/Exports/DirectionsExport.php

99 lines
3.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Exports;
use App\Models\Direction;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
class DirectionsExport implements WithMapping, FromQuery, WithHeadings, ShouldAutoSize
{
public function query()
{
return Direction::query();
}
public function headings(): array
{
return [
'Код',
'Имя',
'Кафедры',
'Ур-нь обр.',
'Форма обр.',
'бюджетные места',
'квота',
'платн. места',
'ст-ть платн. мест',
'период',
'Профиль подготовки',
'вступительные испытания ЕГЕ (Обязательное)',
'вступительные испытания ЕГЕ (По выбору)',
'вступительные испытания СПО',
'вступительные испытания Магистратура'
];
}
public function map($row): array
{
return [
[
$row->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;
});
}
}