From 1e8f0c484588882e01bc173f7f60e2cf1376f790 Mon Sep 17 00:00:00 2001 From: msquare Date: Wed, 27 Dec 2017 12:24:55 +0100 Subject: fixes #208, fixes #310: T-Shirt Scoreā„¢ should be shown on the user view page below your shifts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/model/User_model.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'includes/model') 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 @@ -17,6 +17,30 @@ function User_delete($user_id) DB::delete('DELETE FROM `User` WHERE `UID`=?', [$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. * -- cgit v1.2.3-70-g09d2