| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
interface SH4_Shifts_View_ICommon |
| 3 |
{ |
| 4 |
public function breadcrumb( SH4_Shifts_Model $model ); |
| 5 |
public function menu( SH4_Shifts_Model $model ); |
| 6 |
public function icons( SH4_Shifts_Model $model, $iknow = array() ); |
| 7 |
} |
| 8 |
|
| 9 |
#[AllowDynamicProperties] |
| 10 |
class SH4_Shifts_View_Common implements SH4_Shifts_View_ICommon |
| 11 |
{ |
| 12 |
public function __construct( |
| 13 |
HC3_Hooks $hooks, |
| 14 |
HC3_Settings $settings, |
| 15 |
HC3_Auth $auth, |
| 16 |
HC3_Ui $ui, |
| 17 |
SH4_Shifts_Presenter $presenter, |
| 18 |
SH4_Shifts_Conflicts $conflicts |
| 19 |
) |
| 20 |
{ |
| 21 |
$this->self = $hooks->wrap($this); |
| 22 |
$this->ui = $ui; |
| 23 |
$this->presenter = $hooks->wrap($presenter); |
| 24 |
$this->auth = $hooks->wrap( $auth ); |
| 25 |
$this->conflicts = $hooks->wrap( $conflicts ); |
| 26 |
$this->settings = $hooks->wrap( $settings ); |
| 27 |
} |
| 28 |
|
| 29 |
public function breadcrumb( SH4_Shifts_Model $model ) |
| 30 |
{ |
| 31 |
$id = $model->getId(); |
| 32 |
|
| 33 |
$return = array(); |
| 34 |
|
| 35 |
// schedule link |
| 36 |
$scheduleLink = HC3_Session::instance()->getUserdata( 'scheduleLink' ); |
| 37 |
if( ! $scheduleLink ){ |
| 38 |
$scheduleLink = array( 'schedule', array() ); |
| 39 |
} |
| 40 |
// $return['schedule'] = array( $scheduleLink, '__Schedule__' ); |
| 41 |
|
| 42 |
$label = $this->presenter->presentTitle($model); |
| 43 |
$return['schedule/' . $id ] = array( 'shifts/' . $id , $label ); |
| 44 |
// $return['schedule/' . $id ] = $label; |
| 45 |
|
| 46 |
return $return; |
| 47 |
} |
| 48 |
|
| 49 |
public function bulkMenu( array $models ) |
| 50 |
{ |
| 51 |
$ret = null; |
| 52 |
|
| 53 |
$menu = array(); |
| 54 |
$skipMulti = array( |
| 55 |
'employee_pickup', |
| 56 |
'employee_assign', |
| 57 |
// 'employee_pickup/reset', |
| 58 |
// 'employee_pickup/request' |
| 59 |
); |
| 60 |
|
| 61 |
foreach( $models as $m ){ |
| 62 |
$fullMenu = $this->self->menu( $m ); |
| 63 |
foreach( $fullMenu as $k0 => $thisMenu ){ |
| 64 |
foreach( $thisMenu as $k1 => $actionArray ){ |
| 65 |
$k = $k0 . '_' . $k1; |
| 66 |
if( (count($models) > 1) && (! in_array($k, $skipMulti)) ){ |
| 67 |
$thisK = $k . ':' . $m->getId(); |
| 68 |
} |
| 69 |
else { |
| 70 |
$thisK = $k; |
| 71 |
} |
| 72 |
$menu[$thisK] = $actionArray; |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
if( ! $menu ) return $ret; |
| 78 |
|
| 79 |
$id = $m->getId(); |
| 80 |
|
| 81 |
$menu = $this->ui->helperActionsFromArray( $menu, true ); |
| 82 |
$menu = $this->ui->makeCollection( $menu ); |
| 83 |
|
| 84 |
$checkbox = $this->ui->makeInputCheckbox( 'id[]', null, $id, true ); |
| 85 |
$checkbox = $this->ui->makeBlock( $checkbox ) |
| 86 |
->addAttr('class', 'sh4-shift-checker') |
| 87 |
->addAttr('style', 'display: none;') |
| 88 |
; |
| 89 |
$ret = $this->ui->makeCollection( array($checkbox, $menu) ); |
| 90 |
|
| 91 |
return $ret; |
| 92 |
} |
| 93 |
|
| 94 |
public function menu( SH4_Shifts_Model $model ) |
| 95 |
{ |
| 96 |
$id = $model->getId(); |
| 97 |
|
| 98 |
$return = array(); |
| 99 |
|
| 100 |
$conflicts = $this->conflicts->get( $model ); |
| 101 |
if( $conflicts ){ |
| 102 |
$label = '__View Conflicts__'; |
| 103 |
$return['datetime']['conflicts'] = array( 'shifts/' . $id . '/conflicts', $label ); |
| 104 |
} |
| 105 |
$return['datetime']['time'] = array( 'shifts/' . $id . '/time', '__Change Time__' ); |
| 106 |
$return['datetime']['date'] = array( 'shifts/' . $id . '/date', '__Change Date__' ); |
| 107 |
|
| 108 |
if( $model->isOpen() ){ |
| 109 |
$return['employee']['assign'] = array( |
| 110 |
array( 'shifts/--ID--/employee', $id ), |
| 111 |
'__Assign__' |
| 112 |
); |
| 113 |
} |
| 114 |
else { |
| 115 |
$return['employee']['change'] = array( |
| 116 |
array( 'shifts/--ID--/employee', $id ), |
| 117 |
'__Change Employee__' |
| 118 |
); |
| 119 |
$return['employee']['change2'] = array( |
| 120 |
array( 'shifts/--ID--/employeecopy', $id ), |
| 121 |
'__Copy To Another Employee__' |
| 122 |
); |
| 123 |
$return['employee']['unassign'] = array( |
| 124 |
'shifts/' . $id . '/employee/0', |
| 125 |
null, |
| 126 |
'__Unassign__' |
| 127 |
); |
| 128 |
} |
| 129 |
|
| 130 |
if( $model->isDraft() ){ |
| 131 |
$confirm = $this->settings->get('shifts_confirm_publish') ? true : false; |
| 132 |
$return['status']['publish'] = array( 'shifts/' . $id . '/publish', NULL, '__Publish__', $confirm ); |
| 133 |
} |
| 134 |
else { |
| 135 |
$noDraft = $this->settings->get('shifts_no_draft') ? TRUE : FALSE; |
| 136 |
if( ! $noDraft ){ |
| 137 |
$return['status']['unpublish'] = array( 'shifts/' . $id . '/unpublish', NULL, '__Unpublish__' ); |
| 138 |
// $return['status']['unpublish2'] = array( 'shifts/' . $id . '/unpublish','<input type="text"><button type="submit">unbub</button', '' ); |
| 139 |
} |
| 140 |
} |
| 141 |
$return['status']['delete'] = array( 'shifts/' . $id . '/delete', NULL, '__Delete__' ); |
| 142 |
|
| 143 |
$return['calendar']['change'] = array('shifts/' . $id . '/calendar', '__Change Calendar__' ); |
| 144 |
|
| 145 |
return $return; |
| 146 |
} |
| 147 |
|
| 148 |
public function icons( SH4_Shifts_Model $model, $iknow = array() ) |
| 149 |
{ |
| 150 |
$return = array(); |
| 151 |
$calendar = $model->getCalendar(); |
| 152 |
|
| 153 |
if( $model->isDraft() ){ |
| 154 |
if( ! $calendar->isAvailability() ){ |
| 155 |
$sign = $this->ui->makeBlock('?') |
| 156 |
->tag('align', 'center') |
| 157 |
->addAttr('style', 'width: 1em;') |
| 158 |
->tag('border') |
| 159 |
// ->tag('border-color', 'gray' ) |
| 160 |
// ->tag('bgcolor', 'silver') |
| 161 |
->tag('bgcolor', 'gray') |
| 162 |
->tag('color', 'white') |
| 163 |
->tag('muted', 1) |
| 164 |
->addAttr('title', '__Draft__') |
| 165 |
; |
| 166 |
if( ! isset($return['status']) ){ |
| 167 |
$return['status'] = array(); |
| 168 |
} |
| 169 |
$return['status'][] = $sign; |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
if( ! in_array('conflicts', $iknow) ){ |
| 174 |
$conflicts = array(); |
| 175 |
$currentUser = $this->auth->getCurrentUser(); |
| 176 |
$currentUserId = $currentUser->getId(); |
| 177 |
if( $currentUserId ){ |
| 178 |
$conflicts = $this->conflicts->get( $model ); |
| 179 |
} |
| 180 |
|
| 181 |
if( $conflicts ){ |
| 182 |
$sign = $this->ui->makeBlock('!') |
| 183 |
->tag('align', 'center') |
| 184 |
->addAttr('style', 'width: 1em;') |
| 185 |
->tag('border') |
| 186 |
->tag('border-color', 'red' ) |
| 187 |
->tag('bgcolor', 'lightred') |
| 188 |
->tag('muted', 1) |
| 189 |
->addAttr('title', '__Conflicts__') |
| 190 |
; |
| 191 |
if( ! isset($return['datetime']) ){ |
| 192 |
$return['datetime'] = array(); |
| 193 |
} |
| 194 |
$return['datetime'][] = $sign; |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
if( $model->isOpen() ){ |
| 199 |
$sign = $this->ui->makeBlock('!') |
| 200 |
->tag('align', 'center') |
| 201 |
->addAttr('style', 'width: 1em;') |
| 202 |
->tag('border') |
| 203 |
// ->tag('border-color', 'orange' ) |
| 204 |
// ->tag('bgcolor', 'yellow') |
| 205 |
->tag('bgcolor', 'orange') |
| 206 |
->tag('color', 'white') |
| 207 |
->tag('muted', 1) |
| 208 |
->addAttr('title', '__Open Shift__') |
| 209 |
; |
| 210 |
if( ! isset($return['employee']) ){ |
| 211 |
$return['employee'] = array(); |
| 212 |
} |
| 213 |
$return['employee'][] = $sign; |
| 214 |
} |
| 215 |
|
| 216 |
return $return; |
| 217 |
} |
| 218 |
} |