| 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 postClearSelected() |
| 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 |
$employeeIds = $this->post->get('employee'); |
| 147 |
|
| 148 |
$to = 'admin/reminders/review'; |
| 149 |
$params = array( |
| 150 |
'date' => $date, |
| 151 |
'type' => $type |
| 152 |
); |
| 153 |
$to = $this->uri->makeUrl(array($to, $params)); |
| 154 |
|
| 155 |
if (!$employeeIds) { |
| 156 |
$ret = array($to, ''); |
| 157 |
return $ret; |
| 158 |
} |
| 159 |
|
| 160 |
// reminders |
| 161 |
$reminders = $this->remindersQuery->find($type, $date); |
| 162 |
|
| 163 |
foreach ($reminders as $reminder) { |
| 164 |
if (!$reminder->log) { |
| 165 |
continue; |
| 166 |
} |
| 167 |
|
| 168 |
$thisEmployeeId = $reminder->employee->getId(); |
| 169 |
if (!in_array($thisEmployeeId, $employeeIds)) { |
| 170 |
continue; |
| 171 |
} |
| 172 |
|
| 173 |
$this->remindersCommandLog->delete($reminder->log); |
| 174 |
} |
| 175 |
|
| 176 |
$msg = '__Logs Cleared__'; |
| 177 |
$ret = array($to, $msg); |
| 178 |
|
| 179 |
return $ret; |
| 180 |
} |
| 181 |
|
| 182 |
public function render() |
| 183 |
{ |
| 184 |
$params = $this->request->getParams(); |
| 185 |
$date = isset($params['date']) ? $params['date'] : $this->t->setNow()->formatDateDb(); |
| 186 |
$type = isset($params['type']) ? $params['type'] : SH4_Reminders_Model::RANGE_DAILY; |
| 187 |
|
| 188 |
// post to |
| 189 |
$slug = $this->request->getSlug(); |
| 190 |
$to = $this->uri->makeUrl( $slug ); |
| 191 |
|
| 192 |
$params = array( |
| 193 |
'date' => $date, |
| 194 |
'type' => $type |
| 195 |
); |
| 196 |
$toSend = $this->uri->makeUrl( array($slug . '/send', $params) ); |
| 197 |
$toClear = $this->uri->makeUrl( array($slug . '/clear', $params) ); |
| 198 |
$toClearSelected = $this->uri->makeUrl( array($slug . '/clearselected', $params) ); |
| 199 |
|
| 200 |
// reminders |
| 201 |
$reminders = $this->remindersQuery->find( $type, $date ); |
| 202 |
|
| 203 |
// reminder logs |
| 204 |
$notSent = array(); |
| 205 |
$logs = array(); |
| 206 |
foreach( $reminders as $reminder ){ |
| 207 |
if( $reminder->log ){ |
| 208 |
$logs[ $reminder->log->id ] = $reminder->log; |
| 209 |
} |
| 210 |
else { |
| 211 |
$notSent[] = 1; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
ob_start(); |
| 216 |
?> |
| 217 |
|
| 218 |
<?php |
| 219 |
// _print_r( $logs ); |
| 220 |
?> |
| 221 |
|
| 222 |
<div class="hc-mb3"> |
| 223 |
<form action="<?php echo $to; ?>" method="post" accept-charset="utf-8"> |
| 224 |
<fieldset class="hc-p1 hc-border"> |
| 225 |
<legend>__Filter__</legend> |
| 226 |
<div class="hc-clearfix"> |
| 227 |
<div class="hc-col hc-col-3"> |
| 228 |
<div class="hc-p2"> |
| 229 |
<?php echo $this->ui->makeInputDatepicker( 'date', NULL, $date ); ?> |
| 230 |
</div> |
| 231 |
</div> |
| 232 |
<div class="hc-col hc-col-7"> |
| 233 |
<div class="hc-p2"> |
| 234 |
<?php |
| 235 |
$types = array( |
| 236 |
SH4_Reminders_Model::RANGE_DAILY => '__Daily__', |
| 237 |
SH4_Reminders_Model::RANGE_WEEKLY => '__Weekly__', |
| 238 |
SH4_Reminders_Model::RANGE_MONTHLY => '__Monthly__', |
| 239 |
); |
| 240 |
|
| 241 |
if( $this->sms->isEnabled() ){ |
| 242 |
$types[ SH4_Reminders_Model::RANGE_DAILY_SMS ] = '__Daily__' . ' ' . '__SMS__'; |
| 243 |
} |
| 244 |
?> |
| 245 |
|
| 246 |
<?php foreach( $types as $k => $label ) : ?> |
| 247 |
<label> |
| 248 |
<input type="radio" name="hc-type" value="<?php echo $k; ?>"<?php if( $k == $type ) : ?> checked<?php endif; ?>/> |
| 249 |
<?php echo $label; ?> |
| 250 |
</label> |
| 251 |
<?php endforeach; ?> |
| 252 |
</div> |
| 253 |
</div> |
| 254 |
<div class="hc-col hc-col-2"> |
| 255 |
<button type="submit" class="button button-secondary hc-block">__Apply Filter__</button> |
| 256 |
</div> |
| 257 |
</div> |
| 258 |
</fieldset> |
| 259 |
</form> |
| 260 |
</div> |
| 261 |
|
| 262 |
<?php if( $reminders ) : ?> |
| 263 |
|
| 264 |
<?php if($logs) : ?> |
| 265 |
<form action="<?php echo $toClearSelected; ?>" method="post" accept-charset="utf-8"> |
| 266 |
<?php endif; ?> |
| 267 |
<table class="wp-list-table widefat fixed striped"> |
| 268 |
|
| 269 |
<thead> |
| 270 |
<tr> |
| 271 |
<?php if($logs) : ?><td style="width: 2em;"></td><?php endif; ?> |
| 272 |
<td class="hc-col-4">__Employee__</td> |
| 273 |
<td class="hc-col-4">__User__</td> |
| 274 |
<td class="hc-col-1">__Shifts__</td> |
| 275 |
<td class="hc-col-3">__Sent__</td> |
| 276 |
</tr> |
| 277 |
</thead> |
| 278 |
|
| 279 |
<tbody> |
| 280 |
<?php foreach( $reminders as $r ) : ?> |
| 281 |
<?php |
| 282 |
$toParams = array(); |
| 283 |
$toParams[ 'employee' ] = array( $r->employee->getId() ); |
| 284 |
$toParams[ 'type' ] = 'list'; |
| 285 |
$toParams[ 'groupby' ] = 'none'; |
| 286 |
|
| 287 |
if( SH4_Reminders_Model::RANGE_DAILY == $r->range ){ |
| 288 |
$toParams[ 'start' ] = $r->date; |
| 289 |
$toParams[ 'end' ] = $r->date; |
| 290 |
} |
| 291 |
|
| 292 |
if( SH4_Reminders_Model::RANGE_DAILY_SMS == $r->range ){ |
| 293 |
$toParams[ 'start' ] = $r->date; |
| 294 |
$toParams[ 'end' ] = $r->date; |
| 295 |
} |
| 296 |
|
| 297 |
if( SH4_Reminders_Model::RANGE_WEEKLY == $r->range ){ |
| 298 |
$start = $this->t->setDateDb( $r->date )->setStartWeek()->formatDateDb(); |
| 299 |
$end = $this->t->setDateDb( $start )->modify('+1 week')->modify('-1 day')->formatDateDb(); |
| 300 |
$toParams[ 'start' ] = $start; |
| 301 |
$toParams[ 'end' ] = $end; |
| 302 |
} |
| 303 |
|
| 304 |
if( SH4_Reminders_Model::RANGE_MONTHLY == $r->range ){ |
| 305 |
$start = $this->t->setDateDb( $r->date )->setStartMonth()->formatDateDb(); |
| 306 |
$end = $this->t->setDateDb( $start )->modify('+1 month')->modify('-1 day')->formatDateDb(); |
| 307 |
$toParams[ 'start' ] = $start; |
| 308 |
$toParams[ 'end' ] = $end; |
| 309 |
} |
| 310 |
|
| 311 |
$to = 'schedule'; |
| 312 |
$detailsLink = $this->uri->makeUrl( array($to, $toParams) ); |
| 313 |
$employeeId = $r->employee->getId(); |
| 314 |
?> |
| 315 |
|
| 316 |
<tr> |
| 317 |
<?php if($logs) : ?> |
| 318 |
<td class="hc-align-center"> |
| 319 |
<?php if($r->log): ?> |
| 320 |
<label><input id="employee-<?php echo esc_attr($employeeId); ?>" type="checkbox" name="hc-employee[]" value="<?php echo esc_attr($employeeId); ?>"></label> |
| 321 |
<?php endif; ?> |
| 322 |
</td> |
| 323 |
<?php endif; ?> |
| 324 |
<td> |
| 325 |
<?php if($logs) : ?><label for="employee-<?php echo esc_attr($employeeId); ?>"><?php endif; ?> |
| 326 |
<?php echo $this->employeesPresenter->presentTitle( $r->employee ); ?> |
| 327 |
<?php if($logs) : ?></label><?php endif; ?> |
| 328 |
<?php if( in_array($r->range, [SH4_Reminders_Model::RANGE_DAILY_SMS]) ) : ?> |
| 329 |
<?php $phone = $this->sms->getEmployeePhone($employeeId); ?> |
| 330 |
<a href="<?php echo esc_attr($this->uri->makeUrl('admin/reminders/sms')); ?>" title="__Phone Number__" class="hc-block"> |
| 331 |
<?php if( $phone ) : ?><?php echo esc_html( $phone ); ?><?php else : ?>__No Phone Number__<?php endif; ?> |
| 332 |
</a> |
| 333 |
<?php endif; ?> |
| 334 |
</td> |
| 335 |
<td> |
| 336 |
<?php if( $r->user ): ?> |
| 337 |
<?php echo $this->usersPresenter->presentTitle( $r->user ); ?> |
| 338 |
<?php if( in_array($r->range, [SH4_Reminders_Model::RANGE_DAILY_SMS]) ) : ?> |
| 339 |
<?php else : ?> |
| 340 |
<div title="__Email__"><?php echo esc_html($r->user->getEmail()); ?></div> |
| 341 |
<?php endif; ?> |
| 342 |
<?php else : ?> |
| 343 |
__N/A__ |
| 344 |
<?php endif; ?> |
| 345 |
</td> |
| 346 |
<td> |
| 347 |
<a href="<?php echo $detailsLink; ?>" class="hc-block" target="_blank"><?php echo count( $r->shifts ); ?></a> |
| 348 |
</td> |
| 349 |
<td> |
| 350 |
<?php if( $r->log ) : ?> |
| 351 |
<?php echo $this->t->setDateTimeDb( $r->log->sent_on )->formatDateWithWeekday(); ?> <?php echo $this->t->formatTime(); ?> |
| 352 |
<?php else : ?> |
| 353 |
<mark>__Not Sent__</mark> |
| 354 |
<?php endif; ?> |
| 355 |
</td> |
| 356 |
</tr> |
| 357 |
<?php endforeach; ?> |
| 358 |
</tbody> |
| 359 |
|
| 360 |
</table> |
| 361 |
|
| 362 |
<?php if( $logs ) : ?> |
| 363 |
<p> |
| 364 |
<button type="submit" class="button button-secondary hc-xs-block">× __Clear Logs For Selected Employees__</button> |
| 365 |
</p> |
| 366 |
</form> |
| 367 |
<?php endif; ?> |
| 368 |
|
| 369 |
<?php if( $logs ) : ?> |
| 370 |
<form action="<?php echo $toClear; ?>" method="post" accept-charset="utf-8"> |
| 371 |
<p> |
| 372 |
<button type="submit" class="button button-secondary hc-xs-block">× __Clear All Logs__</button> |
| 373 |
</p> |
| 374 |
</form> |
| 375 |
<?php endif; ?> |
| 376 |
|
| 377 |
<?php if( $notSent ) : ?> |
| 378 |
<form action="<?php echo $toSend; ?>" method="post" accept-charset="utf-8"> |
| 379 |
<p> |
| 380 |
<button type="submit" class="button button-primary hc-xs-block">__Send Reminder Messages__</button> |
| 381 |
</p> |
| 382 |
</form> |
| 383 |
<?php endif; ?> |
| 384 |
|
| 385 |
|
| 386 |
<?php else: ?> |
| 387 |
|
| 388 |
<p> |
| 389 |
__No Reminders__ |
| 390 |
</p> |
| 391 |
|
| 392 |
<?php endif; ?> |
| 393 |
|
| 394 |
<?php |
| 395 |
$ret = trim( ob_get_clean() ); |
| 396 |
|
| 397 |
$this->layout |
| 398 |
->setContent( $ret ) |
| 399 |
->setHeader( $this->self->header() ) |
| 400 |
->setBreadcrumb( $this->self->breadcrumbs() ) |
| 401 |
; |
| 402 |
|
| 403 |
$ret = $this->layout->render(); |
| 404 |
return $ret; |
| 405 |
} |
| 406 |
} |