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 / calendars / html / admin / view / employees.php

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

175 lines 4.5 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_Calendars_Html_Admin_View_Employees
4 {
5 public function __construct(
6 HC3_Hooks $hooks,
7 HC3_Ui $ui,
8 HC3_Ui_Layout1 $layout,
9
10 SH4_App_Query $appQuery,
11
12 SH4_Employees_Query $employeesQuery,
13 SH4_Employees_Presenter $employeesPresenter,
14
15 SH4_Calendars_Query $calendarsQuery,
16 SH4_Calendars_Presenter $calendarsPresenter
17 )
18 {
19 $this->self = $hooks->wrap($this);
20 $this->ui = $ui;
21 $this->layout = $layout;
22
23 $this->appQuery = $hooks->wrap( $appQuery );
24
25 $this->employeesQuery = $hooks->wrap( $employeesQuery );
26 $this->employeesPresenter = $hooks->wrap( $employeesPresenter );
27
28 $this->calendarsQuery = $hooks->wrap( $calendarsQuery );
29 $this->calendarsPresenter = $hooks->wrap( $calendarsPresenter );
30 }
31
32 public function render( $id )
33 {
34 $model = $this->calendarsQuery->findById($id);
35
36 $currentEmployees = $this->appQuery->findEmployeesForCalendar( $model );
37 $currentEmployeesIds = array_keys( $currentEmployees );
38
39 $employees = $this->employeesQuery->findActive();
40
41 $employeesView = array();
42 foreach( $employees as $employee ){
43 $employeeId = $employee->getId();
44 $checked = in_array( $employeeId, $currentEmployeesIds ) ? TRUE : FALSE;
45
46 $thisView = $this->employeesPresenter->presentTitle( $employee );
47 $thisView = $this->ui->makeInputCheckbox( 'employee[]', $thisView, $employeeId, $checked );
48
49 $descriptionView = $employee->getDescription();
50 if( strlen($descriptionView) ){
51 $maxDesc = 40;
52
53 $shortDescriptionView = $descriptionView;
54 if( strlen($descriptionView) > $maxDesc ){
55 $shortDescriptionView = substr($descriptionView, 0, $maxDesc) . '...';
56 }
57
58 if( strlen($descriptionView) > $maxDesc ){
59 $descriptionView = $this->ui->makeCollapse( $shortDescriptionView, $descriptionView )
60 ->arrow( NULL )
61 ->hideToggle()
62 ;
63 }
64 $descriptionView = $this->ui->makeBlock( $descriptionView )
65 ->tag('font-style', 'italic')
66 ->tag('font-size', 2)
67 ;
68
69 $thisView = $this->ui->makeList( array($thisView, $descriptionView) )
70 ->gutter(1)
71 ;
72 }
73
74 $thisView = $this->ui->makeBlock( $thisView )
75 ->tag('border')
76 ->tag('padding', 1)
77 ;
78
79 if( $checked ){
80 $thisView
81 ->tag('border-color', 'olive')
82 ;
83 }
84
85 $employeesView[] = $thisView;
86 }
87
88 $out = $this->ui->makeGrid();
89 foreach( $employeesView as $v ){
90 $out->add( $v, 3, 12 );
91 }
92
93 $out = $this->ui->makeBlock( $out )
94 ->addAttr( 'id', 'sh4-calendars-employees' )
95 ;
96 $toggleAll = $this->ui->makeInputCheckbox( 'toggle_all', '__Toggle All__' )
97 ->addAttr( 'class', 'sh4-calendars-employees-select-all' )
98 ;
99
100 $buttons = $this->ui->makeInputSubmit( '__Save__')
101 ->tag('primary')
102 ;
103 $out = $this->ui->makeList( array($toggleAll, $out, $buttons) );
104
105 $out = $this->ui->makeForm(
106 'admin/calendars/' . $id . '/employees',
107 $out
108 );
109
110 // add check all
111 $js = $this->renderJs();
112 $out = $this->ui->makeCollection( array($js, $out) );
113
114 $this->layout
115 ->setContent( $out )
116 ->setBreadcrumb( $this->self->breadcrumb($model) )
117 ->setHeader( $this->self->header($model) )
118 ;
119
120 $out = $this->layout->render();
121 return $out;
122 }
123
124 public function header( SH4_Calendars_Model $model )
125 {
126 $out = '__Employees__';
127 return $out;
128 }
129
130 public function breadcrumb( SH4_Calendars_Model $model )
131 {
132 $calendarId = $model->getId();
133 $calendarTitle = $this->calendarsPresenter->presentTitle( $model );
134
135 $return = array();
136 $return['admin'] = array( 'admin', '__Administration__' );
137 $return['calendars'] = array( 'admin/calendars', '__Calendars__' );
138 $return['calendars/edit'] = $calendarTitle;
139 return $return;
140 }
141
142 public function renderJs()
143 {
144 ob_start();
145 ?>
146
147 <script language="JavaScript">
148 ( function(){
149
150 document.addEventListener('DOMContentLoaded', function()
151 {
152 var self = this;
153 var el = document.getElementById( 'sh4-calendars-employees' );
154
155 this.toggleAll = function( e ){
156 var checkers = el.getElementsByTagName( 'input' );
157 for( ii = 0; ii < checkers.length; ii++ ){
158 checkers[ii].checked = ! checkers[ii].checked;
159 }
160 };
161
162 var togglers = document.getElementsByClassName( 'sh4-calendars-employees-select-all' );
163 for( ii = 0; ii < togglers.length; ii++ ){
164 togglers[ii].addEventListener( 'change', self.toggleAll );
165 }
166 });
167
168 })();
169
170 </script>
171
172 <?php
173 return ob_get_clean();
174 }
175 }