Completed
Pull Request — master (#21)
by Shawn
08:00 queued 05:52
created

ProcessMonday::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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 = array();
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::where('name', 'report_address')->first();
57
58
        Mail::to($reportAddress->secondary, $reportAddress->primary)->send(new EmailAdminSummary($array));
59
    }
60
61
    /**
62
     * @return mixed
63
     */
64
    private function getDutyList()
65
    {
66
        $duties = Duty::all();
67
68
        return $duties->map(function ($item) {
69
            $userDateArray = (new DutyList($item))->emailOutput();
70
            $userDateArray->put('duty', $item);
71
72
            return $userDateArray;
73
        });
74
    }
75
}
76