| 1 |
<?php |
| 2 |
class Shift_Template_HC_Model extends MY_model |
| 3 |
{ |
| 4 |
/* |
| 5 |
properties: |
| 6 |
name |
| 7 |
start |
| 8 |
end |
| 9 |
*/ |
| 10 |
|
| 11 |
var $table = 'shift_templates'; |
| 12 |
var $default_order_by = array('start' => 'ASC'); |
| 13 |
var $validation = array( |
| 14 |
'name' => array('required', 'trim', 'max_length' => 50, 'unique'), |
| 15 |
'start' => array('required', 'trim'), |
| 16 |
'end' => array('required', 'trim', 'differs' => 'start', 'check_break'), |
| 17 |
'lunch_break' => array('check_break'), |
| 18 |
); |
| 19 |
|
| 20 |
public function get_duration( $use_break = TRUE ) |
| 21 |
{ |
| 22 |
if( $this->end > $this->start ) |
| 23 |
$return = $this->end - $this->start; |
| 24 |
else |
| 25 |
$return = $this->end + (24*60*60 - $this->start); |
| 26 |
|
| 27 |
if( $use_break ){ |
| 28 |
if( isset($this->lunch_break) && $this->lunch_break ){ |
| 29 |
$return = $return - $this->lunch_break; |
| 30 |
} |
| 31 |
} |
| 32 |
return $return; |
| 33 |
} |
| 34 |
|
| 35 |
public function _check_break( $field ) |
| 36 |
{ |
| 37 |
$return = ( $this->get_duration(FALSE) > $this->lunch_break ) ? TRUE : FALSE; |
| 38 |
if( ! $return ){ |
| 39 |
$return = HCM::__('The break should not be longer than the shift itself'); |
| 40 |
} |
| 41 |
return $return; |
| 42 |
} |
| 43 |
} |