PluginProbe
ShiftController Employee Shift Scheduling / 4.9.85
ShiftController Employee Shift Scheduling v4.9.85
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 / employees / html / admin / view / index.php

index.php in ShiftController Employee Shift Scheduling 4.9.85, at sh4/employees/html/admin/view/index.php

351 lines 9.2 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 #[AllowDynamicProperties]
3 class SH4_Employees_Html_Admin_View_Index
4 {
5 public function __construct(
6 HC3_Hooks $hooks,
7
8 HC3_Ui $ui,
9 HC3_Ui_Layout1 $layout,
10 HC3_Request $request,
11
12 SH4_Employees_Query $query,
13 SH4_Calendars_Query $calendarsQuery,
14
15 HC3_Users_Presenter $usersPresenter,
16 SH4_Calendars_Presenter $calendarsPresenter,
17
18 SH4_App_Query $appQuery
19 )
20 {
21 $this->request = $request;
22 $this->ui = $ui;
23 $this->layout = $layout;
24
25 $this->usersPresenter = $hooks->wrap( $usersPresenter );
26 $this->calendarsPresenter = $hooks->wrap( $calendarsPresenter );
27
28 $this->query = $hooks->wrap($query);
29 $this->calendarsQuery = $hooks->wrap( $calendarsQuery );
30 $this->appQuery = $hooks->wrap($appQuery);
31
32 $this->self = $hooks->wrap($this);
33 }
34
35 public function render()
36 {
37 $this->request
38 ->initParam('calendar', NULL)
39 ->initParam('status', 'active')
40 ;
41
42 $params = $this->request->getParams();
43 $currentStatus = $params['status'];
44
45 switch( $currentStatus ){
46 case 'all':
47 $entries = $this->query->findAll();
48 break;
49 case 'active':
50 $entries = $this->query->findActive();
51 break;
52 case 'archive':
53 $entries = $this->query->findArchived();
54 break;
55 }
56
57 $tableColumns = $this->self->listingColumns();
58
59 $keys = array_keys( $tableColumns );
60 $firstKey = array_shift( $keys );
61
62 $tableRows = array();
63 foreach( $entries as $e ){
64 $row = $this->self->listingCell($e);
65
66 // actions for first cell
67 $itemMenu = $this->self->listingCellMenu( $e );
68 $actions = $this->ui->helperActionsFromArray( $itemMenu );
69
70 if( $actions ){
71 $actions = $this->ui->makeListInline($actions)
72 ->gutter(1)
73 ->separated()
74 ;
75 $row[$firstKey] = $this->ui->makeList( array($row[$firstKey], $actions) )->gutter(1);
76 }
77
78 $tableRows[] = $row;
79 }
80
81 $content = $this->ui->makeTable( $tableColumns, $tableRows );
82
83 // form
84 $option = array();
85 $option['archive'] = '__Archive__';
86 $option['restore'] = '__Restore__';
87 $option['delete'] = '__Delete__';
88
89 $allowed = array();
90 foreach( $entries as $model ){
91 if( $model->isArchived() ){
92 $allowed['restore'] = 1;
93 $allowed['delete'] = 1;
94 }
95 else {
96 $allowed['archive'] = 1;
97 }
98 }
99 $option = array_intersect_key( $option, $allowed );
100
101 if( $option ){
102 array_unshift( $option, '- ' . '__Action__' . ' -' );
103
104 $selectAction = $this->ui->makeInputSelect( 'action', '__With Selected__', $option );
105 $buttons = $this->ui->makeInputSubmit( '__Apply Action__' )->tag('primary');
106
107 $hidden = $this->ui->makeInputHidden( 'id', null );
108 $js = <<<EOT
109 <script>
110 function sh4EmployeeForm(){
111 var idValue = [];
112 var idInputs = document.getElementsByName("hc-id[]");
113 for( var ii = 0; ii < idInputs.length; ii++ ){
114 if( idInputs[ii].checked ){
115 idValue.push( idInputs[ii].value );
116 }
117 }
118
119 if( idValue.length ){
120 var idInput = document.getElementsByName("hc-id")[0];
121 idInput.value = idValue.join( ':' );
122 return true;
123 }
124 else {
125 return false;
126 }
127 }
128 </script>
129 EOT;
130
131 $form = $this->ui->makeList( array($js, $hidden, $selectAction, $buttons) );
132 $form = $this->ui->makeForm(
133 'admin/employees',
134 $form
135 );
136 $form->setId( 'sh4-employee-form' );
137 $form->setAttr( 'onsubmit', 'return sh4EmployeeForm();' );
138
139 $content = $this->ui->makeList( array($content, $form) );
140 }
141
142 $byStatus = $this->self->byStatus( $entries );
143 if( $byStatus ){
144 $byStatusView = array();
145 foreach( $byStatus as $bys ){
146 list( $href, $hrefLabel, $countAddon ) = $bys;
147
148 $thisSelected = FALSE;
149 if( isset($href[1]['status']) && $href[1]['status'] == $currentStatus ){
150 $thisSelected = TRUE;
151 }
152
153 if( $thisSelected ){
154 $thisOne = $this->ui->makeSpan( $hrefLabel );
155 }
156 else {
157 $thisOne = $this->ui->makeAhref( $href, $hrefLabel );
158 }
159
160 if( strlen($countAddon) ){
161 $thisOne = $this->ui->makeListInline( array($thisOne, '(' . $countAddon . ')') )->gutter(1);
162 }
163
164 if( $thisSelected ){
165 $thisOne
166 ->tag('font-style', 'bold')
167 ;
168 }
169
170 $byStatusView[] = $thisOne;
171 }
172 $byStatusView = $this->ui->makeListInline( $byStatusView )->separated();
173
174 $content = $this->ui->makeList( array($byStatusView, $content) )->gutter(1);
175 }
176
177 $this->layout
178 ->setContent( $content )
179 ->setBreadcrumb( $this->self->breadcrumb() )
180 ->setHeader( $this->self->header() )
181 ->setMenu( $this->self->menu() )
182 ;
183
184 $out = $this->layout->render();
185 return $out;
186 }
187
188 public function breadcrumb()
189 {
190 $return = array();
191 $return['admin'] = array( 'admin', '__Administration__' );
192 return $return;
193 }
194
195 public function menu()
196 {
197 $return = array(
198 'new' => array( 'admin/employees/new', '__Add New__' )
199 );
200
201 if( defined('WPINC') ){
202 $return['importwp'] = array( 'admin/employees/importwp', '__Import WordPress Users__' );
203 }
204
205 $return['sort'] = array( 'admin/employees/sort', '__Sort Order__' );
206 $return['settings'] = array( 'admin/employees/settings', '__Settings__' );
207
208 return $return;
209 }
210
211 public function header()
212 {
213 $out = '__Employees__';
214 return $out;
215 }
216
217 public function byStatus( $entries )
218 {
219 $return = array();
220
221 $count1 = $this->query->countActive();
222 $count2 = $this->query->countArchived();
223
224 $return['all'] = array( array('admin/employees', array('status' => 'all')), '__All__', ($count1 + $count2) );
225
226 if( $count1 = $this->query->countActive() ){
227 $return['active'] = array( array('admin/employees', array('status' => 'active')), '__Active__', $count1 );
228 }
229 if( $count2 = $this->query->countArchived() ){
230 $return['archived'] = array( array('admin/employees', array('status' => 'archive')), '__Archived__', $count2 );
231 }
232
233 return $return;
234 }
235
236 public function listingColumns()
237 {
238 $return = array(
239 'title' => '__Name__',
240 'calendars' => '__Calendars__',
241 'user' => '__Linked User Account__',
242 );
243 return $return;
244 }
245
246 public function listingCell( $model )
247 {
248 $return = array();
249 $id = $model->getId();
250
251 $titleView = $model->getTitle();
252 $titleView = esc_html( $titleView );
253
254 if( $model->isArchived() ){
255 $titleView = $this->ui->makeSpan($titleView)
256 ->tag('font-style', 'line-through')
257 ;
258 }
259
260 $titleView = $this->ui->makeSpan( $titleView )
261 ->tag('font-size', 4)
262 ->tag('font-style', 'bold')
263 ;
264
265 $idView = $model->getId();
266 $idLabel = $this->ui->makeBlock('id')
267 ->tag('mute')
268 ->tag('font-size', 2)
269 ;
270 $idView = $this->ui->makeListInline( array($idLabel, $idView) )
271 ->gutter(1)
272 ;
273
274 if( $model->getId() ){
275 $checkbox = $this->ui->makeInputCheckbox( 'id[]', null, $model->getId() );
276 $titleView = $this->ui->makeListInline( array($checkbox, $titleView) )->gutter(1);
277 $titleView = $this->ui->makeElement( 'label', $titleView );
278 }
279
280 $descriptionView = $model->getDescription();
281 // $descriptionView = $this->ui->makeLongText( $descriptionView );
282
283 // $titleView = $this->ui->makeList( array($titleView, $descriptionView, $idView) )->gutter(0);
284 $titleView = $this->ui->makeList( array($titleView, $idView) )->gutter(0);
285
286 $return['title'] = $titleView;
287
288 $calendars = $this->appQuery->findCalendarsForEmployee( $model );
289
290 $calendarsView = array();
291 foreach( $calendars as $calendar ){
292 $calendarsView[] = $this->calendarsPresenter->presentTitle($calendar);
293 }
294 $calendarsView = $this->ui->makeListInline( $calendarsView )->gutter(2);
295
296 $calendarActions = array();
297 $calendarActions[] = array( 'admin/employees/' . $id . '/calendars', '__Edit__' );
298
299 if( $calendarActions ){
300 $calendarActions = $this->ui->helperActionsFromArray( $calendarActions );
301 $calendarActions = $this->ui->makeListInline( $calendarActions )->gutter(1)->separated();
302 $calendarsView = $this->ui->makeList( array($calendarsView, $calendarActions) )->gutter(0);
303 }
304
305 $return['calendars'] = $calendarsView;
306
307 $user = $this->appQuery->findUserByEmployee( $model );
308 $userView = $user ? $this->usersPresenter->presentTitle( $user ) : '__N/A__';
309
310 $userActions = array();
311 if( $id > 0 ){
312 if( $user ){
313 $userActions[] = array( 'admin/employees/' . $id . '/user/0', NULL, '__Unlink__' );
314 }
315 else {
316 $userActions[] = array( 'admin/employees/' . $id . '/user', '__Link To User Account__' );
317 }
318 }
319
320 if( $userActions ){
321 $userActions = $this->ui->helperActionsFromArray( $userActions );
322 $userActions = $this->ui->makeListInline( $userActions )->gutter(1)->separated();
323 $userView = $this->ui->makeList( array($userView, $userActions) )->gutter(0);
324 }
325
326 $return['user'] = $userView;
327
328 return $return;
329 }
330
331 public function listingCellMenu( $model )
332 {
333 $id = $model->getId();
334
335 $return = array();
336
337 if( $id > 0 ){
338 $return['edit'] = array( 'admin/employees/' . $id, '__Edit__' );
339
340 if( $model->isArchived() ){
341 $return['restore'] = array( 'admin/employees/' . $id . '/restore', null, '__Restore__');
342 $return['delete'] = array( 'admin/employees/' . $id . '/delete', '__Delete__' );
343 }
344 else {
345 $return['archive'] = array( 'admin/employees/' . $id . '/archive', null, '__Archive__' );
346 }
347 }
348
349 return $return;
350 }
351 }