title != '') {
$info_text = icon('info-circle') . $shift->title . '
';
}
list($shift_signup_state, $shifts_row) = $this->renderShiftNeededAngeltypes(
$shift,
$needed_angeltypes,
$shift_entries,
$user
);
$class = $this->classForSignupState($shift_signup_state);
$blocks = ceil(($shift->end->timestamp - $shift->start->timestamp) / ShiftCalendarRenderer::SECONDS_PER_ROW);
$blocks = max(1, $blocks);
$room = $shift->room;
return [
$blocks,
div(
'shift-card" style="height: '
. ($blocks * ShiftCalendarRenderer::BLOCK_HEIGHT - ShiftCalendarRenderer::MARGIN)
. 'px;',
div(
'shift card bg-' . $class,
[
$this->renderShiftHead($shift, $class, $shift_signup_state->getFreeEntries()),
div('card-body ' . $this->classBg(), [
$info_text,
Room_name_render($room)
]),
$shifts_row
]
)
)
];
}
/**
* @param ShiftSignupState $shiftSignupState
* @return string
*/
private function classForSignupState(ShiftSignupState $shiftSignupState)
{
return match ($shiftSignupState->getState()) {
ShiftSignupState::ADMIN, ShiftSignupState::OCCUPIED => 'success',
ShiftSignupState::SIGNED_UP => 'primary',
ShiftSignupState::NOT_ARRIVED, ShiftSignupState::NOT_YET, ShiftSignupState::SHIFT_ENDED => 'secondary',
ShiftSignupState::ANGELTYPE, ShiftSignupState::COLLIDES => 'warning',
ShiftSignupState::FREE => 'danger',
default => 'light',
};
}
/**
* @param Shift $shift
* @param array[] $needed_angeltypes
* @param ShiftEntry[]|Collection $shift_entries
* @param User $user
* @return array
*/
private function renderShiftNeededAngeltypes(Shift $shift, $needed_angeltypes, $shift_entries, $user)
{
$shift_entries_filtered = [];
foreach ($needed_angeltypes as $needed_angeltype) {
$shift_entries_filtered[$needed_angeltype['id']] = [];
}
foreach ($shift_entries as $shift_entry) {
$shift_entries_filtered[$shift_entry->angel_type_id][] = $shift_entry;
}
$html = '';
/** @var ShiftSignupState $shift_signup_state */
$shift_signup_state = null;
foreach ($needed_angeltypes as $angeltype) {
if ($angeltype['count'] > 0 || count($shift_entries_filtered[$angeltype['id']]) > 0) {
list($angeltype_signup_state, $angeltype_html) = $this->renderShiftNeededAngeltype(
$shift,
$shift_entries_filtered[$angeltype['id']],
$angeltype,
$user
);
if (is_null($shift_signup_state)) {
$shift_signup_state = $angeltype_signup_state;
} else {
$shift_signup_state->combineWith($angeltype_signup_state);
}
$html .= $angeltype_html;
}
}
if (is_null($shift_signup_state)) {
$shift_signup_state = new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, 0);
}
if (auth()->can('user_shifts_admin')) {
$html .= '