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 / reminders / html / admin / review.php

review.php in ShiftController Employee Shift Scheduling 4.9.85, at sh4/reminders/html/admin/review.php

350 lines 9.1 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_Reminders_Html_Admin_Review
4 {
5 public function __construct(
6 HC3_Ui $ui,
7 HC3_Time $t,
8 HC3_Uri $uri,
9 HC3_Post $post,
10
11 SH4_Reminders_Command $remindersCommand,
12 SH4_Reminders_CommandLog $remindersCommandLog,
13 SH4_Reminders_Query $remindersQuery,
14 SH4_Reminders_QueryLog $remindersQueryLog,
15
16 SH4_Reminders_CommandSms $remindersCommandSms,
17 SH4_Reminders_Sms $sms,
18
19 HC3_Users_Presenter $usersPresenter,
20 SH4_Employees_Presenter $employeesPresenter,
21
22 HC3_Request $request,
23 HC3_Ui_Layout1 $layout,
24 HC3_Hooks $hooks
25 )
26 {
27 $this->ui = $ui;
28 $this->t = $t;
29 $this->post = $hooks->wrap( $post );
30 $this->sms = $hooks->wrap( $sms );
31
32 $this->remindersCommand = $hooks->wrap( $remindersCommand );
33 $this->remindersCommandSms = $hooks->wrap( $remindersCommandSms );
34 $this->remindersCommandLog = $hooks->wrap( $remindersCommandLog );
35 $this->remindersQuery = $hooks->wrap( $remindersQuery );
36 $this->remindersQueryLog = $hooks->wrap( $remindersQueryLog );
37
38 $this->uri = $uri;
39 $this->layout = $layout;
40 $this->request = $request;
41 $this->self = $hooks->wrap( $this );
42
43 $this->employeesPresenter = $hooks->wrap( $employeesPresenter );
44 $this->usersPresenter = $hooks->wrap( $usersPresenter );
45 }
46
47 public function breadcrumbs()
48 {
49 $ret = array();
50 $ret['admin'] = array( 'admin', '__Administration__' );
51 $ret['admin/reminders'] = array( 'admin/reminders', '__Reminders__' );
52 return $ret;
53 }
54
55 public function header()
56 {
57 $ret = '__Review Reminders__';
58 return $ret;
59 }
60
61 public function post()
62 {
63 $type = $this->post->get('type');
64 $date = $this->post->get('date');
65
66 $slug = $this->request->getSlug();
67 $params = array(
68 'date' => $date,
69 'type' => $type
70 );
71
72 $to = $this->uri->makeUrl( array($slug, $params) );
73
74 $ret = array( $to, NULL );
75 return $ret;
76 }
77
78 public function postSend()
79 {
80 $params = $this->request->getParams();
81 $date = isset($params['date']) ? $params['date'] : $this->t->setNow()->formatDateDb();
82 $type = isset($params['type']) ? $params['type'] : SH4_Reminders_Model::RANGE_DAILY;
83
84 // reminders
85 $reminders = $this->remindersQuery->find( $type, $date );
86
87 if( in_array($type, [SH4_Reminders_Model::RANGE_DAILY_SMS]) ){
88 $command = $this->remindersCommandSms;
89 }
90 else {
91 $command = $this->remindersCommand;
92 }
93
94 foreach( $reminders as $reminder ){
95 if( $reminder->log ){
96 $this->remindersCommandLog->delete( $reminder->log );
97 }
98
99 $command->send( $reminder );
100 }
101
102 $to = 'admin/reminders/review';
103 $params = array(
104 'date' => $date,
105 'type' => $type
106 );
107 $to = $this->uri->makeUrl( array($to, $params) );
108
109 $msg = '__Reminders Sent__';
110 $ret = array( $to, $msg );
111 return $ret;
112 }
113
114 public function postClear()
115 {
116 $params = $this->request->getParams();
117 $date = isset($params['date']) ? $params['date'] : $this->t->setNow()->formatDateDb();
118 $type = isset($params['type']) ? $params['type'] : SH4_Reminders_Model::RANGE_DAILY;
119
120 // reminders
121 $reminders = $this->remindersQuery->find( $type, $date );
122
123 foreach( $reminders as $reminder ){
124 if( $reminder->log ){
125 $this->remindersCommandLog->delete( $reminder->log );
126 }
127 }
128
129 $to = 'admin/reminders/review';
130 $params = array(
131 'date' => $date,
132 'type' => $type
133 );
134 $to = $this->uri->makeUrl( array($to, $params) );
135
136 $msg = '__Logs Cleared__';
137 $ret = array( $to, $msg );
138 return $ret;
139 }
140
141 public function render()
142 {
143 $params = $this->request->getParams();
144 $date = isset($params['date']) ? $params['date'] : $this->t->setNow()->formatDateDb();
145 $type = isset($params['type']) ? $params['type'] : SH4_Reminders_Model::RANGE_DAILY;
146
147 // post to
148 $slug = $this->request->getSlug();
149 $to = $this->uri->makeUrl( $slug );
150
151 $params = array(
152 'date' => $date,
153 'type' => $type
154 );
155 $toSend = $this->uri->makeUrl( array($slug . '/send', $params) );
156 $toClear = $this->uri->makeUrl( array($slug . '/clear', $params) );
157
158 // reminders
159 $reminders = $this->remindersQuery->find( $type, $date );
160
161 // reminder logs
162 $notSent = array();
163 $logs = array();
164 foreach( $reminders as $reminder ){
165 if( $reminder->log ){
166 $logs[ $reminder->log->id ] = $reminder->log;
167 }
168 else {
169 $notSent[] = 1;
170 }
171 }
172
173 ob_start();
174 ?>
175
176 <?php
177 // _print_r( $logs );
178 ?>
179
180 <div class="hc-mb3">
181 <form action="<?php echo $to; ?>" method="post" accept-charset="utf-8">
182 <fieldset class="hc-p1 hc-border">
183 <legend>__Filter__</legend>
184 <div class="hc-clearfix">
185 <div class="hc-col hc-col-3">
186 <div class="hc-p2">
187 <?php echo $this->ui->makeInputDatepicker( 'date', NULL, $date ); ?>
188 </div>
189 </div>
190 <div class="hc-col hc-col-7">
191 <div class="hc-p2">
192 <?php
193 $types = array(
194 SH4_Reminders_Model::RANGE_DAILY => '__Daily__',
195 SH4_Reminders_Model::RANGE_WEEKLY => '__Weekly__',
196 SH4_Reminders_Model::RANGE_MONTHLY => '__Monthly__',
197 );
198
199 if( $this->sms->isEnabled() ){
200 $types[ SH4_Reminders_Model::RANGE_DAILY_SMS ] = '__Daily__' . ' ' . '__SMS__';
201 }
202 ?>
203
204 <?php foreach( $types as $k => $label ) : ?>
205 <label>
206 <input type="radio" name="hc-type" value="<?php echo $k; ?>"<?php if( $k == $type ) : ?> checked<?php endif; ?>/>
207 <?php echo $label; ?>
208 </label>
209 <?php endforeach; ?>
210 </div>
211 </div>
212 <div class="hc-col hc-col-2">
213 <button type="submit" class="button button-secondary hc-block">__Apply Filter__</button>
214 </div>
215 </div>
216 </fieldset>
217 </form>
218 </div>
219
220 <?php if( $reminders ) : ?>
221
222 <table class="wp-list-table widefat fixed striped">
223
224 <thead>
225 <tr>
226 <td class="hc-col-4">
227 __Employee__
228 </td>
229 <td class="hc-col-4">
230 __User__
231 </td>
232 <td class="hc-col-1">
233 __Shifts__
234 </td>
235 <td class="hc-col-3">
236 __Sent__
237 </td>
238 </tr>
239 </thead>
240
241 <tbody>
242 <?php foreach( $reminders as $r ) : ?>
243 <?php
244 $toParams = array();
245 $toParams[ 'employee' ] = array( $r->employee->getId() );
246 $toParams[ 'type' ] = 'list';
247 $toParams[ 'groupby' ] = 'none';
248
249 if( SH4_Reminders_Model::RANGE_DAILY == $r->range ){
250 $toParams[ 'start' ] = $r->date;
251 $toParams[ 'end' ] = $r->date;
252 }
253
254 if( SH4_Reminders_Model::RANGE_DAILY_SMS == $r->range ){
255 $toParams[ 'start' ] = $r->date;
256 $toParams[ 'end' ] = $r->date;
257 }
258
259 if( SH4_Reminders_Model::RANGE_WEEKLY == $r->range ){
260 $start = $this->t->setDateDb( $r->date )->setStartWeek()->formatDateDb();
261 $end = $this->t->setDateDb( $start )->modify('+1 week')->modify('-1 day')->formatDateDb();
262 $toParams[ 'start' ] = $start;
263 $toParams[ 'end' ] = $end;
264 }
265
266 if( SH4_Reminders_Model::RANGE_MONTHLY == $r->range ){
267 $start = $this->t->setDateDb( $r->date )->setStartMonth()->formatDateDb();
268 $end = $this->t->setDateDb( $start )->modify('+1 month')->modify('-1 day')->formatDateDb();
269 $toParams[ 'start' ] = $start;
270 $toParams[ 'end' ] = $end;
271 }
272
273 $to = 'schedule';
274 $detailsLink = $this->uri->makeUrl( array($to, $toParams) );
275 ?>
276
277 <tr>
278 <td>
279 <?php echo $this->employeesPresenter->presentTitle( $r->employee ); ?>
280 <?php if( in_array($r->range, [SH4_Reminders_Model::RANGE_DAILY_SMS]) ) : ?>
281 <?php $phone = $this->sms->getEmployeePhone( $r->employee->getId() ); ?>
282 <a href="<?php echo esc_attr($this->uri->makeUrl('admin/reminders/sms')); ?>" title="__Phone Number__" class="hc-block">
283 <?php if( $phone ) : ?><?php echo esc_html( $phone ); ?><?php else : ?>__No Phone Number__<?php endif; ?>
284 </a>
285 <?php endif; ?>
286 </td>
287 <td>
288 <?php if( $r->user ): ?>
289 <?php echo $this->usersPresenter->presentTitle( $r->user ); ?>
290 <?php if( in_array($r->range, [SH4_Reminders_Model::RANGE_DAILY_SMS]) ) : ?>
291 <?php else : ?>
292 <div title="__Email__"><?php echo esc_html($r->user->getEmail()); ?></div>
293 <?php endif; ?>
294 <?php else : ?>
295 __N/A__
296 <?php endif; ?>
297 </td>
298 <td>
299 <a href="<?php echo $detailsLink; ?>" class="hc-block" target="_blank"><?php echo count( $r->shifts ); ?></a>
300 </td>
301 <td>
302 <?php if( $r->log ) : ?>
303 <?php echo $this->t->setDateTimeDb( $r->log->sent_on )->formatDateWithWeekday(); ?> <?php echo $this->t->formatTime(); ?>
304 <?php else : ?>
305 <mark>__Not Sent__</mark>
306 <?php endif; ?>
307 </td>
308 </tr>
309 <?php endforeach; ?>
310 </tbody>
311
312 </table>
313
314 <?php if( $notSent ) : ?>
315 <form action="<?php echo $toSend; ?>" method="post" accept-charset="utf-8">
316 <p>
317 <button type="submit" class="button button-primary hc-xs-block">__Send Reminder Messages__</button>
318 </p>
319 </form>
320 <?php endif; ?>
321
322 <?php if( $logs ) : ?>
323 <form action="<?php echo $toClear; ?>" method="post" accept-charset="utf-8">
324 <p>
325 <button type="submit" class="button button-secondary hc-xs-block">&times; __Clear Logs__</button>
326 </p>
327 </form>
328 <?php endif; ?>
329
330 <?php else: ?>
331
332 <p>
333 __No Reminders__
334 </p>
335
336 <?php endif; ?>
337
338 <?php
339 $ret = trim( ob_get_clean() );
340
341 $this->layout
342 ->setContent( $ret )
343 ->setHeader( $this->self->header() )
344 ->setBreadcrumb( $this->self->breadcrumbs() )
345 ;
346
347 $ret = $this->layout->render();
348 return $ret;
349 }
350 }