Some checks failed
tests / ci (pull_request) Has been cancelled
- Updated LecturerController to load multiple departments for lecturers. - Modified LecturerRequest to accept an array of department IDs instead of a single department ID. - Changed Department model to establish a many-to-many relationship with Lecturer. - Adjusted Lecturer model to reflect the new many-to-many relationship with Department. - Updated LecturerService to handle multiple departments during creation and updates. - Created LecturerFactory and StudentFactory for generating test data. - Added a migration for the new lecturer_department pivot table. - Refactored seeder classes to accommodate the new structure for lecturers and departments. - Enhanced frontend components for creating and editing lecturers to support multiple department selection.
69 lines
1.9 KiB
PHP
69 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use App\Exports\Concerns\StyledHeadingRow;
|
|
use App\Models\User;
|
|
use App\Services\Admin\Users\LecturerService;
|
|
use Illuminate\Support\Enumerable;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
|
use Maatwebsite\Excel\Concerns\WithEvents;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
|
use Maatwebsite\Excel\Concerns\WithStyles;
|
|
|
|
class LecturersExport implements FromCollection, ShouldAutoSize, WithEvents, WithHeadings, WithMapping, WithStyles
|
|
{
|
|
use StyledHeadingRow;
|
|
|
|
public function __construct(
|
|
private readonly string $search = '',
|
|
private readonly ?string $gender = null,
|
|
private readonly ?int $departmentId = null,
|
|
) {}
|
|
|
|
public function title(): string
|
|
{
|
|
return 'Data Dosen';
|
|
}
|
|
|
|
public function collection(): Enumerable
|
|
{
|
|
return app(LecturerService::class)->forExport($this->search, $this->gender, $this->departmentId);
|
|
}
|
|
|
|
public function headings(): array
|
|
{
|
|
return [
|
|
'NIDN',
|
|
'Nama Lengkap',
|
|
'Username',
|
|
'Email',
|
|
'Nomor Telepon',
|
|
'Jurusan',
|
|
'Jenis Kelamin',
|
|
'Tempat Lahir',
|
|
'Tanggal Lahir',
|
|
'Alamat',
|
|
];
|
|
}
|
|
|
|
public function map($user): array
|
|
{
|
|
/** @var User $user */
|
|
return [
|
|
$user->lecturer?->lecturer_number ?? '-',
|
|
$user->profile?->full_name ?? '-',
|
|
$user->username,
|
|
$user->email,
|
|
$user->profile?->phone_number ?? '-',
|
|
$user->lecturer?->departments->pluck('name')->join(', ') ?: '-',
|
|
$user->profile?->gender?->label() ?? '-',
|
|
$user->profile?->birth_place ?? '-',
|
|
$user->profile?->birth_date?->format('d M Y') ?? '-',
|
|
$user->profile?->address ?? '-',
|
|
];
|
|
}
|
|
}
|