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 / _wordpress / users / html / admin / view / index.php

index.php in ShiftController Employee Shift Scheduling 4.9.26, at sh4/_wordpress/users/html/admin/view/index.php

227 lines 5.8 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_Users_Html_Admin_View_Index
3 {
4 public function __construct(
5 HC3_Hooks $hooks,
6
7 HC3_Ui $ui,
8 HC3_Ui_Layout1 $layout,
9
10 HC3_IPermission $permission,
11
12 SH4_App_Query $appQuery,
13 SH4_Calendars_Presenter $calendarsPresenter,
14 SH4_Calendars_Query $calendarsQuery,
15
16 SH4_Employees_Presenter $employeesPresenter,
17 HC3_Users_Presenter $usersPresenter,
18 HC3_Users_Query $usersQuery
19 )
20 {
21 $this->self = $hooks->wrap($this);
22 $this->ui = $ui;
23 $this->layout = $layout;
24
25 $this->permission = $hooks->wrap($permission);
26
27 $this->calendarsQuery = $hooks->wrap( $calendarsQuery );
28 $this->calendarsPresenter = $hooks->wrap( $calendarsPresenter );
29
30 $this->appQuery = $hooks->wrap( $appQuery );
31 $this->employeesPresenter = $hooks->wrap( $employeesPresenter );
32 $this->usersPresenter = $hooks->wrap( $usersPresenter );
33 $this->usersQuery = $hooks->wrap( $usersQuery );
34 }
35
36 public function render()
37 {
38 $entries = $this->appQuery->findAllUsersWithEmployee();
39
40 $managers = array();
41 $calendars = $this->calendarsQuery->findAll();
42 foreach( $calendars as $calendar ){
43 $thisManagers = $this->appQuery->findManagersForCalendar( $calendar );
44 $managers = $managers + $thisManagers;
45 }
46
47 $admins = $this->permission->findAdmins();
48
49 $entries = $admins + $managers + $entries;
50
51 $tableColumns = $this->self->listingColumns();
52
53 $keys = array_keys( $tableColumns );
54 $firstKey = array_shift( $keys );
55
56 $tableRows = array();
57 foreach( $entries as $e ){
58 $row = $this->self->listingCell($e);
59
60 // actions for first cell
61 $actions = array();
62 $itemMenu = $this->self->listingCellMenu( $e );
63 foreach( $itemMenu as $item ){
64 // form
65 if( count($item) == 3 ){
66 list( $href, $formContent, $btnLabel ) = $item;
67 $btn = $this->ui->makeInputSubmit($btnLabel)
68 ->tag('nice-link')
69 ;
70 $formContent = $formContent ? $this->ui->makeListInline( array($formContent, $btn) ) : $btn;
71 $item = $this->ui->makeForm( $href, $formContent );
72 if( ! $item ){
73 continue;
74 }
75 }
76 // link
77 else {
78 list( $href, $label ) = $item;
79 $item = $this->ui->makeAhref( $href, $label );
80 if( ! $item ){
81 continue;
82 }
83 $item->tag('nice-link');
84 }
85 $actions[] = $item;
86 }
87
88 if( $actions ){
89 $actions = $this->ui->makeListInline($actions)
90 ->gutter(1)
91 ->separated()
92 ;
93 $row[$firstKey] = $this->ui->makeList( array($row[$firstKey], $actions) )->gutter(1);
94 }
95
96 $tableRows[] = $row;
97 }
98
99 $content = $this->ui->makeTable( $tableColumns, $tableRows );
100
101 $this->layout
102 ->setContent( $content )
103 ->setBreadcrumb( $this->self->breadcrumb() )
104 ->setHeader( $this->self->header() )
105 ->setMenu( $this->self->menu() )
106 ;
107
108 $out = $this->layout->render();
109 return $out;
110 }
111
112 public function breadcrumb()
113 {
114 $return = array();
115 $return['admin'] = array( 'admin', '__Administration__' );
116 return $return;
117 }
118
119 public function menu()
120 {
121 $return = array(
122 'new' => array( admin_url('user-new.php'), '__Add New__' )
123 );
124 return $return;
125 }
126
127 public function header()
128 {
129 $out = '__Users__';
130 return $out;
131 }
132
133 public function listingColumns()
134 {
135 $return = array(
136 'title' => '__WordPress User__' . ' / ' . '__Role__',
137 'role' => '__ShiftController Role__',
138 'employee' => '__Linked Employee__',
139 'calendar' => '__Managed Calendars__',
140 'notes' => '__Notes__',
141 );
142 return $return;
143 }
144
145 public function listingCell( HC3_Users_Model $model )
146 {
147 $return = array();
148 $id = $model->getId();
149
150 $titleView = $this->usersPresenter->presentTitle( $model );
151
152 $wpUser = get_userdata( $id );
153 $wpRole = NULL;
154 if( isset($wpUser->roles) ){
155 global $wp_roles;
156 $wpRole = array();
157 foreach( $wpUser->roles as $wpr ){
158 $wpRole[] = $wp_roles->roles[ $wpr ]['name'];
159 }
160 $wpRole = join(', ', $wpRole);
161 $titleView = $this->ui->makeList( array($titleView, $wpRole) )->gutter(0);
162 }
163 $return['title'] = $titleView;
164
165 $employee = $this->appQuery->findEmployeeByUser( $model );
166 $calendars = $this->appQuery->findCalendarsManagedByUser( $model );
167
168 $employeeActions = array();
169 if( $employee ){
170 $employeeView = $this->employeesPresenter->presentTitle( $employee );
171 $employeeActions[] = array( 'admin/users/' . $id . '/employee/0', NULL, '__Unlink__' );
172 }
173 else {
174 $employeeView = '__N/A__';
175 $employeeActions[] = array( 'admin/users/' . $id . '/employee', '__Link To Employee__' );
176 }
177
178 $employeeActions = $this->ui->helperActionsFromArray( $employeeActions );
179 if( $employeeActions ){
180 $employeeActions = $this->ui->makeListInline( $employeeActions )->gutter(1)->separated();
181 $employeeView = $this->ui->makeList( array($employeeView, $employeeActions) )->gutter(0);
182 }
183
184 $return['employee'] = $employeeView;
185
186 $isAdmin = $this->permission->isAdmin( $model );
187
188 $calendarsView = array();
189 $roleView = array();
190
191 if( $employee ){
192 $roleView[] = '__Employee__';
193 }
194
195 if( $isAdmin ){
196 $roleView[] = '__Administrator__';
197 $calendarsView[] = '__All__';
198 }
199 elseif( $calendars ){
200 $roleView[] = '__Manager__';
201 foreach( $calendars as $calendar ){
202 $calendarsView[] = $this->calendarsPresenter->presentTitle($calendar);
203 }
204 }
205 else {
206 $calendarsView[] = '__N/A__';
207 }
208
209 $roleView = join( ', ', $roleView );
210 $return['role'] = $roleView;
211
212 $calendarsView = $this->ui->makeListInline( $calendarsView );
213 $return['calendar'] = $calendarsView;
214
215 return $return;
216 }
217
218 public function listingCellMenu( $model )
219 {
220 $id = $model->getId();
221 $return = array();
222
223 $return['edit'] = array( get_edit_user_link($id), '__Edit WordPress User__' );
224
225 return $return;
226 }
227 }