From 0e2b2573420cf318fc2cbd605b987adf7c2b60c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20H=C3=A4usler?= Date: Sun, 24 Aug 2014 15:49:46 +0200 Subject: [PATCH] begin to refactor user shift state --- includes/controller/users_controller.php | 2 +- includes/model/User_model.php | 17 ----------------- includes/pages/admin_free.php | 2 +- includes/sys_menu.php | 2 +- includes/view/User_view.php | 6 +++--- 5 files changed, 6 insertions(+), 23 deletions(-) diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 77997278..1f3b3677 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -50,7 +50,7 @@ function user_controller() { return array( $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']) ); } diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 45600676..7d2809f7 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -3,23 +3,6 @@ * 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 * diff --git a/includes/pages/admin_free.php b/includes/pages/admin_free.php index 836197db..13d4f795 100644 --- a/includes/pages/admin_free.php +++ b/includes/pages/admin_free.php @@ -49,7 +49,7 @@ function admin_free() { $free_users_table[] = array( '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'], 'jabber' => $usr['jabber'], 'email' => $usr['email'], diff --git a/includes/sys_menu.php b/includes/sys_menu.php index 89c07572..790ca3b2 100644 --- a/includes/sys_menu.php +++ b/includes/sys_menu.php @@ -19,7 +19,7 @@ function header_toolbar() { $toolbar_items = array(); 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(); diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 1824a1c4..e5405835 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -19,7 +19,7 @@ $tshirt_sizes = array( 'XL-G' => "XL Girl" ); -function User_shift_mode_render($shift_mode) { +function User_shift_state_render($user) { if ($shift_mode == 0) return '' . _("Free") . ''; if ($shift_mode > 8 * 3600) @@ -30,7 +30,7 @@ function User_shift_mode_render($shift_mode) { return '' . _("Current shift ends in") . ''; } -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; $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( '

' . _("User state") . '

', ($admin_user_privilege && $freeloader) ? ' ' . _("Freeloader") . '
' : '', - $user_source['Gekommen'] ? User_shift_mode_render($user_shift_mode) . '
' : '', + $user_source['Gekommen'] ? User_shift_state_render($user_source) . '
' : '', ($user_source['Gekommen'] ? ' ' . _("Arrived") . '' : '' . _("Not arrived") . ''), ($user_source['Gekommen'] && $admin_user_privilege && $user_source['Aktiv']) ? ' ' . _("Active") . '' : '', ($user_source['Gekommen'] && $admin_user_privilege && $user_source['Tshirt']) ? ' ' . _("T-Shirt") . '' : ''