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

CompletedTrainingExportHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 32
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A view() 0 11 1
A title() 0 4 1
A registerEvents() 0 9 1
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