PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
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 / schedule / html / view / report.php

report.php in ShiftController Employee Shift Scheduling 4.9.26, at sh4/schedule/html/view/report.php

189 lines 4.9 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 class SH4_Schedule_Html_View_Report
3 {
4 public function __construct(
5 HC3_Hooks $hooks,
6 HC3_Ui $ui,
7 HC3_Request $request,
8 HC3_Time $t,
9
10 SH4_Shifts_Duration $shiftsDuration,
11 SH4_Shifts_DurationService $shiftsDurationService,
12 SH4_Calendars_Presenter $calendarsPresenter,
13 SH4_Employees_Presenter $employeesPresenter,
14
15 SH4_Schedule_Html_View_Common $common
16 )
17 {
18 $this->self = $hooks->wrap($this);
19
20 $this->ui = $ui;
21 $this->t = $t;
22 $this->request = $request;
23
24 $this->calendarsPresenter = $hooks->wrap( $calendarsPresenter );
25 $this->employeesPresenter = $hooks->wrap( $employeesPresenter );
26
27 $this->common = $hooks->wrap( $common );
28 $this->shiftsDuration = $hooks->wrap( $shiftsDuration );
29 $this->shiftsDurationService = $hooks->wrap( $shiftsDurationService );
30 }
31
32 public function render()
33 {
34 $params = $this->request->getParams();
35 $shifts = $this->common->getShifts();
36
37 $header = array(
38 'qty' => '__Number Of Shifts__',
39 'duration' => '__Hours__',
40 );
41
42 $rows = array();
43
44 $this->shiftsDuration->reset();
45 foreach( $shifts as $shift ){
46 $this->shiftsDuration->add( $shift );
47 }
48
49 $row = array();
50 $row['qty'] = $this->shiftsDuration->getQty();
51 $row['duration'] = $this->shiftsDuration->formatDuration();
52
53 $rows[] = $row;
54
55 $out = $this->ui->makeTable( $header, $rows );
56
57 return $out;
58 }
59
60 public function renderByCalendar()
61 {
62 $calendars = $this->common->getCalendars();
63 $employees = $this->common->getEmployees();
64 $shifts = $this->common->getShifts();
65
66 $header = array(
67 'label' => NULL,
68 'qty' => '__Number Of Shifts__',
69 'duration' => '__Hours__',
70 );
71
72 $viewBy = array();
73 $rows = array();
74
75 foreach( $calendars as $calendar ){
76 $calendarId = $calendar->getId();
77 $rows[ $calendarId ] = array('label' => '', 'qty' => 0, 'duration' => 0);
78
79 // $label = $this->calendarsPresenter->presentTitle( $calendar );
80 $label = $calendar->getTitle();
81 $rows[ $calendarId ]['label'] = $label;
82
83 $viewBy[ $calendarId ] = array();
84 }
85
86 foreach( $shifts as $shift ){
87 $calendar = $shift->getCalendar();
88 $calendarId = $calendar->getId();
89
90 if( ! array_key_exists($calendarId, $viewBy) ){
91 continue;
92 }
93 $viewBy[ $calendarId ][] = $shift;
94 }
95
96 reset( $viewBy );
97 foreach( $viewBy as $calendarId => $thisShifts ){
98 $this->shiftsDuration->reset();
99 foreach( $thisShifts as $shift ){
100 $this->shiftsDuration->add( $shift );
101 }
102
103 $rows[ $calendarId ]['qty'] = $this->shiftsDuration->getQty();
104 $rows[ $calendarId ]['duration'] = $this->shiftsDuration->formatDuration();
105 }
106
107 $out = $this->ui->makeTable( $header, $rows );
108 return $out;
109 }
110
111 public function renderByEmployee()
112 {
113 $calendars = $this->common->getCalendars();
114 $employees = $this->common->getEmployees();
115 $shifts = $this->common->getShifts();
116
117 $header = array(
118 'label' => NULL,
119 );
120
121 foreach( $calendars as $calendar ){
122 $calendarId = $calendar->getId();
123 $calendarView = $this->calendarsPresenter->presentTitle( $calendar );
124 $header['calendar_' . $calendarId] = $calendarView;
125 }
126 $header['total'] = '__Total__';
127
128 $viewBy = array();
129 $rows = array();
130
131 foreach( $employees as $employee ){
132 $employeeId = $employee ? $employee->getId() : 0;
133 $rows[ $employeeId ] = array('label' => '', 'qty' => 0, 'duration' => 0);
134
135 // $label = $employee->getTitle();
136 $label = $this->employeesPresenter->presentTitle( $employee );
137 $label = $this->ui->makeSpan( $label )
138 ->tag('font-size', 4)
139 ;
140 $rows[ $employeeId ]['label'] = $label;
141
142 $viewBy[ $employeeId ] = array();
143 }
144
145 foreach( $shifts as $shift ){
146 $employee = $shift->getEmployee();
147 $employeeId = $employee ? $employee->getId() : 0;
148
149 if( ! array_key_exists($employeeId, $viewBy) ){
150 continue;
151 }
152 $viewBy[ $employeeId ][] = $shift;
153 }
154
155 reset( $viewBy );
156 foreach( $viewBy as $employeeId => $thisShifts ){
157 $durations = array();
158
159 $durations[0] = $this->shiftsDurationService->newCounter();
160 reset( $calendars );
161 foreach( $calendars as $calendar ){
162 $calendarId = $calendar->getId();
163 $durations[ $calendarId ] = $this->shiftsDurationService->newCounter();
164 }
165
166 reset( $thisShifts );
167 foreach( $thisShifts as $shift ){
168 $calendar = $shift->getCalendar();
169 $calendarId = $calendar->getId();
170 if( ! array_key_exists($calendarId, $durations) ){
171 continue;
172 }
173 $durations[$calendarId]->add( $shift );
174 $durations[0]->add( $shift );
175 }
176
177 reset( $calendars );
178 foreach( $calendars as $calendar ){
179 $calendarId = $calendar->getId();
180 $rows[ $employeeId ]['calendar_' . $calendarId] = $durations[$calendarId]->formatDuration();
181 }
182 $rows[ $employeeId ]['total'] = $durations[0]->formatDuration();
183 }
184
185 $out = $this->ui->makeTable( $header, $rows );
186
187 return $out;
188 }
189 }