PluginProbe
ShiftController Employee Shift Scheduling / trunk
ShiftController Employee Shift Scheduling vtrunk
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 / feed / html / admin / feed.php

feed.php in ShiftController Employee Shift Scheduling trunk, at sh4/feed/html/admin/feed.php

207 lines 6.6 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_Feed_Html_Admin_Feed
4 {
5 public function __construct(
6 HC3_Hooks $hooks,
7 HC3_Ui $ui,
8 HC3_Ui_Layout1 $layout,
9
10 HC3_Time $t,
11
12 HC3_Auth $auth,
13 HC3_IPermission $permission,
14 HC3_UriAction $uriAction,
15
16 SH4_Calendars_Permissions $calendarsPermissions,
17 SH4_Calendars_Query $calendarsQuery,
18 SH4_Calendars_Presenter $calendarsPresenter,
19 SH4_Employees_Presenter $employeesPresenter,
20 SH4_App_Query $appQuery,
21
22 SH4_Schedule_Html_View_Common $scheduleViewCommon
23 )
24 {
25 $this->self = $hooks->wrap($this);
26
27 $this->ui = $ui;
28 $this->layout = $layout;
29 $this->uriAction = $uriAction;
30 $this->t = $t;
31
32 $this->auth = $hooks->wrap( $auth );
33 $this->permission = $hooks->wrap($permission);
34 $this->calendarsPresenter = $hooks->wrap( $calendarsPresenter );
35 $this->employeesPresenter = $hooks->wrap( $employeesPresenter );
36
37 $this->calendarsPermissions = $hooks->wrap( $calendarsPermissions );
38 $this->calendarsQuery = $hooks->wrap( $calendarsQuery );
39
40 $this->appQuery = $hooks->wrap( $appQuery );
41 $this->scheduleViewCommon = $hooks->wrap( $scheduleViewCommon );
42 }
43
44 public function render()
45 {
46 $currentUser = $this->auth->getCurrentUser();
47 $token = $this->auth->getTokenByUser( $currentUser );
48
49 $out = array();
50
51 $calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser );
52 $calendarsAsViewer = $this->appQuery->findCalendarsViewedByUser( $currentUser );
53
54 $calendarsAsEmployee = array();
55 $meEmployee = $this->appQuery->findEmployeeByUser( $currentUser );
56 if( $meEmployee ){
57 $employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee );
58 foreach( $employeeCalendars as $thisCalendar ){
59 $thisCalendarId = $thisCalendar->getId();
60 $perms = array(
61 'employee_view_own_publish',
62 'employee_view_own_draft',
63 'employee_view_others_publish',
64 'employee_view_others_draft',
65 'employee_view_open_publish',
66 'employee_view_open_draft'
67 );
68
69 reset( $perms );
70 foreach( $perms as $perm ){
71 $thisPerm = $this->calendarsPermissions->get($thisCalendar, $perm);
72 if( $thisPerm ){
73 $calendarsAsEmployee[ $thisCalendarId ] = $thisCalendar;
74 break;
75 }
76 }
77 }
78 }
79
80 // links
81 $links = array();
82
83 $allCalendars = $calendarsAsManager + $calendarsAsViewer + $calendarsAsEmployee;
84 $allCalendarsIds = array_keys( $allCalendars );
85 $calendars = $this->calendarsQuery->findManyActiveById( $allCalendarsIds );
86
87 // if( $meEmployee ){
88 // $meEmployeeId = $meEmployee->getId();
89 // $links[] = array( 'feed/' . $token . '/x/' . $meEmployeeId, '__My Schedule__' );
90 // }
91
92 if( $calendarsAsManager ){
93 $links[] = array( 'feed/' . $token, '__All From Today__' );
94 $links[] = array( 'json/' . $token, '__All From Today__' );
95
96 $links[] = array( 'feed/' . $token . '/s', '__All From Today__' . ': ' . '__Shifts__' );
97 $links[] = array( 'json/' . $token . '/t', '__All From Today__' . ': ' . '__Time Off__' );
98
99 $links[] = array( 'feed/' . $token . '/x/x/20181123/20190101', '__From Date__' . ' / ' . '__To Date__' );
100 $links[] = array( 'json/' . $token . '/x/x/20181123/20190101', '__From Date__' . ' / ' . '__To Date__' );
101
102 foreach( $calendars as $calendar ){
103 $calendarId = $calendar->getId();
104 $calendarTitle = $this->calendarsPresenter->presentTitle( $calendar );
105 $links[] = array( 'feed/' . $token . '/' . $calendarId, $calendarTitle );
106 $links[] = array( 'json/' . $token . '/' . $calendarId, $calendarTitle );
107 }
108
109 $employees = $this->scheduleViewCommon->findAllEmployees();
110 if( count($employees) > 1 ){
111 foreach( $employees as $employee ){
112 $employeeId = $employee->getId();
113 $employeeTitle = $this->employeesPresenter->presentTitle( $employee );
114 $links[] = array( 'feed/' . $token . '/x/' . $employeeId, $employeeTitle );
115 $links[] = array( 'json/' . $token . '/x/' . $employeeId, $employeeTitle );
116 }
117 }
118 }
119
120 $note = '__Here is the automatic CSV/JSON feed of the shifts that can be used with other 3rd party applications.__';
121 $out[] = $note;
122
123 $timezone = $this->t->getTimezone();
124 $timezoneView = $timezone->getName();
125
126 $timezoneLabel = '__Timezone__';
127 $timezoneLabel = $this->ui->makeBlock( $timezoneLabel )
128 ->tag('muted')
129 ->tag('font-size', 2)
130 ;
131 $timezoneView = $this->ui->makeListInline( array($timezoneLabel, $timezoneView) );
132 $timezoneView = $this->ui->makeBlock( $timezoneView )
133 ->tag('border')
134 ->tag('padding', 2)
135 ;
136
137 $out[] = $timezoneView;
138
139 // online
140 $thisOut = array();
141
142 $linksView = array();
143 reset( $links );
144 foreach( $links as $linkArray ){
145 list( $to, $linkLabel ) = $linkArray;
146 // $link = $this->uriAction->makeUrl( $to );
147 $link = site_url( '/?hcs=sh4&hca=' . $to );
148 $linkView = $this->ui->makeInputText( NULL, $linkLabel, $link )
149 ->addAttr( 'onclick', 'this.focus(); this.select();' )
150 ;
151 $linksView[] = $linkView;
152 }
153 $linksView = $this->ui->makeList( $linksView );
154 $thisOut[] = $linksView;
155
156
157 $thisOut = $this->ui->makeList( $thisOut );
158 $out[] = $thisOut;
159
160 if( class_exists('SH4_CFields_Model') ){
161 $f = null;
162 if (class_exists('ShiftController4Legacy_Pro')) {
163 $f = ShiftController4Legacy_Pro::$instance->root();
164 } elseif (class_exists('ShiftController4')) {
165 $f = ShiftController4::$instance->root();
166 }
167
168 if (null !== $f) {
169 $cfieldsQuery = $f->make('SH4_CFields_Query');
170 $cfields = $cfieldsQuery->read();
171 if( $cfields ){
172 $moreOut = '<p><strong>__Optional Arguments__</strong></p>';
173 $moreOut .= '<p>';
174 foreach( $cfields as $cfield ){
175 $moreOut .= '<em>' . $cfield->getName() . '</em> (' . $cfield->getLabel() . ')<br>';
176 }
177 $moreOut .= '</p>';
178 $out[] = $moreOut;
179 }
180 }
181 }
182
183 $out = $this->ui->makeList( $out )->gutter(3);
184
185 $this->layout
186 ->setContent( $out )
187 ->setBreadcrumb( $this->self->breadcrumb() )
188 ->setHeader( $this->self->header() )
189 ;
190
191 $out = $this->layout->render();
192 return $out;
193 }
194
195 public function header()
196 {
197 $out = '__Shifts Feed__';
198 return $out;
199 }
200
201 public function breadcrumb()
202 {
203 $return = array();
204 $return['admin'] = array( 'admin', '__Administration__' );
205 return $return;
206 }
207 }