Completed
Push — master ( ac047e...863ff8 )
by Sheela
06:46
created

ProcessMonday::getDutyList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 2
1
<?php
2
3
namespace SET\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\Mail;
7
use SET\Duty;
8
use SET\Handlers\Duty\DutyList;
9
use SET\Mail\EmailAdminSummary;
10
use SET\Setting;
11
12
class ProcessMonday extends Command
13
{
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'emails:monday';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Process all commands for monday & send single email to Reporter';
27
28
    protected $classesToProcess = [
29
        'notes'     => SendReminders::class,
30
        'visits'    => ExpiringVisits::class,
31
        'records'   => RenewTraining::class,
32
        'destroyed' => DeleteUsers::class,
33
    ];
34
35
    /**
36
     * Execute the console command.
37
     *
38
     * @return mixed
39
     */
40
    public function handle()
41
    {
42
        $mailArray = [];
43
44
        foreach ($this->classesToProcess as $key => $class) {
45
            $mailArray[$key] = (new $class())->handle()->getList();
46
        }
47
48
        $mailArray['dutyLists'] = $this->getDutyList();
49
50
        //Send FSO a summary email with all the lists we retrieved.
51
        $this->sendReporterEmail($mailArray);
52
    }
53
54
    private function sendReporterEmail($array)
55
    {
56
        $reportAddress = Setting::get('summary_recipient', null);
57
        if ($reportAddress !== null) {
58
            Mail::to($reportAddress)->send(new EmailAdminSummary($array));
59
        }
60
    }
61
62
    /**
63
     * @return mixed
64
     */
65
    private function getDutyList()
66
    {
67
        $duties = Duty::all();
68
69
        return $duties->map(function ($item) {
70
            $userDateArray = (new DutyList($item))->emailOutput();
71
            $userDateArray->put('duty', $item);
72
73
            return $userDateArray;
74
        });
75
    }
76
}
77