| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
interface SH4_ShiftTypes_Model_ |
| 3 |
{ |
| 4 |
public function getId(); |
| 5 |
public function getTitle(); |
| 6 |
public function getRange(); |
| 7 |
|
| 8 |
public function getStart(); |
| 9 |
public function getEnd(); |
| 10 |
public function getBreakStart(); |
| 11 |
public function getBreakEnd(); |
| 12 |
|
| 13 |
public function isAllDay(); |
| 14 |
public function getDuration(); |
| 15 |
} |
| 16 |
|
| 17 |
class SH4_ShiftTypes_Model implements SH4_ShiftTypes_Model_ |
| 18 |
{ |
| 19 |
const RANGE_HOURS = 'hours'; |
| 20 |
const RANGE_DAYS = 'days'; |
| 21 |
|
| 22 |
private $id = NULL; |
| 23 |
private $title = NULL; |
| 24 |
private $range = NULL; |
| 25 |
|
| 26 |
private $start = 0; |
| 27 |
private $end = 86400; |
| 28 |
private $breakStart = NULL; |
| 29 |
private $breakEnd = NULL; |
| 30 |
|
| 31 |
public function __construct( $id, $title, $range, $start, $end, $breakStart = NULL, $breakEnd = NULL ) |
| 32 |
{ |
| 33 |
$this->id = $id; |
| 34 |
$this->title = $title; |
| 35 |
$this->range = $range; |
| 36 |
$this->start = $start; |
| 37 |
$this->end = $end; |
| 38 |
$this->breakStart = $breakStart; |
| 39 |
$this->breakEnd = $breakEnd; |
| 40 |
return $this; |
| 41 |
} |
| 42 |
|
| 43 |
public function getId() |
| 44 |
{ |
| 45 |
return $this->id; |
| 46 |
} |
| 47 |
|
| 48 |
public function getTitle() |
| 49 |
{ |
| 50 |
return $this->title; |
| 51 |
} |
| 52 |
|
| 53 |
public function getRange() |
| 54 |
{ |
| 55 |
return $this->range; |
| 56 |
} |
| 57 |
|
| 58 |
public function getStart() |
| 59 |
{ |
| 60 |
return $this->start; |
| 61 |
} |
| 62 |
|
| 63 |
public function getEnd() |
| 64 |
{ |
| 65 |
return $this->end; |
| 66 |
} |
| 67 |
|
| 68 |
public function getBreakStart() |
| 69 |
{ |
| 70 |
return $this->breakStart; |
| 71 |
} |
| 72 |
|
| 73 |
public function getBreakEnd() |
| 74 |
{ |
| 75 |
return $this->breakEnd; |
| 76 |
} |
| 77 |
|
| 78 |
public function isAllDay() |
| 79 |
{ |
| 80 |
$return = FALSE; |
| 81 |
if( ($this->getStart() == 0) && ($this->getEnd() == 24*60*60) ){ |
| 82 |
$return = TRUE; |
| 83 |
} |
| 84 |
return $return; |
| 85 |
} |
| 86 |
|
| 87 |
public function getDuration() |
| 88 |
{ |
| 89 |
$start = $this->getStart(); |
| 90 |
$end = $this->getEnd(); |
| 91 |
|
| 92 |
$return = ( $end > $start ) ? ($end - $start) : (24*60*60 - $start) + $end; |
| 93 |
return $return; |
| 94 |
} |
| 95 |
} |