1 | <?php |
||
11 | class ActionItemsComposer |
||
12 | { |
||
13 | /** |
||
14 | * Bind data to the view. |
||
15 | * |
||
16 | * @param View $view |
||
17 | * |
||
18 | * @return void |
||
19 | */ |
||
20 | public function compose(View $view) |
||
21 | { |
||
22 | $dueTraining = $this->getDueTraining(); |
||
23 | $expiringVisits = $this->getExpiringVisits(); |
||
24 | $eligibilityRenewal = $this->getEligibilityRenewal(); |
||
25 | |||
26 | $view->with('dueTraining', $dueTraining) |
||
27 | ->with('expiringVisits', $expiringVisits) |
||
28 | ->with('eligibilityRenewal', $eligibilityRenewal); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @return \Illuminate\Database\Eloquent\Collection|static[] |
||
33 | */ |
||
34 | private function getDueTraining() |
||
35 | { |
||
36 | return Training::with(['users', 'assignedUsers' => function ($query) { |
||
37 | //filter the assignedusers we get back |
||
38 | $query->ActiveUsers() |
||
39 | ->whereNull('completed_date') |
||
40 | ->where('due_date', '<=', Carbon::now()); |
||
41 | }]) |
||
42 | ->whereHas('assignedUsers', function ($q) { |
||
43 | //filter the training we get. |
||
44 | $q->ActiveUsers() |
||
45 | ->whereNull('completed_date') |
||
46 | ->where('due_date', '<=', Carbon::now()); |
||
47 | }) |
||
48 | ->get(); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return \Illuminate\Database\Eloquent\Collection|static[] |
||
53 | */ |
||
54 | private function getExpiringVisits() |
||
62 | |||
63 | /** |
||
64 | * @return Collection |
||
65 | */ |
||
66 | private function getEligibilityRenewal() |
||
67 | { |
||
68 | $builtUser = new Collection(); |
||
69 | $users = User::where('elig_date', '<=', Carbon::now())->active()->get(); |
||
70 | |||
71 | foreach ($users as $user) { |
||
72 | $calculatedDays = $this->calculateDaysToRenewClearance($user); |
||
73 | |||
74 | $this->buildUserArray($calculatedDays, $builtUser, $user); |
||
75 | } |
||
76 | |||
77 | return $this->sortUserCollection($builtUser); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param $user |
||
82 | * |
||
83 | * @return int |
||
84 | */ |
||
85 | private function calculateDaysToRenewClearance($user) |
||
102 | |||
103 | /** |
||
104 | * @param int $calculatedDays |
||
105 | * @param $user |
||
106 | * @param $builtUser |
||
107 | */ |
||
108 | private function buildUserArray($calculatedDays, Collection $builtUser, User $user) |
||
118 | |||
119 | private function sortUserCollection($userArray) |
||
125 | } |
||
126 |