| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
#[AllowDynamicProperties] |
| 3 |
class SH4_New_Controller_CustomTime |
| 4 |
{ |
| 5 |
public function __construct( |
| 6 |
HC3_Hooks $hooks, |
| 7 |
|
| 8 |
HC3_Request $request, |
| 9 |
HC3_Post $post, |
| 10 |
|
| 11 |
HC3_Time $t |
| 12 |
) |
| 13 |
{ |
| 14 |
$this->t = $t; |
| 15 |
$this->request = $request; |
| 16 |
$this->post = $hooks->wrap( $post ); |
| 17 |
|
| 18 |
$this->self = $hooks->wrap($this); |
| 19 |
} |
| 20 |
|
| 21 |
public function execute( $calendarId ) |
| 22 |
{ |
| 23 |
$thisId = array(); |
| 24 |
|
| 25 |
$params = $this->request->getParams(); |
| 26 |
|
| 27 |
$time = $this->post->get('time'); |
| 28 |
list( $start, $end ) = explode('-', $time); |
| 29 |
$thisId[] = $start; |
| 30 |
$thisId[] = $end; |
| 31 |
|
| 32 |
$startBreak = $endBreak = NULL; |
| 33 |
$breakOn = $this->post->get('break_on'); |
| 34 |
if( $breakOn ){ |
| 35 |
$break = $this->post->get('break'); |
| 36 |
list( $startBreak, $endBreak ) = explode( '-', $break ); |
| 37 |
} |
| 38 |
|
| 39 |
if( $breakOn ){ |
| 40 |
$errors = array(); |
| 41 |
|
| 42 |
if( ($end > 24*60*60) && ($startBreak < $start) ){ |
| 43 |
$startBreak = 24*60*60 + $startBreak; |
| 44 |
$endBreak = 24*60*60 + $endBreak; |
| 45 |
} |
| 46 |
|
| 47 |
if( ($startBreak >= $end) OR ($startBreak < $start) ){ |
| 48 |
$msg = '__Lunch break should be within shift hours.__'; |
| 49 |
$errors['break'] = $msg; |
| 50 |
} |
| 51 |
if( ($endBreak > $end) OR ($endBreak <= $start) ){ |
| 52 |
$msg = '__Lunch break should be within shift hours.__'; |
| 53 |
$errors['break'] = $msg; |
| 54 |
} |
| 55 |
|
| 56 |
if( $errors ){ |
| 57 |
$return = array( '-referrer-', $errors, TRUE ); |
| 58 |
return $return; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
if( $breakOn ){ |
| 63 |
$thisId[] = $startBreak; |
| 64 |
$thisId[] = $endBreak; |
| 65 |
} |
| 66 |
|
| 67 |
$thisId = join('-', $thisId); |
| 68 |
|
| 69 |
$to = 'new'; |
| 70 |
$toParams = $params; |
| 71 |
$toParams['calendar'] = $calendarId; |
| 72 |
$toParams['shifttype'] = $thisId; |
| 73 |
$to = array( $to, $toParams ); |
| 74 |
|
| 75 |
$return = array( $to, NULL ); |
| 76 |
return $return; |
| 77 |
} |
| 78 |
} |
| 79 |
|