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()) {
ShiftSignupStatus::ADMIN, ShiftSignupStatus::OCCUPIED => 'success',
ShiftSignupStatus::SIGNED_UP => 'primary',
ShiftSignupStatus::NOT_ARRIVED, ShiftSignupStatus::NOT_YET, ShiftSignupStatus::SHIFT_ENDED => 'secondary',
ShiftSignupStatus::ANGELTYPE, ShiftSignupStatus::COLLIDES => 'warning',
ShiftSignupStatus::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(ShiftSignupStatus::SHIFT_ENDED, 0);
}
if (auth()->can('user_shifts_admin')) {
$html .= '