|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SET\Handlers\Duty; |
|
4
|
|
|
|
|
5
|
|
|
use SET\Duty; |
|
6
|
|
|
use SET\DutySwap; |
|
7
|
|
|
|
|
8
|
|
|
class DutyList |
|
9
|
|
|
{ |
|
10
|
|
|
private $duty; |
|
11
|
|
|
|
|
12
|
|
|
public function __construct($duty) |
|
13
|
|
|
{ |
|
14
|
|
|
if (is_int($duty)) { |
|
15
|
|
|
$duty = Duty::findOrFail($duty); |
|
16
|
|
|
} |
|
17
|
|
|
$this->duty = $duty; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function htmlOutput() |
|
21
|
|
|
{ |
|
22
|
|
|
return $this->processedList()->htmlOutput(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function scheduledUpdate() |
|
26
|
|
|
{ |
|
27
|
|
|
//build the list and write into the database the next record. |
|
28
|
|
|
$this->processedList()->iterateList(); |
|
29
|
|
|
//build the list again (with the new record on top) and generate our email output. |
|
30
|
|
|
return $this->processedList()->emailOutput(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function emailOutput() |
|
34
|
|
|
{ |
|
35
|
|
|
$userGroup = $this->processedList(); |
|
36
|
|
|
|
|
37
|
|
|
return $userGroup->emailOutput(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function setLastWorkedDate() |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->processedList()->setLastWorkedDate(); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param array $dateArray |
|
47
|
|
|
* @param array $IDArray |
|
48
|
|
|
* @param string $type |
|
49
|
|
|
*/ |
|
50
|
|
|
public function processSwapRequest(array $dateArray, array $IDArray, $type) |
|
51
|
|
|
{ |
|
52
|
|
|
for ($i = 0; $i < 2; $i++) { |
|
53
|
|
|
$futureSwap = DutySwap::where('date', $dateArray[$i]) |
|
54
|
|
|
->where('duty_id', $this->duty->id)->first(); |
|
55
|
|
|
$flippedI = ($i == 0 ? 1 : 0); |
|
56
|
|
|
|
|
57
|
|
|
if (is_null($futureSwap)) { |
|
58
|
|
|
$this->createDutySwap($dateArray[$i], $IDArray[$flippedI], $type); |
|
59
|
|
|
} else { |
|
60
|
|
|
$futureSwap->imageable_id = $IDArray[$flippedI]; |
|
61
|
|
|
$futureSwap->save(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
private function processedList() |
|
67
|
|
|
{ |
|
68
|
|
|
if ($this->duty->has_groups) { |
|
69
|
|
|
return new DutyGroups($this->duty); |
|
70
|
|
|
} else { |
|
71
|
|
|
return new DutyUsers($this->duty); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param $date |
|
77
|
|
|
* @param $ID |
|
78
|
|
|
* @param $type |
|
79
|
|
|
*/ |
|
80
|
|
|
private function createDutySwap($date, $ID, $type) |
|
81
|
|
|
{ |
|
82
|
|
|
DutySwap::create([ |
|
83
|
|
|
'imageable_id' => $ID, |
|
84
|
|
|
'imageable_type' => $type, |
|
85
|
|
|
'duty_id' => $this->duty->id, |
|
86
|
|
|
'date' => $date, |
|
87
|
|
|
]); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: