begin to refactor user shift state

This commit is contained in:
Philip Häusler 2014-08-24 15:49:46 +02:00
parent 25b5096c7e
commit 0e2b257342
5 changed files with 6 additions and 23 deletions

View File

@ -50,7 +50,7 @@ function user_controller() {
return array( return array(
$user_source['Nick'], $user_source['Nick'],
User_view($user_source, $admin_user_privilege, User_is_freeloader($user_source), User_shift_state($user_source), User_angeltypes($user_source), User_groups($user_source), $shifts, $user['UID'] == $user_source['UID']) User_view($user_source, $admin_user_privilege, User_is_freeloader($user_source), User_angeltypes($user_source), User_groups($user_source), $shifts, $user['UID'] == $user_source['UID'])
); );
} }

View File

@ -3,23 +3,6 @@
* User model * User model
*/ */
/**
* Returns -seconds until free if user is busy or seconds until next shift.
* 0 if there is an error or no upcoming shift.
*
* @param User $user
*/
function User_shift_state($user) {
$shifts = ShiftEntries_upcoming_for_user($user);
if ($shifts === false)
return 0;
if (count($shifts) == 0)
return 0;
if ($shifts[0]['start'] < time())
return $shifts[0]['end'] - time();
return $shifts[0]['start'] - time();
}
/** /**
* Returns true if user is freeloader * Returns true if user is freeloader
* *

View File

@ -49,7 +49,7 @@ function admin_free() {
$free_users_table[] = array( $free_users_table[] = array(
'name' => User_Nick_render($usr), 'name' => User_Nick_render($usr),
'shift_state' => User_shift_mode_render(User_shift_state($usr)), 'shift_state' => User_shift_state_render($usr),
'dect' => $usr['DECT'], 'dect' => $usr['DECT'],
'jabber' => $usr['jabber'], 'jabber' => $usr['jabber'],
'email' => $usr['email'], 'email' => $usr['email'],

View File

@ -19,7 +19,7 @@ function header_toolbar() {
$toolbar_items = array(); $toolbar_items = array();
if (isset($user)) if (isset($user))
$toolbar_items[] = toolbar_item_link('#', 'time', User_shift_mode_render(User_shift_state($user))); $toolbar_items[] = toolbar_item_link('#', 'time', User_shift_state_render(User_shift_state($user)));
$toolbar_items[] = make_langselect(); $toolbar_items[] = make_langselect();

View File

@ -19,7 +19,7 @@ $tshirt_sizes = array(
'XL-G' => "XL Girl" 'XL-G' => "XL Girl"
); );
function User_shift_mode_render($shift_mode) { function User_shift_state_render($user) {
if ($shift_mode == 0) if ($shift_mode == 0)
return '<span class="text-success">' . _("Free") . '</span>'; return '<span class="text-success">' . _("Free") . '</span>';
if ($shift_mode > 8 * 3600) if ($shift_mode > 8 * 3600)
@ -30,7 +30,7 @@ function User_shift_mode_render($shift_mode) {
return '<span class="text-danger moment-countdown" data-seconds="' . $shift_mode . '">' . _("Current shift ends in") . '</span>'; return '<span class="text-danger moment-countdown" data-seconds="' . $shift_mode . '">' . _("Current shift ends in") . '</span>';
} }
function User_view($user_source, $admin_user_privilege, $freeloader, $user_shift_mode, $user_angeltypes, $user_groups, $shifts, $its_me) { function User_view($user_source, $admin_user_privilege, $freeloader, $user_angeltypes, $user_groups, $shifts, $its_me) {
global $LETZTES_AUSTRAGEN, $privileges; global $LETZTES_AUSTRAGEN, $privileges;
$user_name = htmlspecialchars($user_source['Vorname']) . " " . htmlspecialchars($user_source['Name']); $user_name = htmlspecialchars($user_source['Vorname']) . " " . htmlspecialchars($user_source['Name']);
@ -106,7 +106,7 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_shift
div('col-md-3', array( div('col-md-3', array(
'<h4>' . _("User state") . '</h4>', '<h4>' . _("User state") . '</h4>',
($admin_user_privilege && $freeloader) ? '<span class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"></span> ' . _("Freeloader") . '</span><br />' : '', ($admin_user_privilege && $freeloader) ? '<span class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"></span> ' . _("Freeloader") . '</span><br />' : '',
$user_source['Gekommen'] ? User_shift_mode_render($user_shift_mode) . '<br />' : '', $user_source['Gekommen'] ? User_shift_state_render($user_source) . '<br />' : '',
($user_source['Gekommen'] ? '<span class="text-success"><span class="glyphicon glyphicon-home"></span> ' . _("Arrived") . '</span>' : '<span class="text-danger">' . _("Not arrived") . '</span>'), ($user_source['Gekommen'] ? '<span class="text-success"><span class="glyphicon glyphicon-home"></span> ' . _("Arrived") . '</span>' : '<span class="text-danger">' . _("Not arrived") . '</span>'),
($user_source['Gekommen'] && $admin_user_privilege && $user_source['Aktiv']) ? ' <span class="text-success">' . _("Active") . '</span>' : '', ($user_source['Gekommen'] && $admin_user_privilege && $user_source['Aktiv']) ? ' <span class="text-success">' . _("Active") . '</span>' : '',
($user_source['Gekommen'] && $admin_user_privilege && $user_source['Tshirt']) ? ' <span class="text-success">' . _("T-Shirt") . '</span>' : '' ($user_source['Gekommen'] && $admin_user_privilege && $user_source['Tshirt']) ? ' <span class="text-success">' . _("T-Shirt") . '</span>' : ''