| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class SH4_ConflictsCalendar_Overlap implements SH4_Shifts_Conflict_IConflict |
| 3 |
{ |
| 4 |
private $_conflictingShifts = array(); |
| 5 |
public $ui, $widget, $shiftsQuery; |
| 6 |
|
| 7 |
public function __construct( |
| 8 |
HC3_Hooks $hooks, |
| 9 |
HC3_Ui $ui, |
| 10 |
|
| 11 |
SH4_Shifts_Query $shiftsQuery, |
| 12 |
SH4_Shifts_View_Widget $widget |
| 13 |
) |
| 14 |
{ |
| 15 |
$this->ui = $ui; |
| 16 |
$this->widget = $widget; |
| 17 |
|
| 18 |
$this->shiftsQuery = $hooks->wrap( $shiftsQuery ); |
| 19 |
} |
| 20 |
|
| 21 |
// find overlapping shifts for the same calendar |
| 22 |
public function check( SH4_Shifts_Model $shift ) |
| 23 |
{ |
| 24 |
$return = TRUE; |
| 25 |
|
| 26 |
$this->_conflictingShifts = array(); |
| 27 |
|
| 28 |
// $isOpen = $shift->isOpen(); |
| 29 |
// if( $isOpen ){ |
| 30 |
// return $return; |
| 31 |
// } |
| 32 |
|
| 33 |
$calendar = $shift->getCalendar(); |
| 34 |
if( $calendar->isAvailability() ){ |
| 35 |
return $return; |
| 36 |
} |
| 37 |
|
| 38 |
$calendar = $shift->getCalendar(); |
| 39 |
if( ! $calendar ){ |
| 40 |
return $return; |
| 41 |
} |
| 42 |
$calendarId = $calendar->getId(); |
| 43 |
$id = $shift->getId(); |
| 44 |
|
| 45 |
$this->shiftsQuery |
| 46 |
->setStart( $shift->getStart() ) |
| 47 |
->setEnd( $shift->getEnd() ) |
| 48 |
; |
| 49 |
|
| 50 |
$testShifts = $this->shiftsQuery->find(); |
| 51 |
|
| 52 |
foreach( $testShifts as $testShift ){ |
| 53 |
$testId = $testShift->getId(); |
| 54 |
|
| 55 |
if( $testId == $id ){ |
| 56 |
continue; |
| 57 |
} |
| 58 |
|
| 59 |
$testCalendar = $testShift->getCalendar(); |
| 60 |
if( $testCalendar->isAvailability() ){ |
| 61 |
continue; |
| 62 |
} |
| 63 |
|
| 64 |
$testCalendarId = $testCalendar->getId(); |
| 65 |
if( $testCalendarId != $calendarId ){ |
| 66 |
continue; |
| 67 |
} |
| 68 |
|
| 69 |
$this->_conflictingShifts[] = $testShift; |
| 70 |
} |
| 71 |
|
| 72 |
if( $this->_conflictingShifts ){ |
| 73 |
$return = FALSE; |
| 74 |
} |
| 75 |
|
| 76 |
return $return; |
| 77 |
} |
| 78 |
|
| 79 |
public function render() |
| 80 |
{ |
| 81 |
$label = '__Calendar Overlap__'; |
| 82 |
|
| 83 |
$iknow = array('conflicts'); |
| 84 |
$hori = TRUE; |
| 85 |
|
| 86 |
$viewShifts = array(); |
| 87 |
foreach( $this->_conflictingShifts as $shift ){ |
| 88 |
$viewShifts[] = $this->widget->render( $shift, $iknow, $hori ); |
| 89 |
} |
| 90 |
$out = $this->ui->makeList( $viewShifts ); |
| 91 |
|
| 92 |
$out = $this->ui->makeLabelled( $label, $out ); |
| 93 |
return $out; |
| 94 |
} |
| 95 |
} |