PluginProbe
ShiftController Employee Shift Scheduling / 4.9.66
ShiftController Employee Shift Scheduling v4.9.66
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / sh4 / shifts / duration.php

duration.php in ShiftController Employee Shift Scheduling 4.9.66, at sh4/shifts/duration.php

159 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 interface SH4_Shifts_IDuration
3 {
4 public function reset();
5 public function add( SH4_Shifts_Model $shift );
6 public function getQty();
7 public function getDuration();
8 public function getDurationHours();
9 public function formatDuration();
10 }
11
12 class SH4_Shifts_Duration implements SH4_Shifts_IDuration
13 {
14 protected $qty = 0;
15 protected $duration = 0;
16 protected $shifts = array();
17 protected $qtyTimeoff = 0;
18 protected $durationTimeoff = 0;
19 protected $settings;
20 protected $t;
21
22 public function __construct(
23 HC3_Settings $settings,
24 HC3_Time $t
25 )
26 {
27 $this->settings = $settings;
28 $this->t = $t;
29 }
30
31 public function reset()
32 {
33 $this->qty = 0;
34 $this->duration = 0;
35 $this->qtyTimeoff = 0;
36 $this->durationTimeoff = 0;
37 $this->shifts = array();
38 return $this;
39 }
40
41 public function add( SH4_Shifts_Model $model )
42 {
43 $id = $model->getId();
44 if( isset($this->shifts[$id]) ){
45 return $this;
46 }
47 $this->shifts[$id] = $id;
48
49 $start = $model->getStart();
50 $end = $model->getEnd();
51
52 $this->t->setDateTimeDb( $start );
53 $startTs = $this->t->getTimestamp();
54 $startDayStart = $this->t->setStartDay()->getTimestamp();
55 $startDate = $this->t->formatDateDb();
56 $startDayTs = $startTs - $startDayStart;
57
58 $this->t->setDateTimeDb( $end );
59 $endTs = $this->t->getTimestamp();
60 $endDayStart = $this->t->setStartDay()->getTimestamp();
61 $endDate = $this->t->formatDateDb();
62 $endDayTs = $endTs - $endDayStart;
63
64 $duration = abs( $endTs - $startTs );
65 if( ($startDayTs == 0) && ($endDayTs == 0) ){
66 $fullDayCountAs = $this->settings->get('full_day_count_as');
67
68 // $durationDays = $duration / (24 * 60 * 60);
69
70 $durationDays = 0;
71 $rexDate = $startDate;
72 $this->t->setDateDb( $rexDate );
73 while( $rexDate < $endDate ){
74 $durationDays++;
75 $rexDate = $this->t
76 ->modify( '+1 day' )
77 ->formatDateDb()
78 ;
79 }
80
81 $duration = $durationDays * $fullDayCountAs;
82 // echo "DD = '$durationDays'<br>";
83 }
84
85 $noBreak = $this->settings->get( 'shifttypes_nobreak' );
86 if( ! $noBreak ){
87 $breakStart = $model->getBreakStart();
88 $breakEnd = $model->getBreakEnd();
89
90 if( ! ((NULL === $breakStart) && (NULL === $breakEnd)) ){
91 $this->t->setDateTimeDb( $breakStart );
92 $breakStartTs = $this->t->getTimestamp();
93 $this->t->setDateTimeDb( $breakEnd );
94 $breakEndTs = $this->t->getTimestamp();
95
96 $breakDuration = abs( $breakEndTs - $breakStartTs );
97 $duration = $duration - $breakDuration;
98 }
99 }
100
101 $this->qty++;
102 $this->duration += $duration;
103
104 // is timeoff
105 $calendar = $model->getCalendar();
106 if( $calendar->isTimeoff() ){
107 $this->qtyTimeoff++;
108 $this->durationTimeoff += $duration;
109 }
110
111 return $this;
112 }
113
114 public function getDuration()
115 {
116 return $this->duration;
117 }
118
119 public function getDurationTimeoff()
120 {
121 return $this->durationTimeoff;
122 }
123
124 public function getDurationHours()
125 {
126 $return = $this->getDuration();
127 $return = $return / (60 * 60);
128 $return = sprintf( '%0.2f', $return );
129 return $return;
130 }
131
132 public function formatDuration( $duration = NULL )
133 {
134 if( NULL === $duration ){
135 $duration = $this->getDuration();
136 }
137
138 $hours = floor( $duration / (60 * 60) );
139 $remain = $duration - $hours * (60 * 60);
140 $minutes = floor( $remain / 60 );
141
142 $hoursView = $hours;
143 $minutesView = sprintf( '%02d', $minutes );
144
145 $return = $hoursView . ':' . $minutesView;
146 // $return = gmdate( "H:i", $this->getDuration() );
147 return $return;
148 }
149
150 public function getQty()
151 {
152 return $this->qty;
153 }
154
155 public function getQtyTimeoff()
156 {
157 return $this->qtyTimeoff;
158 }
159 }