/** * Redirects the user to his next shift. */ function shift_next_controller() { global $user, $privileges; if (!in_array('user_shifts', $privileges)) { redirect(page_link_to('?')); } $upcoming_shifts = ShiftEntries_upcoming_for_user($user); if ($upcoming_shifts === false) { return false; } if (count($upcoming_shifts) > 0) { redirect(shift_link($upcoming_shifts[0])); } redirect(page_link_to('user_shifts')); }
function User_shift_state_render($user) { $upcoming_shifts = ShiftEntries_upcoming_for_user($user); if ($upcoming_shifts === false) { return false; } if (count($upcoming_shifts) == 0) { return '<span class="text-success">' . _("Free") . '</span>'; } if ($upcoming_shifts[0]['start'] > time()) { if ($upcoming_shifts[0]['start'] - time() > 3600) { return '<span class="text-success moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Next shift %c") . '</span>'; } else { return '<span class="text-warning moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Next shift %c") . '</span>'; } } $halfway = ($upcoming_shifts[0]['start'] + $upcoming_shifts[0]['end']) / 2; if (time() < $halfway) { return '<span class="text-danger moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Shift starts %c") . '</span>'; } else { return '<span class="text-danger moment-countdown" data-timestamp="' . $upcoming_shifts[0]['end'] . '">' . _("Shift ends %c") . '</span>'; } }