summaryrefslogtreecommitdiff
path: root/includes/model/User_model.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/model/User_model.php')
-rw-r--r--includes/model/User_model.php24
1 files changed, 24 insertions, 0 deletions
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