| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
interface SH4_Shifts_IConflicts |
| 3 |
{ |
| 4 |
public function register( $check ); |
| 5 |
public function get( SH4_Shifts_Model $shift ); |
| 6 |
} |
| 7 |
|
| 8 |
class SH4_Shifts_Conflicts implements SH4_Shifts_IConflicts |
| 9 |
{ |
| 10 |
protected $checks = array(); |
| 11 |
protected $cache = array(); |
| 12 |
public $dic; |
| 13 |
|
| 14 |
public function __construct( HC3_Dic $dic ) |
| 15 |
{ |
| 16 |
$this->dic = $dic; |
| 17 |
} |
| 18 |
|
| 19 |
public function register( $check ) |
| 20 |
{ |
| 21 |
$this->checks[] = $check; |
| 22 |
return $this; |
| 23 |
} |
| 24 |
|
| 25 |
public function get( SH4_Shifts_Model $shift, array $skipIdList = array() ) |
| 26 |
{ |
| 27 |
$id = $shift->getId(); |
| 28 |
if( ($id > 0) && isset($this->cache[$id]) ){ |
| 29 |
return $this->cache[$id]; |
| 30 |
} |
| 31 |
|
| 32 |
$return = array(); |
| 33 |
|
| 34 |
reset( $this->checks ); |
| 35 |
foreach( $this->checks as $check ){ |
| 36 |
$check = $this->dic->make( $check ); |
| 37 |
|
| 38 |
$checkResult = $check->check( $shift, $skipIdList ); |
| 39 |
if( ! $checkResult ){ |
| 40 |
$return[] = $check; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
$this->cache[$id] = $return; |
| 45 |
|
| 46 |
return $return; |
| 47 |
} |
| 48 |
} |