Completed
Push — Framework-Dependencies-Upgrade ( c65851...f5579c )
by Sheela
21:02 queued 11:08
created

CompletedTrainingExportHandler::title()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace SET\Handlers\Excel;
4
5
//use Maatwebsite\Excel\Files\ExportHandler;
6
//use Maatwebsite\Excel\Concerns\FromCollection;
7
use Illuminate\Contracts\View\View;
8
use Maatwebsite\Excel\Concerns\FromView;
9
use Maatwebsite\Excel\Concerns\WithEvents;
10
use Maatwebsite\Excel\Concerns\WithTitle;
11
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
12
use Maatwebsite\Excel\Events\AfterSheet;
13
use SET\Training;
14
use SET\User;
15
16
class CompletedTrainingExportHandler implements FromView, WithEvents, ShouldAutoSize, WithTitle
17
{
18
    public function view(): View
19
    {
20
        $trainings = Training::all();
21
        $users = User::skipSystem()->with([
22
            'assignedTrainings' => function ($q) {
23
                $q->whereNotNull('completed_date')->orderBy('completed_date', 'desc');
24
            },
25
        ])->active()->orderBy('last_name')->get();
26
        return view('report.completed_training', ['users' => $users, 'trainings' => $trainings]);
27
28
    }
29
30
    public function title(): string
31
    {
32
        return 'User-Training';
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function registerEvents(): array
39
    {
40
        return [
41
            AfterSheet::class    => function(AfterSheet $event) {
42
                $cellRange = 'A1:ZZ1'; // All headers
43
                $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setBold(true);
44
            },
45
        ];
46
    }
47
}
48