|
1
|
|
|
<?php |
|
2
|
|
|
namespace Schedules; |
|
3
|
|
|
|
|
4
|
|
|
trait ShiftSchedule |
|
5
|
|
|
{ |
|
6
|
|
|
public function getRoleNameFromID($roleID) |
|
7
|
|
|
{ |
|
8
|
|
|
static $roles = null; |
|
9
|
|
|
if($roles === null) |
|
10
|
|
|
{ |
|
11
|
|
|
$dataTable = \DataSetFactory::getDataTableByNames('fvs', 'roles'); |
|
12
|
|
|
$tmp = $dataTable->read(); |
|
13
|
|
|
$roles = array(); |
|
14
|
|
|
$count = count($tmp); |
|
15
|
|
|
for($i = 0; $i < $count; $i++) |
|
16
|
|
|
{ |
|
17
|
|
|
if(isset($tmp[$i]['display_name'])) |
|
18
|
|
|
{ |
|
19
|
|
|
$roles[$tmp[$i]['short_name']] = $tmp[$i]['display_name']; |
|
20
|
|
|
} |
|
21
|
|
|
else |
|
22
|
|
|
{ |
|
23
|
|
|
$roles[$tmp[$i]['short_name']] = $tmp[$i]['short_name']; |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
return $roles[$roleID]; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function shiftSort($a, $b) |
|
31
|
|
|
{ |
|
32
|
|
|
return strcmp($this->getRoleNameFromID($a['roleID']), $this->getRoleNameFromID($b['roleID'])); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
View Code Duplication |
public function shiftTimeSort($a, $b) |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
$interval = $a['startTime']->diff($b['startTime']); |
|
38
|
|
|
if($interval->invert === 0) |
|
39
|
|
|
{ |
|
40
|
|
|
if($interval->h || $interval->i) |
|
41
|
|
|
{ |
|
42
|
|
|
return -1; |
|
43
|
|
|
} |
|
44
|
|
|
else |
|
45
|
|
|
{ |
|
46
|
|
|
return 0; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
else if($interval->invert === 1 && ($interval->h || $interval->days)) |
|
50
|
|
|
{ |
|
51
|
|
|
return 1; |
|
52
|
|
|
} |
|
53
|
|
|
print_r($interval); |
|
54
|
|
|
die(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getStringBetween($string, $start, $end) |
|
58
|
|
|
{ |
|
59
|
|
|
$index = strpos($string, $start); |
|
60
|
|
|
if($index === false) |
|
61
|
|
|
{ |
|
62
|
|
|
return $string; |
|
63
|
|
|
} |
|
64
|
|
|
$index++; |
|
65
|
|
|
$len = strpos($string, $end, $index) - $index; |
|
66
|
|
|
return substr($string, $index, $len); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function daySort($a, $b) |
|
70
|
|
|
{ |
|
71
|
|
|
$a_date = $this->getStringBetween($a, '(', ')'); |
|
72
|
|
|
$b_date = $this->getStringBetween($b, '(', ')'); |
|
73
|
|
|
return strcasecmp($a_date, $b_date); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
View Code Duplication |
public function groupSort($a, $b) |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
$aArr = explode(' ', $a); |
|
79
|
|
|
$bArr = explode(' ', $b); |
|
80
|
|
|
if($aArr[1] === 'PM' && $bArr[1] === 'AM') |
|
81
|
|
|
{ |
|
82
|
|
|
return 1; |
|
83
|
|
|
} |
|
84
|
|
|
else if($aArr[1] === 'AM' && $bArr[1] === 'PM') |
|
85
|
|
|
{ |
|
86
|
|
|
return -1; |
|
87
|
|
|
} |
|
88
|
|
|
return strcmp($a, $b); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.