diff options
author | msquare <msquare@notrademark.de> | 2017-12-27 12:24:55 +0100 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2017-12-27 12:24:55 +0100 |
commit | 1e8f0c484588882e01bc173f7f60e2cf1376f790 (patch) | |
tree | 92a039f8449c55109e4e1832deef4fe56177ae4d /includes | |
parent | abf4b1da30e7fabebfa5e36cfc5c1fe691320a1e (diff) |
fixes #208, fixes #310: T-Shirt Score™ should be shown on the user view page below your shifts
Diffstat (limited to 'includes')
-rw-r--r-- | includes/controller/users_controller.php | 6 | ||||
-rw-r--r-- | includes/model/User_model.php | 24 | ||||
-rw-r--r-- | includes/view/User_view.php | 24 |
3 files changed, 45 insertions, 9 deletions
diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index e206176f..ae297851 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -220,7 +220,7 @@ function user_controller() ); } } - + if ($user_source['api_key'] == '') { User_reset_api_key($user_source, false); } @@ -234,7 +234,9 @@ function user_controller() User_angeltypes($user_source), User_groups($user_source), $shifts, - $user['UID'] == $user_source['UID'] + $user['UID'] == $user_source['UID'], + User_tshirt_score($user_source), + in_array('admin_active', $privileges) ) ]; } diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 33fca639..fa24aac1 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -18,6 +18,30 @@ function User_delete($user_id) } /** + * Returns the tshirt score (number of hours counted for tshirt). + * Accounts only ended shifts. + * + * @param array[] $user + */ +function User_tshirt_score($user) { + $shift_sum_formula = config('shift_sum_formula'); + + $result = DB::selectOne(' + SELECT ROUND((' . $shift_sum_formula . ') / 3600, 2) AS `tshirt_score` + FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID` + LEFT JOIN `Shifts` ON `ShiftEntry`.`SID` = `Shifts`.`SID` + WHERE `User`.`UID` = ? + AND `Shifts`.`end` < ? + GROUP BY `User`.`UID` + ',[ + $user['UID'], + time() + ]); + + return $result['tshirt_score']; +} + +/** * Update user. * * @param array $user diff --git a/includes/view/User_view.php b/includes/view/User_view.php index a80eb096..7a36aafe 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -401,16 +401,14 @@ function User_view_myshift($shift, $user_source, $its_me) * @param bool $its_me * @return array */ -function User_view_myshifts($shifts, $user_source, $its_me) +function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshirt_admin) { $myshifts_table = []; $timesum = 0; foreach ($shifts as $shift) { $myshifts_table[] = User_view_myshift($shift, $user_source, $its_me); - if ($shift['freeloaded']) { - $timesum += (-2 * ($shift['end'] - $shift['start'])); - } else { + if (!$shift['freeloaded']) { $timesum += ($shift['end'] - $shift['start']); } } @@ -418,12 +416,22 @@ function User_view_myshifts($shifts, $user_source, $its_me) if (count($myshifts_table) > 0) { $myshifts_table[] = [ 'date' => '<b>' . _('Sum:') . '</b>', - 'time' => '<b>' . round($timesum / 3600, 1) . ' h</b>', + 'time' => '<b>' . round($timesum / 3600, 2) . ' h</b>', 'room' => '', 'shift_info' => '', 'comment' => '', 'actions' => '' ]; + if($its_me || $tshirt_admin) { + $myshifts_table[] = [ + 'date' => '<b>' . _('Your t-shirt score') . '™:</b>', + 'time' => '<b>' . round($tshirt_score, 2) . ' h</b>', + 'room' => '', + 'shift_info' => '', + 'comment' => '', + 'actions' => '' + ]; + } } return $myshifts_table; } @@ -438,12 +446,14 @@ function User_view_myshifts($shifts, $user_source, $its_me) * @param array[] $user_groups * @param array[] $shifts * @param bool $its_me + * @param int $tshirt_score + * @param bool $tshirt_admin * @return string */ -function User_view($user_source, $admin_user_privilege, $freeloader, $user_angeltypes, $user_groups, $shifts, $its_me) +function User_view($user_source, $admin_user_privilege, $freeloader, $user_angeltypes, $user_groups, $shifts, $its_me, $tshirt_score, $tshirt_admin) { $user_name = htmlspecialchars($user_source['Vorname']) . ' ' . htmlspecialchars($user_source['Name']); - $myshifts_table = User_view_myshifts($shifts, $user_source, $its_me); + $myshifts_table = User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshirt_admin); return page_with_title( '<span class="icon-icon_angel"></span> ' |